def referencesf(p, oids=None): """Return a list of object ids found in a pickle A list may be passed in, in which case, information is appended to it. Only ordinary internal references are included. Weak and multi-database references are not included. """ refs = [] u = Unpickler(BytesIO(p)) u.persistent_load = refs.append u.noload() u.noload() # Now we have a list of referencs. Need to convert to list of # oids: if oids is None: oids = [] for reference in refs: if isinstance(reference, tuple): oid = reference[0] elif isinstance(reference, (bytes, str)): oid = reference else: assert isinstance(reference, list) continue if not isinstance(oid, bytes): assert isinstance(oid, str) # this happens on Python 3 when all bytes in the oid are < 0x80 oid = oid.encode("ascii") oids.append(oid) return oids
def referencesf(p, oids=None): """Return a list of object ids found in a pickle A list may be passed in, in which case, information is appended to it. Only ordinary internal references are included. Weak and multi-database references are not included. """ refs = [] u = Unpickler(BytesIO(p)) u.persistent_load = refs.append u.noload() u.noload() # Now we have a list of referencs. Need to convert to list of # oids: if oids is None: oids = [] for reference in refs: if isinstance(reference, tuple): oid = reference[0] elif isinstance(reference, (bytes, str)): oid = reference else: assert isinstance(reference, list) continue if not isinstance(oid, bytes): assert isinstance(oid, str) # this happens on Python 3 when all bytes in the oid are < 0x80 oid = oid.encode('ascii') oids.append(oid) return oids
def get_refs(a_pickle): """Return oid and class information for references in a pickle The result of a list of oid and class information tuples. If the reference doesn't contain class information, then the klass information is None. """ refs = [] u = Unpickler(BytesIO(a_pickle)) u.persistent_load = refs.append u.noload() u.noload() # Now we have a list of references. Need to convert to list of # oids and class info: result = [] for reference in refs: if isinstance(reference, tuple): oid, klass = reference elif isinstance(reference, (bytes, str)): data, klass = reference, None else: assert isinstance(reference, list) continue if not isinstance(oid, bytes): assert isinstance(oid, str) # this happens on Python 3 when all bytes in the oid are < 0x80 oid = oid.encode("ascii") result.append((oid, klass)) return result
def get_refs(a_pickle): """Return oid and class information for references in a pickle The result of a list of oid and class information tuples. If the reference doesn't contain class information, then the klass information is None. """ refs = [] u = Unpickler(BytesIO(a_pickle)) u.persistent_load = refs.append u.noload() u.noload() # Now we have a list of references. Need to convert to list of # oids and class info: result = [] for reference in refs: if isinstance(reference, tuple): oid, klass = reference elif isinstance(reference, (bytes, str)): data, klass = reference, None else: assert isinstance(reference, list) continue if not isinstance(oid, bytes): assert isinstance(oid, str) # this happens on Python 3 when all bytes in the oid are < 0x80 oid = oid.encode('ascii') result.append((oid, klass)) return result