Hi list,
I had an issue today where I needed to pickle a suds object. This is clearly not possible using pickle by itself, and I couldn't get copy_reg to dance either.
In the end, I ended up writing:
from suds.sudsobject import asdict, Object
def suds_pickle(sobject): begin = asdict(sobject)
for key, value in begin.iteritems(): if isinstance(value, Object): begin[key] = suds_pickle(value)
return begin
def suds_unpickle(fact, klass, dct): inst = fact.create(klass)
def fill(dct, pnt): for key, value in dct.iteritems(): if isinstance(value, dict): fill(value, getattr(pnt, key)) else: setattr(pnt, key, value)
fill(dct, inst)
return inst
Maybe someone will find it useful. suds_pickle returns a dict'ed version of an object recursively, and suds_unpickle takes 3 args: a factory, instance name and the dictionary from before.
It worked well enough for my purpose, but may need some improvement for larger things.
HTH,
Jesper Noehr