Ticket #15197: 15197-4.diff

File 15197-4.diff, 2.8 KB (added by Claude Paroz, 12 years ago)

Patch without HttpResponse.getvalue()

  • django/core/serializers/json.py

    diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
    index 937d839..941b9e0 100644
    a b class Serializer(PythonSerializer):  
    5252        self._current = None
    5353
    5454    def getvalue(self):
    55         # overwrite PythonSerializer.getvalue() with base Serializer.getvalue()
    56         if callable(getattr(self.stream, 'getvalue', None)):
    57             return self.stream.getvalue()
     55        # Grand-parent super
     56        return super(PythonSerializer, self).getvalue()
    5857
    5958
    6059def Deserializer(stream_or_string, **options):
  • django/core/serializers/pyyaml.py

    diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
    index b639ad2..73e92d5 100644
    a b class Serializer(PythonSerializer):  
    4444        yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
    4545
    4646    def getvalue(self):
    47         return self.stream.getvalue()
     47        # Grand-parent super
     48        return super(PythonSerializer, self).getvalue()
    4849
    4950def Deserializer(stream_or_string, **options):
    5051    """
  • tests/regressiontests/serializers_regress/tests.py

    diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
    index f1b70a1..4e73be0 100644
    a b from django.core import serializers  
    2121from django.core.serializers import SerializerDoesNotExist
    2222from django.core.serializers.base import DeserializationError
    2323from django.db import connection, models
     24from django.http import HttpResponse
    2425from django.test import TestCase
    2526from django.utils.functional import curry
    2627from django.utils.unittest import skipUnless
    def streamTest(format, self):  
    501502    obj.save_base(raw=True)
    502503
    503504    # Serialize the test database to a stream
    504     stream = BytesIO()
    505     serializers.serialize(format, [obj], indent=2, stream=stream)
    506 
    507     # Serialize normally for a comparison
    508     string_data = serializers.serialize(format, [obj], indent=2)
    509 
    510     # Check that the two are the same
    511     self.assertEqual(string_data, stream.getvalue())
    512     stream.close()
     505    for stream in (BytesIO(), HttpResponse()):
     506        serializers.serialize(format, [obj], indent=2, stream=stream)
     507
     508        # Serialize normally for a comparison
     509        string_data = serializers.serialize(format, [obj], indent=2)
     510
     511        # Check that the two are the same
     512        if isinstance(stream, BytesIO):
     513            self.assertEqual(string_data, stream.getvalue())
     514        else:
     515            self.assertEqual(string_data, stream.content)
     516        stream.close()
    513517
    514518for format in serializers.get_serializer_formats():
    515519    setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))
Back to Top