diff options
| -rw-r--r-- | rest_framework/compat.py | 9 | ||||
| -rw-r--r-- | rest_framework/renderers.py | 6 | 
2 files changed, 13 insertions, 2 deletions
| diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 4ab23a4d..0201bd83 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -291,6 +291,15 @@ except ImportError:      oauth2_constants = None      provider_now = None +# `seperators` argument to `json.dumps()` differs between 2.x and 3.x +# See: http://bugs.python.org/issue22767 +if six.PY3: +    SHORT_SEPARATORS = (',', ':') +    LONG_SEPARATORS = (', ', ': ') +else: +    SHORT_SEPARATORS = (b',', b':') +    LONG_SEPARATORS = (b', ', b': ') +  # Handle lazy strings across Py2/Py3  from django.utils.functional import Promise diff --git a/rest_framework/renderers.py b/rest_framework/renderers.py index 4dfd0f49..c950b498 100644 --- a/rest_framework/renderers.py +++ b/rest_framework/renderers.py @@ -18,7 +18,9 @@ from django.test.client import encode_multipart  from django.utils import six  from django.utils.xmlutils import SimplerXMLGenerator  from rest_framework import exceptions, serializers, status, VERSION -from rest_framework.compat import StringIO, smart_text, yaml +from rest_framework.compat import ( +    SHORT_SEPARATORS, LONG_SEPARATORS, StringIO, smart_text, yaml +)  from rest_framework.exceptions import ParseError  from rest_framework.settings import api_settings  from rest_framework.request import is_form_media_type, override_method @@ -87,7 +89,7 @@ class JSONRenderer(BaseRenderer):          renderer_context = renderer_context or {}          indent = self.get_indent(accepted_media_type, renderer_context) -        separators = (',', ':') if (indent is None and self.compact) else (', ', ': ') +        separators = SHORT_SEPARATORS if (indent is None and self.compact) else LONG_SEPARATORS          ret = json.dumps(              data, cls=self.encoder_class, | 
