Sh3ll
OdayForums


Server : Apache
System : Linux server1.cgrithy.com 3.10.0-1160.95.1.el7.x86_64 #1 SMP Mon Jul 24 13:59:37 UTC 2023 x86_64
User : nobody ( 99)
PHP Version : 8.1.23
Disable Function : NONE
Directory :  /opt/alt/python38/lib64/python3.8/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/alt/python38/lib64/python3.8/__pycache__/tarfile.cpython-38.opt-2.pyc
U

��,a�n�@sfdZdZdZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZzddlZWnek
r�dZYnXzddlZWnek
r�dZYnXeefZzeef7ZWnek
r�YnXdddd	d
ddd
dddddddgZdZdZedZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.dZ/d*Z0d+Z1e1Z2e e!e"e#e&e'e(e$e%e)e*e+fZ3e e!e(e+fZ4e)e*e+fZ5d,Z6d-d.d/d0hZ7e8e8e8e9e9e9d1�Z:ej;d2k�r�d3Z<ne�=�Z<d4d5�Z>d6d7�Z?d8d9�Z@d:e2fd;d<�ZAd=d>�ZBdedfd?d@�ZCdAdB�ZDGdCd	�d	eE�ZFGdDd
�d
eF�ZGGdEd
�d
eF�ZHGdFd�deF�ZIGdGd�deF�ZJGdHd�deF�ZKGdIdJ�dJeK�ZLGdKdL�dLeK�ZMGdMdN�dNeK�ZNGdOdP�dPeK�ZOGdQdR�dReK�ZPGdSdT�dT�ZQGdUdV�dV�ZRGdWdX�dXeS�ZTGdYdZ�dZeS�ZUGd[d\�d\ejV�ZWGd]d�deS�ZXGd^d�deS�ZYd_d�ZZeYjZd`da�Z[e\dbk�rbe[�dS)cz0.9.0u"Lars Gustäbel (lars@gustaebel.de)u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.�)�openN�TarFile�TarInfo�
is_tarfile�TarError�	ReadError�CompressionError�StreamError�ExtractError�HeaderError�ENCODING�USTAR_FORMAT�
GNU_FORMAT�
PAX_FORMAT�DEFAULT_FORMATr�i�sustar  sustar00�d��0�1�2�3�4�5�6�7�L�K�S�x�g�X��)�path�linkpath�size�mtime�uid�gid�uname�gnamer%r&r+r,)Zatime�ctimer(r)r*r'�nt�utf-8cCs(|�||�}|d|�|t|�tS�N)�encode�len�NUL)�s�length�encoding�errors�r8�,/opt/alt/python38/lib64/python3.8/tarfile.py�stn�sr:cCs*|�d�}|dkr|d|�}|�||�S)Nr���)�find�decode)r4r6r7�pr8r8r9�nts�s
r?cCs�|ddkrbd}tt|�d�D]}|dK}|||d7}q |ddkr�dt|�d|}n@z"t|dd�}t|��p|d	d�}Wntk
r�td
��YnX|S)Nr)��r#�rA��ascii�strict�0�invalid header)�ranger2r?�int�strip�
ValueError�InvalidHeaderError)r4�n�ir8r8r9�nti�srOrBcCs�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�insertrK)rM�digits�formatr4rNr8r8r9�itn�s 2
rUcCs0dtt�d|��}dtt�d|��}||fS)NrCZ
148B8x356BZ
148b8x356b)�sum�structZunpack_from)�bufZunsigned_chksumZ
signed_chksumr8r8r9�calc_chksums�s	rYc	Cs�|pd}|dkrdS|dkr.t�|||�dSt||�\}}t|�D],}|�|�}t|�|krf|d��|�|�qD|dkr�|�|�}t|�|kr�|d��|�|�dS)Ni@r�unexpected end of data)�shutil�copyfileobj�divmodrH�readr2�write)	�srcZdstr5�	exception�bufsize�blocks�	remainder�brXr8r8r9r\�s$


r\cCs8ttjdd�}|dk	r(|�|d��|�}t|dd�dS)Nr6�backslashreplace� )�end)�getattr�sys�stdoutr1r=�print)r4r6r8r8r9�_safe_printsrmc@seZdZdS)rN��__name__�
__module__�__qualname__r8r8r8r9r
sc@seZdZdS)r
Nrnr8r8r8r9r

sc@seZdZdS)rNrnr8r8r8r9rsc@seZdZdS)rNrnr8r8r8r9rsc@seZdZdS)r	Nrnr8r8r8r9r	sc@seZdZdS)rNrnr8r8r8r9rsc@seZdZdS)�EmptyHeaderErrorNrnr8r8r8r9rrsrrc@seZdZdS)�TruncatedHeaderErrorNrnr8r8r8r9rssrsc@seZdZdS)�EOFHeaderErrorNrnr8r8r8r9rt"srtc@seZdZdS)rLNrnr8r8r8r9rL%srLc@seZdZdS)�SubsequentHeaderErrorNrnr8r8r8r9ru(sruc@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�hasattrrzr�fd)�self�name�moder8r8r9�__init__5s��

z_LowLevelFile.__init__cCst�|j�dSr0)r{�closer��r�r8r8r9r�>sz_LowLevelFile.closecCst�|j|�Sr0)r{r^r��r�r'r8r8r9r^Asz_LowLevelFile.readcCst�|j|�dSr0)r{r_r��r�r4r8r8r9r_Dsz_LowLevelFile.writeN)rorprqr�r�r^r_r8r8r8r9rv/s	rvc@sneZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�ZdS)�_Streamc	Cs�d|_|dkrt||�}d|_|dkr6t|�}|��}|p<d|_||_||_||_||_d|_	d|_
d|_�zL|dkr�zddl}Wnt
k
r�td��YnX||_|�d�|_|d	kr�|��|j|_n|��n�|d
k�r:zddl}Wnt
k
�r
td��YnX|d	k�r.d|_|��|_t|_n
|��|_n||dk�r�zddl}Wnt
k
�rntd
��YnX|d	k�r�d|_|��|_|j|_n
|��|_n|dk�r�td|��Wn&|j�s�|j��d|_�YnXdS)NTF�*��r�gzzzlib module is not availablerx�bz2�bz2 module is not available�xz�lzma module is not available�tar�unknown compression type %r) �_extfileobjrv�_StreamProxy�getcomptyper�r��comptype�fileobjrbrX�pos�closed�zlib�ImportErrorr�crc32�crc�
_init_read_gz�errorra�_init_write_gzr��dbufZBZ2Decompressor�cmp�OSErrorZ
BZ2Compressor�lzmaZLZMADecompressor�	LZMAErrorZLZMACompressorr�)	r�r�r�r�r�rbr�r�r�r8r8r9r�Rsl












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�dd	�t�dS)
N�	r�<Ls�s��.gz���z
iso-8859-1�replace)r�ZcompressobjZDEFLATED�	MAX_WBITSZ
DEF_MEM_LEVELr�rW�packrI�time�_Stream__writer��endswithr{r%�basenamer1r3)r�Z	timestampr8r8r9r��s�z_Stream._init_write_gzcCsR|jdkr|j�||j�|_|jt|�7_|jdkrD|j�|�}|�|�dS)Nr�r�)	r�r�r�r�r�r2r��compressr�r�r8r8r9r_�s

z
_Stream.writecCsN|j|7_t|j�|jkrJ|j�|jd|j��|j|jd�|_qdSr0)rXr2rbr�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|j
d@��W5|js�|j��XdS)NTryr�r�r�r�l��)r�r�r�r�r�r�rXr��flushr_rWr�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�dS)
Nr�r$s��not a gzip filer#�zunsupported compression method��rCrB�)r�Z
decompressobjr�r�r��
_Stream__readrr�ordr^r3)r��flagZxlenr4r8r8r9r��s*
 


z_Stream._init_read_gzcCs|jSr0)r�r�r8r8r9�tell�sz_Stream.tellrcCsX||jdkrJt||j|j�\}}t|�D]}|�|j�q,|�|�ntd��|jS)Nrz seeking backwards is not allowed)r�r]rbrHr^r	)r�r�rcrdrNr8r8r9�seek�sz_Stream.seekcCs |�|�}|jt|�7_|Sr0)�_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
k
r�td��YnX|�|�|t|�7}q&d�
|�}||d�|_|d|�S)Nr�r�zinvalid compressed data)r�r�r2r�rXr�r^rbr��
decompressrar�append�join�r�r'�c�trXr8r8r9r�
s(




z
_Stream._readcCsjt|j�}|jg}||krF|j�|j�}|s.qF|�|�|t|�7}qd�|�}||d�|_|d|�S)Nr�)r2rXr�r^rbr�r�r�r8r8r9Z__read(s


z_Stream.__readN)r)rorprqr�r�r�r_r�r�r�r�r�r^r�r�r8r8r8r9r�GsF
	

r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
r�cCs||_|j�t�|_dSr0)r�r^�	BLOCKSIZErX)r�r�r8r8r9r�>sz_StreamProxy.__init__cCs|jj|_|jSr0)r�r^rXr�r8r8r9r^Bs
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�Fs$z_StreamProxy.getcomptypecCs|j��dSr0)r�r�r�r8r8r9r�Psz_StreamProxy.closeN)rorprqr�r^r�r�r8r8r8r9r�9s
r�c@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Ze	j
fdd�Zddd�Zdd�Z
dd�ZdS)�_FileInFileNcCs�||_||_||_d|_t|dd�|_d|_|dkr>d|fg}d|_g|_d}|j}|D]L\}}||kr||j�	d||df�|j�	d||||f�||7}||}qX||jkr�|j�	d||jdf�dS)Nrr�FT)
r��offsetr'�positionrir�r��	map_index�mapr�)r�r�r�r'Z	blockinfoZlastposZrealposr8r8r9r�]s(


z_FileInFile.__init__cCsdSr0r8r�r8r8r9r�vsz_FileInFile.flushcCsdS�NTr8r�r8r8r9�readableysz_FileInFile.readablecCsdS)NFr8r�r8r8r9�writable|sz_FileInFile.writablecCs
|j��Sr0)r��seekabler�r8r8r9r�sz_FileInFile.seekablecCs|jSr0)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_ENDrK)r�r��whencer8r8r9r��s


z_FileInFile.seekc	Cs
|dkr|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�r5rer8r8r9r^�s,

z_FileInFile.readcCs&|�t|��}||dt|��<t|�Sr0)r^r2)r�rerXr8r8r9�readinto�sz_FileInFile.readintocCs
d|_dSr�)r�r�r8r8r9r��sz_FileInFile.close)N)N)rorprqr�r�r�r�r�r�r�r�r�r^r�r�r8r8r8r9r�Ws

r�cseZdZ�fdd�Z�ZS)�ExFileObjectcs&t|j|j|j|j�}t��|�dSr0)r�r��offset_datar'�sparse�superr�)r��tarfile�tarinfor���	__class__r8r9r��s

�zExFileObject.__init__)rorprqr��
__classcell__r8r8r�r9r��sr�c@s�eZdZeddddddddd	d
ddd
dddddddd�Zdddd�Zedd��Zejdd��Zedd��Z	e	jdd��Z	dd�Z
dd �Zee
d!fd"d#�Zd$d%�Zd&d'�Zd(d)�Zed*d+��Zd,d-�Zed.d/��Zed0d1��Zed2d3��Zed4d5��Zed6d7��Zed8d9��Zd:d;�Zd<d=�Zd>d?�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�Z0dS)erzName 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�type�linknamer+r,�devmajor�devminorr�r��pax_headersr�r��_sparse_structs�_link_targetr�cCsj||_d|_d|_d|_d|_d|_d|_t|_d|_	d|_
d|_d|_d|_
d|_d|_d|_i|_dS)Ni�rr�)r�r�r)r*r'r(r��REGTYPEr�r�r+r,r�r�r�r�r�r��r�r�r8r8r9r��s"zTarInfo.__init__cCs|jSr0�r�r�r8r8r9r%szTarInfo.pathcCs
||_dSr0r�r�r8r8r9r%
scCs|jSr0�r�r�r8r8r9r&szTarInfo.linkpathcCs
||_dSr0r�)r�r�r8r8r9r&scCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�ror��idr�r8r8r9�__repr__szTarInfo.__repr__cCsl|j|jd@|j|j|j|j|j|j|j|j	|j
|j|jd�
}|dt
krh|d�d�sh|dd7<|S)N�)
r�r�r)r*r'r(r�r�r�r+r,r�r�r�r��/)r�r�r)r*r'r(r�r�r�r+r,r�r��DIRTYPEr�)r��infor8r8r9�get_infos"�zTarInfo.get_info�surrogateescapecCsT|��}|tkr|�|||�S|tkr4|�|||�S|tkrH|�||�Std��dS)Nzinvalid format)r�r
�create_ustar_headerr�create_gnu_headerr�create_pax_headerrK)r�rTr6r7r�r8r8r9�tobuf2s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_LINKrK�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)Nrr�r�r�)
�	GNU_MAGICr2r1r�_create_gnu_long_header�GNUTYPE_LONGLINKr�GNUTYPE_LONGNAMErr)r�r�r6r7rXr8r8r9r�MszTarInfo.create_gnu_headerc
	Cs*t|d<|j��}ddtfddtfddfD]j\}}}||kr>q*z||�dd	�Wn$tk
rv||||<Yq*YnXt||�|kr*||||<q*d
D]`\}}||kr�d||<q�||}d|kr�d|d
kr�nn
t|t	�r�t
|�||<d||<q�|�r|�|t|�}	nd}	|	|�
|tdd�S)Nrr�r%r�r&)r+r+� )r,r,rrDrE))r)rB)r*rB)r'�)r(rrrBr#r�r�)rr��copyrrr1�UnicodeEncodeErrorr2�
isinstance�float�str�_create_pax_generic_header�XHDTYPErr
)
r�r�r6r�r�Zhnamer5rS�valrXr8r8r9r�[s8
�
*
zTarInfo.create_pax_headercCs|�|td�S)Nr/)r�XGLTYPE)�clsr�r8r8r9�create_pax_global_header�sz TarInfo.create_pax_global_headercCs~|�d�}tdt|��D]T}d�|d|��}d�||d��}t|�||��tkrt|�||��tkrqvqtd��||fS)Nr�r#zname is too long)�splitrHr2r�r1�
LENGTH_PREFIXrrK)r�r�r6r7Z
componentsrNrr8r8r9r�s
�zTarInfo._posix_split_namecCsVt|�dd�d||�t|�dd�d@d|�t|�dd�d|�t|�d	d�d|�t|�d
d�d|�t|�dd�d|�d
|�dt�t|�dd�d||�|�dt�t|�dd�d||�t|�dd�d||�t|�dd�d|�t|�dd�d|�t|�dd�d||�g}t�dtd�|��}t	|td��d}|dd�t
d|d�|dd�}|S)Nr�r�rr�rr�rBr)r*r'rr(s        r�r�rr+rr,r�r�rrz%dsr�i����z%06orDi����)r:�getrUr�rrWr�r�r�rYrP)r�rTr6r7�partsrXr�r8r8r9r�s(

�&zTarInfo._create_headercCs.tt|�t�\}}|dkr*|t|t7}|S)Nr)r]r2r�r3)Zpayloadrcrdr8r8r9�_create_payload�szTarInfo._create_payloadcCsR|�||�t}i}d|d<||d<t|�|d<t|d<|�|t||�|�|�S)Nz
././@LongLinkr�r�r'r)r1r3r2rrr
r)rr�r�r6r7r�r8r8r9r�s�zTarInfo._create_gnu_long_headerc	Cs2d}|��D]8\}}z|�dd�Wqtk
rBd}YqFYqXqd}|rV|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�r�r'rr�)
�itemsr1rr2rrPrrr
r)rr�r�r6Zbinary�keyword�valueZrecords�lrMr>r�r8r8r9r�s<

(�z"TarInfo._create_pax_generic_headerc	Csvt|�dkrtd��t|�tkr(td��|�t�tkr>td��t|dd��}|t|�krbt	d��|�}t
|dd�||�|_t|dd	��|_t|d	d
��|_
t|d
d��|_t|dd��|_t|dd��|_||_|dd
�|_t
|d
d�||�|_t
|dd�||�|_t
|dd�||�|_t|dd��|_t|dd��|_t
|dd�||�}|jtk�r�|j�d��r�t|_|jtk�r8d}g}td�D]l}	z0t|||d��}
t||d|d��}Wntk
�r�Y�qYnX|�|
|f�|d7}�q�t|d�}t|dd��}
|||
f|_ |�!��rP|j�"d�|_|�rr|jt#k�rr|d|j|_|S)Nrzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�r�i�r�r�i�i�i�)$r2rrr�rs�countr3rtrOrYrLr?r�r�r)r*r'r(r�r�r�r+r,r�r��AREGTYPEr�r��GNUTYPE_SPARSErHrKr��boolr��isdir�rstrip�	GNU_TYPES)rrXr6r7r��objrr��structsrNr��numbytes�
isextended�origsizer8r8r9�frombufsZ
zTarInfo.frombufcCs8|j�t�}|�||j|j�}|j��t|_|�|�Sr0)	r�r^r�r8r6r7r�r��_proc_member)rr�rXr3r8r8r9�fromtarfileKszTarInfo.fromtarfilecCsT|jttfkr|�|�S|jtkr,|�|�S|jtttfkrF|�	|�S|�
|�SdSr0)r�r
r	�
_proc_gnulongr.�_proc_sparserr�SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r�r8r8r9r9`s



zTarInfo._proc_membercCsR|j��|_|j}|��s$|jtkr4||�|j�7}||_|�	|j
|j|j�|Sr0)
r�r�r��isregr��SUPPORTED_TYPES�_blockr'r��_apply_pax_infor�r6r7)r�r�r�r8r8r9r?mszTarInfo._proc_builtincCs�|j�|�|j��}z|�|�}Wntk
r>td��YnX|j|_|jt	krft
||j|j�|_
n|jtkr�t
||j|j�|_|S)N� missing or bad subsequent header)r�r^rBr'r:rrur�r�r
r?r6r7r�r	r�)r�r�rX�nextr8r8r9r;~s

zTarInfo._proc_gnulongc
	Cs�|j\}}}|`|r�|j�t�}d}td�D]n}z0t|||d��}t||d|d��}	Wntk
rzYq�YnX|r�|	r�|�||	f�|d7}q,t|d�}q||_	|j�
�|_|j|�|j
�|_||_
|S)Nr�rr+i�)r�r�r^r�rHrOrKr�r/r�r�r�rBr'r�)
r�r�r4r6r7rXr�rNr�r5r8r8r9r<�s(
zTarInfo._proc_sparsecCs.|j�|�|j��}|jtkr&|j}n
|j��}t�	d|�}|dk	rX|�
d��d�|d<|�d�}|dkrr|j
}nd}t�d�}d}|�||�}|s��q6|��\}	}
t|	�}	|	dkr�td��||�d	�d|�d�|	d�}|�|
dd|j�}
|
tk�r|�|||j
|j�}n|�|dd|j�}|||
<||	7}q�z|�|�}Wntk
�rbtd
��YnXd|k�r||�||�nHd|k�r�|�|||�n.|�d
�dk�r�|�d�dk�r�|�|||�|jttfk�r*|� ||j
|j�|j!|_!d|k�r*|j"}
|�#��s|jt$k�r$|
|�|j�7}
|
|_!|S)Ns\d+ hdrcharset=([^\n]+)\nr#r/�
hdrcharsetZBINARYs(\d+) ([^=]+)=rrGr$rD�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrFr')%r�r^rBr'r�rr�r
�re�search�groupr=rr6�compile�match�groupsrIrLrhr��_decode_pax_fieldr7�PAX_NAME_FIELDSr:rru�_proc_gnusparse_01�_proc_gnusparse_00�_proc_gnusparse_10rr=rCr�r�r@rA)r�r�rXr�rOrGr6Zregexr�r5r!r"rEr�r8r8r9r>�sh



$	
�
�
�


 
zTarInfo._proc_paxcCshg}t�d|�D]}|�t|�d���qg}t�d|�D]}|�t|�d���q:tt||��|_dS)Ns\d+ GNU.sparse.offset=(\d+)\nr#s\d+ GNU.sparse.numbytes=(\d+)\n)rK�finditerr�rIrM�list�zipr�)r�rEr�rXZoffsetsrOr5r8r8r9rTszTarInfo._proc_gnusparse_00cCs@dd�|d�d�D�}tt|ddd�|ddd���|_dS)NcSsg|]}t|��qSr8)rI)�.0�xr8r8r9�
<listcomp>&sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>rH�,r$r#)rrWrXr�)r�rEr�r�r8r8r9rS#szTarInfo._proc_gnusparse_01cCs�d}g}|j�t�}|�dd�\}}t|�}t|�|dkrtd|krT||j�t�7}|�dd�\}}|�t|��q,|j��|_t	t
|ddd�|ddd���|_dS)Nrr#r$)r�r^r�rrIr2r�r�r�rWrXr�)r�rEr�r�Zfieldsr�rXZnumberr8r8r9rU)szTarInfo._proc_gnusparse_10c	Cs�|��D]�\}}|dkr&t|d|�q|dkr@t|dt|��q|dkrZt|dt|��q|tkr|tkr�zt||�}Wntk
r�d}YnX|dkr�|�d�}t|||�q|��|_dS)NzGNU.sparse.namer%rIr'zGNU.sparse.realsizerr�)	r �setattrrI�
PAX_FIELDS�PAX_NUMBER_FIELDSrKr1r
r�)r�r�r6r7r!r"r8r8r9rC9s"

zTarInfo._apply_pax_infocCs4z|�|d�WStk
r.|�||�YSXdS)NrE)r=�UnicodeDecodeError)r�r"r6Zfallback_encodingZfallback_errorsr8r8r9rQPszTarInfo._decode_pax_fieldcCs"t|t�\}}|r|d7}|tS)Nr#)r]r�)r�r,rcrdr8r8r9rBXszTarInfo._blockcCs
|jtkSr0)r��
REGULAR_TYPESr�r8r8r9r@asz
TarInfo.isregcCs|��Sr0)r@r�r8r8r9�isfileeszTarInfo.isfilecCs
|jtkSr0)r�r�r�r8r8r9r0isz
TarInfo.isdircCs
|jtkSr0)r��SYMTYPEr�r8r8r9�issymmsz
TarInfo.issymcCs
|jtkSr0)r��LNKTYPEr�r8r8r9�islnkqsz
TarInfo.islnkcCs
|jtkSr0)r��CHRTYPEr�r8r8r9�ischrusz
TarInfo.ischrcCs
|jtkSr0)r��BLKTYPEr�r8r8r9�isblkysz
TarInfo.isblkcCs
|jtkSr0)r��FIFOTYPEr�r8r8r9�isfifo}szTarInfo.isfifocCs
|jdk	Sr0)r�r�r8r8r9�issparse�szTarInfo.issparsecCs|jtttfkSr0)r�rgrirkr�r8r8r9�isdev�sz
TarInfo.isdev)r�)1rorprq�dict�	__slots__r��propertyr%�setterr&r�r�rrr�r�r�r��classmethodrr�staticmethodrrrrr8r:r9r?r;r<r>rTrSrUrCrQrBr@rbr0rdrfrhrjrlrmrnr8r8r8r9r�s��





1


	

2
>

h	c
@s�eZdZdZdZdZdZeZe	Z
dZeZ
eZd[dd�Zedddefd	d
��Zed\dd��Zed]dd��Zed^dd��Zed_dd��Zddddd�Zdd�Zdd�Zdd�Zdd �Zd`d!d"�Zdadd$�d%d&�Zdbdd'�d(d)�Zdcd*d+�Z dddd-�d.d/�Z!dedd-�d1d2�Z"d3d4�Z#dfd5d6�Z$d7d8�Z%d9d:�Z&d;d<�Z'd=d>�Z(d?d@�Z)dAdB�Z*dCdD�Z+dEdF�Z,dGdH�Z-dIdJ�Z.dgdKdL�Z/dMdN�Z0dhdOdP�Z1dQdR�Z2dSdT�Z3dUdV�Z4dWdX�Z5dYdZ�Z6dS)irrFr#Nrxr�c
Cs�ddddd�}||krtd��||_|||_|sh|jdkrTtj�|�sTd|_d|_t||j�}d	|_n@|dkr�t|d
�r�t	|j
ttf�r�|j
}t|d�r�|j|_d|_|r�tj�
|�nd|_
||_|dk	r�||_|dk	r�||_|dk	r�||_|dk	r�||_|dk	�r||_|	|_|
dk	�r0|jtk�r0|
|_ni|_|dk	�rF||_|dk	�rV||_|
|_d	|_g|_d	|_|j��|_i|_z�|jd
k�r�d|_ |�!�|_ |jdk�r2|j�"|j�z|j�#|�}|j�$|�WnXt%k
�r�|j�"|j�Y�q2Yn0t&k
�r,}zt't|���W5d}~XYnX�q�|jdk�r|d|_|j�r||j�(|j�)��}|j�*|�|jt+|�7_Wn&|j�s�|j�,�d|_�YnXdS)N�rbzr+b�wbZxb�rx�aryrZ�!mode must be 'r', 'a', 'w' or 'x'rxryFr�r�Trx�rxryrZ)-rKr��_moder{r%�exists�	bltn_openr�r�rr�rrP�abspathr�rTr��dereference�ignore_zerosr6r7rr��debug�
errorlevel�copybufsizer��members�_loadedr�r��inodes�firstmemberrEr�r:r�rtrrrr
r_r2r�)r�r�r�r�rTr�rr�r6r7r�r�r�r�Zmodes�erXr8r8r9r��s�
�





"
zTarFile.__init__c

s�|s|std��|dkr��fdd�}t�j|d�D]j}t��j|�}|dk	rV|��}	z||d|f|�WSttfk
r�|dk	r�|�|	�Yq2Yq2Xq2td���nd|k�r|�dd	�\}
}|
p�d}
|p�d
}|�jkr�t��j|�}ntd|��|||
|f|�Sd|k�r�|�dd	�\}
}|
�p.d}
|�p8d
}|
d
k�rLtd��t	||
|||�}z�||
|f|�}Wn|�
��YnXd|_|S|dk�r��j|||f|�Std��dS)Nznothing to open)rx�r:*cs�j|dkS)N�taropen)�	OPEN_METH)r��rr8r9�not_compressed<sz$TarFile.open.<locals>.not_compressed��keyrxz%file could not be opened successfully�:r#r�r��|rwzmode must be 'r' or 'w'Frzzundiscernible mode)
rK�sortedr�rir�rrr�rr�r�r�r�)
rr�r�r�rb�kwargsr�r��funcZ	saved_pos�filemode�streamr�r8r�r9rsP%







zTarFile.opencKs |dkrtd��||||f|�S)Nrwry)rK)rr�r�r�r�r8r8r9r�mszTarFile.taropenr�cKs�|dkrtd��zddlm}Wntk
r<td��YnXz|||d||�}Wn.tk
r�|dk	r||dkr|td���YnXz|j|||f|�}WnBtk
r�|��|dkr�td���Yn|���YnXd	|_	|S)
N�rxryrZ�mode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availablererxr�F)
rKZgzipr�r�rr�rr�r�r�)rr�r�r��
compresslevelr�r�r�r8r8r9�gzopenus0zTarFile.gzopenc	Ks�|dkrtd��zddlm}Wntk
r<td��YnX||pF|||d�}z|j|||f|�}WnFttfk
r�|��|dkr�t	d���Yn|���YnXd	|_
|S)
Nr�r�r)�BZ2Filer�)r�rxznot a bzip2 fileF)rKr�r�r�rr�r��EOFErrorr�rr�)rr�r�r�r�r�r�r�r8r8r9�bz2open�s&zTarFile.bz2openc		Ks�|dkrtd��zddlm}m}Wntk
r@td��YnX||pJ|||d�}z|j|||f|�}WnF|tfk
r�|��|dkr�t	d���Yn|���YnXd	|_
|S)
Nr�r�r)�LZMAFiler�r�)�presetrxznot an lzma fileF)rKr�r�r�r�rr�r�r�rr�)	rr�r�r�r�r�r�r�r�r8r8r9�xzopen�s&zTarFile.xzopenr�r�r�r�)r�r�r�r�cCs�|jr
dSd|_z`|jdkrn|j�ttd�|jtd7_t	|jt
�\}}|dkrn|j�tt
|�W5|js�|j��XdS)NTrzr$r)r�r�r�r�r�r_r3r�r�r]�
RECORDSIZE)r�rcrdr8r8r9r��s
z
TarFile.closecCs"|�|�}|dkrtd|��|S)Nzfilename %r not found)�
_getmember�KeyError)r�r�r�r8r8r9�	getmember�s
zTarFile.getmembercCs|��|js|��|jSr0)�_checkr��_loadr�r�r8r8r9�
getmembers�szTarFile.getmemberscCsdd�|��D�S)NcSsg|]
}|j�qSr8r�)rYr�r8r8r9r[sz$TarFile.getnames.<locals>.<listcomp>)r�r�r8r8r9�getnamesszTarFile.getnamescCs^|�d�|dk	r|j}|dkr$|}tj�|�\}}|�tjd�}|�d�}|��}||_	|dkr�|j
stt�|�}q�t�|�}nt�
|���}d}|j}t�|�r�|j|jf}	|j
s�|jdkr�|	|jkr�||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|_/Wnt0k
�r�YnXt1�rzt1�2|j&�d|_3Wnt0k
�rYnX|
tt!fk�rZt4td��rZt4td��rZt�5|j6�|_7t�8|j6�|_9|S)N�awxr�r�r#r�major�minor):r�r�r{r%�
splitdriver��sep�lstripr�r�r�lstat�stat�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�rer��S_ISDIRr��S_ISFIFOrk�S_ISLNKrc�readlink�S_ISCHRrg�S_ISBLKrir��st_uidr)�st_gidr*�st_sizer'�st_mtimer(r�r��pwd�getpwuidr+r��grpZgetgrgidr,r�r��st_rdevr�r�r�)r�r��arcnamer�Zdrvr�Zstatresr�Zstmd�inoder�r8r8r9�
gettarinfo	s�	


��

zTarFile.gettarinfoT)r�cCs�|��|dkr|}|D]�}|r�tt�|j��td|jp>|j|jpH|jf�|�	�s`|�
�rztdd|j|jf�ntd|j
�tdt�|j�dd��t|j|��r�dnd�|r�|��r�td	|j�|��r�td
|j�t�qdS)Nz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dr�r�r�z-> zlink to )r�rmr�r�r�r+r)r,r*rhrjr�r�r'r��	localtimer(r�r0rdr�rfrl)r��verboser�r�r8r8r9rWls0
���zTarFile.list��filterc	Cs6|�d�|dkr|}|jdk	rFtj�|�|jkrF|�dd|�dS|�d|�|�||�}|dkrz|�dd|�dS|dk	r�||�}|dkr�|�dd|�dS|��r�t|d��}|�	||�W5QRXn`|�
��r(|�	|�|�r2tt�|��D]*}|j
tj�||�tj�||�||d�q�n
|�	|�dS)	Nr�r$ztarfile: Skipped %rr#ztarfile: Unsupported type %rztarfile: Excluded %rrur�)r�r�r{r%r~�_dbgr�r@r}�addfiler0r��listdir�addr�)r�r�r��	recursiver�r��fr8r8r9r��s8



�
zTarFile.addcCs�|�d�t�|�}|�|j|j|j�}|j�|�|jt	|�7_|j
}|dk	r�t||j|j|d�t
|jt�\}}|dkr�|j�tt|�|d7}|j|t7_|j�|�dS)Nr�)rbrr#)r�r
r�rTr6r7r�r_r�r2r�r\r'r]r�r3r�r�)r�r�r�rXrbrcrdr8r8r9r��s

zTarFile.addfile�.��
numeric_ownercCs�g}|dkr|}|D]>}|��r:|�|�t�|�}d|_|j|||��|d�q|jdd�d�|��|D]�}tj�	||j
�}z,|j|||d�|�||�|�
||�Wqptk
r�}z"|jdkrЂn|�dd|�W5d}~XYqpXqpdS)	N���	set_attrsr�cSs|jSr0r�)rxr8r8r9�<lambda>�r�z$TarFile.extractall.<locals>.<lambda>r�r�r#�tarfile: %s)r0r�r
r��extract�sort�reverser{r%r�r��chown�utime�chmodr
r�r�)r�r%r�r�Zdirectoriesr��dirpathr�r8r8r9�
extractall�s.

�
zTarFile.extractallr�c
Cs|�d�t|t�r |�|�}n|}|��r>tj�||j�|_	z"|j
|tj�||j�||d�Wn�tk
r�}zH|j
dkr��n6|jdkr�|�dd|j�n|�dd|j|jf�W5d}~XYnBtk
�r}z"|j
dkr�n|�dd|�W5d}~XYnXdS)Nrxr�rr#r�ztarfile: %s %r)r�rrr�rfr{r%r�r�r��_extract_memberr�r�r��filenamer��strerrorr
)r��memberr%r�r�r�r�r8r8r9r�s*	

�


(
zTarFile.extractcCs�|�d�t|t�r |�|�}n|}|��s6|jtkrB|�||�S|��sR|�	�rzt|j
t�rhtd��q~|�
|�|��SndSdS)Nrxz'cannot extract (sym)link as file object)r�rrr�r@r�rA�
fileobjectrfrdr�r�r	�extractfile�_find_link_target)r�r�r�r8r8r9r�&s


zTarFile.extractfilecCsT|�d�}|�dtj�}tj�|�}|r>tj�|�s>t�|�|��sN|�	�rh|�
dd|j|jf�n|�
d|j�|�
�r�|�||�n�|��r�|�||�nx|��r�|�||�nb|��s�|��r�|�||�nD|��s�|�	�r�|�||�n&|jtk�r|�||�n|�||�|�rP|�|||�|�	��sP|�||�|�||�dS)Nr�r#z%s -> %s)r1r�r{r�r%�dirnamer|�makedirsrfrdr�r�r�r@�makefiler0�makedirrl�makefiforhrj�makedev�makelinkr�rA�makeunknownr�r�r�)r�r��
targetpathr�r�Z	upperdirsr8r8r9r�Es4


zTarFile._extract_membercCs*zt�|d�Wntk
r$YnXdS)Nr�)r{�mkdir�FileExistsError�r�r�r�r8r8r9r�vszTarFile.makedirc	Cs�|j}|�|j�|j}t|d��b}|jdk	rn|jD]"\}}|�|�t|||t|�q4|�|j�|�	�nt|||jt|�W5QRXdS)Nrv)
r�r�r�r�r}r�r\rr'�truncate)r�r�r��sourcerb�targetr�r'r8r8r9r��s


zTarFile.makefilecCs"|�||�|�dd|j�dS)Nr#z9tarfile: Unknown file type %r, extracted as regular file.)r�r�r�r�r8r8r9r��s�zTarFile.makeunknowncCs"ttd�rt�|�ntd��dS)N�mkfifozfifo not supported by system)r�r{r�r
r�r8r8r9r��s
zTarFile.makefifocCs^ttd�rttd�std��|j}|��r6|tjO}n
|tjO}t�||t�	|j
|j��dS)N�mknodr�z'special devices not supported by system)r�r{r
r�rjr��S_IFBLK�S_IFCHRr�r�r�r�)r�r�r�r�r8r8r9r��s
�zTarFile.makedevcCs�zb|��r0tj�|�r t�|�t�|j|�n0tj�|j�rNt�	|j|�n|�
|�|�|�WnHtk
r�z|�
|�|�|�Wnt
k
r�td��YnXYnXdS)Nz%unable to resolve link inside archive)rdr{r%�lexists�unlink�symlinkr�r|r��linkr�r��symlink_exceptionr�r
r�r8r8r9r��s"
��zTarFile.makelinkcCs�ttd�r�t��dkr�|j}|j}|s�ztr<t�|j�d}Wntk
rRYnXzt	rjt	�
|j�d}Wntk
r�YnXz4|��r�ttd�r�t�
|||�nt�|||�Wntk
r�td��YnXdS)N�geteuidrr$�lchownzcould not change owner)r�r{rr*r)r�Zgetgrnamr,r�r��getpwnamr+rdrr�r�r
)r�r�r�r��g�ur8r8r9r��s(z
TarFile.chowncCs4zt�||j�Wntk
r.td��YnXdS)Nzcould not change mode)r{r�r�r�r
r�r8r8r9r��sz
TarFile.chmodcCsHttd�sdSzt�||j|jf�Wntk
rBtd��YnXdS)Nr�z"could not change modification time)r�r{r�r(r�r
r�r8r8r9r��s
z
TarFile.utimec
Cs�|�d�|jdk	r$|j}d|_|S|j|j��krZ|j�|jd�|j�d�sZtd��d}z|j�	|�}W�q�t
k
r�}z6|jr�|�dd|j|f�|jt
7_WY�q^W5d}~XY�q�tk
�r6}zR|j�r|�dd|j|f�|jt
7_WY� q^n|jdk�r&tt|���W5d}~XYn�tk
�r^|jdk�rZtd��Ynjtk
�r�}z|jdk�r�tt|���W5d}~XYn0tk
�r�}ztt|���W5d}~XYnX�q�q^|dk	�r�|j�|�nd|_|S)	NZrar#rZr$z0x%X: %srz
empty fileT)r�r�r�r�r�r�r^rr�r:rtr�r�r�rLrrrrsrur�r�r�)r��mr�r�r8r8r9rE�sJ



zTarFile.nextcCsn|��}|dk	r"|d|�|��}|r2tj�|�}t|�D].}|rRtj�|j�}n|j}||kr:|Sq:dSr0)r��indexr{r%�normpath�reversedr�)r�r�r��	normalizer�r��member_namer8r8r9r�/	szTarFile._getmembercCs|��}|dkrqqd|_dSr�)rEr�)r�r�r8r8r9r�F	sz
TarFile._loadcCs:|jrtd|jj��|dk	r6|j|kr6td|j��dS)Nz%s is closedzbad operation for mode %r)r�r�r�ror�)r�r�r8r8r9r�P	szTarFile._checkcCs`|��r.d�tdtj�|j�|jf��}d}n
|j}|}|j||dd�}|dkr\t	d|��|S)Nr�T)r�rzlinkname %r not found)
rdr�r�r{r%r�r�r�r�r�)r�r�r��limitr�r8r8r9r�Y	s zTarFile._find_link_targetccs�|jr|jEdHdSd}|jdk	r:|��}|d7}|V|t|j�krT|j|}n"|jsr|��}|svd|_dSndS|d7}|Vq:dS)Nrr#T)r�r�r�rEr2)r�r	r�r8r8r9�__iter__l	s$
zTarFile.__iter__cCs||jkrt|tjd�dS)N��file)r�rlrj�stderr)r��level�msgr8r8r9r��	s
zTarFile._dbgcCs|��|Sr0)r�r�r8r8r9�	__enter__�	szTarFile.__enter__cCs,|dkr|��n|js"|j��d|_dSr�)r�r�r�r�)r�r�r"�	tracebackr8r8r9�__exit__�	s


zTarFile.__exit__)
NrxNNNNNNr�NNNN)rxN)rxNr�)rxNr�)rxNN)NNN)T)NT)N)r�N)r�T)TF)NF)N)7rorprqr�rr�r�rrTrr6r7rr�r�r�r�rsr�rr�r�r�r�r�r�r�r�r�r�rWr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rEr�r�r�r�rr�rrr8r8r8r9r�s��
oZ �


c 3
(&�
1
6


	cCs2zt|�}|��WdStk
r,YdSXdS)NTF)rr�r)r�r�r8r8r9r�	sc	Cs�ddl}d}|j|d�}|jdddddd	�|jd
d�}|jdd
ddd�|jdddddd�|jdddddd�|jddddd�|��}|jdk	�r|j}t|�r�t|d�� }|��t	|��t
jd�W5QRX|jr�t	d �
|��n|�d!d"�
|���n�|jdk	�r\|j}t|��rFt�|d#��}|j|jd$�W5QRXn|�d!d"�
|���nr|jdk	�r,t|j�d!k�r�|jd}tj}n,t|j�d%k�r�|j\}}n|�d!|���t|��rt�|d#��}|j|d&�W5QRX|j�r*|d'k�rd(�
|�}	nd)�
||�}	t	|	�n|�d!d"�
|��n�|jdk	�r�|j�d�}
tj�|
�\}}d*d*d+d+d,d,d,d,d-�}
||
k�r�d.|
|nd/}|j}t�|
|��}|D]}|�|��q�W5QRX|j�r�t	d0�
|
��dS)1Nrz3A simple command-line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpT)Zrequiredz-lz--list�	<tarfile>zShow listing of a tarfile)�metavarrz-ez	--extract�+)rz<output_dir>zExtract tarfile into target dir)�nargsrrz-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrxrz{!r} is a tar archive.r#z{!r} is not a tar archive.
r�)r�r$)r%r�z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r�r�r�)r�z.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:ryz{!r} file created.)�argparse�ArgumentParser�add_argumentZadd_mutually_exclusive_group�
parse_argsZtestrrr�rlrjrr�rT�exitrWrr�r2r{�curdirZformat_helpr�Zcreate�popr%�splitextr�)r!r�parserrM�argsr`r�Ztfr&rZtar_name�_ZextZcompressionsZtar_modeZ	tar_files�	file_namer8r8r9�main�	s��
�
�
�
�



�
�
r-�__main__)]�version�
__author__�__credits__�builtinsrr}rjr{r�r[r�r�rWr
rKr�r�r��AttributeError�NotImplementedErrorrr��	NameError�__all__r3r�r�rrrrrr�r-rercrgrir�rkZCONTTYPEr
r	r.rrr=r
rrrrArar2r^rRrrIr_r�r�getfilesystemencodingr:r?rOrUrYr\rm�	Exceptionrr
rrr	rrrrsrtrLrurvr��objectr�r��BufferedReaderr�rrrr-ror8r8r8r9�<module> s


�����
shD!W


ZeroDay Forums Mini