def __new__(self, name, bases, cdict, _p_changed=False): # _p_changed will be None if we are being loaded from the # database, because __getnewargs__ returns an extra argument # for _p_changed. # The above is *not* true for old (< 2.8) ZClass code. # Old ZClass records have all of their data in their # arguments. This is rather fortunate. It means that # we don't need to call __setstate__. We *do*, however, need # to call pmc_init_of. cdict = dict([(k, v) for (k, v) in cdict.items() if not k.startswith('_p_')]) cdict['_p_class_dict'] = {'_p_changed': _p_changed} result = super(ZClassPersistentMetaClass, self ).__new__(self, name, bases, cdict) ExtensionClass.pmc_init_of(result) return result
def __setstate__(self, state): try: self.__bases__, cdict = state except TypeError: # Maybe an old ZClass with state == None if state is None: cdict = None if cdict is not None: cdict = dict([(k, v) for (k, v) in cdict.items() if not k.startswith('_p_')]) _p_class_dict = self._p_class_dict self._p_class_dict = {} to_remove = [ k for k in self.__dict__ if ((k not in cdict) and (k not in ZODB.persistentclass.special_class_descrs) and (k != '_p_class_dict') )] for k in to_remove: delattr(self, k) try: del cdict['__slotnames__'] except KeyError: pass for k, v in cdict.items(): setattr(self, k, v) self._p_class_dict = _p_class_dict ExtensionClass.pmc_init_of(self) self._p_changed = False