1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 __doc__ = """
25 SCons compatibility package for old Python versions
26
27 This subpackage holds modules that provide backwards-compatible
28 implementations of various things that we'd like to use in SCons but which
29 only show up in later versions of Python than the early, old version(s)
30 we still support.
31
32 Other code will not generally reference things in this package through
33 the SCons.compat namespace. The modules included here add things to
34 the builtins namespace or the global module list so that the rest
35 of our code can use the objects and names imported here regardless of
36 Python version.
37
38 The rest of the things here will be in individual compatibility modules
39 that are either: 1) suitably modified copies of the future modules that
40 we want to use; or 2) backwards compatible re-implementations of the
41 specific portions of a future module's API that we want to use.
42
43 GENERAL WARNINGS: Implementations of functions in the SCons.compat
44 modules are *NOT* guaranteed to be fully compliant with these functions in
45 later versions of Python. We are only concerned with adding functionality
46 that we actually use in SCons, so be wary if you lift this code for
47 other uses. (That said, making these more nearly the same as later,
48 official versions is still a desirable goal, we just don't need to be
49 obsessive about it.)
50
51 We name the compatibility modules with an initial '_scons_' (for example,
52 _scons_subprocess.py is our compatibility module for subprocess) so
53 that we can still try to import the real module name and fall back to
54 our compatibility module if we get an ImportError. The import_as()
55 function defined below loads the module as the "real" name (without the
56 '_scons'), after which all of the "import {module}" statements in the
57 rest of our code will find our pre-loaded compatibility module.
58 """
59
60 __revision__ = "src/engine/SCons/compat/__init__.py e724ae812eb96f4858a132f5b8c769724744faf6 2019-07-21 00:04:47 bdeegan"
61
62 import os
63 import sys
64 import importlib
65
66 PYPY = hasattr(sys, 'pypy_translation_info')
67
68
70 """
71 Attempt to import the old module and load it under the new name.
72 Used for purely cosmetic name changes in Python 3.x.
73 """
74 try:
75 sys.modules[new] = importlib.import_module(old)
76 return True
77 except ImportError:
78 return False
79
80
81
82
83 rename_module('pickle', 'cPickle')
84
85
86
87
88 import pickle
89
90
91
92 PICKLE_PROTOCOL = pickle.HIGHEST_PROTOCOL
93
94
95
96 rename_module('profile', 'cProfile')
97
98
99
100 rename_module('queue', 'Queue')
101
102
103
104 rename_module('winreg', '_winreg')
105
106
107
108
109 try:
110 sys.intern
111 except AttributeError:
112
113
114 sys.intern = intern
115
116
117
118 import collections
119
120 try:
121 collections.UserDict
122 except AttributeError:
123 from UserDict import UserDict as _UserDict
124 collections.UserDict = _UserDict
125 del _UserDict
126
127 try:
128 collections.UserList
129 except AttributeError:
130 from UserList import UserList as _UserList
131 collections.UserList = _UserList
132 del _UserList
133
134 try:
135 collections.UserString
136 except AttributeError:
137 from UserString import UserString as _UserString
138 collections.UserString = _UserString
139 del _UserString
140
141
142 import shutil
143 try:
144 shutil.SameFileError
145 except AttributeError:
148
149 shutil.SameFileError = SameFileError
150
185
186 return metaclass('temporary_class', None, {})
187
188
190 """
191 Workaround for PyPy not working well with __slots__ and __class__ assignment.
192 """
193
194 - def __new__(meta, name, bases, dct):
198
199
200
201
202
203
204