def __init__(self, file, protocol=None, buffer_callback=None): if protocol is None: protocol = DEFAULT_PROTOCOL Pickler.__init__(self, file, protocol=protocol, buffer_callback=buffer_callback) # map functions __globals__ attribute ids, to ensure that functions # sharing the same global namespace at pickling time also share their # global namespace at unpickling time. self.globals_ref = {} # Take into account potential custom reducers registered by external # modules self.dispatch_table = copyreg.dispatch_table.copy() self.dispatch_table.update(self.dispatch) self.proto = int(protocol)
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