summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorKaren Tracey <kmtracey@gmail.com>2010-02-28 15:18:03 +0000
committerKaren Tracey <kmtracey@gmail.com>2010-02-28 15:18:03 +0000
commit9e95d6f6047a43268d3138a03342ad0534c4362b (patch)
treef00680e0b8e5ce43038882c325b40ca1e60612fc /django/utils
parent68f216a6925e5e0d78e499157b2c2a261bb7f24c (diff)
Fixed #12302: Modified force_unicode to avoid raising unicode errors when
handed exceptions with non-ASCII bytestring data and no working unicode method under Python 2.6 and higher. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12621 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/encoding.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 66e6ebdd76..2c9ef0975b 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -89,7 +89,16 @@ def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
# SafeUnicode at the end.
s = s.decode(encoding, errors)
except UnicodeDecodeError, e:
- raise DjangoUnicodeDecodeError(s, *e.args)
+ if not isinstance(s, Exception):
+ raise DjangoUnicodeDecodeError(s, *e.args)
+ else:
+ # If we get to here, the caller has passed in an Exception
+ # subclass populated with non-ASCII bytestring data without a
+ # working unicode method. Try to handle this without raising a
+ # further exception by individually forcing the exception args
+ # to unicode.
+ s = ' '.join([force_unicode(arg, encoding, strings_only,
+ errors) for arg in s])
return s
def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'):