a X�Zg:�� @s�dZdZdZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZz ddlZWney�dZYn0z ddlZWney�dZYn0eefZzeef7ZWney�Yn0gd�ZdZdZd Zd Zed Zd Zd ZdZ dZ!dZ"dZ#d Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4e4Z5e#e$e%e&e)e*e+e'e(e,e-e.f Z6e#e$e+e.fZ7e,e-e.fZ8d Z9hd!�Z:e;e;e;ed#k�r�d$Z?ne�@�Z?d%d&�ZAd'd(�ZBd)d*�ZCd+e5fd,d-�ZDd.d/�ZEdedfd0d1�ZFd2d3�ZGGd4d5�d5eH�ZIGd6d7�d7eI�ZJGd8d9�d9eI�ZKGd:d;�d;eI�ZLGdd?�d?eI�ZNGd@dA�dAeN�ZOGdBdC�dCeN�ZPGdDdE�dEeN�ZQGdFdG�dGeN�ZRGdHdI�dIeN�ZSGdJdK�dK�ZTGdLdM�dM�ZUGdNdO�dOeV�ZWGdPdQ�dQeV�ZXGdRdS�dSejY�ZZGdTdU�dUeI�Z[GdVdW�dWe[�Z\GdXdY�dYe[�Z]GdZd[�d[e[�Z^Gd\d]�d]e[�Z_Gd^d_�d_e[�Z`dsd`da�Zadbdc�Zbddde�Zcdfdg�Zdebeceddh�ZeeV�Zfe�gdi�ZhGdjdk�dkeV�ZiGdldm�dmeV�Zjdndo�ZkejjZdpdq�Zlemdrk�r�el�dS)tz0.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)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)Nr�����)�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) Nr)���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) NrrBr#z%0*orDrCr@rAzoverflow in number field)rI�bytesr3r� bytearrayrH�insertr0)rL�digits�formatr4rMr8r8r9�itn�s  2    rTcCs0dtt�d|��}dtt�d|��}||fS)NrCZ 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)Ni@r�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@s eZdZdS)rN��__name__� __module__� __qualname__r8r8r8r9rsrc@s eZdZdS)r Nror8r8r8r9r sr c@s eZdZdS)rNror8r8r8r9rsrc@s eZdZdS)rNror8r8r8r9rsrc@s eZdZdS)r Nror8r8r8r9r !sr c@s eZdZdS)r Nror8r8r8r9r $sr c@s eZdZdS)�EmptyHeaderErrorNror8r8r8r9rs'srsc@s eZdZdS)�TruncatedHeaderErrorNror8r8r8r9rt*srtc@s eZdZdS)�EOFHeaderErrorNror8r8r8r9ru-sruc@s eZdZdS)rKNror8r8r8r9rK0srKc@s eZdZdS)�SubsequentHeaderErrorNror8r8r8r9rv3srvc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) � _LowLevelFilecCsFtjtjtjBtjBd�|}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)rprqrrr�r�r^r_r8r8r8r9rw:s rwc@sneZdZdd�Zdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z ddd�Z dd�Z dd�Z dd�ZdS)�_Streamc Cs�d|_|durt||�}d|_|dkr6t|�}|��}|pd|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|jSr�)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)NrzInvalid 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)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)rprqrrr�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)� FilterErrorNror8r8r8r9r��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��sr�cCs�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�Z target_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�eZdZeddddddddd d d d d dddddddd�Zdhdd�Zedd��Zejdd��Zedd��Z e jdd��Z dd�Z e e e e e e e e de d � d!d"�Z d#d$�Z eed%fd&d'�Zd(d)�Zd*d+�Zd,d-�Zed.d/��Zd0d1�Zed2d3��Zed4d5��Zed6d7��Zed8d9��Zed:d;��Zedd?�Zd@dA�ZdBdC�Z dDdE�Z!dFdG�Z"dHdI�Z#dJdK�Z$dLdM�Z%dNdO�Z&dPdQ�Z'dRdS�Z(dTdU�Z)dVdW�Z*dXdY�Z+dZd[�Z,d\d]�Z-d^d_�Z.d`da�Z/dbdc�Z0ddde�Z1dfdg�Z2dS)irzName 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.z Group 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)Ni�rr�)r�r�r)r*r'r(r�REGTYPErr r+r,rrr�r�r�r�r�r�r8r8r9r�xs"zTarInfo.__init__cCs|jSr��r�r�r8r8r9r%�sz TarInfo.pathcCs ||_dSr�r!r r8r8r9r%�scCs|jSr��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�|| _ | Sr�) �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)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)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)N�magicr zlinkname is too longr��prefix) � POSIX_MAGICr2r1� LENGTH_LINKr0� LENGTH_NAME�_posix_split_name�_create_headerr )r�r+r6r7r8r8r9r/�s zTarInfo.create_ustar_headercCs�t|d<d}t|d�||��tkr<||�|dt||�7}t|d�||��tkrl||�|dt||�7}||�|t ||�S)Nr4r�r r�) � GNU_MAGICr2r1r7�_create_gnu_long_header�GNUTYPE_LONGLINKr8�GNUTYPE_LONGNAMEr:r)r�r+r6r7rXr8r8r9r0�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)Nr4r�r%r r&)r+r+� )r,r,r?rDrE))r)rB)r*rB)r'� )r(r@FrrBr#Tr�r�)r6rr&r8r7r1�UnicodeEncodeErrorr2� isinstance�float�round�str�_create_pax_generic_header�XHDTYPEr:r ) r�r+r6rr�Zhnamer5rRZ needs_pax�valZ val_is_floatZval_intrXr8r8r9r1 s> �      zTarInfo.create_pax_headercCs|�|td�S)Nr/)rF�XGLTYPE)�clsrr8r8r9�create_pax_global_headerCsz TarInfo.create_pax_global_headercCs~|�d�}tdt|��D]T}d�|d|��}d�||d��}t|�||��tkrt|�||��tkrqvqtd��||fS)Nrr#zname is too long)�splitrHr2r�r1� LENGTH_PREFIXr8r0)r�r�r6r7� componentsrMr5r8r8r9r9Is �zTarInfo._posix_split_namec Cs�|�d�ttfv}|r@t|�dd�d|�}t|�dd�d|�}ntdd||�}tdd||�}|�dt�}|durxtd��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)NrrrrBrr�zTarInfo.type must not be Noner�rr�r)r)r*r'r@r(s r r4r+r?r,r5rz%dsr�i����z%06orDi����)�get�CHRTYPE�BLKTYPErTr:rr0r6rVr�r�r�rYrO) r+rSr6r7Zhas_device_fieldsrrZfiletype�partsrXrr8r8r9r:Ys:  �&zTarInfo._create_headercCs.tt|�t�\}}|dkr*|t|t7}|S)Nr)r]r2r�r3)�payloadrdrer8r8r9�_create_payload�szTarInfo._create_payloadcCsR|�||�t}i}d|d<||d<t|�|d<t|d<|�|t||�|�|�S)Nz ././@LongLinkr�rr'r4)r1r3r2r;r:r rT)rJr�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)NFr/rETr�s21 hdrcharset=BINARY r-r�rrD� �=� z././@PaxHeaderr�rr'r4r�) r.r1rAr2rErOr6r:r rT) rJrrr6�binary�keywordr2�records�lrLr>r+r8r8r9rF�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|d d ��|_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)Nrz empty headerztruncated headerzend of file header��z bad checksumr�l�t�|��ii i)iIiQiYi�ri�r�r@�i�i�i�)$r2rsr�rt�countr3rurNrYrKr?r�r�r)r*r'r(rrr r+r,rr�AREGTYPEr�r*�GNUTYPE_SPARSErHr0r��boolrr �rstrip� GNU_TYPES)rJrXr6r7r�objr5r��structsrMr��numbytes� isextended�origsizer8r8r9�frombuf�sZ         zTarInfo.frombufcCs8|j�t�}|�||j|j�}|j��t|_|�|�Sr�) r�r^r�ror6r7r�r�� _proc_member)rJr�rXrjr8r8r9� fromtarfiles zTarInfo.fromtarfilecCsT|jttfvr|�|�S|jtkr,|�|�S|jtttfvrF|� |�S|� |�SdSr�) rr>r=� _proc_gnulongrf� _proc_sparserGrI�SOLARIS_XHDTYPE� _proc_pax� _proc_builtin)r�r�r8r8r9rp%s    zTarInfo._proc_membercCsR|j��|_|j}|��s$|jtvr4||�|j�7}||_|� |j |j |j �|Sr�) r�r�r�rr�SUPPORTED_TYPES�_blockr'r��_apply_pax_inforr6r7)r�r�r�r8r8r9rv2s zTarInfo._proc_builtincCs�|j�|�|j��}z|�|�}Wnty<td��Yn0|j|_|jt krdt ||j |j �|_ n|jtkr�t ||j |j �|_|S)N� missing or bad subsequent header)r�r^rxr'rqr rvr�rr>r?r6r7r�r=r )r�r�rX�nextr8r8r9rrCs   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)Nr�r@rci�)rr�r^r�rHrNr0r�rgr�r�r�rxr'r�) r�r�rkrmrnrXr�rMr�rlr8r8r9rsYs(       zTarInfo._proc_sparsecCs�|j�|�|j��}|jtkr&|j}n |j��}d}d}g}t|�|k�rh||dk�rht � ||�}spt d��zt |� d��}Wnty�t d��Yn0|dkr�t d��||t|�kr�t d��|�d�|d} ||�d�d| �} | �d�\} } } | �r| dk�s|| dk�r$t d��|�|| | f�| dk�r^|du�r^| dk�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)NrrGr#�rVr�s hdrcharsetsBINARYr/rz�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrFr')%r�r^rxr'rrIrr&r2�_header_length_prefix_re�matchrKrI�groupr0r�ri� partitionr�r6�_decode_pax_fieldr7�PAX_NAME_FIELDSrqr rv�_proc_gnusparse_01�_proc_gnusparse_00rO�_proc_gnusparse_10rGrtryr�r�rrw)r�r�rXrr�r6� raw_headersr�r5Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuerYr2r{r�r8r8r9ruus|        �  � �     zTarInfo._proc_paxc Cs�g}g}|D]�\}}}|dkrRz|�t|����Wq�tyNtd��Yq�0q |dkr z|�t|����Wq ty�td��Yq 0q tt||��|_dS)NsGNU.sparse.offsetrGsGNU.sparse.numbytes)r�rIr=r0rK�list�zipr�)r�r{r�Zoffsetsrl�_rYr2r8r8r9r��s  zTarInfo._proc_gnusparse_00cCs@dd�|d�d�D�}tt|ddd�|ddd���|_dS)NcSsg|] }t|��qSr8)rI)�.0�xr8r8r9� r�z.TarInfo._proc_gnusparse_01..r~�,r$r#)rLr�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)NrWr#r$) r�r^r�rLrIr2r�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)NzGNU.sparse.namer%rr'zGNU.sparse.realsizerr) r.�setattrrI� PAX_FIELDS�PAX_NUMBER_FIELDSr0rhr&r)r�rr6r7rYr2r8r8r9rys"   zTarInfo._apply_pax_infocCs2z|�|d�WSty,|�||�YS0dS)NrE)r=�UnicodeDecodeError)r�r2r6Zfallback_encodingZfallback_errorsr8r8r9r�/s zTarInfo._decode_pax_fieldcCs"t|t�\}}|r|d7}|tS)Nr#)r]r�)r�rdrdrer8r8r9rx7szTarInfo._blockcCs |jtvSr�)r� REGULAR_TYPESr�r8r8r9r@sz TarInfo.isregcCs|��Sr�)rr�r8r8r9�isfileDszTarInfo.isfilecCs |jtkSr�)rr*r�r8r8r9r Hsz TarInfo.isdircCs |jtkSr�)r�SYMTYPEr�r8r8r9r Lsz TarInfo.issymcCs |jtkSr�)r�LNKTYPEr�r8r8r9r Psz TarInfo.islnkcCs |jtkSr�)rrPr�r8r8r9�ischrTsz TarInfo.ischrcCs |jtkSr�)rrQr�r8r8r9�isblkXsz TarInfo.isblkcCs |jtkSr�)r�FIFOTYPEr�r8r8r9�isfifo\szTarInfo.isfifocCs |jduSr�)r�r�r8r8r9�issparse`szTarInfo.issparsecCs|jtttfvSr�)rrPrQr�r�r8r8r9�isdevcsz TarInfo.isdev)r�)3rprqrr�dict� __slots__r��propertyr%�setterr&r$r%r�r,rr r3r/r0r1� classmethodrKr9� staticmethodr:rTr<rFrorqrprvrrrsrur�r�r�ryr�rxrr�r r r r�r�r�r�r�r8r8r8r9rUs��     �  :  )   2 >  y rc @s�eZdZdZdZdZdZeZe Z dZ e Z eZdZdedd�Zedddefd d ��Zedfd d ��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�Zd }| d v�rRtd��t || |||�} z�|| | fi|��} Wn| � ��Yn0d| _ | S|dv�r��j |||fi|��Std��dS)Nznothing to open)ry�r:*cs�j|dkS)N�taropen)� OPEN_METH)r��rJr8r9�not_compressedsz$TarFile.open..not_compressed)�keyryz%file could not be opened successfully�:r#r�r��|rxzmode must be 'r' or 'w'Fr�zundiscernible mode) r0�sortedr�rjr�rrr�rLr�r�r�r�) rJr�r�r�rc�kwargsr�r��funcZ saved_pos�filemode�streamr�r8r�r9r�sP%            z TarFile.opencKs$|dvrtd��||||fi|��S)Nr�r�)r0)rJr�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) N�ryrzr��mode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availablerfryr�F) r0�gzipr�r�rr�rr�r�r�)rJr�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) Nr�r�r)�BZ2Filer�)r�ryznot a bzip2 fileF) r0r�r�r�rr�r��EOFErrorr�rr�)rJr�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) Nr�r�r)�LZMAFiler�r�)�presetryznot an lzma fileF) r0r�r�r�r�rr�r�r�rr�) rJr�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)NTr�r$r) r�r�r�r_r3r�r�r]� RECORDSIZEr�r�)r�rdrer8r8r9r��s  �z TarFile.closecCs(|�|�d��}|dur$td|��|S)Nrzfilename %r not found)� _getmemberrh�KeyError)r�r�r�r8r8r9� getmember�s zTarFile.getmembercCs|��|js|��|jSr�)�_checkr��_loadr�r�r8r8r9� getmembers�szTarFile.getmemberscCsdd�|��D�S)NcSsg|] }|j�qSr8r!)r�r�r8r8r9r��r�z$TarFile.getnames..)r�r�r8r8r9�getnames�szTarFile.getnamesc CsZ|�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)N�awxrr�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_ISCHRrP�S_ISBLKrQr��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) 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�r r 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>|� |�|�rHt t� |��D],}|j tj�||�tj�||�||d��qn |� |�dS) Nr�r$ztarfile: Skipped %rr#ztarfile: Unsupported type %r�tarfile: Excluded %rr�r)r�r�r|r%r��_dbgr�rr��addfiler r��listdir�addr�)r�r�r�� recursiverr��fr8r8r9rss6    ,  � z TarFile.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)Nr�)rcrr#)r�r&r3rSr6r7r�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$t y�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|�environrOr��_CONFIG_FILENAME�FileNotFoundError� configparser� ConfigParserZ read_file�_NAMED_FILTERSr�r0�_RH_SAFER_DEFAULT�warnings�warn�RuntimeWarningrrrBrE� TypeError�callable)r�rr��filerZconfr8r8r9�_get_filter_function�sZ    �(�  �  �  zTarFile._get_filter_function�.)� numeric_ownerrc Cs�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)N�� set_attrsrcSs|jSr�r!)r�r8r8r9� r�z$TarFile.extractall..T)r��reverse)r)r�_get_extract_tarinfor r�� _extract_one�sortr|r%r�r��chown�utime�chmodr �_handle_nonfatal_error) r�r%r�rrZ directories�filter_functionrr��dirpathr�r8r8r9� extractall�s,  � zTarFile.extractallr�cCs4|�|�}|�|||�}|dur0|�||||�dSr�)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)Nr$r)rBrEr�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)Nryr) r��_extract_memberr|r%r�r�r�r+r r&)r�r�r%rrr�r8r8r9r!K s � zTarFile._extract_onecCs"|jdkr�n|�dd|�dS)Nr#� tarfile: %s)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)Nrr#r-ztarfile: %s %rztarfile: %s %s)r�rBr��filenamer�strerrorrrpr.r8r8r9r+_ s   zTarFile._handle_fatal_errorcCs�|�d�t|t�r |�|�}n|}|��s6|jtvrB|�||�S|��sR|� �rzt|j t �rht d��q~|� |�|��SndSdS)Nryz'cannot extract (sym)link as file object)r�rBrEr�rrrw� fileobjectr r r�r�r � extractfile�_find_link_target)r�rr�r8r8r9r2k 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)Nrr#z%s -> %s)rhr�r|rr%r r��makedirsr r rr�r r�makefiler �makedirr��makefifor�r��makedev�makelinkrrw� makeunknownr#r%r$)r�r�� targetpathrrZ upperdirsr8r8r9r,� s4       zTarFile._extract_membercCs>z&|jdurt�|�n t�|d�Wnty8Yn0dS)Ni�)r�r|�mkdir�FileExistsError�r�r�r;r8r8r9r6� s    zTarFile.makedircCs�|j}|�|j�|j}t|d��l}|jdurn|jD]"\}}|�|�t|||t|�q4|�|j�|� �nt|||jt|�Wd�n1s�0YdS)Nr�) r�r�r�r�r�r�r\rr'�truncate)r�r�r;�sourcerc�targetr�r'r8r8r9r5� s      zTarFile.makefilecCs"|�||�|�dd|j�dS)Nr#z9tarfile: Unknown file type %r, extracted as regular file.)r5rrr>r8r8r9r:� s �zTarFile.makeunknowncCs"ttd�rt�|�ntd��dS)N�mkfifozfifo not supported by system)r�r|rBr r>r8r8r9r7� s  zTarFile.makefifocCsjttd�rttd�std��|j}|dur.d}|��rB|tjO}n |tjO}t�||t� |j |j ��dS)N�mknodr8z'special devices not supported by systemr) r�r|r r�r�r��S_IFBLK�S_IFCHRrCr8rr)r�r�r;r�r8r8r9r8� s  �zTarFile.makedevc Cs�zb|��r0tj�|�r t�|�t�|j|�n0tj�|j�rNt� |j|�n|� |� |�|�WnDt y�z|� |� |�|�Wnt y�td��Yn0Yn0dS)Nz%unable to resolve link inside archive)r r|r%�lexists�unlink�symlinkr r�r�linkr,r3�symlink_exceptionr�r r>r8r8r9r9� 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)N�geteuidrr$r;�lchownzcould not change owner)r�r|rKr*r)r�r,�getgrnamr�r�r+�getpwnamr rLr#r�r )r�r�r;r�g�ur8r8r9r# s0     z TarFile.chowncCs@|jdurdSzt�||j�Wnty:td��Yn0dS)Nzcould not change mode)r�r|r%r�r r>r8r8r9r%6 s   z TarFile.chmodcCsT|j}|durdSttd�s dSzt�|||f�WntyNtd��Yn0dS)Nr$z"could not change modification time)r(r�r|r$r�r )r�r�r;r(r8r8r9r$@ s  z TarFile.utimec Csl|�d�|jdur$|j}d|_|S|j|j��krZ|j�|jd�|j�d�sZtd��d}z|j� |�}W�qJt y�}zD|j r�|� 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) NZrar#rZr$z0x%X: %srz empty filez zlib error: T)r�r�r�r�r�r�r^rr�rqrur�rr�rKrErsrtrv� Exceptionr�rBr�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)NFT) r��indexr0r|r%�normpath�reversedr�r�) r�r�r�� normalizer�ZskippingrSr� member_namer8r8r9r�� s,       zTarFile._getmembercCs|��}|durqqd|_dSr�)r{r�r�r8r8r9r�� sz TarFile._loadcCs:|jrtd|jj��|dur6|j|vr6td|j��dS)Nz %s is closedzbad 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)NrT)r�rVzlinkname %r not found) r r�rr|r%r r�r r�r�)r�r�r �limitrr8r8r9r3� s  zTarFile._find_link_targetccs�|jr|jEdHdSd}|jdur:|��}|d7}|V|t|j�krT|j|}n"|jsr|��}|svd|_dSndS|d7}|Vq:dS)Nrr#T)r�r�r�r{r2)r�rSr�r8r8r9�__iter__� s$   zTarFile.__iter__cCs||jkrt|tjd�dS)N�r)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�rr2� tracebackr8r8r9�__exit__ s   zTarFile.__exit__) NryNNNNNNr-NNNN)ryN)ryNr�)ryNr�)ryNN)NNN)T)NT)N)rN)r�T)TF)NF)N)=rprqrrr�r�r�r�rrSr r6r7rr�r�r1r r�r�r�rr�r�r�r�r�r�r�r�r�r�r�rrrr)r*r r!r&r+r2r,r6r5r:r7r8r9r#r%r$r{r�r�r�r3rYrr^r`r8r8r8r9rhs�� oZ    �    c&3 5� -�    � 1! ? ( rcCsFz,t|d�rt|d�}nt|�}|��WdSty@YdS0dS)Nr^)r�TF)r�rr�r)r�r�r8r8r9r s   rc Cs`ddl}d}|j|d�}|jdddddd �|jd d td 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 zFilter for extraction)�metavar�choicesreT)�requiredz-lz--list� zShow listing of a tarfile)rfrez-ez --extract�+)riz zExtract tarfile into target dir)�nargsrfrez-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction ryrZz{!r} is a tar archive.z{!r} is not a tar archive. r�)r�r$)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:rzz{!r} file created.)�argparse�ArgumentParser� add_argumentr�add_mutually_exclusive_group� parse_argsrr*�exit�testrrr�rmrkr[r�rSr�rr2r|�curdir� format_helpr)Zcreate�popr%�splitextr)rlra�parserr��argsr`r�Ztfrsr]Ztar_namer��extZ compressionsZtar_modeZ tar_files� file_namer8r8r9�main% s�  ��  � � � �    2  0    0  �   � .r{�__main__)T)n�version� __author__� __credits__�builtinsrr�rkr|r�r[r�r�rVr&�rerr�r�r��AttributeError�NotImplementedErrorrJr�� NameError�__all__rr r3r�r�r;r6r8r7rMrrer�r�rPrQr*r�ZCONTTYPEr>r=rfrGrIrtr rrrrwr�rir�r�rCrIr�r�r �getfilesystemencodingr:r?rNrTrYr\rnrQrr rrr r rsrtrurKrvrwr��objectr�r��BufferedReaderr�r�r�r�r�r�r�rrrrrr%�compiler�rrrr{rpr8r8r8r9� s        ����  sh  ?�  3_