def _write_index(self, fp, index): index_offset = fp.tell() compressed = compress(dumps(index)) write_int8_str(fp, compressed) fp.seek(len(self.MAGIC)) write_int8(fp, index_offset) assert fp.tell() == len(self.MAGIC) + 8
position = self.sio.tell() self.pickler.dump(obj.__getstate__()) uncompressed = self.sio.getvalue() pickled_type = uncompressed[:position] pickled_state = uncompressed[position:] if WRITE_COMPRESSED_STATE_PICKLES: state = compress(pickled_state) else: state = pickled_state data = pickled_type + state self.refs.discard(obj._p_oid) return data, join_bytes(self.refs) COMPRESSED_START_BYTE = compress(dumps({}, 2))[0] class ObjectReader (object): def __init__(self, connection): self.connection = connection self.load_count = 0 def _get_unpickler(self, file): connection = self.connection get_instance = connection.get_cache().get_instance def persistent_load(oid_klass): oid, klass = oid_klass return get_instance(oid, klass, connection) unpickler = Unpickler(file) unpickler.persistent_load = persistent_load
def pickling(self): a = Persistent() pickle_a = dumps(a, 2) b = loads(pickle_a) assert isinstance(b, Persistent)
def pickling(self): a = SlottedPersistentObjectWithDict() pickle_a = dumps(a, 2) b = loads(pickle_a) assert isinstance(b, SlottedPersistentObjectWithDict)
def test_pickling(self): a = PersistentObject() pickle_a = dumps(a, 2) b = loads(pickle_a) assert isinstance(b, PersistentObject)
self.refs.clear() position = self.sio.tell() self.pickler.dump(obj.__getstate__()) uncompressed = self.sio.getvalue() pickled_type = uncompressed[:position] pickled_state = uncompressed[position:] if WRITE_COMPRESSED_STATE_PICKLES: state = compress(pickled_state) else: state = pickled_state data = pickled_type + state self.refs.discard(obj._p_oid) return data, join_bytes(self.refs) COMPRESSED_START_BYTE = compress(dumps({}, 2))[0] class ObjectReader(object): def __init__(self, connection): self.connection = connection self.load_count = 0 def _get_unpickler(self, file): connection = self.connection get_instance = connection.get_cache().get_instance def persistent_load(oid_klass): oid, klass = oid_klass return get_instance(oid, klass, connection)