Mixin for persisting an instance with pickle.
| 3 | |
| 4 | |
| 5 | class PickleWriteable: |
| 6 | """Mixin for persisting an instance with pickle.""" |
| 7 | |
| 8 | def save(self, path): |
| 9 | try: |
| 10 | with open(path, 'wb') as f: |
| 11 | pickle.dump(self, f) |
| 12 | except (pickle.PickleError, OSError) as e: |
| 13 | raise IOError('Unable to save {} to path: {}'.format(self.__class__.__name__, path)) from e |
| 14 | |
| 15 | @classmethod |
| 16 | def load(cls, path): |
| 17 | try: |
| 18 | with open(path, 'rb') as f: |
| 19 | return pickle.load(f) |
| 20 | except (pickle.PickleError, OSError) as e: |
| 21 | raise IOError('Unable to load {} from path: {}'.format(cls.__name__, path)) from e |
nothing calls this directly
no outgoing calls
no test coverage detected