1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[py3] Refactored __unicode__ to __str__.

* Renamed the __unicode__ methods
* Applied the python_2_unicode_compatible decorator
* Removed the StrAndUnicode mix-in that is superseded by
  python_2_unicode_compatible
* Kept the __unicode__ methods in classes that specifically
  test it under Python 2
This commit is contained in:
Aymeric Augustin
2012-08-12 12:32:08 +02:00
parent 79d62a7175
commit d4a0b27838
142 changed files with 1072 additions and 481 deletions

View File

@@ -8,6 +8,7 @@ import re
from django.utils.encoding import force_text
from django.utils.html_parser import HTMLParser, HTMLParseError
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
WHITESPACE = re.compile('\s+')
@@ -17,6 +18,7 @@ def normalize_whitespace(string):
return WHITESPACE.sub(' ', string)
@python_2_unicode_compatible
class Element(object):
def __init__(self, name, attributes):
self.name = name
@@ -117,7 +119,7 @@ class Element(object):
def __getitem__(self, key):
return self.children[key]
def __unicode__(self):
def __str__(self):
output = '<%s' % self.name
for key, value in self.attributes:
if value:
@@ -136,11 +138,12 @@ class Element(object):
return six.text_type(self)
@python_2_unicode_compatible
class RootElement(Element):
def __init__(self):
super(RootElement, self).__init__(None, ())
def __unicode__(self):
def __str__(self):
return ''.join(six.text_type(c) for c in self.children)