lJc@sdZddkZeiZddddddd d d d d ddg ZdZdejordZdZddkTyddkl Z Wne j onXddk Z ddkZei ee[ndejordZdZddkTyddkl Z Wne j onXddkZ ddkZei ee[n?dejodZdZddkTyddkl Z Wne j onXeiiddjoddkZ nddkZ ddklZddkZei ee[ndejordZdZddkTyddkl Z Wne j onXddkZ ddkZei ee[ndejordZdZddkTyddkl Z Wne j onXddkZ ddkZei ee[ndejordZdZddkTyddkl Z Wne j onXddkZ ddkZei ee[n e de eidYZ<e<e/Z/dd?Z>ei.d@dAZ?e?dBo\e?dC oNe?dDoAd!Z@d"ZAZBdEZCdFZDdGZEdHZFdIZGne?dCo/dJZHdKZIei dCdLdMdNgne?dOo/dPZJdQZKei dOdRdSdTgne?dBoe?dUp dVddWZLei.dUne?dXp dVddYZMei.dXne?dZp dVdd[ZNei.dZq nddkOZPd\ZQd]ZRyePiSeTeReQWne0j onXd^ZUd_ZVyePiSeWeVeUWne0j onXe?d`p daZXndS(dsOS routines for Mac, NT, or Posix depending on what system we're on. This exports: - all functions from posix, nt, os2, mac, or ce, e.g. unlink, stat, etc. - os.path is one of the modules posixpath, ntpath, or macpath - os.name is 'posix', 'nt', 'os2', 'mac', 'ce' or 'riscos' - 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 ('.' or '/') - 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). iNtaltseptcurdirtpardirtseptpathseptlineseptdefpathtnametpathtdevnulltSEEK_SETtSEEK_CURtSEEK_ENDcCseyt|iSWnMtj oAg}t|D]"}|ddjo ||q3q3~SnXdS(Nit_(tlistt__all__tAttributeErrortdir(tmodulet_[1]tn((s/sys/lib/python/os.pyt_get_exports_list#stposixs (t*(t_exittnts tos2sEMX GCC(tlinktmacs tcetriscossno os specific module foundsos.path(RRRRRtextsepRR iiiicCsddkl}ti|\}}|pti|\}}n|oq|ojti| oYyt||Wn,tj o }|i|joqnX|tjodSqnt||dS(smakedirs(path [, mode=0777]) 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. This is recursive. i(tEEXISTN( terrnoR RtsplittexiststmakedirstOSErrorRtmkdir(RtmodeR theadttailte((s/sys/lib/python/os.pyR$s    cCst|ti|\}}|pti|\}}nxM|oE|o>yt|Wntj oPnXti|\}}qBWdS(sremovedirs(path) 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(trmdirRR"terror(RR(R)((s/sys/lib/python/os.pyt removedirss cCsti|\}}|o&|oti| ot|nt||ti|\}}|o/|o(yt|Wqtj oqXndS(s@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 way 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(RR"R#R$trenameR-R,(toldtnewR(R)((s/sys/lib/python/os.pytrenamess R$R-R1c cs>ddkl}l}l}yt|}Wn4tj o(}|dj o||ndSnXgg}} xB|D]:} |||| o|i| qw| i| qwW|o||| fVnxP|D]H} ||| } || p&x#t| ||D] } | Vq WqqW|p||| fVndS(se 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. By default errors from the os.listdir() call are ignored. If optional arg 'onerror' is specified, it should be a function; it will be called with one argument, an os.error 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. 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: from os.path import join, getsize for root, dirs, files in walk('python/Lib/email'): print root, "consumes", print sum([getsize(join(root, name)) for name in files]), print "bytes in", len(files), "non-directory files" if 'CVS' in dirs: dirs.remove('CVS') # don't visit CVS directories i(tjointisdirtislinkN( tos.pathR2R3R4tlistdirR,tNonetappendtwalk( ttopttopdowntonerrorR2R3R4tnamesterrtdirstnondirsRRtx((s/sys/lib/python/os.pyR9s04    R9cGst||dS(spexecl(file, *args) Execute the executable file with argument list args, replacing the current process. N(texecv(tfiletargs((s/sys/lib/python/os.pytexecl=scGs"|d}t||d |dS(sexecle(file, *args, env) Execute the executable file with argument list args and environment env, replacing the current process. iN(texecve(RCRDtenv((s/sys/lib/python/os.pytexecleDs cGst||dS(sexeclp(file, *args) Execute the executable file (which is searched for along $PATH) with argument list args, replacing the current process. N(texecvp(RCRD((s/sys/lib/python/os.pytexeclpLscGs"|d}t||d |dS(sexeclpe(file, *args, env) Execute the executable file (which is searched for along $PATH) with argument list args and environment env, replacing the current process. iN(texecvpe(RCRDRG((s/sys/lib/python/os.pytexeclpeSs cCst||dS(sexecp(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(t_execvpe(RCRD((s/sys/lib/python/os.pyRI\scCst|||dS(sexecvpe(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(RM(RCRDRG((s/sys/lib/python/os.pyRKdsRERHRJRLRIRKcCs{ddkl}l}|dj ot}||f}nt}|f}t}ti|\}}|o|||dSnd|jo|d} nt } | it } d} d} x| D]} ti | |}y|||Wqt j oV}t id}|i|jo-|i|jo| djo|} |} qPqXqW| ot | | nt ||dS(Ni(tENOENTtENOTDIRtPATHi(R!RNROR7RFRBtenvironRR"RRR2R,tsystexc_info(RCRDRGRNROtfunctargrestR(R)tenvpathRPt saved_exctsaved_tbRtfullnameR*ttb((s/sys/lib/python/os.pyRMos>      cCst|ddS(Nt(tputenv(tkey((s/sys/lib/python/os.pytunsetenvs(t_EnvironR_cBseZdZdZdZyeWnej odZn XdZdZdZ d dZ d dZ d Z RS( cCsJtii||i}x*|iD]\}}|||i 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(RR7RB(R'RCRD((s/sys/lib/python/os.pyR.scCst||||tS(s: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. (RRF(R'RCRDRG((s/sys/lib/python/os.pytspawnve7scCst|||dtS(s8spawnvp(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(RR7RI(R'RCRD((s/sys/lib/python/os.pytspawnvpCscCst||||tS(s\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. (RRK(R'RCRDRG((s/sys/lib/python/os.pytspawnvpeMscGst|||S(sspawnl(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(R'RCRD((s/sys/lib/python/os.pytspawnl[scGs!|d}t|||d |S(s: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. i(R(R'RCRDRG((s/sys/lib/python/os.pytspawnleds RRRRcGst|||S(sWspawnlp(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'RCRD((s/sys/lib/python/os.pytspawnlpvscGs!|d}t|||d |S(s]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. i(R(R'RCRDRG((s/sys/lib/python/os.pytspawnlpes RRRtpopen2ttcCs.ddk}|i||\}}||fS(sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout) are returned.iN(R(tcmdR'tbufsizeRtstdouttstdin((s/sys/lib/python/os.pyRs tpopen3cCs4ddk}|i||\}}}|||fS(sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout, child_stderr) are returned.iN(RR(RR'RRRRtstderr((s/sys/lib/python/os.pyRs tpopen4cCs.ddk}|i||\}}||fS(sExecute the shell command 'cmd' in a sub-process. On UNIX, 'cmd' may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with os.spawnv()). If 'cmd' is a string it will be passed to the shell (as with os.system()). If 'bufsize' is specified, it sets the buffer size for the I/O pipes. The file objects (child_stdin, child_stdout_stderr) are returned.iN(RR(RR'RRRR((s/sys/lib/python/os.pyRs cCs t||S(N(t stat_result(ttupRr((s/sys/lib/python/os.pyt_make_stat_resultscCs|i\}}t|fS(N(t __reduce__R(tsrttypeRD((s/sys/lib/python/os.pyt_pickle_stat_resultscCs t||S(N(tstatvfs_result(RRr((s/sys/lib/python/os.pyt_make_statvfs_resultscCs|i\}}t|fS(N(RR(RRRD((s/sys/lib/python/os.pyt_pickle_statvfs_resultsturandomc Csytdt}Wn%ttfj otdnXd}x5t||jo!|t||t|7}qDWt||S(sfurandom(n) -> str Return a string of n random bytes suitable for cryptographic use. s /dev/randoms&/dev/urandom (or equivalent) not foundR[(topentO_RDONLYR%tIOErrortNotImplementedErrortlentreadtclose(Rt _urandomfdtbytes((s/sys/lib/python/os.pyRs" (sos2snt(sos2snt(Yt__doc__RRtbuiltin_module_namest_namesRRRRRRt ImportErrort posixpathRtextendRtntpathRtversiontfindt os2emxpatht _emx_linkRRtmacpathRRt riscospathtmodulesR5RRRRRRRR R R R R$R-R1R{R7R9R8RQRwRERHRJRLRIRKRMR\R`R^t riscosenvironR_tIterableUserDictRyR}tP_WAITRt P_NOWAITORRRRRRRRRRRRtcopy_regt _copy_regRRtpickleRRRRR(((s/sys/lib/python/os.pyssH                              :   U        %     .#    (