def check(Pickler): for proto in range(pickle.HIGHEST_PROTOCOL + 1): f = io.BytesIO() pickler = Pickler(f, proto) pickler.dump('abc') self.assertEqual(self.loads(f.getvalue()), 'abc') pickler = Pickler(io.BytesIO()) self.assertEqual(pickler.persistent_id('def'), 'def') r = weakref.ref(pickler) del pickler self.assertIsNone(r())
def __setitem__(self, key, value): if type(value) is dict: blue = Blue_dict(key, value, self, self) self.__vars__[key] = blue self.__blues__[key] = blue with open(f'{self.name}.blue', 'wb') as fp: p = Pickler(fp) p.dump(self) else: self.__vars__[key] = value with open(f'{self.name}.blue', 'wb') as fp: p = Pickler(fp) p.dump(self) self.__base_reload__()
def dump(self, obj): try: return Pickler.dump(self, obj) except RuntimeError as e: if "recursion" in e.args[0]: msg = ("Could not pickle object as excessively deep recursion " "required.") raise pickle.PicklingError(msg) else: raise
def saveturn(): filename = 'lastturn' if lexists(filename): file = open(filename, 'wb') else: file = open(filename, 'xb') saver = Pickler(file) saver.dump(summoners) saver.dump(teams) saver.dump(board) saver.dump(boardwidth) saver.dump(boardheight) saver.dump(modifiers) saver.dump(gamemods) saver.dump(whoseturn) saver.dump(phase) saver.dump(subphase) #cannot save action, because will give error with inner methods (like render). file.close()
def __delitem__(self, key): del self.__vars__[key] with open(f'{self.name}.blue', 'wb') as thing: p = Pickler(thing) p.dump(self) self.__base_reload__()