B \]|@sdZddlZddlZddlZejZddddddd d d d d ddddddddgZddZddZ dekrdZ dZ ddl Tyddl m Z edWnek rYnXddlZyddl mZWnek rYnXddl Z ee e [ nd ekrd Z d!Z ddlTyddlm Z edWnek r6YnXddlZddlZee e[yddlmZWnek r~YnXned"eejd#<dd$lmZmZmZmZmZmZmZmZ[ed%re Z!d&d'Z"e#Z$e"d(d)e"d*d+e"d,d-e"d.d/e"d0d1e"d2d3e"d4d5e"d6d7e"d8d9e"d:d;e"dd?e"d@dAe"dBdCe"dBdDe"dEd1e$Z%e#Z$e"d(d)e$Z&e#Z$e"dFdGe"dHd+e"dId-e"dJdKe"dJdLe"dMdNe$'ee"dOdPe"dQd1e"dRd1e"dSdTedUr&edVr&e"dWdUe$Z(e#Z$e"d(d)e"d,d-e"d.d/e"dXdYe"dZd+ed[rve"d\d-e"d2d3e"d]d1e"d^d/e"d.d/e"dEd1e"d_d/e$Z)[$[[!["dZ*d`Z+daZ,ddddeZ-dfdgZ.dhdiZ/ededgdigddkdlZ0edle1ehe%krHe2ehe(krHddcddndodpZ3dqdrZ4edpye5Wne6k rjiZ5YnXdsdtZ7dudvZ8dwdxZ9dydzZ:d{d|Z;d}d~Zddl?m@Z@Gddde@ZAyeBZCWne6k rddZCYnXdekredyeDZEWne6k rDddZEYnXdekrZedddZFeFZ5[FdddZGe d kZHedeHrddZIeAe5jJeIeKeIeKeCeEZL[IdddZMedddZNeN\ZOZP[NedrHedsHedrHdZQd`ZRZSedddgddZTddZUddZVddZWddZXeddddgedrpddZYddZZeddgedrddZ[ddZ\eddgdddZ]GdddZ^ddZ_ddZ`edse`Zadea_bGdddejcZddS)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). NaltsepcurdirpardirseppathseplinesepdefpathnamepathdevnullSEEK_SETSEEK_CURSEEK_ENDfsencodefsdecode get_exec_pathfdopenpopenextsepcCs |tkS)N)globals)r r/usr/local/lib/python3.7/os.py_exists%srcCs2y t|jStk r,ddt|DSXdS)NcSsg|]}|ddkr|qS)r_r).0nrrr ,sz%_get_exports_list..)list__all__AttributeErrordir)modulerrr_get_exports_list(s r"posix )*)_exitr&)_have_functionsntz zno os specific module foundzos.path)rrrrrrrr r'cCs"|tkr|tkrtt|dS)N)_globalsr'_setadd)strfnrrr_adddsr.ZHAVE_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|yt||dWntk rVYnXt}t|trpttd}||kr|dSyt||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_okZASCIIN) r splitexistsmakedirsFileExistsErrorr isinstancebytesr5OSErrorisdir)r moderJheadtailZcdirrrrrMs$   rMcCslt|t|\}}|s(t|\}}x>|rf|rfy t|Wntk rTPYnXt|\}}q*WdS)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 rKrQ)r rTrUrrr removedirss   rVcCsnt|\}}|r(|r(t|s(t|t||t|\}}|rj|rjy 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 rKrLrMr:rVrQ)oldnewrTrUrrrrenamess  rYTc cst|}g}g}g}y t|}Wn2tk rR}z|dk rB||dSd}~XYnX|xy(y t|} Wntk rPYnXWn2tk r}z|dk r||dSd}~XYnXy | } Wntk rd} YnX| r|| jn || j|s`| r`|rd} n.y | } Wntk r:d} YnX| } | r`|| j q`WWdQRX|r|||fVt j t j } }xn|D]4}|||}|s| |st ||||EdHqWn0x"|D]}t ||||EdHqW|||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 is ineffective, 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) fspathr@rQnext StopIterationis_dirappendr is_symlinkr islinkjoinwalk)toptopdownonerrorZ followlinksdirsnondirsZ walk_dirs scandir_iterrorentryr]Z walk_intor_r`radirnameZnew_pathrrrrbs`:            rb.)follow_symlinksdir_fdccst|trt|dst|}|s.t|d|d}t|t|d}zB|s^t|j r|t |t|r|t ||t|t |||EdHWdt|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__F)rmrn)rnN)rOinthasattrrZr2r8O_RDONLYstZS_ISDIRst_moder samestat_fwalkrPclose)rcrdrermrnorig_sttopfdrrrfwalks!rzc cst|}g}g}|s|rdng} x|D]} | j} |ry|j||}Wntk r2t|dYnX||S)N)rrrr)rkeyvaluerrr __getitem__s z_Environ.__getitem__cCs.||}||}|||||j|<dS)N)rrrr)rrrrrr __setitem__s   z_Environ.__setitem__cCsD||}||y |j|=Wntk r>t|dYnXdS)N)rrrr)rrZ encodedkeyrrr __delitem__s    z_Environ.__delitem__ccs(t|j}x|D]}||VqWdS)N)rrr)rkeysrrrr__iter__s  z_Environ.__iter__cCs t|jS)N)lenr)rrrr__len__sz_Environ.__len__cs$ddfddjDS)Nzenviron({{{}}})z, c3s*|]"\}}d||VqdS)z {!r}: {!r}N)formatrr)rrr)rrr sz$_Environ.__repr__..)rraritems)rr)rr__repr__s z_Environ.__repr__cCst|S)N)dict)rrrrcopysz _Environ.copycCs||kr|||<||S)Nr)rrrrrr setdefaultsz_Environ.setdefaultN) __name__ __module__ __qualname__rrrrrrrrrrrrrrs  rcCsdS)Nr)rrrrrrrcCs t|dS)N)_putenv)rrrrrrrcstdkrLdd}|t}fdd}i}xJtD]\}}||||<q2Wn(tfddfdd }}t}t||||ttS) Nr(cSs t|tstdt|j|S)Nzstr expected, not %s)rOr,rtyper)rrrr check_strs z!_createenviron..check_strcs |S)N)upper)r)encoderrrsz!_createenviron..encodekeycs(t|tstdt|j|dS)Nzstr expected, not %ssurrogateescape)rOr,rrrr)r)encodingrrrs z_createenviron..encodecs |dS)Nr)decode)r)rrrrsz_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.)rr)rdefaultrrrgetenvsr)rrcCs t|tstdt|j|S)Nzbytes expected, not %s)rOrPrrr)rrrr _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.)environbr)rrrrrgetenvbsr)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)rZrOr,r)filename)rerrorsrrr#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)rZrOrPr)r)rrrrr/s  z_fscodec..fsdecode)rrgetfilesystemencodeerrors)rrr)rrr_fscodecs   rforkspawnvr~P_WAITP_NOWAIT P_NOWAITOcCst|ttfstd|r"|ds*tdt}|spy$|dkrJ|||n ||||WqtdYqXnV|tkr||SxHt|d\}}t |rq~q~t |rt | St |rt |Stdq~WdS)Nzargv must be a tuple or a listrz"argv first element cannot be emptyz"Not stopped, signaled or exited???)rOtuplerrrrr&rwaitpid WIFSTOPPED WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUSrQ)rSrrrZfuncZpidZwpidZstsrrr _spawnvefLs.   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)rr~)rSrrrrrrkscCst||||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. )rrA)rSrrrrrrspawnvetsrcCst|||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)rr)rSrrrrrspawnvpsrcCst||||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. )rr)rSrrrrrrspawnvpesrcGs 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. )r)rSrrrrrspawnlsrcGs|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)rSrrrrrrspawnlesrcGs 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)rSrrrrrspawnlpsrcGs|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)rSrrrrrrspawnlpesrrrcCst|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) rOr,rrr subprocessioZPopenZPIPE _wrap_close TextIOWrapperrr)ZcmdrS bufferingrrprocrrrrs$  c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCs||_||_dS)N)_stream_proc)rstreamrrrrrsz_wrap_close.__init__cCs8|j|j}|dkr dStdkr,|S|d>SdS)Nrr()rrwrwaitr )rZ returncoderrrrws  z_wrap_close.closecCs|S)Nr)rrrr __enter__sz_wrap_close.__enter__cGs |dS)N)rw)rrrrr__exit__sz_wrap_close.__exit__cCs t|j|S)N)getattrr)rr rrr __getattr__sz_wrap_close.__getattr__cCs t|jS)N)iterr)rrrrrsz_wrap_close.__iter__N) rrrrrwrrrrrrrrrs  rcOs4t|tstdt|ddl}|j|f||S)Nz&invalid fd type (%s, expected integer)r)rOrprrrr8)fdrkwargsrrrrrs cCst|ttfr|St|}y||}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) rOr,rPrrrrqrrr)r Z path_typeZ path_reprrrr_fspaths rrZc@s*eZdZdZejddZeddZdS)PathLikezCAbstract base class for implementing the file system path protocol.cCstdS)z9Return the file system path representation of the object.N)NotImplementedError)rrrrr/szPathLike.__fspath__cCs t|dS)Nr)rq)clssubclassrrr__subclasshook__4szPathLike.__subclasshook__N) rrr__doc__abcabstractmethodr classmethodrrrrrr+sr)rIF)TNF)rlTN)N)N)N)N)rr)errrr2rsbuiltin_module_namesZ_namesrrr"r rr#r&r^ ImportErrorZ posixpathr r'extendr(ZntpathmodulesZos.pathrrrrrrrr rr)r.setr*Zsupports_dir_fdZsupports_effective_idsr+Z supports_fdZsupports_follow_symlinksr r rrMrVrYrbr8r@rzrvr NameErrorrrrrrrrrZ_collections_abcrrrrrrrrrrrrPrrrrrrrrrrrrrrrrrrrrrrZrABCrrrrrs~       (                                              08     - 7