U l a@sdZddlZddlZddlZddlZddlZddlZddlmZddl m Z ddddd d d gZ Gd d d eZ d dZ e dfddZe fdd Ze fddZe fddZeeefZdS)z/Utilities for extracting common archive formatsN)DistutilsError)ensure_directoryunpack_archiveunpack_zipfileunpack_tarfiledefault_filterUnrecognizedFormatextraction_driversunpack_directoryc@seZdZdZdS)rz#Couldn't recognize the archive typeN)__name__ __module__ __qualname____doc__rrXC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-wx4infiz\setuptools\archive_util.pyrscCs|S)z@The default progress/filter callback; returns True for all filesr)srcdstrrrrsc CsN|ptD]4}z||||Wntk r4YqYqXdSqtd|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_filterZdriversZdriverrrrrs  c 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) ospathisdirrwalkjoinrshutilcopyfilecopystat) rrrpathsbasedirsfilesrrdftargetrrrr @s$   * c Cst|std|ft|}|D]}|j}|ds,d|dkrPq,tj j |f|d}|||}|sxq,| drt |n4t || |j}t|d}||W5QRX|jd?} | r,t|| q,W5QRXdS)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 filer..wbN)zipfile is_zipfilerZipFileinfolistr startswithsplitrrrendswithrreadopenwrite external_attrchmod) rrrzinfonamer&datar%Zunix_attributesrrrr[s(         c Csfzt|}Wn$tjk r2td|fYnXt|dd|_|D]}|j}|dsPd| dkrPt j j |f| d}|dk r| s|r|j}|rt|j}t ||}t|}||}q|dk rP|s|rP|||} | rP| t jr"| dd} z||| WqPtjk rJYqPXqPW5QRdSQRXdS) 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 filecWsdS)Nr)argsrrrz unpack_tarfile..rr'NT)tarfiler2TarErrorr contextlibclosingchownr8r.r/rrrislnkissymlinkname posixpathdirnamenormpath _getmemberisfilerr0sep_extract_member ExtractError) rrrtarobjmemberr8Z prelim_dstlinkpathr!Z final_dstrrrrsB         )rr*r>rrrFr@distutils.errorsr pkg_resourcesr__all__rrrr rrr rrrrs2   $  % /