Ticket #5268: yaml_patch.diff

File yaml_patch.diff, 1.6 KB (added by Daniel Poelzleithner, 17 years ago)

better patch. use safe_dump with tests

  • django/core/serializers/pyyaml.py

     
    2020    def end_serialization(self):
    2121        self.options.pop('stream', None)
    2222        self.options.pop('fields', None)
    23         yaml.dump(self.objects, self.stream, **self.options)
     23        yaml.safe_dump(self.objects, self.stream, **self.options)
    2424
    2525    def getvalue(self):
    2626        return self.stream.getvalue()
  • tests/modeltests/serializers/models.py

     
    2182183.4
    219219
    220220"""}
     221
     222try:
     223    import yaml
     224    __test__['YAML'] = """
     225# Create some data:
     226
     227>>> as = Article.objects.all().order_by("id")[:2]
     228>>> from django.core import serializers
     229
     230# test if serial
     231
     232>>> de = serializers.serialize("yaml", as)
     233>>> print de
     234- fields:
     235    author: 2
     236    categories: [3, 1]
     237    headline: Just kidding; I love TV poker
     238    pub_date: 2006-06-16 11:00:00
     239  model: serializers.article
     240  pk: 1
     241- fields:
     242    author: 1
     243    categories: [2, 3]
     244    headline: Time to reform copyright
     245    pub_date: 2006-06-16 13:00:11
     246  model: serializers.article
     247  pk: 2
     248<BLANKLINE>
     249
     250>>> obs = list(serializers.deserialize("yaml", de))
     251>>> for i in obs: print i
     252<DeserializedObject: Just kidding; I love TV poker>
     253<DeserializedObject: Time to reform copyright>
     254
     255"""
     256except ImportError: pass
     257   
Back to Top