From 76b73ce72515678faff06b05dd585136fb0f5bf1 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 4 Dec 2007 20:31:34 +0000 Subject: [PATCH] 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 --- django/core/serializers/pyyaml.py | 2 +- tests/modeltests/serializers/models.py | 38 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index 92159dbbe3e..668bcb288aa 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 1c7dbabfd1e..0ccc19f895c 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 +