From 59fdce2fe29d36bdac17c07d51dc2861a3acf4f9 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 2 Jul 2010 17:33:57 +0200 Subject: [PATCH] [FIX] tools.ustr: corrected backwards compatibility for conversion of non-string objects bzr revid: odo@openerp.com-20100702153357-5qc6y03lxudynpyz --- bin/tools/misc.py | 9 +++++++-- 1 file 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):