def test_check_record_pack_unpack(self): oid = '0'*8 data = 'sample' reflist = ['1'*8, '2'*8] refs = ''.join(reflist) result=unpack_record(pack_record(oid, data, refs)) assert result[0] == oid assert result[1] == data assert split_oids(result[2]) == reflist assert split_oids('') == []
def gen_referring_oid_record(storage, referred_oid): """(storage:Storage, referred_oid:str) -> sequence([oid:str, record:str]) Generate oid, record pairs for all objects that include a reference to the `referred_oid`. """ for oid, record in storage.gen_oid_record(): if referred_oid in split_oids(unpack_record(record)[2]): yield oid, record
def get_reference_index(storage): """(storage:Storage) -> {oid:str : [referring_oid:str]} Return a full index giving the referring oids for each oid. This might be large. """ result = {} for oid, record in storage.gen_oid_record(): for ref in split_oids(unpack_record(record)[2]): result.setdefault(ref, []).append(oid) return result
def gen_reachable_records(): todo = [ROOT_OID] seen = set() while todo: oid = todo.pop() if oid in seen: continue seen.add(oid) record = self.load(oid) record_oid, data, refdata = unpack_record(record) assert oid == record_oid todo.extend(split_oids(refdata)) yield oid, record while self.pack_extra: oid = self.pack_extra.pop() yield oid, self.load(oid)