JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/pip/_vendor/distlib/_backport/__pycache__/tarfile.cpython-39.pyc

a

[��f�i�
@sFddlmZdZdZdZdZdZdZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZzddlZddlZWney�dZZYn0eefZzeef7ZWney�Yn0gd	�Zejdd
kr�ddlZnddlZejZdZdZed
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5d Z6d!Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1fZ9e&e'e.e1fZ:e/e0e1fZ;d"Z<e=d#�Z>e?e?e?e@e@e@d$�ZAd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGd+ZHd,ZIdZJd-ZKd.ZLd/ZMd0ZNd1ZOd2ZPd3ZQd!ZRd ZSe	jTd4v�rd5ZUne�V�ZUd6d7�ZWd8d9�ZXd:d;�ZYd2e8fd<d=�ZZd>d?�Z[d{d@dA�Z\eBdBfeCdCfeDdDfeEdEfeFdFfeGdGffeKdHffeLdIffeMeHBdJfeHdKfeMdLffeNdHffeOdIffePeIBdJfeIdKfePdLffeQdHffeRdIffeSeJBdMfeJdNfeSdLfff
Z]dOdP�Z^GdQdR�dRe_�Z`GdSdT�dTe`�ZaGdUdV�dVe`�ZbGdWdX�dXe`�ZcGdYdZ�dZe`�ZdGd[d\�d\e`�ZeGd]d^�d^ee�ZfGd_d`�d`ee�ZgGdadb�dbee�ZhGdcdd�ddee�ZiGdedf�dfee�ZjGdgdh�dhek�ZlGdidj�djek�ZmGdkdl�dlek�ZnGdmdn�dnek�ZoGdodp�dpek�ZpGdqdr�drek�ZqGdsdt�dtek�ZrGdudv�dvek�ZsGdwdx�dxek�Ztdydz�ZueZvesjZdS)|�)�print_functionz
$Revision$z0.9.0u"Lars Gustäbel (lars@gustaebel.de)z5$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $z?$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.N)�TarFile�TarInfo�
is_tarfile�TarError����sustar  sustar00�d��0�1�2�3�4�5�6�7�L�K�S�x�g�X��)�path�linkpath�size�mtime�uid�gid�uname�gname)rrr#r$)Zatime�ctimer r!r"ri�i�i`�@i ii����@� ���)�ntZcezutf-8cCs(|�||�}|d|�|t|�tS)z8Convert a string to a null-terminated bytes object.
    N)�encode�len�NUL)�s�length�encoding�errors�r7�I/usr/lib/python3.9/site-packages/pip/_vendor/distlib/_backport/tarfile.py�stn�sr9cCs*|�d�}|dkr|d|�}|�||�S)z8Convert a null-terminated bytes object to a string.
    r���N)�find�decode)r3r5r6�pr7r7r8�nts�s
r>cCs�|dtd�krHztt|dd�p"dd�}Wq~tyDtd��Yq~0n6d}tt|�d�D] }|dK}|t||d�7}q\|S)	z/Convert a number field to a python number.
    rr)�ascii�strict�0r-zinvalid headerr)�chr�intr>�
ValueError�InvalidHeaderError�ranger1�ord)r3�n�ir7r7r8�nti�srJcCs�d|krd|dkr<nnd|d|f�d�t}n||tksT|d|dkr\td��|dkr|t�dt�d	|��d}t�}t|d�D]}|�	d|d
@�|dL}q�|�	dd�|S)z/Convert a python number to a number field.
    rr-rz%0*or?r(zoverflow in number field�L�l�r))
r0r2�
GNU_FORMATrD�struct�unpack�pack�	bytearrayrF�insert)rH�digits�formatr3rIr7r7r8�itn�s	 
rVc	Cshdtt�d|dd��t�d|dd���}dtt�d|dd��t�d	|dd���}||fS)
a�Calculate the checksum for a member's header by summing up all
       characters except for the chksum field which is treated as if
       it was filled with spaces. According to the GNU tar sources,
       some tars (Sun and NeXT) calculate chksum with signed char,
       which will be different if there are chars in the buffer with
       the high bit set. So we calculate two checksums, unsigned and
       signed.
    r(Z148BN�Z356B�r	Z148bZ356b)�sumrOrP)�bufZunsigned_chksumZ
signed_chksumr7r7r8�calc_chksums�s	00r[cCs�|dkrdS|dur4|�d�}|s$q0|�|�qdSd}t||�\}}t|�D],}|�|�}t|�|krptd��|�|�qN|dkr�|�|�}t|�|kr�td��|�|�dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    rNr&zend of file reached)�read�write�divmodrFr1�IOError)�src�dstr4rZ�BUFSIZE�blocks�	remainder�br7r7r8�copyfileobjs*



rfrL�-re�d�cr=�r�wr3�S�x�t�TcCsJg}tD]6}|D]"\}}||@|kr|�|�qq|�d�qd�|�S)zcConvert a file's mode to a string of the form
       -rwxrwxrwx.
       Used by TarFile.list()
    rg�)�filemode_table�append�join)�modeZperm�table�bit�charr7r7r8�filemode8s
rxc@seZdZdZdS)rzBase exception.N��__name__�
__module__�__qualname__�__doc__r7r7r7r8rGsrc@seZdZdZdS)�ExtractErrorz%General exception for extract errors.Nryr7r7r7r8r~Jsr~c@seZdZdZdS)�	ReadErrorz&Exception for unreadable tar archives.Nryr7r7r7r8rMsrc@seZdZdZdS)�CompressionErrorz.Exception for unavailable compression methods.Nryr7r7r7r8r�Psr�c@seZdZdZdS)�StreamErrorz=Exception for unsupported operations on stream-like TarFiles.Nryr7r7r7r8r�Ssr�c@seZdZdZdS)�HeaderErrorz!Base exception for header errors.Nryr7r7r7r8r�Vsr�c@seZdZdZdS)�EmptyHeaderErrorzException for empty headers.Nryr7r7r7r8r�Ysr�c@seZdZdZdS)�TruncatedHeaderErrorz Exception for truncated headers.Nryr7r7r7r8r�\sr�c@seZdZdZdS)�EOFHeaderErrorz"Exception for end of file headers.Nryr7r7r7r8r�_sr�c@seZdZdZdS)rEzException for invalid headers.Nryr7r7r7r8rEbsrEc@seZdZdZdS)�SubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nryr7r7r7r8r�esr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
_LowLevelFilez�Low-level file object. Supports reading and writing.
       It is used instead of a regular file object for streaming
       access.
    cCsFtjtjtjBtjBd�|}ttd�r2|tjO}t�||d�|_dS)N)rjrk�O_BINARYi�)	�os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr��open�fd)�self�namertr7r7r8�__init__rs��

z_LowLevelFile.__init__cCst�|j�dS�N)r��closer��r�r7r7r8r�{sz_LowLevelFile.closecCst�|j|�Sr�)r�r\r��r�rr7r7r8r\~sz_LowLevelFile.readcCst�|j|�dSr�)r�r]r��r�r3r7r7r8r]�sz_LowLevelFile.writeN)rzr{r|r}r�r�r\r]r7r7r7r8r�ls
	r�c@steZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�Zddd�Z
dd�Zdd�ZdS)�_Streama�Class that serves as an adapter between TarFile and
       a stream-like object.  The stream-like object only
       needs to have a read() or write() method and is accessed
       blockwise.  Use of gzip or bzip2 compression is possible.
       A stream-like object could be for example: sys.stdin,
       sys.stdout, a socket, a tape device etc.

       _Stream is intended to be used only internally.
    cCsNd|_|durt||�}d|_|dkr6t|�}|��}|p<d|_||_||_||_||_d|_	d|_
d|_z�|dkr�zddl}Wnt
y�td	��Yn0||_|�d�|_|d
kr�|��n|��|dk�r zddl}Wnt
y�td��Yn0|d
k�rd|_|��|_n
|��|_Wn&|j�s<|j��d|_�Yn0dS)
z$Construct a _Stream object.
        TNF�*rp�r�gzzzlib module is not availablerj�bz2�bz2 module is not available)�_extfileobjr��_StreamProxy�getcomptyper�rt�comptype�fileobj�bufsizerZ�pos�closed�zlib�ImportErrorr��crc32�crc�
_init_read_gz�_init_write_gzr��dbuf�BZ2Decompressor�cmp�
BZ2Compressorr�)r�r�rtr�r�r�r�r�r7r7r8r��sP





z_Stream.__init__cCst|d�r|js|��dS)Nr�)r�r�r�r�r7r7r8�__del__�sz_Stream.__del__cCs�|j�d|jj|jj|jjd�|_t�dtt	�	���}|�
d|d�|j�d�rf|jdd�|_|�
|j�
d	d
�t�dS)z6Initialize for writing with gzip compression.
        �	r�<Ls�s�z.gzN���z
iso-8859-1�replace)r��compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVELr�rOrQrC�time�_Stream__writer��endswithr0r2)r�Z	timestampr7r7r8r��s�z_Stream._init_write_gzcCsR|jdkr|j�||j�|_|jt|�7_|jdkrD|j�|�}|�|�dS)z&Write string s to the stream.
        r��tarN)	r�r�r�r�r�r1r��compressr�r�r7r7r8r]�s

z
_Stream.writecCsN|j|7_t|j�|jkrJ|j�|jd|j��|j|jd�|_qdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rZr1r�r�r]r�r7r7r8Z__write�sz_Stream.__writecCs�|jr
dS|jdkr2|jdkr2|j|j��7_|jdkr�|jr�|j�|j�d|_|jdkr�|j�t�	d|j
d@��|j�t�	d|jd@��|js�|j�
�d|_dS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        Nrkr�r�r�r�l��T)r�rtr�rZr��flushr�r]rOrQr�r�r�r�r�r7r7r8r��s

z
_Stream.closecCs�|j�|jj�|_d|_|�d�dkr0td��|�d�dkrFtd��t|�d��}|�d�|d	@r�t|�d��d
t|�d��}|�	|�|d@r�|�d�}|r�|t
kr�q�q�|d@r�|�d�}|r�|t
kr�q�q�|d@r�|�d�d
S)z:Initialize for reading a gzip compressed fileobj.
        r�rs��not a gzip filer�zunsupported compression method�r.r(r-r,N)r��
decompressobjr�r�r��
_Stream__readrr�rGr\r2)r��flagZxlenr3r7r7r8r�s*
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        �r�r�r7r7r8�tell#sz_Stream.tellrcCsX||jdkrJt||j|j�\}}t|�D]}|�|j�q,|�|�ntd��|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)r�r^r�rFr\r�)r�r�rcrdrIr7r7r8�seek(sz_Stream.seekNcCsV|dur6g}|�|j�}|sq*|�|�qd�|�}n
|�|�}|jt|�7_|S)z�Return the next size number of bytes from the stream.
           If size is not defined, return all bytes of the stream
           up to EOF.
        Nrp)�_readr�rrrsr�r1)r�rrnrZr7r7r8r\5s
z_Stream.readcCs�|jdkr|�|�St|j�}||kr�|�|j�}|s8q�z|j�|�}Wntybtd��Yn0|j|7_|t|�7}q|jd|�}|j|d�|_|S)z+Return size bytes from the stream.
        r�zinvalid compressed dataN)	r�r�r1r�r�r��
decompressr_r�r�rrirZr7r7r8r�Gs 


z
_Stream._readcCsdt|j�}||krB|j�|j�}|s&qB|j|7_|t|�7}q
|jd|�}|j|d�|_|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        N)r1rZr�r\r�r�r7r7r8Z__read\s
z_Stream.__read)r)N)rzr{r|r}r�r�r�r]r�r�r�r�r�r\r�r�r7r7r7r8r��s
4
	

r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r�zsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs||_|j�t�|_dSr�)r�r\�	BLOCKSIZErZ)r�r�r7r7r8r�qsz_StreamProxy.__init__cCs|jj|_|jSr�)r�r\rZr�r7r7r8r\us
z_StreamProxy.readcCs$|j�d�rdS|j�d�r dSdS)Ns�r�sBZh91r�r�)rZ�
startswithr�r7r7r8r�ys
z_StreamProxy.getcomptypecCs|j��dSr�)r�r�r�r7r7r8r��sz_StreamProxy.closeN)rzr{r|r}r�r\r�r�r7r7r7r8r�ls
r�c@sLeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�ZdS)�	_BZ2ProxyaSmall proxy class that enables external file object
       support for "r:bz2" and "w:bz2" modes. This is actually
       a workaround for a limitation in bz2 module's BZ2File
       class which (unlike gzip.GzipFile) has no support for
       a file object argument.
    r&cCs(||_||_t|jdd�|_|��dS)Nr�)r�rt�getattrr��init)r�r�rtr7r7r8r��sz_BZ2Proxy.__init__cCsDddl}d|_|jdkr6|��|_|j�d�d|_n
|��|_dS)Nrrjr�)	r�r�rtr��bz2objr�r�rZr�)r�r�r7r7r8r��s

z_BZ2Proxy.initcCs�t|j�}||krN|j�|j�}|s&qN|j�|�}|j|7_|t|�7}q
|jd|�}|j|d�|_|jt|�7_|Sr�)r1rZr�r\�	blocksizer�r�r�)r�rrm�raw�datarZr7r7r8r\�s
z_BZ2Proxy.readcCs&||jkr|��|�||j�dSr�)r�r�r\)r�r�r7r7r8r��s
z_BZ2Proxy.seekcCs|jSr�r�r�r7r7r8r��sz_BZ2Proxy.tellcCs.|jt|�7_|j�|�}|j�|�dSr�)r�r1r�r�r�r])r�r�r�r7r7r8r]�sz_BZ2Proxy.writecCs$|jdkr |j��}|j�|�dS)Nrk)rtr�r�r�r])r�r�r7r7r8r��s

z_BZ2Proxy.closeN)rzr{r|r}r�r�r�r\r�r�r]r�r7r7r7r8r��s
r�c@s<eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zddd�ZdS)�_FileInFilezA thin wrapper around an existing file object that
       provides a part of its data as an individual file
       object.
    NcCs�||_||_||_d|_|dur*d|fg}d|_g|_d}|j}|D]L\}}||krh|j�d||df�|j�d||||f�||7}||}qD||jkr�|j�d||jdf�dS)NrFT)r��offsetr�position�	map_index�maprr)r�r�r�rZ	blockinfoZlastposZrealposr7r7r8r��s$


z_FileInFile.__init__cCst|jd�sdS|j��S)N�seekableT)r�r�r�r�r7r7r8r��sz_FileInFile.seekablecCs|jS)�*Return the current file position.
        �r�r�r7r7r8r��sz_FileInFile.tellcCs
||_dS)�(Seek to a position in the file.
        Nr�)r�r�r7r7r8r��sz_FileInFile.seekcCs�|dur|j|j}nt||j|j�}d}|dkr�|j|j\}}}}||jkr^|krfq�nq�q4|jd7_|jt|j�kr4d|_q4t|||j�}|r�|j�||j|�||j�|�7}n|t	|7}||8}|j|7_q,|S)z!Read data from the file.
        Nr�rr)
rr��minr�r�r1r�r�r\r2)r�rrZr��start�stopr�r4r7r7r8r\�s&z_FileInFile.read)N)N)	rzr{r|r}r�r�r�r�r\r7r7r7r8r��s
r�c@szeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zddd
�Z	e	Z
ddd�Zdd�Zdd�Z
ejfdd�Zdd�Zdd�ZdS)�ExFileObjectzaFile-like object for reading an archive member.
       Is returned by TarFile.extractfile().
    r'cCsDt|j|j|j|j�|_|j|_d|_d|_|j|_d|_d|_	dS)NrjFrr�)
r�r��offset_datar�sparser�rtr�r��buffer)r��tarfile�tarinfor7r7r8r�s�zExFileObject.__init__cCsdS�NTr7r�r7r7r8�readable!szExFileObject.readablecCsdS)NFr7r�r7r7r8�writable$szExFileObject.writablecCs
|j��Sr�)r�r�r�r7r7r8r�'szExFileObject.seekableNcCs�|jrtd��d}|jrL|dur.|j}d|_n|jd|�}|j|d�|_|durd||j��7}n||j�|t|��7}|jt|�7_|S)z~Read at most size bytes from the file. If size is not
           present or None, read all data until EOF is reached.
        �I/O operation on closed filer�N)r�rDr�r�r\r1r�)r�rrZr7r7r8r\*szExFileObject.readr:cCs�|jrtd��|j�d�d}|dkrt|j�|j�}|j|7_|rNd|vr&|j�d�d}|dkrtt|j�}qtq&|dkr�t||�}|jd|�}|j|d�|_|j	t|�7_	|S)z�Read one entire line from the file. If size is present
           and non-negative, return a string with at most that
           size, which may be an incomplete line.
        r��
rrr:N)
r�rDr�r;r�r\r�r1r�r�)r�rr�rZr7r7r8�readlineEs"

zExFileObject.readlinecCs"g}|��}|sq|�|�q|S)z0Return a list with all remaining lines.
        )r�rr)r��result�liner7r7r8�	readlinesbs
zExFileObject.readlinescCs|jrtd��|jS)r�r�)r�rDr�r�r7r7r8r�lszExFileObject.tellcCs�|jrtd��|tjkr.tt|d�|j�|_nj|tjkrj|dkrTt|j|d�|_q�t|j||j�|_n.|tj	kr�tt|j||j�d�|_ntd��d|_
|j�|j�dS)r�r�rzInvalid argumentr�N)
r�rDr��SEEK_SETr��maxrr��SEEK_CUR�SEEK_ENDr�r�r�)r�r��whencer7r7r8r�ts


zExFileObject.seekcCs
d|_dS)zClose the file object.
        TN)r�r�r7r7r8r��szExFileObject.closeccs|��}|sq|VqdS)z/Get an iterator over the file's lines.
        N)r�)r�r�r7r7r8�__iter__�szExFileObject.__iter__)N)r:)rzr{r|r}r�r�r�r�r�r\�read1r�r�r�r�r�r�r�r�r7r7r7r8r�s



r�c@s�eZdZdZdZdVdd�Zdd�Zdd	�Zeee�Z	d
d�Z
dd
�Zee
e�Zdd�Z
dd�Zeedfdd�Zdd�Zdd�Zdd�Zedd��Zdd�Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zd+d,�Zd-d.�Z d/d0�Z!d1d2�Z"d3d4�Z#d5d6�Z$d7d8�Z%d9d:�Z&d;d<�Z'd=d>�Z(d?d@�Z)dAdB�Z*dCdD�Z+dEdF�Z,dGdH�Z-dIdJ�Z.dKdL�Z/dMdN�Z0dOdP�Z1dQdR�Z2dSdT�Z3dUS)WraInformational class which holds the details about an
       archive member given by a tar header block.
       TarInfo objects are returned by TarFile.getmember(),
       TarFile.getmembers() and TarFile.gettarinfo() and are
       usually created internally.
    )r�rtr!r"rr �chksum�type�linknamer#r$�devmajor�devminorr�r��pax_headersr�r��_sparse_structs�_link_targetrpcCsj||_d|_d|_d|_d|_d|_d|_t|_d|_	d|_
d|_d|_d|_
d|_d|_d|_i|_dS)zXConstruct a TarInfo object. name is the optional name
           of the member.
        i�rrpN)r�rtr!r"rr r��REGTYPEr�r�r#r$r�r�r�r�r�r��r�r�r7r7r8r��s"zTarInfo.__init__cCs|jSr��r�r�r7r7r8�_getpath�szTarInfo._getpathcCs
||_dSr�rrr7r7r8�_setpath�szTarInfo._setpathcCs|jSr��r�r�r7r7r8�_getlinkpath�szTarInfo._getlinkpathcCs
||_dSr�r)r�r�r7r7r8�_setlinkpath�szTarInfo._setlinkpathcCsd|jj|jt|�fS)Nz<%s %r at %#x>)�	__class__rzr��idr�r7r7r8�__repr__�szTarInfo.__repr__cCsl|j|jd@|j|j|j|j|j|j|j|j	|j
|j|jd�
}|dt
krh|d�d�sh|dd7<|S)z9Return the TarInfo's attributes as a dictionary.
        �)
r�rtr!r"rr r�r�r�r#r$r�r�r�r��/)r�rtr!r"rr r�r�r�r#r$r�r��DIRTYPEr�)r��infor7r7r8�get_info�s"�zTarInfo.get_info�surrogateescapecCsT|��}|tkr|�|||�S|tkr4|�|||�S|tkrH|�||�Std��dS)z<Return a tar header as a string of 512 byte blocks.
        zinvalid formatN)r�USTAR_FORMAT�create_ustar_headerrN�create_gnu_header�
PAX_FORMAT�create_pax_headerrD)r�rUr5r6r
r7r7r8�tobuf�sz
TarInfo.tobufcCsZt|d<t|d�tkr td��t|d�tkrJ|�|d�\|d<|d<|�|t||�S)z3Return the object as a ustar header block.
        �magicr�zlinkname is too longr��prefix)�POSIX_MAGICr1�LENGTH_LINKrD�LENGTH_NAME�_posix_split_name�_create_headerr)r�r
r5r6r7r7r8r�szTarInfo.create_ustar_headercCspt|d<d}t|d�tkr4||�|dt||�7}t|d�tkr\||�|dt||�7}||�|t||�S)z:Return the object as a GNU header block sequence.
        rr�r�r�)	�	GNU_MAGICr1r�_create_gnu_long_header�GNUTYPE_LONGLINKr�GNUTYPE_LONGNAMErrN)r�r
r5r6rZr7r7r8rszTarInfo.create_gnu_headerc
	Cs(t|d<|j��}ddtfddtfddfD]h\}}}||vr>q*z||�dd	�Wn"tyt||||<Yq*Yn0t||�|kr*||||<q*d
D]`\}}||vr�d||<q�||}d|kr�d|d
kr�nn
t|t	�r�t
|�||<d||<q�|�r|�|t|�}	nd}	|	|�
|tdd�S)z�Return the object as a ustar header block. If it cannot be
           represented this way, prepend a pax extended header sequence
           with supplement information.
        rr�rr�r)r#r#r+)r$r$r+r?r@))r!r-)r"r-)r�)r r!rr-rr�r�)rr��copyrrr0�UnicodeEncodeErrorr1�
isinstance�float�str�_create_pax_generic_header�XHDTYPErr)
r�r
r5r�r�Zhnamer4rT�valrZr7r7r8rs4
�
*
zTarInfo.create_pax_headercCs|�|td�S)zAReturn the object as a pax global header block sequence.
        �utf8)r'�XGLTYPE)�clsr�r7r7r8�create_pax_global_headerDsz TarInfo.create_pax_global_headercCsj|dtd�}|r.|ddkr.|dd�}q|t|�d�}|dd�}|rZt|�tkrbtd��||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        Nrr:rzname is too long)�
LENGTH_PREFIXr1rrD)r�r�rr7r7r8rJszTarInfo._posix_split_namecCsVt|�dd�d||�t|�dd�d@d|�t|�dd�d|�t|�d	d�d|�t|�d
d�d|�t|�dd�d|�d
|�dt�t|�dd�d||�|�dt�t|�dd�d||�t|�dd�d||�t|�dd�d|�t|�dd�d|�t|�dd�d||�g}t�dtd�|��}t	|td��d}|dd�d|�
d�|dd�}|S)z�Return a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        r�rprrtrr
r-r!r"rr!r s        r�r�rr#r+r$r�r�rrz%dsr�Ni����z%06or?i����)r9�getrVr�rrOrQr�rsr[r0)r
rUr5r6�partsrZr�r7r7r8rYs(

�&zTarInfo._create_headercCs.tt|�t�\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes
           up to the next 512 byte border.
        r)r^r1r�r2)Zpayloadrcrdr7r7r8�_create_payloaduszTarInfo._create_payloadcCsR|�||�t}i}d|d<||d<t|�|d<t|d<|�|t||�|�|�S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
           for name.
        z
././@LongLinkr�r�rr)r0r2r1rrrr1)r,r�r�r5r6r
r7r7r8rs�zTarInfo._create_gnu_long_headerc	Cs0d}|��D]6\}}z|�dd�Wqty@d}YqDYq0qd}|rT|d7}|��D]�\}}|�d�}|r�|�|d�}n
|�d�}t|�t|�d}d	}	}
|tt|
��}	|	|
kr�q�|	}
q�|tt|
�d
�d|d|d
7}q\i}d|d<||d<t|�|d<t|d<|�|td
d�|�	|�S)z�Return a POSIX.1-2008 extended or global header sequence
           that contains a list of keyword, value pairs. The values
           must be strings.
        Fr*r@Tr�s21 hdrcharset=BINARY
rrrr?� �=r�z././@PaxHeaderr�r�rrr�)
�itemsr0r#r1r&�bytesrrrr1)r,r�r�r5Zbinary�keyword�valueZrecordsrLrHr=r
r7r7r8r'�s<

(�z"TarInfo._create_pax_generic_headerc	Cstt|�dkrtd��t|�tkr(td��|�t�tkr>td��t|dd��}|t|�vrbt	d��|�}t
|dd�||�|_t|dd	��|_t|d	d
��|_
t|d
d��|_t|dd��|_t|dd��|_||_|dd
�|_t
|d
d�||�|_t
|dd�||�|_t
|dd�||�|_t|dd��|_t|dd��|_t
|dd�||�}|jtk�r�|j�d��r�t|_|jtk�r6d}g}td�D]j}	z0t|||d��}
t||d|d��}Wnt�y�Y�qYn0|�|
|f�|d7}�q�t|d�}t|dd��}
|||
f|_ |�!��rN|j�"d�|_|�rp|jt#v�rp|d|j|_|S)zAConstruct a TarInfo object from a 512 byte bytes object.
        rzempty headerztruncated headerzend of file headerrWrXzbad checksumr�l�t�|��ii	i)iIiQiYi�ri�r.r!�i�i�i�)$r1r�r�r��countr2r�rJr[rEr>r�rtr!r"rr r�r�r�r#r$r�r��AREGTYPEr�r�GNUTYPE_SPARSErFrDrr�boolr��isdir�rstrip�	GNU_TYPES)r,rZr5r6r��objrr��structsrIr��numbytes�
isextended�origsizer7r7r8�frombuf�sZ
zTarInfo.frombufcCs8|j�t�}|�||j|j�}|j��t|_|�|�S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	r�r\r�rJr5r6r�r��_proc_member)r,r�rZrEr7r7r8�fromtarfileszTarInfo.fromtarfilecCsT|jttfvr|�|�S|jtkr,|�|�S|jtttfvrF|�	|�S|�
|�SdS)zYChoose the right processing method depending on
           the type and call it.
        N)r�r r�
_proc_gnulongr@�_proc_sparser(r+�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin�r�r�r7r7r8rKs



zTarInfo._proc_membercCsR|j��|_|j}|��s$|jtvr4||�|j�7}||_|�	|j
|j|j�|S)zfProcess a builtin type or an unknown type which
           will be treated as a regular file.
        )
r�r�r��isregr��SUPPORTED_TYPES�_blockrr��_apply_pax_infor�r5r6)r�r�r�r7r7r8rQ$szTarInfo._proc_builtincCs�|j�|�|j��}z|�|�}Wnty<td��Yn0|j|_|jt	krdt
||j|j�|_
n|jtkr�t
||j|j�|_|S)zSProcess the blocks that hold a GNU longname
           or longlink member.
        � missing or bad subsequent header)r�r\rUrrLr�r�r�r�r r>r5r6r�rr�)r�r�rZ�nextr7r7r8rM5s

zTarInfo._proc_gnulongc
	Cs�|j\}}}|`|r�|j�t�}d}td�D]l}z0t|||d��}t||d|d��}	WntyxYq�Yn0|r�|	r�|�||	f�|d7}q,t|d�}q||_	|j�
�|_|j|�|j
�|_||_
|S)z8Process a GNU sparse header plus extra headers.
        r�r!r=i�)r�r�r\r�rFrJrDrrrAr�r�r�rUrr�)
r�r�rFrHrIrZr�rIr�rGr7r7r8rNKs(
zTarInfo._proc_sparsecCs|j�|�|j��}|jtkr&|j}n
|j��}t�	d|�}|durX|�
d��d�|d<|�d�}|dkrr|j
}nd}t�d�}d}|�||�}|s��q&|��\}	}
t|	�}	||�d	�d|�d�|	d�}|�|
dd|j�}
|
tv�r|�|||j
|j�}n|�|dd|j�}|||
<||	7}q�z|�|�}Wnt�yPtd
��Yn0d|v�rj|�||�nHd|v�r�|�|||�n.|�d
�dk�r�|�d�dk�r�|�|||�|jttfv�r|�||j
|j�|j |_ d|v�r|j!}
|�"��s|jt#v�r|
|�|j�7}
|
|_ |S)zVProcess an extended or global header as described in
           POSIX.1-2008.
        s\d+ hdrcharset=([^\n]+)\nNrr*�
hdrcharsetZBINARYs(\d+) ([^=]+)=rrrW�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrAr)$r�r\rUrr�r+r�r"�re�search�groupr<r/r5�compile�match�groupsrC�endr��_decode_pax_fieldr6�PAX_NAME_FIELDSrLr�r��_proc_gnusparse_01�_proc_gnusparse_00�_proc_gnusparse_10r(rOrVr�r�rSrT)r�r�rZr�rbrZr5Zregexr�r4r6r7rXr�r7r7r8rPgsd



$	
�
�
�


 
zTarInfo._proc_paxcCshg}t�d|�D]}|�t|�d���qg}t�d|�D]}|�t|�d���q:tt||��|_dS)z?Process a GNU tar extended sparse header, version 0.0.
        s\d+ GNU.sparse.offset=(\d+)\nrs\d+ GNU.sparse.numbytes=(\d+)\nN)r^�finditerrrrCr`�list�zipr�)r�rXr�rZZoffsetsrbrGr7r7r8rh�szTarInfo._proc_gnusparse_00cCs@dd�|d�d�D�}tt|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|��qSr7)rC)�.0rmr7r7r8�
<listcomp>�r�z.TarInfo._proc_gnusparse_01.<locals>.<listcomp>r[�,Nrr)�splitrkrlr�)r�rXr�r�r7r7r8rg�szTarInfo._proc_gnusparse_01cCs�d}g}|j�t�}|�dd�\}}t|�}t|�|dkrtd|vrT||j�t�7}|�dd�\}}|�t|��q,|j��|_t	t
|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        Nr�rr)r�r\r�rprCr1rrr�r�rkrlr�)r�rXr�r��fieldsr�rZZnumberr7r7r8ri�szTarInfo._proc_gnusparse_10c	Cs�|��D]�\}}|dkr&t|d|�q|dkr@t|dt|��q|dkrZt|dt|��q|tvr|tvr�zt||�}Wnty�d}Yn0|dkr�|�d�}t|||�q|��|_dS)	zoReplace fields with supplemental information from a previous
           pax extended or global header.
        zGNU.sparse.namerr\rzGNU.sparse.realsizerrN)	r4�setattrrC�
PAX_FIELDS�PAX_NUMBER_FIELDSrDrCr"r�)r�r�r5r6r6r7r7r7r8rV�s"

zTarInfo._apply_pax_infocCs2z|�|d�WSty,|�||�YS0dS)z1Decode a single field from a pax record.
        r@N)r<�UnicodeDecodeError)r�r7r5Zfallback_encodingZfallback_errorsr7r7r8reszTarInfo._decode_pax_fieldcCs"t|t�\}}|r|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it,
           e.g. _block(834) => 1024.
        r)r^r�)r�r>rcrdr7r7r8rU
szTarInfo._blockcCs
|jtvSr�)r��
REGULAR_TYPESr�r7r7r8rSsz
TarInfo.isregcCs|��Sr�)rSr�r7r7r8�isfileszTarInfo.isfilecCs
|jtkSr�)r�rr�r7r7r8rBsz
TarInfo.isdircCs
|jtkSr�)r��SYMTYPEr�r7r7r8�issymsz
TarInfo.issymcCs
|jtkSr�)r��LNKTYPEr�r7r7r8�islnksz
TarInfo.islnkcCs
|jtkSr�)r��CHRTYPEr�r7r7r8�ischr sz
TarInfo.ischrcCs
|jtkSr�)r��BLKTYPEr�r7r7r8�isblk"sz
TarInfo.isblkcCs
|jtkSr�)r��FIFOTYPEr�r7r7r8�isfifo$szTarInfo.isfifocCs
|jduSr�)r�r�r7r7r8�issparse&szTarInfo.issparsecCs|jtttfvSr�)r�r|r~r�r�r7r7r8�isdev(sz
TarInfo.isdevN)rp)4rzr{r|r}�	__slots__r�rr�propertyrrrrr	r�DEFAULT_FORMAT�ENCODINGrrrr�classmethodr-r�staticmethodrr1rr'rJrLrKrQrMrNrPrhrgrirVrerUrSrwrBryr{r}rr�r�r�r7r7r7r8r�sf



1


	

2
>

f	rc@s�eZdZdZdZdZdZdZeZ	e
ZdZe
ZeZdVdd	�Zedddefd
d��ZedWdd
��ZedXdd��ZedYdd��Zdddd�Zdd�Zdd�Zdd�Zdd�ZdZdd �Zd[d"d#�Zd\d$d%�Zd]d&d'�Z d^d)d*�Z!d_d,d-�Z"d.d/�Z#d`d0d1�Z$d2d3�Z%d4d5�Z&d6d7�Z'd8d9�Z(d:d;�Z)d<d=�Z*d>d?�Z+d@dA�Z,dBdC�Z-dDdE�Z.dadFdG�Z/dHdI�Z0dbdJdK�Z1dLdM�Z2dNdO�Z3dPdQ�Z4dRdS�Z5dTdU�Z6dS)crz=The TarFile Class provides an interface to tar archives.
    rFrNrjrc

Cs�t|�dks|dvrtd��||_dddd�||_|sn|jdkrZtj�|�sZd	|_d|_t||j�}d
|_n0|dur�t	|d�r�|j
}t	|d
�r�|j|_d|_|r�tj�|�nd|_
||_|dur�||_
|dur�||_|dur�||_|dur�||_|du�r||_|	|_|
du�r&|j
tk�r&|
|_ni|_|du�r<||_|du�rL||_d
|_g|_d
|_|j��|_i|_z�|jdk�r�d|_|��|_|jdk�r"|j�|j�z|j� |�}|j�!|�WnXt"�y�|j�|j�Y�q"Yn2t#�y}
zt$t%|
���WYd}
~
n
d}
~
00�q�|jdv�rld|_|j�rl|j�&|j�'��}|j�(|�|jt|�7_Wn&|j�s�|j�)�d|_�Yn0dS)a�Open an (uncompressed) tar archive `name'. `mode' is either 'r' to
           read from an existing archive, 'a' to append data to an existing
           file or 'w' to create a new file overwriting an existing one. `mode'
           defaults to 'r'.
           If `fileobj' is given, it is used for reading or writing data. If it
           can be determined, `mode' is overridden by `fileobj's mode.
           `fileobj' is not closed, when TarFile is closed.
        rr��mode must be 'r', 'a' or 'w'�rbzr+b�wb)rj�arkr�rkFNr�rtTrj�aw)*r1rDrt�_moder�r�exists�	bltn_openr�r�r��abspathr�rUr��dereference�ignore_zerosr5r6rr��debug�
errorlevelr��members�_loadedr�r��inodes�firstmemberrXr�rLrrr�r�rr&r-r"r]r�)r�r�rtr�rUr�r�r�r5r6r�r�r��erZr7r7r8r�Fs�





&
zTarFile.__init__c
Ks�|s|std��|dvr�|jD]�}t||j|�}|durB|��}z||d|fi|��WSttfy�}	z*|dur�|�|�WYd}	~	qWYd}	~	qd}	~	00qtd���nd|v�r|�dd�\}
}|
p�d}
|p�d}||jvr�t||j|�}ntd	|��|||
|fi|��Sd
|v�r�|�d
d�\}
}|
�p:d}
|�pDd}|
dv�rXtd��t||
|||�}z|||
|fi|��}Wn|�	��Yn0d
|_
|S|dv�r�|j|||fi|��Std��dS)a|Open a tar archive for reading, writing or appending. Return
           an appropriate TarFile class.

           mode:
           'r' or 'r:*' open for reading with transparent compression
           'r:'         open for reading exclusively uncompressed
           'r:gz'       open for reading with gzip compression
           'r:bz2'      open for reading with bzip2 compression
           'a' or 'a:'  open for appending, creating the file if necessary
           'w' or 'w:'  open for writing without compression
           'w:gz'       open for writing with gzip compression
           'w:bz2'      open for writing with bzip2 compression

           'r|*'        open a stream of tar blocks with transparent compression
           'r|'         open an uncompressed stream of tar blocks for reading
           'r|gz'       open a gzip compressed stream of tar blocks
           'r|bz2'      open a bzip2 compressed stream of tar blocks
           'w|'         open an uncompressed stream for writing
           'w|gz'       open a gzip compressed stream for writing
           'w|bz2'      open a bzip2 compressed stream for writing
        znothing to open)rjzr:*Nrjz%file could not be opened successfully�:rr�zunknown compression type %r�|�rw�mode must be 'r' or 'w'Fr�zundiscernible mode)rD�	OPEN_METHr�r�rr�r�rpr�r�r��taropen)
r,r�rtr�r��kwargsr��funcZ	saved_posr�rx�streamrnr7r7r8r��sN

$






zTarFile.opencKs0t|�dks|dvrtd��||||fi|��S)zCOpen uncompressed tar archive name for reading or writing.
        rr�r�)r1rD)r,r�rtr�r�r7r7r8r��szTarFile.taropenr�c		Ks�t|�dks|dvrtd��zddl}|jWnttfyLtd��Yn0|du}z.|�||d||�}|j|||fi|��}WnXty�|s�|dur�|�	�|dur��t
d��Yn"|s�|dur�|�	��Yn0||_|S)	zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        rr�r�rNzgzip module is not availablerer�)r1rD�gzipZGzipFiler��AttributeErrorr�r�r_r�rr�)	r,r�rtr��
compresslevelr�r�Z
extfileobjrnr7r7r8�gzopens.
zTarFile.gzopenc	Ks�t|�dks|dvrtd��zddl}WntyBtd��Yn0|durXt||�}n|j|||d�}z|j|||fi|��}Wn&tt	fy�|�
�td��Yn0d	|_|S)
zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        rr�zmode must be 'r' or 'w'.rNr�)r�znot a bzip2 fileF)
r1rDr�r�r�r��BZ2Filer�r_�EOFErrorr�rr�)r,r�rtr�r�r�r�rnr7r7r8�bz2open$s zTarFile.bz2openr�r�r�)r�r�r�cCs�|jr
dS|jdvrf|j�ttd�|jtd7_t|jt�\}}|dkrf|j�tt|�|j	sv|j�
�d|_dS)zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        Nr�rrT)r�rtr�r]r2r�r�r^�
RECORDSIZEr�r�)r�rcrdr7r7r8r�Hs

z
TarFile.closecCs"|�|�}|durtd|��|S)aReturn a TarInfo object for member `name'. If `name' can not be
           found in the archive, KeyError is raised. If a member occurs more
           than once in the archive, its last occurrence is assumed to be the
           most up-to-date version.
        Nzfilename %r not found)�
_getmember�KeyError)r�r�r�r7r7r8�	getmember\s
zTarFile.getmembercCs|��|js|��|jS)z�Return the members of the archive as a list of TarInfo objects. The
           list has the same order as the members in the archive.
        )�_checkr��_loadr�r�r7r7r8�
getmembersgszTarFile.getmemberscCsdd�|��D�S)z�Return the members of the archive as a list of their names. It has
           the same order as the list returned by getmembers().
        cSsg|]
}|j�qSr7r)rmr�r7r7r8rnur�z$TarFile.getnames.<locals>.<listcomp>)r�r�r7r7r8�getnamesqszTarFile.getnamescCsh|�d�|dur|j}|dur$|}tj�|�\}}|�tjd�}|�d�}|��}||_	|dur�t
td�r~|js~t�|�}q�t�
|�}nt�|���}d}|j}t
�|��r|j|jf}	|js�|jdkr�|	|jvr�||j|	kr�t}
|j|	}nt}
|	d�rt||j|	<nht
�|��rt}
nVt
�|��r0t}
nDt
�|��rLt}
t�|�}n(t
�|��r^t }
nt
�!|��rpt"}
ndS||_||_#|j$|_%|j&|_'|
tk�r�|j(|_)nd|_)|j*|_+|
|_,||_-t.�r�zt.�/|j%�d|_0Wnt1�y�Yn0t2�r"zt2�3|j'�d|_4Wnt1�y Yn0|
t t"fv�rdt
td��rdt
td	��rdt�5|j6�|_7t�8|j6�|_9|S)
aOCreate a TarInfo object for either the file `name' or the file
           object `fileobj' (using os.fstat on its file descriptor). You can
           modify some of the TarInfo's attributes before you add it using
           addfile(). If given, `arcname' specifies an alternative name for the
           file in the archive.
        r�Nr�lstatrprr�major�minor):r�r�r�r�
splitdriver��sep�lstripr�r�r�r�r��stat�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�rzr��S_ISDIRr�S_ISFIFOr��S_ISLNKrx�readlink�S_ISCHRr|�S_ISBLKr~rt�st_uidr!�st_gidr"�st_sizer�st_mtimer r�r��pwd�getpwuidr#r��grp�getgrgidr$r��st_rdevr�r�r�)r�r��arcnamer��drvr�Zstatresr�Zstmd�inoder�r7r7r8�
gettarinfows�

��


zTarFile.gettarinfoTcCs|��|D]�}|r�tt|j�dd�td|jp4|j|jp>|jfdd�|��sZ|�	�rxtdd|j
|jfdd�ntd|jdd�tdt
�|j�dd	�dd�t|j|��r�d
nddd�|r�|��r�td|jdd�|��r�td
|jdd�t�qdS)z�Print a table of contents to sys.stdout. If `verbose' is False, only
           the names of the members are printed. If it is True, an `ls -l'-like
           output is produced.
        � )rdz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dNr�rrpz->zlink to)r��printrxrtr#r!r$r"r}rr�r�rr��	localtimer r�rBryr�r{)r��verboser�r7r7r8rk�s8
��
����zTarFile.listc	Csn|�d�|dur|}|durPddl}|�dtd�||�rP|�dd|�dS|jdur�tj�|�|jkr�|�dd|�dS|�d|�|�	||�}|dur�|�dd	|�dS|dur�||�}|dur�|�dd|�dS|�
��r
t|d
�}|�||�|�
�n`|���r`|�|�|�rjt�|�D].}|jtj�||�tj�||�|||d��q.n
|�|�dS)a~Add the file `name' to the archive. `name' may be any type of file
           (directory, fifo, symbolic link, etc.). If given, `arcname'
           specifies an alternative name for the file in the archive.
           Directories are added recursively by default. This can be avoided by
           setting `recursive' to False. `exclude' is a function that should
           return True for each filename to be excluded. `filter' is a function
           that expects a TarInfo object argument and returns the changed
           TarInfo object, if it returns None the TarInfo object will be
           excluded from the archive.
        r�Nrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rr�)�filter)r��warnings�warn�DeprecationWarning�_dbgr�r�rr�r�rSr��addfiler�rB�listdir�addrs)	r�r�r��	recursiveZexcluder�r�r��fr7r7r8r��sH
�




�zTarFile.addcCs�|�d�t�|�}|�|j|j|j�}|j�|�|jt	|�7_|dur�t
||j|j�t|jt
�\}}|dkr�|j�tt
|�|d7}|j|t
7_|j�|�dS)a]Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
           given, tarinfo.size bytes are read from it and added to the archive.
           You can create TarInfo objects using gettarinfo().
           On Windows platforms, `fileobj' should always be opened with mode
           'rb' to avoid irritation about the file size.
        r�Nrr)r�r"rrUr5r6r�r]r�r1rfrr^r�r2r�rr)r�r�r�rZrcrdr7r7r8r�4s

zTarFile.addfile�.cCs�g}|dur|}|D]<}|��r:|�|�t�|�}d|_|j|||��d�q|jdd�d�|��|D]�}tj�	||j
�}z(|�||�|�||�|�
||�Wqnty�}z*|jdkrȂn|�dd|�WYd}~qnd}~00qndS)	aMExtract all members from the archive to the current working
           directory and set owner, modification time and permissions on
           directories afterwards. `path' specifies a different directory
           to extract to. `members' is optional and must be a subset of the
           list returned by getmembers().
        N���	set_attrscSs|jSr�r)r�r7r7r8�<lambda>dr�z$TarFile.extractall.<locals>.<lambda>)�keyr�tarfile: %s)rBrrr"rt�extract�sort�reverser�rrsr��chown�utime�chmodr~r�r�)r�rr�Zdirectoriesr��dirpathr�r7r7r8�
extractallNs*


zTarFile.extractallrpc
Cs|�d�t|t�r |�|�}n|}|��r>tj�||j�|_	z |j
|tj�||j�|d�Wn�ty�}zP|j
dkr|�n6|jdur�|�dd|j�n|�dd|j|jf�WYd}~nLd}~0t�y}z*|j
dkr�n|�dd|�WYd}~n
d}~00dS)axExtract a member from the archive to the current working directory,
           using its full name. Its file information is extracted as accurately
           as possible. `member' may be a filename or a TarInfo object. You can
           specify a different directory using `path'. File attributes (owner,
           mtime, mode) are set unless `set_attrs' is False.
        rjr�rNrr�ztarfile: %s %r)r�r$r&r�r{r�rrsr�r��_extract_memberr��EnvironmentErrorr��filenamer��strerrorr~)r��memberrr�r�r�r7r7r8r�ts(

�


,
zTarFile.extractcCs�|�d�t|t�r |�|�}n|}|��r8|�||�S|jtvrN|�||�S|��s^|�	�r�t|j
t�rttd��q�|�
|�|��SndSdS)a�Extract a member from the archive as a file object. `member' may be
           a filename or a TarInfo object. If `member' is a regular file, a
           file-like object is returned. If `member' is a link, a file-like
           object is constructed from the link's target. If `member' is none of
           the above, None is returned.
           The file-like object is read-only and provides the following
           methods: read(), readline(), readlines(), seek() and tell()
        rjz'cannot extract (sym)link as file objectN)r�r$r&r�rS�
fileobjectr�rTr{ryr�r�r��extractfile�_find_link_target)r�r�r�r7r7r8r��s	



zTarFile.extractfilecCsR|�d�}|�dtj�}tj�|�}|r>tj�|�s>t�|�|��sN|�	�rh|�
dd|j|jf�n|�
d|j�|�
�r�|�||�n�|��r�|�||�nx|��r�|�||�nb|��s�|��r�|�||�nD|��s�|�	�r�|�||�n&|jtv�r|�||�n|�||�|�rN|�||�|�	��sN|�||�|�||�dS)z\Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        rrz%s -> %sN)rCr�r�r�r�dirnamer��makedirsr{ryr�r�r�rS�makefilerB�makedirr��makefifor}r�makedev�makelinkr�rT�makeunknownr�r�r�)r�r��
targetpathr�Z	upperdirsr7r7r8r��s4


zTarFile._extract_memberc
CsHzt�|d�Wn2tyB}z|jtjkr.�WYd}~n
d}~00dS)z,Make a directory called targetpath.
        r�N)r��mkdirr��errnoZEEXIST�r�r�rr�r7r7r8r��s
zTarFile.makedircCs||j}|�|j�t|d�}|jdurN|jD]\}}|�|�t|||�q,nt|||j�|�|j�|��|��dS)z'Make a file called targetpath.
        r�N)	r�r�r�r�r�rfr�truncater�)r�r�r�source�targetr�rr7r7r8r��s


zTarFile.makefilecCs"|�||�|�dd|j�dS)zYMake a file from a TarInfo object with an unknown type
           at targetpath.
        rz9tarfile: Unknown file type %r, extracted as regular file.N)r�r�r��r�r�rr7r7r8r	s�zTarFile.makeunknowncCs"ttd�rt�|�ntd��dS)z'Make a fifo called targetpath.
        �mkfifozfifo not supported by systemN)r�r�r
r~r	r7r7r8r�	s
zTarFile.makefifocCs^ttd�rttd�std��|j}|��r6|tjO}n
|tjO}t�||t�	|j
|j��dS)z<Make a character or block device called targetpath.
        �mknodr�z'special devices not supported by systemN)r�r�r~rtrr��S_IFBLK�S_IFCHRrr�r�r�)r�r�rrtr7r7r8r�	s
�zTarFile.makedevcCs�zL|��rt�|j|�n0tj�|j�r8t�|j|�n|�|�	|�|�Wn<t
y�|��r~tj�tj�|j
�|j�}n|j}Yn40z|�|�	|�|�Wnty�td��Yn0dS)z�Make a (symbolic) link called targetpath. If it cannot be created
          (platform limitation), we try to make a copy of the referenced file
          instead of a link.
        z%unable to resolve link inside archiveN)ryr��symlinkr�rr�r��linkr�r��symlink_exceptionrsr�r�r�r~)r�r�rrr7r7r8r'	s(���zTarFile.makelinkc
Cs�tr�ttd�r�t��dkr�zt�|j�d}WntyF|j}Yn0zt�	|j
�d}Wntyt|j}Yn0z>|��r�ttd�r�t�
|||�ntjdkr�t�|||�Wn,ty�}ztd��WYd}~n
d}~00dS)z6Set owner of targetpath according to tarinfo.
        �geteuidrr�lchownZos2emxzcould not change ownerN)r�r�r�rr��getgrnamr$r�r"�getpwnamr#r!ryr�sys�platformr�r�r~)r�r�r�g�ur�r7r7r8r�D	s 
z
TarFile.chownc
CsNttd�rJzt�||j�Wn,tyH}ztd��WYd}~n
d}~00dS)zASet file permissions of targetpath according to tarinfo.
        r�zcould not change modeN)r�r�r�rtr�r~rr7r7r8r�Z	s

z
TarFile.chmodc
CsXttd�sdSzt�||j|jf�Wn,tyR}ztd��WYd}~n
d}~00dS)zBSet modification time of targetpath according to tarinfo.
        r�Nz"could not change modification time)r�r�r�r r�r~rr7r7r8r�c	s
z
TarFile.utimec
Cs�|�d�|jdur$|j}d|_|S|j�|j�d}z|j�|�}W�q�ty�}zD|jr�|�	dd|j|f�|jt
7_WYd}~q6WYd}~�q�d}~0t�y}z\|jr�|�	dd|j|f�|jt
7_WYd}~q6n|jdk�rtt
|���WYd}~n�d}~0t�y>|jdk�r:td��Ynnt�yz}z$|jdk�rftt
|���WYd}~n:d}~0t�y�}ztt
|���WYd}~n
d}~00�q�q6|du�r�|j�|�nd|_|S)z�Return the next member of the archive as a TarInfo object, when
           TarFile is opened for reading. Return None if there is no more
           available.
        ZraNrz0x%X: %srz
empty fileT)r�r�r�r�r�r�rLr�r�r�r�rErr&r�r�r�r�rrr�)r��mr�r�r7r7r8rXn	sD

"  "
zTarFile.nextcCsn|��}|dur"|d|�|��}|r2tj�|�}t|�D].}|rRtj�|j�}n|j}||kr:|Sq:dS)z}Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        N)r��indexr�r�normpath�reversedr�)r�r�r��	normalizer�r��member_namer7r7r8r��	szTarFile._getmembercCs|��}|durqqd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)rXr��r�r�r7r7r8r��	sz
TarFile._loadcCs:|jrtd|jj��|dur6|j|vr6td|j��dS)znCheck if TarFile is still open, and if the operation's mode
           corresponds to TarFile's mode.
        z%s is closedNzbad operation for mode %r)r�r_rrzrt)r�rtr7r7r8r��	szTarFile._checkcCsX|��r&tj�|j�d|j}d}n
|j}|}|j||dd�}|durTtd|��|S)zZFind the target member of a symlink or hardlink member in the
           archive.
        rNT)r�rzlinkname %r not found)ryr�rr�r�r�r�r�)r�r�r��limitr�r7r7r8r��	szTarFile._find_link_targetcCs|jrt|j�St|�SdS)z$Provide an iterator object.
        N)r��iterr��TarIterr�r7r7r8r��	s
zTarFile.__iter__cCs||jkrt|tjd�dS)z.Write debugging output to sys.stderr.
        )�fileN)r�r�r�stderr)r��level�msgr7r7r8r��	s
zTarFile._dbgcCs|��|Sr�)r�r�r7r7r8�	__enter__�	szTarFile.__enter__cCs,|dur|��n|js"|j��d|_dSr�)r�r�r�r�)r�r�r7�	tracebackr7r7r8�__exit__�	s


zTarFile.__exit__)NrjNNNNNNrNNN)rjN)rjNr�)rjNr�)NNN)T)NTNN)N)r�N)rpT)T)NF)N)7rzr{r|r}r�r�r�r�r�rUr�r5r6rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rkr�r�r�r�r�r�r�r�rr�r�rr�r�r�rXr�r�r�r�r�r�r'r)r7r7r7r8r,sp�
kK�	

b

>

&
#&
0	1


	rc@s,eZdZdZdd�Zdd�Zdd�ZeZdS)	r"zMIterator Class.

       for tarinfo in TarFile(...):
           suite...
    cCs||_d|_dS)z$Construct a TarIter object.
        rN)r�rrRr7r7r8r�
szTarIter.__init__cCs|S)z Return iterator object.
        r7r�r7r7r8r�
szTarIter.__iter__cCs`|jjs$|j��}|sNd|j_t�n*z|jj|j}WntyLt�Yn0|jd7_|S)z�Return the next item using TarFile's next() method.
           When all members have been read, set TarFile as _loaded.
        Tr)r�r�rX�
StopIterationr�r�
IndexErrorrr7r7r8�__next__

s

zTarIter.__next__N)rzr{r|r}r�r�r,rXr7r7r7r8r"�	s
r"cCs0zt|�}|��WdSty*YdS0dS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)r�r�r)r�rnr7r7r8r#
sr)N)wZ
__future__r�__version__�version�
__author__Z__date__Z	__cvsid__�__credits__rr�r�rr�rOr"r^r�r�r�r��NotImplementedErrorrZWindowsError�	NameError�__all__�version_infoZ__builtin__�builtinsr�Z_openr2r�r�rrrrr.r�r?rzrxr|r~rr�ZCONTTYPEr rr@r(r+rOrrNrr�rTrvrDrs�setrfr%rCrt�S_IFLNK�S_IFREGr�S_IFDIRr
�S_IFIFOZTSUIDZTSGIDZTSVTXZTUREADZTUWRITEZTUEXECZTGREADZTGWRITEZTGEXECZTOREADZTOWRITEZTOEXECr�r��getfilesystemencodingr9r>rJrVr[rfrqrx�	Exceptionrr~rr�r�r�r�r�r�rEr��objectr�r�r�r�r�r�rrr"rr�r7r7r7r8�<module>sN
����
�
�
�
��i?KT*
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL8=;6c| !qfF3aů&~$l}'NWUs$Uk^SV:U# 6w++s&r+nڐ{@29 gL u"TÙM=6(^"7r}=6YݾlCuhquympǦ GjhsǜNlɻ}o7#S6aw4!OSrD57%|?x>L |/nD6?/8w#[)L7+6〼T ATg!%5MmZ/c-{1_Je"|^$'O&ޱմTrb$w)R$& N1EtdU3Uȉ1pM"N*(DNyd96.(jQ)X 5cQɎMyW?Q*!R>6=7)Xj5`J]e8%t!+'!1Q5 !1 AQaqё#2"0BRb?Gt^## .llQT $v,,m㵜5ubV =sY+@d{N! dnO<.-B;_wJt6;QJd.Qc%p{ 1,sNDdFHI0ГoXшe黅XۢF:)[FGXƹ/w_cMeD,ʡcc.WDtA$j@:) -# u c1<@ۗ9F)KJ-hpP]_x[qBlbpʖw q"LFGdƶ*s+ډ_Zc"?%t[IP 6J]#=ɺVvvCGsGh1 >)6|ey?Lӣm,4GWUi`]uJVoVDG< SB6ϏQ@ TiUlyOU0kfV~~}SZ@*WUUi##; s/[=!7}"WN]'(L! ~y5g9T̅JkbM' +s:S +B)v@Mj e Cf jE 0Y\QnzG1д~Wo{T9?`Rmyhsy3!HAD]mc1~2LSu7xT;j$`}4->L#vzŏILS ֭T{rjGKC;bpU=-`BsK.SFw4Mq]ZdHS0)tLg