0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Resolve py3 compat issue - always return bytes from WagtailJSONRenderer

This commit is contained in:
Tom Christie 2015-07-21 17:31:40 +01:00
parent 0d0ff6c89a
commit 40db88f4e1

View File

@ -2,6 +2,7 @@ import json
from django.core.serializers.json import DjangoJSONEncoder
from django.core.urlresolvers import reverse
from django.utils.six import text_type
from rest_framework import renderers
@ -53,4 +54,9 @@ class WagtailJSONRenderer(renderers.BaseRenderer):
else:
return super(WagtailAPIJSONEncoder, self).default(o)
return json.dumps(data, indent=4, cls=WagtailAPIJSONEncoder)
ret = json.dumps(data, indent=4, cls=WagtailAPIJSONEncoder)
# Deal with inconsistent py2/py3 behavior, and always return bytes.
if isinstance(ret, text_type):
return bytes(ret.encode('utf-8'))
return ret