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

Class DBPickler

Doc/includes/dbpickle.py:11–23  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9MemoRecord = namedtuple("MemoRecord", "key, task")
10
11class DBPickler(pickle.Pickler):
12
13 def persistent_id(self, obj):
14 # Instead of pickling MemoRecord as a regular class instance, we emit a
15 # persistent ID.
16 if isinstance(obj, MemoRecord):
17 # Here, our persistent ID is simply a tuple, containing a tag and a
18 # key, which refers to a specific record in the database.
19 return ("MemoRecord", obj.key)
20 else:
21 # If obj does not have a persistent ID, return None. This means obj
22 # needs to be pickled as usual.
23 return None
24
25
26class DBUnpickler(pickle.Unpickler):

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…