U e5dS@sdZddlZddlZddlZddlmZejZdddddd d d d d dddddddddgZ ddZ ddZ dekrdZ dZ ddlTzddlmZe dWnek rYnXddlZzdd lmZWnek rYnXddlZe e e[nd!ekrd!Z d"Z ddlTzddlmZe dWnek rBYnXddlZddlZe e e[zdd lmZWnek rYnXned#eejd$<dd%lmZmZmZmZmZmZm Z m!Z![e d&re"Z#d'd(Z$e%Z&e$d)d*e$d+d,e$d-d.e$d/d0e$d1d2e$d3d4e$d5d6e$d7d8e$d9d:e$d;d<e$d=d>e$d?d@e$dAdBe$dCdDe$dCdEe$dFd2e&Z'e%Z&e$d)d*e&Z(e%Z&e$dGdHe$dId,e$dJd.e$dKdLe$dKdMe$dNdOe&)ee$dPdQe$dRd2e$dSd2e$dTdUe dVr2e dWr2e$dXdVe&Z*e%Z&e$d)d*e$d-d.e$d/d0e$dYdZe$d[d,e d\re$d]d.e$d3d4e$d^d2e$d_d0e$d/d0e$dFd2e$d`d0e&Z+[&[[#[$dZ,daZ-dbZ.ddedfZ/dgdhZ0didjZ1e dfdhdjgddldmZ2e dme3ehe'krTe4ehe*krTdddddodpdqZ5drdsZ6e dqdtduZ7dvdwZ8dxdyZ9dzd{Z:d|d}Z;d~dZddlm?Z?Gddde?Z@zeAZBWneCk rddZBYnXde kre dzeDZEWneCk r,ddZEYnXde krBe dddZFeFZG[FdddZHe d!kZIe deIrddZJe@eGjKeJeLeJeLeBeEZM[JdddZNe dddZOeO\ZPZQ[Oe dr0e ds0e dr0dZRdaZSZTe dddgddZUddZVddZWddZXddZYe ddddge drXddZZddZ[e ddge drddZ\ddZ]e ddgdddZ^GdddZ_ddZ`ddZae dseaZbdeb_cGdddejdZee d!krGdddZfddZgdS)aNOS routines for NT or Posix depending on what system we're on. This exports: - all functions from posix or nt, e.g. unlink, stat, etc. - os.path is either posixpath or ntpath - os.name is either 'posix' or 'nt' - os.curdir is a string representing the current directory (always '.') - os.pardir is a string representing the parent directory (always '..') - os.sep is the (or a most common) pathname separator ('/' or '\\') - os.extsep is the extension separator (always '.') - 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). N)_check_methodsaltsepcurdirpardirseppathseplinesepdefpathnamepathdevnullSEEK_SETSEEK_CURSEEK_ENDfsencodefsdecode get_exec_pathfdopenpopenextsepcCs |tkSN)globals)r r/usr/lib64/python3.8/os.py_exists'srcCs8z t|jWStk r2ddt|DYSXdS)NcSsg|]}|ddkr|qS)r_r).0nrrr .s z%_get_exports_list..)list__all__AttributeErrordir)modulerrr_get_exports_list*s r$posix )*)_exitr()_have_functionsntz zno os specific module foundzos.path)rrrrr rrr r)cCs"|tkr|tkrtt|dSr)_globalsr)_setadd)strfnrrr_addfsr0ZHAVE_FACCESSATaccessZ HAVE_FCHMODATchmodZ HAVE_FCHOWNATchownZ HAVE_FSTATATstatZHAVE_FUTIMESATutimeZ HAVE_LINKATlinkZ HAVE_MKDIRATmkdirZ HAVE_MKFIFOATmkfifoZ HAVE_MKNODATmknodZ HAVE_OPENATopenZHAVE_READLINKATreadlinkZ HAVE_RENAMEATrenameZHAVE_SYMLINKATsymlinkZ HAVE_UNLINKATunlinkrmdirZHAVE_UTIMENSATZ HAVE_FCHDIRchdirZ HAVE_FCHMODZ HAVE_FCHOWNZHAVE_FDOPENDIRlistdirscandirZ HAVE_FEXECVEexecveZHAVE_FTRUNCATEtruncateZ HAVE_FUTIMENSZ HAVE_FUTIMESZHAVE_FPATHCONFpathconfstatvfsfstatvfsZ HAVE_FSTATVFSZ HAVE_LCHFLAGSZchflagsZ HAVE_LCHMODlchownZ HAVE_LCHOWNZ HAVE_LUTIMESZ HAVE_LSTATZ MS_WINDOWSFcCst|\}}|s t|\}}|r||r|t|s|zt||dWntk rVYnXt}t|trpttd}||kr|dSzt||Wn$t k r|rt |sYnXdS)amakedirs(name [, 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 already exists, raise an OSError if exist_ok is False. Otherwise no exception is raised. This is recursive. )exist_okASCIIN) r splitexistsmakedirsFileExistsErrorr isinstancebytesr7OSErrorisdir)r moderLheadtailcdirrrrrPs$   rPcCsjt|t|\}}|s(t|\}}|rf|rfz t|Wntk rTYqfYnXt|\}}q(dS)aremovedirs(name) 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)r?r rNrT)r rWrXrrr removedirss   rZcCsnt|\}}|r(|r(t|s(t|t||t|\}}|rj|rjz t|Wntk rhYnXdS)a<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 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)r rNrOrPr<rZrT)oldnewrWrXrrrrenamess  r]Tc cst|}g}g}g}z t|}Wn8tk rX}z|dk rB||WYdSd}~XYnX|z.z t|} Wntk rYWqpYnXWnBtk r}z$|dk r||WYW5QRdSd}~XYnXz | } Wntk rd} YnX| r|| jn || j|sb| rb|r0d} n.z | } Wntk rVd} YnX| } | rb|| j qbW5QRX|r|||fVt j t j } }|D]4}|||}|s| |st ||||EdHqn,|D]}t ||||EdHq|||fVdS)a 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 has no effect on the behavior of os.walk(), since the directories in dirnames have already been generated by the time dirnames itself is generated. No matter the value of topdown, the list of subdirectories is retrieved before the tuples for the directory and its subdirectories are generated. By default errors from the os.scandir() call are ignored. If optional arg 'onerror' is specified, it should be a function; it will be called with one argument, an OSError 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 NFT) fspathrBrTnext StopIterationis_dirappendr is_symlinkr islinkjoinwalk)toptopdownonerror followlinksdirsnondirs walk_dirs scandir_iterrorentryra walk_intorcrdredirnamenew_pathrrrrfs^;  "       rf.follow_symlinksdir_fdccst|trt|dst|}|s.t|d|d}t|t|d}zB|s^t |j r|t |t|r|t ||t|t|||EdHW5t|XdS)aDirectory tree generator. This behaves exactly like walk(), except that it yields a 4-tuple dirpath, dirnames, filenames, dirfd `dirpath`, `dirnames` and `filenames` are identical to walk() output, and `dirfd` is a file descriptor referring to the directory `dirpath`. The advantage of fwalk() over walk() is that it's safe against symlink races (when follow_symlinks is False). If dir_fd is not None, it should be a file descriptor open to a directory, and top should be relative; top will then be relative to that directory. (dir_fd is always supported for fwalk.) Caution: Since fwalk() yields file descriptors, those are only valid until the next iteration step, so you should dup() them if you want to keep them for a longer period. Example: import os for root, dirs, files, rootfd in os.fwalk('python/Lib/email'): print(root, "consumes", end="") print(sum(os.stat(name, dir_fd=rootfd).st_size 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 __index__FrurwN)rRinthasattrr^r4r:O_RDONLYclosestS_ISDIRst_moder samestat_fwalkrS)rgrhrirvrworig_sttopfdrrrfwalks!rc cst|}g}g}|s|rdng} |D]} | j} |r:t| } z4| rb|| | dk rl| | n || Wq$tk rz| r|| Wntk rYnXYq$Xq$|r||||fV| dkr|nt|| D]} z@|s|rt| |dd} n| \} } | jdd} t | t |d} Wn>tk r\}z|dk rD||WYqW5d}~XYnXz@|sxt | t| rt || }t| |||||EdHW5t | Xq|s||||fVdS)NF)rwrv)rvry)rBr rrarbrTrczipr4r:r|r}r rrer)rtoppathisbytesrhrirvrnrkrlentriesrpr rdirfderrdirpathrrrrsZ      rcGst||dS)zpexecl(file, *args) Execute the executable file with argument list args, replacing the current process. N)execvfileargsrrrexeclsrcGs |d}t||dd|dS)zexecle(file, *args, env) Execute the executable file with argument list args and environment env, replacing the current process. N)rCrrenvrrrexeclesrcGst||dS)zexeclp(file, *args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. N)execvprrrrexeclp"srcGs |d}t||dd|dS)zexeclpe(file, *args, env) Execute the executable file (which is searched for along $PATH) with argument list args and environment env, replacing the current process. rN)execvperrrrexeclpe)srcCst||dS)zexecvp(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_execvperrrrr2srcCst|||dS)zexecvpe(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. Nrrrrrr:src Cs|dk rt}||f}nt}|f}t}t|r@||f|dSd}t|}tdkrft|}tt|}|D]~}t ||}z||f|Wqjt t fk r} z| } W5d} ~ XYqjt k r} z| } |dkr| }W5d} ~ XYqjXqj|dk r|| dS)Nr*) rCrenvironr rrrr rmapreFileNotFoundErrorNotADirectoryErrorrT) rrr exec_funcargrest saved_exc path_listr"fullnameelast_excrrrrEs6    rc Csddl}|dkrt}||dtz|d}Wntk rPd}YnXtrz |d}Wnttfk rzYnX|dk rt d|}|dk rt |t rt |}W5QRX|dkrt }|tS)zReturns 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. rNignorePATHsPATHz*env cannot contain 'PATH' and b'PATH' keys)warningsrcatch_warnings simplefilter BytesWarningget TypeErrorsupports_bytes_environKeyError ValueErrorrRrSrr rNr)rrr path_listbrrrres0     )MutableMappingc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)_EnvironcCs.||_||_||_||_||_||_||_dSr) encodekey decodekey encodevalue decodevalueputenvunsetenv_data)selfdatarrrrrrrrr__init__sz_Environ.__init__cCs>z|j||}Wntk r2t|dYnX||Sr)rrrrrkeyvaluerrr __getitem__s z_Environ.__getitem__cCs.||}||}|||||j|<dSr)rrrrrrrr __setitem__s   z_Environ.__setitem__cCsD||}||z |j|=Wntk r>t|dYnXdSr)rrrr)rr encodedkeyrrr __delitem__s    z_Environ.__delitem__ccs$t|j}|D]}||VqdSr)rrr)rkeysrrrr__iter__s z_Environ.__iter__cCs t|jSr)lenrrrrr__len__sz_Environ.__len__cs$ddfddjDS)Nzenviron({{{}}})z, c3s*|]"\}}d||VqdS)z {!r}: {!r}N)formatrr)rrrrrr sz$_Environ.__repr__..)rreritemsrrrr__repr__s  z_Environ.__repr__cCst|Sr)dictrrrrcopysz _Environ.copycCs||kr|||<||Srrrrrr setdefaultsz_Environ.setdefaultN) __name__ __module__ __qualname__rrrrrrrrrrrrrrs  rcCsdSrr)rrrrrrrcCs t|dS)N)_putenvrrrrrrrcstdkrHdd}|t}fdd}i}tD]\}}||||<q0n(tfddfdd }}t}t||||ttS) Nr*cSs t|tstdt|j|S)Nstr expected, not %s)rRr.rtyperrrrr check_strs z!_createenviron..check_strcs |Sr)upperr)encoderrrsz!_createenviron..encodekeycs(t|tstdt|j|dS)Nrsurrogateescape)rRr.rrrrrencodingrrrs z_createenviron..encodecs |dS)Nr)decoderrrrrsz_createenviron..decode) r r.rrsysgetfilesystemencodingrr _unsetenv)rrrrrrr)rrr_createenvirons*   rcCs t||S)zGet 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.)rrrdefaultrrrgetenvsr)rrcCs t|tstdt|j|S)Nzbytes expected, not %s)rRrSrrrrrrr _check_bytess rcCs t||S)zGet 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.)environbrrrrrgetenvbsr)rrcs4ttfdd}fdd}||fS)Ncs&t|}t|tr|S|SdS)aEncode filename (an os.PathLike, bytes, or str) to the filesystem encoding with 'surrogateescape' error handler, return bytes unchanged. On Windows, use 'strict' error handler if the file system encoding is 'mbcs' (which is the default encoding). N)r^rRr.rfilenamererrorsrrr s  z_fscodec..fsencodecs&t|}t|tr|S|SdS)aDecode filename (an os.PathLike, bytes, or str) from the filesystem encoding with 'surrogateescape' error handler, return str unchanged. On Windows, use 'strict' error handler if the file system encoding is 'mbcs' (which is the default encoding). N)r^rRrSrrrrrr,s  z_fscodec..fsdecode)rrgetfilesystemencodeerrors)rrrrr_fscodecs   rforkspawnvrP_WAITP_NOWAIT P_NOWAITOcCst|ttfstd|r"|ds*tdt}|spz$|dkrJ|||n ||||WqtdYqXnR|tkr||St|d\}}t |rq|q|t |rt | St |rt |Stdq|dS)Nzargv must be a tuple or a listrz"argv first element cannot be emptyz"Not stopped, signaled or exited???)rRtuplerrrrr(rwaitpid WIFSTOPPED WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUSrT)rVrrrfuncpidwpidstsrrr _spawnvefIs,   rcCst|||dtS)aspawnv(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)rrrVrrrrrrhscCst||||tS)a: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. )rrCrVrrrrrrspawnveqsrcCst|||dtS)a8spawnvp(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)rrrrrrspawnvp}sr cCst||||tS)a\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. )rrrrrrspawnvpesr cGs t|||S)aspawnl(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. )rrrrrspawnlsr cGs|d}t|||dd|S)a: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. rN)rrrrrspawnlesr cGs t|||S)aWspawnlp(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 rrrrspawnlpsr cGs|d}t|||dd|S)a]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. rN)r rrrrspawnlpesrrrcCst|tstdt||dkr.td||dks>|dkrFtdddl}ddl}|dkr|j|d|j|d}t | |j |S|j|d|j|d }t | |j |SdS) Nz&invalid cmd type (%s, expected string))rwzinvalid mode %rrz+popen() does not support unbuffered streamsrT)shellstdoutbufsize)rstdinr) rRr.rrr subprocessioPopenPIPE _wrap_close TextIOWrapperrr)cmdrV bufferingrrprocrrrrs(  c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCs||_||_dSr)_stream_proc)rstreamrrrrrsz_wrap_close.__init__cCs8|j|j}|dkr dStdkr,|S|d>SdS)Nrr*)rr}rwaitr )r returncoderrrr}s  z_wrap_close.closecCs|Srrrrrr __enter__sz_wrap_close.__enter__cGs |dSrr}rrrrr__exit__sz_wrap_close.__exit__cCs t|j|Sr)getattrr)rr rrr __getattr__sz_wrap_close.__getattr__cCs t|jSr)iterrrrrrrsz_wrap_close.__iter__N) rrrrr}r$r'r)rrrrrrs  rcOs4t|tstdt|ddl}|j|f||S)Nz&invalid fd type (%s, expected integer)r)rRrzrrrr:)fdrkwargsrrrrrs cCst|ttfr|St|}z||}Wn0tk rXt|drFntd|jYnXt|ttfrl|Std |jt|jdS)aaReturn the path representation of a path-like object. If str or bytes is passed in, it is returned unchanged. Otherwise the os.PathLike interface is used to get the path representation. If the path representation is not str or bytes, TypeError is raised. If the provided path is not str, bytes, or os.PathLike, TypeError is raised. __fspath__z/expected str, bytes or os.PathLike object, not z7expected {}.__fspath__() to return str or bytes, not {}N) rRr.rSrr-r!r{rrr)r path_type path_reprrrr_fspaths"  r0r^c@s*eZdZdZejddZeddZdS)PathLikezCAbstract base class for implementing the file system path protocol.cCstdS)z9Return the file system path representation of the object.N)NotImplementedErrorrrrrr-,szPathLike.__fspath__cCs|tkrt|dStS)Nr-)r1rNotImplemented)clssubclassrrr__subclasshook__1s zPathLike.__subclasshook__N) rrr__doc__abcabstractmethodr- classmethodr6rrrrr1(s  r1c@s4eZdZddZddZddZddZd d Zd S) _AddedDllDirectorycCs||_||_||_dSr)r _cookie_remove_dll_directory)rr cookieZremove_dll_directoryrrrr:sz_AddedDllDirectory.__init__cCs||jd|_dSr)r=r<r rrrrr}>s z_AddedDllDirectory.closecCs|Srrrrrrr$Asz_AddedDllDirectory.__enter__cGs |dSrr%r&rrrr'Csz_AddedDllDirectory.__exit__cCs|jrd|jSdS)Nzz)r rrrrrrEs z_AddedDllDirectory.__repr__N)rrrrr}r$r'rrrrrr;9s r;cCs ddl}||}t|||jS)aOAdd a path to the DLL search path. This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes. Remove the directory by calling close() on the returned object or using it in a with statement. rN)r*Z_add_dll_directoryr;r=)r r*r>rrradd_dll_directoryJs  r?)rKF)TNF)rtTN)N)N)N)N)rr)hr7r8rr4r~_collections_abcrbuiltin_module_namesZ_namesr rr$r rr%r(rb ImportError posixpathr r)extendr*ZntpathmodulesZos.pathrrrrr rrr rr+r0setr,supports_dir_fdsupports_effective_idsr- supports_fdsupports_follow_symlinksr rrrPrZr]rfr:rBrrrrrrrrrrrrrr NameErrorrrrrrrrrrSrrrrrrrrrrrr r r r r rrrrr0r^rABCr1r;r?rrrrs      (                                              08    - 7