| 1 |
""" |
| 2 |
This module is here to ensure compatibility of Windows/Linux/MacOS and |
| 3 |
different Python versions. |
| 4 |
""" |
| 5 |
import errno |
| 6 |
import sys |
| 7 |
import pickle |
| 8 |
from typing import Any |
| 9 |
|
| 10 |
|
| 11 |
class Unpickler(pickle.Unpickler): |
| 12 |
def find_class(self, module: str, name: str) -> Any: |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
if module == 'pathlib._local': |
| 19 |
module = 'pathlib' |
| 20 |
return super().find_class(module, name) |
| 21 |
|
| 22 |
|
| 23 |
def pickle_load(file): |
| 24 |
try: |
| 25 |
return Unpickler(file).load() |
| 26 |
|
| 27 |
|
| 28 |
except OSError: |
| 29 |
if sys.platform == 'win32': |
| 30 |
raise EOFError() |
| 31 |
raise |
| 32 |
|
| 33 |
|
| 34 |
def pickle_dump(data, file, protocol): |
| 35 |
try: |
| 36 |
pickle.dump(data, file, protocol) |
| 37 |
|
| 38 |
|
| 39 |
file.flush() |
| 40 |
|
| 41 |
|
| 42 |
except OSError: |
| 43 |
if sys.platform == 'win32': |
| 44 |
raise IOError(errno.EPIPE, "Broken pipe") |
| 45 |
raise |