Your IP : 18.221.161.43


Current Path : /usr/lib64/python3.6/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/__pycache__/tarfile.cpython-36.opt-2.pyc

3

�Qg���'@s$dZdZdZdZdZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZyddlZWnek
r�dZYnXyddlZWnek
r�dZYnXeefZyeef7ZWnek
r�YnXdd	d
ddd
dddddddddgZdZdZdZdZedZdZ dZ!dZ"dZ#dZ$d Z%dZ&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3dZ4d.Z5d/Z6e5Z7e%e&e'e(e+e,e-e)e*e.e/e0fZ8e%e&e-e0fZ9e.e/e0fZ:d�Z;d0d1d6d7hZ<e=e=e=e>e>e>d8�Z?e	j@d9k�r�d:ZAnejB�ZAd;d<�ZCd=d>�ZDd?d@�ZEdAe7fdBdC�ZFdDdE�ZGdedfdFdG�ZHdHdI�ZIdJdK�ZJGdLd�deK�ZLGdMd�deL�ZMGdNd�deL�ZNGdOd
�d
eL�ZOGdPd�deL�ZPGdQd�deL�ZQGdRdS�dSeQ�ZRGdTdU�dUeQ�ZSGdVdW�dWeQ�ZTGdXdY�dYeQ�ZUGdZd[�d[eQ�ZVGd\d]�d]�ZWGd^d_�d_�ZXGd`da�daeY�ZZGdbdc�dceY�Z[Gddde�dee
j\�Z]Gdfdg�dgeL�Z^Gdhdi�die^�Z_Gdjdk�dke^�Z`Gdldm�dme^�ZaGdndo�doe^�ZbGdpdq�dqe^�Zcd�drds�Zddtdu�Zedvdw�Zfdxdy�Zgeeefegdz�ZheY�Ziejjd{�ZkGd|d	�d	eY�ZlGd}d�deY�Zmd~d
�ZnemjZdd��Zoepd�k�r eo�dS)�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.�)�openN�TarFile�TarInfo�
is_tarfile�TarError�	ReadError�CompressionError�StreamError�ExtractError�HeaderError�ENCODING�USTAR_FORMAT�
GNU_FORMAT�
PAX_FORMAT�DEFAULT_FORMATrTz/etc/python/tarfile.cfg�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�gname)ZatimeZctimer(r)r*r'�ntzutf-8cCs8|dkrtd��|j||�}|d|�|t|�tS)Nzmetadata cannot contain None)�
ValueError�encode�len�NUL)�s�length�encoding�errors�r6�/usr/lib64/python3.6/tarfile.py�stn�sr8cCs*|jd�}|dkr|d|�}|j||�S)Nrr#���)�find�decode)r2r4r5�pr6r6r7�nts�s
r=cCs�|ddkrfd}x0tt|�d�D]}|dK}|||d7}q"W|ddkr�dt|�d|}n@y"t|dd�}t|j�p�d	d�}Wntk
r�td
��YnX|S)Nr��r#���ascii�strict�0zinvalid header)r>r?)�ranger0r=�int�stripr.�InvalidHeaderError)r2�n�ir6r6r7�nti�srKr@cCs�t|�}d|ko"d|dknrDtd|d|fd�t}n�|tkr�d|d|kopd|dknr�|dkr�tdg�}ntdg�}d||}x6t|d�D]}|jd|d@�|dL}q�Wntd	��|S)
Nrr@r#z%0*orBrAr>r?zoverflow in number field)rF�bytesr1r�	bytearrayrE�insertr.)rI�digits�formatr2rJr6r6r7�itn�s 2
rQcCs0dttjd|��}dttjd|��}||fS)NrAZ
148B8x356BZ
148b8x356b)�sum�structZunpack_from)�bufZunsigned_chksumZ
signed_chksumr6r6r7�calc_chksums�s	rUc	Cs�|pd}|dkrdS|dkr.tj|||�dSt||�\}}x8t|�D],}|j|�}t|�|krh|d��|j|�qFW|dkr�|j|�}t|�|kr�|d��|j|�dS)N�irzunexpected end of datai@)�shutil�copyfileobj�divmodrE�readr0�write)	�src�dstr3�	exception�bufsize�blocks�	remainder�brTr6r6r7rX�s$


rXcCs ddl}|jdtd�tj|�S)Nrz$deprecated in favor of stat.filemoder$)�warnings�warn�DeprecationWarning�stat�filemode)�modercr6r6r7rgsrgcCs8ttjdd�}|dk	r(|j|d�j|�}t|dd�dS)Nr4�backslashreplace� )�end)�getattr�sys�stdoutr/r;�print)r2r4r6r6r7�_safe_printsrpc@seZdZdS)rN)�__name__�
__module__�__qualname__r6r6r6r7rsc@seZdZdS)r
N)rqrrrsr6r6r6r7r
!sc@seZdZdS)rN)rqrrrsr6r6r6r7r$sc@seZdZdS)rN)rqrrrsr6r6r6r7r'sc@seZdZdS)r	N)rqrrrsr6r6r6r7r	*sc@seZdZdS)rN)rqrrrsr6r6r6r7r-sc@seZdZdS)�EmptyHeaderErrorN)rqrrrsr6r6r6r7rt0srtc@seZdZdS)�TruncatedHeaderErrorN)rqrrrsr6r6r6r7ru3sruc@seZdZdS)�EOFHeaderErrorN)rqrrrsr6r6r6r7rv6srvc@seZdZdS)rHN)rqrrrsr6r6r6r7rH9srHc@seZdZdS)�SubsequentHeaderErrorN)rqrrrsr6r6r6r7rw<srwc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
_LowLevelFilecCsFtjtjtjBtjBd�|}ttd�r2|tjO}tj||d�|_dS)N)�r�w�O_BINARYi�)	�os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr{r�fd)�self�namerhr6r6r7�__init__Is

z_LowLevelFile.__init__cCstj|j�dS)N)r|�closer�)r�r6r6r7r�Rsz_LowLevelFile.closecCstj|j|�S)N)r|rZr�)r�r'r6r6r7rZUsz_LowLevelFile.readcCstj|j|�dS)N)r|r[r�)r�r2r6r6r7r[Xsz_LowLevelFile.writeN)rqrrrsr�r�rZr[r6r6r6r7rxCs	rxc@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zddd�Zdd�Z
dd�ZdS)�_Streamc	Cs�d|_|dkrt||�}d|_|dkr6t|�}|j�}|p<d|_||_||_||_||_d|_	d|_
d|_�yL|dkr�yddl}Wnt
k
r�td��YnX||_|jd�|_|d	kr�|j�|j|_n|j�n�|d
k�r:yddl}Wnt
k
�r
td��YnX|d	k�r.d|_|j�|_t|_n
|j�|_n||dk�r�yddl}Wnt
k
�rntd
��YnX|d	k�r�d|_|j�|_|j|_n
|j�|_n|dk�r�td|��Wn&|j�s�|jj�d|_�YnXdS)NTF�*��r�gzzzlib module is not availablery�bz2zbz2 module is not available�xzzlzma module is not available�tarzunknown compression type %r) �_extfileobjrx�_StreamProxy�getcomptyper�rh�comptype�fileobjr_rT�pos�closed�zlib�ImportErrorr�crc32�crc�
_init_read_gz�errorr^�_init_write_gzr��dbufZBZ2Decompressor�cmp�OSErrorZ
BZ2Compressor�lzmaZLZMADecompressor�	LZMAErrorZLZMACompressorr�)	r�r�rhr�r�r_r�r�r�r6r6r7r�fsl












z_Stream.__init__cCst|d�r|jr|j�dS)Nr�)r�r�r�)r�r6r6r7�__del__�sz_Stream.__del__cCs�|jjd|jj|jj|jjd�|_tjdtt	j	���}|j
d|d�|jjd�rf|jdd
�|_|j
|jj
dd	�t�dS)N�	rz<Ls�s�z.gz�z
iso-8859-1�replace���)r�ZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�rS�packrF�time�_Stream__writer��endswithr/r1)r�Z	timestampr6r6r7r��sz_Stream._init_write_gzcCsR|jdkr|jj||j�|_|jt|�7_|jdkrD|jj|�}|j|�dS)Nr�r�)	r�r�r�r�r�r0r��compressr�)r�r2r6r6r7r[�s

z
_Stream.writecCsR|j|7_x>t|j�|jkrL|jj|jd|j��|j|jd�|_qWdS)N)rTr0r_r�r[)r�r2r6r6r7Z__write�sz_Stream.__writecCs�|jr
dSd|_z�|jdkr:|jdkr:|j|jj�7_|jdkr�|jr�|jj|j�d|_|jdkr�|jjtj	d|j
��|jjtj	d|jd@��Wd|js�|jj
�XdS)NTrzr�r�r�z<Ll��)r�rhr�rTr��flushr�r[rSr�r�r�r�r�)r�r6r6r7r��s
z
_Stream.closecCs�|jj|jj�|_d|_|jd�dkr0td��|jd�dkrFtd��t|jd��}|jd�|d	@r�t|jd��d
t|jd��}|j	|�|d@r�x|jd�}|s�|t
kr�Pq�W|d@r�x|jd�}|s�|t
kr�Pq�W|d@r�|jd�dS)
Nr�r$s�znot a gzip filer#�zunsupported compression method��rAr@rV)r�Z
decompressobjr�r�r��
_Stream__readrr�ordrZr1)r��flagZxlenr2r6r6r7r��s.
 


z_Stream._init_read_gzcCs|jS)N)r�)r�r6r6r7�tellsz_Stream.tellrcCs\||jdkrNt||j|j�\}}xt|�D]}|j|j�q.W|j|�ntd��|jS)Nrz seeking backwards is not allowed)r�rYr_rErZr	)r�r�r`rarJr6r6r7�seeksz_Stream.seekNcCsZ|dkr:g}x |j|j�}|s P|j|�qWdj|�}n
|j|�}|jt|�7_|S)Nr�)�_readr_�append�joinr�r0)r�r'�trTr6r6r7rZs
z_Stream.readcCs�|jdkr|j|�St|j�}|jg}xd||kr�|j|j�}|sBPy|jj|�}Wn|jk
rptd��YnX|j	|�|t|�7}q(Wdj
|�}||d�|_|d|�S)Nr�zinvalid compressed datar�)r�r�r0r�r_r�Z
decompressr^rr�r�)r�r'�cr�rTr6r6r7r�*s"





z
_Stream._readcCsnt|j�}|jg}x6||krH|jj|j�}|s0P|j|�|t|�7}qWdj|�}||d�|_|d|�S)Nr�)r0rTr�rZr_r�r�)r�r'r�r�rTr6r6r7Z__read@s



z_Stream.__read)r)N)rqrrrsr�r�r�r[r�r�r�r�r�rZr�r�r6r6r6r7r�[sF
	

r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r�cCs||_|jjt�|_dS)N)r�rZ�	BLOCKSIZErT)r�r�r6r6r7r�Vsz_StreamProxy.__init__cCs|jj|_|jS)N)r�rZrT)r�r'r6r6r7rZZs
z_StreamProxy.readcCsP|jjd�rdS|jdd�dkr8|jdd�dkr8d	S|jjd�rHdSd
SdS)Ns�r�rr�sBZhr��
s1AY&SYr��]���7zXZr�r�)r�r�)rT�
startswith)r�r6r6r7r�^s$z_StreamProxy.getcomptypecCs|jj�dS)N)r�r�)r�r6r6r7r�hsz_StreamProxy.closeN)rqrrrsr�rZr�r�r6r6r6r7r�Qs
r�c@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Ze	j
fdd�Zddd�Zdd�Z
dd�ZdS)�_FileInFileNcCs�||_||_||_d|_t|dd�|_d|_|dkr>d|fg}d|_g|_d}|j}xT|D]L\}}||kr~|jj	d||df�|jj	d||||f�||7}||}qZW||jkr�|jj	d||jdf�dS)Nrr�FT)
r��offsetr'�positionrlr�r��	map_index�mapr�)r�r�r�r'Z	blockinfoZlastposZrealposr6r6r7r�us(

z_FileInFile.__init__cCsdS)Nr6)r�r6r6r7r��sz_FileInFile.flushcCsdS)NTr6)r�r6r6r7�readable�sz_FileInFile.readablecCsdS)NFr6)r�r6r6r7�writable�sz_FileInFile.writablecCs
|jj�S)N)r��seekable)r�r6r6r7r��sz_FileInFile.seekablecCs|jS)N)r�)r�r6r6r7r��sz_FileInFile.tellcCs�|tjkr tt|d�|j�|_nj|tjkr\|dkrFt|j|d�|_q�t|j||j�|_n.|tjkr�tt|j||j�d�|_ntd��|jS)NrzInvalid argument)	�io�SEEK_SET�min�maxr'r��SEEK_CUR�SEEK_ENDr.)r�r��whencer6r6r7r��s


z_FileInFile.seekc	Cs|dkr|j|j}nt||j|j�}d}x�|dk�rxZ|j|j\}}}}||jkob|knrlPq:|jd7_|jt|j�kr:d|_q:Wt|||j�}|r�|jj||j|�|jj|�}t|�|kr�t	d��||7}n|t
|7}||8}|j|7_q.W|S)Nr�rr#zunexpected end of data)r'r�r�r�r�r0r�r�rZrr1)	r�r'rT�data�start�stopr�r3rbr6r6r7rZ�s.

z_FileInFile.readcCs&|jt|��}||dt|��<t|�S)N)rZr0)r�rbrTr6r6r7�readinto�sz_FileInFile.readintocCs
d|_dS)NT)r�)r�r6r6r7r��sz_FileInFile.close)N)N)rqrrrsr�r�r�r�r�r�r�r�r�rZr�r�r6r6r6r7r�os

r�cseZdZ�fdd�Z�ZS)�ExFileObjectcs&t|j|j|j|j�}t�j|�dS)N)r�r��offset_datar'�sparse�superr�)r��tarfile�tarinfor�)�	__class__r6r7r��s
zExFileObject.__init__)rqrrrsr��
__classcell__r6r6)r�r7r��sr�c@seZdZdS)�FilterErrorN)rqrrrsr6r6r6r7r��sr�cseZdZ�fdd�Z�ZS)�AbsolutePathErrorcs ||_t�jd|j�d��dS)Nzmember z has an absolute path)r�r�r�r�)r�r�)r�r6r7r��szAbsolutePathError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�OutsideDestinationErrorcs.||_||_t�j|j�d|�d�d�dS)Nz would be extracted to z, z which is outside the destination)r��_pathr�r�r�)r�r�r%)r�r6r7r��sz OutsideDestinationError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�SpecialFileErrorcs||_t�j|j�d��dS)Nz is a special file)r�r�r�r�)r�r�)r�r6r7r��szSpecialFileError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�AbsoluteLinkErrorcs||_t�j|j�d��dS)Nz! is a symlink to an absolute path)r�r�r�r�)r�r�)r�r6r7r��szAbsoluteLinkError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�LinkOutsideDestinationErrorcs.||_||_t�j|j�d|�d�d�dS)Nz would link to z, z which is outside the destination)r�r�r�r�r�)r�r�r%)r�r6r7r��sz$LinkOutsideDestinationError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cCs�i}|j}tjj|�}|jdtjf�r@|jjdtj�}|d<tjj|�rTt|��tjjtjj	||��}tjj
||g�|kr�t||��|j}|dk	�r|d@}|r�|j
�s�|j�r�|d@s�|dM}|dO}n|j�s�|j�r�d}nt|��||jk�r||d<|�r�|jdk	�rd|d<|jdk	�r.d|d	<|jdk	�rBd|d
<|jdk	�rVd|d<|j��sj|j��r�tjj|j��r�t|��|j��r�tjj	|tjj|�|j�}ntjj	||j�}tjj|�}tjj
||g�|k�r�t||��|S)
N�/r�i��@�Ii�rhr)r*r+r,i����)r�r|r%�realpathr��sep�lstrip�isabsr�r��
commonpathr�rh�isreg�islnk�isdir�issymr�r)r*r+r,�linknamer��dirnamer�)�member�	dest_pathZfor_data�	new_attrsr�Ztarget_pathrhr6r6r7�_get_filtered_attrssZ






r�cCs|S)Nr6)r�r�r6r6r7�fully_trusted_filterCsr�cCs(t||d�}|r$|jf|ddi��S|S)NF�deep)r�r�)r�r�r�r6r6r7�
tar_filterFsr�cCs(t||d�}|r$|jf|ddi��S|S)NTr�F)r�r�)r�r�r�r6r6r7�data_filterLsr�)Z
fully_trustedr�r�s([0-9]{1,20}) c@s�eZdZdlZdmdd�Zdd�Zdd�Zeee�Zdd�Z	dd�Z
ee	e
�Zd d!�Ze
e
e
e
e
e
e
e
d"e
d#�
d$d%�Zd&d'�Zeed(fd)d*�Zd+d,�Zd-d.�Zd/d0�Zed1d2��Zd3d4�Zed5d6��Zed7d8��Zed9d:��Zed;d<��Zed=d>��Zed?d@��ZdAdB�Z dCdD�Z!dEdF�Z"dGdH�Z#dIdJ�Z$dKdL�Z%dMdN�Z&dOdP�Z'dQdR�Z(dSdT�Z)dUdV�Z*dWdX�Z+dYdZ�Z,d[d\�Z-d]d^�Z.d_d`�Z/dadb�Z0dcdd�Z1dedf�Z2dgdh�Z3didj�Z4dkS)nrr�rhr)r*r'r(�chksum�typer�r+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)Ni�rr�)r�rhr)r*r'r(r��REGTYPEr�r�r+r,r�r�r�r�r�r�)r�r�r6r6r7r�ps"zTarInfo.__init__cCs|jS)N)r�)r�r6r6r7�_getpath�szTarInfo._getpathcCs
||_dS)N)r�)r�r�r6r6r7�_setpath�szTarInfo._setpathcCs|jS)N)r�)r�r6r6r7�_getlinkpath�szTarInfo._getlinkpathcCs
||_dS)N)r�)r�r�r6r6r7�_setlinkpath�szTarInfo._setlinkpathcCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�rqr��id)r�r6r6r7�__repr__�szTarInfo.__repr__T)
r�r(rhr�r)r*r+r,r��_KEEPc
Cs�|	rtj|�}n
tj|�}||
k	r(||_||
k	r6||_||
k	rD||_||
k	rR||_||
k	r`||_||
k	rn||_||
k	r|||_||
k	r�||_	|S)N)
�copy�deepcopyr�r(rhr�r)r*r+r,)r�r�r(rhr�r)r*r+r,r�r�resultr6r6r7r��s(
zTarInfo.replacecCs�|jdkrd}n
|jd@}|j||j|j|j|j|j|j|j|j	|j
|j|jd�
}|dt
kr~|djd�r~|dd7<|S)Ni�)
r�rhr)r*r'r(r�r�r�r+r,r�r�r�r�r�)rhr�r)r*r'r(r�r�r�r+r,r�r��DIRTYPEr�)r�rh�infor6r6r7�get_info�s&


zTarInfo.get_info�surrogateescapecCs~|j�}x(|j�D]\}}|dkrtd|��qW|tkrH|j|||�S|tkr^|j|||�S|tkrr|j||�Std��dS)Nz%s may not be Nonezinvalid format)	r�itemsr.r
�create_ustar_headerr�create_gnu_headerr�create_pax_header)r�rPr4r5rr��valuer6r6r7�tobuf�sz
TarInfo.tobufcCsnt|d<t|dj||��tkr(td��t|dj||��tkr^|j|d||�\|d<|d<|j|t||�S)N�magicr�zlinkname is too longr��prefix)	�POSIX_MAGICr0r/�LENGTH_LINKr.�LENGTH_NAME�_posix_split_name�_create_headerr
)r�rr4r5r6r6r7r�szTarInfo.create_ustar_headercCs�t|d<d}t|dj||��tkr<||j|dt||�7}t|dj||��tkrl||j|dt||�7}||j|t	||�S)Nrr�r�r�)
�	GNU_MAGICr0r/r�_create_gnu_long_header�GNUTYPE_LONGLINKr�GNUTYPE_LONGNAMErr)r�rr4r5rTr6r6r7r�szTarInfo.create_gnu_headerc
Cs4t|d<|jj�}x�ddtfddtfddfD]h\}}}||kr@q,y||jd	d
�Wn"tk
rv||||<w,YnXt||�|kr,||||<q,WxldD]d\}}||kr�d||<q�||}d|ko�d|dkn�s�t|t	�r�t
|�||<d||<q�W|�r|j|t|�}	nd}	|	|j
|td	d�S)Nrr�r%r�r&r+� r,rBrCr)r@r*r'�r(rr#r�r�)r+r+r)r,r,r�r)r@�r*r@�r'r �r(r )r!r"r#r$)rr�rrrr/�UnicodeEncodeErrorr0�
isinstance�float�str�_create_pax_generic_header�XHDTYPErr
)
r�rr4r�r�Zhnamer3rO�valrTr6r6r7r�s4
.zTarInfo.create_pax_headercCs|j|td�S)Nzutf-8)r)�XGLTYPE)�clsr�r6r6r7�create_pax_global_header.sz TarInfo.create_pax_global_headercCs�|jd�}xltdt|��D]R}dj|d|��}dj||d��}t|j||��tkrt|j||��tkrPqWtd��||fS)Nr�r#zname is too long)�splitrEr0r�r/�
LENGTH_PREFIXrr.)r�r�r4r5Z
componentsrJrr6r6r7r4s
zTarInfo._posix_split_namecCs�|jd�ttfk}|r@t|jdd�d|�}t|jdd�d|�}ntdd||�}tdd||�}|jdt�}|dkrxtd��t|jdd�d	||�t|jd
d�d@d|�t|jdd�d|�t|jd
d�d|�t|jdd�d|�t|jdd�d|�d|t|jdd�d	||�|jdt�t|jdd�d||�t|jdd�d||�t|jdd�d|�t|jdd�d|�t|jdd�d||�g}tj	dt
dj|��}	t|	t
d��d}
|	dd�t
d|
d�|	d d�}	|	S)!Nr�r�rr@r�r�zTarInfo.type must not be Noner�rrhi�r)r*r'r r(s        r�rr+rr,rrz%dsr�ilz%06orBiei����i����)�get�CHRTYPE�BLKTYPErQr8r�r.rrSr�r�r�rUrL)rrPr4r5Zhas_device_fieldsr�r�Zfiletype�partsrTr�r6r6r7rDs8
&zTarInfo._create_headercCs.tt|�t�\}}|dkr*|t|t7}|S)Nr)rYr0r�r1)Zpayloadr`rar6r6r7�_create_payloadnszTarInfo._create_payloadcCsR|j||�t}i}d|d<||d<t|�|d<t|d<|j|t||�|j|�S)Nz
././@LongLinkr�r�r'r)r/r1r0rrr
r5)r-r�r�r4r5rr6r6r7rxszTarInfo._create_gnu_long_headercCs:d}x@|j�D]4\}}y|jdd�Wqtk
r@d}PYqXqWd}|rV|d7}x�|j�D]�\}}|jd�}|r�|j|d�}n
|jd�}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<|j|td
d�|j	|�S)NFzutf-8rCTr�s21 hdrcharset=BINARY
r
r�rrB� �=�
z././@PaxHeaderr�r�r'rr�)
rr/r%r0r(rLrrr
r5)r-r�r�r4Zbinary�keywordrZrecords�lrIr<rr6r6r7r)�s<

*z"TarInfo._create_pax_generic_headercCstt|�dkrtd��t|�tkr(td��|jt�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�|jjd��r�t|_|jtk�r6d}g}xrtd�D]f}	y0t|||d��}
t||d|d��}Wntk
�r�PYnX|j|
|f�|d7}�q�Wt|d�}t|dd��}
|||
f|_ |j!��rN|jj"d�|_|�rp|jt#k�rp|d|j|_|S)Nrzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�r�i�r�r �i�i�i�)$r0rtr�ru�countr1rvrKrUrHr=r�rhr)r*r'r(r�r�r�r+r,r�r��AREGTYPEr�r
�GNUTYPE_SPARSErEr.r��boolr�r��rstrip�	GNU_TYPES)r-rTr4r5r��objrr��structsrJr��numbytes�
isextended�origsizer6r6r7�frombuf�sZ
zTarInfo.frombufcCs8|jjt�}|j||j|j�}|jj�t|_|j|�S)N)	r�rZr�rNr4r5r�r��_proc_member)r-r�rTrIr6r6r7�fromtarfile�szTarInfo.fromtarfilecCsT|jttfkr|j|�S|jtkr,|j|�S|jtttfkrF|j	|�S|j
|�SdS)N)r�rr�
_proc_gnulongrE�_proc_sparser*r,�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r�r6r6r7rOs



zTarInfo._proc_membercCsR|jj�|_|j}|j�s$|jtkr4||j|j�7}||_|j	|j
|j|j�|S)N)
r�r�r�r�r��SUPPORTED_TYPES�_blockr'r��_apply_pax_infor�r4r5)r�r�r�r6r6r7rUszTarInfo._proc_builtincCs�|jj|j|j��}y|j|�}Wntk
r>td��YnX|j|_|jt	krft
||j|j�|_
n|jtkr�t
||j|j�|_|S)Nz missing or bad subsequent header)r�rZrWr'rPrrwr�r�rr=r4r5r�rr�)r�r�rT�nextr6r6r7rQ.s

zTarInfo._proc_gnulongc
Cs�|j\}}}|`x�|r�|jjt�}d}xvtd�D]j}y0t|||d��}t||d|d��}	Wntk
rzPYnX|r�|	r�|j||	f�|d7}q0Wt|d�}qW||_	|jj
�|_|j|j|j
�|_||_
|S)Nr�r rBi�)r�r�rZr�rErKr.r�rFr�r�r�rWr'r�)
r�r�rJrLrMrTr�rJr�rKr6r6r7rRDs(zTarInfo._proc_sparsecCs�|jj|j|j��}|jtkr&|j}n
|jj�}d}d}g}�x0t|�|koV||dk�rnt	j
||�}|srtd��yt|j
d��}Wntk
r�td��YnX|dkr�td��||t|�kr�td��|jd�|d}	||jd�d|	�}
|
jd�\}}}
|�s"|dk�s"||	dk�r*td��|j|||
f�|dk�rd|dk�rd|
dk�r`|j}nd	}||7}q@W|dk�r~d	}x`|D]X\}}}
|j|d	d	|j�}|tk�r�|j|
||j|j�}n|j|
d	d	|j�}|||<�q�Wy|j|�}Wntk
�rtd
��YnXd|k�r&|j||�nFd|k�r>|j||�n.|jd
�dk�rl|jd�dk�rl|j|||�|jttfk�r�|j ||j|j�|j!|_!d|k�r�|j"}|j#��s�|jt$k�r�||j|j�7}||_!|S)Nrzinvalid headerr#�r7r�s
hdrcharsetsBINARYzutf-8z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrDr')%r�rZrWr'r�r,r�rr0�_header_length_prefix_re�matchrHrF�groupr.r�rk�	partitionr�r4�_decode_pax_fieldr5�PAX_NAME_FIELDSrPrrw�_proc_gnusparse_01�_proc_gnusparse_00r1�_proc_gnusparse_10r*rSrXr�r�r�rV)r�r�rTr�r�r4�raw_headersr^r3Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuer9rrYr�r6r6r7rT`sx

 







 
zTarInfo._proc_paxcCs�g}g}x�|D]�\}}}|dkrVy|jt|j���Wq�tk
rRtd��Yq�Xq|dkry|jt|j���Wqtk
r�td��YqXqWtt||��|_dS)NsGNU.sparse.offsetzinvalid headersGNU.sparse.numbytes)r�rFr;r.rH�list�zipr�)r�rYrfZoffsetsrK�_r9rr6r6r7rd�szTarInfo._proc_gnusparse_00cCs@dd�|djd�D�}tt|ddd�|ddd���|_dS)NcSsg|]}t|��qSr6)rF)�.0�xr6r6r7�
<listcomp>�sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>zGNU.sparse.map�,r$r#)r/rgrhr�)r�rYr�r�r6r6r7rc�szTarInfo._proc_gnusparse_01cCs�d}g}|jjt�}|jdd�\}}t|�}xJt|�|dkrvd|krV||jjt�7}|jdd�\}}|jt|��q.W|jj�|_t	t
|ddd�|ddd���|_dS)Nr8r#r$)r�rZr�r/rFr0r�r�r�rgrhr�)r�rYr�r�Zfieldsr�rTZnumberr6r6r7re�szTarInfo._proc_gnusparse_10c
Cs�x�|j�D]�\}}|dkr(t|d|�q
|dkrBt|dt|��q
|dkr\t|dt|��q
|tkr
|tkr�yt||�}Wntk
r�d}YnX|dkr�|jd�}t|||�q
W|j�|_dS)NzGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerr�)	r�setattrrF�
PAX_FIELDS�PAX_NUMBER_FIELDSr.rGrr�)r�r�r4r5r9rr6r6r7rXs"

zTarInfo._apply_pax_infocCs.y|j|d�Stk
r(|j||�SXdS)NrC)r;�UnicodeDecodeError)r�rr4Zfallback_encodingZfallback_errorsr6r6r7raszTarInfo._decode_pax_fieldcCs"t|t�\}}|r|d7}|tS)Nr#)rYr�)r�rCr`rar6r6r7rW#szTarInfo._blockcCs
|jtkS)N)r��
REGULAR_TYPES)r�r6r6r7r�,sz
TarInfo.isregcCs|j�S)N)r�)r�r6r6r7�isfile.szTarInfo.isfilecCs
|jtkS)N)r�r
)r�r6r6r7r�0sz
TarInfo.isdircCs
|jtkS)N)r��SYMTYPE)r�r6r6r7r�2sz
TarInfo.issymcCs
|jtkS)N)r��LNKTYPE)r�r6r6r7r�4sz
TarInfo.islnkcCs
|jtkS)N)r�r2)r�r6r6r7�ischr6sz
TarInfo.ischrcCs
|jtkS)N)r�r3)r�r6r6r7�isblk8sz
TarInfo.isblkcCs
|jtkS)N)r��FIFOTYPE)r�r6r6r7�isfifo:szTarInfo.isfifocCs
|jdk	S)N)r�)r�r6r6r7�issparse<szTarInfo.issparsecCs|jtttfkS)N)r�r2r3rx)r�r6r6r7�isdev>sz
TarInfo.isdevN)r�rhr)r*r'r(r�r�r�r+r,r�r�r�r�r�r�r�r�r�)r�)5rqrrrs�	__slots__r�rr�propertyr%rrr&rrr�rrrrrrr�classmethodr.r�staticmethodrr5rr)rNrPrOrUrQrRrTrdrcrerXrarWr�rsr�r�r�rvrwryrzr{r6r6r6r7rbsd



1*
3?
z	c
@s�eZdZdZdZdZdZeZe	Z
dZeZ
eZdZdedd�Zedddefd	d
��Zedfdd��Zedgdd��Zedhdd��Zedidd��Zddddd�Zdd�Zdd�Zdd�Zdd �Zdjd!d"�Zdkdd$�d%d&�Zdldd'�d(d)�Z dmd*d+�Z!d,d-�Z"dnddd/�d0d1�Z#doddd/�d3d4�Z$d5d6�Z%d7d8�Z&d9d:�Z'd;d<�Z(d=d>�Z)dpd?d@�Z*dAdB�Z+dCdD�Z,dEdF�Z-dGdH�Z.dIdJ�Z/dKdL�Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dqdUdV�Z5dWdX�Z6drdYdZ�Z7d[d\�Z8d]d^�Z9d_d`�Z:dadb�Z;dcdd�Z<dS)srrFr#Nryr
cCs�ddddd�}||krtd��||_|||_|sj|jdkrVtjj|�rVd|_d|_t||j�}d	|_n@|dkr�t|d
�r�t	|j
ttf�r�|j
}t|d�r�|j|_d|_|r�tjj
|�nd|_
||_|dk	r�||_|dk	r�||_|dk	r�||_|dk	�r||_|dk	�r||_|	|_|
dk	�r4|jtk�r4|
|_ni|_|dk	�rJ||_|dk	�rZ||_|
|_d	|_g|_d	|_|jj�|_i|_�y�|jd
k�r�d|_ |j!�|_ |jdk�r8x�|jj"|j�y|jj#|�}|jj$|�WnTt%k
�r|jj"|j�PYn0t&k
�r0}zt't|���WYdd}~XnX�q�W|jdk�r�d|_|j�r�|jj(|jj)��}|jj*|�|jt+|�7_Wn&|j�s�|jj,�d|_�YnXdS)N�rbzr+b�wbZxb)ry�arzrkz!mode must be 'r', 'a', 'w' or 'x'r�rzFr�rhTryrk)r�rzrk)-r.rh�_moder|r%�exists�	bltn_openr�r�r&r�r(rL�abspathr�rPr��dereference�ignore_zerosr4r5rr��debug�
errorlevel�copybufsizer��members�_loadedr�r��inodes�firstmemberrYr�rPr�rvrrr.rr[r0r�)r�r�rhr�rPr�r�r�r4r5r�r�r�r�Zmodes�erTr6r6r7r�^s�






$
zTarFile.__init__c

s�|r|rtd��|dkr��fdd�}xtt�j|d�D]b}t��j|�}|dk	r\|j�}	y||d|f|�Sttfk
r�|dk	r�|j|	�w8Yq8Xq8Wtd���nd|k�r|jdd	�\}
}|
p�d}
|p�d
}|�jkr�t��j|�}ntd|��|||
|f|�Sd|k�r�|jdd	�\}
}|
�p.d}
|�p8d
}|
dk�rLtd��t	||
|||�}y�||
|f|�}Wn|j
��YnXd|_|S|dk�r��j|||f|�Std��dS)Nznothing to openry�r:*cs�j|dkS)N�taropen)�	OPEN_METH)r�)r-r6r7�not_compressed�sz$TarFile.open.<locals>.not_compressed)�keyz%file could not be opened successfully�:r#r�zunknown compression type %r�|rzzmode must be 'r' or 'w'Fr�rkzundiscernible mode)ryr�)ryrz)r�rzrk)
r.�sortedr�rlr�rrr�r/r�r�r�r�)
r-r�rhr�r_�kwargsr�r��funcZ	saved_posrg�streamr�r6)r-r7r�sP%







zTarFile.opencKs |dkrtd��||||f|�S)Nryr�rzrkz!mode must be 'r', 'a', 'w' or 'x')ryr�rzrk)r.)r-r�rhr�r�r6r6r7r�(szTarFile.taropenr�cKs�|d
krtd��yddl}|jWn ttfk
rBtd��YnXy|j||d||�}Wn.tk
r�|dk	r�|dkr�td���YnXy|j|||f|�}WnBtk
r�|j	�|dkr�td���Yn|j	��YnXd	|_
|S)Nryrzrkzmode must be 'r', 'w' or 'x'rzgzip module is not availablerbznot a gzip fileF)ryrzrk)r.�gzipZGzipFiler��AttributeErrorrr�rr�r�r�)r-r�rhr��
compresslevelr�r�r�r6r6r7�gzopen0s2
zTarFile.gzopencKs�|d
krtd��yddl}Wntk
r8td��YnX|j|pD|||d�}y|j|||f|�}WnFttfk
r�|j�|dkr�t	d���Yn|j��YnXd	|_
|S)Nryrzrkzmode must be 'r', 'w' or 'x'rzbz2 module is not available)r�znot a bzip2 fileF)ryrzrk)r.r�r�rZBZ2Filer�r��EOFErrorr�rr�)r-r�rhr�r�r�r�r�r6r6r7�bz2openRs(zTarFile.bz2opencKs�|d
krtd��yddl}Wntk
r8td��YnX|j|pD|||d�}y|j|||f|�}WnH|jtfk
r�|j�|dkr�t	d���Yn|j��YnXd	|_
|S)Nryrzrkzmode must be 'r', 'w' or 'x'rzlzma module is not available)�presetznot an lzma fileF)ryrzrk)r.r�r�rZLZMAFiler�r�r�r�rr�)r-r�rhr�r�r�r�r�r6r6r7�xzopenos&zTarFile.xzopenr�r�r�r�)r�r�r�r�c
Cs�|jr
dSd|_z`|jdkrn|jjttd�|jtd7_t|jt�\}}|dkrn|jjtt|�Wd|j	s�|jj
�XdS)NTr�rzrkr$r)r�rzrk)r�rhr�r[r1r�r�rY�
RECORDSIZEr�r�)r�r`rar6r6r7r��s
z
TarFile.closecCs"|j|�}|dkrtd|��|S)Nzfilename %r not found)�
_getmember�KeyError)r�r�r�r6r6r7�	getmember�s
zTarFile.getmembercCs|j�|js|j�|jS)N)�_checkr��_loadr�)r�r6r6r7�
getmembers�szTarFile.getmemberscCsdd�|j�D�S)NcSsg|]
}|j�qSr6)r�)rjr�r6r6r7rl�sz$TarFile.getnames.<locals>.<listcomp>)r�)r�r6r6r7�getnames�szTarFile.getnamescCsp|jd�|dk	r|j}|dkr$|}tjj|�\}}|jtjd�}|jd�}|j�}||_	|dkr�t
td�r�|jr�tj|�}q�tj
|�}ntj|j��}d}|j}t
j|��r|j|jf}	|jr�|jdkr�|	|jkr�||j|	kr�t}
|j|	}nt}
|	d�rx||j|	<nht
j|��r"t}
nVt
j|��r4t}
nDt
j|��rPt}
tj|�}n(t
j|��rbt }
nt
j!|��rtt"}
ndS||_||_#|j$|_%|j&|_'|
tk�r�|j(|_)nd|_)|j*|_+|
|_,||_-t.�r�yt.j/|j%�d|_0Wnt1k
�r�YnXt2�r*yt2j3|j'�d|_4Wnt1k
�r(YnX|
t t"fk�rlt
td��rlt
td��rltj5|j6�|_7tj8|j6�|_9|S)	N�awxr��lstatr�r#r�major�minor):r�r�r|r%�
splitdriver�r�r�r�r�r�r�r�rf�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�rur��S_ISDIRr
�S_ISFIFOrx�S_ISLNKrt�readlink�S_ISCHRr2�S_ISBLKr3rh�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�r6r6r7�
gettarinfo�s~	




zTarFile.gettarinfoT)r�cCs0|j�|dkr|}�x|D�]
}|r�|jdkr:td�nttj|j��td|jpX|j|jpb|jf�|j	�sz|j
�r�tdd|j|jf�ntd|j
�|jdkr�td�ntdtj|j�dd��t|j|j�r�d	nd
�|�r"|j��r
td|j�|j��r"td|j�t�qWdS)
Nz
??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02dr�r�r�z-> zlink to )r�rhrprfrgr+r)r,r*rvrwr�r�r'r(r�Z	localtimer�r�r�r�r�ro)r��verboser�r�r6r6r7rg*s2





zTarFile.list)�filterc	
Csv|jd�|dkr|}|dk	rPddl}|jdtd�||�rP|jdd|�dS|jdk	r�tjj|�|jkr�|jdd|�dS|jd|�|j	||�}|dkr�|jdd|�dS|dk	r�||�}|dkr�|jdd|�dS|j
��rt|d	��}|j||�WdQRXnd|j
��rh|j|�|�rrxHtj|�D].}|jtjj||�tjj||�|||d
��q4Wn
|j|�dS)Nr�rzuse the filter argument insteadr$ztarfile: Excluded %rztarfile: Skipped %rr#ztarfile: Unsupported type %rr�)r�)r�rcrdre�_dbgr�r|r%r�r�r�r��addfiler��listdir�addr�)	r�r�r��	recursiveZexcluder�rcr��fr6r6r7r�PsB



zTarFile.addcCs�|jd�tj|�}|j|j|j|j�}|jj|�|jt	|�7_|j
}|dk	r�t||j|j|d�t
|jt�\}}|dkr�|jjtt|�|d7}|j|t7_|jj|�dS)Nr�)r_rr#)r�rrrPr4r5r�r[r�r0r�rXr'rYr�r1r�r�)r�r�r�rTr_r`rar6r6r7r��s

zTarFile.addfilec"CsH|dk�r|j}|dk�r�tjjd�}|dkr�ytt�}Wntk
rNYnBXddl}|jddd�}|�|j	|�WdQRX|jdddd�}|r�yt
|}Wn&tk
r�td|�d	��d�YnX||_|St
�r�tjdt�tStSt|t��rtd��|St|��r|Syt
|Stk
�rBtd|�d	��d�YnXdS)NZ PYTHON_TARFILE_EXTRACTION_FILTERr�#)Z
interpolationZcomment_prefixesr�r�)Zfallbackzfilter z
 not foundz4The default behavior of tarfile extraction has been z$changed to disallow common exploits z(including CVE-2007-4559). z1By default, absolute/parent paths are disallowed z and some mode bits are cleared. z/See https://access.redhat.com/articles/7004769 zfor more details.z#String names are not supported for z2TarFile.extraction_filter. Use a function such as ztarfile.data_filter directly.)r�zXThe default behavior of tarfile extraction has been changed to disallow common exploits zsThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 aThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 for more details.zUString names are not supported for TarFile.extraction_filter. Use a function such as zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)�extraction_filterr|�environr1r��_CONFIG_FILENAME�FileNotFoundError�configparserZConfigParserZ	read_file�_NAMED_FILTERSr�r.�_RH_SAFER_DEFAULTrcrd�RuntimeWarningr�r�r&r(�	TypeError�callable)r�r�r��filer�Zconfr6r6r7�_get_filter_function�sR


zTarFile._get_filter_function�.)�
numeric_ownerr�cCs�g}|j|�}|dkr|}xN|D]F}|j|||�}|dkr<q |j�rN|j|�|j|||j�|d�q W|jdd�dd�xv|D]n}tjj||j	�}	y,|j
||	|d�|j||	�|j||	�Wq�t
k
r�}
z|j|
�WYdd}
~
Xq�Xq�WdS)N)�	set_attrsr�cSs|jS)N)r�)r�r6r6r7�<lambda>�sz$TarFile.extractall.<locals>.<lambda>T)r��reverse)r�)r��_get_extract_tarinfor�r��_extract_one�sortr|r%r�r��chown�utime�chmodr
�_handle_nonfatal_error)r�r%r�r�r�Zdirectories�filter_functionr�r��dirpathr�r6r6r7�
extractall�s*



zTarFile.extractallr�cCs4|j|�}|j|||�}|dk	r0|j||||�dS)N)r�r�r�)r�r�r%r�r�r�r�r�r6r6r7�extract	s
zTarFile.extractcCs�t|t�r|j|�}n|}|}y|||�}WnZttfk
r\}z|j|�WYdd}~Xn,tk
r�}z|j|�WYdd}~XnX|dkr�|jdd|j	�dS|j
�r�tj|�}tj
j||j�|_|S)Nr$ztarfile: Excluded %r)r&r(r�r�r��_handle_fatal_errorr
r�r�r�r�rr|r%r�r�r�)r�r�r�r%r�Z
unfilteredr�r6r6r7r�	s"

zTarFile._get_extract_tarinfocCs�|jd�y"|j|tjj||j�||d�WnVtk
rX}z|j|�WYdd}~Xn,tk
r�}z|j	|�WYdd}~XnXdS)Nry)r�r�)
r��_extract_memberr|r%r�r�r�r�r
r�)r�r�r%r�r�r�r6r6r7r�2	s
zTarFile._extract_onecCs"|jdkr�n|jdd|�dS)Nr#ztarfile: %s)r�r�)r�r�r6r6r7r�?	s
zTarFile._handle_nonfatal_errorcCsn|jdkr�n\t|t�rP|jdkr6|jdd|j�qj|jdd|j|jf�n|jddt|�j|f�dS)Nrr#ztarfile: %sztarfile: %s %rztarfile: %s %s)r�r&r��filenamer��strerrorr�rq)r�r�r6r6r7r�F	s


zTarFile._handle_fatal_errorcCs�|jd�t|t�r |j|�}n|}|j�s6|jtkrB|j||�S|j�sR|j	�rzt|j
t�rhtd��q~|j
|j|��SndSdS)Nryz'cannot extract (sym)link as file object)r�r&r(r�r�r�rV�
fileobjectr�r�r�r�r	�extractfile�_find_link_target)r�r�r�r6r6r7r�R	s


zTarFile.extractfilecCsV|jd�}|jdtj�}tjj|�}|r@tjj|�r@tj|�|j�sP|j	�rj|j
dd|j|jf�n|j
d|j�|j
�r�|j||�n�|j�r�|j||�nx|j�r�|j||�nb|j�s�|j�r�|j||�nD|j�s�|j	�r�|j||�n&|jtk�r|j||�n|j||�|�rR|j|||�|j	��sR|j||�|j||�dS)Nr�r#z%s -> %s)rGr�r|r�r%r�r��makedirsr�r�r�r�r�r��makefiler��makedirry�makefiforvrw�makedev�makelinkr�rV�makeunknownr�r�r�)r�r��
targetpathr�r�Z	upperdirsr6r6r7r�q	s4


zTarFile._extract_membercCs@y&|jdkrtj|�ntj|d�Wntk
r:YnXdS)Ni�)rhr|�mkdir�FileExistsError)r�r�r�r6r6r7r��	s
zTarFile.makedircCs�|j}|j|j�|j}t|d��f}|jdk	rrx,|jD]"\}}|j|�t|||t|�q6W|j|j�|j	�nt|||jt|�WdQRXdS)Nr�)
r�r�r�r�r�r�rXrr'�truncate)r�r�r��sourcer_�targetr�r'r6r6r7r��	s


zTarFile.makefilecCs"|j||�|jdd|j�dS)Nr#z9tarfile: Unknown file type %r, extracted as regular file.)r�r�r�)r�r�r�r6r6r7r��	szTarFile.makeunknowncCs"ttd�rtj|�ntd��dS)N�mkfifozfifo not supported by system)r�r|rr
)r�r�r�r6r6r7r��	s
zTarFile.makefifocCsnttd�sttd�r td��|j}|dkr2d}|j�rF|tjO}n
|tjO}tj||tj	|j
|j��dS)N�mknodr�z'special devices not supported by systemi�)r�r|r
rhrwrf�S_IFBLK�S_IFCHRrr�r�r�)r�r�r�rhr6r6r7r��	s
zTarFile.makedevcCs�yL|j�rtj|j|�n0tjj|j�r8tj|j|�n|j|j	|�|�WnHt
k
r�y|j|j	|�|�Wntk
r�td��YnXYnXdS)Nz%unable to resolve link inside archive)
r�r|�symlinkr�r%r�r��linkr�r��symlink_exceptionr�r
)r�r�r�r6r6r7r��	s

zTarFile.makelinkcCs�ttd�r�tj�dkr�|j}|j}|s�ytrB|jrBtj|j�d}Wntk
rXYnXyt	rv|j
rvt	j|j
�d}Wntk
r�YnX|dkr�d}|dkr�d}y4|j�r�ttd�r�tj
|||�ntj|||�Wntk
r�td��YnXdS)	N�geteuidrr$r#�lchownzcould not change ownerr9r9)r�r|r	r*r)r�r,Zgetgrnamr�r�r+�getpwnamr�r
r�r�r
)r�r�r�r��g�ur6r6r7r��	s0

z
TarFile.chowncCsL|jdkrdSttd�rHytj||j�Wntk
rFtd��YnXdS)Nr�zcould not change mode)rhr�r|r�r�r
)r�r�r�r6r6r7r�
s

z
TarFile.chmodcCsV|j}|dkrdSttd�s dSytj|||f�Wntk
rPtd��YnXdS)Nr�z"could not change modification time)r(r�r|r�r�r
)r�r�r�r(r6r6r7r�$
s
z
TarFile.utimecCs�|jd�|jdk	r$|j}d|_|S|j|jj�krZ|jj|jd�|jjd�sZtd��d}�xby|jj	|�}W�nHt
k
r�}z2|jr�|jdd|j|f�|jt
7_wbWYdd}~Xn�tk
�r,}zN|j�r|jdd|j|f�|jt
7_wbn|jdk�rtt|���WYdd}~Xn�tk
�rT|jdk�rPtd��Ynjtk
�r�}z|jdk�r~tt|���WYdd}~Xn0tk
�r�}ztt|���WYdd}~XnXPqbW|dk	�r�|jj|�nd|_|S)	NZrar#zunexpected end of datar$z0x%X: %srz
empty fileT)r�r�r�r�r�r�rZrr�rPrvr�r�r�rHr(rtrurwr�r�r�)r��mr�r�r6r6r7rY2
sL


zTarFile.nextc	Cs�|j�}d}|dk	rHy|j|�}Wntk
r:d}YnX|d|�}|rXtjj|�}xLt|�D]@}|r||j|jkrbd}qb|r�tjj|j�}n|j}||krb|SqbW|r�t|��dS)NFT)	r��indexr.r|r%�normpath�reversedr�r�)	r�r�r��	normalizer�Zskippingrr��member_namer6r6r7r�h
s,
zTarFile._getmembercCs"x|j�}|dkrPqWd|_dS)NT)rYr�)r�r�r6r6r7r��
s
z
TarFile._loadcCs:|jrtd|jj��|dk	r6|j|kr6td|j��dS)Nz%s is closedzbad operation for mode %r)r�r�r�rqrh)r�rhr6r6r7r��
szTarFile._checkcCs`|j�r.djtdtjj|j�|jf��}d}n
|j}|}|j||dd�}|dkr\t	d|��|S)Nr�T)r�rzlinkname %r not found)
r�r�r�r|r%r�r�r�r�r�)r�r�r��limitr�r6r6r7r��
s zTarFile._find_link_targetccs�|jr|jEdHdSd}|jdk	r:|j�}|d7}|VxN|t|j�krV|j|}n"|jst|j�}|sxd|_dSndS|d7}|Vq<WdS)Nrr#T)r�r�r�rYr0)r�rr�r6r6r7�__iter__�
s&
zTarFile.__iter__cCs||jkrt|tjd�dS)N)r�)r�rorm�stderr)r��level�msgr6r6r7r��
s
zTarFile._dbgcCs|j�|S)N)r�)r�r6r6r7�	__enter__�
szTarFile.__enter__cCs,|dkr|j�n|js"|jj�d|_dS)NT)r�r�r�r�)r�r�r�	tracebackr6r6r7�__exit__�
s


zTarFile.__exit__)
NryNNNNNNr
NNNN)ryN)ryNr�)ryNr�)ryNN)NNN)T)NTN)N)r�N)r�T)TF)NF)N)=rqrrrsr�r�r�r�rrPrr4r5rr�r�r�r�r�r~r�rr�r�r�r�r�r�r�r�r�r�rgr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rYr�r�r�r�rr�rrr6r6r6r7rBs�
lZ!

d&=
5,

0!6
(

	cCs.yt|�}|j�dStk
r(dSXdS)NTF)rr�r)r�r�r6r6r7r�
scCsddl}d}|j|d�}|jdddddd	�|jd
dtdd
�|j�}|jddddd�|jdddd5dd�|jdddd6dd�|jdddd d�|j�}|jr�|jr�|jd!d"�|j	�r*|j	}t
|��rt|d#�� }|j�t
|j�tjd$�WdQRX|j�r&t
d%j|��n|jd!d&j|���n�|j�r�|j}t
|��rjtj|d'��}|j|jd(�WdQRXn|jd!d&j|���n�|j�rPt|j�d!k�r�|jd}tj}n,t|j�d)k�r�|j\}}n|jd!|j��t
|��r<tj|d'��}|j||jd*�WdQRX|j�rN|d+k�r&d,j|�}	nd-j||�}	t
|	�n|jd!d&j|��n�|j�r�|jjd�}
tjj|
�\}}d.d.d/d/d0d0d0d0d1�}
||
k�r�d2|
|nd3}|j}tj|
|�� }x|D]}|j|��q�WWdQRX|j�rt
d4j|
��n|jd!|j��dS)7Nrz3A simple command line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpz--filterz<filtername>zFilter for extraction)�metavar�choicesr z-lz--list�	<tarfile>zShow listing of a tarfile)r!r z-ez	--extract�+�<output_dir>zExtract tarfile into target dir)�nargsr!r z-cz--create�<name>�<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction
ry)r�z{!r} is a tar archive.z{!r} is not a tar archive.
zr:*)r�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.)r#r%)r'r()�argparse�ArgumentParser�add_argumentr�Zadd_mutually_exclusive_group�
parse_argsr�r��exitZtestrrr�rormrr�rPrgrr0r|�curdirZformat_helpr�Zcreate�popr%�splitextr�)r)r�parserr_�argsr\r�Ztfr.rZtar_nameriZextZcompressionsZtar_modeZ	tar_files�	file_namer6r6r7�main�
s�










r4�__main__)r%r&r'r(r)r*r+r,)T)q�version�
__author__Z__date__Z	__cvsid__�__credits__�builtinsrr�rmr|r�rWrfr�rSr�rercr�r�r�r��NotImplementedErrorrr��	NameError�__all__r�r�r1r�r�rrrrr0r�rDrurtr2r3r
rxZCONTTYPErrrEr*r,rSr
rrrrVrrrHrorbr'rFrpr�r�getfilesystemencodingr8r=rKrQrUrXrgrp�	Exceptionrr
rrr	rrtrurvrHrwrxr��objectr�r��BufferedReaderr�r�r�r�r�r�r�r�r�r�r�r�r�compiler]rrrr4rqr6r6r6r7�<module> s



wh

?
e4b


?>