MCPcopy Index your code
hub / github.com/python/cpython / DBUnpickler

Class DBUnpickler

Doc/includes/dbpickle.py:26–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class DBUnpickler(pickle.Unpickler):
27
28 def __init__(self, file, connection):
29 super().__init__(file)
30 self.connection = connection
31
32 def persistent_load(self, pid):
33 # This method is invoked whenever a persistent ID is encountered.
34 # Here, pid is the tuple returned by DBPickler.
35 cursor = self.connection.cursor()
36 type_tag, key_id = pid
37 if type_tag == "MemoRecord":
38 # Fetch the referenced record from the database and return it.
39 cursor.execute("SELECT * FROM memos WHERE key=?", (str(key_id),))
40 key, task = cursor.fetchone()
41 return MemoRecord(key, task)
42 else:
43 # Always raises an error if you cannot return the correct object.
44 # Otherwise, the unpickler will think None is the object referenced
45 # by the persistent ID.
46 raise pickle.UnpicklingError("unsupported persistent object")
47
48
49def main():

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…