a DOg@sTdZddlZddlZddlZddlmZeee Z ej Z gdZ ddZddZd e vrd Zd Zdd lTzdd lmZe d WneyYn0ddlZzddlmZWneyYn0ddlZe ee[nde vrpdZdZdd lTzdd lmZe d Wney&Yn0ddlZddlZe ee[zddlmZWneylYn0nedeejd<ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%[ edre&Z'ddZ(e)Z*e(dde(dde(dde(dde(dd e(d!d"e(d#d$e(d%d&e(d'd(e(d)d*e(d+d,e(d-d.e(d/d0e(d1d2e(d1d3e(d4d e*Z+e)Z*e(dde*Z,e)Z*e(d5d6e(d7de(d8de(d9d:e(d9d;e(dd?e(d@d e(dAd e(dBdCedDredEre(dFdDe*Z.e)Z*e(dde(dde(dde(dGdHe(dIdedJrde(dKde(d!d"e(dLd e(dMde(dde(d4d e(dNde*Z/[*[['[(dZ0dOZ1dPZ2ddSdTZ3dUdVZ4dWdXZ5e gdYdd[d\Z6d]d^Z7e d\e8ehe+krdkdlZ?dmdnZ@dodpZAe gdqddrdsZBddtduZCddvlmDZDmEZEGdwdxdxeDZFdydzZGeGZH[Gdd{d|ZIedkZJe d}eJrd~dZKeFeHjLeKeMeKeMZN[KdddZOe dddZPeP\ZQZR[PedredsedrdZSdOZTZUe gdddZVddZWddZXddZYddZZe gdedrddZ[ddZ\e ddgedrddZ]ddZ^e ddgdddZ_GdddZ`ddZaddZbedsebZcdec_dGdddejeZfedkrPGdddZgddZhdS)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_methods)altsepcurdirpardirseppathseplinesepdefpathnamepathdevnullSEEK_SETSEEK_CURSEEK_ENDfsencodefsdecode get_exec_pathfdopenpopenextsepcCs |tvSN)globals)r r'/opt/alt/python39/lib64/python3.9/os.py_exists)srcCs6z t|jWSty0ddt|DYS0dS)NcSsg|]}|ddkr|qS)r_r).0nrrr 0z%_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"|tvr|tvrtt|dSr)_globalsr*_setadd)strfnrrr_addhsr1ZHAVE_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|\}}|rz|rzt|szzt||dWntyTYn0t}t|trnttd}||krzdSzt||Wn"t y|rt |sYn0dS)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 isinstancebytesr8OSErrorisdir)r moderMheadtailcdirrrrrQs$     rQcCsht|t|\}}|s(t|\}}|rd|rdz t|WntyRYqdYn0t|\}}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 rOrU)r rXrYrrr removedirss    r[cCslt|\}}|r(|r(t|s(t|t||t|\}}|rh|rhz t|WntyfYn0dS)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 rOrPrQr=r[rU)oldnewrXrYrrrrenamess   r^)rQr[r^TcCs$td||||tt||||S)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 zos.walk)sysaudit_walkfspath)toptopdownonerror followlinksrrrwalks;rgc cs g}g}g}z t|}Wn6tyN}z|dur8||WYd}~dSd}~00|z,z t|} WntyYWq`Yn0WnBty}z*|dur||WYd}~WddSd}~00z | } Wntyd} Yn0| r|| jn || j|sX| rX|r"d} n,z | } WntyFd} Yn0| } | rX|| jqXWdn1sv0Y|r|||fVtj tj } }|D]4}|||}|s| |st ||||EdHqn,|D]}t ||||EdHq|||fVdS)NFT) rCrUnext StopIterationis_dirappendr is_symlinkr islinkjoinra)rcrdrerfdirsnondirs walk_dirs scandir_iterrorentryrj walk_intorlrmrndirnamenew_pathrrrraXs\   $     .  ra.follow_symlinksdir_fdccstd|||||t|tr(t|ds0t|}|sBt|d|d}t|t|d}zJ|srt |j rt |t|rt||t|t|||EdHWt|n t|0dS)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 zos.fwalk __index__Fryr{N)r_r`rSinthasattrrbr5r;O_RDONLYstS_ISDIRst_moder samestat_fwalkrTclose)rcrdrerzr{orig_sttopfdrrrfwalks! rc cst|}g}g}|s|rdng} |D]} | j} |r:t| } z4| rb|| | durl| | n || Wq$tyz| r|| WntyYn0Yq$0q$|r||||fV| dur|nt|| D]} z@|s |rt| |dd} n| \} } | jdd} t | t |d} WnDty^}z*|dur>||WYd}~qWYd}~n d}~00zH|szt | t| rt || }t| |||||EdHWt| qt| 0q|s||||fVdS)NF)r{rz)rzr})rCr rrjrkrUrlzipr5r;rr rrnrr)rtoppathisbytesrdrerzrrrorpentriesrtr rdirfderrdirpathrrrrsV      "  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)rDrrenvrrrexecle srcGst||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_execvperrrrr8srcCst|||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@sr)rrrrrrc Cs|durt}||f}nt}|f}t}t|rB||g|RdSd}t|}tdkrht|}tt|}|D]}t ||}z||g|RWqlt t fy} z| } WYd} ~ qld} ~ 0t y} z| } |dur| }WYd} ~ qld} ~ 00ql|dur|| dS)Nr+) rDrenvironr rvrr rmaprnFileNotFoundErrorNotADirectoryErrorrU) rrr exec_funcargrest saved_exc path_listr#fullnameelast_excrrrrKs6    rc Csddl}|durt}||dtz|d}WntyNd}Yn0trz |d}WnttfyvYn0|durt d|}|durt |t rt |}Wdn1s0Y|durt }|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 ValueErrorrSrTrr rOr)rrr path_listbrrrrks0      &r)MutableMappingMappingc@sleZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS)_EnvironcCs"||_||_||_||_||_dSr) encodekey decodekey encodevalue decodevalue_data)selfdatarrrrrrr__init__s z_Environ.__init__cCs<z|j||}Wnty0t|dYn0||Sr)rrrrrkeyvaluerrr __getitem__s  z_Environ.__getitem__cCs,||}||}t||||j|<dSr)rrputenvrrrrr __setitem__s   z_Environ.__setitem__cCs@||}t|z |j|=Wnty:t|dYn0dSr)runsetenvrr)rr encodedkeyrrr __delitem__s    z_Environ.__delitem__ccs$t|j}|D]}||VqdSr)r rr)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__..)rrnritemsrrrr__repr__s  z_Environ.__repr__cCst|Sr)dictrrrrcopysz _Environ.copycCs||vr|||<||Srrrrrr setdefaultsz_Environ.setdefaultcCs|||Sr)update)rotherrrr__ior__s z_Environ.__ior__cCs$t|tstSt|}|||SrrSrNotImplementedrrrrr]rrr__or__s   z_Environ.__or__cCs$t|tstSt|}|||Srrrrrr__ror__s   z_Environ.__ror__N)__name__ __module__ __qualname__rrrrrrrrrrrrrrrrrs rcstdkrHdd}|t}fdd}i}tD]\}}||||<q0n(tfddfdd }}t}t||||S) Nr+cSs t|tstdt|j|S)Nstr expected, not %s)rSr/rtyperrrrr check_strs z!_createenviron..check_strcs |Sr)upper)r)encoderrrsz!_createenviron..encodekeycs(t|tstdt|j|dS)Nrsurrogateescape)rSr/rrrrrencodingrrrs z_createenviron..encodecs |dS)Nr)decoderrrrrsz_createenviron..decode)r r/rrr_getfilesystemencodingr)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)rSrTrrrrrrr _check_bytes s 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)rbrSr/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)rbrSrTrrrrrr0s  z_fscodec..fsdecode)r_rgetfilesystemencodeerrors)rrrrr_fscodec s   rforkspawnvr)P_WAITP_NOWAIT P_NOWAITOcCst|ttfstd|r"|ds*tdt}|spz$|durJ|||n ||||WqtdYq0n,|tkr||St|d\}}t |rq|t |SdS)Nzargv must be a tuple or a listrz"argv first element cannot be empty) rStupler rrrr)rwaitpid WIFSTOPPEDwaitstatus_to_exitcode)rWrrrfuncpidwpidstsrrr _spawnvefMs$  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)rrrWrrrrrrhscCst||||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. )rrDrWrrrrrrspawnveqsr cCst|||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)rrr rrrspawnvp}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. )rrr rrrspawnvpesr )rr r r 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. )rr rrrspawnlsrcGs|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)r r rrrspawnlesrcGs 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 r rrrspawnlpsrcGs|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 r rrrspawnlpesrrrcCst|tstdt||dvr.td||dks>|durFtdddl}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) rSr/rrr subprocessioPopenPIPE _wrap_close TextIOWrapperrr)cmdrW bufferingrrprocrrrrs(  rc@s<eZdZddZddZddZddZd d Zd d Zd S)rcCs||_||_dSr)_stream_proc)rstreamr rrrrsz_wrap_close.__init__cCs8|j|j}|dkr dStdkr,|S|d>SdS)Nrr+)r!rr"waitr )r returncoderrrrs  z_wrap_close.closecCs|Srrrrrr __enter__sz_wrap_close.__enter__cGs |dSrrrrrrr__exit__sz_wrap_close.__exit__cCs t|j|Sr)getattrr!)rr rrr __getattr__sz_wrap_close.__getattr__cCs t|jSr)iterr!rrrrrsz_wrap_close.__iter__N) rrrrrr'r*r,rrrrrrs  rcOs:t|tstdt|ddl}|j|g|Ri|S)Nz&invalid fd type (%s, expected integer)r)rSr~rrrr;)fdrkwargsrrrrrs rcCst|ttfr|St|}z||}Wn.tyVt|drDntd|jYn0t|ttfrj|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) rSr/rTrr0r"rrrr)r path_type path_reprrrr_fspaths"   r3rbc@s2eZdZdZejddZeddZee Z dS)PathLikezCAbstract base class for implementing the file system path protocol.cCstdS)z9Return the file system path representation of the object.N)NotImplementedErrorrrrrr0,szPathLike.__fspath__cCs|turt|dStS)Nr0)r4rr)clssubclassrrr__subclasshook__1s zPathLike.__subclasshook__N) rrr__doc__abcabstractmethodr0 classmethodr8 GenericAlias__class_getitem__rrrrr4(s   r4c@s4eZdZddZddZddZddZd d Zd S) _AddedDllDirectorycCs||_||_||_dSr)r _cookie_remove_dll_directory)rr cookieZremove_dll_directoryrrrr<sz_AddedDllDirectory.__init__cCs||jd|_dSr)rAr@r rrrrr@s z_AddedDllDirectory.closecCs|Srrrrrrr'Csz_AddedDllDirectory.__enter__cGs |dSrr(r)rrrr*Esz_AddedDllDirectory.__exit__cCs|jrd|jSdS)Nzz)r rrrrrrGs z_AddedDllDirectory.__repr__N)rrrrrr'r*rrrrrr?;s 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?rA)r r+rBrrradd_dll_directoryLs  rC)rLF)TNF)rxTN)N)N)N)N)rr)ir9r:r_r5r_collections_abcrrr r~r=builtin_module_namesZ_namesr!rr%r rr&r)rk ImportError posixpathr r*extendr+ZntpathmodulesZos.pathrrrrr rrr rr,r1setr-supports_dir_fdsupports_effective_idsr. supports_fdsupports_follow_symlinksr rrrQr[r^rgrar;rCrrrrrrrrrrrrrrrrrrrrTrrrrrrrrrrr r r rrrrrrrr3rbrABCr4r?rCrrrrsb        (                                             >R 18    -G