ok

Mini Shell

Direktori : /proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //proc/thread-self/root/opt/alt/python37/lib64/python3.7/__pycache__/tarfile.cpython-37.pyc

B

� fj�@srdZdZdZdZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZyddlZWnek
r�dZYnXyddlZWnek
r�dZYnXeefZyeef7ZWnek
r�YnXddd	d
ddd
ddddddddgZdZdZedZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/dZ0d+Z1d,Z2e1Z3e!e"e#e$e'e(e)e%e&e*e+e,fZ4e!e"e)e,fZ5e*e+e,fZ6d-Z7d.d/d0d1hZ8e9e9e9e:e:e:d2�Z;ej<d3k�r�d4Z=ne�>�Z=d5d6�Z?d7d8�Z@d9d:�ZAd;e3fd<d=�ZBd>d?�ZCdedfd@dA�ZDdBdC�ZEdDdE�ZFGdFd
�d
eG�ZHGdGd�deH�ZIGdHd�deH�ZJGdId�deH�ZKGdJd
�d
eH�ZLGdKd�deH�ZMGdLdM�dMeM�ZNGdNdO�dOeM�ZOGdPdQ�dQeM�ZPGdRdS�dSeM�ZQGdTdU�dUeM�ZRGdVdW�dW�ZSGdXdY�dY�ZTGdZd[�d[eU�ZVGd\d]�d]eU�ZWGd^d_�d_e	jX�ZYGd`d�deU�ZZGdad�deU�Z[dbd	�Z\e[jZdcdd�Z]e^dek�rne]�dS)fz,Read from and write to tar format archives.
z0.9.0u"Lars Gustäbel (lars@gustaebel.de)u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.�)�openN�TarFile�TarInfo�
is_tarfile�TarError�	ReadError�CompressionError�StreamError�ExtractError�HeaderError�ENCODING�USTAR_FORMAT�
GNU_FORMAT�
PAX_FORMAT�DEFAULT_FORMATr�i�sustar  sustar00�d��0�1�2�3�4�5�6�7�L�K�S�x�g�X��)�path�linkpath�size�mtime�uid�gid�uname�gnamer%r&r+r,)ZatimeZctimer(r)r*r'�ntzutf-8cCs(|�||�}|d|�|t|�tS)z8Convert a string to a null-terminated bytes object.
    N)�encode�len�NUL)�s�length�encoding�errors�r5�,/opt/alt/python37/lib64/python3.7/tarfile.py�stn�sr7cCs*|�d�}|dkr|d|�}|�||�S)z8Convert a null-terminated bytes object to a string.
    r���N)�find�decode)r1r3r4�pr5r5r6�nts�s
r<cCs�|ddkrfd}x0tt|�d�D]}|dK}|||d7}q"W|ddkr�dt|�d|}n@y"t|dd�}t|��p�d	d�}Wntk
r�td
��YnX|S)z/Convert a number field to a python number.
    r)��r#�r>��ascii�strict�0zinvalid header)�ranger/r<�int�strip�
ValueError�InvalidHeaderError)r1�n�ir5r5r6�nti�srKr?cCs�t|�}d|kr$d|dkrDnntd|d|fd�t}n�|tkr�d|d|krrd|dkr�nnZ|dkr�tdg�}ntdg�}d||}x6t|d�D]}|�d|d@�|dL}q�Wntd	��|S)
z/Convert a python number to a number field.
    rr?r#z%0*orAr@r=r>zoverflow in number field)rE�bytesr0r�	bytearrayrD�insertrG)rI�digits�formatr1rJr5r5r6�itn�s 2
rQcCs0dtt�d|��}dtt�d|��}||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@Z
148B8x356BZ
148b8x356b)�sum�structZunpack_from)�bufZunsigned_chksumZ
signed_chksumr5r5r6�calc_chksums�s	rUc	Cs�|pd}|dkrdS|dkr.t�|||�dSt||�\}}x8t|�D],}|�|�}t|�|krh|d��|�|�qFW|dkr�|�|�}t|�|kr�|d��|�|�dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    i@rNzunexpected end of data)�shutil�copyfileobj�divmodrD�readr/�write)	�src�dstr2�	exception�bufsize�blocks�	remainder�brTr5r5r6rW�s$


rWcCs ddl}|�dtd�t�|�S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)�warnings�warn�DeprecationWarning�stat�filemode)�moderbr5r5r6rfsrfcCs8ttjdd�}|dk	r(|�|d��|�}t|dd�dS)Nr3�backslashreplace� )�end)�getattr�sys�stdoutr.r:�print)r1r3r5r5r6�_safe_print
sroc@seZdZdZdS)rzBase exception.N)�__name__�
__module__�__qualname__�__doc__r5r5r5r6rsc@seZdZdZdS)r
z%General exception for extract errors.N)rprqrrrsr5r5r5r6r
sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rprqrrrsr5r5r5r6rsc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rprqrrrsr5r5r5r6rsc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.N)rprqrrrsr5r5r5r6r	sc@seZdZdZdS)rz!Base exception for header errors.N)rprqrrrsr5r5r5r6r sc@seZdZdZdS)�EmptyHeaderErrorzException for empty headers.N)rprqrrrsr5r5r5r6rt#srtc@seZdZdZdS)�TruncatedHeaderErrorz Exception for truncated headers.N)rprqrrrsr5r5r5r6ru&sruc@seZdZdZdS)�EOFHeaderErrorz"Exception for end of file headers.N)rprqrrrsr5r5r5r6rv)srvc@seZdZdZdS)rHzException for invalid headers.N)rprqrrrsr5r5r5r6rH,srHc@seZdZdZdS)�SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rprqrrrsr5r5r5r6rw/srwc@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)�r�w�O_BINARYi�)	�os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr{r�fd)�self�namergr5r5r6�__init__<s

z_LowLevelFile.__init__cCst�|j�dS)N)r|�closer�)r�r5r5r6r�Esz_LowLevelFile.closecCst�|j|�S)N)r|rYr�)r�r'r5r5r6rYHsz_LowLevelFile.readcCst�|j|�dS)N)r|rZr�)r�r1r5r5r6rZKsz_LowLevelFile.writeN)rprqrrrsr�r�rYrZr5r5r5r6rx6s
	rxc@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.
    c	Cs�d|_|dkrt||�}d|_|dkr6t|�}|��}|p<d|_||_||_||_||_d|_	d|_
d|_�yL|dkr�yddl}Wnt
k
r�td	��YnX||_|�d�|_|d
kr�|��|j|_n|��n�|dk�r:yddl}Wnt
k
�r
td��YnX|d
k�r.d|_|��|_t|_n
|��|_n||d
k�r�yddl}Wnt
k
�rntd��YnX|d
k�r�d|_|��|_|j|_n
|��|_n|dk�r�td|��Wn&|j�s�|j��d|_�YnXdS)z$Construct a _Stream object.
        TNF�*��r�gzzzlib module is not availablery�bz2zbz2 module is not available�xzzlzma module is not available�tarzunknown compression type %r) �_extfileobjrx�_StreamProxy�getcomptyper�rg�comptype�fileobjr^rT�pos�closed�zlib�ImportErrorr�crc32�crc�
_init_read_gz�errorr]�_init_write_gzr��dbufZBZ2Decompressor�cmp�OSErrorZ
BZ2Compressor�lzmaZLZMADecompressor�	LZMAErrorZLZMACompressorr�)	r�r�rgr�r�r^r�r�r�r5r5r6r�Ysl












z_Stream.__init__cCst|d�r|js|��dS)Nr�)r�r�r�)r�r5r5r6�__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.
        �	rz<Ls�s�z.gzN���z
iso-8859-1�replace)r�ZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�rS�packrE�time�_Stream__writer��endswithr.r0)r�Z	timestampr5r5r6r��sz_Stream._init_write_gzcCsR|jdkr|j�||j�|_|jt|�7_|jdkrD|j�|�}|�|�dS)z&Write string s to the stream.
        r�r�N)	r�r�r�r�r�r/r��compressr�)r�r1r5r5r6rZ�s

z
_Stream.writecCsR|j|7_x>t|j�|jkrL|j�|jd|j��|j|jd�|_qWdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rTr/r^r�rZ)r�r1r5r5r6Z__write�sz_Stream.__writecCs�|jr
dSd|_z�|jdkr:|jdkr:|j|j��7_|jdkr�|jr�|j�|j�d|_|jdkr�|j�t�	d|j
��|j�t�	d|jd@��Wd|js�|j�
�XdS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        NTrzr�r�r�z<Ll��)r�rgr�rTr��flushr�rZrSr�r�r�r�r�)r�r5r5r6r��s
z
_Stream.closecCs�|j�|jj�|_d|_|�d�dkr0td��|�d�dkrFtd��t|�d��}|�d�|d	@r�t|�d��d
t|�d��}|�	|�|d@r�x|�d�}|r�|t
kr�Pq�W|d@r�x|�d�}|r�|t
kr�Pq�W|d@r�|�d�d
S)z:Initialize for reading a gzip compressed fileobj.
        r�r$s�znot a gzip filer#�zunsupported compression method��r@r?�N)r�Z
decompressobjr�r�r��
_Stream__readrr�ordrYr0)r��flagZxlenr1r5r5r6r��s.
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r�)r�r5r5r6�tell�sz_Stream.tellrcCs\||jdkrNt||j|j�\}}xt|�D]}|�|j�q.W|�|�ntd��|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)r�rXr^rDrYr	)r�r�r_r`rJr5r5r6�seek�sz_Stream.seekNcCsZ|dkr:g}x |�|j�}|s P|�|�qWd�|�}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.
        Nr�)�_readr^�append�joinr�r/)r�r'�trTr5r5r6rYs
z_Stream.readcCs�|jdkr|�|�St|j�}|jg}xd||kr�|�|j�}|sBPy|j�|�}Wn|jk
rptd��YnX|�	|�|t|�7}q(Wd�
|�}||d�|_|d|�S)z+Return size bytes from the stream.
        r�zinvalid compressed datar�N)r�r�r/r�r^r�Z
decompressr]rr�r�)r�r'�cr�rTr5r5r6r�s"





z
_Stream._readcCsnt|j�}|jg}x6||krH|j�|j�}|s0P|�|�|t|�7}qWd�|�}||d�|_|d|�S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        r�N)r/rTr�rYr^r�r�)r�r'r�r�rTr5r5r6Z__read3s



z_Stream.__read)r)N)rprqrrrsr�r�r�rZr�r�r�r�r�rYr�r�r5r5r5r6r�Ns	F
	

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�|_dS)N)r�rY�	BLOCKSIZErT)r�r�r5r5r6r�Isz_StreamProxy.__init__cCs|jj|_|jS)N)r�rYrT)r�r'r5r5r6rYMs
z_StreamProxy.readcCsP|j�d�rdS|jdd�dkr8|jdd�dkr8d	S|j�d
�rHdSdSdS)
Ns�r�r�sBZhr��
s1AY&SYr�)s]�s�7zXZr�r�)rT�
startswith)r�r5r5r6r�Qs$z_StreamProxy.getcomptypecCs|j��dS)N)r�r�)r�r5r5r6r�[sz_StreamProxy.closeN)rprqrrrsr�rYr�r�r5r5r5r6r�Ds

r�c@sjeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
jfdd�Zddd�Z
dd�Zdd�ZdS)�_FileInFilezA thin wrapper around an existing file object that
       provides a part of its data as an individual file
       object.
    NcCs�||_||_||_d|_t|dd�|_d|_|dkr>d|fg}d|_g|_d}|j}xT|D]L\}}||kr~|j�	d||df�|j�	d||||f�||7}||}qZW||jkr�|j�	d||jdf�dS)Nrr�FT)
r��offsetr'�positionrkr�r��	map_index�mapr�)r�r�r�r'Z	blockinfoZlastposZrealposr5r5r6r�hs(

z_FileInFile.__init__cCsdS)Nr5)r�r5r5r6r��sz_FileInFile.flushcCsdS)NTr5)r�r5r5r6�readable�sz_FileInFile.readablecCsdS)NFr5)r�r5r5r6�writable�sz_FileInFile.writablecCs
|j��S)N)r��seekable)r�r5r5r6r��sz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r�)r�r5r5r6r��sz_FileInFile.tellcCs�|tjkr tt|d�|j�|_nj|tjkr\|dkrFt|j|d�|_q�t|j||j�|_n.|tjkr�tt|j||j�d�|_ntd��|jS)z(Seek to a position in the file.
        rzInvalid argument)	�io�SEEK_SET�min�maxr'r��SEEK_CUR�SEEK_ENDrG)r�r��whencer5r5r6r��s


z_FileInFile.seekc	Cs|dkr|j|j}nt||j|j�}d}x�|dk�rxZ|j|j\}}}}||jkrd|krlnnPq:|jd7_|jt|j�kr:d|_q:Wt|||j�}|r�|j�||j|�|j�|�}t|�|kr�t	d��||7}n|t
|7}||8}|j|7_q.W|S)z!Read data from the file.
        Nr�rr#zunexpected end of data)r'r�r�r�r�r/r�r�rYrr0)	r�r'rT�data�start�stopr�r2rar5r5r6rY�s.

z_FileInFile.readcCs&|�t|��}||dt|��<t|�S)N)rYr/)r�rarTr5r5r6�readinto�sz_FileInFile.readintocCs
d|_dS)NT)r�)r�r5r5r6r��sz_FileInFile.close)N)N)rprqrrrsr�r�r�r�r�r�r�r�r�rYr�r�r5r5r5r6r�bs

r�cseZdZ�fdd�Z�ZS)�ExFileObjectcs&t|j|j|j|j�}t��|�dS)N)r�r��offset_datar'�sparse�superr�)r��tarfile�tarinfor�)�	__class__r5r6r��s
zExFileObject.__init__)rprqrrr��
__classcell__r5r5)r�r6r��sr�c@s�eZdZdZdZdTdd�Zedd��Zejdd��Zed	d
��Z	e	jdd
��Z	dd
�Z
dd�Zee
dfdd�Zdd�Zdd�Zdd�Zedd��Zdd�Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�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�Z.dOdP�Z/dQdR�Z0dSS)UraInformational 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�rgr)r*r'r(�chksum�type�linknamer+r,�devmajor�devminorr�r��pax_headersr�r��_sparse_structs�_link_targetr�cCsj||_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�rr�N)r�rgr)r*r'r(r��REGTYPEr�r�r+r,r�r�r�r�r�r�)r�r�r5r5r6r��s"zTarInfo.__init__cCs|jS)N)r�)r�r5r5r6r%�szTarInfo.pathcCs
||_dS)N)r�)r�r�r5r5r6r%scCs|jS)N)r�)r�r5r5r6r&szTarInfo.linkpathcCs
||_dS)N)r�)r�r�r5r5r6r&	scCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�rpr��id)r�r5r5r6�__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.
        i�)
r�rgr)r*r'r(r�r�r�r+r,r�r�r�r��/)r�rgr)r*r'r(r�r�r�r+r,r�r��DIRTYPEr�)r��infor5r5r6�get_infos 
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�r
�create_ustar_headerr�create_gnu_headerr�create_pax_headerrG)r�rPr3r4r�r5r5r6�tobuf(sz
TarInfo.tobufcCsnt|d<t|d�||��tkr(td��t|d�||��tkr^|�|d||�\|d<|d<|�|t||�S)z3Return the object as a ustar header block.
        �magicr�zlinkname is too longr��prefix)	�POSIX_MAGICr/r.�LENGTH_LINKrG�LENGTH_NAME�_posix_split_name�_create_headerr
)r�r�r3r4r5r5r6r�6szTarInfo.create_ustar_headercCs�t|d<d}t|d�||��tkr<||�|dt||�7}t|d�||��tkrl||�|dt||�7}||�|t	||�S)z:Return the object as a GNU header block sequence.
        r�r�r�r�)
�	GNU_MAGICr/r.r��_create_gnu_long_header�GNUTYPE_LONGLINKr��GNUTYPE_LONGNAMEr�r)r�r�r3r4rTr5r5r6r�CszTarInfo.create_gnu_headerc
	Cs0t|d<|j��}x�ddtfddtfddfD]h\}}}||kr@q,y||�dd	�Wn"tk
rv||||<w,YnXt||�|kr,||||<q,Wxhd
D]`\}}||kr�d||<q�||}d|kr�d|d
kr�nn
t|t	�r�t
|�||<d||<q�W|�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.
        r�r�r%r�r&)r+r+� )r,r,r�rArB))r)r?)r*r?)r'�)r(r�rr?r#r�r�)r�r��copyr�r�r.�UnicodeEncodeErrorr/�
isinstance�float�str�_create_pax_generic_header�XHDTYPEr�r
)
r�r�r3r�r�Zhnamer2rO�valrTr5r5r6r�Qs4
*zTarInfo.create_pax_headercCs|�|td�S)zAReturn the object as a pax global header block sequence.
        zutf-8)r�XGLTYPE)�clsr�r5r5r6�create_pax_global_header�sz TarInfo.create_pax_global_headercCs�|�d�}xltdt|��D]R}d�|d|��}d�||d��}t|�||��tkrt|�||��tkrPqWtd��||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        r�r#Nzname is too long)�splitrDr/r�r.�
LENGTH_PREFIXr�rG)r�r�r3r4Z
componentsrJr�r5r5r6r��s
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�t
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�r�rrgri�r?r)r*r'r�r(s        r�r�r�r+r�r,r�r�r�rz%dsr�Ni����z%06orAi����)r7�getrQr�r�rSr�r�r�rUrL)r�rPr3r4�partsrTr�r5r5r6r��s&

&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)rXr/r�r0)Zpayloadr_r`r5r5r6�_create_payload�szTarInfo._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�r'r�)r.r0r/r�r�r
r
)rr�r�r3r4r�r5r5r6r��szTarInfo._create_gnu_long_headerc	Cs:d}x@|��D]4\}}y|�dd�Wqtk
r@d}PYqXqWd}|rV|d7}x�|��D]�\}}|�d�}|r�|�|d�}n
|�d�}t|�t|�d}d	}	}
x"|tt|
��}	|	|
kr�P|	}
q�W|tt|
�d
�d|d|d
7}q`Wi}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.
        Fzutf-8rBTr�s21 hdrcharset=BINARY
r�r�rrA� �=�
z././@PaxHeaderr�r�r'r�r�)
�itemsr.r�r/r�rLr�r�r
r
)rr�r�r3Zbinary�keyword�valueZrecords�lrIr;r�r5r5r6r�s<

*z"TarInfo._create_pax_generic_headerc	Cstt|�dkrtd��t|�tkr(td��|�t�tkr>td��t|dd��}|t|�krbt	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}xrtd�D]f}	y0t|||d��}
t||d|d��}Wntk
�r�PYnX|�|
|f�|d7}�q�Wt|d�}t|dd��}
|||
f|_ |�!��rN|j�"d�|_|�rp|jt#k�rp|d|j|_|S)zAConstruct a TarInfo object from a 512 byte bytes object.
        rzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�r�i�r�r��i�i�i�)$r/rtr�ru�countr0rvrKrUrHr<r�rgr)r*r'r(r�r�r�r+r,r�r��AREGTYPEr�r��GNUTYPE_SPARSErDrGr��boolr��isdir�rstrip�	GNU_TYPES)rrTr3r4r��objr�r��structsrJr��numbytes�
isextended�origsizer5r5r6�frombufsZ
zTarInfo.frombufcCs8|j�t�}|�||j|j�}|j��t|_|�|�S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	r�rYr�r&r3r4r�r��_proc_member)rr�rTr!r5r5r6�fromtarfileAszTarInfo.fromtarfilecCsT|jttfkr|�|�S|jtkr,|�|�S|jtttfkrF|�	|�S|�
|�SdS)zYChoose the right processing method depending on
           the type and call it.
        N)r�r�r��
_proc_gnulongr�_proc_sparserr�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r�r5r5r6r'Vs



zTarInfo._proc_membercCsR|j��|_|j}|��s$|jtkr4||�|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�_blockr'r��_apply_pax_infor�r3r4)r�r�r�r5r5r6r-cszTarInfo._proc_builtincCs�|j�|�|j��}y|�|�}Wntk
r>td��YnX|j|_|jt	krft
||j|j�|_
n|jtkr�t
||j|j�|_|S)zSProcess the blocks that hold a GNU longname
           or longlink member.
        z missing or bad subsequent header)r�rYr0r'r(rrwr�r�r�r<r3r4r�r�r�)r�r�rT�nextr5r5r6r)ts

zTarInfo._proc_gnulongc
	Cs�|j\}}}|`x�|r�|j�t�}d}xvtd�D]j}y0t|||d��}t||d|d��}	Wntk
rzPYnX|r�|	r�|�||	f�|d7}q0Wt|d�}qW||_	|j�
�|_|j|�|j
�|_||_
|S)z8Process a GNU sparse header plus extra headers.
        r�r�ri�)r�r�rYr�rDrKrGr�rr�r�r�r0r'r�)
r�r�r"r$r%rTr�rJr�r#r5r5r6r*�s(zTarInfo._proc_sparsecCs0|j�|�|j��}|jtkr&|j}n
|j��}t�	d|�}|dk	rX|�
d��d�|d<|�d�}|dkrr|j
}nd}t�d�}d}x�|�||�}|s�P|��\}	}
t|	�}	|	dkr�td	��||�d
�d|�d�|	d�}|�|
dd|j�}
|
tk�r|�|||j
|j�}n|�|dd|j�}|||
<||	7}q�Wy|�|�}Wntk
�rdtd��YnXd|k�r~|�||�nHd
|k�r�|�|||�n.|�d�dk�r�|�d�dk�r�|�|||�|jttfk�r,|� ||j
|j�|j!|_!d|k�r,|j"}
|�#��s|jt$k�r&|
|�|j�7}
|
|_!|S)zVProcess an extended or global header as described in
           POSIX.1-2008.
        s\d+ hdrcharset=([^\n]+)\nNr#zutf-8�
hdrcharsetZBINARYs(\d+) ([^=]+)=rzinvalid headerr$z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrCr')%r�rYr0r'r�rr�r��re�search�groupr:rr3�compile�match�groupsrErHrjr��_decode_pax_fieldr4�PAX_NAME_FIELDSr(rrw�_proc_gnusparse_01�_proc_gnusparse_00�_proc_gnusparse_10rr+r1r�r�r.r/)r�r�rTr�r:r4r3Zregexr�r2rrr2r�r5r5r6r,�sd



$	





 
zTarInfo._proc_paxcCspg}x(t�d|�D]}|�t|�d���qWg}x(t�d|�D]}|�t|�d���q@Wtt||��|_dS)z?Process a GNU tar extended sparse header, version 0.0.
        s\d+ GNU.sparse.offset=(\d+)\nr#s\d+ GNU.sparse.numbytes=(\d+)\nN)r6�finditerr�rEr8�list�zipr�)r�r2r�rTZoffsetsr:r#r5r5r6r?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|��qSr5)rE)�.0�xr5r5r6�
<listcomp>sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>zGNU.sparse.map�,Nr$r#)rrBrCr�)r�r2r�r�r5r5r6r>szTarInfo._proc_gnusparse_01cCs�d}g}|j�t�}|�dd�\}}t|�}xJt|�|dkrvd|krV||j�t�7}|�dd�\}}|�t|��q.W|j��|_t	t
|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        Nr
r#r$)r�rYr�rrEr/r�r�r�rBrCr�)r�r2r�r�Zfieldsr�rTZnumberr5r5r6r@szTarInfo._proc_gnusparse_10c	Cs�x�|��D]�\}}|dkr(t|d|�q
|dkrBt|dt|��q
|dkr\t|dt|��q
|tkr
|tkr�yt||�}Wntk
r�d}YnX|dkr�|�d�}t|||�q
W|��|_dS)	zoReplace fields with supplemental information from a previous
           pax extended or global header.
        zGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerr�N)	r�setattrrE�
PAX_FIELDS�PAX_NUMBER_FIELDSrGrr�r�)r�r�r3r4rrr5r5r6r1/s"

zTarInfo._apply_pax_infocCs.y|�|d�Stk
r(|�||�SXdS)z1Decode a single field from a pax record.
        rBN)r:�UnicodeDecodeError)r�rr3Zfallback_encodingZfallback_errorsr5r5r6r<Fs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#)rXr�)r�rr_r`r5r5r6r0NszTarInfo._blockcCs
|jtkS)N)r��
REGULAR_TYPES)r�r5r5r6r.Wsz
TarInfo.isregcCs|��S)N)r.)r�r5r5r6�isfileYszTarInfo.isfilecCs
|jtkS)N)r�r�)r�r5r5r6r[sz
TarInfo.isdircCs
|jtkS)N)r��SYMTYPE)r�r5r5r6�issym]sz
TarInfo.issymcCs
|jtkS)N)r��LNKTYPE)r�r5r5r6�islnk_sz
TarInfo.islnkcCs
|jtkS)N)r��CHRTYPE)r�r5r5r6�ischrasz
TarInfo.ischrcCs
|jtkS)N)r��BLKTYPE)r�r5r5r6�isblkcsz
TarInfo.isblkcCs
|jtkS)N)r��FIFOTYPE)r�r5r5r6�isfifoeszTarInfo.isfifocCs
|jdk	S)N)r�)r�r5r5r6�issparsegszTarInfo.issparsecCs|jtttfkS)N)r�rRrTrV)r�r5r5r6�isdevisz
TarInfo.isdevN)r�)1rprqrrrs�	__slots__r��propertyr%�setterr&r�r�rrr�r�r�r��classmethodrr��staticmethodr�r
r�rr&r(r'r-r)r*r,r?r>r@r1r<r0r.rMrrOrQrSrUrWrXrYr5r5r5r6r�sT

1
3?
h	c
@s�eZdZdZdZdZdZdZeZ	e
ZdZe
ZeZd\dd	�Zedddefd
d��Zed]dd
��Zed^dd��Zed_dd��Zed`dd��Zddddd�Zdd�Zdd�Zdd�Zd d!�Zdad"d#�Zdbdd%�d&d'�Zdcdd(�d)d*�Z ddd+d,�Z!dedd.�d/d0�Z"dfdd.�d2d3�Z#d4d5�Z$dgd6d7�Z%d8d9�Z&d:d;�Z'd<d=�Z(d>d?�Z)d@dA�Z*dBdC�Z+dDdE�Z,dFdG�Z-dHdI�Z.dJdK�Z/dhdLdM�Z0dNdO�Z1didPdQ�Z2dRdS�Z3dTdU�Z4dVdW�Z5dXdY�Z6dZd[�Z7dS)jrz=The TarFile Class provides an interface to tar archives.
    rFr#Nryr�c
Cs�ddddd�}||krtd��||_|||_|sh|jdkrTtj�|�sTd|_d|_t||j�}d	|_n@|d
kr�t|d�r�t	|j
ttf�r�|j
}t|d�r�|j|_d
|_|r�tj�
|�nd
|_
||_|d
k	r�||_|d
k	r�||_|d
k	r�||_|d
k	r�||_|d
k	�r||_|	|_|
d
k	�r0|jtk�r0|
|_ni|_|d
k	�rF||_|d
k	�rV||_|
|_d	|_g|_d	|_|j��|_i|_y�|jdk�r�d
|_ |�!�|_ |jdk�r2x�|j�"|j�y|j�#|�}|j�$|�WnTt%k
�r�|j�"|j�PYn0t&k
�r*}zt't|���Wd
d
}~XYnX�q�W|jdk�r|d
|_|j�r||j�(|j�)��}|j�*|�|jt+|�7_Wn&|j�s�|j�,�d
|_�YnXd
S)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.
        �rbzr+b�wbZxb)ry�arzrEz!mode must be 'r', 'a', 'w' or 'x'rarzFNr�rgTry)rarzrE)-rGrg�_moder|r%�exists�	bltn_openr�r�r�r�r�rL�abspathr�rPr��dereference�ignore_zerosr3r4rr��debug�
errorlevel�copybufsizer��members�_loadedr�r��inodes�firstmemberr2r�r(r�rvrrrr�rZr/r�)r�r�rgr�rPr�rfrgr3r4r�rhrirjZmodes�erTr5r5r6r��s�





$
zTarFile.__init__c

s�|s|std��|dkr��fdd�}xtt�j|d�D]b}t��j|�}|dk	rX|��}	y||d|f|�Sttfk
r�|dk	r�|�|	�w4Yq4Xq4Wtd���nd	|k�r|�d	d
�\}
}|
p�d}
|p�d}|�jkr�t��j|�}ntd|��|||
|f|�Sd
|k�r�|�d
d
�\}
}|
�p*d}
|�p4d}|
dk�rHtd��t	||
|||�}y�||
|f|�}Wn|�
��YnXd|_|S|dk�r��j|||f|�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
           'r:xz'       open for reading with lzma 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
           'w:xz'       open for writing with lzma compression

           'x' or 'x:'  create a tarfile exclusively without compression, raise
                        an exception if the file is already created
           'x:gz'       create a gzip compressed tarfile, raise an exception
                        if the file is already created
           'x:bz2'      create a bzip2 compressed tarfile, raise an exception
                        if the file is already created
           'x:xz'       create an lzma compressed tarfile, raise an exception
                        if the file is already created

           '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
           'r|xz'       open an lzma 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
           'w|xz'       open an lzma compressed stream for writing
        znothing to open)ryzr:*cs�j|dkS)N�taropen)�	OPEN_METH)r�)rr5r6�not_compressed sz$TarFile.open.<locals>.not_compressed)�keyNryz%file could not be opened successfully�:r#r�zunknown compression type %r�|)ryrzzmode must be 'r' or 'w'F)rarzrEzundiscernible mode)
rG�sortedrqrkr�rrr�rr�r�r�rp)
rr�rgr�r^�kwargsrrr��funcZ	saved_posrf�streamr�r5)rr6r�sP%







zTarFile.opencKs |dkrtd��||||f|�S)zCOpen uncompressed tar archive name for reading or writing.
        )ryrarzrEz!mode must be 'r', 'a', 'w' or 'x')rG)rr�rgr�rwr5r5r6rpQszTarFile.taropenr�cKs�|dkrtd��yddlm}Wntk
r<td��YnXy|||d||�}Wn.tk
r�|dk	r||dkr|td	���YnXy|j|||f|�}WnBtk
r�|��|dkr�td	���Yn|���YnXd
|_	|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrEzmode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availableraNryznot a gzip fileF)
rGZgziprzr�rr�rrpr�r�)rr�rgr��
compresslevelrwrzr�r5r5r6�gzopenYs0zTarFile.gzopenc	Ks�|dkrtd��yddlm}Wntk
r<td��YnX||pF|||d�}y|j|||f|�}WnFttfk
r�|��|dkr�t	d���Yn|���YnXd	|_
|S)
zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrEzmode must be 'r', 'w' or 'x'r)�BZ2Filezbz2 module is not available)r{ryznot a bzip2 fileF)rGr�r}r�rrpr��EOFErrorr�rr�)rr�rgr�r{rwr}r�r5r5r6�bz2openzs&zTarFile.bz2openc		Ks�|dkrtd��yddlm}m}Wntk
r@td��YnX||pJ|||d�}y|j|||f|�}WnF|tfk
r�|��|dkr�t	d���Yn|���YnXd	|_
|S)
zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrEzmode must be 'r', 'w' or 'x'r)�LZMAFiler�zlzma module is not available)�presetryznot an lzma fileF)rGr�r�r�r�rrpr~r�rr�)	rr�rgr�r�rwr�r�r�r5r5r6�xzopen�s&zTarFile.xzopenrpr|rr�)r�r�r�r�cCs�|jr
dSd|_z`|jdkrn|j�ttd�|jtd7_t|jt�\}}|dkrn|j�tt|�Wd|j	s�|j�
�XdS)zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NT)rarzrEr$r)r�rgr�rZr0r�r�rX�
RECORDSIZEr�r�)r�r_r`r5r5r6r��s
z
TarFile.closecCs"|�|�}|dkrtd|��|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�r5r5r6�	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.
        )�_checkrl�_loadrk)r�r5r5r6�
getmembers�szTarFile.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�qSr5)r�)rDr�r5r5r6rF�sz$TarFile.getnames.<locals>.<listcomp>)r�)r�r5r5r6�getnames�szTarFile.getnamescCsl|�d�|dk	r|j}|dkr$|}tj�|�\}}|�tjd�}|�d�}|��}||_	|dkr�t
td�r~|js~t�|�}q�t�
|�}nt�|���}d}|j}t
�|��r|j|jf}	|js�|jdkr�|	|jkr�||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�yt.�/|j%�d|_0Wnt1k
�r�YnXt2�r&yt2�3|j'�d|_4Wnt1k
�r$YnX|
t t"fk�rht
td��rht
td	��rht�5|j6�|_7t�8|j6�|_9|S)
a�Create a TarInfo object from the result of os.stat or equivalent
           on an existing file. The file is either named by `name', or
           specified as a file object `fileobj' with a file descriptor. If
           given, `arcname' specifies an alternative name for the file in the
           archive, otherwise, the name is taken from the 'name' attribute of
           'fileobj', or the 'name' argument. The name should be a text
           string.
        �awxNr��lstatr�r#r�major�minor):r�r�r|r%�
splitdriver��sep�lstripr�r�r�rfr�re�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkrmrPr��S_ISDIRr��S_ISFIFOrV�S_ISLNKrN�readlink�S_ISCHRrR�S_ISBLKrTrg�st_uidr)�st_gidr*�st_sizer'�st_mtimer(r�r��pwd�getpwuidr+r��grpZgetgrgidr,r��st_rdevr�r�r�)r�r��arcnamer�Zdrvr�Zstatresr�Zstmd�inoder�r5r5r6�
gettarinfo�s~	




zTarFile.gettarinfoT)rkcCs�|��|dkr|}x�|D]�}|r�tt�|j��td|jp@|j|jpJ|jf�|�	�sb|�
�r|tdd|j|jf�ntd|j
�tdt�|j�dd��t|j|��r�dnd	�|r�|��r�td
|j�|��r�td|j�t�qWdS)aPrint 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. `members' is optional and must be a subset of the
           list returned by getmembers().
        Nz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dr�r�r�z-> zlink to )r�rorerfrgr+r)r,r*rSrUr�r�r'r�Z	localtimer(r�rrOr�rQrn)r��verboserkr�r5r5r6rBQs*
zTarFile.list)�filterc	Cs:|�d�|dkr|}|jdk	rFtj�|�|jkrF|�dd|�dS|�d|�|�||�}|dkrz|�dd|�dS|dk	r�||�}|dkr�|�dd|�dS|��r�t|d��}|�	||�WdQRXnd|�
��r,|�	|�|�r6xHtt�|��D]*}|j
tj�||�tj�||�||d	�q�Wn
|�	|�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. `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�Nr$ztarfile: Skipped %rr#ztarfile: Unsupported type %rztarfile: Excluded %rr_)r�)r�r�r|r%re�_dbgr�r.rd�addfilerrv�listdir�addr�)r�r�r��	recursiver�r��fr5r5r6r�qs4



zTarFile.addcCs�|�d�t�|�}|�|j|j|j�}|j�|�|jt	|�7_|j
}|dk	r�t||j|j|d�t
|jt�\}}|dkr�|j�tt|�|d7}|j|t7_|j�|�dS)aAdd the TarInfo object `tarinfo' to the archive. If `fileobj' is
           given, it should be a binary file, and tarinfo.size bytes are read
           from it and added to the archive. You can create TarInfo objects
           directly, or by using gettarinfo().
        r�N)r^rr#)r�r�r�rPr3r4r�rZr�r/rjrWr'rXr�r0rkr�)r�r�r�rTr^r_r`r5r5r6r��s

zTarFile.addfile�.)�
numeric_ownercCsg}|dkr|}xF|D]>}|��r<|�|�t�|�}d|_|j|||��|d�qW|jdd�d�|��x�|D]�}tj�	||j
�}y,|j|||d�|�||�|�
||�Wqvtk
r�}z"|jdkrւn|�dd	|�Wdd}~XYqvXqvWdS)
a�Extract 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(). If `numeric_owner` is True, only
           the numbers for user/group names are used and not the names.
        Ni�)�	set_attrsr�cSs|jS)N)r�)rar5r5r6�<lambda>�r�z$TarFile.extractall.<locals>.<lambda>)rs)r�r#ztarfile: %s)rr�r�rg�extract�sort�reverser|r%r�r��chown�utime�chmodr
rir�)r�r%rkr�Zdirectoriesr��dirpathror5r5r6�
extractall�s,




zTarFile.extractallr�c
Cs|�d�t|t�r |�|�}n|}|��r>tj�||j�|_	y"|j
|tj�||j�||d�Wn�tk
r�}zH|j
dkr��n6|jdkr�|�dd|j�n|�dd|j|jf�Wdd}~XYnBtk
�r}z"|j
dkr�n|�dd|�Wdd}~XYnXdS)a�Extract 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. If `numeric_owner`
           is True, only the numbers for user/group names are used and not
           the names.
        ry)r�r�rNr#ztarfile: %sztarfile: %s %r)r�r�r�r�rQr|r%r�r�r��_extract_memberr�r�ri�filenamer��strerrorr
)r��memberr%r�r�r�ror5r5r6r��s(	



(
zTarFile.extractcCs�|�d�t|t�r |�|�}n|}|��s6|jtkrB|�||�S|��sR|�	�rzt|j
t�rhtd��q~|�
|�|��SndSdS)z�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 or a
           link, an io.BufferedReader object is returned. Otherwise, None is
           returned.
        ryz'cannot extract (sym)link as file objectN)r�r�r�r�r.r�r/�
fileobjectrQrOr�r�r	�extractfile�_find_link_target)r�r�r�r5r5r6r�s


zTarFile.extractfilecCsT|�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&|jtk�r|�||�n|�||�|�rP|�|||�|�	��sP|�||�|�||�dS)z\Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        r�r#z%s -> %sN)rr�r|r�r%�dirnamerc�makedirsrQrOr�r�r�r.�makefiler�makedirrW�makefiforSrU�makedev�makelinkr�r/�makeunknownr�r�r�)r�r��
targetpathr�r�Z	upperdirsr5r5r6r�*s4


zTarFile._extract_membercCs*yt�|d�Wntk
r$YnXdS)z,Make a directory called targetpath.
        i�N)r|�mkdir�FileExistsError)r�r�r�r5r5r6r�[szTarFile.makedirc	Cs�|j}|�|j�|j}t|d��f}|jdk	rrx,|jD]"\}}|�|�t|||t|�q6W|�|j�|�	�nt|||jt|�WdQRXdS)z'Make a file called targetpath.
        r`N)
r�r�r�rjrdr�rWrr'�truncate)r�r�r��sourcer^�targetr�r'r5r5r6r�es


zTarFile.makefilecCs"|�||�|�dd|j�dS)zYMake a file from a TarInfo object with an unknown type
           at targetpath.
        r#z9tarfile: Unknown file type %r, extracted as regular file.N)r�r�r�)r�r�r�r5r5r6r�uszTarFile.makeunknowncCs"ttd�rt�|�ntd��dS)z'Make a fifo called targetpath.
        �mkfifozfifo not supported by systemN)r�r|r�r
)r�r�r�r5r5r6r�}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
rgrUre�S_IFBLK�S_IFCHRr�r�r�r�)r�r�r�rgr5r5r6r��s
zTarFile.makedevcCs�yL|��rt�|j|�n0tj�|j�r8t�|j|�n|�|�	|�|�WnHt
k
r�y|�|�	|�|�Wntk
r�td��YnXYnXdS)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)
rOr|�symlinkr�r%rcr��linkr�r��symlink_exceptionr�r
)r�r�r�r5r5r6r��s

zTarFile.makelinkcCs�ttd�r�t��dkr�|j}|j}|s�ytr<t�|j�d}Wntk
rRYnXyt	rjt	�
|j�d}Wntk
r�YnXy4|��r�ttd�r�t�
|||�nt�|||�Wntk
r�td��YnXdS)z�Set owner of targetpath according to tarinfo. If numeric_owner
           is True, use .gid/.uid instead of .gname/.uname. If numeric_owner
           is False, fall back to .gid/.uid when the search based on name
           fails.
        �geteuidrr$�lchownzcould not change ownerN)r�r|r�r*r)r�Zgetgrnamr,r�r��getpwnamr+rOr�r�r�r
)r�r�r�r��g�ur5r5r6r��s(z
TarFile.chowncCs>ttd�r:yt�||j�Wntk
r8td��YnXdS)zASet file permissions of targetpath according to tarinfo.
        r�zcould not change modeN)r�r|r�rgr�r
)r�r�r�r5r5r6r��s

z
TarFile.chmodcCsHttd�sdSyt�||j|jf�Wntk
rBtd��YnXdS)zBSet modification time of targetpath according to tarinfo.
        r�Nz"could not change modification time)r�r|r�r(r�r
)r�r�r�r5r5r6r��s
z
TarFile.utimec
Cs�|�d�|jdk	r$|j}d|_|S|j|j��krZ|j�|jd�|j�d�sZtd��d}�xby|j�	|�}W�nHt
k
r�}z0|jr�|�dd|j|f�|jt
7_wbWdd}~XYn�tk
�r,}zL|j�r|�dd|j|f�|jt
7_wbn|jdk�rtt|���Wdd}~XYn�tk
�rT|jdk�rPtd��Ynjtk
�r�}z|jdk�r~tt|���Wdd}~XYn0tk
�r�}ztt|���Wdd}~XYnXPqbW|dk	�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.
        ZraNr#zunexpected end of datar$z0x%X: %srz
empty fileT)r�rnr�r�r�r�rYrr�r(rvrgr�r�rHr�rtrurwrkr�rl)r��mr�ror5r5r6r2�sL


zTarFile.nextcCsn|��}|dk	r"|d|�|��}|r2tj�|�}x6t|�D]*}|rTtj�|j�}n|j}||kr<|Sq<WdS)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��	normalizerkr��member_namer5r5r6r�	szTarFile._getmembercCs"x|��}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r2rl)r�r�r5r5r6r�)	s
z
TarFile._loadcCs:|jrtd|jj��|dk	r6|j|kr6td|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�r�rprg)r�rgr5r5r6r�3	szTarFile._checkcCs`|��r.d�tdtj�|j�|jf��}d}n
|j}|}|j||dd�}|dkr\t	d|��|S)zZFind the target member of a symlink or hardlink member in the
           archive.
        r�NT)r�r�zlinkname %r not found)
rOr�r�r|r%r�r�r�r�r�)r�r�r��limitr�r5r5r6r�<	s zTarFile._find_link_targetccs�|jr|jEdHdSd}|jdk	r:|��}|d7}|VxN|t|j�krV|j|}n"|jst|��}|sxd|_dSndS|d7}|Vq<WdS)z$Provide an iterator object.
        Nrr#T)rlrkrnr2r/)r�r�r�r5r5r6�__iter__O	s&
zTarFile.__iter__cCs||jkrt|tjd�dS)z.Write debugging output to sys.stderr.
        )�fileN)rhrnrl�stderr)r��level�msgr5r5r6r�n	s
zTarFile._dbgcCs|��|S)N)r�)r�r5r5r6�	__enter__t	szTarFile.__enter__cCs,|dkr|��n|js"|j��d|_dS)NT)r�r�r�r�)r�r�r�	tracebackr5r5r6�__exit__x	s


zTarFile.__exit__)
NryNNNNNNr�NNNN)ryN)ryNr�)ryNr�)ryNN)NNN)T)NT)N)r�N)r�T)TF)NF)N)8rprqrrrsrhrfrgrirrPrr3r4rr�r�r�r�r]r�rrpr|rr�rqr�r�r�r�r�rBr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r2r�r�r�r�r�r�r�r�r5r5r5r6rmsv
lZ 

d 3
(&
0
	6


	cCs.yt|�}|��dStk
r(dSXdS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)rr�r)r�r�r5r5r6r�	sc	Cs�ddl}d}|j|d�}|jdddddd	�|jd
d�}|jdd
ddd�|jdddddd�|jdddddd�|jddddd�|��}|jdk	�r|j}t|�r�t|d�� }|��t	|��t
jd�WdQRX|jr�t	d �
|��n|�d!d"�
|���n�|jdk	�r\|j}t|��rFt�|d#��}|j|jd$�WdQRXn|�d!d"�
|���nv|jdk	�r,t|j�d!k�r�|jd}tj}n,t|j�d%k�r�|j\}}n|�d!|���t|��rt�|d#��}|j|d&�WdQRX|j�r*|d'k�rd(�
|�}	nd)�
||�}	t	|	�n|�d!d"�
|��n�|jdk	�r�|j�d�}
tj�|
�\}}d*d*d+d+d,d,d,d,d-�}
||
k�r�d.|
|nd/}|j}t�|
|�� }x|D]}|�|��q�WWdQRX|j�r�t	d0�
|
��dS)1Nrz3A simple command-line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpT)Zrequiredz-lz--listz	<tarfile>zShow listing of a tarfile)�metavarr�z-ez	--extract�+)z	<tarfile>z<output_dir>zExtract tarfile into target dir)�nargsr�r�z-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validry)r�z{!r} is a tar archive.r#z{!r} is not a tar archive.
zr:*)r�r$)r%r�z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r�r�r�)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:rzz{!r} file created.)�argparse�ArgumentParser�add_argumentZadd_mutually_exclusive_group�
parse_argsZtestrrr�rnrlr�r�rP�exitrBrr�r/r|�curdirZformat_helpr�Zcreate�popr%�splitextr�)r�r��parserr8�argsr[r�Ztfr�r�Ztar_name�_ZextZcompressionsZtar_modeZ	tar_files�	file_namer5r5r6�main�	s�









r�__main__)_rs�version�
__author__�__credits__�builtinsrrdrlr|r�rVrer�rSr�r6r�r�r��AttributeError�NotImplementedErrorr�r��	NameError�__all__r0r�r�r�r�r�r�rr�rrPrNrRrTr�rVZCONTTYPEr�r�rrrr+r
rrrr/rLr rIr=r�rErJr�r�getfilesystemencodingr7r<rKrQrUrWrfro�	Exceptionrr
rrr	rrtrurvrHrwrxr��objectr�r��BufferedReaderr�rrrrrpr5r5r5r6�<module>s�



wh W


Zerion Mini Shell 1.0