Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #5268: the YAML serializer now uses yaml.safe_dump() instead th…

…e 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
  • Loading branch information...
commit 76b73ce72515678faff06b05dd585136fb0f5bf1 1 parent 35921e5
@jacobian jacobian authored
View
2  django/core/serializers/pyyaml.py
@@ -20,7 +20,7 @@ class Serializer(PythonSerializer):
def end_serialization(self):
self.options.pop('stream', 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):
return self.stream.getvalue()
View
38 tests/modeltests/serializers/models.py
@@ -218,3 +218,41 @@ class Score(models.Model):
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
+

0 comments on commit 76b73ce

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