Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/os.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c@s�dZddkZeiZddddddd	d
ddd
ddg
Zd�ZdejordZdZddkTyddkl	Z	Wne
j
onXddkZddkZei
ee��[n�dejordZdZddkTyddkl	Z	Wne
j
onXddkZddkZei
ee��[n?dejo�dZdZddkTyddkl	Z	Wne
j
onXeiid�djoddkZnddkZddklZddkZei
ee��[n�dejordZdZddkTyddkl	Z	Wne
j
onXddkZddkZei
ee��[ndejordZdZddkTyddkl	Z	Wne
j
onXddkZddkZei
ee��[n�dejordZdZddkTyddkl	Z	Wne
j
onXddkZddkZei
ee��[n
e
d�eeid<dd klZlZlZl Z l!Z!l"Z"l#Z#l$Z$[d!Z%d"Z&d#Z'd$d%�Z(d&�Z)d'�Z*ei
d(d)d*g�e+dd+�Z-ei.d,�ye/Wne0j
o
hZ/nXd-�Z1d.�Z2d/�Z3d0�Z4d1�Z5d2�Z6ei
d3d4d5d6d7d8g�dd9�Z7ye8Wne0j
on�Xddk9Z9edbjo
d:�Z:nedjodd;k;l<Z<nDedcjod<e9i=fd=��YZ<nd<e9i=fd>��YZ<e<e/�Z/dd?�Z>ei.d@�dA�Z?e?dB�o\e?dC�oNe?dD�oAd!Z@d"ZAZBdE�ZCdF�ZDdG�ZEdH�ZFdI�ZGne?dC�o/dJ�ZHdK�ZIei
dCdLdMdNg�ne?dO�o/dP�ZJdQ�ZKei
dOdRdSdTg�ne?dB�o�e?dU�p dVddW�ZLei.dU�ne?dX�p dVddY�ZMei.dX�ne?dZ�p dVdd[�ZNei.dZ�q
nddkOZPd\�ZQd]�ZRyePiSeTeReQ�Wne0j
onXd^�ZUd_�ZVyePiSeWeVeU�Wne0j
onXe?d`�p
da�ZXndS(ds�OS routines for Mac, NT, or Posix depending on what system we're on.

This exports:
  - all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc.
  - os.path is one of the modules posixpath, ntpath, or macpath
  - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos'
  - os.curdir is a string representing the current directory ('.' or ':')
  - os.pardir is a string representing the parent directory ('..' or '::')
  - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
  - os.extsep is the extension separator ('.' or '/')
  - os.altsep is the alternate pathname separator (None or '/')
  - os.pathsep is the component separator used in $PATH etc
  - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
  - os.defpath is the default search path for executables
  - os.devnull is the file path of the null device ('/dev/null', etc.)

Programs that import and use 'os' stand a better chance of being
portable between different platforms.  Of course, they must then
only use functions that are defined by all platforms (e.g., unlink
and opendir), and leave all pathname manipulation to os.path
(e.g., split and join).
i�NtaltseptcurdirtpardirtseptpathseptlineseptdefpathtnametpathtdevnulltSEEK_SETtSEEK_CURtSEEK_ENDcCseyt|i�SWnMtj
oAg}t|�D]"}|ddjo||q3q3~SnXdS(Nit_(tlistt__all__tAttributeErrortdir(tmodulet_[1]tn((s/sys/lib/python/os.pyt_get_exports_list#stposixs
(t*(t_exittnts
tos2sEMX GCC(tlinktmacs
tcetriscossno os specific module foundsos.path(RRRRRtextsepRR	iiii�cCs�ddkl}ti|�\}}|pti|�\}}n|oq|ojti|�oYyt||�Wn,tj
o }|i|jo�q�nX|tjodSq�nt||�dS(smakedirs(path [, mode=0777])

    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.  This is
    recursive.

    i�(tEEXISTN(	terrnoR RtsplittexiststmakedirstOSErrorRtmkdir(RtmodeR theadttailte((s/sys/lib/python/os.pyR$�s	
cCs�t|�ti|�\}}|pti|�\}}nxM|oE|o>yt|�Wntj
oPnXti|�\}}qBWdS(s�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.

    N(trmdirRR"terror(RR(R)((s/sys/lib/python/os.pyt
removedirs�s
cCs�ti|�\}}|o&|oti|�ot|�nt||�ti|�\}}|o/|o(yt|�Wq�tj
oq�XndS(s@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.

    N(RR"R#R$trenameR-R,(toldtnewR(R)((s/sys/lib/python/os.pytrenames�s
R$R-R1c
cs>ddkl}l}l}yt|�}Wn4tj
o(}|dj	o||�ndSnXgg}}	xB|D]:}
||||
��o|i|
�qw|	i|
�qwW|o|||	fVnxP|D]H}
|||
�}||�p&x#t|||�D]}|Vq
Wq�q�W|p|||	fVndS(se	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.

    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:

    from os.path import join, getsize
    for root, dirs, files in walk('python/Lib/email'):
        print root, "consumes",
        print sum([getsize(join(root, name)) for name in files]),
        print "bytes in", len(files), "non-directory files"
        if 'CVS' in dirs:
            dirs.remove('CVS')  # don't visit CVS directories
    i�(tjointisdirtislinkN(	tos.pathR2R3R4tlistdirR,tNonetappendtwalk(
ttopttopdowntonerrorR2R3R4tnamesterrtdirstnondirsRRtx((s/sys/lib/python/os.pyR9�s04
	

R9cGst||�dS(spexecl(file, *args)

    Execute the executable file with argument list args, replacing the
    current process. N(texecv(tfiletargs((s/sys/lib/python/os.pytexecl=scGs"|d}t||d |�dS(s�execle(file, *args, env)

    Execute the executable file with argument list args and
    environment env, replacing the current process. i�N(texecve(RCRDtenv((s/sys/lib/python/os.pytexecleDs
cGst||�dS(s�execlp(file, *args)

    Execute the executable file (which is searched for along $PATH)
    with argument list args, replacing the current process. N(texecvp(RCRD((s/sys/lib/python/os.pytexeclpLscGs"|d}t||d |�dS(s�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. i�N(texecvpe(RCRDRG((s/sys/lib/python/os.pytexeclpeSs
cCst||�dS(s�execp(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. N(t_execvpe(RCRD((s/sys/lib/python/os.pyRI\scCst|||�dS(s�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. N(RM(RCRDRG((s/sys/lib/python/os.pyRKdsRERHRJRLRIRKcCs{ddkl}l}|dj	ot}||f}nt}|f}t}ti|�\}}|o|||�dSnd|jo|d}	nt	}	|	it
�}
d}d}x�|
D]�}
ti|
|�}y|||�Wq�tj
oV}t
i�d}|i|jo-|i|jo|djo|}|}qPq�Xq�W|ot||�nt||�dS(Ni�(tENOENTtENOTDIRtPATHi(R!RNROR7RFRBtenvironRR"RRR2R,tsystexc_info(RCRDRGRNROtfunctargrestR(R)tenvpathRPt	saved_exctsaved_tbRtfullnameR*ttb((s/sys/lib/python/os.pyRMos>
	

 
cCst|d�dS(Nt(tputenv(tkey((s/sys/lib/python/os.pytunsetenv�s(t_EnvironR_cBs�eZd�Zd�Zd�ZyeWnej
od�ZnXd�Zd�Zd�Z	d
d�Zd
d�Zd	�Z
RS(cCsJtii|�|i}x*|i�D]\}}|||i�<q&WdS(N(tUserDictt__init__tdatatitemstupper(tselfRQRbtktv((s/sys/lib/python/os.pyRa�s
	
cCs$t||�||i|i�<dS(N(R\RbRd(ReR]titem((s/sys/lib/python/os.pyt__setitem__�s
cCs|i|i�S(N(RbRd(ReR]((s/sys/lib/python/os.pyt__getitem__�scCs|i|i�=dS(N(RbRd(ReR]((s/sys/lib/python/os.pyt__delitem__�scCst|�|i|i�=dS(N(R^RbRd(ReR]((s/sys/lib/python/os.pyRk�s
cCs|i�|ijS(N(RdRb(ReR]((s/sys/lib/python/os.pythas_key�scCs|i�|ijS(N(RdRb(ReR]((s/sys/lib/python/os.pyt__contains__�scCs|ii|i�|�S(N(RbtgetRd(ReR]tfailobj((s/sys/lib/python/os.pyRn�scKs�|ojy|i�}Wn4tj
o(xB|D]\}}|||<q/WqqXx |D]}||||<qUWn|o|i|�ndS(N(tkeysRtupdate(RetdicttkwargsRpRfRg((s/sys/lib/python/os.pyRq�scCs
t|�S(N(Rr(Re((s/sys/lib/python/os.pytcopy�sN(t__name__t
__module__RaRiRjR^t	NameErrorRkRlRmR7RnRqRt(((s/sys/lib/python/os.pyR_�s						cBsVeZd�Zd�Zdd�ZyeWnej
onXd�Zd�Z	RS(cCstii|�||_dS(N(R`RaRb(ReRQ((s/sys/lib/python/os.pyRa�scCst||�||i|<dS(N(R\Rb(ReR]Rh((s/sys/lib/python/os.pyRi�s
cKs�|ojy|i�}Wn4tj
o(xB|D]\}}|||<q/WqqXx |D]}||||<qUWn|o|i|�ndS(N(RpRRq(ReRrRsRpRfRg((s/sys/lib/python/os.pyRq�scCst|�|i|=dS(N(R^Rb(ReR]((s/sys/lib/python/os.pyRk�s
cCs
t|�S(N(Rr(Re((s/sys/lib/python/os.pyRt�sN(
RuRvRaRiR7RqR^RwRkRt(((s/sys/lib/python/os.pyR_�s			cCsti||�S(s�Get an environment variable, return None if it doesn't exist.
    The optional second argument can specify an alternate default.(RQRn(R]tdefault((s/sys/lib/python/os.pytgetenv�sRycCs0yt|�tSWntj
otSnXdS(N(tevaltTrueRwtFalse(R((s/sys/lib/python/os.pyt_existss

tforktspawnvRBcCs�t�}|pJy2|djo|||�n||||�Wq�td�q�Xn�|tjo|Snxlt|d�\}}t|�oqrqrt|�ot|�Sqrt|�ot	|�Sqrt
d�qrdS(Niis"Not stopped, signaled or exited???(R~R7RtP_NOWAITtwaitpidt
WIFSTOPPEDtWIFSIGNALEDtWTERMSIGt	WIFEXITEDtWEXITSTATUSR,(R'RCRDRGRTtpidtwpidtsts((s/sys/lib/python/os.pyt	_spawnvefs&	




cCst|||dt�S(sspawnv(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. N(R�R7RB(R'RCRD((s/sys/lib/python/os.pyR.scCst||||t�S(s: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. (R�RF(R'RCRDRG((s/sys/lib/python/os.pytspawnve7scCst|||dt�S(s8spawnvp(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. N(R�R7RI(R'RCRD((s/sys/lib/python/os.pytspawnvpCscCst||||t�S(s\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. (R�RK(R'RCRDRG((s/sys/lib/python/os.pytspawnvpeMscGst|||�S(sspawnl(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. (R(R'RCRD((s/sys/lib/python/os.pytspawnl[scGs!|d}t|||d |�S(s: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. i�(R�(R'RCRDRG((s/sys/lib/python/os.pytspawnleds
R�R�R�R�cGst|||�S(sWspawnlp(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. (R�(R'RCRD((s/sys/lib/python/os.pytspawnlpvscGs!|d}t|||d |�S(s]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. i�(R�(R'RCRDRG((s/sys/lib/python/os.pytspawnlpe�s
R�R�R�tpopen2ttcCs.ddk}|i||�\}}||fS(s�Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
            may be a sequence, in which case arguments will be passed directly to
            the program without shell intervention (as with os.spawnv()).  If 'cmd'
            is a string it will be passed to the shell (as with os.system()). If
            'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
            file objects (child_stdin, child_stdout) are returned.i�N(R�(tcmdR'tbufsizeR�tstdouttstdin((s/sys/lib/python/os.pyR��stpopen3cCs4ddk}|i||�\}}}|||fS(s�Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
            may be a sequence, in which case arguments will be passed directly to
            the program without shell intervention (as with os.spawnv()).  If 'cmd'
            is a string it will be passed to the shell (as with os.system()). If
            'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
            file objects (child_stdin, child_stdout, child_stderr) are returned.i�N(R�R�(R�R'R�R�R�R�tstderr((s/sys/lib/python/os.pyR��stpopen4cCs.ddk}|i||�\}}||fS(s�Execute the shell command 'cmd' in a sub-process.  On UNIX, 'cmd'
            may be a sequence, in which case arguments will be passed directly to
            the program without shell intervention (as with os.spawnv()).  If 'cmd'
            is a string it will be passed to the shell (as with os.system()). If
            'bufsize' is specified, it sets the buffer size for the I/O pipes.  The
            file objects (child_stdin, child_stdout_stderr) are returned.i�N(R�R�(R�R'R�R�R�R�((s/sys/lib/python/os.pyR��scCs
t||�S(N(tstat_result(ttupRr((s/sys/lib/python/os.pyt_make_stat_result�scCs|i�\}}t|fS(N(t
__reduce__R�(tsrttypeRD((s/sys/lib/python/os.pyt_pickle_stat_result�scCs
t||�S(N(tstatvfs_result(R�Rr((s/sys/lib/python/os.pyt_make_statvfs_result�scCs|i�\}}t|fS(N(R�R�(R�R�RD((s/sys/lib/python/os.pyt_pickle_statvfs_result�sturandomc	Cs�ytdt�}Wn%ttfj
otd��nXd}x5t|�|jo!|t||t|��7}qDWt|�|S(sfurandom(n) -> str

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

        s/dev/randoms&/dev/urandom (or equivalent) not foundR[(topentO_RDONLYR%tIOErrortNotImplementedErrortlentreadtclose(Rt
_urandomfdtbytes((s/sys/lib/python/os.pyR��s"
(sos2snt(sos2snt(Yt__doc__RRtbuiltin_module_namest_namesRRRRRRtImportErrort	posixpathRtextendRtntpathRtversiontfindt
os2emxpatht	_emx_linkRRtmacpathRRt
riscospathtmodulesR5RRRRRRRR	R
RRR$R-R1R{R7R9R8RQRwRERHRJRLRIRKRMR\R`R^t
riscosenvironR_tIterableUserDictRyR}tP_WAITR�t	P_NOWAITOR�RR�R�R�R�R�R�R�R�R�R�tcopy_regt	_copy_regR�R�tpickleR�R�R�R�R�(((s/sys/lib/python/os.pys<module>sH		











	
:		U
								%



.#
	(
					


			
	
	






				


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.