summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-06-28 16:28:25 +0200
committerClaude Paroz <claude@2xlibre.net>2012-06-28 16:29:29 +0200
commit26cb227cfe42d2500eac62dc0d90fb5227b275b3 (patch)
treee2a6a3e8a376ed8f8d47945957bdc10821d3f7dd
parent4f53e77f0720bd4d74b1b08857db8f7d32c65008 (diff)
Fixed #15197 -- Fixed yaml serialization into HttpResponse
Thanks fourga38 for the report and hirokiky at gmail.com for the initial patch.
-rw-r--r--django/core/serializers/json.py5
-rw-r--r--django/core/serializers/pyyaml.py3
-rw-r--r--tests/regressiontests/serializers_regress/tests.py18
3 files changed, 15 insertions, 11 deletions
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 937d839239..941b9e0ba8 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -52,9 +52,8 @@ class Serializer(PythonSerializer):
self._current = None
def getvalue(self):
- # overwrite PythonSerializer.getvalue() with base Serializer.getvalue()
- if callable(getattr(self.stream, 'getvalue', None)):
- return self.stream.getvalue()
+ # Grand-parent super
+ return super(PythonSerializer, self).getvalue()
def Deserializer(stream_or_string, **options):
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
index b639ad2dae..73e92d557f 100644
--- a/django/core/serializers/pyyaml.py
+++ b/django/core/serializers/pyyaml.py
@@ -44,7 +44,8 @@ class Serializer(PythonSerializer):
yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
def getvalue(self):
- return self.stream.getvalue()
+ # Grand-parent super
+ return super(PythonSerializer, self).getvalue()
def Deserializer(stream_or_string, **options):
"""
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index f1b70a1d2e..4e73be015c 100644
--- a/tests/regressiontests/serializers_regress/tests.py
+++ b/tests/regressiontests/serializers_regress/tests.py
@@ -21,6 +21,7 @@ from django.core import serializers
from django.core.serializers import SerializerDoesNotExist
from django.core.serializers.base import DeserializationError
from django.db import connection, models
+from django.http import HttpResponse
from django.test import TestCase
from django.utils.functional import curry
from django.utils.unittest import skipUnless
@@ -501,15 +502,18 @@ def streamTest(format, self):
obj.save_base(raw=True)
# Serialize the test database to a stream
- stream = BytesIO()
- serializers.serialize(format, [obj], indent=2, stream=stream)
+ for stream in (BytesIO(), HttpResponse()):
+ serializers.serialize(format, [obj], indent=2, stream=stream)
- # Serialize normally for a comparison
- string_data = serializers.serialize(format, [obj], indent=2)
+ # Serialize normally for a comparison
+ string_data = serializers.serialize(format, [obj], indent=2)
- # Check that the two are the same
- self.assertEqual(string_data, stream.getvalue())
- stream.close()
+ # Check that the two are the same
+ if isinstance(stream, BytesIO):
+ self.assertEqual(string_data, stream.getvalue())
+ else:
+ self.assertEqual(string_data, stream.content)
+ stream.close()
for format in serializers.get_serializer_formats():
setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))