def save_inst(self, obj): """Inner logic to save instance. Based off pickle.save_inst Supports __transient__""" cls = obj.__class__ # Try the dispatch table (pickle module doesn't do it) f = self.dispatch.get(cls) if f: f(self, obj) # Call unbound method with explicit self return memo = self.memo write = self.write save = self.save if hasattr(obj, '__getinitargs__'): args = obj.__getinitargs__() len(args) # XXX Assert it's a sequence pickle._keep_alive(args, memo) else: args = () write(pickle.MARK) if self.bin: save(cls) for arg in args: save(arg) write(pickle.OBJ) else: for arg in args: save(arg) write(pickle.INST + cls.__module__ + '\n' + cls.__name__ + '\n') self.memoize(obj) try: getstate = obj.__getstate__ except AttributeError: stuff = obj.__dict__ #remove items if transient if hasattr(obj, '__transient__'): transient = obj.__transient__ stuff = stuff.copy() for k in list(stuff.keys()): if k in transient: del stuff[k] else: stuff = getstate() pickle._keep_alive(stuff, memo) save(stuff) write(pickle.BUILD)
def save_inst_logic(self, obj): """Inner logic to save instance. Based off pickle.save_inst Supports __transient__""" cls = obj.__class__ memo = self.memo write = self.write save = self.save if hasattr(obj, '__getinitargs__'): args = obj.__getinitargs__() len(args) # XXX Assert it's a sequence pickle._keep_alive(args, memo) else: args = () write(pickle.MARK) if self.bin: save(cls) for arg in args: save(arg) write(pickle.OBJ) else: for arg in args: save(arg) write(pickle.INST + cls.__module__ + '\n' + cls.__name__ + '\n') self.memoize(obj) try: getstate = obj.__getstate__ except AttributeError: stuff = obj.__dict__ #remove items if transient if hasattr(obj, '__transient__'): transient = obj.__transient__ stuff = stuff.copy() for k in list(stuff.keys()): if k in transient: del stuff[k] else: stuff = getstate() pickle._keep_alive(stuff, memo) save(stuff) write(pickle.BUILD)
def save_inst(self, obj): """Inner logic to save instance. Based off pickle.save_inst Supports __transient__""" cls = obj.__class__ memo = self.memo write = self.write save = self.save if hasattr(obj, '__getinitargs__'): args = obj.__getinitargs__() len(args) # assert it's a sequence pickle._keep_alive(args, memo) # pylint: disable=protected-access else: args = () write(pickle.MARK) if self.bin: save(cls) for arg in args: save(arg) write(pickle.OBJ) else: for arg in args: save(arg) write(pickle.INST + cls.__module__ + '\n' + cls.__name__ + '\n') self.memoize(obj) try: getstate = obj.__getstate__ except AttributeError: stuff = obj.__dict__ #remove items if transient if hasattr(obj, '__transient__'): transient = obj.__transient__ stuff = stuff.copy() for k in list(stuff.keys()): if k in transient: del stuff[k] else: stuff = getstate() pickle._keep_alive(stuff, memo) # pylint: disable=protected-access save(stuff) write(pickle.BUILD)
def save_inst(self, obj): """Inner logic to save instance. Based off pickle.save_inst""" cls = obj.__class__ # Try the dispatch table (pickle module doesn't do it) f = self.dispatch.get(cls) if f: f(self, obj) # Call unbound method with explicit self return memo = self.memo write = self.write save = self.save if hasattr(obj, '__getinitargs__'): args = obj.__getinitargs__() len(args) # XXX Assert it's a sequence pickle._keep_alive(args, memo) else: args = () write(pickle.MARK) if self.bin: save(cls) for arg in args: save(arg) write(pickle.OBJ) else: for arg in args: save(arg) write(pickle.INST + cls.__module__ + '\n' + cls.__name__ + '\n') self.memoize(obj) try: getstate = obj.__getstate__ except AttributeError: stuff = obj.__dict__ else: stuff = getstate() pickle._keep_alive(stuff, memo) save(stuff) write(pickle.BUILD)
def _state_instance(self, obj): md = obj.__METADATA__ cls = md.get('class') cls_md = cls.__METADATA__ memo = self.memo write = self.write save = self.save args = md.get('initargs') if len(args) > 0: _keep_alive(args, memo) write(MARK) if self.bin: save(cls) for arg in args: save(arg) write(OBJ) else: for arg in args: save(arg) write(INST + cls_md.get('module') + '\n' + cls_md.get('name') + '\n') self.memoize(obj) stuff = dict(obj.__dict__) stuff.pop('__METADATA__') if '__setstate_data__' in stuff: data = stuff.pop('__setstate_data__') _keep_alive(data, memo) save(data) else: save(stuff) write(BUILD)