summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2015-06-04 23:31:29 +0100
committerTim Graham <timograham@gmail.com>2015-06-05 08:40:57 -0400
commitc91bc68e9a5f9f1e2cce00d01d62d16a858155f0 (patch)
tree8622be51f023d5eae4028184a70662544d16abad /django/utils/encoding.py
parent2fbea621e68d3365679e45fa17b61d06aa8cdf76 (diff)
downloaddjango-c91bc68e9a5f9f1e2cce00d01d62d16a858155f0.tar.gz
Fixed #24927 -- Used python_2_unicode_compatible from six
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py18
1 files changed, 2 insertions, 16 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 4e347bdc5f..48fde393a7 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -25,22 +25,8 @@ class DjangoUnicodeDecodeError(UnicodeDecodeError):
type(self.obj))
-def python_2_unicode_compatible(klass):
- """
- A decorator that defines __unicode__ and __str__ methods under Python 2.
- Under Python 3 it does nothing.
-
- To support Python 2 and 3 with a single code base, define a __str__ method
- returning text and apply this decorator to the class.
- """
- if six.PY2:
- if '__str__' not in klass.__dict__:
- raise ValueError("@python_2_unicode_compatible cannot be applied "
- "to %s because it doesn't define __str__()." %
- klass.__name__)
- klass.__unicode__ = klass.__str__
- klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
- return klass
+# For backwards compatibility. (originally in Django, then added to six 1.9)
+python_2_unicode_compatible = six.python_2_unicode_compatible
def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):