Mini Shell

Direktori : /usr/lib64/python3.9/__pycache__/
Upload File :
Current File : //usr/lib64/python3.9/__pycache__/tarfile.cpython-39.pyc

a

X�Zg:��@s�dZdZdZdZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZzddlZWney�dZYn0zddlZWney�dZYn0eefZzeef7ZWney�Yn0gd�ZdZd	Zd
ZdZedZd
ZdZ dZ!dZ"dZ#dZ$d
Z%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5e5Z6e$e%e&e'e*e+e,e(e)e-e.e/fZ7e$e%e,e/fZ8e-e.e/fZ9d!Z:hd"�Z;e<e<e<e=e=e=d#�Z>ej?d$k�r�d%Z@ne�A�Z@d&d'�ZBd(d)�ZCd*d+�ZDd,e6fd-d.�ZEd/d0�ZFdedfd1d2�ZGd3d4�ZHGd5d6�d6eI�ZJGd7d8�d8eJ�ZKGd9d:�d:eJ�ZLGd;d<�d<eJ�ZMGd=d>�d>eJ�ZNGd?d@�d@eJ�ZOGdAdB�dBeO�ZPGdCdD�dDeO�ZQGdEdF�dFeO�ZRGdGdH�dHeO�ZSGdIdJ�dJeO�ZTGdKdL�dL�ZUGdMdN�dN�ZVGdOdP�dPeW�ZXGdQdR�dReW�ZYGdSdT�dTe	jZ�Z[GdUdV�dVeJ�Z\GdWdX�dXe\�Z]GdYdZ�dZe\�Z^Gd[d\�d\e\�Z_Gd]d^�d^e\�Z`Gd_d`�d`e\�Zadtdadb�Zbdcdd�Zcdedf�Zddgdh�Zeecedeedi�ZfeW�Zge�hdj�ZiGdkdl�dleW�ZjGdmdn�dneW�Zkdodp�ZlekjZdqdr�Zmendsk�r�em�dS)uz,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_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>r,r&r%r+)Zatime�ctimer(r)r*r'�nt�utf-8cCs8|durtd��|�||�}|d|�|t|�tS)z8Convert a string to a null-terminated bytes object.
    Nzmetadata cannot contain None)�
ValueError�encode�len�NUL)�s�length�encoding�errors�r8�/usr/lib64/python3.9/tarfile.py�stn�sr:cCs*|�d�}|dkr|d|�}|�||�S)z8Convert a null-terminated bytes object to a string.
    r���N)�find�decode)r4r6r7�pr8r8r9�nts�s
r?cCs�|ddvrbd}tt|�d�D]}|dK}|||d7}q |ddkr�dt|�d|}n>z"t|dd�}t|��p|d	d�}Wnty�td
��Yn0|S)z/Convert a number field to a python number.
    r)��r#�rA��ascii�strict�0�invalid header)�ranger2r?�int�stripr0�InvalidHeaderError)r4�n�ir8r8r9�nti�srNrBcCs�t|�}d|kr$d|dkrDnntd|d|fd�t}n�|tkr�d|d|krrd|dkr�nnV|dkr�tdg�}ntdg�}d||}t|d�D]}|�d|d@�|dL}q�ntd	��|S)
z/Convert a python number to a number field.
    rrBr#z%0*orDrCr@rAzoverflow in number field)rI�bytesr3r�	bytearrayrH�insertr0)rL�digits�formatr4rMr8r8r9�itn�s 2
rTcCs0dtt�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.
    rCZ
148B8x356BZ
148b8x356b)�sum�struct�unpack_from)�bufZunsigned_chksumZ
signed_chksumr8r8r9�calc_chksums�s	rYc	Cs�|pd}|dkrdS|dur.t�|||�dSt||�\}}t|�D],}|�|�}t|�|krf|d��|�|�qD|dkr�|�|�}t|�|kr�|d��|�|�dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    i@rN�unexpected end of data)�shutil�copyfileobj�divmodrH�readr2�write)	�src�dstr5�	exception�bufsize�blocks�	remainder�brXr8r8r9r\�s$


r\cCs8ttjdd�}|dur(|�|d��|�}t|dd�dS)Nr6�backslashreplace� )�end)�getattr�sys�stdoutr1r=�print)r4r6r8r8r9�_safe_printsrnc@seZdZdZdS)rzBase exception.N��__name__�
__module__�__qualname__�__doc__r8r8r8r9rsrc@seZdZdZdS)r
z%General exception for extract errors.Nror8r8r8r9r
sr
c@seZdZdZdS)rz&Exception for unreadable tar archives.Nror8r8r8r9rsrc@seZdZdZdS)rz.Exception for unavailable compression methods.Nror8r8r8r9rsrc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.Nror8r8r8r9r	!sr	c@seZdZdZdS)rz!Base exception for header errors.Nror8r8r8r9r$src@seZdZdZdS)�EmptyHeaderErrorzException for empty headers.Nror8r8r8r9rt'srtc@seZdZdZdS)�TruncatedHeaderErrorz Exception for truncated headers.Nror8r8r8r9ru*sruc@seZdZdZdS)�EOFHeaderErrorz"Exception for end of file headers.Nror8r8r8r9rv-srvc@seZdZdZdS)rKzException for invalid headers.Nror8r8r8r9rK0srKc@seZdZdZdS)�SubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nror8r8r8r9rw3srwc@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�name�moder8r8r9�__init__@s��

z_LowLevelFile.__init__cCst�|j�dS�N)r}�closer��r�r8r8r9r�Isz_LowLevelFile.closecCst�|j|�Sr�)r}r^r��r�r'r8r8r9r^Lsz_LowLevelFile.readcCst�|j|�dSr�)r}r_r��r�r4r8r8r9r_Osz_LowLevelFile.writeN)rprqrrrsr�r�r^r_r8r8r8r9rx:s
	rxc@sreZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�Zdd�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|_|durt||�}d|_|dkr6t|�}|��}|p<d|_||_||_||_||_d|_	d|_
d|_�zF|dkr�zddl}Wnt
y�td	��Yn0||_|�d�|_|d
kr�|��|j|_n|��n�|dk�r6zddl}Wnt
�ytd��Yn0|d
k�r*d|_|��|_t|_n
|��|_nz|d
k�r�zddl}Wnt
�yhtd��Yn0|d
k�r�d|_|��|_|j|_n
|��|_n|dk�r�td|��Wn&|j�s�|j��d|_�Yn0dS)z$Construct a _Stream object.
        TNF�*��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�fileobjrcrX�pos�closed�zlib�ImportErrorr�crc32�crc�
_init_read_gz�errorrb�_init_write_gzr��dbuf�BZ2Decompressor�cmp�OSError�
BZ2Compressor�lzma�LZMADecompressor�	LZMAError�LZMACompressorr�)	r�r�r�r�r�rcr�r�r�r8r8r9r�]sl












z_Stream.__init__cCst|d�r|js|��dS)Nr�)r�r�r�r�r8r8r9�__del__�sz_Stream.__del__cCs�|j�d|jj|jj|jjd�|_t�dtt	�	���}|�
d|d�|j�d�rf|jdd�|_t
j�|j�|_|�
|j�d	d
�t�dS)z6Initialize for writing with gzip compression.
        �	r�<Ls�s��.gzN���z
iso-8859-1�replace)r��compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVELr�rV�packrI�time�_Stream__writer��endswithr}r%�basenamer1r3)r�Z	timestampr8r8r9r��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�r2r��compressr�r�r8r8r9r_�s

z
_Stream.writecCsN|j|7_t|j�|jkrJ|j�|jd|j��|j|jd�|_qdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rXr2rcr�r_r�r8r8r9Z__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@��W|js�|j�
�n|js�|j�
�0dS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        NTr{r�r�r�r�l��)r�r�r�rXr��flushr�r_rVr�r�r�r�r�r�r8r8r9r��s 
�z
_Stream.closecCs�|j�|jj�|_d|_|�d�dkr0td��|�d�dkrFtd��t|�d��}|�d�|d	@r�t|�d��d
t|�d��}|�	|�|d@r�|�d�}|r�|t
kr�q�q�|d@r�|�d�}|r�|t
kr�q�q�|d@r�|�d�d
S)z:Initialize for reading a gzip compressed fileobj.
        r�r$s��not a gzip filer#�zunsupported compression method��rCrB�N)r��
decompressobjr�r�r��
_Stream__readrr�ordr^r3)r��flagZxlenr4r8r8r9r��s*
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r�r�r8r8r9�tell�sz_Stream.tellrcCsX||jdkrJt||j|j�\}}t|�D]}|�|j�q,|�|�ntd��|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)r�r]rcrHr^r	)r�r�rdrerMr8r8r9�seeksz_Stream.seekcCs,|dusJ�|�|�}|jt|�7_|S)z5Return the next size number of bytes from the stream.N)�_readr�r2)r�r'rXr8r8r9r^s
z_Stream.readcCs�|jdkr|�|�St|j�}|jg}||kr�|jrB|j}d|_n|j�|j�}|sVq�z|j�	|�}Wn|j
y�td��Yn0|�|�|t|�7}q&d�
|�}||d�|_|d|�S)z+Return size bytes from the stream.
        r�r�zinvalid compressed dataN)r�r�r2r�rXr�r^rcr��
decompressrbr�append�join�r�r'�c�trXr8r8r9r�s(




z
_Stream._readcCsjt|j�}|jg}||krF|j�|j�}|s.qF|�|�|t|�7}qd�|�}||d�|_|d|�S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        r�N)r2rXr�r^rcr�r�r�r8r8r9Z__read3s


z_Stream.__readN)r)rprqrrrsr�r�r�r_r�r�r�r�r�r^r�r�r8r8r8r9r�Rs
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�|_dSr�)r�r^�	BLOCKSIZErX)r�r�r8r8r9r�Isz_StreamProxy.__init__cCs|jj|_|jSr�)r�r^rXr�r8r8r9r^Ms
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�)rX�
startswithr�r8r8r9r�Qs$z_StreamProxy.getcomptypecCs|j��dSr�)r�r�r�r8r8r9r�[sz_StreamProxy.closeN)rprqrrrsr�r^r�r�r8r8r8r9r�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|_|dur>d|fg}d|_g|_d}|j}|D]L\}}||kr||j�	d||df�|j�	d||||f�||7}||}qX||jkr�|j�	d||jdf�dS)Nrr�FT)
r��offsetr'�positionrjr�r��	map_index�mapr�)r�r�r�r'Z	blockinfoZlastposZrealposr8r8r9r�hs(


z_FileInFile.__init__cCsdSr�r8r�r8r8r9r��sz_FileInFile.flushcCsdS�NTr8r�r8r8r9�readable�sz_FileInFile.readablecCsdS)NFr8r�r8r8r9�writable�sz_FileInFile.writablecCs
|j��Sr�)r��seekabler�r8r8r9r��sz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r�r�r8r8r9r��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_ENDr0)r�r��whencer8r8r9r��s


z_FileInFile.seekc	Cs
|dur|j|j}nt||j|j�}d}|dk�r|j|j\}}}}||jkr`|krhq�nq�q6|jd7_|jt|j�kr6d|_q6t|||j�}|r�|j�||j|�|j�|�}t|�|kr�t	d��||7}n|t
|7}||8}|j|7_q,|S)z!Read data from the file.
        Nr�rr#rZ)r'r�r�r�r�r2r�r�r^rr3)	r�r'rX�data�start�stopr�r5rfr8r8r9r^�s,

z_FileInFile.readcCs&|�t|��}||dt|��<t|�Sr�)r^r2)r�rfrXr8r8r9�readinto�sz_FileInFile.readintocCs
d|_dSr�)r�r�r8r8r9r��sz_FileInFile.close)N)N)rprqrrrsr�r�r�r�r�r�r�r�r�r^r�r�r8r8r8r9r�bs

r�cseZdZ�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__�rprqrrr��
__classcell__r8r8r�r9r��sr�c@seZdZdS)�FilterErrorN)rprqrrr8r8r8r9r��sr�cseZdZ�fdd�Z�ZS)�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��sr�cseZdZ�fdd�Z�ZS)�OutsideDestinationErrorcs.||_||_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��s
�z OutsideDestinationError.__init__r�r8r8r�r9r��sr�cseZdZ�fdd�Z�ZS)�SpecialFileErrorcs||_t��|j�d��dS)Nz is a special filer�r�r�r8r9r��szSpecialFileError.__init__r�r8r8r�r9r��sr�cseZdZ�fdd�Z�ZS)�AbsoluteLinkErrorcs||_t��|j�d��dS)Nz is a link to an absolute pathr�r�r�r8r9r��szAbsoluteLinkError.__init__r�r8r8r�r9r��sr�cseZdZ�fdd�Z�ZS)�LinkOutsideDestinationErrorcs.||_||_t��|j�d|�d�d�dS)Nz would link to r�r�r�r�r�r8r9r��s
�z$LinkOutsideDestinationError.__init__r�r8r8r�r9r�srcCs�i}|j}tj�|�}|�dtjf�r@|j�dtj�}|d<tj�|�rTt|��tj�tj�	||��}tj�
||g�|kr�t||��|j}|dur�|d@}|r�|�
�s�|��r�|d@s�|dM}|dO}n|��s�|��r�d}nt|��||jkr�||d<|�r�|jdu�rd|d<|jdu�r*d|d	<|jdu�r>d|d
<|jdu�rRd|d<|���sf|���r�tj�|j��r~t|��|���r�tj�	|tj�|�|j�}ntj�	||j�}tj�|�}tj�
||g�|k�r�t||��|S)N�/r�i��@i�����r�r)r*r+r,)r�r}r%�realpathr��sep�lstrip�isabsr�r��
commonpathr�r��isreg�islnk�isdir�issymr�r)r*r+r,�linknamer��dirnamer)�member�	dest_pathZfor_data�	new_attrsr�Ztarget_pathr�r8r8r9�_get_filtered_attrs�s^




��
rcCs|Sr�r8)rrr8r8r9�fully_trusted_filter6srcCs,t||d�}|r(|jfi|�ddi��S|S)NF�deep�rr��rrrr8r8r9�
tar_filter9srcCs,t||d�}|r(|jfi|�ddi��S|S)NTrFrrr8r8r9�data_filter?sr)Z
fully_trustedr�r�s([0-9]{1,20}) c@s�eZdZdZedddddddd	d
ddd
ddddddddd�Zdidd�Zedd��Zej	dd��Zedd��Z
e
j	dd��Z
dd�Zeeeeeeeed ed!�
d"d#�Z
d$d%�Zeed&fd'd(�Zd)d*�Zd+d,�Zd-d.�Zed/d0��Zd1d2�Zed3d4��Zed5d6��Zed7d8��Zed9d:��Zed;d<��Zed=d>��Zd?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�Z3dS)jraInformational 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.
    zName of the archive member.zPermission bits.z6User ID of the user who originally stored this member.z7Group ID of the user who originally stored this member.zSize in bytes.zTime of last modification.zHeader checksum.z�File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.z
User name.zGroup name.zDevice major number.zDevice minor number.zThe tar header starts here.zThe file's data starts here.zMA dictionary containing key-value pairs of an associated pax extended header.zSparse member information.N)r�r�r)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)zXConstruct a TarInfo object. name is the optional name
           of the member.
        i�rr�N)r�r�r)r*r'r(r�REGTYPErr
r+r,rrr�r�r�r�r�r�r8r8r9r�xs"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".�r�r�r8r8r9r%�szTarInfo.pathcCs
||_dSr�r"r!r8r8r9r%�scCs|jS)z0In pax headers, "linkname" is called "linkpath".�r
r�r8r8r9r&�szTarInfo.linkpathcCs
||_dSr�r#)r�r
r8r8r9r&�scCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�rpr��idr�r8r8r9�__repr__�szTarInfo.__repr__T)
r�r(r�r
r)r*r+r,r�_KEEPc
Cs�|	rt�|�}n
t�|�}||
ur(||_||
ur6||_||
urD||_||
urR||_||
ur`||_||
urn||_||
ur|||_||
ur�||_	|S)zGReturn a deep copy of self with the given attributes replaced.
        )
�copy�deepcopyr�r(r�r
r)r*r+r,)r�r�r(r�r
r)r*r+r,rr&�resultr8r8r9r��s(
zTarInfo.replacecCs�|jdurd}n
|jd@}|j||j|j|j|j|j|j|j|j	|j
|j|jd�
}|dt
kr||d�d�s||dd7<|S)z9Return the TarInfo's attributes as a dictionary.
        N�)
r�r�r)r*r'r(rrr
r+r,rrrr�r)r�r�r)r*r'r(rrr
r+r,rr�DIRTYPEr�)r�r��infor8r8r9�get_info�s(

�zTarInfo.get_info�surrogateescapecCsz|��}|��D]\}}|durtd|��q|tkrD|�|||�S|tkrZ|�|||�S|tkrn|�||�Std��dS)z<Return a tar header as a string of 512 byte blocks.
        Nz%s may not be Nonezinvalid format)	r-�itemsr0r
�create_ustar_headerr�create_gnu_headerr�create_pax_header)r�rSr6r7r,r��valuer8r8r9�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_MAGICr2r1�LENGTH_LINKr0�LENGTH_NAME�_posix_split_name�_create_headerr
)r�r,r6r7r8r8r9r0�s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.
        r5r�r
r�)
�	GNU_MAGICr2r1r8�_create_gnu_long_header�GNUTYPE_LONGLINKr9�GNUTYPE_LONGNAMEr;r)r�r,r6r7rXr8r8r9r1�szTarInfo.create_gnu_headerc
	CsLt|d<|j��}ddtfddtfddfD]h\}}}||vr>q*z||�dd	�Wn"tyt||||<Yq*Yn0t||�|kr*||||<q*d
D]�\}}d}||}	t|	t	�}
|
r�t
|	�n|	}d|kr�d
|dks�nd||<d}n|
�r|||<d}|r�||vr�t|	�||<q�|�r4|�|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.
        r5r�r%r
r&)r+r+� )r,r,r@rDrE))r)rB)r*rB)r'�)r(rAFrrBr#Tr�r�)r7rr'r9r8r1�UnicodeEncodeErrorr2�
isinstance�float�round�str�_create_pax_generic_header�XHDTYPEr;r
)
r�r,r6rr�Zhnamer5rRZ	needs_pax�valZval_is_floatZval_intrXr8r8r9r2	s>
�

zTarInfo.create_pax_headercCs|�|td�S)zAReturn the object as a pax global header block sequence.
        r/)rG�XGLTYPE)�clsrr8r8r9�create_pax_global_headerCsz TarInfo.create_pax_global_headercCs~|�d�}tdt|��D]T}d�|d|��}d�||d��}t|�||��tkrt|�||��tkrqvqtd��||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        rr#Nzname is too long)�splitrHr2r�r1�
LENGTH_PREFIXr9r0)r�r�r6r7�
componentsrMr6r8r8r9r:Is
�zTarInfo._posix_split_namecCs�|�d�ttfv}|r@t|�dd�d|�}t|�dd�d|�}ntdd||�}tdd||�}|�dt�}|durxtd��t|�d	d�d
||�t|�dd�d@d|�t|�d
d�d|�t|�dd�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) z�Return a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        rrrrBrr�NzTarInfo.type must not be Noner�rr�r*r)r*r'rAr(s        r
r5r+r@r,r6rz%dsr�i����z%06orDi����)�get�CHRTYPE�BLKTYPErTr:r r0r7rVr�r�r�rYrO)r,rSr6r7Zhas_device_fieldsrrZfiletype�partsrXrr8r8r9r;Ys:
�&zTarInfo._create_headercCs.tt|�t�\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes
           up to the next 512 byte border.
        r)r]r2r�r3)�payloadrdrer8r8r9�_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�rr'r5)r1r3r2r<r;r
rU)rKr�rr6r7r,r8r8r9r=�s�zTarInfo._create_gnu_long_headerc	Cs0d}|��D]6\}}z|�dd�Wqty@d}YqDYq0qd}|rT|d7}|��D]�\}}|�d�}|r�|�|d�}n
|�d�}t|�t|�d}d	}	}
|tt|
��}	|	|
kr�q�|	}
q�|tt|
�d
�d|d|d
7}q\i}d|d<||d<t|�|d<t|d<|�|td
d�|�	|�S)z�Return a POSIX.1-2008 extended or global header sequence
           that contains a list of keyword, value pairs. The values
           must be strings.
        Fr/rETr�s21 hdrcharset=BINARY
r.r�rrD� �=�
z././@PaxHeaderr�rr'r5r�)
r/r1rBr2rFrOr7r;r
rU)rKrrr6�binary�keywordr3�records�lrLr>r,r8r8r9rG�s<

(�z"TarInfo._create_pax_generic_headerc	Cstt|�dkrtd��t|�tkr(td��|�t�tkr>td��t|dd��}|t|�vrbt	d��|�}t
|dd�||�|_t|dd	��|_t|d	d
��|_
t|d
d��|_t|dd��|_t|dd��|_||_|dd
�|_t
|d
d�||�|_t
|dd�||�|_t
|dd�||�|_t|dd��|_t|dd��|_t
|dd�||�}|jtk�r�|j�d��r�t|_|jtk�r6d}g}td�D]j}	z0t|||d��}
t||d|d��}Wnt�y�Y�qYn0|�|
|f�|d7}�q�t|d�}t|dd��}
|||
f|_ |�!��rN|j�"d�|_|�rp|jt#v�rp|d|j|_|S)zAConstruct a TarInfo object from a 512 byte bytes object.
        rzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�ri�r�rA�i�i�i�)$r2rtr�ru�countr3rvrNrYrKr?r�r�r)r*r'r(rrr
r+r,rr�AREGTYPEr�r+�GNUTYPE_SPARSErHr0r��boolrr�rstrip�	GNU_TYPES)rKrXr6r7r�objr6r��structsrMr��numbytes�
isextended�origsizer8r8r9�frombuf�sZ
zTarInfo.frombufcCs8|j�t�}|�||j|j�}|j��t|_|�|�S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	r�r^r�rpr6r7r�r��_proc_member)rKr�rXrkr8r8r9�fromtarfileszTarInfo.fromtarfilecCsT|jttfvr|�|�S|jtkr,|�|�S|jtttfvrF|�	|�S|�
|�SdS)zYChoose the right processing method depending on
           the type and call it.
        N)rr?r>�
_proc_gnulongrg�_proc_sparserHrJ�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r�r8r8r9rq%s



zTarInfo._proc_membercCsR|j��|_|j}|��s$|jtvr4||�|j�7}||_|�	|j
|j|j�|S)zfProcess a builtin type or an unknown type which
           will be treated as a regular file.
        )
r�r�r�r	r�SUPPORTED_TYPES�_blockr'r��_apply_pax_inforr6r7)r�r�r�r8r8r9rw2szTarInfo._proc_builtincCs�|j�|�|j��}z|�|�}Wnty<td��Yn0|j|_|jt	krdt
||j|j�|_
n|jtkr�t
||j|j�|_|S)zSProcess the blocks that hold a GNU longname
           or longlink member.
        � missing or bad subsequent header)r�r^ryr'rrrrwr�rr?r?r6r7r�r>r
)r�r�rX�nextr8r8r9rsCs

zTarInfo._proc_gnulongc
	Cs�|j\}}}|`|r�|j�t�}d}td�D]l}z0t|||d��}t||d|d��}	WntyxYq�Yn0|r�|	r�|�||	f�|d7}q,t|d�}q||_	|j�
�|_|j|�|j
�|_||_
|S)z8Process a GNU sparse header plus extra headers.
        r�rArdi�)rr�r^r�rHrNr0r�rhr�r�r�ryr'r�)
r�r�rlrnrorXr�rMr�rmr8r8r9rtYs(
zTarInfo._proc_sparsecCs�|j�|�|j��}|jtkr&|j}n
|j��}d}d}g}t|�|k�rh||dk�rht	�
||�}sptd��zt|�
d��}Wnty�td��Yn0|dkr�td��||t|�kr�td��|�d�|d}	||�d�d|	�}
|
�d�\}}}
|�r|dk�s||	dk�r$td��|�|||
f�|dk�r^|du�r^|
d	k�rZ|j}nd
}||7}q<|du�rvd
}|D]X\}}}
|�|d
d
|j�}|tv�r�|�|
||j|j�}n|�|
d
d
|j�}|||<�qzz|�|�}Wnt�y�td��Yn0d|v�r|�||�nFd
|v�r0|�||�n.|�d�dk�r^|�d�dk�r^|�|||�|jttfv�r�|� ||j|j�|j!|_!d|v�r�|j"}|�#��s�|jt$v�r�||�|j�7}||_!|S)zVProcess an extended or global header as described in
           POSIX.1-2008.
        rNrGr#�rWr�s
hdrcharsetsBINARYr/r{�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrFr')%r�r^ryr'rrJrr'r2�_header_length_prefix_re�matchrKrI�groupr0r�ri�	partitionr�r6�_decode_pax_fieldr7�PAX_NAME_FIELDSrrrrw�_proc_gnusparse_01�_proc_gnusparse_00rP�_proc_gnusparse_10rHrurzr�r�r	rx)r�r�rXrr�r6�raw_headersr�r5Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuerZr3r|r�r8r8r9rvus|





�
�
�

 
zTarInfo._proc_paxc	Cs�g}g}|D]�\}}}|dkrRz|�t|����Wq�tyNtd��Yq�0q|dkrz|�t|����Wqty�td��Yq0qtt||��|_dS)z?Process a GNU tar extended sparse header, version 0.0.
        sGNU.sparse.offsetrGsGNU.sparse.numbytesN)r�rIr=r0rK�list�zipr�)r�r|r�Zoffsetsrm�_rZr3r8r8r9r��szTarInfo._proc_gnusparse_00cCs@dd�|d�d�D�}tt|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|��qSr8)rI)�.0�xr8r8r9�
<listcomp>r�z.TarInfo._proc_gnusparse_01.<locals>.<listcomp>r�,Nr$r#)rMr�r�r�)r�r|rr�r8r8r9r�szTarInfo._proc_gnusparse_01cCs�d}g}|j�t�}|�dd�\}}t|�}t|�|dkrtd|vrT||j�t�7}|�dd�\}}|�t|��q,|j��|_t	t
|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        NrXr#r$)r�r^r�rMrIr2r�r�r�r�r�r�)r�r|rr��fieldsr�rX�numberr8r8r9r�szTarInfo._proc_gnusparse_10c	Cs�|��D]�\}}|dkr&t|d|�q|dkr@t|dt|��q|dkrZt|dt|��q|tvr|tvr�zt||�}Wnty�d}Yn0|dkr�|�d�}t|||�q|��|_dS)	zoReplace fields with supplemental information from a previous
           pax extended or global header.
        zGNU.sparse.namer%r�r'zGNU.sparse.realsizerrN)	r/�setattrrI�
PAX_FIELDS�PAX_NUMBER_FIELDSr0rir'r)r�rr6r7rZr3r8r8r9rzs"

zTarInfo._apply_pax_infocCs2z|�|d�WSty,|�||�YS0dS)z1Decode a single field from a pax record.
        rEN)r=�UnicodeDecodeError)r�r3r6Zfallback_encodingZfallback_errorsr8r8r9r�/szTarInfo._decode_pax_fieldcCs"t|t�\}}|r|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it,
           e.g. _block(834) => 1024.
        r#)r]r�)r�rerdrer8r8r9ry7szTarInfo._blockcCs
|jtvS�z4Return True if the Tarinfo object is a regular file.)r�
REGULAR_TYPESr�r8r8r9r	@sz
TarInfo.isregcCs|��Sr�)r	r�r8r8r9�isfileDszTarInfo.isfilecCs
|jtkS)z!Return True if it is a directory.)rr+r�r8r8r9rHsz
TarInfo.isdircCs
|jtkS)z%Return True if it is a symbolic link.)r�SYMTYPEr�r8r8r9rLsz
TarInfo.issymcCs
|jtkS)z!Return True if it is a hard link.)r�LNKTYPEr�r8r8r9r
Psz
TarInfo.islnkcCs
|jtkS)z(Return True if it is a character device.)rrQr�r8r8r9�ischrTsz
TarInfo.ischrcCs
|jtkS)z$Return True if it is a block device.)rrRr�r8r8r9�isblkXsz
TarInfo.isblkcCs
|jtkS)zReturn True if it is a FIFO.)r�FIFOTYPEr�r8r8r9�isfifo\szTarInfo.isfifocCs
|jduSr�)r�r�r8r8r9�issparse`szTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rrQrRr�r�r8r8r9�isdevcsz
TarInfo.isdev)r�)4rprqrrrs�dict�	__slots__r��propertyr%�setterr&r%r&r�r-rrr4r0r1r2�classmethodrLr:�staticmethodr;rUr=rGrprrrqrwrsrtrvr�r�r�rzr�ryr	r�rrr
r�r�r�r�r�r8r8r8r9rUs��




�
:

)
	

2
>

y	rc
@s�eZdZdZdZdZdZdZeZ	e
ZdZe
ZeZdZdfdd	�Zedddefd
d��Zedgdd
��Zedhdd��Zedidd��Zedjdd��Zddddd�Zdd�Zdd�Zdd�Zd d!�Zdkd"d#�Zdldd%�d&d'�Z dmdd(�d)d*�Z!dnd+d,�Z"d-d.�Z#doddd0�d1d2�Z$dpddd0�d4d5�Z%d6d7�Z&d8d9�Z'd:d;�Z(d<d=�Z)d>d?�Z*dqd@dA�Z+dBdC�Z,dDdE�Z-dFdG�Z.dHdI�Z/dJdK�Z0dLdM�Z1dNdO�Z2dPdQ�Z3dRdS�Z4dTdU�Z5drdVdW�Z6dXdY�Z7dsdZd[�Z8d\d]�Z9d^d_�Z:d`da�Z;dbdc�Z<ddde�Z=dS)trz=The TarFile Class provides an interface to tar archives.
    rFr#Nrzr.c
Cs�ddddd�}||vrtd��||_|||_|sh|jdkrTtj�|�sTd|_d|_t||j�}d	|_n@|d
ur�t|d�r�t	|j
ttf�r�|j
}t|d�r�|j|_d
|_|r�tj�
|�nd
|_
||_|d
ur�||_|d
ur�||_|d
ur�||_|d
ur�||_|d
u�r||_|	|_|
d
u�r0|jtk�r0|
|_ni|_|d
u�rF||_|d
u�rV||_|
|_d	|_g|_d	|_|j��|_i|_z�|jdk�r�d
|_ |�!�|_ |jdk�r2|j�"|j�z|j�#|�}|j�$|�WnXt%�y�|j�"|j�Y�q2Yn2t&�y,}zt't|���WYd
}~n
d
}~00�q�|jdv�r|d
|_|j�r||j�(|j�)��}|j�*|�|jt+|�7_Wn&|j�s�|j�,�d
|_�Yn0d
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�wb�xb�rz�ar{r��!mode must be 'r', 'a', 'w' or 'x'r�r{FNr�r�Trz�r�r{r�)-r0r��_moder}r%�exists�	bltn_openr�r�rCr�rFrO�abspathr�rSr��dereference�ignore_zerosr6r7rr�debug�
errorlevel�copybufsizer��members�_loadedr�r��inodes�firstmemberr|r�rrr�rvrrrLr'r_r2r�)r�r�r�r�rSr�r�r�r6r7rr�r�r�Zmodes�erXr8r8r9r��s�
�





&
zTarFile.__init__c

s�|s|std��|dvr��fdd�}t�j|d�D]l}t��j|�}|durV|��}	z||d|fi|��WSttfy�|dur�|�|	�Yq2Yq20q2td���nd	|v�r|�d	d
�\}
}|
p�d}
|p�d}|�jvr�t��j|�}ntd|��|||
|fi|��Sd
|v�r�|�d
d
�\}
}|
�p4d}
|�p>d}|
dv�rRtd��t	||
|||�}z�||
|fi|��}Wn|�
��Yn0d|_|S|dv�r��j|||fi|��Std��dS)a�Open a tar archive for reading, writing or appending. Return
           an appropriate TarFile class.

           mode:
           'r' or 'r:*' open for reading with transparent compression
           'r:'         open for reading exclusively uncompressed
           'r:gz'       open for reading with gzip compression
           'r:bz2'      open for reading with bzip2 compression
           '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)rz�r:*cs�j|dkS)N�taropen)�	OPEN_METH)r��rKr8r9�not_compressedsz$TarFile.open.<locals>.not_compressed)�keyNrzz%file could not be opened successfully�:r#r�r��|ryzmode must be 'r' or 'w'Fr�zundiscernible mode)
r0�sortedr�rjr�rrr�rMr�r�r�r�)
rKr�r�r�rc�kwargsr�r��funcZ	saved_pos�filemode�streamr�r8r�r9r�sP%







zTarFile.opencKs$|dvrtd��||||fi|��S)zCOpen uncompressed tar archive name for reading or writing.
        r�r�)r0)rKr�r�r�r�r8r8r9r�NszTarFile.taropenr�cKs�|dvrtd��zddlm}Wnty:td��Yn0z|||d||�}Wn,ty~|durx|dkrxtd	���Yn0z|j|||fi|��}Wn@ty�|��|dkr�td	���Yn|���Yn0d
|_	|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        �rzr{r��mode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availablerfNrzr�F)
r0�gzipr�r�rr�rr�r�r�)rKr�r�r��
compresslevelr�r�r�r8r8r9�gzopenVs0zTarFile.gzopenc	Ks�|dvrtd��zddlm}Wnty:td��Yn0||pD|||d�}z|j|||fi|��}WnDttfy�|��|dkr�t	d���Yn|���Yn0d	|_
|S)
zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        r�r�r)�BZ2Filer�)r�rzznot a bzip2 fileF)r0r�r�r�rr�r��EOFErrorr�rr�)rKr�r�r�r�r�r�r�r8r8r9�bz2openws&zTarFile.bz2openc		Ks�|dvrtd��zddlm}m}Wnty>td��Yn0||pH|||d�}z|j|||fi|��}WnD|tfy�|��|dkr�t	d���Yn|���Yn0d	|_
|S)
zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        r�r�r)�LZMAFiler�r�)�presetrzznot an lzma fileF)r0r�r�r�r�rr�r�r�rr�)	rKr�r�r�r�r�r�r�r�r8r8r9�xzopen�s&zTarFile.xzopenr�r�r�r�)r�r�r�r�cCs�|jr
dSd|_zp|jdvrn|j�ttd�|jtd7_t|jt�\}}|dkrn|j�tt|�W|j	s�|j�
�n|j	s�|j�
�0dS)zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NTr�r$r)r�r�r�r_r3r�r�r]�
RECORDSIZEr�r�)r�rdrer8r8r9r��s
�z
TarFile.closecCs(|�|�d��}|dur$td|��|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.
        rNzfilename %r not found)�
_getmemberri�KeyError)r�r�r�r8r8r9�	getmember�szTarFile.getmembercCs|��|js|��|jS)z�Return the members of the archive as a list of TarInfo objects. The
           list has the same order as the members in the archive.
        )�_checkr��_loadr�r�r8r8r9�
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�qSr8r")r�r�r8r8r9r��r�z$TarFile.getnames.<locals>.<listcomp>)r�r�r8r8r9�getnames�szTarFile.getnamescCsZ|�d�|dur|j}|dur$|}tj�|�\}}|�tjd�}|�d�}|��}||_	|dur�|j
stt�|�}q�t�|�}nt�
|���}d}|j}t�|�r�|j|jf}	|j
s�|jdkr�|	|jvr�||j|	kr�t}
|j|	}nt}
|	dr�||j|	<nht�|��rt}
nVt�|��r"t}
nDt�|��r>t}
t�|�}n(t�|��rPt}
nt� |��rbt!}
ndS||_||_"|j#|_$|j%|_&|
tk�r�|j'|_(nd|_(|j)|_*|
|_+||_,t-�r�zt-�.|j$�d|_/Wnt0�y�Yn0t1�rzt1�2|j&�d|_3Wnt0�yYn0|
tt!fv�rVt4td��rVt4td��rVt�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.
        �awxNrr�r#r�major�minor):r�r�r}r%�
splitdriver�rrr�r�r��lstat�stat�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�r�r �S_ISDIRr+�S_ISFIFOr��S_ISLNKr��readlink�S_ISCHRrQ�S_ISBLKrRr��st_uidr)�st_gidr*�st_sizer'�st_mtimer(rr
�pwd�getpwuidr+r��grp�getgrgidr,r�r��st_rdevrr�r)r�r��arcnamer��drvr�Zstatresr
Zstmd�inoderr8r8r9�
gettarinfo�s�	


��

zTarFile.gettarinfoT)r�cCs*|��|dur|}|D�]
}|r�|jdur6td�ntt�|j��td|jpT|j|jp^|jf�|�	�sv|�
�r�tdd|j|jf�ntd|j
�|jdur�td�ntdt�|j�dd	��t|j|��r�d
nd�|�r|���rtd|j�|���rtd
|j�t�qdS)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
??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02dr�rr�z-> zlink to )r�r�rnr�r�r+r)r,r*r�r�rrr'r(r��	localtimer�rrr
r
rm)r��verboser�r�r8r8r9r�Ms8



��

�

zTarFile.list��filtercCsL|�d�|dur|}|jdurFtj�|�|jkrF|�dd|�dS|�d|�|�||�}|durz|�dd|�dS|dur�||�}|dur�|�dd|�dS|��r�t|d��}|�	||�Wd�n1s�0Ynb|�
��r>|�	|�|�rHtt�|��D],}|j
tj�||�tj�||�||d	��qn
|�	|�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 %r�tarfile: Excluded %rr�r)r�r�r}r%r��_dbgr�r	r��addfilerr��listdir�addr�)r�r�r��	recursiverr��fr8r8r9rss6

,

�zTarFile.addcCs�|�d�t�|�}|�|j|j|j�}|j�|�|jt	|�7_|j
}|dur�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)rcrr#)r�r'r4rSr6r7r�r_r�r2r�r\r'r]r�r3r�r�)r�r�r�rXrcrdrer8r8r9r�s

zTarFile.addfilecCsT|du�r|j}|dur�tj�d�}|dur�ztt�}WntyJYnV0ddl}|jddd�}|�|�	|�Wd�n1s�0Y|jdddd�}|r�zt
|}Wn$ty�td|�d	��d�Yn0||_|St
r�t�d
t�tStSt|t��rtd��|St|��r|Sz
t
|WSt�yNtd|�d	��d�Yn0dS)NZ PYTHON_TARFILE_EXTRACTION_FILTERr)�#)Z
interpolationZcomment_prefixesr�r�)�fallbackzfilter z
 not foundaThe 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.zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)�extraction_filterr}�environrPr��_CONFIG_FILENAME�FileNotFoundError�configparser�ConfigParserZ	read_file�_NAMED_FILTERSr�r0�_RH_SAFER_DEFAULT�warnings�warn�RuntimeWarningrrrCrF�	TypeError�callable)r�rr��filerZconfr8r8r9�_get_filter_function�sZ
�(��	�

zTarFile._get_filter_function�.)�
numeric_ownerrcCs�g}|�|�}|dur|}|D]F}|�|||�}|dur:q|��rL|�|�|j|||��|d�q|jdd�dd�|D]p}tj�||j	�}	z,|j
||	|d�|�||	�|�||	�Wq|t
y�}
z|�|
�WYd}
~
q|d}
~
00q|dS)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.

           The `filter` function will be called on each member just
           before extraction.
           It can return a changed TarInfo or None to skip the member.
           String names of common filters are accepted.
        N��	set_attrsrcSs|jSr�r")r�r8r8r9�<lambda>	r�z$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�s,

�zTarFile.extractallr�cCs4|�|�}|�|||�}|dur0|�||||�dS)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.

           The `filter` function will be called before extraction.
           It can return a changed TarInfo or None to skip the member.
           String names of common filters are accepted.
        N)rr"r#)r�rr%rrrr)r�r8r8r9�extract!	s
zTarFile.extractc
Cs�t|t�r|�|�}n|}|}z|||�}Wn^ttfy^}z|�|�WYd}~n6d}~0ty�}z|�|�WYd}~n
d}~00|dur�|�dd|j	�dS|�
�r�t�|�}tj
�||j�|_|S)z@Get filtered TarInfo (or None) from member, which might be a strNr$r)rCrFr�r�r��_handle_fatal_errorr
r(rr�r
r'r}r%r�r
r)r�rr)r%r�Z
unfilteredr�r8r8r9r"4	s"
 
zTarFile._get_extract_tarinfoc
Cs�|�d�z"|j|tj�||j�||d�WnZtyZ}z|�|�WYd}~n6d}~0ty�}z|�	|�WYd}~n
d}~00dS)z%Extract from filtered tarinfo to diskrzrN)
r��_extract_memberr}r%r�r�r�r-r
r()r�r�r%rrr�r8r8r9r#K	s
�
zTarFile._extract_onecCs"|jdkr�n|�dd|�dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#�tarfile: %sN)r�r�r�r�r8r8r9r(X	s
zTarFile._handle_nonfatal_errorcCsn|jdkr�n\t|t�rP|jdur6|�dd|j�qj|�dd|j|jf�n|�ddt|�j|f�dS)z1Handle "fatal" error according to self.errorlevelrNr#r/ztarfile: %s %rztarfile: %s %s)r�rCr��filenamer�strerrorrrpr0r8r8r9r-_	s


zTarFile._handle_fatal_errorcCs�|�d�t|t�r |�|�}n|}|��s6|jtvrB|�||�S|��sR|�	�rzt|j
t�rhtd��q~|�
|�|��SndSdS)a\Extract a member from the archive as a file object. `member' may be
           a filename or a TarInfo object. If `member' is a regular file or
           a link, an io.BufferedReader object is returned. For all other
           existing members, None is returned. If `member' does not appear
           in the archive, KeyError is raised.
        rzz'cannot extract (sym)link as file objectN)r�rCrFr�r	rrx�
fileobjectr
rr�r�r	�extractfile�_find_link_target)r�rr�r8r8r9r4k	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&|jtv�r|�||�n|�||�|�rP|�|||�|�	��sP|�||�|�||�dS)z\Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        rr#z%s -> %sN)rir�r}rr%rr��makedirsr
rrr�r
r	�makefiler�makedirr��makefifor�r��makedev�makelinkrrx�makeunknownr%r'r&)r�r��
targetpathrrZ	upperdirsr8r8r9r.�	s4


zTarFile._extract_membercCs>z&|jdurt�|�nt�|d�Wnty8Yn0dS)z,Make a directory called targetpath.
        Ni�)r�r}�mkdir�FileExistsError�r�r�r=r8r8r9r8�	s
zTarFile.makedircCs�|j}|�|j�|j}t|d��l}|jdurn|jD]"\}}|�|�t|||t|�q4|�|j�|�	�nt|||jt|�Wd�n1s�0YdS)z'Make a file called targetpath.
        r�N)
r�r�r�r�r�r�r\rr'�truncate)r�r�r=�sourcerc�targetr�r'r8r8r9r7�	s


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)r7rrr@r8r8r9r<�	s�zTarFile.makeunknowncCs"ttd�rt�|�ntd��dS)z'Make a fifo called targetpath.
        �mkfifozfifo not supported by systemN)r�r}rDr
r@r8r8r9r9�	s
zTarFile.makefifocCsjttd�rttd�std��|j}|dur.d}|��rB|tjO}n
|tjO}t�||t�	|j
|j��dS)z<Make a character or block device called targetpath.
        �mknodr:z'special devices not supported by systemNr)r�r}r
r�r�r��S_IFBLK�S_IFCHRrEr:rr)r�r�r=r�r8r8r9r:�	s
�zTarFile.makedevcCs�zb|��r0tj�|�r t�|�t�|j|�n0tj�|j�rNt�	|j|�n|�
|�|�|�WnDty�z|�
|�|�|�Wnt
y�td��Yn0Yn0dS)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)rr}r%�lexists�unlink�symlinkr
r�r�linkr.r5�symlink_exceptionr�r
r@r8r8r9r;�	s"
��zTarFile.makelinkcCs�ttd�r�t��dkr�|j}|j}|s�ztrB|jrBt�|j�d}WntyVYn0zt	rt|j
rtt	�|j
�d}Wnty�Yn0|dur�d}|dur�d}z4|��r�ttd�r�t�
|||�nt�|||�Wnty�td��Yn0dS)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$Nr;�lchownzcould not change owner)r�r}rMr*r)r�r,�getgrnamr�r�r+�getpwnamrrNr%r�r
)r�r�r=r�g�ur8r8r9r%
s0

z
TarFile.chowncCs@|jdurdSzt�||j�Wnty:td��Yn0dS)zASet file permissions of targetpath according to tarinfo.
        Nzcould not change mode)r�r}r'r�r
r@r8r8r9r'6
s
z
TarFile.chmodcCsT|j}|durdSttd�s dSzt�|||f�WntyNtd��Yn0dS)zBSet modification time of targetpath according to tarinfo.
        Nr&z"could not change modification time)r(r�r}r&r�r
)r�r�r=r(r8r8r9r&@
s
z
TarFile.utimecCsl|�d�|jdur$|j}d|_|S|j|j��krZ|j�|jd�|j�d�sZtd��d}z|j�	|�}W�qJt
y�}zD|jr�|�dd|j|f�|jt
7_WYd}~q^WYd}~�qJd}~0t�yD}z`|j�r|�dd|j|f�|jt
7_WYd}~q^n|jdk�r.tt|���WYd}~�qJd}~0t�yj|jdk�rftd��Yn�t�y�}z$|jdk�r�tt|���WYd}~n�d}~0t�y�}ztt|���WYd}~nvd}~0t�yB}zTz.ddl}t||j��rtd	|����n|�Wnt�y,|�Yn0WYd}~n
d}~00�qJq^|du�rb|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#rZr$z0x%X: %srz
empty filezzlib error: T)r�r�r�r�r�r�r^rr�rrrvr�rr�rKrFrtrurw�	Exceptionr�rCr�r�r�r�r�)r��mr�r�r�r8r8r9r|N
sZ

""   
zTarFile.nextc	Cs�|��}d}|durFz|�|�}Wnty8d}Yn0|d|�}|rVtj�|�}t|�D]D}|rx|j|jkr^d}q^|r�tj�|j�}n|j}||kr^|Sq^|r�t|��dS)z}Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        FNT)	r��indexr0r}r%�normpath�reversedr�r�)	r�r�r��	normalizer�ZskippingrUr�member_namer8r8r9r��
s,

zTarFile._getmembercCs|��}|durqqd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r|r�r�r8r8r9r��
sz
TarFile._loadcCs:|jrtd|jj��|dur6|j|vr6td|j��dS)znCheck if TarFile is still open, and if the operation's mode
           corresponds to TarFile's mode.
        z%s is closedNzbad operation for mode %r)r�r�r�rpr�)r�r�r8r8r9r��
szTarFile._checkcCs`|��r.d�tdtj�|j�|jf��}d}n
|j}|}|j||dd�}|dur\t	d|��|S)zZFind the target member of a symlink or hardlink member in the
           archive.
        rNT)r�rXzlinkname %r not found)
rr�rr}r%rr�r
r�r�)r�r�r
�limitrr8r8r9r5�
s zTarFile._find_link_targetccs�|jr|jEdHdSd}|jdur:|��}|d7}|V|t|j�krT|j|}n"|jsr|��}|svd|_dSndS|d7}|Vq:dS)z$Provide an iterator object.
        Nrr#T)r�r�r�r|r2)r�rUr�r8r8r9�__iter__�
s$
zTarFile.__iter__cCs||jkrt|tjd�dS)z.Write debugging output to sys.stderr.
        �rN)r�rmrk�stderr)r��level�msgr8r8r9r�
s
zTarFile._dbgcCs|��|Sr�)r�r�r8r8r9�	__enter__szTarFile.__enter__cCs,|dur|��n|js"|j��d|_dSr�)r�r�r�r�)r�rr3�	tracebackr8r8r9�__exit__s


zTarFile.__exit__)
NrzNNNNNNr.NNNN)rzN)rzNr�)rzNr�)rzNN)NNN)T)NT)N)rN)r�T)TF)NF)N)>rprqrrrsr�r�r�r�rrSrr6r7rr�r�r3r
r�r�r�rr�r�r�r�r�r�r�r�r�r�r�rrrr+r,r"r#r(r-r4r.r8r7r<r9r:r;r%r'r&r|r�r�r�r5r[rr`rbr8r8r8r9rhs��
oZ �


c&3
5�-�
 �
1!
?
(

	rcCsFz,t|d�rt|d�}nt|�}|��WdSty@YdS0dS)z�Return True if name points to a tar archive that we
       are able to handle, else return False.

       'name' should be a string, file, or file-like object.
    r^)r�TFN)r�rr�r)r�r�r8r8r9rs
rc	Cs`ddl}d}|j|d�}|jdddddd	�|jd
dtdd
�|jdd�}|jddddd�|jdddddd�|jdddddd�|jdd dd!d�|��}|jr�|jdur�|�d"d#�|j	du�rJ|j	}t
|��r4t|d$��*}|��t
|��tjd%�Wd�n1�s0Y|j�rFt
d&�|��n|�d"d'�|���n|jdu�r�|j}t
|��r�t�|d(��}|j|jd)�Wd�n1�s�0Yn|�d"d'�|���n�|jdu�r�t|j�d"k�r�|jd}tj}n,t|j�d*k�r|j\}}n|�d"|���t
|��r�t�|d(�� }|j||jd+�Wd�n1�sR0Y|j�r�|d,k�rzd-�|�}	nd.�||�}	t
|	�n|�d"d'�|��n�|jdu�r\|j�d�}
tj�|
�\}}d/d/d0d0d1d1d1d1d2�}
||
v�r�d3|
|nd4}|j}t�|
|��&}|D]}|�|��qWd�n1�s<0Y|j�r\t
d5�|
��dS)6Nrz3A simple command-line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpz--filterz<filtername>zFilter for extraction)�metavar�choicesrgT)�requiredz-lz--list�	<tarfile>zShow listing of a tarfile)rhrgz-ez	--extract�+)rkz<output_dir>zExtract tarfile into target dir)�nargsrhrgz-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction
rzr\z{!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_argumentr�add_mutually_exclusive_group�
parse_argsrr,�exit�testrrr�rmrkr]rrSr�rr2r}�curdir�format_helpr+Zcreate�popr%�splitextr)rnrc�parserr��argsr`r�Ztfrur_Ztar_namer��extZcompressionsZtar_modeZ	tar_files�	file_namer8r8r9�main%s���
�
�
�
�
2
0

0
�
�
.r}�__main__)T)ors�version�
__author__�__credits__�builtinsrr�rkr}r�r[r�r�rVr'�rerr�r�r��AttributeError�NotImplementedErrorrLr��	NameError�__all__rrr3r�r�r<r7r9r8rNr rfr�r�rQrRr+r�ZCONTTYPEr?r>rgrHrJrur
rrrrxr�rjr�r�rDrIr�r�r�getfilesystemencodingr:r?rNrTrYr\rnrSrr
rrr	rrtrurvrKrwrxr��objectr�r��BufferedReaderr�r�r�r�r�r�rrrrrrr&�compiler�rrrr}rpr8r8r8r9�<module>s

����
sh

?�
3_


Zerion Mini Shell 1.0