diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2013-09-06 21:03:46 +0200 |
|---|---|---|
| committer | Florian Apolloner <florian@apolloner.eu> | 2013-09-06 21:03:46 +0200 |
| commit | 85359ec9a4514087e2cc666b77eb635aacba5073 (patch) | |
| tree | dadff0704a02dc3f0cb1aaa2351265f3a07adadf /django/utils | |
| parent | cc957cb16cfdad7e6c9e97dc885fc415abbf5eaa (diff) | |
| parent | 2326dedde81c59950d2b1e0653a837e1d7019acd (diff) | |
Merge branch 't20812'
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/encoding.py | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 667c3def45..a7239f4b0f 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -67,16 +67,15 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'): return s try: if not isinstance(s, six.string_types): - if hasattr(s, '__unicode__'): - s = s.__unicode__() - else: - 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) + s = six.text_type(s) + elif hasattr(s, '__unicode__'): + 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 |
