From dce34dc9696734f7ca02d410ddac69d714a25f1e Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sun, 12 Aug 2012 20:36:43 +0200 Subject: [PATCH] [py3] Made __repr__ return str with Python 3 --- django/contrib/databrowse/datastructures.py | 12 ++++++------ django/core/files/uploadedfile.py | 4 ++-- django/core/urlresolvers.py | 8 +++++--- django/db/models/base.py | 4 ++-- django/template/base.py | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/django/contrib/databrowse/datastructures.py b/django/contrib/databrowse/datastructures.py index 13e24167f5..9d6ac34f3f 100644 --- a/django/contrib/databrowse/datastructures.py +++ b/django/contrib/databrowse/datastructures.py @@ -7,7 +7,7 @@ from __future__ import unicode_literals from django.db import models from django.utils import formats 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.utils.encoding import python_2_unicode_compatible @@ -23,7 +23,7 @@ class EasyModel(object): self.verbose_name_plural = model._meta.verbose_name_plural def __repr__(self): - return '' % smart_bytes(self.model._meta.object_name) + return smart_str('' % self.model._meta.object_name) def model_databrowse(self): "Returns the ModelDatabrowse class for this model." @@ -62,7 +62,7 @@ class EasyField(object): self.model, self.field = easy_model, field def __repr__(self): - return smart_bytes('' % (self.model.model._meta.object_name, self.field.name)) + return smart_str('' % (self.model.model._meta.object_name, self.field.name)) def choices(self): for value, label in self.field.choices: @@ -80,7 +80,7 @@ class EasyChoice(object): self.value, self.label = value, label def __repr__(self): - return smart_bytes('' % (self.model.model._meta.object_name, self.field.name)) + return smart_str('' % (self.model.model._meta.object_name, self.field.name)) 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)) @@ -91,7 +91,7 @@ class EasyInstance(object): self.model, self.instance = easy_model, instance def __repr__(self): - return smart_bytes('' % (self.model.model._meta.object_name, self.instance._get_pk_val())) + return smart_str('' % (self.model.model._meta.object_name, self.instance._get_pk_val())) def __str__(self): val = smart_text(self.instance) @@ -135,7 +135,7 @@ class EasyInstanceField(object): self.raw_value = getattr(instance.instance, field.name) def __repr__(self): - return smart_bytes('' % (self.model.model._meta.object_name, self.field.name)) + return smart_str('' % (self.model.model._meta.object_name, self.field.name)) def values(self): """ diff --git a/django/core/files/uploadedfile.py b/django/core/files/uploadedfile.py index 3a6c632975..97d53482e4 100644 --- a/django/core/files/uploadedfile.py +++ b/django/core/files/uploadedfile.py @@ -8,7 +8,7 @@ from io import BytesIO from django.conf import settings from django.core.files.base import File 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', 'SimpleUploadedFile') @@ -30,7 +30,7 @@ class UploadedFile(File): self.charset = charset def __repr__(self): - return smart_bytes("<%s: %s (%s)>" % ( + return smart_str("<%s: %s (%s)>" % ( self.__class__.__name__, self.name, self.content_type)) def _get_name(self): diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 2fe744e8eb..1498c9989d 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -14,7 +14,7 @@ from threading import local from django.http import Http404 from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist 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.importlib import import_module from django.utils.module_loading import module_has_submodule @@ -190,7 +190,7 @@ class RegexURLPattern(LocaleRegexProvider): self.name = name 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): """ @@ -240,7 +240,9 @@ class RegexURLResolver(LocaleRegexProvider): self._app_dict = {} 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): lookups = MultiValueDict() diff --git a/django/db/models/base.py b/django/db/models/base.py index 3a569c805a..30e07be3a7 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -23,7 +23,7 @@ from django.db.models import signals from django.db.models.loading import register_models, get_model from django.utils.translation import ugettext_lazy as _ 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.text import get_text_list, capfirst @@ -404,7 +404,7 @@ class Model(six.with_metaclass(ModelBase, object)): u = six.text_type(self) except (UnicodeEncodeError, UnicodeDecodeError): 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): if not six.PY3 and hasattr(self, '__unicode__'): diff --git a/django/template/base.py b/django/template/base.py index 24ad9320e0..091d53421f 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -11,7 +11,7 @@ from django.utils.importlib import import_module from django.utils.itercompat import is_iterable from django.utils.text import (smart_split, unescape_string_literal, 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.safestring import (SafeData, EscapeData, mark_safe, mark_for_escaping) @@ -848,7 +848,7 @@ class TextNode(Node): self.s = s def __repr__(self): - return "" % smart_bytes(self.s[:25], 'ascii', + return "" % smart_str(self.s[:25], 'ascii', errors='replace') def render(self, context):