[py3] Made __repr__ return str with Python 3

This commit is contained in:
Claude Paroz 2012-08-12 20:36:43 +02:00
parent c1684e3dcb
commit dce34dc969
5 changed files with 17 additions and 15 deletions

View File

@ -7,7 +7,7 @@ from __future__ import unicode_literals
from django.db import models from django.db import models
from django.utils import formats from django.utils import formats
from django.utils.text import capfirst from django.utils.text import capfirst
from django.utils.encoding import smart_text, smart_bytes, iri_to_uri from django.utils.encoding import smart_text, smart_str, iri_to_uri
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.utils.encoding import python_2_unicode_compatible from django.utils.encoding import python_2_unicode_compatible
@ -23,7 +23,7 @@ class EasyModel(object):
self.verbose_name_plural = model._meta.verbose_name_plural self.verbose_name_plural = model._meta.verbose_name_plural
def __repr__(self): def __repr__(self):
return '<EasyModel for %s>' % smart_bytes(self.model._meta.object_name) return smart_str('<EasyModel for %s>' % self.model._meta.object_name)
def model_databrowse(self): def model_databrowse(self):
"Returns the ModelDatabrowse class for this model." "Returns the ModelDatabrowse class for this model."
@ -62,7 +62,7 @@ class EasyField(object):
self.model, self.field = easy_model, field self.model, self.field = easy_model, field
def __repr__(self): def __repr__(self):
return smart_bytes('<EasyField for %s.%s>' % (self.model.model._meta.object_name, self.field.name)) return smart_str('<EasyField for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
def choices(self): def choices(self):
for value, label in self.field.choices: for value, label in self.field.choices:
@ -80,7 +80,7 @@ class EasyChoice(object):
self.value, self.label = value, label self.value, self.label = value, label
def __repr__(self): def __repr__(self):
return smart_bytes('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name)) return smart_str('<EasyChoice for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
def url(self): def url(self):
return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value)) return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value))
@ -91,7 +91,7 @@ class EasyInstance(object):
self.model, self.instance = easy_model, instance self.model, self.instance = easy_model, instance
def __repr__(self): def __repr__(self):
return smart_bytes('<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val())) return smart_str('<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val()))
def __str__(self): def __str__(self):
val = smart_text(self.instance) val = smart_text(self.instance)
@ -135,7 +135,7 @@ class EasyInstanceField(object):
self.raw_value = getattr(instance.instance, field.name) self.raw_value = getattr(instance.instance, field.name)
def __repr__(self): def __repr__(self):
return smart_bytes('<EasyInstanceField for %s.%s>' % (self.model.model._meta.object_name, self.field.name)) return smart_str('<EasyInstanceField for %s.%s>' % (self.model.model._meta.object_name, self.field.name))
def values(self): def values(self):
""" """

View File

@ -8,7 +8,7 @@ from io import BytesIO
from django.conf import settings from django.conf import settings
from django.core.files.base import File from django.core.files.base import File
from django.core.files import temp as tempfile from django.core.files import temp as tempfile
from django.utils.encoding import smart_bytes from django.utils.encoding import smart_str
__all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile', __all__ = ('UploadedFile', 'TemporaryUploadedFile', 'InMemoryUploadedFile',
'SimpleUploadedFile') 'SimpleUploadedFile')
@ -30,7 +30,7 @@ class UploadedFile(File):
self.charset = charset self.charset = charset
def __repr__(self): def __repr__(self):
return smart_bytes("<%s: %s (%s)>" % ( return smart_str("<%s: %s (%s)>" % (
self.__class__.__name__, self.name, self.content_type)) self.__class__.__name__, self.name, self.content_type))
def _get_name(self): def _get_name(self):

View File

@ -14,7 +14,7 @@ from threading import local
from django.http import Http404 from django.http import Http404
from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist
from django.utils.datastructures import MultiValueDict from django.utils.datastructures import MultiValueDict
from django.utils.encoding import iri_to_uri, force_text, smart_bytes from django.utils.encoding import iri_to_uri, force_text, smart_str
from django.utils.functional import memoize, lazy from django.utils.functional import memoize, lazy
from django.utils.importlib import import_module from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
@ -190,7 +190,7 @@ class RegexURLPattern(LocaleRegexProvider):
self.name = name self.name = name
def __repr__(self): def __repr__(self):
return smart_bytes('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern)) return smart_str('<%s %s %s>' % (self.__class__.__name__, self.name, self.regex.pattern))
def add_prefix(self, prefix): def add_prefix(self, prefix):
""" """
@ -240,7 +240,9 @@ class RegexURLResolver(LocaleRegexProvider):
self._app_dict = {} self._app_dict = {}
def __repr__(self): def __repr__(self):
return smart_bytes('<%s %s (%s:%s) %s>' % (self.__class__.__name__, self.urlconf_name, self.app_name, self.namespace, self.regex.pattern)) return smart_str('<%s %s (%s:%s) %s>' % (
self.__class__.__name__, self.urlconf_name, self.app_name,
self.namespace, self.regex.pattern))
def _populate(self): def _populate(self):
lookups = MultiValueDict() lookups = MultiValueDict()

View File

@ -23,7 +23,7 @@ from django.db.models import signals
from django.db.models.loading import register_models, get_model from django.db.models.loading import register_models, get_model
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.functional import curry from django.utils.functional import curry
from django.utils.encoding import smart_bytes, force_text from django.utils.encoding import smart_bytes, smart_str, force_text
from django.utils import six from django.utils import six
from django.utils.text import get_text_list, capfirst from django.utils.text import get_text_list, capfirst
@ -404,7 +404,7 @@ class Model(six.with_metaclass(ModelBase, object)):
u = six.text_type(self) u = six.text_type(self)
except (UnicodeEncodeError, UnicodeDecodeError): except (UnicodeEncodeError, UnicodeDecodeError):
u = '[Bad Unicode data]' u = '[Bad Unicode data]'
return smart_bytes('<%s: %s>' % (self.__class__.__name__, u)) return smart_str('<%s: %s>' % (self.__class__.__name__, u))
def __str__(self): def __str__(self):
if not six.PY3 and hasattr(self, '__unicode__'): if not six.PY3 and hasattr(self, '__unicode__'):

View File

@ -11,7 +11,7 @@ from django.utils.importlib import import_module
from django.utils.itercompat import is_iterable from django.utils.itercompat import is_iterable
from django.utils.text import (smart_split, unescape_string_literal, from django.utils.text import (smart_split, unescape_string_literal,
get_text_list) get_text_list)
from django.utils.encoding import smart_text, force_text, smart_bytes from django.utils.encoding import smart_text, force_text, smart_str
from django.utils.translation import ugettext_lazy, pgettext_lazy from django.utils.translation import ugettext_lazy, pgettext_lazy
from django.utils.safestring import (SafeData, EscapeData, mark_safe, from django.utils.safestring import (SafeData, EscapeData, mark_safe,
mark_for_escaping) mark_for_escaping)
@ -848,7 +848,7 @@ class TextNode(Node):
self.s = s self.s = s
def __repr__(self): def __repr__(self):
return "<Text Node: '%s'>" % smart_bytes(self.s[:25], 'ascii', return "<Text Node: '%s'>" % smart_str(self.s[:25], 'ascii',
errors='replace') errors='replace')
def render(self, context): def render(self, context):