|
24 | 24 | altsep = None |
25 | 25 |
|
26 | 26 | if 'posix' in _names: |
27 | | - name = 'posix' |
28 | | - curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':' |
29 | | - defpath = ':/bin:/usr/bin' |
30 | | - from posix import * |
31 | | - try: |
32 | | - from posix import _exit |
33 | | - except ImportError: |
34 | | - pass |
35 | | - import posixpath |
36 | | - path = posixpath |
37 | | - del posixpath |
| 27 | + name = 'posix' |
| 28 | + curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':' |
| 29 | + defpath = ':/bin:/usr/bin' |
| 30 | + from posix import * |
| 31 | + try: |
| 32 | + from posix import _exit |
| 33 | + except ImportError: |
| 34 | + pass |
| 35 | + import posixpath |
| 36 | + path = posixpath |
| 37 | + del posixpath |
38 | 38 | elif 'nt' in _names: |
39 | | - name = 'nt' |
40 | | - curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
41 | | - defpath = '.;C:\\bin' |
42 | | - from nt import * |
43 | | - try: |
44 | | - from nt import _exit |
45 | | - except ImportError: |
46 | | - pass |
47 | | - import ntpath |
48 | | - path = ntpath |
49 | | - del ntpath |
| 39 | + name = 'nt' |
| 40 | + curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
| 41 | + defpath = '.;C:\\bin' |
| 42 | + from nt import * |
| 43 | + try: |
| 44 | + from nt import _exit |
| 45 | + except ImportError: |
| 46 | + pass |
| 47 | + import ntpath |
| 48 | + path = ntpath |
| 49 | + del ntpath |
50 | 50 | elif 'dos' in _names: |
51 | | - name = 'dos' |
52 | | - curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
53 | | - defpath = '.;C:\\bin' |
54 | | - from dos import * |
55 | | - try: |
56 | | - from dos import _exit |
57 | | - except ImportError: |
58 | | - pass |
59 | | - import dospath |
60 | | - path = dospath |
61 | | - del dospath |
| 51 | + name = 'dos' |
| 52 | + curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
| 53 | + defpath = '.;C:\\bin' |
| 54 | + from dos import * |
| 55 | + try: |
| 56 | + from dos import _exit |
| 57 | + except ImportError: |
| 58 | + pass |
| 59 | + import dospath |
| 60 | + path = dospath |
| 61 | + del dospath |
62 | 62 | elif 'os2' in _names: |
63 | | - name = 'os2' |
64 | | - curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
65 | | - defpath = '.;C:\\bin' |
66 | | - from os2 import * |
67 | | - try: |
68 | | - from os2 import _exit |
69 | | - except ImportError: |
70 | | - pass |
71 | | - import ntpath |
72 | | - path = ntpath |
73 | | - del ntpath |
| 63 | + name = 'os2' |
| 64 | + curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';' |
| 65 | + defpath = '.;C:\\bin' |
| 66 | + from os2 import * |
| 67 | + try: |
| 68 | + from os2 import _exit |
| 69 | + except ImportError: |
| 70 | + pass |
| 71 | + import ntpath |
| 72 | + path = ntpath |
| 73 | + del ntpath |
74 | 74 | elif 'mac' in _names: |
75 | | - name = 'mac' |
76 | | - curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n' |
77 | | - defpath = ':' |
78 | | - from mac import * |
79 | | - try: |
80 | | - from mac import _exit |
81 | | - except ImportError: |
82 | | - pass |
83 | | - import macpath |
84 | | - path = macpath |
85 | | - del macpath |
| 75 | + name = 'mac' |
| 76 | + curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n' |
| 77 | + defpath = ':' |
| 78 | + from mac import * |
| 79 | + try: |
| 80 | + from mac import _exit |
| 81 | + except ImportError: |
| 82 | + pass |
| 83 | + import macpath |
| 84 | + path = macpath |
| 85 | + del macpath |
86 | 86 | else: |
87 | | - raise ImportError, 'no os specific module found' |
| 87 | + raise ImportError, 'no os specific module found' |
88 | 88 |
|
89 | 89 | del _names |
90 | 90 |
|
91 | 91 | # Make sure os.environ exists, at least |
92 | 92 | try: |
93 | | - environ |
| 93 | + environ |
94 | 94 | except NameError: |
95 | | - environ = {} |
| 95 | + environ = {} |
96 | 96 |
|
97 | 97 | def execl(file, *args): |
98 | | - execv(file, args) |
| 98 | + execv(file, args) |
99 | 99 |
|
100 | 100 | def execle(file, *args): |
101 | | - env = args[-1] |
102 | | - execve(file, args[:-1], env) |
| 101 | + env = args[-1] |
| 102 | + execve(file, args[:-1], env) |
103 | 103 |
|
104 | 104 | def execlp(file, *args): |
105 | | - execvp(file, args) |
| 105 | + execvp(file, args) |
106 | 106 |
|
107 | 107 | def execlpe(file, *args): |
108 | | - env = args[-1] |
109 | | - execvpe(file, args[:-1], env) |
| 108 | + env = args[-1] |
| 109 | + execvpe(file, args[:-1], env) |
110 | 110 |
|
111 | 111 | def execvp(file, args): |
112 | | - _execvpe(file, args) |
| 112 | + _execvpe(file, args) |
113 | 113 |
|
114 | 114 | def execvpe(file, args, env): |
115 | | - _execvpe(file, args, env) |
| 115 | + _execvpe(file, args, env) |
116 | 116 |
|
117 | 117 | _notfound = None |
118 | 118 | def _execvpe(file, args, env = None): |
119 | | - if env: |
120 | | - func = execve |
121 | | - argrest = (args, env) |
122 | | - else: |
123 | | - func = execv |
124 | | - argrest = (args,) |
125 | | - env = environ |
126 | | - global _notfound |
127 | | - head, tail = path.split(file) |
128 | | - if head: |
129 | | - apply(func, (file,) + argrest) |
130 | | - return |
131 | | - if env.has_key('PATH'): |
132 | | - envpath = env['PATH'] |
133 | | - else: |
134 | | - envpath = defpath |
135 | | - import string |
136 | | - PATH = string.splitfields(envpath, pathsep) |
137 | | - if not _notfound: |
138 | | - import tempfile |
139 | | - # Exec a file that is guaranteed not to exist |
140 | | - try: execv(tempfile.mktemp(), ()) |
141 | | - except error, _notfound: pass |
142 | | - exc, arg = error, _notfound |
143 | | - for dir in PATH: |
144 | | - fullname = path.join(dir, file) |
145 | | - try: |
146 | | - apply(func, (fullname,) + argrest) |
147 | | - except error, (errno, msg): |
148 | | - if errno != arg[0]: |
149 | | - exc, arg = error, (errno, msg) |
150 | | - raise exc, arg |
| 119 | + if env: |
| 120 | + func = execve |
| 121 | + argrest = (args, env) |
| 122 | + else: |
| 123 | + func = execv |
| 124 | + argrest = (args,) |
| 125 | + env = environ |
| 126 | + global _notfound |
| 127 | + head, tail = path.split(file) |
| 128 | + if head: |
| 129 | + apply(func, (file,) + argrest) |
| 130 | + return |
| 131 | + if env.has_key('PATH'): |
| 132 | + envpath = env['PATH'] |
| 133 | + else: |
| 134 | + envpath = defpath |
| 135 | + import string |
| 136 | + PATH = string.splitfields(envpath, pathsep) |
| 137 | + if not _notfound: |
| 138 | + import tempfile |
| 139 | + # Exec a file that is guaranteed not to exist |
| 140 | + try: execv(tempfile.mktemp(), ()) |
| 141 | + except error, _notfound: pass |
| 142 | + exc, arg = error, _notfound |
| 143 | + for dir in PATH: |
| 144 | + fullname = path.join(dir, file) |
| 145 | + try: |
| 146 | + apply(func, (fullname,) + argrest) |
| 147 | + except error, (errno, msg): |
| 148 | + if errno != arg[0]: |
| 149 | + exc, arg = error, (errno, msg) |
| 150 | + raise exc, arg |
151 | 151 |
|
152 | 152 | # Change environ to automatically call putenv() if it exists |
153 | 153 | try: |
154 | | - # This will fail if there's no putenv |
155 | | - putenv |
| 154 | + # This will fail if there's no putenv |
| 155 | + putenv |
156 | 156 | except NameError: |
157 | | - pass |
| 157 | + pass |
158 | 158 | else: |
159 | | - import UserDict |
160 | | - |
161 | | - class _Environ(UserDict.UserDict): |
162 | | - def __init__(self, environ): |
163 | | - UserDict.UserDict.__init__(self) |
164 | | - self.data = environ |
165 | | - def __getinitargs__(self): |
166 | | - import copy |
167 | | - return (copy.copy(self.data),) |
168 | | - def __setitem__(self, key, item): |
169 | | - putenv(key, item) |
170 | | - self.data[key] = item |
171 | | - def __copy__(self): |
172 | | - return _Environ(self.data.copy()) |
173 | | - |
174 | | - environ = _Environ(environ) |
| 159 | + import UserDict |
| 160 | + |
| 161 | + if name in ('os2', ): # Where Env Var Names Must Be UPPERCASE |
| 162 | + import string |
| 163 | + class _Environ(UserDict.UserDict): |
| 164 | + def __init__(self, environ): |
| 165 | + UserDict.UserDict.__init__(self) |
| 166 | + self.data = environ |
| 167 | + def __setitem__(self, key, item): |
| 168 | + key = string.upper(key) |
| 169 | + putenv(key, item) |
| 170 | + self.data[key] = item |
| 171 | + def __getitem__(self, key): |
| 172 | + return self.data[string.upper(key)] |
| 173 | + |
| 174 | + else: # Where Env Var Names Can Be Mixed Case |
| 175 | + class _Environ(UserDict.UserDict): |
| 176 | + def __init__(self, environ): |
| 177 | + UserDict.UserDict.__init__(self) |
| 178 | + self.data = environ |
| 179 | + def __getinitargs__(self): |
| 180 | + import copy |
| 181 | + return (copy.copy(self.data),) |
| 182 | + def __setitem__(self, key, item): |
| 183 | + putenv(key, item) |
| 184 | + self.data[key] = item |
| 185 | + def __copy__(self): |
| 186 | + return _Environ(self.data.copy()) |
| 187 | + |
| 188 | + environ = _Environ(environ) |
0 commit comments