From 72e08a3e8b6427cb93f0f98b42724e31e5b3d8f9 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 15 Dec 2014 11:55:17 +0000 Subject: Use unicode internally everywhere for 'repr' --- rest_framework/utils/representation.py | 5 ++++- rest_framework/utils/serializer_helpers.py | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'rest_framework/utils') diff --git a/rest_framework/utils/representation.py b/rest_framework/utils/representation.py index 3f17a8b9..0d829a83 100644 --- a/rest_framework/utils/representation.py +++ b/rest_framework/utils/representation.py @@ -2,9 +2,11 @@ Helper functions for creating user-friendly representations of serializer classes and serializer fields. """ +from __future__ import unicode_literals from django.db import models from django.utils.encoding import force_text from django.utils.functional import Promise +from rest_framework.compat import unicode_repr import re @@ -24,10 +26,11 @@ def smart_repr(value): if isinstance(value, Promise) and value._delegate_text: value = force_text(value) - value = repr(value) + value = unicode_repr(value) # Representations like u'help text' # should simply be presented as 'help text' + print type(value), value if value.startswith("u'") and value.endswith("'"): return value[1:] diff --git a/rest_framework/utils/serializer_helpers.py b/rest_framework/utils/serializer_helpers.py index 277cf649..65a04d06 100644 --- a/rest_framework/utils/serializer_helpers.py +++ b/rest_framework/utils/serializer_helpers.py @@ -1,5 +1,6 @@ +from __future__ import unicode_literals import collections -from rest_framework.compat import OrderedDict +from rest_framework.compat import OrderedDict, unicode_to_repr class ReturnDict(OrderedDict): @@ -47,9 +48,9 @@ class BoundField(object): return self._field.__class__ def __repr__(self): - return '<%s value=%s errors=%s>' % ( + return unicode_to_repr('<%s value=%s errors=%s>' % ( self.__class__.__name__, self.value, self.errors - ) + )) class NestedBoundField(BoundField): -- cgit v1.2.3 From dc66cce16da6793efe4a4a4dcdd18db62c859abb Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 15 Dec 2014 12:01:29 +0000 Subject: Remove erronous print --- rest_framework/utils/representation.py | 1 - 1 file changed, 1 deletion(-) (limited to 'rest_framework/utils') diff --git a/rest_framework/utils/representation.py b/rest_framework/utils/representation.py index 0d829a83..1bfc64c1 100644 --- a/rest_framework/utils/representation.py +++ b/rest_framework/utils/representation.py @@ -30,7 +30,6 @@ def smart_repr(value): # Representations like u'help text' # should simply be presented as 'help text' - print type(value), value if value.startswith("u'") and value.endswith("'"): return value[1:] -- cgit v1.2.3