summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2015-01-31 16:05:16 +0100
committerClaude Paroz <claude@2xlibre.net>2015-02-03 18:26:08 +0100
commitea3e40c278eb27fb3c8362d9e8cd67f957bf4f57 (patch)
treef1dff819d7569eba4175c95b6e3d001ffe0301f7 /django/utils
parentd88c24f436ae23ff5aec4ea06c0c27499a71e074 (diff)
[1.8.x] Fixed #24252 -- Forced lazy __str__ to utf-8 on Python 2
Thanks Stanislas Guerra for the report and Tomas Ehrlich for the review. Backport of cd0ceaa102 from master.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/functional.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/utils/functional.py b/django/utils/functional.py
index aa0d6f850a..37cc7c7f0f 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -120,6 +120,7 @@ def lazy(func, *resultclasses):
cls.__str__ = cls.__text_cast
else:
cls.__unicode__ = cls.__text_cast
+ cls.__str__ = cls.__bytes_cast_encoded
elif cls._delegate_bytes:
if six.PY3:
cls.__bytes__ = cls.__bytes_cast
@@ -142,6 +143,9 @@ def lazy(func, *resultclasses):
def __bytes_cast(self):
return bytes(func(*self.__args, **self.__kw))
+ def __bytes_cast_encoded(self):
+ return func(*self.__args, **self.__kw).encode('utf-8')
+
def __cast(self):
if self._delegate_bytes:
return self.__bytes_cast()