a oe@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z gdZ GdddeZ d d Z e dfd d Ze fd dZe fddZe fddZddZddZe fddZeeefZdS)z/Utilities for extracting common archive formatsN)DistutilsError)ensure_directory)unpack_archiveunpack_zipfileunpack_tarfiledefault_filterUnrecognizedFormatextraction_driversunpack_directoryc@seZdZdZdS)r z#Couldn't recognize the archive typeN)__name__ __module__ __qualname____doc__rr8C:\Program Files\Certbot\pkgs\setuptools\archive_util.pyr sr cCs|S)z@The default progress/filter callback; returns True for all filesr)srcdstrrrrsrc CsL|ptD]2}z||||Wnty2YqYq0dSqtd|dS)aUnpack `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_dirprogress_filterZdriversZdriverrrrr!s   rc Cstj|std||d|fi}t|D]\}}}||\}}|D],} || dtj|| f|tj|| <qH|D]T} tj|| } ||| | } | sqzt| 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) ospathisdirr walkjoinrshutilcopyfilecopystat) rrrpathsbasedirsfilesrrdftargetrrrr As"   * r cCsRt|std|ft|}t|||Wdn1sD0YdS)zUnpack 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)rrrzrrrr\s  rc Cs|D]}|j}|dsd|dvr,qtjj|g|dR}|||}|sVq|drjt|nHt|| |j}t |d}| |Wdn1s0Y|j d?}|rt ||qdS)zInternal/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 startswithsplitrrrendswithrreadopenwriteZ external_attrchmod) Z zipfile_objrrinfonamer'datar&Zunix_attributesrrrr+ks"      ( r+cCs|durT|s|rT|j}|rHt|j}t||}t|}||}q|duoj| pj| }|rt|St ddS)z;Resolve any links and extract link targets as normal files.NzGot unknown file type) ZislnkZissymZlinkname posixpathdirnamer9rnormpathZ _getmemberisfiler LookupError)tar_objZtar_member_objZlinkpathr"Zis_file_or_dirrrr_resolve_tar_file_or_dirs"    rAc csdd|_t||D]}|j}|dsd|dvr>qtjj|g|dR}zt ||}Wnt y|YqYn0|||}|sq| tj r|dd}||fVqWdn1s0YdS)z1Emit member-destination pairs from a tar archive.cWsdS)Nr)argsrrrz _iter_open_tar..rr-N) chown contextlibclosingr9r1r2rrrrAr?r3sep)r@rrmemberr9Z prelim_dst final_dstrrr_iter_open_tars"       rLc Cszt|}Wn6tjyD}ztd|f|WYd}~n d}~00t|||D].\}}z|||WqRtjy~YqR0qRdS)zUnpack 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)tarfiler5TarErrorr rLZ_extract_memberZ ExtractError)rrrtarobjerJrKrrrrs$ r)rr(rMrrr;rGZdistutils.errorsr_pathr__all__r rrr rr+rArLrr rrrrs&