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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user