Skip to content

Commit 61de0ac

Browse files
committed
Reindented according to new standard, without tabs.
Also added one more os2 specific piece of code, by Jeff Rush.
1 parent 63cf396 commit 61de0ac

1 file changed

Lines changed: 131 additions & 117 deletions

File tree

Lib/os.py

Lines changed: 131 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -24,151 +24,165 @@
2424
altsep = None
2525

2626
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
3838
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
5050
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
6262
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
7474
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
8686
else:
87-
raise ImportError, 'no os specific module found'
87+
raise ImportError, 'no os specific module found'
8888

8989
del _names
9090

9191
# Make sure os.environ exists, at least
9292
try:
93-
environ
93+
environ
9494
except NameError:
95-
environ = {}
95+
environ = {}
9696

9797
def execl(file, *args):
98-
execv(file, args)
98+
execv(file, args)
9999

100100
def execle(file, *args):
101-
env = args[-1]
102-
execve(file, args[:-1], env)
101+
env = args[-1]
102+
execve(file, args[:-1], env)
103103

104104
def execlp(file, *args):
105-
execvp(file, args)
105+
execvp(file, args)
106106

107107
def execlpe(file, *args):
108-
env = args[-1]
109-
execvpe(file, args[:-1], env)
108+
env = args[-1]
109+
execvpe(file, args[:-1], env)
110110

111111
def execvp(file, args):
112-
_execvpe(file, args)
112+
_execvpe(file, args)
113113

114114
def execvpe(file, args, env):
115-
_execvpe(file, args, env)
115+
_execvpe(file, args, env)
116116

117117
_notfound = None
118118
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
151151

152152
# Change environ to automatically call putenv() if it exists
153153
try:
154-
# This will fail if there's no putenv
155-
putenv
154+
# This will fail if there's no putenv
155+
putenv
156156
except NameError:
157-
pass
157+
pass
158158
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

Comments
 (0)