1 | n/a | # This module is used to map the old Python 2 names to the new names used in |
---|
2 | n/a | # Python 3 for the pickle module. This needed to make pickle streams |
---|
3 | n/a | # generated with Python 2 loadable by Python 3. |
---|
4 | n/a | |
---|
5 | n/a | # This is a copy of lib2to3.fixes.fix_imports.MAPPING. We cannot import |
---|
6 | n/a | # lib2to3 and use the mapping defined there, because lib2to3 uses pickle. |
---|
7 | n/a | # Thus, this could cause the module to be imported recursively. |
---|
8 | n/a | IMPORT_MAPPING = { |
---|
9 | n/a | '__builtin__' : 'builtins', |
---|
10 | n/a | 'copy_reg': 'copyreg', |
---|
11 | n/a | 'Queue': 'queue', |
---|
12 | n/a | 'SocketServer': 'socketserver', |
---|
13 | n/a | 'ConfigParser': 'configparser', |
---|
14 | n/a | 'repr': 'reprlib', |
---|
15 | n/a | 'tkFileDialog': 'tkinter.filedialog', |
---|
16 | n/a | 'tkSimpleDialog': 'tkinter.simpledialog', |
---|
17 | n/a | 'tkColorChooser': 'tkinter.colorchooser', |
---|
18 | n/a | 'tkCommonDialog': 'tkinter.commondialog', |
---|
19 | n/a | 'Dialog': 'tkinter.dialog', |
---|
20 | n/a | 'Tkdnd': 'tkinter.dnd', |
---|
21 | n/a | 'tkFont': 'tkinter.font', |
---|
22 | n/a | 'tkMessageBox': 'tkinter.messagebox', |
---|
23 | n/a | 'ScrolledText': 'tkinter.scrolledtext', |
---|
24 | n/a | 'Tkconstants': 'tkinter.constants', |
---|
25 | n/a | 'Tix': 'tkinter.tix', |
---|
26 | n/a | 'ttk': 'tkinter.ttk', |
---|
27 | n/a | 'Tkinter': 'tkinter', |
---|
28 | n/a | 'markupbase': '_markupbase', |
---|
29 | n/a | '_winreg': 'winreg', |
---|
30 | n/a | 'thread': '_thread', |
---|
31 | n/a | 'dummy_thread': '_dummy_thread', |
---|
32 | n/a | 'dbhash': 'dbm.bsd', |
---|
33 | n/a | 'dumbdbm': 'dbm.dumb', |
---|
34 | n/a | 'dbm': 'dbm.ndbm', |
---|
35 | n/a | 'gdbm': 'dbm.gnu', |
---|
36 | n/a | 'xmlrpclib': 'xmlrpc.client', |
---|
37 | n/a | 'SimpleXMLRPCServer': 'xmlrpc.server', |
---|
38 | n/a | 'httplib': 'http.client', |
---|
39 | n/a | 'htmlentitydefs' : 'html.entities', |
---|
40 | n/a | 'HTMLParser' : 'html.parser', |
---|
41 | n/a | 'Cookie': 'http.cookies', |
---|
42 | n/a | 'cookielib': 'http.cookiejar', |
---|
43 | n/a | 'BaseHTTPServer': 'http.server', |
---|
44 | n/a | 'test.test_support': 'test.support', |
---|
45 | n/a | 'commands': 'subprocess', |
---|
46 | n/a | 'urlparse' : 'urllib.parse', |
---|
47 | n/a | 'robotparser' : 'urllib.robotparser', |
---|
48 | n/a | 'urllib2': 'urllib.request', |
---|
49 | n/a | 'anydbm': 'dbm', |
---|
50 | n/a | '_abcoll' : 'collections.abc', |
---|
51 | n/a | } |
---|
52 | n/a | |
---|
53 | n/a | |
---|
54 | n/a | # This contains rename rules that are easy to handle. We ignore the more |
---|
55 | n/a | # complex stuff (e.g. mapping the names in the urllib and types modules). |
---|
56 | n/a | # These rules should be run before import names are fixed. |
---|
57 | n/a | NAME_MAPPING = { |
---|
58 | n/a | ('__builtin__', 'xrange'): ('builtins', 'range'), |
---|
59 | n/a | ('__builtin__', 'reduce'): ('functools', 'reduce'), |
---|
60 | n/a | ('__builtin__', 'intern'): ('sys', 'intern'), |
---|
61 | n/a | ('__builtin__', 'unichr'): ('builtins', 'chr'), |
---|
62 | n/a | ('__builtin__', 'unicode'): ('builtins', 'str'), |
---|
63 | n/a | ('__builtin__', 'long'): ('builtins', 'int'), |
---|
64 | n/a | ('itertools', 'izip'): ('builtins', 'zip'), |
---|
65 | n/a | ('itertools', 'imap'): ('builtins', 'map'), |
---|
66 | n/a | ('itertools', 'ifilter'): ('builtins', 'filter'), |
---|
67 | n/a | ('itertools', 'ifilterfalse'): ('itertools', 'filterfalse'), |
---|
68 | n/a | ('itertools', 'izip_longest'): ('itertools', 'zip_longest'), |
---|
69 | n/a | ('UserDict', 'IterableUserDict'): ('collections', 'UserDict'), |
---|
70 | n/a | ('UserList', 'UserList'): ('collections', 'UserList'), |
---|
71 | n/a | ('UserString', 'UserString'): ('collections', 'UserString'), |
---|
72 | n/a | ('whichdb', 'whichdb'): ('dbm', 'whichdb'), |
---|
73 | n/a | ('_socket', 'fromfd'): ('socket', 'fromfd'), |
---|
74 | n/a | ('_multiprocessing', 'Connection'): ('multiprocessing.connection', 'Connection'), |
---|
75 | n/a | ('multiprocessing.process', 'Process'): ('multiprocessing.context', 'Process'), |
---|
76 | n/a | ('multiprocessing.forking', 'Popen'): ('multiprocessing.popen_fork', 'Popen'), |
---|
77 | n/a | ('urllib', 'ContentTooShortError'): ('urllib.error', 'ContentTooShortError'), |
---|
78 | n/a | ('urllib', 'getproxies'): ('urllib.request', 'getproxies'), |
---|
79 | n/a | ('urllib', 'pathname2url'): ('urllib.request', 'pathname2url'), |
---|
80 | n/a | ('urllib', 'quote_plus'): ('urllib.parse', 'quote_plus'), |
---|
81 | n/a | ('urllib', 'quote'): ('urllib.parse', 'quote'), |
---|
82 | n/a | ('urllib', 'unquote_plus'): ('urllib.parse', 'unquote_plus'), |
---|
83 | n/a | ('urllib', 'unquote'): ('urllib.parse', 'unquote'), |
---|
84 | n/a | ('urllib', 'url2pathname'): ('urllib.request', 'url2pathname'), |
---|
85 | n/a | ('urllib', 'urlcleanup'): ('urllib.request', 'urlcleanup'), |
---|
86 | n/a | ('urllib', 'urlencode'): ('urllib.parse', 'urlencode'), |
---|
87 | n/a | ('urllib', 'urlopen'): ('urllib.request', 'urlopen'), |
---|
88 | n/a | ('urllib', 'urlretrieve'): ('urllib.request', 'urlretrieve'), |
---|
89 | n/a | ('urllib2', 'HTTPError'): ('urllib.error', 'HTTPError'), |
---|
90 | n/a | ('urllib2', 'URLError'): ('urllib.error', 'URLError'), |
---|
91 | n/a | } |
---|
92 | n/a | |
---|
93 | n/a | PYTHON2_EXCEPTIONS = ( |
---|
94 | n/a | "ArithmeticError", |
---|
95 | n/a | "AssertionError", |
---|
96 | n/a | "AttributeError", |
---|
97 | n/a | "BaseException", |
---|
98 | n/a | "BufferError", |
---|
99 | n/a | "BytesWarning", |
---|
100 | n/a | "DeprecationWarning", |
---|
101 | n/a | "EOFError", |
---|
102 | n/a | "EnvironmentError", |
---|
103 | n/a | "Exception", |
---|
104 | n/a | "FloatingPointError", |
---|
105 | n/a | "FutureWarning", |
---|
106 | n/a | "GeneratorExit", |
---|
107 | n/a | "IOError", |
---|
108 | n/a | "ImportError", |
---|
109 | n/a | "ImportWarning", |
---|
110 | n/a | "IndentationError", |
---|
111 | n/a | "IndexError", |
---|
112 | n/a | "KeyError", |
---|
113 | n/a | "KeyboardInterrupt", |
---|
114 | n/a | "LookupError", |
---|
115 | n/a | "MemoryError", |
---|
116 | n/a | "NameError", |
---|
117 | n/a | "NotImplementedError", |
---|
118 | n/a | "OSError", |
---|
119 | n/a | "OverflowError", |
---|
120 | n/a | "PendingDeprecationWarning", |
---|
121 | n/a | "ReferenceError", |
---|
122 | n/a | "RuntimeError", |
---|
123 | n/a | "RuntimeWarning", |
---|
124 | n/a | # StandardError is gone in Python 3, so we map it to Exception |
---|
125 | n/a | "StopIteration", |
---|
126 | n/a | "SyntaxError", |
---|
127 | n/a | "SyntaxWarning", |
---|
128 | n/a | "SystemError", |
---|
129 | n/a | "SystemExit", |
---|
130 | n/a | "TabError", |
---|
131 | n/a | "TypeError", |
---|
132 | n/a | "UnboundLocalError", |
---|
133 | n/a | "UnicodeDecodeError", |
---|
134 | n/a | "UnicodeEncodeError", |
---|
135 | n/a | "UnicodeError", |
---|
136 | n/a | "UnicodeTranslateError", |
---|
137 | n/a | "UnicodeWarning", |
---|
138 | n/a | "UserWarning", |
---|
139 | n/a | "ValueError", |
---|
140 | n/a | "Warning", |
---|
141 | n/a | "ZeroDivisionError", |
---|
142 | n/a | ) |
---|
143 | n/a | |
---|
144 | n/a | try: |
---|
145 | n/a | WindowsError |
---|
146 | n/a | except NameError: |
---|
147 | n/a | pass |
---|
148 | n/a | else: |
---|
149 | n/a | PYTHON2_EXCEPTIONS += ("WindowsError",) |
---|
150 | n/a | |
---|
151 | n/a | for excname in PYTHON2_EXCEPTIONS: |
---|
152 | n/a | NAME_MAPPING[("exceptions", excname)] = ("builtins", excname) |
---|
153 | n/a | |
---|
154 | n/a | MULTIPROCESSING_EXCEPTIONS = ( |
---|
155 | n/a | 'AuthenticationError', |
---|
156 | n/a | 'BufferTooShort', |
---|
157 | n/a | 'ProcessError', |
---|
158 | n/a | 'TimeoutError', |
---|
159 | n/a | ) |
---|
160 | n/a | |
---|
161 | n/a | for excname in MULTIPROCESSING_EXCEPTIONS: |
---|
162 | n/a | NAME_MAPPING[("multiprocessing", excname)] = ("multiprocessing.context", excname) |
---|
163 | n/a | |
---|
164 | n/a | # Same, but for 3.x to 2.x |
---|
165 | n/a | REVERSE_IMPORT_MAPPING = dict((v, k) for (k, v) in IMPORT_MAPPING.items()) |
---|
166 | n/a | assert len(REVERSE_IMPORT_MAPPING) == len(IMPORT_MAPPING) |
---|
167 | n/a | REVERSE_NAME_MAPPING = dict((v, k) for (k, v) in NAME_MAPPING.items()) |
---|
168 | n/a | assert len(REVERSE_NAME_MAPPING) == len(NAME_MAPPING) |
---|
169 | n/a | |
---|
170 | n/a | # Non-mutual mappings. |
---|
171 | n/a | |
---|
172 | n/a | IMPORT_MAPPING.update({ |
---|
173 | n/a | 'cPickle': 'pickle', |
---|
174 | n/a | '_elementtree': 'xml.etree.ElementTree', |
---|
175 | n/a | 'FileDialog': 'tkinter.filedialog', |
---|
176 | n/a | 'SimpleDialog': 'tkinter.simpledialog', |
---|
177 | n/a | 'DocXMLRPCServer': 'xmlrpc.server', |
---|
178 | n/a | 'SimpleHTTPServer': 'http.server', |
---|
179 | n/a | 'CGIHTTPServer': 'http.server', |
---|
180 | n/a | # For compatibility with broken pickles saved in old Python 3 versions |
---|
181 | n/a | 'UserDict': 'collections', |
---|
182 | n/a | 'UserList': 'collections', |
---|
183 | n/a | 'UserString': 'collections', |
---|
184 | n/a | 'whichdb': 'dbm', |
---|
185 | n/a | 'StringIO': 'io', |
---|
186 | n/a | 'cStringIO': 'io', |
---|
187 | n/a | }) |
---|
188 | n/a | |
---|
189 | n/a | REVERSE_IMPORT_MAPPING.update({ |
---|
190 | n/a | '_bz2': 'bz2', |
---|
191 | n/a | '_dbm': 'dbm', |
---|
192 | n/a | '_functools': 'functools', |
---|
193 | n/a | '_gdbm': 'gdbm', |
---|
194 | n/a | '_pickle': 'pickle', |
---|
195 | n/a | }) |
---|
196 | n/a | |
---|
197 | n/a | NAME_MAPPING.update({ |
---|
198 | n/a | ('__builtin__', 'basestring'): ('builtins', 'str'), |
---|
199 | n/a | ('exceptions', 'StandardError'): ('builtins', 'Exception'), |
---|
200 | n/a | ('UserDict', 'UserDict'): ('collections', 'UserDict'), |
---|
201 | n/a | ('socket', '_socketobject'): ('socket', 'SocketType'), |
---|
202 | n/a | }) |
---|
203 | n/a | |
---|
204 | n/a | REVERSE_NAME_MAPPING.update({ |
---|
205 | n/a | ('_functools', 'reduce'): ('__builtin__', 'reduce'), |
---|
206 | n/a | ('tkinter.filedialog', 'FileDialog'): ('FileDialog', 'FileDialog'), |
---|
207 | n/a | ('tkinter.filedialog', 'LoadFileDialog'): ('FileDialog', 'LoadFileDialog'), |
---|
208 | n/a | ('tkinter.filedialog', 'SaveFileDialog'): ('FileDialog', 'SaveFileDialog'), |
---|
209 | n/a | ('tkinter.simpledialog', 'SimpleDialog'): ('SimpleDialog', 'SimpleDialog'), |
---|
210 | n/a | ('xmlrpc.server', 'ServerHTMLDoc'): ('DocXMLRPCServer', 'ServerHTMLDoc'), |
---|
211 | n/a | ('xmlrpc.server', 'XMLRPCDocGenerator'): |
---|
212 | n/a | ('DocXMLRPCServer', 'XMLRPCDocGenerator'), |
---|
213 | n/a | ('xmlrpc.server', 'DocXMLRPCRequestHandler'): |
---|
214 | n/a | ('DocXMLRPCServer', 'DocXMLRPCRequestHandler'), |
---|
215 | n/a | ('xmlrpc.server', 'DocXMLRPCServer'): |
---|
216 | n/a | ('DocXMLRPCServer', 'DocXMLRPCServer'), |
---|
217 | n/a | ('xmlrpc.server', 'DocCGIXMLRPCRequestHandler'): |
---|
218 | n/a | ('DocXMLRPCServer', 'DocCGIXMLRPCRequestHandler'), |
---|
219 | n/a | ('http.server', 'SimpleHTTPRequestHandler'): |
---|
220 | n/a | ('SimpleHTTPServer', 'SimpleHTTPRequestHandler'), |
---|
221 | n/a | ('http.server', 'CGIHTTPRequestHandler'): |
---|
222 | n/a | ('CGIHTTPServer', 'CGIHTTPRequestHandler'), |
---|
223 | n/a | ('_socket', 'socket'): ('socket', '_socketobject'), |
---|
224 | n/a | }) |
---|
225 | n/a | |
---|
226 | n/a | PYTHON3_OSERROR_EXCEPTIONS = ( |
---|
227 | n/a | 'BrokenPipeError', |
---|
228 | n/a | 'ChildProcessError', |
---|
229 | n/a | 'ConnectionAbortedError', |
---|
230 | n/a | 'ConnectionError', |
---|
231 | n/a | 'ConnectionRefusedError', |
---|
232 | n/a | 'ConnectionResetError', |
---|
233 | n/a | 'FileExistsError', |
---|
234 | n/a | 'FileNotFoundError', |
---|
235 | n/a | 'InterruptedError', |
---|
236 | n/a | 'IsADirectoryError', |
---|
237 | n/a | 'NotADirectoryError', |
---|
238 | n/a | 'PermissionError', |
---|
239 | n/a | 'ProcessLookupError', |
---|
240 | n/a | 'TimeoutError', |
---|
241 | n/a | ) |
---|
242 | n/a | |
---|
243 | n/a | for excname in PYTHON3_OSERROR_EXCEPTIONS: |
---|
244 | n/a | REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'OSError') |
---|
245 | n/a | |
---|
246 | n/a | PYTHON3_IMPORTERROR_EXCEPTIONS = ( |
---|
247 | n/a | 'ModuleNotFoundError', |
---|
248 | n/a | ) |
---|
249 | n/a | |
---|
250 | n/a | for excname in PYTHON3_IMPORTERROR_EXCEPTIONS: |
---|
251 | n/a | REVERSE_NAME_MAPPING[('builtins', excname)] = ('exceptions', 'ImportError') |
---|