3

Q'ícÀã@s¶dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddddd	d
dgZGd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ú=/tmp/pip-build-l_bcah40/setuptools/setuptools/archive_util.pyrscCs|S)z@The default progress/filter callback; returns True for all filesr)ÚsrcÚdstrrrrscCsNxH|ptD]0}y||||ƒWntk
r4w
Yq
XdSq
Wtd|ƒ‚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_filterZdriversZdriverrrrrscCsâtjj|ƒstd|ƒ‚|d|fi}x¸tj|ƒD]ª\}}}||\}}x4|D],}	||	dtjj||	ƒf|tjj||	ƒ<qLWx\|D]T}
tjj||
ƒ}|||
|ƒ}|s¨q‚t|ƒtjj||
ƒ}
tj|
|ƒtj	|
|ƒq‚Wq0WdS)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
?s 
,
c
Csîtj|ƒstd|fƒ‚tj|ƒÂ}xº|jƒD]®}|j}|jdƒs.d|jdƒkrRq.tj	j
|f|jdƒžŽ}|||ƒ}|szq.|jdƒrŽt|ƒn4t|ƒ|j
|jƒ}t|dƒ}|j|ƒWdQRX|jd?}	|	r.tj||	ƒq.WWdQRXdS)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 filerz..ÚwbNé)ÚzipfileÚ
is_zipfilerÚZipFileÚinfolistrÚ
startswithÚsplitrrrÚendswithrÚreadÚopenÚwriteÚ
external_attrÚchmod)
rrrÚzÚinfoÚnamer&Údatar%Zunix_attributesrrrrZs(




c
Cshytj|ƒ}Wn$tjk
r2td|fƒ‚YnXtj|ƒdd„|_x
|D]}|j}|jdƒoxd|j	dƒkrTt
jj|f|j	dƒžŽ}xV|dk	rè|j
ƒs¬|jƒrè|j}|jƒrÜtj|jƒ}tj||ƒ}tj|ƒ}|j|ƒ}q”W|dk	rT|jƒs|jƒrT|||ƒ}	|	rT|	jt
jƒr,|	dd	…}	y|j||	ƒWqTtjk
rTYqTXqTWdSQRXdS)
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Ú<lambda>Žsz unpack_tarfile.<locals>.<lambda>rz..NéTéÿÿÿÿ)Útarfiler1ÚTarErrorrÚ
contextlibÚclosingÚchownr7r-r.rrrÚislnkÚissymÚlinknameÚ	posixpathÚdirnameÚnormpathÚ
_getmemberÚisfilerr/ÚsepÚ_extract_memberÚExtractError)
rrrÚtarobjÚmemberr7Z
prelim_dstÚlinkpathr!Z	final_dstrrrrs8



)rr)r=rrrEr?Zdistutils.errorsrÚ
pkg_resourcesrÚ__all__rrrr
rrr	rrrrÚ<module>s$
"%.