Back to index

python3.2  3.2.2
Classes | Functions | Variables
os Namespace Reference

Classes

class  _Environ
class  _wrap_close

Functions

def _get_exports_list
def _get_masked_mode
def makedirs
def removedirs
def renames
def walk
def execl
def execle
def execlp
def execlpe
def execvp
def execvpe
def _execvpe
def get_exec_path
def _createenviron
def getenv
def _check_bytes
def getenvb
def _fscodec
def _exists
def _spawnvef
def spawnv
def spawnve
def spawnvp
def spawnvpe
def spawnl
def spawnle
def spawnlp
def spawnlpe
def _make_stat_result
def _pickle_stat_result
def _make_statvfs_result
def _pickle_statvfs_result
def urandom
def popen
def fdopen

Variables

 _names = sys.builtin_module_names
list __all__
string name = 'posix'
string linesep = '\n'
int SEEK_SET = 0
int SEEK_CUR = 1
int SEEK_END = 2
dictionary environ = {}
 _putenv = lambdakey,value:None
 _unsetenv = unsetenv
tuple supports_bytes_environ = namenotin('os2', 'nt')
tuple environb
int P_WAIT = 0
int P_NOWAIT = 1

Function Documentation

def os._check_bytes (   value) [private]

Definition at line 543 of file os.py.

00543 
00544     def _check_bytes(value):
00545         if not isinstance(value, bytes):
00546             raise TypeError("bytes expected, not %s" % type(value).__name__)
00547         return value

def os._createenviron ( ) [private]

Definition at line 498 of file os.py.

00498 
00499 def _createenviron():
00500     if name in ('os2', 'nt'):
00501         # Where Env Var Names Must Be UPPERCASE
00502         def check_str(value):
00503             if not isinstance(value, str):
00504                 raise TypeError("str expected, not %s" % type(value).__name__)
00505             return value
00506         encode = check_str
00507         decode = str
00508         def encodekey(key):
00509             return encode(key).upper()
00510         data = {}
00511         for key, value in environ.items():
00512             data[encodekey(key)] = value
00513     else:
00514         # Where Env Var Names Can Be Mixed Case
00515         encoding = sys.getfilesystemencoding()
00516         def encode(value):
00517             if not isinstance(value, str):
00518                 raise TypeError("str expected, not %s" % type(value).__name__)
00519             return value.encode(encoding, 'surrogateescape')
00520         def decode(value):
00521             return value.decode(encoding, 'surrogateescape')
00522         encodekey = encode
00523         data = environ
00524     return _Environ(data,
00525         encodekey, decode,
00526         encode, decode,
00527         _putenv, _unsetenv)
00528 
# unicode environ

Here is the call graph for this function:

def os._execvpe (   file,
  args,
  env = None 
) [private]

Definition at line 357 of file os.py.

00357 
00358 def _execvpe(file, args, env=None):
00359     if env is not None:
00360         exec_func = execve
00361         argrest = (args, env)
00362     else:
00363         exec_func = execv
00364         argrest = (args,)
00365         env = environ
00366 
00367     head, tail = path.split(file)
00368     if head:
00369         exec_func(file, *argrest)
00370         return
00371     last_exc = saved_exc = None
00372     saved_tb = None
00373     path_list = get_exec_path(env)
00374     if name != 'nt':
00375         file = fsencode(file)
00376         path_list = map(fsencode, path_list)
00377     for dir in path_list:
00378         fullname = path.join(dir, file)
00379         try:
00380             exec_func(fullname, *argrest)
00381         except error as e:
00382             last_exc = e
00383             tb = sys.exc_info()[2]
00384             if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR
00385                 and saved_exc is None):
00386                 saved_exc = e
00387                 saved_tb = tb
00388     if saved_exc:
00389         raise saved_exc.with_traceback(saved_tb)
00390     raise last_exc.with_traceback(tb)
00391 

Here is the call graph for this function:

Here is the caller graph for this function:

def os._exists (   name) [private]

Definition at line 601 of file os.py.

00601 
00602 def _exists(name):
00603     return name in globals()
00604 
# Supply spawn*() (probably only for Unix)

Here is the caller graph for this function:

def os._fscodec ( ) [private]

Definition at line 563 of file os.py.

00563 
00564 def _fscodec():
00565     encoding = sys.getfilesystemencoding()
00566     if encoding == 'mbcs':
00567         errors = 'strict'
00568     else:
00569         errors = 'surrogateescape'
00570 
00571     def fsencode(filename):
00572         """
00573         Encode filename to the filesystem encoding with 'surrogateescape' error
00574         handler, return bytes unchanged. On Windows, use 'strict' error handler if
00575         the file system encoding is 'mbcs' (which is the default encoding).
00576         """
00577         if isinstance(filename, bytes):
00578             return filename
00579         elif isinstance(filename, str):
00580             return filename.encode(encoding, errors)
00581         else:
00582             raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
00583 
00584     def fsdecode(filename):
00585         """
00586         Decode filename from the filesystem encoding with 'surrogateescape' error
00587         handler, return str unchanged. On Windows, use 'strict' error handler if
00588         the file system encoding is 'mbcs' (which is the default encoding).
00589         """
00590         if isinstance(filename, str):
00591             return filename
00592         elif isinstance(filename, bytes):
00593             return filename.decode(encoding, errors)
00594         else:
00595             raise TypeError("expect bytes or str, not %s" % type(filename).__name__)
00596 
00597     return fsencode, fsdecode
00598 
fsencode, fsdecode = _fscodec()
def os._get_exports_list (   module) [private]

Definition at line 35 of file os.py.

00035 
00036 def _get_exports_list(module):
00037     try:
00038         return list(module.__all__)
00039     except AttributeError:
00040         return [n for n in dir(module) if n[0] != '_']

def os._get_masked_mode (   mode) [private]

Definition at line 118 of file os.py.

00118 
00119 def _get_masked_mode(mode):
00120     mask = umask(0)
00121     umask(mask)
00122     return mode & ~mask
00123 
00124 #'
00125 
00126 # Super directory utilities.
00127 # (Inspired by Eric Raymond; the doc strings are mostly his)

Here is the caller graph for this function:

def os._make_stat_result (   tup,
  dict 
) [private]

Definition at line 739 of file os.py.

00739 
00740 def _make_stat_result(tup, dict):
00741     return stat_result(tup, dict)

def os._make_statvfs_result (   tup,
  dict 
) [private]

Definition at line 751 of file os.py.

00751 
00752 def _make_statvfs_result(tup, dict):
00753     return statvfs_result(tup, dict)

def os._pickle_stat_result (   sr) [private]

Definition at line 742 of file os.py.

00742 
00743 def _pickle_stat_result(sr):
00744     (type, args) = sr.__reduce__()
00745     return (_make_stat_result, args)
00746 
00747 try:
    _copyreg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
def os._pickle_statvfs_result (   sr) [private]

Definition at line 754 of file os.py.

00754 
00755 def _pickle_statvfs_result(sr):
00756     (type, args) = sr.__reduce__()
00757     return (_make_statvfs_result, args)
00758 
00759 try:
00760     _copyreg.pickle(statvfs_result, _pickle_statvfs_result,
                     _make_statvfs_result)

Here is the call graph for this function:

def os._spawnvef (   mode,
  file,
  args,
  env,
  func 
) [private]

Definition at line 614 of file os.py.

00614 
00615     def _spawnvef(mode, file, args, env, func):
00616         # Internal helper; func is the exec*() function to use
00617         pid = fork()
00618         if not pid:
00619             # Child
00620             try:
00621                 if env is None:
00622                     func(file, args)
00623                 else:
00624                     func(file, args, env)
00625             except:
00626                 _exit(127)
00627         else:
00628             # Parent
00629             if mode == P_NOWAIT:
00630                 return pid # Caller is responsible for waiting!
00631             while 1:
00632                 wpid, sts = waitpid(pid, 0)
00633                 if WIFSTOPPED(sts):
00634                     continue
00635                 elif WIFSIGNALED(sts):
00636                     return -WTERMSIG(sts)
00637                 elif WIFEXITED(sts):
00638                     return WEXITSTATUS(sts)
00639                 else:
00640                     raise error("Not stopped, signaled or exited???")

Here is the call graph for this function:

Here is the caller graph for this function:

def os.execl (   file,
  args 
)
execl(file, *args)

Execute the executable file with argument list args, replacing the
current process. 

Definition at line 307 of file os.py.

00307 
00308 def execl(file, *args):
00309     """execl(file, *args)
00310 
00311     Execute the executable file with argument list args, replacing the
00312     current process. """
00313     execv(file, args)

def os.execle (   file,
  args 
)
execle(file, *args, env)

Execute the executable file with argument list args and
environment env, replacing the current process. 

Definition at line 314 of file os.py.

00314 
00315 def execle(file, *args):
00316     """execle(file, *args, env)
00317 
00318     Execute the executable file with argument list args and
00319     environment env, replacing the current process. """
00320     env = args[-1]
00321     execve(file, args[:-1], env)

def os.execlp (   file,
  args 
)
execlp(file, *args)

Execute the executable file (which is searched for along $PATH)
with argument list args, replacing the current process. 

Definition at line 322 of file os.py.

00322 
00323 def execlp(file, *args):
00324     """execlp(file, *args)
00325 
00326     Execute the executable file (which is searched for along $PATH)
00327     with argument list args, replacing the current process. """
00328     execvp(file, args)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.execlpe (   file,
  args 
)
execlpe(file, *args, env)

Execute the executable file (which is searched for along $PATH)
with argument list args and environment env, replacing the current
process. 

Definition at line 329 of file os.py.

00329 
00330 def execlpe(file, *args):
00331     """execlpe(file, *args, env)
00332 
00333     Execute the executable file (which is searched for along $PATH)
00334     with argument list args and environment env, replacing the current
00335     process. """
00336     env = args[-1]
00337     execvpe(file, args[:-1], env)

Here is the call graph for this function:

def os.execvp (   file,
  args 
)
execvp(file, args)

Execute the executable file (which is searched for along $PATH)
with argument list args, replacing the current process.
args may be a list or tuple of strings. 

Definition at line 338 of file os.py.

00338 
00339 def execvp(file, args):
00340     """execvp(file, args)
00341 
00342     Execute the executable file (which is searched for along $PATH)
00343     with argument list args, replacing the current process.
00344     args may be a list or tuple of strings. """
00345     _execvpe(file, args)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.execvpe (   file,
  args,
  env 
)
execvpe(file, args, env)

Execute the executable file (which is searched for along $PATH)
with argument list args and environment env , replacing the
current process.
args may be a list or tuple of strings. 

Definition at line 346 of file os.py.

00346 
00347 def execvpe(file, args, env):
00348     """execvpe(file, args, env)
00349 
00350     Execute the executable file (which is searched for along $PATH)
00351     with argument list args and environment env , replacing the
00352     current process.
00353     args may be a list or tuple of strings. """
00354     _execvpe(file, args, env)
00355 
00356 __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])

Here is the call graph for this function:

Here is the caller graph for this function:

def os.fdopen (   fd,
  args,
  kwargs 
)

Definition at line 827 of file os.py.

00827 
00828 def fdopen(fd, *args, **kwargs):
00829     if not isinstance(fd, int):
00830         raise TypeError("invalid fd type (%s, expected integer)" % type(fd))
00831     import io
00832     return io.open(fd, *args, **kwargs)

Here is the caller graph for this function:

def os.get_exec_path (   env = None)
Returns the sequence of directories that will be searched for the
named executable (similar to a shell) when launching a process.

*env* must be an environment variable dict or None.  If *env* is None,
os.environ will be used.

Definition at line 392 of file os.py.

00392 
00393 def get_exec_path(env=None):
00394     """Returns the sequence of directories that will be searched for the
00395     named executable (similar to a shell) when launching a process.
00396 
00397     *env* must be an environment variable dict or None.  If *env* is None,
00398     os.environ will be used.
00399     """
00400     # Use a local import instead of a global import to limit the number of
00401     # modules loaded at startup: the os module is always loaded at startup by
00402     # Python. It may also avoid a bootstrap issue.
00403     import warnings
00404 
00405     if env is None:
00406         env = environ
00407 
00408     # {b'PATH': ...}.get('PATH') and {'PATH': ...}.get(b'PATH') emit a
00409     # BytesWarning when using python -b or python -bb: ignore the warning
00410     with warnings.catch_warnings():
00411         warnings.simplefilter("ignore", BytesWarning)
00412 
00413         try:
00414             path_list = env.get('PATH')
00415         except TypeError:
00416             path_list = None
00417 
00418         if supports_bytes_environ:
00419             try:
00420                 path_listb = env[b'PATH']
00421             except (KeyError, TypeError):
00422                 pass
00423             else:
00424                 if path_list is not None:
00425                     raise ValueError(
00426                         "env cannot contain 'PATH' and b'PATH' keys")
00427                 path_list = path_listb
00428 
00429             if path_list is not None and isinstance(path_list, bytes):
00430                 path_list = fsdecode(path_list)
00431 
00432     if path_list is None:
00433         path_list = defpath
00434     return path_list.split(pathsep)
00435 
00436 
# Change environ to automatically call putenv(), unsetenv if they exist.

Here is the call graph for this function:

Here is the caller graph for this function:

def os.getenv (   key,
  default = None 
)
Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are str.

Definition at line 533 of file os.py.

00533 
00534 def getenv(key, default=None):
00535     """Get an environment variable, return None if it doesn't exist.
00536     The optional second argument can specify an alternate default.
00537     key, default and the result are str."""
00538     return environ.get(key, default)

Here is the caller graph for this function:

def os.getenvb (   key,
  default = None 
)
Get an environment variable, return None if it doesn't exist.
The optional second argument can specify an alternate default.
key, default and the result are bytes.

Definition at line 555 of file os.py.

00555 
00556     def getenvb(key, default=None):
00557         """Get an environment variable, return None if it doesn't exist.
00558         The optional second argument can specify an alternate default.
00559         key, default and the result are bytes."""
00560         return environb.get(key, default)

def os.makedirs (   name,
  mode = 0o777,
  exist_ok = False 
)
makedirs(path [, mode=0o777][, exist_ok=False])

Super-mkdir; create a leaf directory and all intermediate ones.
Works like mkdir, except that any intermediate path segment (not
just the rightmost) will be created if it does not exist. If the
target directory with the same mode as we specified already exists,
raises an OSError if exist_ok is False, otherwise no exception is
raised.  This is recursive.

Definition at line 128 of file os.py.

00128 
00129 def makedirs(name, mode=0o777, exist_ok=False):
00130     """makedirs(path [, mode=0o777][, exist_ok=False])
00131 
00132     Super-mkdir; create a leaf directory and all intermediate ones.
00133     Works like mkdir, except that any intermediate path segment (not
00134     just the rightmost) will be created if it does not exist. If the
00135     target directory with the same mode as we specified already exists,
00136     raises an OSError if exist_ok is False, otherwise no exception is
00137     raised.  This is recursive.
00138 
00139     """
00140     head, tail = path.split(name)
00141     if not tail:
00142         head, tail = path.split(head)
00143     if head and tail and not path.exists(head):
00144         try:
00145             makedirs(head, mode, exist_ok)
00146         except OSError as e:
00147             # be happy if someone already created the path
00148             if e.errno != errno.EEXIST:
00149                 raise
00150         if tail == curdir:           # xxx/newdir/. exists if xxx/newdir exists
00151             return
00152     try:
00153         mkdir(name, mode)
00154     except OSError as e:
00155         import stat as st
00156         if not (e.errno == errno.EEXIST and exist_ok and path.isdir(name) and
00157                 st.S_IMODE(lstat(name).st_mode) == _get_masked_mode(mode)):
00158             raise

Here is the call graph for this function:

Here is the caller graph for this function:

def os.popen (   cmd,
  mode = "r",
  buffering = -1 
)

Definition at line 782 of file os.py.

00782 
00783 def popen(cmd, mode="r", buffering=-1):
00784     if not isinstance(cmd, str):
00785         raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
00786     if mode not in ("r", "w"):
00787         raise ValueError("invalid mode %r" % mode)
00788     if buffering == 0 or buffering == None:
00789         raise ValueError("popen() does not support unbuffered streams")
00790     import subprocess, io
00791     if mode == "r":
00792         proc = subprocess.Popen(cmd,
00793                                 shell=True,
00794                                 stdout=subprocess.PIPE,
00795                                 bufsize=buffering)
00796         return _wrap_close(io.TextIOWrapper(proc.stdout), proc)
00797     else:
00798         proc = subprocess.Popen(cmd,
00799                                 shell=True,
00800                                 stdin=subprocess.PIPE,
00801                                 bufsize=buffering)
00802         return _wrap_close(io.TextIOWrapper(proc.stdin), proc)
00803 
# Helper for popen() -- a proxy for a file whose close waits for the process

Here is the caller graph for this function:

def os.removedirs (   name)
removedirs(path)

Super-rmdir; remove a leaf directory and all empty intermediate
ones.  Works like rmdir except that, if the leaf directory is
successfully removed, directories corresponding to rightmost path
segments will be pruned away until either the whole path is
consumed or an error occurs.  Errors during this latter phase are
ignored -- they generally mean that a directory was not empty.

Definition at line 159 of file os.py.

00159 
00160 def removedirs(name):
00161     """removedirs(path)
00162 
00163     Super-rmdir; remove a leaf directory and all empty intermediate
00164     ones.  Works like rmdir except that, if the leaf directory is
00165     successfully removed, directories corresponding to rightmost path
00166     segments will be pruned away until either the whole path is
00167     consumed or an error occurs.  Errors during this latter phase are
00168     ignored -- they generally mean that a directory was not empty.
00169 
00170     """
00171     rmdir(name)
00172     head, tail = path.split(name)
00173     if not tail:
00174         head, tail = path.split(head)
00175     while head and tail:
00176         try:
00177             rmdir(head)
00178         except error:
00179             break
00180         head, tail = path.split(head)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.renames (   old,
  new 
)
renames(old, new)

Super-rename; create directories as necessary and delete any left
empty.  Works like rename, except creation of any intermediate
directories needed to make the new pathname good is attempted
first.  After the rename, directories corresponding to rightmost
path segments of the old name will be pruned way until either the
whole path is consumed or a nonempty directory is found.

Note: this function can fail with the new directory structure made
if you lack permissions needed to unlink the leaf directory or
file.

Definition at line 181 of file os.py.

00181 
00182 def renames(old, new):
00183     """renames(old, new)
00184 
00185     Super-rename; create directories as necessary and delete any left
00186     empty.  Works like rename, except creation of any intermediate
00187     directories needed to make the new pathname good is attempted
00188     first.  After the rename, directories corresponding to rightmost
00189     path segments of the old name will be pruned way until either the
00190     whole path is consumed or a nonempty directory is found.
00191 
00192     Note: this function can fail with the new directory structure made
00193     if you lack permissions needed to unlink the leaf directory or
00194     file.
00195 
00196     """
00197     head, tail = path.split(new)
00198     if head and tail and not path.exists(head):
00199         makedirs(head)
00200     rename(old, new)
00201     head, tail = path.split(old)
00202     if head and tail:
00203         try:
00204             removedirs(head)
00205         except error:
00206             pass
00207 
00208 __all__.extend(["makedirs", "removedirs", "renames"])

Here is the call graph for this function:

def os.spawnl (   mode,
  file,
  args 
)
spawnl(mode, file, *args) -> integer

Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 686 of file os.py.

00686 
00687     def spawnl(mode, file, *args):
00688         """spawnl(mode, file, *args) -> integer
00689 
00690 Execute file with arguments from args in a subprocess.
00691 If mode == P_NOWAIT return the pid of the process.
00692 If mode == P_WAIT return the process's exit code if it exits normally;
00693 otherwise return -SIG, where SIG is the signal that killed it. """
00694         return spawnv(mode, file, args)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.spawnle (   mode,
  file,
  args 
)
spawnle(mode, file, *args, env) -> integer

Execute file with arguments from args in a subprocess with the
supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 695 of file os.py.

00695 
00696     def spawnle(mode, file, *args):
00697         """spawnle(mode, file, *args, env) -> integer
00698 
00699 Execute file with arguments from args in a subprocess with the
00700 supplied environment.
00701 If mode == P_NOWAIT return the pid of the process.
00702 If mode == P_WAIT return the process's exit code if it exits normally;
00703 otherwise return -SIG, where SIG is the signal that killed it. """
00704         env = args[-1]
00705         return spawnve(mode, file, args[:-1], env)
00706 

Here is the call graph for this function:

def os.spawnlp (   mode,
  file,
  args 
)
spawnlp(mode, file, *args) -> integer

Execute file (which is looked for along $PATH) with arguments from
args in a subprocess with the supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 713 of file os.py.

00713 
00714     def spawnlp(mode, file, *args):
00715         """spawnlp(mode, file, *args) -> integer
00716 
00717 Execute file (which is looked for along $PATH) with arguments from
00718 args in a subprocess with the supplied environment.
00719 If mode == P_NOWAIT return the pid of the process.
00720 If mode == P_WAIT return the process's exit code if it exits normally;
00721 otherwise return -SIG, where SIG is the signal that killed it. """
00722         return spawnvp(mode, file, args)

Here is the call graph for this function:

def os.spawnlpe (   mode,
  file,
  args 
)
spawnlpe(mode, file, *args, env) -> integer

Execute file (which is looked for along $PATH) with arguments from
args in a subprocess with the supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 723 of file os.py.

00723 
00724     def spawnlpe(mode, file, *args):
00725         """spawnlpe(mode, file, *args, env) -> integer
00726 
00727 Execute file (which is looked for along $PATH) with arguments from
00728 args in a subprocess with the supplied environment.
00729 If mode == P_NOWAIT return the pid of the process.
00730 If mode == P_WAIT return the process's exit code if it exits normally;
00731 otherwise return -SIG, where SIG is the signal that killed it. """
00732         env = args[-1]
00733         return spawnvpe(mode, file, args[:-1], env)
00734 

Here is the call graph for this function:

def os.spawnv (   mode,
  file,
  args 
)
spawnv(mode, file, args) -> integer

Execute file with arguments from args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 641 of file os.py.

00641 
00642     def spawnv(mode, file, args):
00643         """spawnv(mode, file, args) -> integer
00644 
00645 Execute file with arguments from args in a subprocess.
00646 If mode == P_NOWAIT return the pid of the process.
00647 If mode == P_WAIT return the process's exit code if it exits normally;
00648 otherwise return -SIG, where SIG is the signal that killed it. """
00649         return _spawnvef(mode, file, args, None, execv)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.spawnve (   mode,
  file,
  args,
  env 
)
spawnve(mode, file, args, env) -> integer

Execute file with arguments from args in a subprocess with the
specified environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 650 of file os.py.

00650 
00651     def spawnve(mode, file, args, env):
00652         """spawnve(mode, file, args, env) -> integer
00653 
00654 Execute file with arguments from args in a subprocess with the
00655 specified environment.
00656 If mode == P_NOWAIT return the pid of the process.
00657 If mode == P_WAIT return the process's exit code if it exits normally;
00658 otherwise return -SIG, where SIG is the signal that killed it. """
00659         return _spawnvef(mode, file, args, env, execve)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.spawnvp (   mode,
  file,
  args 
)
spawnvp(mode, file, args) -> integer

Execute file (which is looked for along $PATH) with arguments from
args in a subprocess.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 662 of file os.py.

00662 
00663     def spawnvp(mode, file, args):
00664         """spawnvp(mode, file, args) -> integer
00665 
00666 Execute file (which is looked for along $PATH) with arguments from
00667 args in a subprocess.
00668 If mode == P_NOWAIT return the pid of the process.
00669 If mode == P_WAIT return the process's exit code if it exits normally;
00670 otherwise return -SIG, where SIG is the signal that killed it. """
00671         return _spawnvef(mode, file, args, None, execvp)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.spawnvpe (   mode,
  file,
  args,
  env 
)
spawnvpe(mode, file, args, env) -> integer

Execute file (which is looked for along $PATH) with arguments from
args in a subprocess with the supplied environment.
If mode == P_NOWAIT return the pid of the process.
If mode == P_WAIT return the process's exit code if it exits normally;
otherwise return -SIG, where SIG is the signal that killed it. 

Definition at line 672 of file os.py.

00672 
00673     def spawnvpe(mode, file, args, env):
00674         """spawnvpe(mode, file, args, env) -> integer
00675 
00676 Execute file (which is looked for along $PATH) with arguments from
00677 args in a subprocess with the supplied environment.
00678 If mode == P_NOWAIT return the pid of the process.
00679 If mode == P_WAIT return the process's exit code if it exits normally;
00680 otherwise return -SIG, where SIG is the signal that killed it. """
00681         return _spawnvef(mode, file, args, env, execvpe)

Here is the call graph for this function:

Here is the caller graph for this function:

def os.urandom (   n)
urandom(n) -> str

Return a string of n random bytes suitable for cryptographic use.

Definition at line 765 of file os.py.

00765 
00766     def urandom(n):
00767         """urandom(n) -> str
00768 
00769         Return a string of n random bytes suitable for cryptographic use.
00770 
00771         """
00772         try:
00773             _urandomfd = open("/dev/urandom", O_RDONLY)
00774         except (OSError, IOError):
00775             raise NotImplementedError("/dev/urandom (or equivalent) not found")
00776         bs = b""
00777         while len(bs) < n:
00778             bs += read(_urandomfd, n - len(bs))
00779         close(_urandomfd)
00780         return bs
00781 
# Supply os.popen()

Here is the call graph for this function:

Here is the caller graph for this function:

def os.walk (   top,
  topdown = True,
  onerror = None,
  followlinks = False 
)
Directory tree generator.

For each directory in the directory tree rooted at top (including top
itself, but excluding '.' and '..'), yields a 3-tuple

    dirpath, dirnames, filenames

dirpath is a string, the path to the directory.  dirnames is a list of
the names of the subdirectories in dirpath (excluding '.' and '..').
filenames is a list of the names of the non-directory files in dirpath.
Note that the names in the lists are just names, with no path components.
To get a full path (which begins with top) to a file or directory in
dirpath, do os.path.join(dirpath, name).

If optional arg 'topdown' is true or not specified, the triple for a
directory is generated before the triples for any of its subdirectories
(directories are generated top down).  If topdown is false, the triple
for a directory is generated after the triples for all of its
subdirectories (directories are generated bottom up).

When topdown is true, the caller can modify the dirnames list in-place
(e.g., via del or slice assignment), and walk will only recurse into the
subdirectories whose names remain in dirnames; this can be used to prune
the search, or to impose a specific order of visiting.  Modifying
dirnames when topdown is false is ineffective, since the directories in
dirnames have already been generated by the time dirnames itself is
generated.

By default errors from the os.listdir() call are ignored.  If
optional arg 'onerror' is specified, it should be a function; it
will be called with one argument, an os.error instance.  It can
report the error to continue with the walk, or raise the exception
to abort the walk.  Note that the filename is available as the
filename attribute of the exception object.

By default, os.walk does not follow symbolic links to subdirectories on
systems that support them.  In order to get this functionality, set the
optional argument 'followlinks' to true.

Caution:  if you pass a relative pathname for top, don't change the
current working directory between resumptions of walk.  walk never
changes the current directory, and assumes that the client doesn't
either.

Example:

import os
from os.path import join, getsize
for root, dirs, files in os.walk('python/Lib/email'):
    print(root, "consumes", end="")
    print(sum([getsize(join(root, name)) for name in files]), end="")
    print("bytes in", len(files), "non-directory files")
    if 'CVS' in dirs:
        dirs.remove('CVS')  # don't visit CVS directories

Definition at line 209 of file os.py.

00209 
00210 def walk(top, topdown=True, onerror=None, followlinks=False):
00211     """Directory tree generator.
00212 
00213     For each directory in the directory tree rooted at top (including top
00214     itself, but excluding '.' and '..'), yields a 3-tuple
00215 
00216         dirpath, dirnames, filenames
00217 
00218     dirpath is a string, the path to the directory.  dirnames is a list of
00219     the names of the subdirectories in dirpath (excluding '.' and '..').
00220     filenames is a list of the names of the non-directory files in dirpath.
00221     Note that the names in the lists are just names, with no path components.
00222     To get a full path (which begins with top) to a file or directory in
00223     dirpath, do os.path.join(dirpath, name).
00224 
00225     If optional arg 'topdown' is true or not specified, the triple for a
00226     directory is generated before the triples for any of its subdirectories
00227     (directories are generated top down).  If topdown is false, the triple
00228     for a directory is generated after the triples for all of its
00229     subdirectories (directories are generated bottom up).
00230 
00231     When topdown is true, the caller can modify the dirnames list in-place
00232     (e.g., via del or slice assignment), and walk will only recurse into the
00233     subdirectories whose names remain in dirnames; this can be used to prune
00234     the search, or to impose a specific order of visiting.  Modifying
00235     dirnames when topdown is false is ineffective, since the directories in
00236     dirnames have already been generated by the time dirnames itself is
00237     generated.
00238 
00239     By default errors from the os.listdir() call are ignored.  If
00240     optional arg 'onerror' is specified, it should be a function; it
00241     will be called with one argument, an os.error instance.  It can
00242     report the error to continue with the walk, or raise the exception
00243     to abort the walk.  Note that the filename is available as the
00244     filename attribute of the exception object.
00245 
00246     By default, os.walk does not follow symbolic links to subdirectories on
00247     systems that support them.  In order to get this functionality, set the
00248     optional argument 'followlinks' to true.
00249 
00250     Caution:  if you pass a relative pathname for top, don't change the
00251     current working directory between resumptions of walk.  walk never
00252     changes the current directory, and assumes that the client doesn't
00253     either.
00254 
00255     Example:
00256 
00257     import os
00258     from os.path import join, getsize
00259     for root, dirs, files in os.walk('python/Lib/email'):
00260         print(root, "consumes", end="")
00261         print(sum([getsize(join(root, name)) for name in files]), end="")
00262         print("bytes in", len(files), "non-directory files")
00263         if 'CVS' in dirs:
00264             dirs.remove('CVS')  # don't visit CVS directories
00265     """
00266 
00267     islink, join, isdir = path.islink, path.join, path.isdir
00268 
00269     # We may not have read permission for top, in which case we can't
00270     # get a list of the files the directory contains.  os.walk
00271     # always suppressed the exception then, rather than blow up for a
00272     # minor reason when (say) a thousand readable directories are still
00273     # left to visit.  That logic is copied here.
00274     try:
00275         # Note that listdir and error are globals in this module due
00276         # to earlier import-*.
00277         names = listdir(top)
00278     except error as err:
00279         if onerror is not None:
00280             onerror(err)
00281         return
00282 
00283     dirs, nondirs = [], []
00284     for name in names:
00285         if isdir(join(top, name)):
00286             dirs.append(name)
00287         else:
00288             nondirs.append(name)
00289 
00290     if topdown:
00291         yield top, dirs, nondirs
00292     for name in dirs:
00293         new_path = join(top, name)
00294         if followlinks or not islink(new_path):
00295             for x in walk(new_path, topdown, onerror, followlinks):
00296                 yield x
00297     if not topdown:
00298         yield top, dirs, nondirs
00299 
00300 __all__.append("walk")
00301 
00302 # Make sure os.environ exists, at least
00303 try:
    environ

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

list os.__all__
Initial value:
00001 ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
00002            "defpath", "name", "path", "devnull",
00003            "SEEK_SET", "SEEK_CUR", "SEEK_END"]

Definition at line 31 of file os.py.

os._names = sys.builtin_module_names

Definition at line 28 of file os.py.

os._putenv = lambdakey,value:None

Definition at line 487 of file os.py.

tuple os._unsetenv = unsetenv

Definition at line 492 of file os.py.

tuple os.environ = {}

Definition at line 305 of file os.py.

tuple os.environb
Initial value:
00001 _Environ(environ._data,
00002         _check_bytes, bytes,
00003         _check_bytes, bytes,
00004         _putenv, _unsetenv)

Definition at line 549 of file os.py.

Definition at line 43 of file os.py.

string os.name = 'posix'

Definition at line 42 of file os.py.

Definition at line 608 of file os.py.

Definition at line 607 of file os.py.

Definition at line 114 of file os.py.

Definition at line 115 of file os.py.

Definition at line 113 of file os.py.

tuple os.supports_bytes_environ = namenotin('os2', 'nt')

Definition at line 539 of file os.py.