3 �L�j���'@sBdZdZdZdZdZdZddlmZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZy ddlZWnek r�dZYnXy ddlZWnek r�dZYnXeefZyeef7ZWnek r�YnXd d d d d ddddddddddgZdZdZdZdZedZ dZ!dZ"dZ#dZ$d Z%d!Z&dZ'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4dZ5d/Z6d0Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1f Z9e&e'e.e1fZ:e/e0e1fZ;d�Ze>e>e?e?e?d9�Z@e jAd:k�r�d;ZBne jC�ZBdd?�ZEd@dA�ZFdBe8fdCdD�ZGdEdF�ZHdedfdGdH�ZIdIdJ�ZJdKdL�ZKGdMd �d eL�ZMGdNd�deM�ZNGdOd �d eM�ZOGdPd�deM�ZPGdQd�deM�ZQGdRd�deM�ZRGdSdT�dTeR�ZSGdUdV�dVeR�ZTGdWdX�dXeR�ZUGdYdZ�dZeR�ZVGd[d\�d\eR�ZWGd]d^�d^�ZXGd_d`�d`�ZYGdadb�dbeZ�Z[Gdcdd�ddeZ�Z\Gdedf�dfe j]�Z^Gdgdh�dheM�Z_Gdidj�dje_�Z`Gdkdl�dle_�ZaGdmdn�dne_�ZbGdodp�dpe_�ZcGdqdr�dre_�ZdGdsdt�dte_�Zee_eeNfZfd�dudv�Zgdwdx�Zhdydz�Zid{d|�Zjeheiejd}�ZkeZ�Zlejmd~�ZnGdd �d eZ�ZoGd�d �d eZ�Zpd�d �ZqepjZd�d��Zresd�k�r>er�dS)�z,Read from and write to tar format archives. z0.9.0u"Lars Gustäbel ([email protected])z5$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $z?$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.�)�openN�TarFile�TarInfo� is_tarfile�TarError� ReadError�CompressionError� StreamError� ExtractError� HeaderError�ENCODING� USTAR_FORMAT� GNU_FORMAT� PAX_FORMAT�DEFAULT_FORMATrTz/etc/python/tarfile.cfg�i�sustar sustar00�d��0�1�2�3�4�5�6�7�L�K�S�x�g�X���path�linkpath�size�mtime�uid�gid�uname�gname)ZatimeZctimer(r)r*r'�ntzutf-8cCs8|dkrtd��|j||�}|d|�|t|�tS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None)� ValueError�encode�len�NUL)�s�length�encoding�errors�r6�/usr/lib64/python3.6/tarfile.py�stn�s r8cCs*|jd�}|dkr|d|�}|j||�S)z8Convert a null-terminated bytes object to a string. rr#N�����)�find�decode)r2r4r5�pr6r6r7�nts�s  r=c Cs�|dd krfd}x0tt|�d�D]}|dK}|||d7}q"W|ddkr�dt|�d| }n@y"t|dd�}t|j�p�d d�}Wntk r�td ��YnX|S) z/Convert a number field to a python number. r���r#���ascii�strict�0zinvalid header)r>r?)�ranger0r=�int�stripr.�InvalidHeaderError)r2�n�ir6r6r7�nti�s   rKr@cCs�t|�}d|ko"d|dknrDtd|d|fd�t}n�|tkr�d|d |kopd|dknr�|dkr�tdg�}ntdg�}d||}x6t|d�D]}|jd|d@�|dL}q�Wntd ��|S) z/Convert a python number to a number field. rr@r#z%0*orBrAr>r?zoverflow in number field)rF�bytesr1r� bytearrayrE�insertr.)rI�digits�formatr2rJr6r6r7�itn�s  2   rQcCs0dttjd|��}dttjd|��}||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. rAZ 148B8x356BZ 148b8x356b)�sum�structZ unpack_from)�bufZunsigned_chksumZ signed_chksumr6r6r7� calc_chksums�s rUc Cs�|pd}|dkrdS|dkr.tj|||�dSt||�\}}x8t|�D],}|j|�}t|�|krh|d��|j|�qFW|dkr�|j|�}t|�|kr�|d��|j|�dS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. �irNzunexpected end of datai@)�shutil� copyfileobj�divmodrE�readr0�write) �src�dstr3� exception�bufsize�blocks� remainder�brTr6r6r7rX�s$     rXcCs ddl}|jdtd�tj|�S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)�warnings�warn�DeprecationWarning�stat�filemode)�modercr6r6r7rgsrgcCs8ttjdd�}|dk r(|j|d�j|�}t|dd�dS)Nr4�backslashreplace� )�end)�getattr�sys�stdoutr/r;�print)r2r4r6r6r7� _safe_printsrpc@seZdZdZdS)rzBase exception.N)�__name__� __module__� __qualname__�__doc__r6r6r6r7rsc@seZdZdZdS)r z%General exception for extract errors.N)rqrrrsrtr6r6r6r7r !sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rqrrrsrtr6r6r6r7r$sc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rqrrrsrtr6r6r6r7r'sc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.N)rqrrrsrtr6r6r6r7r *sc@seZdZdZdS)r z!Base exception for header errors.N)rqrrrsrtr6r6r6r7r -sc@seZdZdZdS)�EmptyHeaderErrorzException for empty headers.N)rqrrrsrtr6r6r6r7ru0sruc@seZdZdZdS)�TruncatedHeaderErrorz Exception for truncated headers.N)rqrrrsrtr6r6r6r7rv3srvc@seZdZdZdS)�EOFHeaderErrorz"Exception for end of file headers.N)rqrrrsrtr6r6r6r7rw6srwc@seZdZdZdS)rHzException for invalid headers.N)rqrrrsrtr6r6r6r7rH9srHc@seZdZdZdS)�SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rqrrrsrtr6r6r6r7rx<srxc@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}tj||d�|_dS)N)�r�w�O_BINARYi�) �os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr|r�fd)�self�namerhr6r6r7�__init__Is   z_LowLevelFile.__init__cCstj|j�dS)N)r}�closer�)r�r6r6r7r�Rsz_LowLevelFile.closecCstj|j|�S)N)r}rZr�)r�r'r6r6r7rZUsz_LowLevelFile.readcCstj|j|�dS)N)r}r[r�)r�r2r6r6r7r[Xsz_LowLevelFile.writeN)rqrrrsrtr�r�rZr[r6r6r6r7ryCs  ryc@steZdZdZdd�Zdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z ddd�Z ddd�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|_|dkrt||�}d|_|dkr6t|�}|j�}|pt|j�|jkrL|jj|jd|j��|j|jd�|_qWdS)z]Write string s to the stream if a whole new block is ready to be written. N)rTr0r_r�r[)r�r2r6r6r7Z__write�sz_Stream.__writec Cs�|jr dSd|_z�|jdkr:|jdkr:|j|jj�7_|jdkr�|jr�|jj|j�d|_|jdkr�|jjtj d|j ��|jjtj d|j d@��Wd|j s�|jj �XdS) z[Close the _Stream object. No operation should be done on it afterwards. NTr{r�r�r�zd|fg}d|_g|_d}|j}xT|D]L\}}||kr~|jj d||df�|jj d||||f�||7}||}qZW||jkr�|jj d||jdf�dS)Nrr�FT) r��offsetr'�positionrlr�r�� map_index�mapr�)r�r�r�r'Z blockinfoZlastposZrealposr6r6r7r�us(   z_FileInFile.__init__cCsdS)Nr6)r�r6r6r7r��sz_FileInFile.flushcCsdS)NTr6)r�r6r6r7�readable�sz_FileInFile.readablecCsdS)NFr6)r�r6r6r7�writable�sz_FileInFile.writablecCs |jj�S)N)r��seekable)r�r6r6r7r��sz_FileInFile.seekablecCs|jS)z*Return the current file position. )r�)r�r6r6r7r��sz_FileInFile.tellcCs�|tjkr tt|d�|j�|_nj|tjkr\|dkrFt|j|d�|_q�t|j||j�|_n.|tjkr�tt|j||j�d�|_ntd��|jS)z(Seek to a position in the file. rzInvalid argument) �io�SEEK_SET�min�maxr'r��SEEK_CUR�SEEK_ENDr.)r�r��whencer6r6r7r��s   z_FileInFile.seekc Cs|dkr|j|j}nt||j|j�}d}x�|dk�r xZ|j|j\}}}}||jkob|knrlPq:|jd7_|jt|j�kr:d|_q:Wt|||j�}|r�|jj||j|�|jj|�}t|�|kr�t d��||7}n |t |7}||8}|j|7_q.W|S)z!Read data from the file. Nr�rr#zunexpected end of data) r'r�r�r�r�r0r�r�rZrr1) r�r'rT�data�start�stopr�r3rbr6r6r7rZ�s.      z_FileInFile.readcCs&|jt|��}||dt|��<t|�S)N)rZr0)r�rbrTr6r6r7�readinto�sz_FileInFile.readintocCs d|_dS)NT)r�)r�r6r6r7r��sz_FileInFile.close)N)N)rqrrrsrtr�r�r�r�r�r�r�r�r�rZr�r�r6r6r6r7r�os  r�cseZdZ�fdd�Z�ZS)� ExFileObjectcs&t|j|j|j|j�}t�j|�dS)N)r�r�� offset_datar'�sparse�superr�)r��tarfile�tarinfor�)� __class__r6r7r��s  zExFileObject.__init__)rqrrrsr�� __classcell__r6r6)r�r7r��sr�c@s eZdZdS)� FilterErrorN)rqrrrsr6r6r6r7r��sr�cseZdZ�fdd�Z�ZS)�AbsolutePathErrorcs ||_t�jd|j�d��dS)Nzmember z has an absolute path)r�r�r�r�)r�r�)r�r6r7r��szAbsolutePathError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�OutsideDestinationErrorcs.||_||_t�j|j�d|�d�d�dS)Nz would be extracted to z, z which is outside the destination)r��_pathr�r�r�)r�r�r%)r�r6r7r��sz OutsideDestinationError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�SpecialFileErrorcs||_t�j|j�d��dS)Nz is a special file)r�r�r�r�)r�r�)r�r6r7r��szSpecialFileError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�AbsoluteLinkErrorcs||_t�j|j�d��dS)Nz! is a symlink to an absolute path)r�r�r�r�)r�r�)r�r6r7r��szAbsoluteLinkError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�LinkOutsideDestinationErrorcs.||_||_t�j|j�d|�d�d�dS)Nz would link to z, z which is outside the destination)r�r�r�r�r�)r�r�r%)r�r6r7r��sz$LinkOutsideDestinationError.__init__)rqrrrsr�r�r6r6)r�r7r��sr�cseZdZ�fdd�Z�ZS)�LinkFallbackErrorcs2||_||_t�jd|j�d�d|�d��dS)Nzlink z would be extracted as a zcopy of z, which was rejected)r�r�r�r�r�)r�r�r%)r�r6r7r�szLinkFallbackError.__init__)rqrrrsr�r�r6r6)r�r7r�sr�cCs$i}|j}tjj|tjjd�}|jdtjf�rH|jjdtj�}|d<tjj|�r\t |��tjjtjj ||�tjjd�}tjj ||g�|kr�t ||��|j }|dk �r|d@}|�r�|j�s�|j�r�|d@s�|dM}|dO}n|j�s�|j�r�d}nt|��||j k�r||d<|�r |jdk �r,d|d <|jdk �r@d|d <|jdk �rTd|d <|jdk �rhd|d <|j��s||j��r tjj|j��r�t|��tjj|j�}||jk�r�||d <|j��r�tjj |tjj|�|j�}ntjj ||j�}tjj|tjjd�}tjj ||g�|k�r t||��|S)N)rC�/r�i��@�Ii�rhr)r*r+r,�linknamei����)r�r}r%�realpath� ALLOW_MISSINGr��sep�lstrip�isabsr�r�� commonpathr�rh�isreg�islnk�isdir�issymr�r)r*r+r,r�r��normpath�dirnamer�)�member� dest_pathZfor_data� new_attrsr�Z target_pathrhZ normalizedr6r6r7�_get_filtered_attrssd                r�cCs|S)Nr6)r�r�r6r6r7�fully_trusted_filterTsr�cCs(t||d�}|r$|jf|ddi��S|S)NF�deep)r�r�)r�r�r�r6r6r7� tar_filterWs r�cCs(t||d�}|r$|jf|ddi��S|S)NTr�F)r�r�)r�r�r�r6r6r7� data_filter]s r�)Z fully_trustedr�r�s([0-9]{1,20}) c@s�eZdZdZdmZdndd�Zdd�Zdd�Zeee�Z dd�Z dd �Z ee e �Z d!d"�Z eeeeeeeed#ed$� d%d&�Zd'd(�Zeed)fd*d+�Zd,d-�Zd.d/�Zd0d1�Zed2d3��Zd4d5�Zed6d7��Zed8d9��Zed:d;��Zedd?��Zed@dA��Z dBdC�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�Z0dbdc�Z1ddde�Z2dfdg�Z3dhdi�Z4djdk�Z5dlS)oraInformational 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. r�rhr)r*r'r(�chksum�typer�r+r,�devmajor�devminorr�r�� pax_headersr�r��_sparse_structs� _link_targetr�cCsj||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_i|_dS)zXConstruct a TarInfo object. name is the optional name of the member. i�rr�N)r�rhr)r*r'r(r��REGTYPEr�r�r+r,r�r�r�r�r�r)r�r�r6r6r7r��s"zTarInfo.__init__cCs|jS)N)r�)r�r6r6r7�_getpath�szTarInfo._getpathcCs ||_dS)N)r�)r�r�r6r6r7�_setpath�szTarInfo._setpathcCs|jS)N)r�)r�r6r6r7� _getlinkpath�szTarInfo._getlinkpathcCs ||_dS)N)r�)r�r�r6r6r7� _setlinkpath�szTarInfo._setlinkpathcCsd|jj|jt|�fS)Nz<%s %r at %#x>)r�rqr��id)r�r6r6r7�__repr__�szTarInfo.__repr__T) r�r(rhr�r)r*r+r,r��_KEEPc Cs�| rtj|�} n tj|�} || k r(|| _|| k r6|| _|| k rD|| _|| k rR|| _|| k r`|| _|| k rn|| _|| k r||| _|| k r�|| _ | S)zGReturn a deep copy of self with the given attributes replaced. ) �copy�deepcopyr�r(rhr�r)r*r+r,) r�r�r(rhr�r)r*r+r,r�r �resultr6r6r7r��s(  zTarInfo.replacecCs�|jdkrd}n |jd@}|j||j|j|j|j|j|j|j|j |j |j |j d� }|dt kr~|djd� r~|dd7<|S)z9Return the TarInfo's attributes as a dictionary. Ni�) r�rhr)r*r'r(r�r�r�r+r,r�r�r�r�r�)rhr�r)r*r'r(r�r�r�r+r,r�r��DIRTYPEr�)r�rh�infor6r6r7�get_info�s&   zTarInfo.get_info�surrogateescapecCs~|j�}x(|j�D]\}}|dkrtd|��qW|tkrH|j|||�S|tkr^|j|||�S|tkrr|j||�Std��dS)ztd��t|dd��}|t|�krbt 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 jd��r�t|_|jtk�r6d}g}xrtd�D]f} y0t|||d��} t||d|d��} Wntk �r�PYnX|j| | f�|d7}�q�Wt|d�} t|dd��} || | f|_ |j!��rN|j j"d�|_ |�rp|jt#k�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�r�i�r�r$�i�i�i�)$r0rur�rv�countr1rwrKrUrHr=r�rhr)r*r'r(r�r�r�r+r,r�r��AREGTYPEr�r�GNUTYPE_SPARSErEr.r��boolrr��rstrip� GNU_TYPES)r1rTr4r5r��objrr��structsrJr��numbytes� isextended�origsizer6r6r7�frombuf�sZ       zTarInfo.frombufcCs8|jjt�}|j||j|j�}|jj�t|_|j|�S)zOReturn the next TarInfo object from TarFile object tarfile. ) r�rZr�rRr4r5r�r�� _proc_member)r1r�rTrMr6r6r7� fromtarfile s zTarInfo.fromtarfilecCsT|jttfkr|j|�S|jtkr,|j|�S|jtttfkrF|j |�S|j |�SdS)zYChoose the right processing method depending on the type and call it. N) r�r"r!� _proc_gnulongrI� _proc_sparser.r0�SOLARIS_XHDTYPE� _proc_pax� _proc_builtin)r�r�r6r6r7rS!s    zTarInfo._proc_membercCsR|jj�|_|j}|j�s$|jtkr4||j|j�7}||_|j |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_inforr4r5)r�r�r�r6r6r7rY.s zTarInfo._proc_builtinc Cs�|jj|j|j��}y|j|�}Wntk r>td��YnX|j|_|jt krft ||j |j �|_ n|jtkr�t ||j |j �|_|S)zSProcess the blocks that hold a GNU longname or longlink member. z missing or bad subsequent header)r�rZr[r'rTr rxr�r�r"r=r4r5r�r!r�)r�r�rT�nextr6r6r7rU?s  zTarInfo._proc_gnulongc Cs�|j\}}}|`x�|r�|jjt�}d}xvtd�D]j}y0t|||d��}t||d|d��} Wntk rzPYnX|r�| r�|j|| f�|d7}q0Wt|d�}qW||_ |jj �|_ |j |j |j �|_||_ |S)z8Process a GNU sparse header plus extra headers. r�r$rFi�)rr�rZr�rErKr.r�rJr�r�r�r[r'r�) r�r�rNrPrQrTr�rJr�rOr6r6r7rVUs(    zTarInfo._proc_sparsec Cs�|jj|j|j��}|jtkr&|j}n |jj�}d}d}g}�x0t|�|koV||dk�rnt j ||�}|srt d��yt |j d��}Wntk r�t d��YnX|dkr�t d��||t|�kr�t d��|jd�|d} ||jd�d| �} | jd�\} } } | �s"| dk�s"|| dk�r*t d��|j|| | f�| dk�rd|dk�rd| d k�r`|j}nd }||7}q@W|dk�r~d }x`|D]X\}} } |j| d d |j�}|tk�r�|j| ||j|j�}n|j| d d |j�}|||<�q�Wy|j|�}Wntk �r td ��YnXd |k�r&|j||�nFd |k�r>|j||�n.|jd�dk�rl|jd�dk�rl|j|||�|jttfk�r�|j ||j|j�|j!|_!d|k�r�|j"}|j#��s�|jt$k�r�||j|j�7}||_!|S)zVProcess an extended or global header as described in POSIX.1-2008. rNzinvalid headerr#�r;r�s hdrcharsetsBINARYzutf-8z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrDr')%r�rZr[r'r�r0rr r0�_header_length_prefix_re�matchrHrF�groupr.r�rk� partitionr�r4�_decode_pax_fieldr5�PAX_NAME_FIELDSrTr rx�_proc_gnusparse_01�_proc_gnusparse_00r5�_proc_gnusparse_10r.rWr\r�r�r�rZ)r�r�rTrr�r4� raw_headersrbr3Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuer=rr]r�r6r6r7rXqsx                 zTarInfo._proc_paxc Cs�g}g}x�|D]�\}}}|dkrVy|jt|j���Wq�tk rRtd��Yq�Xq|dkry|jt|j���Wqtk r�td��YqXqWtt||��|_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetzinvalid headersGNU.sparse.numbytesN)r�rFr;r.rH�list�zipr�)r�r]rjZoffsetsrO�_r=rr6r6r7rh�szTarInfo._proc_gnusparse_00cCs@dd�|djd�D�}tt|ddd�|ddd���|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|��qSr6)rF)�.0�xr6r6r7� sz.TarInfo._proc_gnusparse_01..zGNU.sparse.map�,Nr$r#)r3rkrlr�)r�r]rr�r6r6r7rg�szTarInfo._proc_gnusparse_01cCs�d}g}|jjt�}|jdd�\}}t|�}xJt|�|dkrvd|krV||jjt�7}|jdd�\}}|jt|��q.W|jj�|_t t |ddd�|ddd���|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nr<r#r$) r�rZr�r3rFr0r�r�r�rkrlr�)r�r]rr�Zfieldsr�rTZnumberr6r6r7ris  zTarInfo._proc_gnusparse_10c Cs�x�|j�D]�\}}|dkr(t|d|�q |dkrBt|dt|��q |dkr\t|dt|��q |tkr |tkr�yt||�}Wntk r�d}YnX|dkr�|jd�}t|||�q W|j�|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerr�N) r�setattrrF� PAX_FIELDS�PAX_NUMBER_FIELDSr.rKr r)r�rr4r5r=rr6r6r7r\s"  zTarInfo._apply_pax_infoc Cs.y |j|d�Stk r(|j||�SXdS)z1Decode a single field from a pax record. rCN)r;�UnicodeDecodeError)r�rr4Zfallback_encodingZfallback_errorsr6r6r7re,s zTarInfo._decode_pax_fieldcCs2|dkrtd��t|t�\}}|r*|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. rzinvalid offsetr#)rHrYr�)r�rGr`rar6r6r7r[4s zTarInfo._blockcCs |jtkS)N)r�� REGULAR_TYPES)r�r6r6r7r�@sz TarInfo.isregcCs|j�S)N)r�)r�r6r6r7�isfileBszTarInfo.isfilecCs |jtkS)N)r�r)r�r6r6r7r�Dsz TarInfo.isdircCs |jtkS)N)r��SYMTYPE)r�r6r6r7r�Fsz TarInfo.issymcCs |jtkS)N)r��LNKTYPE)r�r6r6r7r�Hsz TarInfo.islnkcCs |jtkS)N)r�r6)r�r6r6r7�ischrJsz TarInfo.ischrcCs |jtkS)N)r�r7)r�r6r6r7�isblkLsz TarInfo.isblkcCs |jtkS)N)r��FIFOTYPE)r�r6r6r7�isfifoNszTarInfo.isfifocCs |jdk S)N)r�)r�r6r6r7�issparsePszTarInfo.issparsecCs|jtttfkS)N)r�r6r7r|)r�r6r6r7�isdevRsz TarInfo.isdevN)r�rhr)r*r'r(r�r�r�r+r,r�r�r�r�rr�r�rr)r�)6rqrrrsrt� __slots__r�rr�propertyr%rrr&r r r�rrr rrrr� classmethodr2r� staticmethodrr9r r-rRrTrSrYrUrVrXrhrgrir\rer[r�rwr�r�r�rzr{r}r~rr6r6r6r7rssf    1  *  3 ?  z c @s�eZdZdZdZdZdZdZeZ e Z dZ e ZeZdZdkdd �Zedddefd d ��Zedld d ��Zedmdd��Zedndd��Zedodd��Zddddd�Zdd�Zdd�Zdd�Zd d!�Zdpd"d#�Zdqdd%�d&d'�Z drdd(�d)d*�Z!dsd+d,�Z"d-d.�Z#dtddd0�d1d2�Z$d3d4�Z%duddd0�d6d7�Z&d8d9�Z'dvd:d;�Z(dd?�Z*d@dA�Z+dwdddB�dCdD�Z,dEdF�Z-dGdH�Z.dIdJ�Z/dKdL�Z0dMdN�Z1dOdP�Z2dQdR�Z3dSdT�Z4dUdV�Z5dWdX�Z6dYdZ�Z7dxd[d\�Z8d]d^�Z9dyd_d`�Z:dadb�Z;dcdd�Zdidj�Z?dS)zrz=The TarFile Class provides an interface to tar archives. rFr#NrzrcCs�ddddd�}||krtd��||_|||_|sj|jdkrVtjj|� rVd|_d|_t||j�}d |_n@|d kr�t|d �r�t |j t t f�r�|j }t|d �r�|j|_d |_|r�tjj |�nd |_ ||_|d k r�||_|d k r�||_|d k r�||_|d k �r||_|d k �r||_| |_| d k �r4|jtk�r4| |_ni|_| d k �rJ| |_| d k �rZ| |_| |_d |_g|_d |_|jj�|_i|_�y�|jdk�r�d |_ |j!�|_ |jdk�r8x�|jj"|j�y|jj#|�}|jj$|�WnTt%k �r|jj"|j�PYn0t&k �r0}zt't |���WYd d }~XnX�q�W|jdk�r�d |_|j�r�|jj(|jj)��}|jj*|�|jt+|�7_Wn&|j�s�|jj,�d |_�YnXd 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�wbZxb)rz�ar{roz!mode must be 'r', 'a', 'w' or 'x'r�r{FNr�rhTrzro)r�r{ro)-r.rh�_moder}r%�exists� bltn_openr�r�r*r�r,rL�abspathr�rPr�� dereference� ignore_zerosr4r5rr�debug� errorlevel� copybufsizer��members�_loadedr�r��inodes� firstmemberr]r�rTr�rwr rr2r r[r0r�)r�r�rhr�rPr�r�r�r4r5rr�r�r�Zmodes�erTr6r6r7r�rs�             $   zTarFile.__init__c s�| r| rtd��|dkr��fdd�}xtt�j|d�D]b}t��j|�}|dk r\|j�} y||d|f|�Sttfk r�|dk r�|j| �w8Yq8Xq8Wtd���nd |k�r |jd d �\} }| p�d} |p�d }|�jkr�t��j|�}n td |��||| |f|�Sd |k�r�|jd d �\} }| �p.d} |�p8d }| dk�rLtd��t || |||�} y�|| | f|�} Wn| j ��YnXd| _ | S|dk�r��j |||f|�Std��dS)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 openrz�r:*cs�j|dkS)N�taropen)� OPEN_METH)r�)r1r6r7�not_compressed sz$TarFile.open..not_compressed)�keyNz%file could not be opened successfully�:r#r�zunknown compression type %r�|r{zmode must be 'r' or 'w'Fr�rozundiscernible mode)rzr�)rzr{)r�r{ro) r.�sortedr�rlr�rrr�r3r�r�r�r�) r1r�rhr�r_�kwargsr�r��funcZ saved_posrg�streamr�r6)r1r7r�sP%             z TarFile.opencKs |dkrtd��||||f|�S)zCOpen uncompressed tar archive name for reading or writing. rzr�r{roz!mode must be 'r', 'a', 'w' or 'x')rzr�r{ro)r.)r1r�rhr�r�r6r6r7r�<szTarFile.taropenr�cKs�|d krtd��yddl}|jWn ttfk rBtd��YnXy|j||d||�}Wn.tk r�|dk r�|dkr�td ���YnXy|j|||f|�}WnBtk r�|j �|dkr�td ���Yn|j ��YnXd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzgzip module is not availablerbznot a gzip fileF)rzr{ro) r.�gzipZGzipFiler��AttributeErrorrr�rr�r�r�)r1r�rhr�� compresslevelr�r�r�r6r6r7�gzopenDs2 zTarFile.gzopencKs�|d krtd��y ddl}Wntk r8td��YnX|j|pD|||d�}y|j|||f|�}WnFttfk r�|j�|dkr�t d ���Yn|j��YnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzbz2 module is not available)r�znot a bzip2 fileF)rzr{ro) r.r�r�rZBZ2Filer�r��EOFErrorr�rr�)r1r�rhr�r�r�r�r�r6r6r7�bz2openfs(  zTarFile.bz2opencKs�|d krtd��y ddl}Wntk r8td��YnX|j|pD|||d�}y|j|||f|�}WnH|jtfk r�|j�|dkr�t d ���Yn|j��YnXd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzlzma module is not available)�presetznot an lzma fileF)rzr{ro) r.r�r�rZLZMAFiler�r�r�r�rr�)r1r�rhr�r�r�r�r�r6r6r7�xzopen�s& zTarFile.xzopenr�r�r�r�)r�r�r�r�c Cs�|jr dSd|_z`|jdkrn|jjttd�|jtd7_t|jt�\}}|dkrn|jjtt|�Wd|j s�|jj �XdS) zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTr�r{ror$r)r�r{ro) r�rhr�r[r1r�r�rY� RECORDSIZEr�r�)r�r`rar6r6r7r��s z TarFile.closecCs"|j|�}|dkrtd|��|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. Nzfilename %r not found)� _getmember�KeyError)r�r�r�r6r6r7� getmember�s  zTarFile.getmembercCs|j�|js|j�|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�r6r6r7� getmembers�szTarFile.getmemberscCsdd�|j�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�qSr6)r�)rnr�r6r6r7rp�sz$TarFile.getnames..)r�)r�r6r6r7�getnames�szTarFile.getnamesc Csp|jd�|dk r|j}|dkr$|}tjj|�\}}|jtjd�}|jd�}|j�}||_ |dkr�t td�r�|j r�tj |�}q�tj |�}ntj|j��}d}|j}t j|��r|j|jf} |j r�|jdkr�| |jkr�||j| kr�t} |j| }nt} | d�rx||j| <nht j|��r"t} nVt j|��r4t} nDt j|��rPt} tj|�}n(t j|��rbt } nt j!|��rtt"} ndS||_||_#|j$|_%|j&|_'| tk�r�|j(|_)nd|_)|j*|_+| |_,||_-t.�r�yt.j/|j%�d|_0Wnt1k �r�YnXt2�r*yt2j3|j'�d|_4Wnt1k �r(YnX| t t"fk�rlt td��rlt td ��rltj5|j6�|_7tj8|j6�|_9|S) 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. �awxNr��lstatr�r#r�major�minor):r�r�r}r%� splitdriver�r�r�r�r�r�r�r�rf�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkr�ryr�S_ISDIRr�S_ISFIFOr|�S_ISLNKrx�readlink�S_ISCHRr6�S_ISBLKr7rh�st_uidr)�st_gidr*�st_sizer'�st_mtimer(r�r��pwd�getpwuidr+r��grpZgetgrgidr,r��st_rdevr�r�r�) r�r��arcnamer�Zdrvr�Zstatresr�Zstmd�inoder�r6r6r7� gettarinfo�s~                 zTarFile.gettarinfoT)r�cCs0|j�|dkr|}�x|D�] }|r�|jdkr:td�nttj|j��td|jpX|j|jpb|jf�|j �sz|j �r�tdd|j |j f�ntd|j �|jdkr�td�ntdtj|j�dd ��t|j|j�r�d nd �|�r"|j��r td |j�|j��r"td |j�t�qWdS)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�r�r�z-> zlink to )r�rhrprfrgr+r)r,r*rzr{r�r�r'r(r�Z localtimer�r�r�r�r�ro)r��verboser�r�r6r6r7rk>s2      z TarFile.list)�filterc Csv|jd�|dkr|}|dk rPddl}|jdtd�||�rP|jdd|�dS|jdk r�tjj|�|jkr�|jdd|�dS|jd|�|j ||�}|dkr�|jdd |�dS|dk r�||�}|dkr�|jdd|�dS|j ��rt |d ��}|j ||�WdQRXnd|j ��rh|j |�|�rrxHtj|�D].}|jtjj||�tjj||�|||d ��q4Wn |j |�dS) 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. `exclude' is a function that should return True for each filename to be excluded. `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�Nrzuse the filter argument insteadr$ztarfile: Excluded %rztarfile: Skipped %rr#ztarfile: Unsupported type %rr�)r�)r�rcrdre�_dbgr�r}r%r�r�r�r��addfiler��listdir�addr�) r�r�r�� recursiveZexcluder�rcr��fr6r6r7r�dsB       z TarFile.addcCs�|jd�tj|�}|j|j|j|j�}|jj|�|jt |�7_|j }|dk r�t ||j|j |d�t |j t�\}}|dkr�|jjtt|�|d7}|j|t7_|jj|�dS)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)r_rr#)r�r rrPr4r5r�r[r�r0r�rXr'rYr�r1r�r�)r�r�r�rTr_r`rar6r6r7r��s   zTarFile.addfilec"CsH|dk�r|j}|dk�r�tjjd�}|dkr�y tt�}Wntk rNYnBXddl}|jddd�}|�|j |�WdQRX|jdddd�}|r�y t |}Wn&t k r�t d|�d ��d�YnX||_|St �r�tjdt�tStSt|t��rtd��|St|��r|Syt |St k �rBt d|�d ��d�YnXdS)NZ PYTHON_TARFILE_EXTRACTION_FILTERr�#)Z interpolationZcomment_prefixesr�r�)Zfallbackzfilter z not foundz4The default behavior of tarfile extraction has been z$changed to disallow common exploits z(including CVE-2007-4559). z1By default, absolute/parent paths are disallowed z and some mode bits are cleared. z/See https://access.redhat.com/articles/7004769 zfor more details.z#String names are not supported for z2TarFile.extraction_filter. Use a function such as ztarfile.data_filter directly.)r�zXThe default behavior of tarfile extraction has been changed to disallow common exploits zsThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. z�The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 aThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 for more details.zUString names are not supported for TarFile.extraction_filter. Use a function such as zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)�extraction_filterr}�environr5r��_CONFIG_FILENAME�FileNotFoundError� configparserZ ConfigParserZ read_file�_NAMED_FILTERSr�r.�_RH_SAFER_DEFAULTrcrd�RuntimeWarningr�r�r*r,� TypeError�callable)r�r�r��filer�Zconfr6r6r7�_get_filter_function�sR       zTarFile._get_filter_function�.)� numeric_ownerr�c"Cs�g}|j|�}|dkr|}xT|D]L}|j|||�\}} |dkr@q |j�rR|j| �|j|||j� ||d�q W|jdd�dd��x$|D�]} y�y|| |�}Wn4tk r�} z|j| t| ��w�WYdd} ~ XnX|dkr�|j| d�w�t j j ||j �} yt j | �} Wn$tk �r.|j|d�w�YnXtj| j��sL|j|d �w�|j|| |d �|j|| �|j|| �Wq�tk �r�} z|j| �WYdd} ~ Xq�Xq�WdS) 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_attrsr��filter_functioncSs|jS)N)r�)r�r6r6r7� sz$TarFile.extractall..T)r��reversezexcluded by filterZmissingznot a directory)r�)r��_get_extract_tarinfor�r�� _extract_one�sort�_FILTER_ERRORS�_log_no_directory_fixup�reprr}r%r�r�r�r�rfr�r��chown�utime�chmodr �_handle_nonfatal_error)r�r%r�r�r�Z directoriesr�r�r�� unfiltered�exc�dirpathr�r�r6r6r7� extractall�sP       zTarFile.extractallcCs|jdd|j|f�dS)Nr$z(tarfile: Not fixing up directory %r (%s))r�r�)r�r��reasonr6r6r7r�4 szTarFile._log_no_directory_fixupr�c Cs8|j|�}|j|||�\}}|dk r4|j||||�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)r�r�r�) r�r�r%r�r�r�r�r�r�r6r6r7�extract8 s  zTarFile.extractcCs�t|t�r|j|�}n|}d}y|||�}WnZttfk r\}z|j|�WYdd}~Xn,tk r�}z|j|�WYdd}~XnX|dkr�|jdd|j �dS|j �r�t j |�}t j j||j�|_||fS)z�Get (filtered, unfiltered) TarInfos from *member* *member* might be a string. Return (None, None) if not found. Nr$ztarfile: Excluded %r)NN)r*r,r�r�r��_handle_fatal_errorr r�r�r�r�r r}r%r�r�r)r�r�r�r%r��filteredr�r6r6r7r�L s"   zTarFile._get_extract_tarinfocCs�|jd�y&|j|tjj||j�||||d�WnVtk r\}z|j|�WYdd}~Xn,tk r�}z|j |�WYdd}~XnXdS)z�Extract from filtered tarinfo to disk. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) rz)r�r�r��extraction_rootN) r��_extract_memberr}r%r�r�r�r�r r�)r�r�r%r�r�r�r�r6r6r7r�j s  zTarFile._extract_onecCs"|jdkr�n|jdd|�dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#z tarfile: %sN)r�r�)r�r�r6r6r7r�~ s zTarFile._handle_nonfatal_errorcCsn|jdkr�n\t|t�rP|jdkr6|jdd|j�qj|jdd|j|jf�n|jddt|�j|f�dS)z1Handle "fatal" error according to self.errorlevelrNr#z tarfile: %sztarfile: %s %rztarfile: %s %s)r�r*r��filenamer��strerrorr�rq)r�r�r6r6r7r�� s   zTarFile._handle_fatal_errorcCs�|jd�t|t�r |j|�}n|}|j�s6|jtkrB|j||�S|j�sR|j �rzt|j t �rht d��q~|j |j|��SndSdS)z�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. Otherwise, None is returned. rzz'cannot extract (sym)link as file objectN)r�r*r,r�r�r�rZ� fileobjectr�r�r�r�r � extractfile�_find_link_target)r�r�r�r6r6r7r�� s      zTarFile.extractfile)r�r�cCs\|jd�}|jdtj�}tjj|�}|r@tjj|� r@tj|�|j�sP|j �rj|j dd|j |j f�n|j d|j �|j �r�|j||�n�|j�r�|j||�n~|j�r�|j||�nh|j�s�|j�r�|j||�nJ|j�s�|j �r�|j||||d�n&|jtk�r|j||�n |j||�|�rX|j|||�|j ��sX|j||�|j||�dS)z�Extract the filtered TarInfo object tarinfo to a physical file called targetpath. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) r�r#z%s -> %s)r�r�N)rKr�r}r�r%r�r��makedirsr�r�r�r�r�r��makefiler��makedirr}�makefiforzr{�makedev�makelink_with_filterr�rZ� makeunknownr�r�r�)r�r�� targetpathr�r�r�r�Z upperdirsr6r6r7r�� s:        zTarFile._extract_memberc Cs@y&|jdkrtj|�n tj|d�Wntk r:YnXdS)z,Make a directory called targetpath. Ni�)rhr}�mkdir�FileExistsError)r�r�rr6r6r7r� s   zTarFile.makedircCs�|j}|j|j�|j}t|d��f}|jdk rrx,|jD]"\}}|j|�t|||t|�q6W|j|j�|j �nt|||jt|�WdQRXdS)z'Make a file called targetpath. r�N) r�r�r�r�r�r�rXrr'�truncate)r�r�r�sourcer_�targetr�r'r6r6r7r� s      zTarFile.makefilecCs"|j||�|jdd|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)rr�r�)r�r�rr6r6r7r s zTarFile.makeunknowncCs"ttd�rtj|�ntd��dS)z'Make a fifo called targetpath. �mkfifozfifo not supported by systemN)r�r}rr )r�r�rr6r6r7r s  zTarFile.makefifocCsnttd� sttd� r td��|j}|dkr2d}|j�rF|tjO}n |tjO}tj||tj |j |j ��dS)zzFilter for extraction)�metavar�choicesr/z-lz--list� zShow listing of a tarfile)r0r/z-ez --extract�+� zExtract tarfile into target dir)�nargsr0r/z-cz--create��zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction rz)r�z{!r} is a tar archive.z{!r} is not a tar archive. zr:*)r�r$)r%r�r�z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r�r�r�)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)r2r4)r6r7)�argparse�ArgumentParser� add_argumentr�Zadd_mutually_exclusive_group� parse_argsr�r��exitZtestrrr�rormr%r�rPrkrr0r}�curdirZ format_helpr�Zcreate�popr%�splitextr�)r8r+�parserrc�argsr\r�Ztfr=r'Ztar_namermZextZ compressionsZtar_modeZ tar_files� file_namer6r6r7�mainc s�                  rC�__main__)r%r&r'r(r)r*r+r,)T)trt�version� __author__Z__date__Z __cvsid__� __credits__�builtinsrr�rmr}r�rWrfr�rSr �rercr�r�r�r��NotImplementedErrorrr�� NameError�__all__r�r�r1r�r�rrrrr4rrHryrxr6r7rr|ZCONTTYPEr"r!rIr.r0rWr rrrrZrvrLrsrfr+rFrtr�r �getfilesystemencodingr8r=rKrQrUrXrgrp� Exceptionrr rrr r rurvrwrHrxryr��objectr�r��BufferedReaderr�r�r�r�r�r�r�r�r�r�r�r�r�r�r �compilerarrrrCrqr6r6r6r7�s&         wh   D h  b