diff options
| author | Tom Christie | 2014-12-15 12:18:55 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-12-15 12:18:55 +0000 |
| commit | b6ee784240b3c7f6cd62af5b6fe6d1014d7bf6d4 (patch) | |
| tree | e3cdb5a6e210e5ba26d6726cc08a44c8f450776b /rest_framework/compat.py | |
| parent | 8934e61b67e4aed38b04f2fe18f011ecbf9010cb (diff) | |
| parent | af53e34dd5873f3373e9991c3825e70d92432e14 (diff) | |
| download | django-rest-framework-b6ee784240b3c7f6cd62af5b6fe6d1014d7bf6d4.tar.bz2 | |
Merge master
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 43ad6eaa..c5242343 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. |
