1
0
mirror of https://github.com/django/django.git synced 2025-10-24 22:26:08 +00:00

Fixed #24252 -- Forced lazy __str__ to utf-8 on Python 2

Thanks Stanislas Guerra for the report and Tomas Ehrlich for
the review.
This commit is contained in:
Claude Paroz
2015-01-31 16:05:16 +01:00
parent 250aa7c39b
commit cd0ceaa102
2 changed files with 15 additions and 0 deletions

View File

@@ -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()