Fixed #5268: the YAML serializer now uses yaml.safe_dump() instead the plain yaml.dump(); this makes YAML dumps more portable, and also removes the crufty '!!python/unicode' business. Thanks, poelzi.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6891 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
35921e570b
commit
76b73ce725
|
@ -20,7 +20,7 @@ class Serializer(PythonSerializer):
|
||||||
def end_serialization(self):
|
def end_serialization(self):
|
||||||
self.options.pop('stream', None)
|
self.options.pop('stream', None)
|
||||||
self.options.pop('fields', None)
|
self.options.pop('fields', None)
|
||||||
yaml.dump(self.objects, self.stream, **self.options)
|
yaml.safe_dump(self.objects, self.stream, **self.options)
|
||||||
|
|
||||||
def getvalue(self):
|
def getvalue(self):
|
||||||
return self.stream.getvalue()
|
return self.stream.getvalue()
|
||||||
|
|
|
@ -218,3 +218,41 @@ None
|
||||||
3.4
|
3.4
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
||||||
|
try:
|
||||||
|
import yaml
|
||||||
|
__test__['YAML'] = """
|
||||||
|
# Create some data:
|
||||||
|
|
||||||
|
>>> articles = Article.objects.all().order_by("id")[:2]
|
||||||
|
>>> from django.core import serializers
|
||||||
|
|
||||||
|
# test if serial
|
||||||
|
|
||||||
|
>>> serialized = serializers.serialize("yaml", articles)
|
||||||
|
>>> print serialized
|
||||||
|
- fields:
|
||||||
|
author: 2
|
||||||
|
categories: [3, 1]
|
||||||
|
headline: Just kidding; I love TV poker
|
||||||
|
pub_date: 2006-06-16 11:00:00
|
||||||
|
model: serializers.article
|
||||||
|
pk: 1
|
||||||
|
- fields:
|
||||||
|
author: 1
|
||||||
|
categories: [2, 3]
|
||||||
|
headline: Time to reform copyright
|
||||||
|
pub_date: 2006-06-16 13:00:11
|
||||||
|
model: serializers.article
|
||||||
|
pk: 2
|
||||||
|
<BLANKLINE>
|
||||||
|
|
||||||
|
>>> obs = list(serializers.deserialize("yaml", serialized))
|
||||||
|
>>> for i in obs:
|
||||||
|
... print i
|
||||||
|
<DeserializedObject: Just kidding; I love TV poker>
|
||||||
|
<DeserializedObject: Time to reform copyright>
|
||||||
|
|
||||||
|
"""
|
||||||
|
except ImportError: pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue