U âQabÀã@s¶dZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddddd d d gZ Gd d „d eƒZ d d„Z e dfdd„Ze fdd „Ze fdd„Ze fdd„ZeeefZdS)z/Utilities for extracting common archive formatséN)ÚDistutilsError)Úensure_directoryÚunpack_archiveÚunpack_zipfileÚunpack_tarfileÚdefault_filterÚUnrecognizedFormatÚextraction_driversÚunpack_directoryc@seZdZdZdS)rz#Couldn't recognize the archive typeN)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú;/usr/lib/python3.8/site-packages/setuptools/archive_util.pyrscCs|S)z@The default progress/filter callback; returns True for all filesr)ÚsrcÚdstrrrrsc CsN|ptD]4}z||||ƒWntk r4YqYqXdSqtd|ƒ‚dS)a¡Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat`` `progress_filter` is a function taking two arguments: a source path internal to the archive ('/'-separated), and a filesystem path where it will be extracted. The callback must return the desired extract path (which may be the same as the one passed in), or else ``None`` to skip that file or directory. The callback can thus be used to report on the progress of the extraction, as well as to filter the items extracted or alter their extraction paths. `drivers`, if supplied, must be a non-empty sequence of functions with the same signature as this function (minus the `drivers` argument), that raise ``UnrecognizedFormat`` if they do not support extracting the designated archive type. The `drivers` are tried in sequence until one is found that does not raise an error, or until all are exhausted (in which case ``UnrecognizedFormat`` is raised). If you do not supply a sequence of drivers, the module's ``extraction_drivers`` constant will be used, which means that ``unpack_zipfile`` and ``unpack_tarfile`` will be tried, in that order. Nz!Not a recognized archive type: %s)r r)ÚfilenameÚ extract_dirÚprogress_filterZdriversZdriverrrrrs  ÿc CsÖtj |¡std|ƒ‚|d|fi}t |¡D]¢\}}}||\}}|D],} || dtj || ¡f|tj || ¡<qH|D]T} tj || ¡} ||| | ƒ} | s qzt| ƒtj || ¡} t | | ¡t  | | ¡qzq.dS)z‡"Unpack" a directory, using the same interface as for archives Raises ``UnrecognizedFormat`` if `filename` is not a directory z%s is not a directoryÚú/N) ÚosÚpathÚisdirrÚwalkÚjoinrÚshutilZcopyfileZcopystat) rrrÚpathsÚbaseÚdirsÚfilesrrÚdÚfÚtargetrrrr ?s$  ÿ * c Csêt |¡std|fƒ‚t |¡¾}| ¡D]®}|j}| d¡s,d| d¡krPq,tj j |f| d¡žŽ}|||ƒ}|sxq,|  d¡rŒt |ƒn4t |ƒ|  |j¡}t|dƒ}| |¡W5QRX|jd?} | r,t || ¡q,W5QRXdS)zòUnpack zip `filename` to `extract_dir` Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined by ``zipfile.is_zipfile()``). See ``unpack_archive()`` for an explanation of the `progress_filter` argument. z%s is not a zip filerú..ÚwbéN)ÚzipfileZ is_zipfilerZZipFileZinfolistrÚ startswithÚsplitrrrÚendswithrÚreadÚopenÚwriteZ external_attrÚchmod) rrrÚzÚinfoÚnamer$Údatar#Zunix_attributesrrrrZs(         c Csfzt |¡}Wn$tjk r2td|fƒ‚YnXt |¡dd„|_|D]ú}|j}| d¡sPd|  d¡krPt j j |f|  d¡žŽ}|dk rà|  ¡s¤| ¡rà|j}| ¡rÔt |j¡}t  ||¡}t |¡}| |¡}qŒ|dk rP| ¡sú| ¡rP|||ƒ} | rP|  t j¡r"| dd…} z| || ¡WqPtjk rJYqPXqPW5QR£dSQRXdS) zûUnpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined by ``tarfile.open()``). See ``unpack_archive()`` for an explanation of the `progress_filter` argument. z/%s is not a compressed or uncompressed tar filecWsdS)Nr)ÚargsrrrÚŽóz unpack_tarfile..rr%NéÿÿÿÿT)Útarfiler-ZTarErrorrÚ contextlibÚclosingÚchownr2r)r*rrrZislnkZissymZlinknameÚ posixpathÚdirnameÚnormpathZ _getmemberÚisfilerr+ÚsepZ_extract_memberZ ExtractError) rrrZtarobjÚmemberr2Z prelim_dstZlinkpathrZ final_dstrrrrs:ÿ         )rr(r8rrr<r9Zdistutils.errorsrZ pkg_resourcesrÚ__all__rrrr rrr rrrrÚs2  þÿ #  % .