summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@rd.io>2012-10-24 15:53:00 -0700
committerAlex Gaynor <alex.gaynor@rd.io>2012-10-24 15:53:00 -0700
commitce1eb320e59b577a600eb84d7f423a1897be3576 (patch)
treead1875003e264d7ff15e5815df42716a7234ffbe
parentda958eb2098372c20cc3aaf905777b1a8d3144eb (diff)
Remove a case that is no longer reachable in encodings.py.
This case was originally designed to handle Exception's which didn't gracefully support coercing themselves to unicode. However, because it lives in the `else` case of `if hasattr(s, '__unicode__'):` we can be sure it's no longer reachable in djanog anymore, because since Python 2.5 exception has subclassed object, which means Exception objects always have an __unicode__ method.
-rw-r--r--django/utils/encoding.py24
1 files changed, 6 insertions, 18 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 3b284f3ed0..b0872471c2 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -98,25 +98,13 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
if hasattr(s, '__unicode__'):
s = s.__unicode__()
else:
- try:
- if six.PY3:
- if isinstance(s, bytes):
- s = six.text_type(s, encoding, errors)
- else:
- s = six.text_type(s)
+ if six.PY3:
+ if isinstance(s, bytes):
+ s = six.text_type(s, encoding, errors)
else:
- s = six.text_type(bytes(s), encoding, errors)
- except UnicodeEncodeError:
- if not isinstance(s, Exception):
- raise
- # If we get to here, the caller has passed in an Exception
- # subclass populated with non-ASCII data without special
- # handling to display as a string. We need to handle this
- # without raising a further exception. We do an
- # approximation to what the Exception's standard str()
- # output should be.
- s = ' '.join([force_text(arg, encoding, strings_only,
- errors) for arg in s])
+ s = six.text_type(s)
+ else:
+ s = six.text_type(bytes(s), encoding, errors)
else:
# Note: We use .decode() here, instead of six.text_type(s, encoding,
# errors), so that if s is a SafeBytes, it ends up being a