Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15197 -- Fixed yaml serialization into HttpResponse

Thanks fourga38 for the report and hirokiky at gmail.com for the
initial patch.
  • Loading branch information...
commit 26cb227cfe42d2500eac62dc0d90fb5227b275b3 1 parent 4f53e77
Claude Paroz authored June 28, 2012
5  django/core/serializers/json.py
@@ -52,9 +52,8 @@ def end_object(self, obj):
52 52
         self._current = None
53 53
 
54 54
     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()
58 57
 
59 58
 
60 59
 def Deserializer(stream_or_string, **options):
3  django/core/serializers/pyyaml.py
@@ -44,7 +44,8 @@ def end_serialization(self):
44 44
         yaml.dump(self.objects, self.stream, Dumper=DjangoSafeDumper, **self.options)
45 45
 
46 46
     def getvalue(self):
47  
-        return self.stream.getvalue()
  47
+        # Grand-parent super
  48
+        return super(PythonSerializer, self).getvalue()
48 49
 
49 50
 def Deserializer(stream_or_string, **options):
50 51
     """
22  tests/regressiontests/serializers_regress/tests.py
@@ -21,6 +21,7 @@
21 21
 from django.core.serializers import SerializerDoesNotExist
22 22
 from django.core.serializers.base import DeserializationError
23 23
 from django.db import connection, models
  24
+from django.http import HttpResponse
24 25
 from django.test import TestCase
25 26
 from django.utils.functional import curry
26 27
 from django.utils.unittest import skipUnless
@@ -501,15 +502,18 @@ def streamTest(format, self):
501 502
     obj.save_base(raw=True)
502 503
 
503 504
     # 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()
513 517
 
514 518
 for format in serializers.get_serializer_formats():
515 519
     setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format))

0 notes on commit 26cb227

Please sign in to comment.
Something went wrong with that request. Please try again.