blob: 978c01e8ef4fed75b2940ccac8858b73f8c8f184 [file] [log] [blame]
Antoine Pitroud9dfaa92009-06-04 20:32:06 +00001# This module is used to map the old Python 2 names to the new names used in
2# Python 3 for the pickle module. This needed to make pickle streams
3# generated with Python 2 loadable by Python 3.
4
5# This is a copy of lib2to3.fixes.fix_imports.MAPPING. We cannot import
6# lib2to3 and use the mapping defined there, because lib2to3 uses pickle.
7# Thus, this could cause the module to be imported recursively.
8IMPORT_MAPPING = {
9 'StringIO': 'io',
10 'cStringIO': 'io',
11 'cPickle': 'pickle',
12 '__builtin__' : 'builtins',
13 'copy_reg': 'copyreg',
14 'Queue': 'queue',
15 'SocketServer': 'socketserver',
16 'ConfigParser': 'configparser',
17 'repr': 'reprlib',
18 'FileDialog': 'tkinter.filedialog',
19 'tkFileDialog': 'tkinter.filedialog',
20 'SimpleDialog': 'tkinter.simpledialog',
21 'tkSimpleDialog': 'tkinter.simpledialog',
22 'tkColorChooser': 'tkinter.colorchooser',
23 'tkCommonDialog': 'tkinter.commondialog',
24 'Dialog': 'tkinter.dialog',
25 'Tkdnd': 'tkinter.dnd',
26 'tkFont': 'tkinter.font',
27 'tkMessageBox': 'tkinter.messagebox',
28 'ScrolledText': 'tkinter.scrolledtext',
29 'Tkconstants': 'tkinter.constants',
30 'Tix': 'tkinter.tix',
31 'ttk': 'tkinter.ttk',
32 'Tkinter': 'tkinter',
33 'markupbase': '_markupbase',
34 '_winreg': 'winreg',
35 'thread': '_thread',
36 'dummy_thread': '_dummy_thread',
37 'dbhash': 'dbm.bsd',
38 'dumbdbm': 'dbm.dumb',
39 'dbm': 'dbm.ndbm',
40 'gdbm': 'dbm.gnu',
41 'xmlrpclib': 'xmlrpc.client',
42 'DocXMLRPCServer': 'xmlrpc.server',
43 'SimpleXMLRPCServer': 'xmlrpc.server',
44 'httplib': 'http.client',
45 'htmlentitydefs' : 'html.entities',
46 'HTMLParser' : 'html.parser',
47 'Cookie': 'http.cookies',
48 'cookielib': 'http.cookiejar',
49 'BaseHTTPServer': 'http.server',
50 'SimpleHTTPServer': 'http.server',
51 'CGIHTTPServer': 'http.server',
52 'test.test_support': 'test.support',
53 'commands': 'subprocess',
54 'UserString' : 'collections',
55 'UserList' : 'collections',
56 'urlparse' : 'urllib.parse',
57 'robotparser' : 'urllib.robotparser',
58 'whichdb': 'dbm',
59 'anydbm': 'dbm'
60}
61
62
63# This contains rename rules that are easy to handle. We ignore the more
64# complex stuff (e.g. mapping the names in the urllib and types modules).
65# These rules should be run before import names are fixed.
66NAME_MAPPING = {
67 ('__builtin__', 'xrange'): ('builtins', 'range'),
68 ('__builtin__', 'reduce'): ('functools', 'reduce'),
69 ('__builtin__', 'intern'): ('sys', 'intern'),
70 ('__builtin__', 'unichr'): ('builtins', 'chr'),
71 ('__builtin__', 'basestring'): ('builtins', 'str'),
72 ('__builtin__', 'long'): ('builtins', 'int'),
73 ('itertools', 'izip'): ('builtins', 'zip'),
74 ('itertools', 'imap'): ('builtins', 'map'),
75 ('itertools', 'ifilter'): ('builtins', 'filter'),
76 ('itertools', 'ifilterfalse'): ('itertools', 'filterfalse'),
77}
78
Walter Doerwald9d1dbca2013-12-02 11:41:01 +010079PYTHON2_EXCEPTIONS = (
80 "ArithmeticError",
81 "AssertionError",
82 "AttributeError",
83 "BaseException",
84 "BufferError",
85 "BytesWarning",
86 "DeprecationWarning",
87 "EOFError",
88 "EnvironmentError",
89 "Exception",
90 "FloatingPointError",
91 "FutureWarning",
92 "GeneratorExit",
93 "IOError",
94 "ImportError",
95 "ImportWarning",
96 "IndentationError",
97 "IndexError",
98 "KeyError",
99 "KeyboardInterrupt",
100 "LookupError",
101 "MemoryError",
102 "NameError",
103 "NotImplementedError",
104 "OSError",
105 "OverflowError",
106 "PendingDeprecationWarning",
107 "ReferenceError",
108 "RuntimeError",
109 "RuntimeWarning",
110 # StandardError is gone in Python 3, so we map it to Exception
111 "StopIteration",
112 "SyntaxError",
113 "SyntaxWarning",
114 "SystemError",
115 "SystemExit",
116 "TabError",
117 "TypeError",
118 "UnboundLocalError",
119 "UnicodeDecodeError",
120 "UnicodeEncodeError",
121 "UnicodeError",
122 "UnicodeTranslateError",
123 "UnicodeWarning",
124 "UserWarning",
125 "ValueError",
126 "Warning",
127 "ZeroDivisionError",
128)
129
130for excname in PYTHON2_EXCEPTIONS:
131 NAME_MAPPING[("exceptions", excname)] = ("builtins", excname)
132
133NAME_MAPPING[("exceptions", "StandardError")] = ("builtins", "Exception")
134
Antoine Pitroud9dfaa92009-06-04 20:32:06 +0000135# Same, but for 3.x to 2.x
136REVERSE_IMPORT_MAPPING = dict((v, k) for (k, v) in IMPORT_MAPPING.items())
137REVERSE_NAME_MAPPING = dict((v, k) for (k, v) in NAME_MAPPING.items())