diff options
| author | Tom Christie | 2014-12-15 11:55:17 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-15 11:55:17 +0000 | 
| commit | 72e08a3e8b6427cb93f0f98b42724e31e5b3d8f9 (patch) | |
| tree | 9d2fe5ded957a5e1c6d86ac87aeafb4be3055ab2 /rest_framework/compat.py | |
| parent | a72f812d80a4000e86a5ad96001f3fbf43fe310a (diff) | |
| download | django-rest-framework-72e08a3e8b6427cb93f0f98b42724e31e5b3d8f9.tar.bz2 | |
Use unicode internally everywhere for 'repr'
Diffstat (limited to 'rest_framework/compat.py')
| -rw-r--r-- | rest_framework/compat.py | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 71520b92..69fdd793 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -16,6 +16,23 @@ from django.utils import six  import django +def unicode_repr(instance): +    # Get the repr of an instance, but ensure it is a unicode string +    # on both python 3 (already the case) and 2 (not the case). +    if six.PY2: +        repr(instance).decode('utf-8') +    return repr(instance) + + +def unicode_to_repr(value): +    # Coerce a unicode string to the correct repr return type, depending on +    # the Python version. We wrap all our `__repr__` implementations with +    # this and then use unicode throughout internally. +    if six.PY2: +        return value.encode('utf-8') +    return value + +  # OrderedDict only available in Python 2.7.  # This will always be the case in Django 1.7 and above, as these versions  # no longer support Python 2.6. | 
