diff options
author | Walter Doerwald <walter@livinglogic.de> | 2013-12-02 10:41:01 (GMT) |
---|---|---|
committer | Walter Doerwald <walter@livinglogic.de> | 2013-12-02 10:41:01 (GMT) |
commit | 9d1dbca5e2f6f75577ad4ea29514a4eabc38e913 (patch) | |
tree | 211fab21bb2ee5641253dbf0d735251f068073ab /Lib/_compat_pickle.py | |
parent | 708a3182c931ff1b6e8a420f87929d143822de28 (diff) | |
download | cpython-9d1dbca5e2f6f75577ad4ea29514a4eabc38e913.zip cpython-9d1dbca5e2f6f75577ad4ea29514a4eabc38e913.tar.gz cpython-9d1dbca5e2f6f75577ad4ea29514a4eabc38e913.tar.bz2 |
Fix issue #19834: Support unpickling of exceptions pickled by Python 2.
Diffstat (limited to 'Lib/_compat_pickle.py')
-rw-r--r-- | Lib/_compat_pickle.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/_compat_pickle.py b/Lib/_compat_pickle.py index 700c80c..978c01e 100644 --- a/Lib/_compat_pickle.py +++ b/Lib/_compat_pickle.py @@ -76,6 +76,62 @@ NAME_MAPPING = { ('itertools', 'ifilterfalse'): ('itertools', 'filterfalse'), } +PYTHON2_EXCEPTIONS = ( + "ArithmeticError", + "AssertionError", + "AttributeError", + "BaseException", + "BufferError", + "BytesWarning", + "DeprecationWarning", + "EOFError", + "EnvironmentError", + "Exception", + "FloatingPointError", + "FutureWarning", + "GeneratorExit", + "IOError", + "ImportError", + "ImportWarning", + "IndentationError", + "IndexError", + "KeyError", + "KeyboardInterrupt", + "LookupError", + "MemoryError", + "NameError", + "NotImplementedError", + "OSError", + "OverflowError", + "PendingDeprecationWarning", + "ReferenceError", + "RuntimeError", + "RuntimeWarning", + # StandardError is gone in Python 3, so we map it to Exception + "StopIteration", + "SyntaxError", + "SyntaxWarning", + "SystemError", + "SystemExit", + "TabError", + "TypeError", + "UnboundLocalError", + "UnicodeDecodeError", + "UnicodeEncodeError", + "UnicodeError", + "UnicodeTranslateError", + "UnicodeWarning", + "UserWarning", + "ValueError", + "Warning", + "ZeroDivisionError", +) + +for excname in PYTHON2_EXCEPTIONS: + NAME_MAPPING[("exceptions", excname)] = ("builtins", excname) + +NAME_MAPPING[("exceptions", "StandardError")] = ("builtins", "Exception") + # Same, but for 3.x to 2.x REVERSE_IMPORT_MAPPING = dict((v, k) for (k, v) in IMPORT_MAPPING.items()) REVERSE_NAME_MAPPING = dict((v, k) for (k, v) in NAME_MAPPING.items()) |