summaryrefslogtreecommitdiff
path: root/django/core/serializers/pyyaml.py
diff options
context:
space:
mode:
authorJeremy Dunck <jdunck@gmail.com>2007-03-23 16:35:57 +0000
committerJeremy Dunck <jdunck@gmail.com>2007-03-23 16:35:57 +0000
commitfa3ed6e1341f7c8b468e2267b3fafddeb58cdac2 (patch)
tree6d8bf65854f8431355e2d91cbc61a37ab6f23d9a /django/core/serializers/pyyaml.py
parent8b279b63bef5c1348cc27c50633fc2d5ef09d7c1 (diff)
gis: Merged revisions 4669-4785 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@4786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/serializers/pyyaml.py')
-rw-r--r--django/core/serializers/pyyaml.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
new file mode 100644
index 0000000000..fa3dec984e
--- /dev/null
+++ b/django/core/serializers/pyyaml.py
@@ -0,0 +1,36 @@
+"""
+YAML serializer.
+
+Requires PyYaml (http://pyyaml.org/), but that's checked for in __init__.
+"""
+
+import datetime
+from django.core.serializers.python import Serializer as PythonSerializer
+from django.core.serializers.python import Deserializer as PythonDeserializer
+try:
+ from cStringIO import StringIO
+except ImportError:
+ from StringIO import StringIO
+import yaml
+
+class Serializer(PythonSerializer):
+ """
+ Convert a queryset to YAML.
+ """
+ def end_serialization(self):
+ yaml.dump(self.objects, self.stream, **self.options)
+
+ def getvalue(self):
+ return self.stream.getvalue()
+
+def Deserializer(stream_or_string, **options):
+ """
+ Deserialize a stream or string of YAML data.
+ """
+ if isinstance(stream_or_string, basestring):
+ stream = StringIO(stream_or_string)
+ else:
+ stream = stream_or_string
+ for obj in PythonDeserializer(yaml.load(stream)):
+ yield obj
+