]>
Commit | Line | Data |
---|---|---|
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 | ||
9 | ||
10 | def pickle_load(file): | |
11 | try: | |
12 | return pickle.load(file) | |
13 | # Python on Windows don't throw EOF errors for pipes. So reraise them with | |
14 | # the correct type, which is caught upwards. | |
15 | except OSError: | |
16 | if sys.platform == 'win32': | |
17 | raise EOFError() | |
18 | raise | |
19 | ||
20 | ||
21 | def pickle_dump(data, file, protocol): | |
22 | try: | |
23 | pickle.dump(data, file, protocol) | |
24 | # On Python 3.3 flush throws sometimes an error even though the writing | |
25 | # operation should be completed. | |
26 | file.flush() | |
27 | # Python on Windows don't throw EPIPE errors for pipes. So reraise them with | |
28 | # the correct type and error number. | |
29 | except OSError: | |
30 | if sys.platform == 'win32': | |
31 | raise IOError(errno.EPIPE, "Broken pipe") | |
32 | raise |