def _toObject(d): """ """ typeName = d.get(TYPENAME, None) if typeName is None: raise Exception("bad object") try: typeClass = classRegistry[typeName] except KeyError: raise o = typeClass(_do_not_finalize=True) #print o #print d #print d['lastName'] for name, attribute in getNamedAttributes(typeClass, recurse=True): try: v = d[attribute.name] setattr(o, name, _toPyval(attribute, v)) except AttributeError: raise o._id = d[ID] try: loadfn = o.__load__ except AttributeError: pass else: loadfn() o._finalize() return o
def _fromObject(typeClass, pyval): d = {} for name, attribute in getNamedAttributes(typeClass, True): try: d[attribute.name] = _fromPyval(attribute, getattr(pyval, name)) except AttributeError: pass if not d.has_key(ID): try: d[ID] = pyval._id except AttributeError: pass d[TYPENAME] = typeClass.__typename__ return d