diff options
| author | Olivier Dony <odo@openerp.com> | 2010-07-02 17:33:57 +0200 |
|---|---|---|
| committer | Olivier Dony <odo@openerp.com> | 2010-07-02 17:33:57 +0200 |
| commit | 59fdce2fe29d36bdac17c07d51dc2861a3acf4f9 (patch) | |
| tree | 5662e26c46b5e16d6aebaaf18117d2d87e9be1d3 /bin/tools/misc.py | |
| parent | d19ade2298441601db57eaa53b3381923868284a (diff) | |
[FIX] tools.ustr: corrected backwards compatibility for conversion of non-string objects
bzr revid: odo@openerp.com-20100702153357-5qc6y03lxudynpyz
Diffstat (limited to 'bin/tools/misc.py')
| -rw-r--r-- | bin/tools/misc.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bin/tools/misc.py b/bin/tools/misc.py index b7be921c916..b3489a8a5dc 100644 --- a/bin/tools/misc.py +++ b/bin/tools/misc.py @@ -857,19 +857,24 @@ def ustr(value, hint_encoding='utf-8'): @rtype: unicode @return: unicode string """ - orig = value if isinstance(value, Exception): return exception_to_unicode(value) if isinstance(value, unicode): return value + if not isinstance(value, basestring): + try: + return unicode(value) + except Exception: + raise UnicodeError('unable de to convert %r' % (value,)) + for ln in get_encodings(hint_encoding): try: return unicode(value, ln) except Exception: pass - raise UnicodeError('unable de to convert %r' % (orig,)) + raise UnicodeError('unable de to convert %r' % (value,)) def exception_to_unicode(e): |
