mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
modified to use a reader
modified to use a reader since direct decoding is not supported
This commit is contained in:
parent
3a2ad8e68c
commit
9a22811671
|
@ -7,6 +7,7 @@ on the request, such as form content or json encoded data.
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import codecs
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.uploadhandler import StopFutureHandlers
|
from django.core.files.uploadhandler import StopFutureHandlers
|
||||||
|
@ -22,7 +23,6 @@ from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from rest_framework import renderers
|
from rest_framework import renderers
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
import codecs
|
|
||||||
|
|
||||||
|
|
||||||
class DataAndFiles(object):
|
class DataAndFiles(object):
|
||||||
|
@ -62,7 +62,7 @@ class JSONParser(BaseParser):
|
||||||
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
decoded_stream = codecs.decode(stream, encoding)
|
decoded_stream = codecs.getreader(encoding)(stream)
|
||||||
return json.load(decoded_stream)
|
return json.load(decoded_stream)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user