Esempio n. 1
0
 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
Esempio n. 2
0
        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
Esempio n. 3
0
 def pickling(self):
     a = Persistent()
     pickle_a = dumps(a, 2)
     b = loads(pickle_a)
     assert isinstance(b, Persistent)
Esempio n. 4
0
 def pickling(self):
     a = SlottedPersistentObjectWithDict()
     pickle_a = dumps(a, 2)
     b = loads(pickle_a)
     assert isinstance(b, SlottedPersistentObjectWithDict)
Esempio n. 5
0
 def pickling(self):
     a = Persistent()
     pickle_a = dumps(a, 2)
     b = loads(pickle_a)
     assert isinstance(b, Persistent)
Esempio n. 6
0
 def pickling(self):
     a = SlottedPersistentObjectWithDict()
     pickle_a = dumps(a, 2)
     b = loads(pickle_a)
     assert isinstance(b, SlottedPersistentObjectWithDict)
Esempio n. 7
0
 def test_pickling(self):
     a = PersistentObject()
     pickle_a = dumps(a, 2)
     b = loads(pickle_a)
     assert isinstance(b, PersistentObject)
Esempio n. 8
0
        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)