blob: da4c684588288a876f2423778b65f6eb34420c7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# Michael DeHaan <mdehaan@redhat.com>
import syck # PySyck 0.61 or greater, not syck-python 0.55
import msg
def serialize(obj):
if obj.filename() is None:
raise Exception("not serializable")
fd = open(obj.filename(),"w+")
datastruct = obj.to_datastruct()
encoded = syck.dump(datastruct)
fd.write(encoded)
fd.close()
return True
def deserialize(obj):
if obj.filename() is None:
raise Exception("not serializable")
try:
fd = open(obj.filename(),"r")
except:
print msg.m("parse_error") % obj.filename()
return
data = fd.read()
datastruct = syck.load(data)
fd.close()
obj.from_datastruct(datastruct)
return True
|