How to deserialize an object with pyYaml using safe_load?

Posted by systempuntoout on Stack Overflow See other posts from Stack Overflow or by systempuntoout
Published on 2010-04-13T06:52:41Z Indexed on 2010/05/22 23:10 UTC
Read the original article Hit count: 389

Filed under:
|

Having a snippet like this:

import yaml
class User(object):
    def __init__(self, name, surname):
       self.name= name
       self.surname= surname

user = User('spam', 'eggs')
serialized_user = yaml.dump(user)
#Network
deserialized_user = yaml.load(serialized_user)
print "name: %s, sname: %s" % (deserialized_user.name, deserialized_user.surname)

Yaml docs says that it is not safe to call yaml.load with any data received from an untrusted source; so, what do i need to modify to my snippet\class to use safe_load method?
Is it possible?

© Stack Overflow or respective owner

Related posts about python

Related posts about pyyaml