Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3435 -- Fixed serializing to a file stream. Patch from SmileyC…

…hris.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5075 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e23ababb523a006dfb7ade8b304397ac5a4537f2 1 parent 74bab89
Malcolm Tredinnick authored April 25, 2007
6  django/core/serializers/base.py
@@ -105,9 +105,11 @@ def handle_m2m_field(self, obj, field):
105 105
 
106 106
     def getvalue(self):
107 107
         """
108  
-        Return the fully serialized queryset.
  108
+        Return the fully serialized queryset (or None if the output stream is
  109
+        not seekable).
109 110
         """
110  
-        return self.stream.getvalue()
  111
+        if callable(getattr(self.stream, 'getvalue', None)):
  112
+            return self.stream.getvalue()
111 113
 
112 114
 class Deserializer(object):
113 115
     """
13  django/core/serializers/json.py
@@ -17,9 +17,10 @@ class Serializer(PythonSerializer):
17 17
     """
18 18
     def end_serialization(self):
19 19
         simplejson.dump(self.objects, self.stream, cls=DateTimeAwareJSONEncoder, **self.options)
20  
-        
  20
+
21 21
     def getvalue(self):
22  
-        return self.stream.getvalue()
  22
+        if callable(getattr(self.stream, 'getvalue', None)):
  23
+            return self.stream.getvalue()
23 24
 
24 25
 def Deserializer(stream_or_string, **options):
25 26
     """
@@ -31,15 +32,15 @@ def Deserializer(stream_or_string, **options):
31 32
         stream = stream_or_string
32 33
     for obj in PythonDeserializer(simplejson.load(stream)):
33 34
         yield obj
34  
-        
  35
+
35 36
 class DateTimeAwareJSONEncoder(simplejson.JSONEncoder):
36 37
     """
37 38
     JSONEncoder subclass that knows how to encode date/time types
38 39
     """
39  
-    
40  
-    DATE_FORMAT = "%Y-%m-%d" 
  40
+
  41
+    DATE_FORMAT = "%Y-%m-%d"
41 42
     TIME_FORMAT = "%H:%M:%S"
42  
-    
  43
+
43 44
     def default(self, o):
44 45
         if isinstance(o, datetime.datetime):
45 46
             return o.strftime("%s %s" % (self.DATE_FORMAT, self.TIME_FORMAT))

0 notes on commit e23abab

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