Your IP : 3.15.144.162


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/tarfile.cpython-310.opt-2.pyc

o

6��f���@s�	dZdZdZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZzddlZWneyFdZYnwzddlZWneyXdZYnweefZzeef7ZWn	eymYnwgd�ZdZdZed	Zd
ZdZdZdZd
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2e2Z3e!e"e#e$e'e(e)e%e&e*e+e,fZ4e!e"e)e,fZ5e*e+e,fZ6dZ7hd�Z8e9e9e9e:e:e:d �Z;ej<d!kr�d"Z=ne�>�Z=d#d$�Z?d%d&�Z@d'd(�ZAd)e3fd*d+�ZBd,d-�ZCdedfd.d/�ZDd0d1�ZEGd2d3�d3eF�ZGGd4d5�d5eG�ZHGd6d7�d7eG�ZIGd8d9�d9eG�ZJGd:d;�d;eG�ZKGd<d=�d=eG�ZLGd>d?�d?eL�ZMGd@dA�dAeL�ZNGdBdC�dCeL�ZOGdDdE�dEeL�ZPGdFdG�dGeL�ZQGdHdI�dI�ZRGdJdK�dK�ZSGdLdM�dMeT�ZUGdNdO�dOeT�ZVGdPdQ�dQejW�ZXGdRdS�dSeG�ZYGdTdU�dUeY�ZZGdVdW�dWeY�Z[GdXdY�dYeY�Z\GdZd[�d[eY�Z]Gd\d]�d]eY�Z^drd_d`�Z_dadb�Z`dcdd�Zadedf�Zbe`eaebdg�ZceT�Zde�edh�ZfGdidj�djeT�ZgGdkdl�dleT�Zhdmdn�ZiehjZdodp�Zjekdqk�r�ej�dSdS)sz0.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�gname>r&r+r,r%)Zatime�ctimer(r)r*r'�nt�utf-8cCs:	|dur	td��|�||�}|d|�|t|�tS)Nzmetadata cannot contain None)�
ValueError�encode�len�NUL)�s�length�encoding�errors�r8�./opt/alt/python310/lib64/python3.10/tarfile.py�stn�s
r:cCs,	|�d�}|dkr|d|�}|�||�S)Nr���)�find�decode)r4r6r7�pr8r8r9�nts�s

r?cCs�	|ddvr3d}tt|�d�D]}|dK}|||d7}q|ddkr1dt|�d|}|Szt|dd�}t|��p@d	d�}W|StyPtd
��w)Nr)��r#�rA��ascii�strict�0�invalid header)�ranger2r?�int�stripr0�InvalidHeaderError)r4�n�ir8r8r9�nti�s ���rNrBcCs�	|}t|�}d|krd|dkr&nntd|d|fd�t}|S|tkrnd|d|kr=d|dkrnntd	��|dkrLtdg�}ntdg�}d||}t|d�D]}|�d|d@�|dL}q]|Std	��)
NrrBr#z%0*orDrCr@rAzoverflow in number field)rI�bytesr3r�	bytearrayrH�insertr0)rL�digits�formatZ
original_nr4rMr8r8r9�itn�s"
 0��

�rTcCs2	dtt�d|��}dtt�d|��}||fS)NrCZ
148B8x356BZ
148b8x356b)�sum�structZunpack_from)�bufZunsigned_chksumZ
signed_chksumr8r8r9�calc_chksums�srXc	Cs�	|pd}|dkrdS|durt�|||�dSt||�\}}t|�D]}|�|�}t|�|kr4|d��|�|�q#|dkrR|�|�}t|�|krM|d��|�|�dS)Ni@r�unexpected end of data)�shutil�copyfileobj�divmodrH�readr2�write)	�srcZdstr5�	exception�bufsize�blocks�	remainder�brWr8r8r9r[�s&


r[cCs8ttjdd�}|dur|�|d��|�}t|dd�dS)Nr6�backslashreplace� )�end)�getattr�sys�stdoutr1r=�print)r4r6r8r8r9�_safe_printsrlc@�eZdZ	dS)rN��__name__�
__module__�__qualname__r8r8r8r9r�rc@rm)r
Nrnr8r8r8r9r
rrr
c@rm)rNrnr8r8r8r9rrrrc@rm)rNrnr8r8r8r9rrrrc@rm)r	Nrnr8r8r8r9r	rrr	c@rm)rNrnr8r8r8r9rrrrc@rm)�EmptyHeaderErrorNrnr8r8r8r9rs!rrrsc@rm)�TruncatedHeaderErrorNrnr8r8r8r9rt$rrrtc@rm)�EOFHeaderErrorNrnr8r8r8r9ru'rrruc@rm)rKNrnr8r8r8r9rK*rrrKc@rm)�SubsequentHeaderErrorNrnr8r8r8r9rv-rrrvc@�.eZdZ	dd�Zdd�Zdd�Zdd�Zd	S)
�
_LowLevelFilecCsFtjtjtjBtjBd�|}ttd�r|tjO}t�||d�|_dS)N��r�w�O_BINARYi�)	�os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr|r�fd)�self�name�moder8r8r9�__init__:s��

z_LowLevelFile.__init__cCst�|j�dS�N)r}�closer��r�r8r8r9r�Csz_LowLevelFile.closecCst�|j|�Sr�)r}r]r��r�r'r8r8r9r]F�z_LowLevelFile.readcCst�|j|�dSr�)r}r^r��r�r4r8r8r9r^Isz_LowLevelFile.writeN)rorprqr�r�r]r^r8r8r8r9rx4s	rxc@speZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�ZdS)�_Streamc	Cs�	d|_|durt||�}d|_|dkrt|�}|��}|pd|_||_||_||_||_d|_	d|_
d|_z�|dkrmzddl}Wnt
yMtd�d�w||_|�d�|_|d	krf|��|j|_WdS|��WdS|d
kr�zddl}Wnt
y�td�d�w|d	kr�d|_|��|_t|_WdS|��|_WdS|dkr�zddl}Wnt
y�td
�d�w|d	kr�d|_|��|_|j|_WdS|��|_WdS|dkr�td|��WdS|js�|j��d|_�)NTF�*��r�gzzzlib module is not availablerz�bz2�bz2 module is not available�xz�lzma module is not available�tar�unknown compression type %r) �_extfileobjrx�_StreamProxy�getcomptyper�r��comptype�fileobjrarW�pos�closed�zlib�ImportErrorr�crc32�crc�
_init_read_gz�errorr`�_init_write_gzr��dbufZBZ2Decompressor�cmp�OSErrorZ
BZ2Compressor�lzmaZLZMADecompressor�	LZMAErrorZLZMACompressorr�)	r�r�r�r�r�rar�r�r�r8r8r9r�Wsv


�
�

�
�
z_Stream.__init__cCs$t|d�r|js|��dSdSdS)Nr�)r�r�r�r�r8r8r9�__del__�s�z_Stream.__del__cCs�	|j�d|jj|jj|jjd�|_t�dtt	�	���}|�
d|d�|j�d�r4|jdd�|_t
j�|j�|_|�
|j�dd	�t�dS)
N�	r�<Ls�s��.gz���z
iso-8859-1�replace)r�ZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�rV�packrI�time�_Stream__writer��endswithr}r%�basenamer1r3)r�Z	timestampr8r8r9r��s�z_Stream._init_write_gzcCsT	|jdkr|j�||j�|_|jt|�7_|jdkr#|j�|�}|�|�dS)Nr�r�)	r�r�r�r�r�r2r��compressr�r�r8r8r9r^�s

z
_Stream.writecCsb	|j|7_t|j�|jkr/|j�|jd|j��|j|jd�|_t|j�|jksdSdSr�)rWr2rar�r^r�r8r8r9Z__write�s�z_Stream.__writecCs�	|jrdSd|_zP|jdkr|jdkr|j|j��7_|jdkrM|jrM|j�|j�d|_|jdkrM|j�t�	d|j
��|j�t�	d|jd@��W|jsX|j�
�dSdS|jsc|j�
�ww)NTr{r�r�r�r�l��)r�r�r�rWr��flushr�r^rVr�r�r�r�r�r�r8r8r9r��s&
�
��z
_Stream.closecCs�	|j�|jj�|_d|_|�d�dkrtd��|�d�dkr$td��t|�d��}|�d�|d	@rIt|�d��d
t|�d��}|�	|�|d@r[	|�d�}|rY|t
krZnqN|d
@rm	|�d�}|rk|t
krlnq`|d@rx|�d�dSdS)Nr�r$s��not a gzip filer#�zunsupported compression method��rCrBT�)r�Z
decompressobjr�r�r��
_Stream__readrr�ordr]r3)r��flagZxlenr4r8r8r9r��s6
 

�
��z_Stream._init_read_gzcC�	|jSr�)r�r�r8r8r9�tell��z_Stream.tellrcCsX	||jdkr(t||j|j�\}}t|�D]}|�|j�q|�|�|jStd��)Nrz seeking backwards is not allowed)r�r\rarHr]r	)r�r�rbrcrMr8r8r9�seek�s
�z_Stream.seekcCs"	|�|�}|jt|�7_|Sr�)�_readr�r2)r�r'rWr8r8r9r]s
z_Stream.readc
Cs�	|jdkr|�|�St|j�}|jg}||krV|jr"|j}d|_n
|j�|j�}|s,n*z|j�	|�}Wn|j
yF}ztd�|�d}~ww|�|�|t|�7}||ksd�
|�}||d�|_|d|�S)Nr�r�zinvalid compressed data)r�r�r2r�rWr�r]rar��
decompressr`r�append�join)r�r'�c�trW�er8r8r9r�s0



��
�
z
_Stream._readcCsr	t|j�}|jg}||kr'|j�|j�}|sn|�|�|t|�7}||ksd�|�}||d�|_|d|�S)Nr�)r2rWr�r]rar�r�)r�r'r�r�rWr8r8r9Z__read-s

�
z_Stream.__readN)r)rorprqr�r�r�r^r�r�r�r�r�r]r�r�r8r8r8r9r�Ls
F
	

r�c@rw)
r�cCs||_|j�t�|_dSr�)r�r]�	BLOCKSIZErW)r�r�r8r8r9r�Csz_StreamProxy.__init__cCs|jj|_|jSr�)r�r]rWr�r8r8r9r]Gs
z_StreamProxy.readcCsL|j�d�rdS|jdd�dkr|jdd�dkrd	S|j�d
�r$dSdS)
Ns�r�r�sBZhr��
s1AY&SYr�)s]�s�7zXZr�r�)rW�
startswithr�r8r8r9r�Ks$z_StreamProxy.getcomptypecCs|j��dSr�)r�r�r�r8r8r9r�Ur�z_StreamProxy.closeN)rorprqr�r]r�r�r8r8r8r9r�>s
r�c@sheZdZ	ddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Ze	j
fdd�Zddd�Zdd�Z
dd�ZdS)�_FileInFileNcCs�||_||_||_d|_t|dd�|_d|_|durd|fg}d|_g|_d}|j}|D]&\}}||kr>|j�	d||df�|j�	d||||f�||7}||}q,||jkre|j�	d||jdf�dSdS)Nrr�FT)
r��offsetr'�positionrhr�r��	map_index�mapr�)r�r�r�r'Z	blockinfoZlastposZrealposr8r8r9r�bs*


�z_FileInFile.__init__cCsdSr�r8r�r8r8r9r�{�z_FileInFile.flushcC�dS�NTr8r�r8r8r9�readable~r�z_FileInFile.readablecCr��NFr8r�r8r8r9�writable�r�z_FileInFile.writablecCs
|j��Sr�)r��seekabler�r8r8r9r���
z_FileInFile.seekablecCr�r�)r�r�r8r8r9r��r�z_FileInFile.tellcCs�	|tjkrtt|d�|j�|_|jS|tjkr5|dkr(t|j|d�|_|jSt|j||j�|_|jS|tjkrJtt|j||j�d�|_|jStd��)NrzInvalid argument)	�io�SEEK_SET�min�maxr'r��SEEK_CUR�SEEK_ENDr0)r�r��whencer8r8r9r��s


��
��z_FileInFile.seekc	Cs	|dur|j|j}n	t||j|j�}d}|dkr�	|j|j\}}}}||jkr1|kr4nnn|jd7_|jt|j�krFd|_qt|||j�}|rq|j�||j|�|j�|�}t|�|krlt	d��||7}n|t
|7}||8}|j|7_|dks|S)Nr�rTr#rY)r'r�r�r�r�r2r�r�r]rr3)	r�r'rW�data�start�stopr�r5rdr8r8r9r]�s4�
�z_FileInFile.readcCs&|�t|��}||dt|��<t|�Sr�)r]r2)r�rdrWr8r8r9�readinto�sz_FileInFile.readintocCs
d|_dSr�)r�r�r8r8r9r��r�z_FileInFile.closer�)rorprqr�r�r�r�r�r�r�r�r�r]r�r�r8r8r8r9r�\s

r�c�eZdZ�fdd�Z�ZS)�ExFileObjectcs&t|j|j|j|j�}t��|�dSr�)r�r��offset_datar'�sparse�superr�)r��tarfile�tarinfor���	__class__r8r9r��s
�zExFileObject.__init__�rorprqr��
__classcell__r8r8r�r9r��sr�c@seZdZdS)�FilterErrorNrnr8r8r8r9r��sr�cr�)�AbsolutePathErrorcs ||_t��d|j�d��dS)Nzmember z has an absolute path�r�r�r�r��r�r�r�r8r9r��szAbsolutePathError.__init__r�r8r8r�r9r���r�cr�)�OutsideDestinationErrorc�.||_||_t��|j�d|�d�d�dS)Nz would be extracted to �, � which is outside the destination�r��_pathr�r�r��r�r�r%r�r8r9r���

�z OutsideDestinationError.__init__r�r8r8r�r9r��r�r�cr�)�SpecialFileErrorc�||_t��|j�d��dS)Nz is a special filer�r�r�r8r9r���zSpecialFileError.__init__r�r8r8r�r9r�r�rcr�)�AbsoluteLinkErrorcr)Nz is a link to an absolute pathr�r�r�r8r9r��rzAbsoluteLinkError.__init__r�r8r8r�r9r�r�rcr�)�LinkOutsideDestinationErrorcr�)Nz would link to r�r�r�r�r�r8r9r��rz$LinkOutsideDestinationError.__init__r�r8r8r�r9r�r�rTcCs�i}|j}tj�|�}|�dtjf�r |j�dtj�}|d<tj�|�r*t|��tj�tj�	||��}tj�
||g�|krDt||��|j}|dur~|d@}|ru|�
�sY|��rf|d@sa|dM}|dO}n|��sn|��rqd}nt|��||jkr~||d<|r�|jdur�d|d<|jdur�d|d	<|jdur�d|d
<|jdur�d|d<|��s�|��r�tj�|j�r�t|��|��r�tj�	|tj�|�|j�}ntj�	||j�}tj�|�}tj�
||g�|kr�t||��|S)N�/r�i��@i�����r�r)r*r+r,)r�r}r%�realpathr��sep�lstrip�isabsr�r��
commonpathr�r��isreg�islnk�isdir�issymrr)r*r+r,�linknamer�dirnamer)�member�	dest_pathZfor_data�	new_attrsr�Ztarget_pathr�r8r8r9�_get_filtered_attrs�s^







��
rcCs|Sr�r8)rrr8r8r9�fully_trusted_filter0r�rcCs,t||d�}|r|jdi|�ddi��S|S)NF�deepr8�rr��rrrr8r8r9�
tar_filter3�rcCs,t||d�}|r|jdi|�ddi��S|S)NTrFr8rrr8r8r9�data_filter9rr)Z
fully_trustedr�r�s([0-9]{1,20}) c@s*eZdZ	ed{idd�dd�dd�dd�d	d
�dd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d$�d&d$��Zd|d(d)�Zed*d+��Zejd,d+��Zed-d.��Z	e	jd/d.��Z	d0d1�Z
eeeeeeeed2ed3�
d4d5�Zd6d7�Z
eed8fd9d:�Zd;d<�Zd=d>�Zd?d@�ZedAdB��ZdCdD�ZedEdF��ZedGdH��ZedIdJ��ZedKdL��ZedMdN��ZedOdP��ZdQdR�ZdSdT�ZdUdV�Z dWdX�Z!dYdZ�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�Z.dsdt�Z/dudv�Z0dwdx�Z1dydz�Z2d$S)}rr�zName of the archive member.r�zPermission bits.r)z6User ID of the user who originally stored this member.r*z7Group ID of the user who originally stored this member.r'zSize in bytes.r(zTime of last modification.�chksumzHeader checksum.�typez�File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.rzcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.r+z
User name.r,zGroup name.�devmajorzDevice major number.�devminorzDevice minor number.r�zThe tar header starts here.r�zThe file's data starts here.�pax_headerszMA dictionary containing key-value pairs of an associated pax extended header.r�zSparse member information.r�N�_sparse_structs�_link_targetr�cCsl	||_d|_d|_d|_d|_d|_d|_t|_d|_	d|_
d|_d|_d|_
d|_d|_d|_i|_dS)Ni�rr�)r�r�r)r*r'r(r�REGTYPEr rr+r,r!r"r�r�r�r#�r�r�r8r8r9r�rs$
zTarInfo.__init__cCr�r��r�r�r8r8r9r%��zTarInfo.pathcC�
||_dSr�r(r'r8r8r9r%��
cCr�r��rr�r8r8r9r&�r)zTarInfo.linkpathcCr*r�r,)r�rr8r8r9r&�r+cCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�ror��idr�r8r8r9�__repr__�szTarInfo.__repr__T)
r�r(r�rr)r*r+r,r�_KEEPc
Cs�	|	r	t�|�}nt�|�}||
ur||_||
ur||_||
ur#||_||
ur*||_||
ur1||_||
ur8||_||
ur?||_||
urF||_	|Sr�)
�copyZdeepcopyr�r(r�rr)r*r+r,)r�r�r(r�rr)r*r+r,rr/�resultr8r8r9r��s*
zTarInfo.replacecCs�	|jdur	d}n|jd@}|j||j|j|j|j|j|j|j|j	|j
|j|jd�
}|dt
kr?|d�d�s?|dd7<|S)N�)
r�r�r)r*r'r(rr rr+r,r!r"r r�r)r�r�r)r*r'r(rr rr+r,r!r"�DIRTYPEr�)r�r��infor8r8r9�get_info�s*

�zTarInfo.get_info�surrogateescapecCsx	|��}|��D]\}}|durtd|��q	|tkr#|�|||�S|tkr.|�|||�S|tkr8|�||�Std��)Nz%s may not be Nonezinvalid format)	r5�itemsr0r
�create_ustar_headerr�create_gnu_headerr�create_pax_header)r�rSr6r7r4r��valuer8r8r9�tobuf�s�z
TarInfo.tobufcCsp	t|d<t|d�||��tkrtd��t|d�||��tkr0|�|d||�\|d<|d<|�|t||�S)N�magicrzlinkname is too longr��prefix)	�POSIX_MAGICr2r1�LENGTH_LINKr0�LENGTH_NAME�_posix_split_name�_create_headerr
)r�r4r6r7r8r8r9r8�szTarInfo.create_ustar_headercCs�	t|d<d}t|d�||��tkr||�|dt||�7}t|d�||��tkr7||�|dt||�7}||�|t	||�S)Nr=r�rr�)
�	GNU_MAGICr2r1r@�_create_gnu_long_header�GNUTYPE_LONGLINKrA�GNUTYPE_LONGNAMErCr)r�r4r6r7rWr8r8r9r9�szTarInfo.create_gnu_headerc
	CsF	t|d<|j��}ddtfddtfddfD]2\}}}||vr qz
||�dd	�Wnty9||||<Yqwt||�|krH||||<qd
D]A\}}d}||}	t|	t	�}
|
r`t
|	�n|	}d|krpd
|dksxnd||<d}n|
r�|||<d}|r�||vr�t|	�||<qK|r�|�|t
|�}nd}||�|tdd�S)Nr=r�r%rr&)r+r+� )r,r,rHrDrE))r)rB)r*rB)r'�)r(rIFrrBr#Tr�r�)r?r#r0rAr@r1�UnicodeEncodeErrorr2�
isinstance�float�round�str�_create_pax_generic_header�XHDTYPErCr
)
r�r4r6r#r�Zhnamer5rRZ	needs_pax�valZval_is_floatZval_intrWr8r8r9r:sF
���
�zTarInfo.create_pax_headercCs	|�|td�S)Nr/)rO�XGLTYPE)�clsr#r8r8r9�create_pax_global_header=sz TarInfo.create_pax_global_headercCs~	|�d�}tdt|��D]-}d�|d|��}d�||d��}t|�||��tkr:t|�||��tkr:||fSq
td��)Nrr#zname is too long)�splitrHr2r�r1�
LENGTH_PREFIXrAr0)r�r�r6r7Z
componentsrMr>r8r8r9rBCs
��zTarInfo._posix_split_namecCs�	|�d�ttfv}|r!t|�dd�d|�}t|�dd�d|�}ntdd||�}tdd||�}|�dt�}|dur=td��t|�dd�d	||�t|�d
d�d@d|�t|�dd�d|�t|�d
d�d|�t|�dd�d|�t|�dd�d|�d|t|�dd�d	||�|�dt�t|�dd�d||�t|�dd�d||�||t|�dd�d||�g}t�	dt
d�|��}	t|	t
d��d}
|	dd�t
d|
d�|	dd�}	|	S)Nr r!rrBr"r�zTarInfo.type must not be Noner�rr�r2r)r*r'rIr(s        rr=r+rHr,r>rz%dsr�i����z%06orDi����)�get�CHRTYPE�BLKTYPErTr:r&r0r?rVr�r�r�rXrO)r4rSr6r7Zhas_device_fieldsr!r"Zfiletype�partsrWrr8r8r9rCSs<
�&zTarInfo._create_headercCs0	tt|�t�\}}|dkr|t|t7}|S)Nr)r\r2r�r3)Zpayloadrbrcr8r8r9�_create_payload}s
zTarInfo._create_payloadcCsT	|�||�t}i}d|d<||d<t|�|d<t|d<|�|t||�|�|�S)Nz
././@LongLinkr�r r'r=)r1r3r2rDrCr
r[)rSr�r r6r7r4r8r8r9rE�s�zTarInfo._create_gnu_long_headerc	Cs.	d}|��D]\}}z|�dd�Wqtyd}Ynwd}|r(|d7}|��D]I\}}|�d�}|r>|�|d�}n|�d�}t|�t|�d}d	}	}
	|tt|
��}	|	|
kr_n|	}
qR|tt|
�d
�d|d|d
7}q,i}d|d<||d<t|�|d<t|d<|�|td
d�|�	|�S)NFr/rETr�s21 hdrcharset=BINARY
r6r�rrD� �=�
z././@PaxHeaderr�r r'r=r�)
r7r1rJr2rNrOr?rCr
r[)rSr#r r6Zbinary�keywordr;Zrecords�lrLr>r4r8r8r9rO�sD�

�(�z"TarInfo._create_pax_generic_headerc	Csh	t|�dkrtd��t|�tkrtd��|�t�tkr td��t|dd��}|t|�vr2t	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�||�}|jtkr�|j�d�r�t|_|jtk�rd}g}td�D]0}	zt|||d��}
t||d|d��}Wn
ty�Yn
w|�|
|f�|d7}q�t|d�}t|dd��}
|||
f|_ |�!��r!|j�"d�|_|�r2|jt#v�r2|d|j|_|S)Nrzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�ri�r�rI�i�i�i�)$r2rsr�rt�countr3rurNrXrKr?r�r�r)r*r'r(rr rr+r,r!r"�AREGTYPEr�r3�GNUTYPE_SPARSErHr0r��boolr$r�rstrip�	GNU_TYPES)rSrWr6r7r�objr>r��structsrMr��numbytes�
isextended�origsizer8r8r9�frombuf�s^�

zTarInfo.frombufcCs:	|j�t�}|�||j|j�}|j��t|_|�|�Sr�)	r�r]r�rtr6r7r�r��_proc_member)rSr�rWror8r8r9�fromtarfile
s

zTarInfo.fromtarfilecCsR	|jttfvr
|�|�S|jtkr|�|�S|jtttfvr$|�	|�S|�
|�Sr�)r rGrF�
_proc_gnulongrk�_proc_sparserPrR�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r�r8r8r9rus




zTarInfo._proc_membercCsj	|j��|_|j}|��s|jtvr||�|j�7}||_|�	|j
|j|j�|�
�r3|j�d�|_|S�Nr)r�r�r�rr �SUPPORTED_TYPES�_blockr'r��_apply_pax_infor#r6r7rr�rm)r�r�r�r8r8r9r{,szTarInfo._proc_builtinc
Cs�	|j�|�|j��}z|�|�}Wnty%}ztt|��d�d}~ww|j|_|j	t
kr9t||j|j
�|_n|j	tkrGt||j|j
�|_|��rR|j�d�|_|Sr|)r�r]r~r'rvrrvrNr�r rGr?r6r7r�rFrr�removesuffix)r�r�rW�nextr�r8r8r9rwBs ��

zTarInfo._proc_gnulongc
	Cs�	|j\}}}|`|rT|j�t�}d}td�D]4}zt|||d��}t||d|d��}	Wn
ty;Ynw|rG|	rG|�||	f�|d7}qt|d�}|s||_	|j�
�|_|j|�|j
�|_||_
|S)Nr�rIrhi�)r$r�r]r�rHrNr0r�rlr�r�r�r~r'r�)
r�r�rprrrsrWr�rMr�rqr8r8r9rx]s.�
�
zTarInfo._proc_sparsec
Cs�	|j�|�|j��}|jtkr|j}n|j��}d}d}g}t|�|kr�||dkr�t	�
||�}s7td��z	t|�
d��}WntyKtd��w|dkrTtd��||t|�kr`td��|�d�|d}	||�d�d|	�}
|
�d�\}}}
|r�|dks�||	dkr�td��|�|||
f�|dkr�|dur�|
dkr�|j}nd	}||7}t|�|kr�||dks+|dur�d	}|D]*\}}}
|�|d	d	|j�}|tvr�|�|
||j|j�}n	|�|
d	d	|j�}|||<q�z|�|�}Wnt�y}ztt|��d�d}~wwd
|v�r|�||�n#d|v�r|�||�n|�d�d
k�r4|�d�dk�r4|�|||�|jtt fv�rg|�!||j|j�|j"|_"d|v�rg|j#}|�$��s\|jt%v�rd||�|j�7}||_"|S)NrrGr#�r]r�s
hdrcharsetsBINARYr/�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrFr')&r�r]r~r'r rRr#r0r2�_header_length_prefix_re�matchrKrI�groupr0r�rg�	partitionr�r6�_decode_pax_fieldr7�PAX_NAME_FIELDSrvrrvrN�_proc_gnusparse_01�_proc_gnusparse_00rW�_proc_gnusparse_10rPryrr�r�rr})r�r�rWr#r�r6�raw_headersr�r5Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuer_r;r�r�r�r8r8r9rzys�

��)
��
�
��

 
zTarInfo._proc_paxc	Cs�	g}g}|D];\}}}|dkr'z|�t|����Wqty&td��w|dkrBz|�t|����WqtyAtd��wqtt||��|_dS)NsGNU.sparse.offsetrGsGNU.sparse.numbytes)r�rIr=r0rK�list�zipr�)r�r�r�Zoffsetsrq�_r_r;r8r8r9r��s$���zTarInfo._proc_gnusparse_00cCsB	dd�|d�d�D�}tt|ddd�|ddd���|_dS)NcSsg|]}t|��qSr8)rI)�.0�xr8r8r9�
<listcomp>	sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>r��,r$r#)rUr�r�r�)r�r�r#r�r8r8r9r�s(zTarInfo._proc_gnusparse_01cCs�	d}g}|j�t�}|�dd�\}}t|�}t|�|dkrBd|vr+||j�t�7}|�dd�\}}|�t|��t|�|dks|j��|_t	t
|ddd�|ddd���|_dS)Nr^r#r$)r�r]r�rUrIr2r�r�r�r�r�r�)r�r�r#r�Zfieldsr�rWZnumberr8r8r9r�s�(zTarInfo._proc_gnusparse_10c	Cs�	|��D]T\}}|dkrt|d|�q|dkr!t|dt|��q|dkr.t|dt|��q|tvrY|tvrJzt||�}WntyId}Ynw|dkrS|�d�}t|||�q|��|_dS)NzGNU.sparse.namer%r�r'zGNU.sparse.realsizerr)	r7�setattrrI�
PAX_FIELDS�PAX_NUMBER_FIELDSr0rmr0r#)r�r#r6r7r_r;r8r8r9rs(�
�zTarInfo._apply_pax_infocCs0	z|�|d�WSty|�||�YSw)NrE)r=�UnicodeDecodeError)r�r;r6Zfallback_encodingZfallback_errorsr8r8r9r�3s�zTarInfo._decode_pax_fieldcCs$	t|t�\}}|r|d7}|tS)Nr#)r\r�)r�rirbrcr8r8r9r~;s
zTarInfo._blockcCs	|jtvSr�)r �
REGULAR_TYPESr�r8r8r9rD�
z
TarInfo.isregcCs
	|��Sr�)rr�r8r8r9�isfileHszTarInfo.isfilecC�	|jtkSr�)r r3r�r8r8r9rLr�z
TarInfo.isdircCr�r�)r �SYMTYPEr�r8r8r9rPr�z
TarInfo.issymcCr�r�)r �LNKTYPEr�r8r8r9rTr�z
TarInfo.islnkcCr�r�)r rXr�r8r8r9�ischrXr�z
TarInfo.ischrcCr�r�)r rYr�r8r8r9�isblk\r�z
TarInfo.isblkcCr�r�)r �FIFOTYPEr�r8r8r9�isfifo`r�zTarInfo.isfifocCs
|jduSr�)r�r�r8r8r9�issparsedr�zTarInfo.issparsecCs	|jtttfvSr�)r rXrYr�r�r8r8r9�isdevgsz
TarInfo.isdevr8)r�)3rorprq�dict�	__slots__r��propertyr%�setterr&r.r/r�r5rrr<r8r9r:�classmethodrTrB�staticmethodrCr[rErOrtrvrur{rwrxrzr�r�r�rr�r~rr�rrrr�r�r�r�r�r8r8r8r9rOs����������
�����������




�
:

)
	

2
>

y	rc@s�eZdZ	dZdZdZdZeZe	Z
dZeZ
eZdZ				dedd�Zedddefd	d
��Zedfdd��Zedgdd��Zedgdd��Zedhdd��Zddddd�Zdd�Zdd�Zdd�Zdd �Zdid!d"�Zdjdd$�d%d&�Zdkdd'�d(d)�Z dld*d+�Z!d,d-�Z"dmddd/�d0d1�Z#dnddd/�d3d4�Z$d5d6�Z%d7d8�Z&d9d:�Z'd;d<�Z(d=d>�Z)	#	dod?d@�Z*dAdB�Z+dCdD�Z,dEdF�Z-dGdH�Z.dIdJ�Z/dKdL�Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dpdUdV�Z5dWdX�Z6dldYdZ�Z7d[d\�Z8d]d^�Z9d_d`�Z:dadb�Z;dcdd�Z<dS)qrrFr#Nrzr6c
Cs�	ddddd�}||vrtd��||_|||_|s5|jdkr+tj�|�s+d|_d|_t||j�}d	|_n |durIt|d
�rIt	|j
ttf�rI|j
}t|d�rR|j|_d|_|r]tj�
|�nd|_
||_|durj||_|durq||_|durx||_|dur||_|dur�||_|	|_|
dur�|jtkr�|
|_ni|_|dur�||_|dur�||_|
|_d	|_g|_d	|_|j��|_i|_z||jd
kr�d|_ |�!�|_ |jdk�r	|j�"|j�z|j�#|�}|j�$|�Wn#t%y�|j�"|j�Ynt&�y	}zt't|��d�d}~wwq�|jdv�r3d|_|j�r6|j�(|j�)��}|j�*|�|jt+|�7_WdSWdSWdS|j�sE|j�,�d|_�)N�rbzr+b�wbZxb�rz�ar{r��!mode must be 'r', 'a', 'w' or 'x'r�r{Fr�r�Trz�r�r{r�)-r0r��_moder}r%�exists�	bltn_openr�r�rKr�rNrO�abspathr�rSr��dereference�ignore_zerosr6r7rr#�debug�
errorlevel�copybufsizer��members�_loadedr�r��inodes�firstmemberr�r�rvr�rurrrTr0r^r2r�)r�r�r�r�rSr�r�r�r6r7r#r�r�r�Zmodesr�rWr8r8r9r��s�
�


����
zTarFile.__init__cs�	|s	|s	td��|dvrp�fdd�}g}t�j|d�D]G}t��j|�}	|dur.|��}
z
|	|d|fi|��WSttfyc}z|�d|�d|���|durY|�|
�WYd}~qd}~wwd	�	|�}td
|����d|vr�|�
dd�\}
}|
pd}
|p�d
}|�jvr�t��j|�}	ntd|��|	||
|fi|��Sd|vr�|�
dd�\}
}|
p�d}
|p�d
}|
dvr�td��t||
|||�}z�||
|fi|��}Wn|���d|_
|S|dvr�j|||fi|��Std��)Nznothing to open)rz�r:*cs�j|dkS)N�taropen)�	OPEN_METH)r��rSr8r9�not_compressed!r�z$TarFile.open.<locals>.not_compressed)�keyrzz	- method z: �
z'file could not be opened successfully:
�:r#r�r��|ryzmode must be 'r' or 'w'Fr�zundiscernible mode)r0�sortedr�rhr�rrr�r�r�rUr�r�r�r�)rSr�r�r�ra�kwargsr�Z
error_msgsr��funcZ	saved_posr�Zerror_msgs_summary�filemode�streamr�r8r�r9r�s\#
��

zTarFile.opencKs&	|dvr	td��||||fi|��S)Nr�r�)r0)rSr�r�r�r�r8r8r9r�UszTarFile.taropenr�c	
Ks�	|dvr	td��zddlm}Wntytd�d�wz|||d||�}WntyC}z|dur>|dkr>td�|��d}~wwz
|j|||fi|��}Wn!tyk}z|��|dkrftd�|��d}~w|���d	|_	|S)
N�rzr{r��mode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availablerdrzr�F)
r0Zgzipr�r�rr�rr�r�r�)	rSr�r�r��
compresslevelr�r�r�r�r8r8r9�gzopen]s:
�
��
�zTarFile.gzopenc	
Ks�	|dvr	td��zddlm}Wntytd�d�w||p"|||d�}z
|j|||fi|��}Wn#ttfyP}z|��|dkrKt	d�|��d}~w|���d	|_
|S)
Nr�r�r)�BZ2Filer�)r�rzznot a bzip2 fileF)r0r�r�r�rr�r��EOFErrorr�rr�)	rSr�r�r�r�r�r�r�r�r8r8r9�bz2open~s,
�
�zTarFile.bz2openc

Ks�	|dvr	td��z
ddlm}m}Wntytd�d�w||p$|||d�}z
|j|||fi|��}Wn#|tfyR}	z|��|dkrMt	d�|	��d}	~	w|���d	|_
|S)
Nr�r�r)�LZMAFiler�r�)�presetrzznot an lzma fileF)r0r�r�r�r�rr�r�r�rr�)
rSr�r�r�r�r�r�r�r�r�r8r8r9�xzopen�s,
�
�zTarFile.xzopenr�r�r�r�)r�r�r�r�cCs�	|jrdSd|_z;|jdvr8|j�ttd�|jtd7_t|jt�\}}|dkr8|j�tt|�W|j	sC|j�
�dSdS|j	sN|j�
�ww)NTr�r$r)r�r�r�r^r3r�r�r\�
RECORDSIZEr�r�)r�rbrcr8r8r9r��s"
�
��z
TarFile.closecCs*	|�|�d��}|durtd|��|S)Nrzfilename %r not found)�
_getmemberrm�KeyError)r�r�r�r8r8r9�	getmember�s
zTarFile.getmembercCs	|��|js|��|jSr�)�_checkr��_loadr�r�r8r8r9�
getmembers�s
zTarFile.getmemberscCs	dd�|��D�S)NcSsg|]}|j�qSr8r()r�r�r8r8r9r��sz$TarFile.getnames.<locals>.<listcomp>)r�r�r8r8r9�getnames�szTarFile.getnamescCsL	|�d�|dur
|j}|dur|}tj�|�\}}|�tjd�}|�d�}|��}||_	|durA|j
s;t�|�}n
t�|�}nt�
|���}d}|j}t�|�r�|j|jf}	|j
st|jdkrt|	|jvrt||j|	krtt}
|j|	}n;t}
|	dr||j|	<n/t�|�r�t}
n't�|�r�t}
nt�|�r�t}
t�|�}nt�|�r�t}
n
t� |�r�t!}
ndS||_||_"|j#|_$|j%|_&|
tkr�|j'|_(nd|_(|j)|_*|
|_+||_,t-r�zt-�.|j$�d|_/Wn	t0y�Ynwt1�rzt1�2|j&�d|_3Wn
t0�yYnw|
tt!fv�r$t4td��r$t4td��r$t�5|j6�|_7t�8|j6�|_9|S)N�awxrr�r#r�major�minor):r�r�r}r%�
splitdriver�r
rr�r�r��lstat�stat�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�r�r&�S_ISDIRr3�S_ISFIFOr��S_ISLNKr��readlink�S_ISCHRrX�S_ISBLKrYr��st_uidr)�st_gidr*�st_sizer'�st_mtimer(r r�pwd�getpwuidr+r��grpZgetgrgidr,r�r��st_rdevr!r�r")r�r��arcnamer�Zdrvr�ZstatresrZstmd�inoder r8r8r9�
gettarinfo�s�



�





��zTarFile.gettarinfoT)r�cCs$	|��|dur|}|D]�}|rg|jdurtd�ntt�|j��td|jp*|j|jp/|jf�|�	�s;|�
�rHtdd|j|jf�ntd|j
�|jdurYtd�ntdt�|j�dd��t|j|��rpd	nd
�|r�|��r�td|j�|��r�td|j�t�q
dS)
Nz
??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02dr�rr�z-> zlink to )r�r�rlr�r�r+r)r,r*r�r�r!r"r'r(r��	localtimer�rrrrrk)r��verboser�r�r8r8r9r�Ts<


��

��zTarFile.list��filtercCsR	|�d�|dur|}|jdur$tj�|�|jkr$|�dd|�dS|�d|�|�||�}|dur>|�dd|�dS|durT||�}|durT|�dd|�dS|��rvt|d��}|�	||�Wd�dS1sowYdS|�
�r�|�	|�|r�tt�|��D]}|j
tj�||�tj�||�||d�q�dSdS|�	|�dS)	Nr�r$ztarfile: Skipped %rr#ztarfile: Unsupported type %r�tarfile: Excluded %rr�r)r�r�r}r%r��_dbgr�rr��addfilerr��listdir�addr�)r�r�r��	recursiverr��fr8r8r9rzs>
	"�
��zTarFile.addcCs�	|�d�t�|�}|�|j|j|j�}|j�|�|jt	|�7_|j
}|durXt||j|j|d�t
|jt�\}}|dkrO|j�tt|�|d7}|j|t7_|j�|�dS)Nr�)rarr#)r�r0r<rSr6r7r�r^r�r2r�r[r'r\r�r3r�r�)r�r�r�rWrarbrcr8r8r9r�s

zTarFile.addfilecCsh|dur|j}|dur
tSt|t�rtd��|St|�r|Szt|WSty3td|�d��d�w)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z
 not found)	�extraction_filterrrKrN�	TypeError�callable�_NAMED_FILTERSr�r0)r�rr8r8r9�_get_filter_function�s 
�
�zTarFile._get_filter_function�.)�
numeric_ownerrcCs�	g}|�|�}|dur|}|D]#}|�|||�}|durq|��r'|�|�|j|||��|d�q|jdd�dd�|D]7}tj�||j	�}	z|j
||	|d�|�||	�|�||	�Wq?t
yv}
z|�|
�WYd}
~
q?d}
~
wwdS)N��	set_attrsrcSs|jSr�r()r�r8r8r9�<lambda>�sz$TarFile.extractall.<locals>.<lambda>T)r��reverse)r)r�_get_extract_tarinforr��_extract_one�sortr}r%r�r��chown�utime�chmodr
�_handle_nonfatal_error)r�r%r�rrZdirectories�filter_functionrr��dirpathr�r8r8r9�
extractall�s4

����zTarFile.extractallr�cCs:	|�|�}|�|||�}|dur|�||||�dSdSr�)rrr)r�rr%rrrrr�r8r8r9�extract	s
�zTarFile.extractc
Cs�	t|t�r|�|�}n|}|}z|||�}Wn/ttfy0}z|�|�WYd}~nd}~wtyF}z|�|�WYd}~nd}~ww|durV|�dd|j	�dS|�
�rht�|�}tj
�||j�|_|S)Nr$r)rKrNr�r�r��_handle_fatal_errorr
rrr�rr0r}r%r�rr%)r�rrr%r�Z
unfilteredr�r8r8r9r	s*
���
zTarFile._get_extract_tarinfoc
Cs�	|�d�z|j|tj�||j�||d�WdSty0}z|�|�WYd}~dSd}~wtyG}z|�	|�WYd}~dSd}~ww)Nrzr)
r��_extract_memberr}r%r�r�r�r!r
r)r�r�r%rrr�r8r8r9r/	s
����zTarFile._extract_onecCs"	|jdkr�|�dd|�dS)Nr#�tarfile: %s)r�r�r�r�r8r8r9r<	s
zTarFile._handle_nonfatal_errorcCsr	|jdkr�t|t�r*|jdur|�dd|j�dS|�dd|j|jf�dS|�ddt|�j|f�dS)Nrr#r#ztarfile: %s %rztarfile: %s %s)r�rKr��filenamer�strerrorr ror$r8r8r9r!C	s


zTarFile._handle_fatal_errorcCs|	|�d�t|t�r|�|�}n|}|��s|jtvr"|�||�S|��s*|�	�r<t|j
t�r4td��|�
|�|��SdS)Nrzz'cannot extract (sym)link as file object)r�rKrNr�rr r}�
fileobjectrrr�r�r	�extractfile�_find_link_target)r�rr�r8r8r9r(O	s

zTarFile.extractfilecCsX	|�d�}|�dtj�}tj�|�}|r tj�|�s t�|�|��s(|�	�r5|�
dd|j|jf�n|�
d|j�|�
�rG|�||�nF|��rR|�||�n;|��r]|�||�n0|��se|��rl|�||�n!|��st|�	�r{|�||�n|jtvr�|�||�n|�||�|r�|�|||�|�	�s�|�||�|�||�dSdSdS)Nrr#z%s -> %s)rmr�r}r
r%rr��makedirsrrrr�rr�makefiler�makedirr��makefifor�r��makedev�makelinkr r}�makeunknownrrr)r�r��
targetpathrrZ	upperdirsr8r8r9r"o	s:


�zTarFile._extract_membercCsD	z|jdurt�|�WdSt�|d�WdSty!YdSw)Ni�)r�r}�mkdir�FileExistsError�r�r�r1r8r8r9r,�	s
�zTarFile.makedircCs�	|j}|�|j�|j}t|d��?}|jdur8|jD]\}}|�|�t|||t|�q|�|j�|�	�nt|||jt|�Wd�dSWd�dS1sTwYdS)Nr�)
r�r�r�r�r�r�r[rr'�truncate)r�r�r1�sourcera�targetr�r'r8r8r9r+�	s


�"�zTarFile.makefilecCs$	|�||�|�dd|j�dS)Nr#z9tarfile: Unknown file type %r, extracted as regular file.)r+rr r4r8r8r9r0�	s

�zTarFile.makeunknowncCs"	ttd�r
t�|�dStd��)N�mkfifozfifo not supported by system)r�r}r8r
r4r8r8r9r-�	s
zTarFile.makefifocCsl	ttd�rttd�std��|j}|durd}|��r"|tjO}n|tjO}t�||t�	|j
|j��dS)N�mknodr.z'special devices not supported by systemr)r�r}r
r�r�r��S_IFBLK�S_IFCHRr9r.r!r")r�r�r1r�r8r8r9r.�	s
�zTarFile.makedevcCs�	z6|��rtj�|�rt�|�t�|j|�WdStj�|j�r,t�	|j|�WdS|�
|�|�|�WdStyXz
|�
|�|�|�WYdSt
yWtd�d�ww)Nz%unable to resolve link inside archive)rr}r%�lexists�unlink�symlinkrr�r%�linkr"r)�symlink_exceptionr�r
r4r8r8r9r/�	s(

��
��zTarFile.makelinkc
Cs
	ttd�r�t��dkr�|j}|j}|sFztr"|jr"t�|j�d}Wn	ty,Ynwzt	r;|j
r;t	�|j
�d}Wn	tyEYnw|durLd}|durRd}z|��rfttd�rft�
|||�WdSt�|||�WdSty�}ztd�|�d}~wwdSdS)N�geteuidrr$r;�lchownzcould not change owner)r�r}rAr*r)r�r,Zgetgrnamr�r�r+�getpwnamrrBrr�r
)r�r�r1r�g�ur�r8r8r9r�	s@
��
��
���z
TarFile.chownc
CsH	|jdurdSz
t�||j�WdSty#}ztd�|�d}~ww)Nzcould not change mode)r�r}rr�r
)r�r�r1r�r8r8r9r
s

��z
TarFile.chmodc
Cs\	|j}|dur
dSttd�sdSzt�|||f�WdSty-}ztd�|�d}~ww)Nrz"could not change modification time)r(r�r}rr�r
)r�r�r1r(r�r8r8r9r$
s

��z
TarFile.utimecCs<	|�d�|jdur|j}d|_|S|j|j��kr.|j�|jd�|j�d�s.td��d}	z|j�	|�}Wn�t
yf}z!|jr\|�dd|j|f�|jt
7_WYd}~q0WYd}~n�d}~wty�}z-|jr�|�dd|j|f�|jt
7_WYd}~q0|jdkr�tt|��d�WYd}~nqd}~wty�|jdkr�td�d�Yn[ty�}z|jdkr�tt|��d�WYd}~nBd}~wty�}ztt|��d�d}~wt�y
}zzddl}t||j�r�td	|���d�|�t�y|�wd}~ww	|du�r|j�|�|Sd|_|S)
NZrar#rYTr$z0x%X: %srz
empty filezzlib error: )r�r�r�r�r�r�r]rr�rvrur�rr�rKrNrsrtrv�	Exceptionr�rKr�r�r�r�r�)r��mr�r�r�r8r8r9r�2
sv

��
��

�
������	
�zTarFile.nextc	Cs�	|��}d}|dur$z|�|�}Wntyd}Ynw|d|�}|r,tj�|�}t|�D]"}|r=|j|jkr<d}q0|rGtj�|j�}n|j}||krR|Sq0|rYt|��dS)NFT)	r��indexr0r}r%�normpath�reversedr�r�)	r�r�r��	normalizer�ZskippingrHr�member_namer8r8r9r�q
s4���zTarFile._getmembercCs"		|��}|durnqd|_dSr�)r�r�r�r8r8r9r��
s�
z
TarFile._loadcCs@	|jrtd|jj��|dur|j|vrtd|j��dSdS)Nz%s is closedzbad operation for mode %r)r�r�r�ror�)r�r�r8r8r9r��
s�zTarFile._checkcCsb	|��rd�tdtj�|j�|jf��}d}n|j}|}|j||dd�}|dur/t	d|��|S)NrT)r�rKzlinkname %r not found)
rr�rr}r%rr�rr�r�)r�r�r�limitrr8r8r9r)�
s zTarFile._find_link_targetccs��	|jr
|jEdHdSd}|jdur|��}|d7}|V	|t|j�kr-|j|}n|js<|��}|s;d|_dSndS|d7}|Vq )Nrr#T)r�r�r�r�r2)r�rHr�r8r8r9�__iter__�
s.�
��zTarFile.__iter__cCs"	||jkrt|tjd�dSdS)N��file)r�rkri�stderr)r��level�msgr8r8r9r�
s
�zTarFile._dbgcCs|��|Sr�)r�r�r8r8r9�	__enter__�
szTarFile.__enter__cCs.|dur
|��dS|js|j��d|_dSr�)r�r�r�r�)r�r r;�	tracebackr8r8r9�__exit__�
s


zTarFile.__exit__)
NrzNNNNNNr6NNNN)rzN)rzNr�)rzNN)NNN�Tr�r�)rN)r�T)TFr�)=rorprqr�r�r�r�rrSrr6r7rr�r�r'rr�r�r�rr�r�r�r�r�r�r�r�r�r�r�rrrrr rrrr!r(r"r,r+r0r-r.r/rrrr�r�r�r�r)rNrrTrVr8r8r8r9rls�
�o] �


c&
3�-�
 
�1!

?(

	rcCsD	zt|d�r
t|d�}nt|�}|��WdSty!YdSw)Nr])r�TF)r�rr�r)r�r�r8r8r9r�
s
�rc	Cshddl}d}|j|d�}|jdddddd	�|jd
dtdd
�|jdd�}|jddddd�|jdddddd�|jdddddd�|jdd dd!d�|��}|jr]|jdur]|�d"d#�|j	dur�|j	}t
|�r�t|d$��}|��t
|��tjd%�Wd�n1s�wY|jr�t
d&�|��dSdS|�d"d'�|��dS|jdur�|j}t
|�r�t�|d(��}|j|jd)�Wd�dS1s�wYdS|�d"d'�|��dS|jdu�rRt|j�d"kr�|jd}tj}nt|j�d*kr�|j\}}n|�d"|���t
|��rGt�|d(��}|j||jd+�Wd�n	1�s%wY|j�rE|d,k�r9d-�|�}	nd.�||�}	t
|	�dSdS|�d"d'�|��dS|jdu�r�|j�d�}
tj�|
�\}}d/d/d0d0d1d1d1d1d2�}
||
v�r|d3|
|nd4}|j}t�|
|��}|D]}|�|��q�Wd�n	1�s�wY|j�r�t
d5�|
��dSdSdS)6Nrz3A simple command-line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpz--filterz<filtername>zFilter for extraction)�metavar�choicesr\T)Zrequiredz-lz--list�	<tarfile>zShow listing of a tarfile)r]r\z-ez	--extract�+)r_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 validr#z&--filter is only valid for extraction
rzrOz{!r} is a tar archive.z{!r} is not a tar archive.
r�)rr$)r%rrz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r�r�r�)r�z.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)�argparse�ArgumentParser�add_argumentrZadd_mutually_exclusive_group�
parse_argsrr �exit�testrrr�rkrirQrrSr�rr2r}�curdirZformat_helprZcreate�popr%�splitextr)rbrX�parserr��argsr_r�ZtfrhrSZtar_namer�ZextZcompressionsZtar_modeZ	tar_files�	file_namer8r8r9�main	s���
�
�
�
�
��
"�

�
���
���rn�__main__rW)l�version�
__author__�__credits__�builtinsrr�rir}r�rZr�r�rVr0�re�warningsr�r�r��AttributeError�NotImplementedErrorr@r��	NameError�__all__r3r�r�rDr?rAr@rVr&rjr�r�rXrYr3r�ZCONTTYPErGrFrkrPrRryr
rrrr}r�rnr�r�rLrIr�r�r�getfilesystemencodingr:r?rNrTrXr[rlrFrr
rrr	rrsrtrurKrvrxr��objectr�r��BufferedReaderr�r�r�r�rrrrrrrrr/�compiler�rrrrnror8r8r8r9�<module>s$���	����

sh

?�
#
_
�

?>