mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
Reindented according to new standard, without tabs.
Also added one more os2 specific piece of code, by Jeff Rush.
This commit is contained in:
parent
63cf3960df
commit
61de0ac4bb
1 changed files with 129 additions and 115 deletions
244
Lib/os.py
244
Lib/os.py
|
|
@ -24,151 +24,165 @@ _names = sys.builtin_module_names
|
||||||
altsep = None
|
altsep = None
|
||||||
|
|
||||||
if 'posix' in _names:
|
if 'posix' in _names:
|
||||||
name = 'posix'
|
name = 'posix'
|
||||||
curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':'
|
curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':'
|
||||||
defpath = ':/bin:/usr/bin'
|
defpath = ':/bin:/usr/bin'
|
||||||
from posix import *
|
from posix import *
|
||||||
try:
|
try:
|
||||||
from posix import _exit
|
from posix import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import posixpath
|
import posixpath
|
||||||
path = posixpath
|
path = posixpath
|
||||||
del posixpath
|
del posixpath
|
||||||
elif 'nt' in _names:
|
elif 'nt' in _names:
|
||||||
name = 'nt'
|
name = 'nt'
|
||||||
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
||||||
defpath = '.;C:\\bin'
|
defpath = '.;C:\\bin'
|
||||||
from nt import *
|
from nt import *
|
||||||
try:
|
try:
|
||||||
from nt import _exit
|
from nt import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import ntpath
|
import ntpath
|
||||||
path = ntpath
|
path = ntpath
|
||||||
del ntpath
|
del ntpath
|
||||||
elif 'dos' in _names:
|
elif 'dos' in _names:
|
||||||
name = 'dos'
|
name = 'dos'
|
||||||
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
||||||
defpath = '.;C:\\bin'
|
defpath = '.;C:\\bin'
|
||||||
from dos import *
|
from dos import *
|
||||||
try:
|
try:
|
||||||
from dos import _exit
|
from dos import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import dospath
|
import dospath
|
||||||
path = dospath
|
path = dospath
|
||||||
del dospath
|
del dospath
|
||||||
elif 'os2' in _names:
|
elif 'os2' in _names:
|
||||||
name = 'os2'
|
name = 'os2'
|
||||||
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
|
||||||
defpath = '.;C:\\bin'
|
defpath = '.;C:\\bin'
|
||||||
from os2 import *
|
from os2 import *
|
||||||
try:
|
try:
|
||||||
from os2 import _exit
|
from os2 import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import ntpath
|
import ntpath
|
||||||
path = ntpath
|
path = ntpath
|
||||||
del ntpath
|
del ntpath
|
||||||
elif 'mac' in _names:
|
elif 'mac' in _names:
|
||||||
name = 'mac'
|
name = 'mac'
|
||||||
curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
|
curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
|
||||||
defpath = ':'
|
defpath = ':'
|
||||||
from mac import *
|
from mac import *
|
||||||
try:
|
try:
|
||||||
from mac import _exit
|
from mac import _exit
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
import macpath
|
import macpath
|
||||||
path = macpath
|
path = macpath
|
||||||
del macpath
|
del macpath
|
||||||
else:
|
else:
|
||||||
raise ImportError, 'no os specific module found'
|
raise ImportError, 'no os specific module found'
|
||||||
|
|
||||||
del _names
|
del _names
|
||||||
|
|
||||||
# Make sure os.environ exists, at least
|
# Make sure os.environ exists, at least
|
||||||
try:
|
try:
|
||||||
environ
|
environ
|
||||||
except NameError:
|
except NameError:
|
||||||
environ = {}
|
environ = {}
|
||||||
|
|
||||||
def execl(file, *args):
|
def execl(file, *args):
|
||||||
execv(file, args)
|
execv(file, args)
|
||||||
|
|
||||||
def execle(file, *args):
|
def execle(file, *args):
|
||||||
env = args[-1]
|
env = args[-1]
|
||||||
execve(file, args[:-1], env)
|
execve(file, args[:-1], env)
|
||||||
|
|
||||||
def execlp(file, *args):
|
def execlp(file, *args):
|
||||||
execvp(file, args)
|
execvp(file, args)
|
||||||
|
|
||||||
def execlpe(file, *args):
|
def execlpe(file, *args):
|
||||||
env = args[-1]
|
env = args[-1]
|
||||||
execvpe(file, args[:-1], env)
|
execvpe(file, args[:-1], env)
|
||||||
|
|
||||||
def execvp(file, args):
|
def execvp(file, args):
|
||||||
_execvpe(file, args)
|
_execvpe(file, args)
|
||||||
|
|
||||||
def execvpe(file, args, env):
|
def execvpe(file, args, env):
|
||||||
_execvpe(file, args, env)
|
_execvpe(file, args, env)
|
||||||
|
|
||||||
_notfound = None
|
_notfound = None
|
||||||
def _execvpe(file, args, env = None):
|
def _execvpe(file, args, env = None):
|
||||||
if env:
|
if env:
|
||||||
func = execve
|
func = execve
|
||||||
argrest = (args, env)
|
argrest = (args, env)
|
||||||
else:
|
else:
|
||||||
func = execv
|
func = execv
|
||||||
argrest = (args,)
|
argrest = (args,)
|
||||||
env = environ
|
env = environ
|
||||||
global _notfound
|
global _notfound
|
||||||
head, tail = path.split(file)
|
head, tail = path.split(file)
|
||||||
if head:
|
if head:
|
||||||
apply(func, (file,) + argrest)
|
apply(func, (file,) + argrest)
|
||||||
return
|
return
|
||||||
if env.has_key('PATH'):
|
if env.has_key('PATH'):
|
||||||
envpath = env['PATH']
|
envpath = env['PATH']
|
||||||
else:
|
else:
|
||||||
envpath = defpath
|
envpath = defpath
|
||||||
import string
|
import string
|
||||||
PATH = string.splitfields(envpath, pathsep)
|
PATH = string.splitfields(envpath, pathsep)
|
||||||
if not _notfound:
|
if not _notfound:
|
||||||
import tempfile
|
import tempfile
|
||||||
# Exec a file that is guaranteed not to exist
|
# Exec a file that is guaranteed not to exist
|
||||||
try: execv(tempfile.mktemp(), ())
|
try: execv(tempfile.mktemp(), ())
|
||||||
except error, _notfound: pass
|
except error, _notfound: pass
|
||||||
exc, arg = error, _notfound
|
exc, arg = error, _notfound
|
||||||
for dir in PATH:
|
for dir in PATH:
|
||||||
fullname = path.join(dir, file)
|
fullname = path.join(dir, file)
|
||||||
try:
|
try:
|
||||||
apply(func, (fullname,) + argrest)
|
apply(func, (fullname,) + argrest)
|
||||||
except error, (errno, msg):
|
except error, (errno, msg):
|
||||||
if errno != arg[0]:
|
if errno != arg[0]:
|
||||||
exc, arg = error, (errno, msg)
|
exc, arg = error, (errno, msg)
|
||||||
raise exc, arg
|
raise exc, arg
|
||||||
|
|
||||||
# Change environ to automatically call putenv() if it exists
|
# Change environ to automatically call putenv() if it exists
|
||||||
try:
|
try:
|
||||||
# This will fail if there's no putenv
|
# This will fail if there's no putenv
|
||||||
putenv
|
putenv
|
||||||
except NameError:
|
except NameError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
import UserDict
|
import UserDict
|
||||||
|
|
||||||
class _Environ(UserDict.UserDict):
|
if name in ('os2', ): # Where Env Var Names Must Be UPPERCASE
|
||||||
def __init__(self, environ):
|
import string
|
||||||
UserDict.UserDict.__init__(self)
|
class _Environ(UserDict.UserDict):
|
||||||
self.data = environ
|
def __init__(self, environ):
|
||||||
def __getinitargs__(self):
|
UserDict.UserDict.__init__(self)
|
||||||
import copy
|
self.data = environ
|
||||||
return (copy.copy(self.data),)
|
def __setitem__(self, key, item):
|
||||||
def __setitem__(self, key, item):
|
key = string.upper(key)
|
||||||
putenv(key, item)
|
putenv(key, item)
|
||||||
self.data[key] = item
|
self.data[key] = item
|
||||||
def __copy__(self):
|
def __getitem__(self, key):
|
||||||
return _Environ(self.data.copy())
|
return self.data[string.upper(key)]
|
||||||
|
|
||||||
environ = _Environ(environ)
|
else: # Where Env Var Names Can Be Mixed Case
|
||||||
|
class _Environ(UserDict.UserDict):
|
||||||
|
def __init__(self, environ):
|
||||||
|
UserDict.UserDict.__init__(self)
|
||||||
|
self.data = environ
|
||||||
|
def __getinitargs__(self):
|
||||||
|
import copy
|
||||||
|
return (copy.copy(self.data),)
|
||||||
|
def __setitem__(self, key, item):
|
||||||
|
putenv(key, item)
|
||||||
|
self.data[key] = item
|
||||||
|
def __copy__(self):
|
||||||
|
return _Environ(self.data.copy())
|
||||||
|
|
||||||
|
environ = _Environ(environ)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue