Ticket #11970: 11970-with-test2.diff

File 11970-with-test2.diff, 2.1 KB (added by Claude Paroz, 13 years ago)

Fixed missing options parameter

  • django/core/serializers/json.py

    diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
    index b8119f5..8d0e7d2 100644
    a b from StringIO import StringIO  
    88
    99from django.core.serializers.python import Serializer as PythonSerializer
    1010from django.core.serializers.python import Deserializer as PythonDeserializer
     11from django.core.serializers import base
    1112from django.utils import datetime_safe
    1213from django.utils import simplejson
    1314
    class Serializer(PythonSerializer):  
    2425        if callable(getattr(self.stream, 'getvalue', None)):
    2526            return self.stream.getvalue()
    2627
     28
    2729def Deserializer(stream_or_string, **options):
    2830    """
    2931    Deserialize a stream or string of JSON data.
    def Deserializer(stream_or_string, **options):  
    3234        stream = StringIO(stream_or_string)
    3335    else:
    3436        stream = stream_or_string
    35     for obj in PythonDeserializer(simplejson.load(stream), **options):
    36         yield obj
     37    try:
     38        for obj in PythonDeserializer(simplejson.load(stream), **options):
     39            yield obj
     40    except ValueError, e:
     41        # Map to deserializer error
     42        raise base.DeserializationError(e.args)
     43
    3744
    3845class DjangoJSONEncoder(simplejson.JSONEncoder):
    3946    """
  • tests/regressiontests/serializers_regress/tests.py

    diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
    index 97b2a79..24a149b 100644
    a b class SerializerTests(TestCase):  
    374374        with self.assertRaises(SerializerDoesNotExist):
    375375            serializers.get_deserializer("nonsense")
    376376
     377    def test_json_deserializer_exception(self):
     378        from django.core.serializers import base
     379        with self.assertRaises(base.DeserializationError):
     380            data = serializers.deserialize("json", """[{"pk":1}""")
     381            for obj in data:
     382                pass
     383
    377384def serializerTest(format, self):
    378385
    379386    # Create all the objects defined in the test data
Back to Top