Ticket #15197: 15197-3.diff

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

Alternative patch

  • 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    """
  • django/http/__init__.py

    diff --git a/django/http/__init__.py b/django/http/__init__.py
    index 30d7e5d..39f7a27 100644
    a b class HttpResponse(object):  
    675675            chunk = chunk.encode(self._charset)
    676676        return str(chunk)
    677677
     678    def getvalue(self):
     679        return self.content
     680
    678681    def close(self):
    679682        if hasattr(self._container, 'close'):
    680683            self._container.close()
  • tests/regressiontests/serializers_regress/tests.py

    diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
    index f1b70a1..468b51f 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)
     505    for stream in (BytesIO(), HttpResponse()):
     506        serializers.serialize(format, [obj], indent=2, stream=stream)
    506507
    507     # Serialize normally for a comparison
    508     string_data = serializers.serialize(format, [obj], indent=2)
     508        # Serialize normally for a comparison
     509        string_data = serializers.serialize(format, [obj], indent=2)
    509510
    510     # Check that the two are the same
    511     self.assertEqual(string_data, stream.getvalue())
    512     stream.close()
     511        # Check that the two are the same
     512        self.assertEqual(string_data, stream.getvalue())
     513        stream.close()
    513514
    514515for format in serializers.get_serializer_formats():
    515516    setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))
Back to Top