grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î £ fÞ›ã1@sëdZddlZddlZddlZddlmZddlZddlZddlZddl Z yddl Z [ dZ Wne k r�dZ YnXyddl mZWne k rÌdZYnXyddlmZWne k rûdZYnXdd d d d d ddddddddddddddddddd gZGd!d„deƒZGd"d „d eƒZGd#d„deƒZGd$d„deƒZGd%d&„d&eƒZGd'd(„d(eƒZd}d+d„Zd,d-„Zd.dd/d „Zd.dd0d „Zeed1ƒr4d.dd2d3„Zn d4d3„Zd.dd5d „Z d.dd6d „Z!d.dd7d „Z"d8d„Z#dde"dd9d„Z$d:d;„Z%d<d=„Z&ej'ejej(ej)hej*koúej+ej,koúejej-kZ.ddd>d„Z/e.e/_0d?d@„Z1dAd„Z2dBdC„Z3dDdE„Z4dFdG„Z5dHddddddIdJ„Z6dddKdL„Z7ddddMdN„Z8ie6d~gdPfdQ6e6dgdRfdS6e8gdTfdU6Z9e rôe6d€gdWfe9dXd_d`„Z?ddZdad„Z@dbd„ZAdcdd„ZBdedf„ZCdgdh„ZDididjgeDgdPfdQ6dkgeDgdRfdS6dlgeCgdTfdU6ZEe rdmgeDgdWfeEdX._nopcstt|ˆƒS)N)Úgetattrr-)rL)rRr!r"Úlookup¯szcopystat..lookupcs)tt|ˆƒ}|tjkr%|SˆS)N)rSr-Úsupports_follow_symlinks)rLr?)rRr!r"rT´sr8ÚutimerBÚst_flagsZchflagsÚ EOPNOTSUPPrG)rXzENOTSUP)r-r.r;r8rDr:Ú st_atime_nsÚ st_mtime_nsÚNotImplementedErrorr,rWr/rFrSrN) r1r2r4ZfollowrTr@ÚmodeÚwhyÚerrr!)rRr"r¡s,+!   'cCs`tjj|ƒr6tjj|tjj|ƒƒ}nt||d|ƒt||d|ƒ|S)a3Copy data and mode bits ("cp src dst"). Return the file's destination. The destination may be a directory. If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst". If source and destination are the same file, a SameFileError will be raised. r4)r-r.ÚisdirÚjoinÚbasenamerr)r1r2r4r!r!r"r ×s $cCs`tjj|ƒr6tjj|tjj|ƒƒ}nt||d|ƒt||d|ƒ|S)zéCopy data and all stat info ("cp -p src dst"). Return the file's destination." The destination may be a directory. If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst". r4)r-r.r_r`rarr)r1r2r4r!r!r"r és $cs‡fdd†}|S)z�Function that can be used as copytree() ignore parameter. Patterns is a sequence of glob-style patterns that are used to exclude filescs:g}x'ˆD]}|jtj||ƒƒq Wt|ƒS)N)ÚextendÚfnmatchÚfilterÚset)r.rJÚ ignored_namesÚpattern)Úpatternsr!r"Ú_ignore_patternsþs z)ignore_patterns.._ignore_patternsr!)rhrir!)rhr"rùscCstj|ƒ}|dk r-|||ƒ}n tƒ}tj|ƒg}xª|D]¢} | |krhqPntjj|| ƒ} tjj|| ƒ} yätjj| ƒr=tj| ƒ} |rãtj| | ƒt | | d| ƒqutjj | ƒ r|rwPntjj | ƒr-t | | |||ƒqu|| | ƒn8tjj | ƒrht | | |||ƒn || | ƒWqPt k r±} z|j| jdƒWYdd} ~ XqPtk rñ}z!|j| | t|ƒfƒWYdd}~XqPXqPWyt ||ƒWn\tk re}z<t|ddƒdkrS|j||t|ƒfƒnWYdd}~XnX|r{t |ƒ‚n|S)aüRecursively copy a directory tree. The destination directory must not already exist. If exception(s) occur, an Error is raised with a list of reasons. If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied. If the file pointed by the symlink doesn't exist, an exception will be added in the list of errors raised in an Error exception at the end of the copy process. You can set the optional ignore_dangling_symlinks flag to true if you want to silence this exception. Notice that this has no effect on platforms that don't support os.symlink. The optional ignore argument is a callable. If given, it is called with the `src` parameter, which is the directory being visited by copytree(), and `names` which is the list of `src` contents, as returned by os.listdir(): callable(src, names) -> ignored_names Since copytree() is called recursively, the callable will be called once for each directory that is copied. It returns a list of names relative to the `src` directory that should not be copied. The optional copy_function argument is a callable that will be used to copy each file. It will be called with the source path and the destination path as arguments. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. Nr4rZwinerror)r-ÚlistdirreÚmakedirsr.r`r;r=r<rÚexistsr_r rrbrOr/ÚappendÚstrrS)r1r2ÚsymlinksÚignoreZ copy_functionZignore_dangling_symlinksrJrfÚerrorsrLZsrcnameZdstnameÚlinktor^r]r!r!r"r sL$      &32c$Cs™y%tjj|ƒr$tdƒ‚nWn2tk rY|tjj|tjƒƒdSYnXg}ytj|ƒ}Wn+tk r |tj|tjƒƒYnXx²|D]ª}tjj||ƒ}ytj|ƒj }Wntk ród}YnXt j |ƒrt ||ƒq¨ytj |ƒWq¨tk rQ|tj |tjƒƒYq¨Xq¨Wytj|ƒWn+tk r”|tj|tjƒƒYnXdS)Nz%Cannot call rmtree on a symbolic linkr)r-r.r;r/ÚsysÚexc_inforjr`rCr:r8ÚS_ISDIRÚ_rmtree_unsafeÚunlinkÚrmdir)r.ÚonerrorrJrLÚfullnamer\r!r!r"rv_s6       " rvc 0Cs@g}ytj|ƒ}WnGtk rb}z'||_|tj|tjƒƒWYdd}~XnXxÖ|D]Î}tjj||ƒ}y(tj|d|ddƒ}|j }Wntk rÇd}YnXtj |ƒróytj |tj d|ƒ} Wn+tk r#|tj |tjƒƒYq8Xz»tjj |tj| ƒƒr�t| ||ƒytj|d|ƒWqÞtk r™|tj|tjƒƒYqÞXnAytdƒ‚Wn.tk rÝ|tjj|tjƒƒYnXWdtj| ƒXqjytj|d|ƒWqjtk r7|tj|tjƒƒYqjXqjWdS)NÚdir_fdr4Frz%Cannot call rmtree on a symbolic link)r-rjr/Úfilenamersrtr.r`r8r:rur>ÚO_RDONLYÚsamestatÚfstatÚ_rmtree_safe_fdrxr;Úcloserw) Útopfdr.ryrJr^rLrzÚorig_str\Údirfdr!r!r"r€€sD ,      ! % r€c!CsÁ|rdd„}n|dkr0dd„}ntr°t|tƒrWtj|ƒ}nytj|ƒ}Wn/tk r›|tj|tjƒƒdSYnXytj |tj ƒ}Wn/tk ræ|tj|tjƒƒdSYnXzµtj j |tj |ƒƒrZt|||ƒytj|ƒWq›tk rV|tj|tjƒƒYq›XnAytdƒ‚Wn.tk rš|tj j|tjƒƒYnXWdtj|ƒXn t||ƒSdS)aÄRecursively delete a directory tree. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error with arguments (func, path, exc_info) where func is platform and implementation dependent; path is the argument to that function that caused it to fail; and exc_info is a tuple returned by sys.exc_info(). If ignore_errors is false and onerror is None, an exception is raised. cWsdS)Nr!)rOr!r!r"ry½szrmtree..onerrorNcWs‚dS)Nr!)rOr!r!r"ryÀsz%Cannot call rmtree on a symbolic link)Ú_use_fd_functionsÚ isinstanceÚbytesr-ÚfsdecoderCÚ Exceptionrsrtr>r}r.r~rr€rxr/r;r�rv)r.Ú ignore_errorsryrƒÚfdr!r!r"r ±s<       ! %cCs5tjjtjjpd}tjj|j|ƒƒS)NÚ)r-r.ÚsepÚaltsepraÚrstrip)r.r�r!r!r"Ú _basenameèsr�c Cs`|}tjj|ƒr~t||ƒr;tj||ƒdStjj|t|ƒƒ}tjj|ƒr~td|ƒ‚q~nytj||ƒWnÇt k r[tjj |ƒrãtj |ƒ}tj ||ƒtj |ƒnttjj|ƒr=t||ƒrtd||fƒ‚nt||ddƒt|ƒnt||ƒtj |ƒYnX|S)a0Recursively move a file or directory to another location. This is similar to the Unix "mv" command. Return the file or directory's destination. If the destination is a directory or a symlink to a directory, the source is moved inside the directory. The destination path must not already exist. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics. If the destination is on our current filesystem, then rename() is used. Otherwise, src is copied to the destination and then removed. Symlinks are recreated under the new name if os.rename() fails because of cross filesystem renames. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. Nz$Destination path '%s' already existsz.Cannot move a directory '%s' into itself '%s'.roT)r-r.r_r3Úrenamer`r�rlrr/r;r=r<rwÚ _destinsrcr r r )r1r2Zreal_dstrrr!r!r"r îs.   cCsut|ƒ}t|ƒ}|jtjjƒs@|tjj7}n|jtjjƒsh|tjj7}n|j|ƒS)N)rÚendswithr-r.r�Ú startswith)r1r2r!r!r"r’s  r’c Cs_tdks|dkrdSyt|ƒ}Wntk rFd}YnX|dk r[|dSdS)z"Returns a gid, given a group name.Né)rÚKeyError)rLÚresultr!r!r"Ú_get_gid(s   r˜c Cs_tdks|dkrdSyt|ƒ}Wntk rFd}YnX|dk r[|dSdS)z"Returns an uid, given a user name.Nr•)rr–)rLr—r!r!r"Ú_get_uid4s   r™Úgzipc s†idd6dd6}idd6} tr>d|d._set_uid_gidzw|%srd)Ú_BZ2_SUPPORTEDÚ ValueErrorr7Úgetr-r.ÚdirnamerlÚinforkr™r˜Útarfiler>Úaddr�)Ú base_nameÚbase_dirÚcompressÚverboseÚdry_runr¡r ÚloggerZtar_compressionZ compress_extZ archive_nameÚ archive_dirr¢Útarr!)r�r r¡ržr"Ú _make_tarball@s4         r²c Cs~|rd}nd}ddlm}ddlm}y |d|||gd|ƒWn"|k rytdƒ|‚YnXdS) Nz-rz-rqr)ÚDistutilsExecError)ÚspawnÚzipr®zkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)Zdistutils.errorsr³Zdistutils.spawnr´r)r«Ú zip_filenamer­r®Z zipoptionsr³r´r!r!r"Ú_call_external_zip~s    r·cCsN|d}tjj|ƒ}|rmtjj|ƒ rm|dk rT|jd|ƒn|smtj|ƒqmnyddl}Wntk r—d}YnX|dkrºt||||ƒn�|dk rÜ|jd||ƒn|sJ|j |dd|j ƒ�H}tjj |ƒ} |j | | ƒ|dk rA|jd| ƒnxýtj |ƒD]ì\} } } xdt| ƒD]V} tjj tjj| | ƒƒ} |j | | ƒ|dk rm|jd| ƒqmqmWxs| D]k} tjj tjj| | ƒƒ} tjj| ƒrÎ|j | | ƒ|dk r9|jd| ƒq9qÎqÎWqQWWdQXn|S) amCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises ExecError. Returns the name of the output zip file. z.zipNz creating %srz#creating '%s' and adding '%s' to itÚwZ compressionz adding '%s')r-r.r¦rlr§rkÚzipfileÚ ImportErrorr·ÚZipFileZ ZIP_DEFLATEDÚnormpathr(ÚwalkÚsortedr`Úisfile)rªr«r­r®r¯r¶r°r¹Zzfr.ÚdirpathZdirnamesÚ filenamesrLr!r!r"Ú _make_zipfile�sH         !  ! 'rÂr¬zgzip'ed tar-fileZgztarzuncompressed tar filer±zZIP filerµrœzbzip2'ed tar-fileZbztarcCs'dd„tjƒDƒ}|jƒ|S)z‘Returns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) cSs&g|]\}}||df‘qS)r•r!)Ú.0rLÚregistryr!r!r"ú Ôs z'get_archive_formats..)Ú_ARCHIVE_FORMATSÚitemsÚsort)Úformatsr!r!r"rÏs  rŒcCs·|dkrg}nt|ƒs4td|ƒ‚nt|ttfƒsXtdƒ‚nxE|D]=}t|ttfƒ s�t|ƒdkr_tdƒ‚q_q_W|||ft|.)Ú_UNPACK_FORMATSrÇrÈ)rÉr!r!r"r(s  c Cs¡i}x9tjƒD]+\}}x|dD]}|||r(r�) r|Ú extract_dirr¹rµr§rLÚtargetÚdataÚfr!r!r"Ú_unpack_zipfilees0    rêcCs^ytj|ƒ}Wn%tjk r:td|ƒ‚YnXz|j|ƒWd|jƒXdS)z:Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` z/%s is not a compressed or uncompressed tar fileN)r¨r>ZTarErrorr$Z extractallr�)r|ræZtarobjr!r!r"Ú_unpack_tarfileŠsrëz.tar.gzz.tgzz.tarz.zipz.bz2cCsIxBtjƒD]4\}}x%|dD]}|j|ƒr$|Sq$Wq WdS)Nr)rÝrÇr“)r|rLr§ràr!r!r"Ú_find_unpack_format¡s  rìcCsì|dkrtjƒ}n|dk r†yt|}Wn'tk r^tdj|ƒƒ‚YnX|d}|||t|dƒ�nbt|ƒ}|dkr¶tdj|ƒƒ‚nt|d}tt|dƒ}||||�dS)aöUnpack an archive. `filename` is the name of the archive. `extract_dir` is the name of the target directory, where the archive is unpacked. If not provided, the current working directory is used. `format` is the archive format: one of "zip", "tar", or "gztar". Or any other registered format. If not provided, unpack_archive will use the filename extension and see if an unpacker was registered for that extension. In case none is found, a ValueError is raised. NzUnknown unpack format '{0}'rÓr•zUnknown archive format '{0}') r-rÔrÝr–r¤r7Údictrìr$)r|rær7rØrÙrPr!r!r"r¨s      ÚstatvfsÚ disk_usageZusageztotal used freecCsVtj|ƒ}|j|j}|j|j}|j|j|j}t|||ƒS)zÖReturn disk usage statistics about the given path. Returned value is a named tuple with attributes 'total', 'used' and 'free', which are the amount of total, used and free space, in bytes. )r-rîÚf_bavailÚf_frsizeÚf_blocksÚf_bfreeÚ_ntuple_diskusage)r.r@ÚfreeÚtotalÚusedr!r!r"rïÒs ÚntcCs/tj|ƒ\}}||}t|||ƒS)z×Return disk usage statistics about the given path. Returned values is a named tuple with attributes 'total', 'used' and 'free', which are the amount of total, used and free space, in bytes. )røZ _getdiskusagerô)r.rörõr÷r!r!r"rïäs cCsø|dkr'|dkr'tdƒ‚n|}|}|dkrHd}nBt|tƒrŠt|ƒ}|dkrŠtdj|ƒƒ‚qŠn|dkrŸd}nBt|tƒsát|ƒ}|dkrátdj|ƒƒ‚qántj |||ƒdS)z¹Change owner user and group of the given path. user and group can be the uid/gid or the user/group names, and in that case, they are converted to their respective uid/gid. Nzuser and/or group must be setrÓzno such user: {!r}zno such group: {!r}éÿÿÿÿrù) r¤r†rnr™Ú LookupErrorr7Úintr˜r-r)r.Úuserr Z_userZ_groupr!r!r"rïs"        éPécCsyttjdƒ}Wnttfk r7d}YnXyttjdƒ}Wnttfk rod}YnX|dksˆ|dkrytjtjjƒƒ}Wn't t fk rÍtj |ƒ}YnX|dkræ|j }n|dkr|j }qntj ||fƒS)aGet the size of the terminal window. For each of the two dimensions, the environment variable, COLUMNS and LINES respectively, is checked. If the variable is defined and the value is a positive integer, it is used. When COLUMNS or LINES is not defined, which is the common case, the terminal connected to sys.__stdout__ is queried by invoking os.get_terminal_size. If the terminal size cannot be successfully queried, either because the system doesn't support querying, or because we are not connected to a terminal, the value given in fallback parameter is used. Fallback defaults to (80, 24) which is the default size used by many terminal emulators. The value returned is a named tuple of type os.terminal_size. ZCOLUMNSrZLINES)rûr-Úenvironr–r¤rrsÚ __stdout__ÚfilenoÚ NameErrorr/Ú terminal_sizeÚcolumnsÚlines)ZfallbackrrÚsizer!r!r"rs$     c s¢dd„}tjjˆƒr5|ˆ|ƒr1ˆSdS|dkr\tjjdtjƒ}n|sfdS|jtjƒ}tj dkrtj |kr¬|j dtj ƒntjjddƒjtjƒ}t ‡fd d †|Dƒƒrøˆg}q‡fd d †|Dƒ}n ˆg}t ƒ}xu|D]m}tjj|ƒ}||kr-|j|ƒx9|D].} tjj|| ƒ} || |ƒre| SqeWq-q-WdS) a3Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file. `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of os.environ.get("PATH"), or can be overridden with a custom search path. cSs5tjj|ƒo4tj||ƒo4tjj|ƒ S)N)r-r.rlÚaccessr_)r?r\r!r!r"Ú _access_checkFs$zwhich.._access_checkNÚPATHÚwin32rZPATHEXTrŒc3s*|] }ˆjƒj|jƒƒVqdS)N)Úlowerr“)rÃrß)Úcmdr!r"ú cszwhich..csg|]}ˆ|‘qSr!r!)rÃrß)r r!r"rÅfs zwhich..)r-r.r¦rÿr¥ÚdefpathråÚpathseprsÚplatformr×ÚinsertÚanyrer0r©r`) r r\r.rZpathextÚfilesÚseenÚdirZnormdirZthefilerLr!)r r"r9s8  !       i@)úcompresszgzip)rN)rzbzip2)rýrþ)Sr#r-rsr8Zos.pathrrcÚ collectionsrFr¨r›r£rºÚpwdrZgrprÚ__all__r/rrrrr$r‰r%rr3rrr,rNrr r rr rvr€r>rwrxÚsupports_dir_fdrjÚ supports_fdrUr…r Zavoids_symlink_attacksr�r r’r˜r™r²r·rÂrÆrrrrrrârrrãrêrërÝrìrrmÚ namedtuplerôrïrLrørrÚF_OKÚX_OKrr!r!r!r"ÚsÖ                    6 Y ! , 5   1 =6    6    %   %     +