diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index 92159dbbe3..668bcb288a 100644 --- a/django/core/serializers/pyyaml.py +++ b/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() diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py index 1c7dbabfd1..0ccc19f895 100644 --- a/tests/modeltests/serializers/models.py +++ b/tests/modeltests/serializers/models.py @@ -218,3 +218,41 @@ None 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 + + +>>> obs = list(serializers.deserialize("yaml", serialized)) +>>> for i in obs: +... print i + + + +""" +except ImportError: pass +