diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py index 1b9a61750d..937d839239 100644 --- a/django/core/serializers/json.py +++ b/django/core/serializers/json.py @@ -8,7 +8,6 @@ from __future__ import absolute_import import datetime import decimal import json -from io import BytesIO from django.core.serializers.base import DeserializationError from django.core.serializers.python import Serializer as PythonSerializer @@ -63,13 +62,13 @@ def Deserializer(stream_or_string, **options): Deserialize a stream or string of JSON data. """ if isinstance(stream_or_string, bytes): - stream = BytesIO(stream_or_string) - elif isinstance(stream_or_string, unicode): - stream = BytesIO(smart_str(stream_or_string)) - else: - stream = stream_or_string + stream_or_string = stream_or_string.decode('utf-8') try: - for obj in PythonDeserializer(json.load(stream), **options): + if isinstance(stream_or_string, basestring): + objects = json.loads(stream_or_string) + else: + objects = json.load(stream_or_string) + for obj in PythonDeserializer(objects, **options): yield obj except GeneratorExit: raise diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index e490b8607d..b639ad2dae 100644 --- a/django/core/serializers/pyyaml.py +++ b/django/core/serializers/pyyaml.py @@ -6,7 +6,7 @@ Requires PyYaml (http://pyyaml.org/), but that's checked for in __init__. import decimal import yaml -from io import BytesIO +from io import StringIO from django.db import models from django.core.serializers.base import DeserializationError @@ -51,9 +51,9 @@ def Deserializer(stream_or_string, **options): Deserialize a stream or string of YAML data. """ if isinstance(stream_or_string, bytes): - stream = BytesIO(stream_or_string) - if isinstance(stream_or_string, unicode): - stream = BytesIO(smart_str(stream_or_string)) + stream_or_string = stream_or_string.decode('utf-8') + if isinstance(stream_or_string, basestring): + stream = StringIO(stream_or_string) else: stream = stream_or_string try: