Ticket #21733: recursionpatch.diff

File recursionpatch.diff, 2.5 KB (added by ntucker, 11 years ago)

Patch

  • django/utils/encoding.py

    diff --git a/django/utils/encoding.py b/django/utils/encoding.py
    index 599952b..2e07c87 100644
    a b class StrAndUnicode(object):  
    4343        def __str__(self):
    4444            return self.__unicode__().encode('utf-8')
    4545
     46class _Python_2_Unicode_Compatible_Str(object):
     47    def __call__(self, obj):
     48        return self.__unicode__().encode('utf-8')
     49_python_2_unicode_compatible_str = _STR()
     50
    4651def python_2_unicode_compatible(klass):
    4752    """
    4853    A decorator that defines __unicode__ and __str__ methods under Python 2.
    def python_2_unicode_compatible(klass):  
    5661            raise ValueError("@python_2_unicode_compatible cannot be applied "
    5762                             "to %s because it doesn't define __str__()." %
    5863                             klass.__name__)
     64        # this was already applied once
     65        if klass.__str__ == _python_2_unicode_compatible_str:
     66            return klass
    5967        klass.__unicode__ = klass.__str__
    60         klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
     68        klass.__str__ = _python_2_unicode_compatible_str
    6169    return klass
    6270
    6371def smart_text(s, encoding='utf-8', strings_only=False, errors='strict'):
Back to Top