a „oe£ã@sÈdZddlZddlZddlZddlZddlZddlZddlmZddl m Z gd¢Z Gdd„deƒZ d d „Z e dfd d „Ze fd d„Ze fdd„Ze fdd„Zdd„Zdd„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)r z#Couldn't recognize the archive typeN)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú8C:\Program Files\Certbot\pkgs\setuptools\archive_util.pyr sr cCs|S)z@The default progress/filter callback; returns True for all filesr)ÚsrcÚdstrrrrsrc CsL|ptD]2}z||||ƒWnty2YqYq0dSqtd|ƒ‚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_filterZdriversZdriverrrrr!s   rc 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ÚshutilÚcopyfileÚcopystat) rrrÚpathsÚbaseÚdirsÚfilesrrÚdÚfÚtargetrrrr As"  ÿ * r cCsRt |¡std|fƒ‚t |¡�}t|||ƒWdƒn1sD0YdS)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 fileN)ÚzipfileÚ is_zipfiler ÚZipFileÚ_unpack_zipfile_obj)rrrÚzrrrr\s  rc CsÒ| ¡D]Ä}|j}| d¡sd| d¡vr,qtjj|g| d¡¢RŽ}|||ƒ}|sVq| d¡rjt|ƒnHt|ƒ|  |j¡}t |dƒ�}|  |¡Wdƒn1s¨0Y|j d?}|rt  ||¡qdS)z·Internal/private API used by other parts of setuptools. Similar to ``unpack_zipfile``, but receives an already opened :obj:`zipfile.ZipFile` object instead of a filename. rú..ÚwbNé)ÚinfolistrÚ startswithÚsplitrrrÚendswithrÚreadÚopenÚwriteZ external_attrÚchmod) Z zipfile_objrrÚinfoÚnamer'Údatar&Zunix_attributesrrrr+ks"      ( r+cCs€|durT| ¡s| ¡rT|j}| ¡rHt |j¡}t ||¡}t |¡}| |¡}q|duoj|  ¡pj|  ¡}|rt|St dƒ‚dS)z;Resolve any links and extract link targets as normal files.NzGot unknown file type) ZislnkZissymZlinknameÚ posixpathÚdirnamer9rÚnormpathZ _getmemberÚisfilerÚ LookupError)Útar_objZtar_member_objZlinkpathr"Zis_file_or_dirrrrÚ_resolve_tar_file_or_dir‰s"ÿÿ    ÿrAc csÔdd„|_t |¡�¬|D]–}|j}| d¡sd| d¡vr>qtjj|g| d¡¢RŽ}zt ||ƒ}Wnt y|YqYn0|||ƒ}|sŽq|  tj ¡r¦|dd…}||fVqWdƒn1sÆ0YdS)z1Emit member-destination pairs from a tar archive.cWsdS)Nr)ÚargsrrrÚ¡óz _iter_open_tar..rr-Néÿÿÿÿ) ÚchownÚ contextlibÚclosingr9r1r2rrrrAr?r3Úsep)r@rrÚmemberr9Z prelim_dstÚ final_dstrrrÚ_iter_open_taržs"       rLc Cs†zt |¡}Wn6tjyD}ztd|fƒ|‚WYd}~n d}~00t|||ƒD].\}}z| ||¡WqRtjy~YqR0qRdS)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 fileNT)Útarfiler5ÚTarErrorr rLZ_extract_memberZ ExtractError)rrrÚtarobjÚerJrKrrrr»s$ÿþý r)rr(rMrrr;rGZdistutils.errorsrÚ_pathrÚ__all__r rrr rr+rArLrr rrrrÚs&