\dP dZddlZddlZddlZddlmZeee Z ej Z gdZ dZdZde vrkdZdZdd lT dd lmZe d n #e$rYnwxYwddlZ dd lmZn #e$rYnwxYwddlZe ee[nyd e vrjd ZdZdd lT dd lmZe d n #e$rYnwxYwddlZddlZe ee[ dd lmZn#e$rYnwxYwedeejd<ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%[ edrWe&Z'dZ(e)Z*e(dde(dde(dde(dde(dde(dde(d d!e(d"d#e(d$d%e(d&d'e(d(d)e(d*d+e(d,d-e(d.d/e(d.d0e(d1de*Z+e)Z*e(dde*Z,e)Z*e(d2d3e(d4de(d5de(d6d7e(d6d8e(d9d:e*-ee(d;d<e(d=de(d>de(d?d@edAredBr e(dCdAe*Z.e)Z*e(dde(dde(dde(dDdEe(dFdedGr e(dHde(dde(dIde(dJde(dde(d1de(dKde*Z/[*[['[(dZ0dLZ1dMZ2ddPZ3dQZ4dRZ5e gdSddUZ6dVZ7e dWe8ehe+kr(e9ehe.kr ddOddYdZZ:d[Z;e d\d]Zd`Z?daZ@dbZAe gdcdddZBddeZCddflmDZDmEZEGdgdheDZFdiZGeGZH[GddjZIed kZJe dkeJr1dlZKeFeHjLeKeMeKeMZN[KddmZOe dndoZPeP\ZQZR[PedprYedqsNedrrCdZSdLxZTZUe gdsdtZVduZWdvZXdwZYdxZZe gdyedqrdzZ[d{Z\e d|d}ged~rdZ]dZ^e ddgej_dkr&ddZ`GddZae dddZbdZceds ecZdded_eGddejfZged krGddZhdZidSdS)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_pathfdopenextsepc"|tvSN)globals)r s ..\python\lib\os.py_existsr)s 799 c~ t|jS#t$rdt|DcYSwxYw)Nc*g|]}|ddk|S)r_).0ns r z%_get_exports_list..0s!666a!A$#+++++r)list__all__AttributeErrordir)modules r_get_exports_listr(,sR7FN### 777663v;;6666667s #<<posix )*)_exitr,)_have_functionsntz zno os specific module foundzos.path)rrrrr rrr r-c||tvr0|tvr)tt|dSdSdSr)_globalsr-_setadd)strfns r_addr5hs> (NN!7!7 HHXb\ " " " " " N!7!7rHAVE_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_FDOPENDIRlistdirscandir HAVE_FEXECVEexecveHAVE_FTRUNCATEtruncate HAVE_FUTIMENS HAVE_FUTIMESHAVE_FPATHCONFpathconfstatvfsfstatvfs HAVE_FSTATVFS HAVE_LCHFLAGSchflags HAVE_LCHMODlchown HAVE_LCHOWN HAVE_LUTIMES HAVE_LSTAT MS_WINDOWSFctj|\}}|stj|\}}|rr|rptj|s\ t||n#t$rYnwxYwt }t |trtt d}||krdS t||dS#t$r|rtj |sYdSwxYw)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 isinstancebytesrCOSErrorisdir)r moderrheadtailcdirs rrvrvs&D!!JD$ &Z%% d  T[..   TH - - - - -    D  dE " " *))D 4<< F dD  tz$//     s$ A A)(A)&B88!CCct|tj|\}}|stj|\}}|rA|rA t|n#t$rYdSwxYwtj|\}}|r|=dSdSdSdS)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)rRr rtrz)r r}r~s r removedirsrs $KKKD!!JD$ &Z%% d &4&  $KKKK    EE Z%% d &4&&&&&&&&&sA A#"A#c"tj|\}}|r%|r#tj|st|t ||tj|\}}|r%|r% t |dS#t $rYdSwxYwdSdS)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 rtrurvrMrrz)oldnewr}r~s rrenamesrsCJD$ T[.. 3CJD$   t         DD s+A<< B  B )rvrrTcptjd||||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 (including symlinks to directories, and 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 ") 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 followlinkss rwalkrs7xIigw <<< gw < < | r|| n#t $rYnwxYwYwxYw|r||||fV| |nt|| D]} |s4|rt| |d} n| J| \} } | d} t| t|} n$#t $r}| ||Yd}~md}~wwxYw |s"tj | t| r/tj || }t| |||||Ed{Vt| #t| wxYw|s ||||fVdSdS)NF)rr)rr)rZr rrrrzrzipr=rIrr rrrr)rtoppathisbytesrrrrrrentriesrr rdirfderrdirpaths rrrs U^^ !<_<$$"  E:D &~~ <<>>)KK%%%*u---NN4(((   ''))-t,,,D    04%/ / / /#ODDT71C1C  D &DD"&tE5"Q"Q"Q&222&* e"'**U*"C"CT8E:::   &GCLLL  "IdmGT%[[&I&II"i66G%eWg&-w I IIIIIIIIe e  04%/ / / / / / 0 0s\AB C)CC CCCCC>A E  E- E((E-1AGG%rc&t||dS)zpexecl(file, *args) Execute the executable file with argument list args, replacing the current process. N)execvfileargss rexeclrs  $rcH|d}t||dd|dS)zexecle(file, *args, env) Execute the executable file with argument list args and environment env, replacing the current process. N)r\rrenvs rexecler s- r(C 4crcC     rc&t||dS)zexeclp(file, *args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. N)execvprs rexeclpr(s  4rcH|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)execvpers rexeclper/s- r(C D$ss)S!!!!!rc&t||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_execvpers rrr8s  T4rc(t|||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. Nrrs rrr@s T4r)rrrrrrc| t}||f}nt}|f}t}tj|r ||g|RdSd}t |}t dkr$t|}tt|}|D]Y}tj ||} ||g|R"#ttf$r } | } Yd} ~ :d} ~ wt$r} | } || }Yd} ~ Rd} ~ wwxYw||| )Nr.) r\renvironr rrr rmaprFileNotFoundErrorNotADirectoryErrorrz) rrr exec_funcargrest saved_exc path_listr&fullnameelast_excs rrrKs=  + ' |D $!!!!!Ic""I t||~~),,   9S$''  Ih ) ) ) ) ) )!#56   HHHHHH   H    Ns$ B##C4B;; CCCcddl}|t}|5|dt |d}n#t $rd}YnwxYwtrZ |d}|td|}n#tt f$rYnwxYw|$t|trt|}dddn #1swxYwY|t}|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_environ ValueErrorKeyErrorrxryrr rtr)rrr path_listbs rrrksyOOO {  " "00h 555 II   III  " 0 ' \ ($DFFF& i(    $Iu)E)E$$Y// )000000000000000, ??7 # ##sXCAC A$!C#A$$ C/B 7C BCB)CCC)MutableMappingMappingcVeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd S)_EnvironcL||_||_||_||_||_dSr) encodekey decodekey encodevalue decodevalue_data)selfdatarrrrs r__init__z_Environ.__init__s+""&& rc |j||}n#t$rt|dwxYw||Sr)rrrrrkeyvalues r __getitem__z_Environ.__getitem__s` *Jt~~c223EE * * *3--T ) *&&&s #>c||}||}t||||j|<dSr)rrputenvrrs r __setitem__z_Environ.__setitem__sEnnS!!  ''sE 3rc||}t| |j|=dS#t$rt|dwxYwr)runsetenvrr)rr encodedkeys r __delitem__z_Environ.__delitem__s_^^C((  * :&&& * * *3--T ) *s 0A c#jKt|j}|D]}||VdSr)r#rr)rkeysrs r__iter__z_Environ.__iter__sIDJ & &C..%% % % % % & &rc*t|jSr)lenrrs r__len__z_Environ.__len__s4:rcdfdjD}d|dS)Nz, c3xK|]4\}}|d|V5dS)z: N)rr)r rrrs r z$_Environ.__repr__..sc$ $ U~~c"" C C(8(8(?(? C C$ $ $ $ $ $ rz environ({z}))rritems)rformatted_itemss` r__repr__z_Environ.__repr__s]))$ $ $ $ "j..00$ $ $   1O0000rc t|Sr)dictrs rcopyz _Environ.copysDzzrc$||vr|||<||Srrrs r setdefaultz_Environ.setdefaults d??DICyrc0|||Sr)update)rothers r__ior__z_Environ.__ior__s E rct|tstSt|}|||SrrxrNotImplementedrrrrrs r__or__z_Environ.__or__s<%)) "! !4jj 5 rct|tstSt|}|||Srrrs r__ror__z_Environ.__ror__s<%)) "! !5kk 4 rN)__name__ __module__ __qualname__rrrrrrr rrrrrrrrrrs'''   ***&&& 111 rrctdkrAd}|t}fd}i}tD]\}}||||<n&t jfdfd}}t}t ||||S)Nr.cxt|ts$tdt|jz|S)Nstr expected, not %s)rxr3rtyperrs r check_strz!_createenviron..check_strs7eS)) O 6e9M MNNNLrc>|Sr)upper)rencodes rrz!_createenviron..encodekeys6#;;$$&& &rct|ts$tdt|jz|dS)Nr"surrogateescape)rxr3rr#rr(rencodings rr(z_createenviron..encodesHeS)) O 6e9M MNNN<<*;<< .decodes<<*;<< .fsencode&s= (## h $ $ ??8V44 4Orc|t|}t|tr|S|S)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). )rrxryr.r<s rrz_fscodec..fsdecode2s= (## h & & ??8V44 4Or)rr/getfilesystemencodeerrors)rrr,r>s @@r_fscodecrA"si(**H  * , ,F             X rforkspawnvr)P_WAITP_NOWAIT P_NOWAITOct|ttfstd|r|dst dt }|s8 | |||n||||dSdS#t dYdSxYw|tkr|S t|d\}}t|r$t|S)Nzargv must be a tuple or a listrz"argv first element cannot be empty) rxtupler#rrrBr,rEwaitpid WIFSTOPPEDwaitstatus_to_exitcode)r|rrrfuncpidwpidstss r _spawnvefrQOs$ .. ><== = C47 CABB Bff 3 ;Dt$$$$DtS)))))%$ c x  3#COO cc??-c222s A66B c2t|||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)rQrr|rrs rrCrCjstT4777rc2t||||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. )rQr\r|rrrs rspawnverVsstT3777rc2t|||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)rQrrSs rspawnvprXstT4888rc2t||||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. )rQrrUs rspawnvperZstT3888r)rCrVrXrZc$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. )rCrSs rspawnlr\sdD$'''rcF|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)rVrUs rspawnler^s)2htT49c222rr\r^rXc$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. )rXrSs rspawnlpr`stT4(((rcF|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)rZrUs rspawnlperbs)2hdD"Is333rr`rbvxworksrrct|tstdt|z|dvrt d|z|dks|t dddl}|dkr4||dd|j|}t|j |S||dd|j| }t|j |S) Nz&invalid cmd type (%s, expected string))rdwzinvalid mode %rrz+popen() does not support unbuffered streamsrdT)shelltextstdoutbufsize)rgrhstdinrj) rxr3rr#r subprocessPopenPIPE _wrap_closerirk)cmdr| bufferingrlprocs rpopenrss#s## RDtCyyPQQ Q z ! !.566 6 >>Y.JKK K 3;;##C*.T+5?,5$77Dt{D11 1##C*.T*4/,5$77Dtz400 0rc2eZdZdZdZdZdZdZdZdS)roc"||_||_dSr)_stream_proc)rstreamrrs rrz_wrap_close.__init__s!DLDJJJrc|j|j}|dkrdStdkr|S|dzS)Nrr.)rvrrwwaitr )r returncodes rrz_wrap_close.closesN L   **JQtt||!!!Q&rc|Srrrs r __enter__z_wrap_close.__enter__Krc.|dSrrrrs r__exit__z_wrap_close.__exit__ JJLLLLLrc,t|j|Sr)getattrrv)rr s r __getattr__z_wrap_close.__getattr__s4<.. .rc*t|jSr)iterrvrs rrz_wrap_close.__iter__s %% %rN) rrrrrr~rrrrrrrorosn    ' ' '       / / / & & & & &rrorsct|tstdt|zddl}d|vr||}|j||||g|Ri|S)Nz&invalid fd type (%s, expected integer)rb)rxintrr#io text_encodingrI)fdr|rqr,rkwargsrs rrrs| b#  M@488KLLL III $##H-- 272tY B4 B B B6 B BBrct|ttfr|St|} ||}n6#t $r)t |drtd|jzwxYwt|ttfr|Std |jt|j)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 {}) rxr3ryr#rr%hasattrrrformat)r path_type path_reprs r_fspathr s$e %% T I9((.. 999 9l + + 9 #%.%7899 9 9 )c5\**C!!' (:(,Y(@"B"BCC Cs A3A8rc^eZdZdZejdZedZee Z dS)PathLikezCAbstract base class for implementing the file system path protocol.ct)z9Return the file system path representation of the object.)NotImplementedErrorrs rrzPathLike.__fspath__4s "!rcB|turt|dStS)Nr)rrr)clssubclasss r__subclasshook__zPathLike.__subclasshook__9s! (??!(L99 9rN) rrr__doc__abcabstractmethodr classmethodr GenericAlias__class_getitem__rrrrr0s`MM"""[ $ L11rrc,eZdZdZdZdZdZdZdS)_AddedDllDirectoryc0||_||_||_dSr)r _cookie_remove_dll_directory)rr cookieremove_dll_directorys rrz_AddedDllDirectory.__init__DsDI!DL)=D & & &rcH||jd|_dSr)rrr rs rrz_AddedDllDirectory.closeHs#  & &t| 4 4 4DIIIrc|Srrrs rr~z_AddedDllDirectory.__enter__Krrc.|dSrrrs rrz_AddedDllDirectory.__exit__MrrcH|jrd|jSdS)Nzz)r rrs rr z_AddedDllDirectory.__repr__Os)y E299$)DDD**rN)rrrrrr~rr rrrrrCs_ > > >          + + + + +rrcVddl}|j|}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._add_dll_directoryrr)r r.rs radd_dll_directoryrTs=  &&t,,!    $   r)rpF)TNF)rTNr)rdr)rdrN)jrrrr=r_collections_abcrr#r#rrbuiltin_module_names_namesr$rr(r r r)r,r ImportError posixpathr r-extendr.ntpathmodulesos.pathrrrrr rrr rr0r5setr1supports_dir_fdsupports_effective_idsr2 supports_fdsupports_follow_symlinksrrrrvrrrrrIrZrrrrrrrrrrrrrr0rr4rr6rryr8r9rArrrDrErFrQrCrVrXrZr\r^r`rbplatformrsrorrrrABCrrrrrrrs 0 ++++++tDI !    777 f DG w       )))))))      LLL NN$$U++,,,  V^^ DG w       III NN$$R(()))  &&&&&&&       +3 4 44 I                      7 U wyyH### 355DD H%%%DG$$$DG$$$DF###D G$$$DF###DG$$$DH%%%DG$$$DF###D J'''DH%%%D I&&&DH%%%DG$$$D G$$$O 355DD H%%%! 355DDG$$$DG$$$DG$$$D I&&&D I&&&DH%%%HHTNNND J'''DG$$$DG$$$D J'''wy)ggj11) _i(((K 355DD H%%%, DG$$$DF###DI&&&DG$$$wx% ]G$$$DF###DG$$$DF###DF###D G$$$DF####     @&&&,4444555========~P!P!P!dv$wx FFO22222sw222$4<<++++++++"     %A?3CCCD DD