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:23:41 +0100
commitcd0ceaa102c1e12b016432db4d180bee7906131f (patch)
treede4beb2be7b3952a9033caf9baf2fc2122e24d21 /django/utils
parent250aa7c39b0025ef3ae508884fda8d6e43c9518f (diff)
Fixed #24252 -- Forced lazy __str__ to utf-8 on Python 2
Thanks Stanislas Guerra for the report and Tomas Ehrlich for the review.
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 9e4df4b2f7..4c085d9c6d 100644
--- a/django/utils/functional.py
+++ b/django/utils/functional.py
@@ -95,6 +95,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
@@ -117,6 +118,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()