Utility method to generate the many possible pickle configurations.
()
| 5741 | |
| 5742 | @staticmethod |
| 5743 | def _generate_pickle_copiers(): |
| 5744 | """Utility method to generate the many possible pickle configurations. |
| 5745 | """ |
| 5746 | class PickleCopier: |
| 5747 | "This class copies object using pickle." |
| 5748 | def __init__(self, proto, dumps, loads): |
| 5749 | self.proto = proto |
| 5750 | self.dumps = dumps |
| 5751 | self.loads = loads |
| 5752 | def copy(self, obj): |
| 5753 | return self.loads(self.dumps(obj, self.proto)) |
| 5754 | def __repr__(self): |
| 5755 | # We try to be as descriptive as possible here since this is |
| 5756 | # the string which we will allow us to tell the pickle |
| 5757 | # configuration we are using during debugging. |
| 5758 | return ("PickleCopier(proto={}, dumps={}.{}, loads={}.{})" |
| 5759 | .format(self.proto, |
| 5760 | self.dumps.__module__, self.dumps.__qualname__, |
| 5761 | self.loads.__module__, self.loads.__qualname__)) |
| 5762 | return (PickleCopier(*args) for args in |
| 5763 | itertools.product(range(pickle.HIGHEST_PROTOCOL + 1), |
| 5764 | {pickle.dumps, pickle._dumps}, |
| 5765 | {pickle.loads, pickle._loads})) |
| 5766 | |
| 5767 | @support.thread_unsafe |
| 5768 | def test_pickle_slots(self): |
no test coverage detected