Yf0@s dZddlZddlZddlZejZddddddd d d d d ddddddddgZddZddZ dekr<dZ dZ ddl Ty!ddl m Z ejdWnek rYnXddlZyddl mZWnek rYnXddl Z eje e [ npd ekrd Z d!Z ddlTy!ddlm Z ejdWnek rYnXddlZddlZeje e[yddlmZWqek rYqXnd"ekrd"Z d!Z ddlTy!ddlm Z ejdWnek rEYnXddlZddlZeje e[yddlmZWqek rYqXn ed#eejd$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#dMdNe%j(ee#dOdPe#dQd2e#dRd2e#dSdTedUredVre#dWdUe%Z)e$Z%e#d)d*e#d-d.e#d/d0e#dXdYe#dZd,ed[r+e#d\d.e#d3d4e#d]d2e#d^d0e#d/d0e#dFd2e#d_d0e%Z*[%[["[#dZ+d`Z,daZ-dbdcdddeZ.dfdgZ/dhdiZ0ejdedgdigdjddcdkdlZ1GdmdndnZ2dodpZ3ejdle4ehe&kr|e5ehe)kr|dqdjddrdcdsddtduZ6dvdwZ7ejduye8Wne9k riZ8YnXdxdyZ:dzd{Z;d|d}Z<d~dZ=ddZ>ddZ?ejdyd{d}dddgdddZ@dddZAddlBmCZCGdddeCZDy eEZFWne9k rtddZFYnXdekrejdy eGZHWne9k rddZHYnXdekrejdddZIeIZ8[IdddZJe d kZKejdeKrdddZLeDe8jMeLeNeLeNeFeHZO[LdddZPejdddZQeQ\ZRZS[Qedr" ed r" edr" dZTd`ZUZVejdddgddZWddZXddZYddZZddZ[ejddddgedrY ddZ\ddZ]ejddgedr ddZ^ddZ_ejddgddddZ`GdddZaddZbdS)aaOS routines for NT or Posix depending on what system we're on. This exports: - all functions from posix, nt or ce, e.g. unlink, stat, etc. - os.path is either posixpath or ntpath - os.name is either 'posix', 'nt' or 'ce'. - 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 (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'/opt/alt/python35/lib64/python3.5/os.py_exists%src CsAyt|jSWn)tk r<ddt|DSYnXdS)NcSs&g|]}|ddkr|qS)r_r).0nrrr ,s z%_get_exports_list..)list__all__AttributeErrordir)modulerrr_get_exports_list(s r"posix )*)_exitr&)_have_functionsntz cezno os specific module foundzos.path)rrrrrrrr r'cCs-|tkr)|tkr)tjt|dS)N)_globalsr'_setadd)strfnrrr_addysr/HAVE_FACCESSATaccess HAVE_FCHMODATchmod HAVE_FCHOWNATchown HAVE_FSTATATstatHAVE_FUTIMESATutime HAVE_LINKATlink HAVE_MKDIRATmkdir HAVE_MKFIFOATmkfifo HAVE_MKNODATmknod HAVE_OPENATopenHAVE_READLINKATreadlink HAVE_RENAMEATrenameHAVE_SYMLINKATsymlink HAVE_UNLINKATunlinkrmdirHAVE_UTIMENSAT HAVE_FCHDIRchdir HAVE_FCHMOD HAVE_FCHOWNHAVE_FDOPENDIRlistdir HAVE_FEXECVEexecveHAVE_FTRUNCATEtruncate HAVE_FUTIMENS HAVE_FUTIMESHAVE_FPATHCONFpathconfstatvfsfstatvfs HAVE_FSTATVFS HAVE_LCHFLAGSZchflags HAVE_LCHMODlchown HAVE_LCHOWN HAVE_LUTIMES HAVE_LSTATZ MS_WINDOWSiFcCstj|\}}|s0tj|\}}|r|rtj| ryt|||Wntk rtYnXt}t|trttd}||krdSyt||Wn,t k r| stj | rYnXdS)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. ASCIIN) r splitexistsmakedirsFileExistsErrorr isinstancebytesr=OSErrorisdir)r modeexist_okheadtailcdirrrrrjs$    rjc Cst|tj|\}}|s:tj|\}}xI|r|ryt|Wntk rlPYnXtj|\}}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)rLr rhrn)r rrrsrrr removedirss  ruc Cstj|\}}|r;|r;tj| r;t|t||tj|\}}|r|ryt|Wntk rYnXdS)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 rhrirjrGrurn)oldnewrrrsrrrrenamess    rxTc$csg}g}yFtdkr9t|tr9t|}n t|}t|}Wn?tk r}z|dk r}||dSWYdd}~XnXx|D]} y| j} Wntk rd} YnX| r|j| jn|j| j| r| r|rd} n2y| j } Wntk r;d} YnX| } | rt | j |||EdHqW|r|||fVt j t j } }xY|D]@}|||}|s| | rt ||||EdHqWn|||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 r(NFT)r rlrm_dummy_scandirscandirrrnis_dirappend is_symlinkwalkr islinkjoin)toptopdownonerror followlinksdirsnondirs scandir_itentrieserrorentryr{ walk_intor}rrdirnamenew_pathrrrr~*sJ;           r~c@sLeZdZdZddZddddZdd Zd d Zd S) _DummyDirEntryzDummy implementation of DirEntry Only used internally by os.walk(bytes). Since os.walk() doesn't need the follow_symlinks parameter: don't implement it, always follow symbolic links. c Cs]||_tj|||_d|_d|_y|jddWntk rXYnXdS)Nfollow_symlinksF)r r r_stat_lstatr7rn)selfr r rrr__init__s    z_DummyDirEntry.__init__rTcCs`|r.|jdkr't|j|_|jS|jdkrUt|jdd|_|jSdS)NrF)rr7r r)rrrrrr7sz_DummyDirEntry.statcCsZ|jdk r>|j r>|jdd}tj|jS|j}tj|jS)NrF)rr}r7stS_ISDIRst_mode)rr7rrrr{s  z_DummyDirEntry.is_dircCs"|jdd}tj|jS)NrF)r7rS_ISLNKr)rr7rrrr}sz_DummyDirEntry.is_symlinkN)__name__ __module__ __qualname____doc__rr7r{r}rrrrrs   rccs)x"t|D]}t||Vq WdS)N)rSr)r r rrrrysry.rdir_fdc cst|ddd|}t|td|}zO|s`tj|jr{tj|t|r{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 rFrN) r7rCO_RDONLYrrrr samestat_fwalkclose)rrrrrorig_sttopfdrrrfwalks#rc cst|}gg}}x|D]}y?tjt|d|jrW|j|n |j|Wq tk ry5tjt|d|ddjr|j|Wntk rw YnXYq Xq W|r||||fVx|D]}y1t|d|d|} t|t d|} Wn>tk r`} z|dk rK|| wWYdd} ~ XnXzO|st j | t| rt j ||} t | | |||EdHWdt| XqW|s||||fVdS)NrrF)rSrrr7rr|rnrrCrr rrrr) rtoppathrrrnamesrrr rdirfderrdirpathrrrr s<    $    rcGst||dS)zpexecl(file, *args) Execute the executable file with argument list args, replacing the current process. N)execv)fileargsrrrexeclBsrcGs(|d}t||dd|dS)zexecle(file, *args, env) Execute the executable file with argument list args and environment env, replacing the current process. reNr)rU)rrenvrrrexecleIs rcGst||dS)zexeclp(file, *args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. N)execvp)rrrrrexeclpQsrcGs(|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. reNrr)execvpe)rrrrrrexeclpeXs rcCst||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)_execvpe)rrrrrrasrcCst|||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. N)r)rrrrrrrisrcCs{|dk r!t}||f}nt}|f}t}tj|\}}|rb|||dSd}}d} t|} tdkrt|}tt| } x| D]} tj | |} y|| |Wqt k rN} zW| }t j d}| j t jkr<| j t jkr<|dkr<| }|} WYdd} ~ XqXqW|rh|j| |j|dS)Nr(rf)rUrenvironr rhrr rmaprrnsysexc_infoerrnoENOENTENOTDIRwith_traceback)rrr exec_funcargrestrrrslast_exc saved_excsaved_tb path_listr fullnameetbrrrrts<        $ rcCsddl}|dkrt}|j|jdty|jd}Wntk rhd}YnXtry|d}Wnttfk rYnX|dk rt d|}|dk rt |t rt |}WdQRX|dkrt }|jtS)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 ValueErrorrlrmrrrhr)rrr path_listbrrrrs.        )MutableMappingc@s|eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)_EnvironcCsC||_||_||_||_||_||_||_dS)N) encodekey decodekey encodevalue decodevalueputenvunsetenv_data)rdatarrrrrrrrrrs      z_Environ.__init__c CsKy|j|j|}Wn!tk r=t|dYnX|j|S)N)rrrr)rkeyvaluerrr __getitem__s  z_Environ.__getitem__cCs?|j|}|j|}|j||||j|sz$_Environ.__repr__..)rrritems)rr)rr__repr__s z_Environ.__repr__cCs t|S)N)dict)rrrrcopysz _Environ.copycCs||kr|||<||S)Nr)rrrrrr setdefaults  z_Environ.setdefaultN) rrrrrrrrrrrrrrrrrs       rcCsdS)Nr)rrrrrsrrcCs t|dS)N)_putenv)rrrrrsrcstdkrldd}|t}fdd}i}xitjD]\}}||||.check_strcs|jS)N)upper)r)encoderrrsz!_createenviron..encodekeycs8t|ts(tdt|j|jdS)Nzstr expected, not %ssurrogateescape)rlr-rrrr)r)encodingrrrsz_createenviron..encodecs|jdS)Nr)decode)r)rrrr"sz_createenviron..decode) r r-rrrgetfilesystemencodingrr _unsetenv)rrrrrrr)rrr_createenviron s"   rcCstj||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)rdefaultrrrgetenv0srrcCs,t|ts(tdt|j|S)Nzbytes expected, not %s)rlrmrrr)rrrr _check_bytes:srcCstj||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)rrrrrgetenvbFsrrcs[tjdkr!dndfdd}fdd}||fS)NmbcsstrictrcsOt|tr|St|tr2|jStdt|jdS)z Encode filename 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). zexpect bytes or str, not %sN)rlrmr-rrrr)filename)rerrorsrrrUs z_fscodec..fsencodecsOt|tr|St|tr2|jStdt|jdS)z Decode filename 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). zexpect bytes or str, not %sN)rlr-rmrrrr)r)rrrrrbs z_fscodec..fsdecode)rr)rrr)rrr_fscodecNs     rforkspawnvrP_WAITP_NOWAIT P_NOWAITOc Cst}|sWy0|dkr.|||n||||WqtdYqXnw|tkrg|Sxdt|d\}}t|rqjqjt|rt| St|rt|St dqjWdS)Nrz"Not stopped, signaled or exited???) rr&rwaitpid WIFSTOPPED WIFSIGNALEDWTERMSIG WIFEXITED WEXITSTATUSrn)rprrrfuncpidwpidstsrrr _spawnvefs&        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)rprrrrrrscCst||||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. )rrU)rprrrrrrspawnvesrcCst|||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)rprrrrrspawnvpsrcCst||||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)rprrrrrrspawnvpesrcGst|||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)rprrrrrspawnlsrcGs'|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. reNrr)r)rprrrrrrspawnles rcGst|||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)rprrrrrspawnlpsrcGs'|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. reNrr)r)rprrrrrrspawnlpes rrcCst|ts%tdt||d krAtd||dksY|dkretdddl}ddl}|dkr|j|ddd |jd |}t |j |j |S|j|ddd |jd |}t |j |j |SdS) Nz&invalid cmd type (%s, expected string)rwzinvalid mode %rrz+popen() does not support unbuffered streamsshellTstdoutbufsizestdin)rr) rlr-rrr subprocessioPopenPIPE _wrap_close TextIOWrapperr r")cmdrp bufferingr#r$procrrrrs$         c@sXeZdZddZddZddZddZd d Zd d Zd S)r'cCs||_||_dS)N)_stream_proc)rstreamr+rrrrs z_wrap_close.__init__cCsH|jj|jj}|dkr,dStdkr<|S|d>SdS)Nrr()r,rr-waitr )r returncoderrrrs   z_wrap_close.closecCs|S)Nr)rrrr __enter__$sz_wrap_close.__enter__cGs|jdS)N)r)rrrrr__exit__&sz_wrap_close.__exit__cCst|j|S)N)getattrr,)rr rrr __getattr__(sz_wrap_close.__getattr__cCs t|jS)N)iterr,)rrrrr*sz_wrap_close.__iter__N) rrrrrr2r3r5rrrrrr's     r'cOsDt|ts%tdt|ddl}|j|||S)Nz&invalid fd type (%s, expected integer)r)rlintrrr$rC)fdrkwargsr$rrrr.s )rr)rrr)crrrr7rbuiltin_module_namesZ_namesrrr"r rr#r&r| ImportError posixpathr r'extendr(Zntpathr)modulesZos.pathrrrrrrrr rr*r/setr+supports_dir_fdsupports_effective_idsr, supports_fdsupports_follow_symlinksr r rrjrurxr~rryrCrSrrr NameErrorrrrrrrrr_collections_abcrrrrrrrrrrrrmrrrrrrrr rrrrrrrrrrr'rrrrrs                         :                                                  +  $!, /        #-7                 #%