Your IP : 3.147.205.114


Current Path : /opt/alt/python311/lib64/python3.11/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/__pycache__/tarfile.cpython-311.opt-2.pyc

�

c��fd���d�	dZdZdZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZ	ddlZn
#e$rdZYnwxYw	ddlZn
#e$rdZYnwxYweefZ	eefz
Zn#e$rYnwxYwgd�ZdZdZed	zZd
ZdZdZdZd
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2e2Z3e!e"e#e$e'e(e)e%e&e*e+e,fZ4e!e"e)e,fZ5e*e+e,fZ6dZ7hd�Z8e9e9e9e:e:e:d �Z;ej<d!krd"Z=nej>��Z=d#�Z?d$�Z@d%�ZAd&e3fd'�ZBd(�ZCdedfd)�ZDd*�ZEGd+�d,eF��ZGGd-�d.eG��ZHGd/�d0eG��ZIGd1�d2eG��ZJGd3�d4eG��ZKGd5�d6eG��ZLGd7�d8eL��ZMGd9�d:eL��ZNGd;�d<eL��ZOGd=�d>eL��ZPGd?�d@eL��ZQGdA�dB��ZRGdC�dD��ZSGdE�dFeT��ZUGdG�dHeT��ZVGdI�dJejW��ZXGdK�dLeG��ZYGdM�dNeY��ZZGdO�dPeY��Z[GdQ�dReY��Z\GdS�dTeY��Z]GdU�dVeY��Z^dedX�Z_dY�Z`dZ�Zad[�Zbe`eaebd\�ZceT��Zdejed]��ZfGd^�d_eT��ZgGd`�daeT��Zhdb�ZiehjZdc�Zjekddkrej��dSdS)fz0.9.0u"Lars Gustäbel (lars@gustaebel.de)u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.�)�openN)�TarFile�TarInfo�
is_tarfile�TarError�	ReadError�CompressionError�StreamError�ExtractError�HeaderError�ENCODING�USTAR_FORMAT�
GNU_FORMAT�
PAX_FORMAT�DEFAULT_FORMATr�i�sustar  sustar00�d��0�1�2�3�4�5�6�7�L�K�S�x�g�X��)�path�linkpath�size�mtime�uid�gid�uname�gname>r&r-r,r')�atime�ctimer)r*r+r(�nt�utf-8c��	|�td���|�||��}|d|�|t|��z
tzzS)Nzmetadata cannot contain None)�
ValueError�encode�len�NUL)�s�length�encoding�errorss    �./opt/alt/python311/lib64/python3.11/tarfile.py�stnr<�sP����y��7�8�8�8�	����6�"�"�A��W�f�W�:��#�a�&�&��C�/�/�/�c�z�	|�d��}|dkr
|d|�}|�||��S)Nr���)�find�decode)r7r9r:�ps    r;�ntsrC�s@���	���u�
�
�A��B�w�w�
�b�q�b�E���8�8�H�f�%�%�%r=c�~�	|ddvr]d}tt|��dz
��D]}|dz}|||dzz
}�|ddkrdt|��dz
z|z
}nT	t|dd��}t|���pd	d��}n#t
$rt
d
���wxYw|S)Nr)��r$�rF��ascii�strict�0�invalid header)�ranger5rC�int�stripr3�InvalidHeaderError)r7�n�is   r;�ntirS�s����	��t�~���
���s�1�v�v��z�"�"�	�	�A�
�!�G�A�
��1�q�5��M�A�A��Q�4�5�=�=��#�a�&�&�1�*�%��)�*�A��	7��A�w��)�)�A��A�G�G�I�I�$��a�(�(�A�A���	7�	7�	7�$�%5�6�6�6�	7�����Hs�*5B � B:rGc���	|}t|��}d|cxkrd|dz
zkr$nn!td|dz
|fzd��tz}n�|tkr�d|dz
z|cxkrd|dz
zkrfnnc|dkrt	dg��}nt	dg��}d|z|z}t|dz
��D] }|�d|dz��|dz}�!ntd	���|S)
NrrGr$z%0*orIrHrErFzoverflow in number field)rN�bytesr6r�	bytearrayrM�insertr3)rQ�digits�format�
original_nr7rRs      r;�itnr[�s8����J��A���A��A�!�!�!�!��f�q�j�!�!�!�!�!�!��&�F�Q�J��?�*�G�4�4�s�:���	�:�	�	�3�6�A�:�#6�"6�!�"Q�"Q�"Q�"Q�c�f�q�j�>Q�"Q�"Q�"Q�"Q�"Q���6�6��5�'�"�"�A�A��5�'�"�"�A��v�
��!�A��v��z�"�"�	�	�A�
�H�H�Q��E�	�"�"�"�
�!�G�A�A�	��3�4�4�4��Hr=c��	dttjd|����z}dttjd|����z}||fS)NrH�
148B8x356B�
148b8x356b)�sum�struct�unpack_from)�buf�unsigned_chksum�
signed_chksums   r;�calc_chksumsre�sR����C�� 2�<�� E� E�F�F�F�O��#�f�0��s�C�C�D�D�D�M��M�)�)r=c���	|pd}|dkrdS|�tj|||��dSt||��\}}t|��D]J}|�|��}t|��|kr|d���|�|���K|dkrH|�|��}t|��|kr|d���|�|��dS)Ni@r�unexpected end of data)�shutil�copyfileobj�divmodrM�readr5�write)	�src�dstr8�	exception�bufsize�blocks�	remainder�brbs	         r;riri�s�����"��G�
��{�{���
�~���3��W�-�-�-����v�w�/�/��F�I�
�6�]�]�����h�h�w�����s�8�8�g����)�4�5�5�5��	�	�#������A�~�~��h�h�y�!�!���s�8�8�i����)�4�5�5�5��	�	�#����
�Fr=c��ttjdd��}|�)|�|d���|��}t|d���dS)Nr9�backslashreplace� )�end)�getattr�sys�stdoutr4rA�print)r7r9s  r;�_safe_printr|sV���s�z�:�t�4�4�H���
�H�H�X�1�2�2�9�9�(�C�C��	�!�������r=c��eZdZ	dS)rN��__name__�
__module__�__qualname__�r=r;rrs��������Dr=rc��eZdZ	dS)rNr~r�r=r;rrs������/��Dr=rc��eZdZ	dS)rNr~r�r=r;rrs������0��Dr=rc��eZdZ	dS)r	Nr~r�r=r;r	r	s������8��Dr=r	c��eZdZ	dS)r
Nr~r�r=r;r
r
s������G��Dr=r
c��eZdZ	dS)rNr~r�r=r;rrs������+��Dr=rc��eZdZ	dS)�EmptyHeaderErrorNr~r�r=r;r�r�!s������&��Dr=r�c��eZdZ	dS)�TruncatedHeaderErrorNr~r�r=r;r�r�$s������*��Dr=r�c��eZdZ	dS)�EOFHeaderErrorNr~r�r=r;r�r�'s������,��Dr=r�c��eZdZ	dS)rPNr~r�r=r;rPrP*s������(��Dr=rPc��eZdZ	dS)�SubsequentHeaderErrorNr~r�r=r;r�r�-s������=��Dr=r�c�(�eZdZ	d�Zd�Zd�Zd�ZdS)�
_LowLevelFilec��tjtjtjztjzd�|}ttd��r|tjz}tj||d��|_dS)N��r�w�O_BINARYi�)	�os�O_RDONLY�O_WRONLY�O_CREAT�O_TRUNC�hasattrr�r�fd)�self�name�modes   r;�__init__z_LowLevelFile.__init__:si������r�z�)�B�J�6�
�
�����2�z�"�"�	 ��B�K��D��'�$��e�,�,����r=c�8�tj|j��dS�N)r��closer��r�s r;r�z_LowLevelFile.closeCs��
��������r=c�6�tj|j|��Sr�)r�rkr��r�r(s  r;rkz_LowLevelFile.readFs���w�t�w��%�%�%r=c�:�tj|j|��dSr�)r�rlr��r�r7s  r;rlz_LowLevelFile.writeIs��
����!�����r=N)rr�r�r�r�rkrlr�r=r;r�r�4sU�������
-�-�-����&�&�&�����r=r�c�Z�eZdZ	d�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
dd
�Zd�Zd�Z
d
�ZdS)�_Streamc��	d|_|�t||��}d|_|dkr#t|��}|���}|pd|_||_||_||_||_d|_	d|_
d|_	|dkr�	ddl}n#t$rtd��d�wxYw||_|�d��|_|d	kr"|j|_|���dS|���dS|d
krs	ddl}n#t$rtd��d�wxYw|d	kr.d|_|���|_t2|_dS|���|_dS|dkrs	ddl}n#t$rtd
��d�wxYw|d	kr.d|_|���|_|j|_dS|���|_dS|dkrtd|z���dS#|js|j���d|_�xYw)NTF�*�r=r�gzzzlib module is not availabler��bz2�bz2 module is not available�xz�lzma module is not available�tar�unknown compression type %r) �_extfileobjr��_StreamProxy�getcomptyper�r��comptype�fileobjrprb�pos�closed�zlib�ImportErrorr	�crc32�crc�errorro�
_init_read_gz�_init_write_gzr��dbuf�BZ2Decompressor�cmp�OSError�
BZ2Compressor�lzma�LZMADecompressor�	LZMAError�LZMACompressorr�)	r�r�r�r�r�rpr�r�r�s	         r;r�z_Stream.__init__Xs���	�����?�#�D�$�/�/�G�$�D���s�?�?�#�7�+�+�G��*�*�,�,�H��
���	���	� ��
����������������-	��4���U��K�K�K�K��"�U�U�U�*�+I�J�J�PT�T�U���� ��	��:�:�c�?�?����3�;�;�%)�Z�D�N��&�&�(�(�(�(�(��'�'�)�)�)�)�)��U�"�"�T��J�J�J�J��"�T�T�T�*�+H�I�I�t�S�T�����3�;�;� #�D�I�"�2�2�4�4�D�H�%,�D�N�N�N�"�0�0�2�2�D�H�H�H��T�!�!�U��K�K�K�K��"�U�U�U�*�+I�J�J�PT�T�U�����3�;�;� #�D�I�#�4�4�6�6�D�H�%)�^�D�N�N�N�#�2�2�4�4�D�H�H�H��U�"�"�&�'D�x�'O�P�P�P�#�"��	��#�
%���"�"�$�$�$��D�K����sy�H�
B�H�B-�-A
H�9H�H�D�H�D6�65H�-H�H�F�H�F/�/5H�&H�H�*Ic�d�t|d��r|js|���dSdSdS)Nr�)r�r�r�r�s r;�__del__z_Stream.__del__�sB���4��"�"�	�4�;�	��J�J�L�L�L�L�L�	�	�	�	r=c�B�	|j�d|jj|jj|jjd��|_t
jdttj	������}|�
d|zdz��|j�d��r|jdd�|_tj�|j��|_|�
|j�dd	��t"z��dS)
N�	r�<Ls�s��.gz���z
iso-8859-1�replace)r��compressobj�DEFLATED�	MAX_WBITS�
DEF_MEM_LEVELr�r`�packrN�time�_Stream__writer��endswithr�r&�basenamer4r6)r��	timestamps  r;r�z_Stream._init_write_gz�s���	��9�(�(��D�I�,>�-1�Y�-@�,@�,0�I�,C�,-�/�/����K��c�$�)�+�+�&6�&6�7�7�	����(�9�4�{�B�C�C�C��9���e�$�$�	'��	�#�2�#��D�I��G�$�$�T�Y�/�/��	����T�Y�%�%�l�I�>�>��D�E�E�E�E�Er=c��	|jdkr%|j�||j��|_|xjt|��z
c_|jdkr|j�|��}|�|��dS)Nr�r�)	r�r�r�r�r�r5r��compressr�r�s  r;rlz
_Stream.write�sx��	��=�D� � ��y���q�$�(�3�3�D�H����C��F�F�����=�E�!�!���!�!�!�$�$�A����Q�����r=c�*�	|xj|z
c_t|j��|jkrd|j�|jd|j���|j|jd�|_t|j��|jk�bdSdSr�)rbr5rpr�rlr�s  r;�__writez_Stream.__write�s���	�	
���A�
����$�(�m�m�d�l�*�*��L���t�x�
���
�6�7�7�7��x���
�
�.�D�H��$�(�m�m�d�l�*�*�*�*�*�*r=c��	|jrdSd|_	|jdkr2|jdkr'|xj|j���z
c_|jdkr�|jr�|j�|j��d|_|jdkrg|j�tj	d|j
����|j�tj	d|jdz����|js|j�
��dSdS#|js|j�
��wwxYw)NTr�r�r=r�r�l��)r�r�r�rbr��flushr�rlr`r�r�r�r�r�r�s r;r�z
_Stream.close�s?��	��;�	��F����	%��y�C���D�M�U�$:�$:����D�H�N�N�,�,�,����y�C���D�H����"�"�4�8�,�,�,�����=�D�(�(��L�&�&�v�{�4���'B�'B�C�C�C��L�&�&�v�{�4���J�9N�'O�'O�P�P�P��#�
%���"�"�$�$�$�$�$�
%�
%��4�#�
%���"�"�$�$�$�$�
%���s�C'D�#Ec��	|j�|jj��|_d|_|�d��dkrt
d���|�d��dkrtd���t|�d����}|�d��|d	zr]t|�d����d
t|�d����zz}|�	|��|dzr%	|�d��}|r|tkrn�$|d
zr%	|�d��}|r|tkrn�$|dzr|�d��dSdS)Nr=r%s��not a gzip filer$�zunsupported compression method��rHrGT�)r��
decompressobjr�r�r��
_Stream__readrr	�ordrkr6)r��flag�xlenr7s    r;r�z_Stream._init_read_gz�s���	��9�*�*�D�I�,?�+?�@�@�����	��;�;�q�>�>�[�(�(��-�.�.�.��;�;�q�>�>�W�$�$�"�#C�D�D�D��4�;�;�q�>�>�"�"�����A�����!�8�	��t�{�{�1�~�~�&�&��s�4�;�;�q�>�>�/B�/B�)B�B�D��I�I�d�O�O�O��!�8�	�
��K�K��N�N����A��H�H��
��"�9�	�
��K�K��N�N����A��H�H��
��!�8�	��K�K��N�N�N�N�N�	�	r=c��	|jSr�)r�r�s r;�tellz_Stream.tell�s��	��x�r=rc��	||jz
dkrbt||jz
|j��\}}t|��D]}|�|j���|�|��ntd���|jS)Nrz seeking backwards is not allowed)r�rjrprMrkr
)r�r�rqrrrRs     r;�seekz_Stream.seek�s���	����>�Q��� &�s�T�X�~�t�|� D� D��F�I��6�]�]�
(�
(���	�	�$�,�'�'�'�'��I�I�i� � � � ��@�A�A�A��x�r=c�l�	|�|��}|xjt|��z
c_|Sr�)�_readr�r5)r�r(rbs   r;rkz_Stream.reads1��C��j�j��������C��H�H�����
r=c�*�	|jdkr|�|��St|j��}|jg}||kr�|jr|j}d|_n"|j�|j��}|snk	|j�	|��}n"#|j
$r}td��|�d}~wwxYw|�|��|t|��z
}||k��d�
|��}||d�|_|d|�S)Nr�r=zinvalid compressed data)r�r�r5r�rbr�rkrpr��
decompressror�append�join)r�r(�c�trb�es      r;r�z
_Stream._reads*��	��=�E�!�!��;�;�t�$�$�$���	�N�N��
�Y�K���$�h�h��x�
��h�������l�'�'���5�5�����
B��h�)�)�#�.�.�����>�
B�
B�
B�� 9�:�:��A�����
B����
�H�H�S�M�M�M�
��S���M�A��$�h�h�
�H�H�Q�K�K���d�e�e�H��	���$��x�s�=B�
B7�"B2�2B7c�B�	t|j��}|jg}||krO|j�|j��}|sn-|�|��|t|��z
}||k�Od�|��}||d�|_|d|�S)Nr=)r5rbr�rkrpr�r�)r�r(r�r�rbs     r;�__readz_Stream.__read.s���	�
���M�M��
�X�J���$�h�h��,�#�#�D�L�1�1�C��
��
�H�H�S�M�M�M�
��S���M�A��$�h�h�
�H�H�Q�K�K���T�U�U�8�����$��x�r=N)r)rr�r�r�r�r�rlr�r�r�r�r�rkr�r�r�r=r;r�r�Ls�������	�D�D�D�L���F�F�F� ���/�/�/�%�%�%�,���>���
����������6����r=r�c�(�eZdZ	d�Zd�Zd�Zd�ZdS)r�c�\�||_|j�t��|_dSr�)r�rk�	BLOCKSIZErb)r�r�s  r;r�z_StreamProxy.__init__Ds$������<�$�$�Y�/�/����r=c�2�|jj|_|jSr�)r�rkrbr�s  r;rkz_StreamProxy.readHs���L�%��	��x�r=c���|j�d��rdS|jdd�dkr|jdd�dkrd	S|j�d
��rdSdS)
Ns�r�r�sBZhr��
s1AY&SYr�)s]�s�7zXZr�r�)rb�
startswithr�s r;r�z_StreamProxy.getcomptypeLsp���8����/�/�	��4�
�X�a��c�]�f�
$�
$���!�B�$��9�)D�)D��5�
�X�
 �
 �!C�
D�
D�	��4��5r=c�8�|j���dSr�)r�r�r�s r;r�z_StreamProxy.closeVs����������r=N)rr�r�r�rkr�r�r�r=r;r�r�?sU�������0�0�0�����������r=r�c�^�eZdZ	dd�Zd�Zd�Zd�Zd�Zd�Ze	j
fd�Zdd	�Zd
�Z
d�ZdS)
�_FileInFileNc���||_||_||_d|_t	|dd��|_d|_|�d|fg}d|_g|_d}|j}|D]T\}}||kr|j�	d||df��|j�	d|||z|f��||z
}||z}�U||jkr%|j�	d||jdf��dSdS)Nrr�FT)
r��offsetr(�positionrxr�r��	map_index�mapr�)r�r�rr(�	blockinfo�lastpos�realposs       r;r�z_FileInFile.__init__cs����������	���
��G�V�T�2�2��	�������T���I����������+��%�	$�	$�L�F�D������������� >�?�?�?��H�O�O�T�6�6�D�=�'�B�C�C�C��t�O�G��t�m�G�G��T�Y����H�O�O�U�G�T�Y��=�>�>�>�>�>��r=c��dSr�r�r�s r;r�z_FileInFile.flush|s���r=c��dS�NTr�r�s r;�readablez_FileInFile.readables���tr=c��dS�NFr�r�s r;�writablez_FileInFile.writable�s���ur=c�4�|j���Sr�)r��seekabler�s r;rz_FileInFile.seekable�s���|�$�$�&�&�&r=c��	|jSr�)r
r�s r;r�z_FileInFile.tell�s��	��}�r=c���	|tjkr)tt|d��|j��|_n�|tjkrG|dkrt|j|zd��|_nst|j|z|j��|_nP|tjkr1tt|j|z|j��d��|_ntd���|jS)NrzInvalid argument)	�io�SEEK_SET�min�maxr(r
�SEEK_CUR�SEEK_ENDr3)r�r
�whences   r;r�z_FileInFile.seek�s���	��R�[� � ���H�a� 0� 0�$�)�<�<�D�M�M�
�r�{�
"�
"��!�|�|� #�D�M�H�$<�a� @� @��
�
� #�D�M�H�$<�d�i� H� H��
�
�
�r�{�
"�
"���D�I��$8�$�)� D� D�a�H�H�D�M�M��/�0�0�0��}�r=c��	|�|j|jz
}nt||j|jz
��}d}|dk�r
	|j|j\}}}}||jcxkr|krnnn5|xjdz
c_|jt|j��krd|_�bt|||jz
��}|rg|j�||j|z
z��|j�|��}t|��|krtd���||z
}n
|t|zz
}||z}|xj|z
c_|dk��
|S)Nr=rTr$rg)r(r
r rrr5r�r�rkrr6)	r�r(rb�data�start�stoprr8rss	         r;rkz_FileInFile.read�sq��	��<��9�t�}�,�D�D��t�T�Y���6�7�7�D����Q�h�h�
+�,0�H�T�^�,D�)��e�T�6��D�M�0�0�0�0�D�0�0�0�0�0���N�N�a�'�N�N��~��T�X���6�6�)*���
+���t�d�m�3�4�4�F��
$���!�!�&�D�M�E�,A�"B�C�C�C��L�%�%�f�-�-���q�6�6�V�#�#�#�$<�=�=�=��q�����s�V�|�#���F�N�D��M�M�V�#�M�M�'�Q�h�h�(�
r=c��|�t|����}||dt|���<t|��Sr�)rkr5)r�rsrbs   r;�readintoz_FileInFile.readinto�s7���i�i��A��������)�3�s�8�8�)���3�x�x�r=c��d|_dSr)r�r�s r;r�z_FileInFile.close�s
������r=r�)rr�r�r�r�rrrr�rrr�rkr*r�r�r=r;r
r
]s��������
?�?�?�?�2
�
�
�������'�'�'����
%'�K����� ����>���
����r=r
c���eZdZ�fd�Z�xZS)�ExFileObjectc���t|j|j|j|j��}t���|��dSr�)r
r��offset_datar(�sparse�superr�)r��tarfile�tarinfor��	__class__s    �r;r�zExFileObject.__init__�sB����g�o�w�/B���g�n�.�.��
������!�!�!�!�!r=�rr�r�r��
__classcell__�r4s@r;r-r-�s8�������"�"�"�"�"�"�"�"�"r=r-c��eZdZdS)�FilterErrorNr~r�r=r;r9r9�s�������Dr=r9c���eZdZ�fd�Z�xZS)�AbsolutePathErrorc�j��||_t���d|j�d���dS)Nzmember z has an absolute path�r3r1r�r��r�r3r4s  �r;r�zAbsolutePathError.__init__�s6������
�����H�7�<�H�H�H�I�I�I�I�Ir=r5r7s@r;r;r;�sA�������J�J�J�J�J�J�J�J�Jr=r;c���eZdZ�fd�Z�xZS)�OutsideDestinationErrorc���||_||_t���|j�d|�d�dz��dS)Nz would be extracted to �, � which is outside the destination�r3�_pathr1r�r��r�r3r&r4s   �r;r�z OutsideDestinationError.__init__�sT��������
�
�����G�L�M�M�4�M�M�M�=�>�	?�	?�	?�	?�	?r=r5r7s@r;r@r@��8�������?�?�?�?�?�?�?�?�?r=r@c���eZdZ�fd�Z�xZS)�SpecialFileErrorc�h��||_t���|j�d���dS)Nz is a special filer=r>s  �r;r�zSpecialFileError.__init__�s3������
�����G�L�>�>�>�?�?�?�?�?r=r5r7s@r;rIrI�sA�������@�@�@�@�@�@�@�@�@r=rIc���eZdZ�fd�Z�xZS)�AbsoluteLinkErrorc�h��||_t���|j�d���dS)Nz is a link to an absolute pathr=r>s  �r;r�zAbsoluteLinkError.__init__�s3������
�����G�L�J�J�J�K�K�K�K�Kr=r5r7s@r;rLrL�sA�������L�L�L�L�L�L�L�L�Lr=rLc���eZdZ�fd�Z�xZS)�LinkOutsideDestinationErrorc���||_||_t���|j�d|�d�dz��dS)Nz would link to rBrCrDrFs   �r;r�z$LinkOutsideDestinationError.__init__�sT��������
�
�����G�L�E�E�4�E�E�E�=�>�	?�	?�	?�	?�	?r=r5r7s@r;rOrO�rGr=rOTc��i}|j}tj�|��}|�dtjf��r,|j�dtjz��x}|d<tj�|��rt|���tj�tj�	||����}tj�
||g��|krt||���|j}|��|dz}|rr|�
��s|���r|dzs|dz}|dz}n:|���s|���rd}nt#|���||jkr||d<|�r]|j�d|d<|j�d|d	<|j�d|d
<|j�d|d<|���s|����rtj�|j��rt/|���|���rDtj�	|tj�|��|j��}n%tj�	||j��}tj�|��}tj�
||g��|krt3||���|S)N�/r�i��@i�����r�r*r+r,r-)r�r�r&�realpathr�sep�lstrip�isabsr;r��
commonpathr@r��isreg�islnk�isdir�issymrIr*r+r,r-�linknamerL�dirnamerO)�member�	dest_path�for_data�	new_attrsr��target_pathr�s       r;�_get_filtered_attrsre�s����I��;�D��� � ��+�+�I�����R�V�}�%�%�D�#)�;�#5�#5�c�B�F�l�#C�#C�C��y�� �	�w�}�}�T���(� ��'�'�'��'�"�"�2�7�<�<�	�4�#@�#@�A�A�K�	�w���;�	�2�3�3�y�@�@�%�f�k�:�:�:��;�D����e�|���
	/��|�|�~�~�
/������
/��e�|�#��F�N�D���
��������
/�6�<�<�>�>�
/����'�v�.�.�.��6�;��� $�I�f���G��:�!�#�I�e���:�!�#�I�e���<�#�!%�I�g���<�#�!%�I�g���<�<�>�>�	G�V�\�\�^�^�	G��w�}�}�V�_�-�-�
0�'��/�/�/��|�|�~�~�
<� �g�l�l�9�+-�7�?�?�4�+@�+@�+1�?�<�<���!�g�l�l�9�+1�?�<�<���'�*�*�;�7�7�K��w�!�!�;�	�":�;�;�y�H�H�1�&�+�F�F�F��r=c��|Sr�r�)r`ras  r;�fully_trusted_filterrg1s���Mr=c�N�t||d��}|r|jdi|�ddi��S|S)NF�deepr��rer��r`rarcs   r;�
tar_filterrl4sC��#�F�I�u�=�=�I��7��v�~�6�6�	�6�6��6�6�6�6��Mr=c�N�t||d��}|r|jdi|�ddi��S|S)NTriFr�rjrks   r;�data_filterrn:sC��#�F�I�t�<�<�I��7��v�~�6�6�	�6�6��6�6�6�6��Mr=)�
fully_trustedr�r&s([0-9]{1,20}) c�p�eZdZ	edTidd�dd�dd�dd�d	d
�dd�d
d�dd�dd�dd�dd�dd�dd�dd�dd�dd �d!d"�d#d$�d%d$�d&d$��ZdUd(�Zed)���Zejd*���Zed+���Z	e	jd,���Z	d-�Z
eeeeeeeed.ed/�
d0�Zd1�Z
eed2fd3�Zd4�Zd5�Zd6�Zed7���Zd8�Zed9���Zed:���Zed;���Zed<���Zed=���Zed>���Zd?�Zd@�ZdA�Z dB�Z!dC�Z"dD�Z#dE�Z$dF�Z%dG�Z&dH�Z'dI�Z(dJ�Z)dK�Z*dL�Z+dM�Z,dN�Z-dO�Z.dP�Z/dQ�Z0dR�Z1dS�Z2d$S)Vrr�zName of the archive member.r�zPermission bits.r*z6User ID of the user who originally stored this member.r+z7Group ID of the user who originally stored this member.r(zSize in bytes.r)zTime of last modification.�chksumzHeader checksum.�typez�File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.r^zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.r,z
User name.r-zGroup name.�devmajorzDevice major number.�devminorzDevice minor number.rzThe tar header starts here.r/zThe file's data starts here.�pax_headerszMA dictionary containing key-value pairs of an associated pax extended header.r0zSparse member information.r2N�_sparse_structs�_link_targetr�c��	||_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)rq�REGTYPErrr^r,r-rsrtrr/r0ru�r�r�s  r;r�zTarInfo.__init__ss���	���	���	���������	���
������	���
���
���
���
���
��������������r=c��	|jSr��r�r�s r;r&zTarInfo.path�s
��2��y�r=c��||_dSr�r|rzs  r;r&zTarInfo.path�s
����	�	�	r=c��	|jSr��r^r�s r;r'zTarInfo.linkpath�s
��:��}�r=c��||_dSr�r)r�r^s  r;r'zTarInfo.linkpath�s
�� ��
�
�
r=c�J�d|jj|jt|��fzS)Nz<%s %r at %#x>)r4rr��idr�s r;�__repr__zTarInfo.__repr__�s!���4�>�#:�4�9�R��X�X�"N�N�Nr=T)
r�r)r�r^r*r+r,r-ri�_KEEPc
��	|	rtj|��}ntj|��}||
ur||_||
ur||_||
ur||_||
ur||_||
ur||_||
ur||_||
ur||_||
ur||_	|Sr�)
�copy�deepcopyr�r)r�r^r*r+r,r-)r�r�r)r�r^r*r+r,r-rir��results            r;r�zTarInfo.replace�s���	��	%��]�4�(�(�F�F��Y�t�_�_�F��u����F�K����� �F�L��u����F�K��5� � �&�F�O��e����F�J��e����F�J����� �F�L����� �F�L��
r=c�@�	|j�d}n
|jdz}|j||j|j|j|j|j|j|j|j	|j
|j|jd�
}|dtkr+|d�d��s|dxxdz
cc<|S)N�)
r�r�r*r+r(r)rqrrr^r,r-rsrtrrr�rR)r�r�r*r+r(r)rqrrr^r,r-rsrt�DIRTYPEr�)r�r��infos   r;�get_infozTarInfo.get_info�s���	��9���D�D��9�v�%�D��	�������	��
����	��
��
��
��
��
�
�
�� ��<�7�"�"�4��<�+@�+@��+E�+E�"���L�L�L�C��L�L�L��r=�surrogateescapec�p�	|���}|���D]\}}|�td|z����|tkr|�|||��S|t
kr|�|||��S|tkr|�||��Std���)Nz%s may not be Nonezinvalid format)	r��itemsr3r�create_ustar_headerr�create_gnu_headerr�create_pax_header)r�rYr9r:r�r��values       r;�tobufz
TarInfo.tobuf�s���	��}�}�����:�:�<�<�	>�	>�K�D�%��}� �!5��!<�=�=�=���\�!�!��+�+�D�(�F�C�C�C�
�z�
!�
!��)�)�$��&�A�A�A�
�z�
!�
!��)�)�$��9�9�9��-�.�.�.r=c��	t|d<t|d�||����tkrt	d���t|d�||����t
kr&|�|d||��\|d<|d<|�|t||��S)N�magicr^zlinkname is too longr��prefix)	�POSIX_MAGICr5r4�LENGTH_LINKr3�LENGTH_NAME�_posix_split_name�_create_headerr)r�r�r9r:s    r;r�zTarInfo.create_ustar_header�s���	�#��W�
��t�J��&�&�x��8�8�9�9�K�G�G��3�4�4�4��t�F�|�"�"�8�V�4�4�5�5��C�C�+/�+A�+A�$�v�,�PX�Z`�+a�+a�(�D��N�D��L��"�"�4��x��H�H�Hr=c��	t|d<d}t|d�||����tkr&||�|dt
||��z
}t|d�||����tkr&||�|dt||��z
}||�|t||��zS)Nr�r=r^r�)
�	GNU_MAGICr5r4r��_create_gnu_long_header�GNUTYPE_LONGLINKr��GNUTYPE_LONGNAMEr�r)r�r�r9r:rbs     r;r�zTarInfo.create_gnu_header�s���	�!��W�
����t�J��&�&�x��8�8�9�9�K�G�G��4�/�/��Z�0@�BR�T\�^d�e�e�e�C��t�F�|�"�"�8�V�4�4�5�5��C�C��4�/�/��V��>N�PX�Z`�a�a�a�C��T�(�(��z�8�V�L�L�L�Lr=c��	t|d<|j���}ddtfddtfddfD]h\}}}||vr�	||�dd	��n#t$r||||<Y�@wxYwt||��|kr||||<�id
D]u\}}d}||}	t|	t��}
|
rt|	��n|	}d|cxkrd
|dz
zks
nd||<d}n	|
r|||<d}|r||vrt|	��||<�v|r|�|t|��}nd}||�|tdd��zS)Nr�r�r&r^r')r,r,� )r-r-r�rIrJ))r*rG)r+rG)r(�)r)r�FrrGr$Tr=r�)r�rur�r�r�r4�UnicodeEncodeErrorr5�
isinstance�float�round�str�_create_pax_generic_header�XHDTYPEr�r)
r�r�r9rur��hnamer8rX�	needs_pax�val�val_is_float�val_intrbs
             r;r�zTarInfo.create_pax_headers���	�$��W�
��&�+�+�-�-��
���-�
�J��/T�&�(>�$@�	0�	0��D�%����#�#��
��T�
�!�!�'�8�4�4�4�4��%�
�
�
�%)�$�Z��E�"���
�����4��:����'�'�%)�$�Z��E�"��R�	-�	-�L�D�&��I��t�*�C�%�c�5�1�1�L�$0�9�e�C�j�j�j�c�G���3�3�3�3�!���
�"3�3�3�3�3���T�
� �	�	��
!�%��T�
� �	��
-�T��4�4�$'��H�H��D�!���	��1�1�+�w��Q�Q�C�C��C��T�(�(��|�W�i�P�P�P�Ps�A$�$A<�;A<c�<�	|�|td��S)Nr1)r��XGLTYPE)�clsrus  r;�create_pax_global_headerz TarInfo.create_pax_global_header>s��	��-�-�k�7�G�L�L�Lr=c��	|�d��}tdt|����D]�}d�|d|���}d�||d���}t|�||����t
kr.t|�||����tkrn��td���||fS)NrRr$zname is too long)�splitrMr5r�r4�
LENGTH_PREFIXr�r3)r�r�r9r:�
componentsrRr�s       r;r�zTarInfo._posix_split_nameDs���	��Z�Z��_�_�
��q�#�j�/�/�*�*�	1�	1�A��X�X�j��!��n�-�-�F��8�8�J�q�r�r�N�+�+�D��6�=�=��6�2�2�3�3�}�D�D�����H�f�5�5�6�6�+�E�E�����/�0�0�0��t�|�r=c��	|�d��ttfv}|rKt|�dd��d|��}t|�dd��d|��}n$t	dd||��}t	dd||��}|�dt
��}|�t
d���t	|�dd��d	||��t|�d
d��dzd|��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}tj	dtzd�|����}	t|	td���d}
|	dd�td|
zd��z|	dd�z}	|	S)NrrrsrrGrtr�zTarInfo.type must not be Noner�rr�r�r*r+r(r�r)s        r^r�r,r�r-r�rz%dsr=i����z%06orIi����)�get�CHRTYPE�BLKTYPEr[r<ryr3r�r`r�rr�rerU)r�rYr9r:�has_device_fieldsrsrt�filetype�partsrbrqs           r;r�zTarInfo._create_headerTs���	�!�H�H�V�,�,��'�0B�B���	4��4�8�8�J��2�2�A�v�>�>�H��4�8�8�J��2�2�A�v�>�>�H�H��2�q�(�F�3�3�H��2�q�(�F�3�3�H��8�8�F�G�,�,�����<�=�=�=�
������$�$�c�8�V�<�<�������#�#�f�,�a��8�8�������"�"�A�v�.�.�������"�"�A�v�.�.�������#�#�R��0�0������!�$�$�b�&�1�1��������R�(�(�#�x��@�@��H�H�W�k�*�*������"�%�%�r�8�V�<�<������"�%�%�r�8�V�<�<��������2�&�&��X�v�>�>�
��$�k�%�)�+�S�X�X�e�_�_�=�=���c�9�*�+�+�.�/�/��2���%�4�%�j�5��F�!2�G�<�<�<�s�4�5�5�z�I���
r=c��	tt|��t��\}}|dkr|t|z
tzz
}|S)Nr)rjr5rr6)�payloadrqrrs   r;�_create_payloadzTarInfo._create_payload~sE��	�#�3�w�<�<��;�;���	��q�=�=��	�I�-��4�4�G��r=c��	|�||��tz}i}d|d<||d<t|��|d<t|d<|�|t
||��|�|��zS)Nz
././@LongLinkr�rrr(r�)r4r6r5r�r�rr�)r�r�rrr9r:r�s      r;r�zTarInfo._create_gnu_long_header�s���	��{�{�8�V�,�,�s�2����&��V����V���4�y�y��V��!��W�
��!�!�$��h��G�G��#�#�D�)�)�*�	*r=c��	d}|���D]/\}}	|�dd���#t$rd}YnwxYwd}|r|dz
}|���D]�\}}|�d��}|r|�|d��}n|�d��}t|��t|��zdz}d	x}	}
	|tt	|
����z}	|	|
krn|	}
�)|tt	|
��d
��dz|zdz|zd
zz
}��i}d|d<||d<t|��|d<t|d<|�|td
d��|�	|��zS)NFr1rJTr=s21 hdrcharset=BINARY
r�rrrI� �=�
z././@PaxHeaderr�rrr(r�r�)
r�r4r�r5r�rUr�r�rr�)r�rurrr9�binary�keywordr��records�lrQrBr�s            r;r�z"TarInfo._create_pax_generic_header�s���	���)�/�/�1�1�	�	�N�G�U�
����W�h�/�/�/�/��%�
�
�
������
�������	1��0�0�G�)�/�/�1�1�	V�	V�N�G�U��n�n�W�-�-�G��
.����X�/@�A�A������W�-�-���G���s�5�z�z�)�A�-�A��I�A��
���C��F�F���O����6�6����	
�

�u�S��V�V�W�-�-��4�w�>��E��M�PU�U�U�G�G���'��V����V���7�|�|��V��#��W�
��!�!�$��g�y�I�I��#�#�G�,�,�-�	-s�5�A�Ac���	t|��dkrtd���t|��tkrtd���|�t
��tkrt
d���t|dd���}|t|��vrtd���|��}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�||��}|jt0kr&|j�d��rt4|_|jt6kr�d}g}t9d��D]h}		t|||dz���}
t||dz|dz���}n#t:$rYn!wxYw|�|
|f��|dz
}�it?|d��}t|dd���}
|||
f|_ |�!��r|j�"d��|_|r |jtFvr|dz|jz|_|S)Nrzempty headerztruncated headerzend of file header��zbad checksumr�l�t�|��ii	i)iIiQiYi�rRi�r�r��i�i�i�)$r5r�rr��countr6r�rSrerPrCr�r�r*r+r(r)rqrrr^r,r-rsrt�AREGTYPEr�r��GNUTYPE_SPARSErMr3r��boolrvr\�rstrip�	GNU_TYPES)r�rbr9r:rq�objr�r��structsrRr�numbytes�
isextended�origsizes              r;�frombufzTarInfo.frombuf�sI��	��s�8�8�q�=�=�"�>�2�2�2��s�8�8�y� � �&�'9�:�:�:��9�9�S�>�>�Y�&�&� �!5�6�6�6��S��S��\�"�"����c�*�*�*�*�$�^�4�4�4��c�e�e���s�1�S�5�z�8�V�4�4����s�3�s�7�|�$�$����c�#�c�'�l�#�#����c�#�c�'�l�#�#����s�3�s�7�|�$�$�����C��G��%�%��	���
��s�3�w�<����3�s�3�w�<��6�:�:�����C��G��h��7�7��	���C��G��h��7�7��	��3�s�3�w�<�(�(����3�s�3�w�<�(�(����S��S��\�8�V�4�4���8�x���C�H�$5�$5�c�$:�$:���C�H�
�8�~�%�%��C��G��1�X�X�
�
��� ��S��r��\�!2�3�3�F�"�3�s�R�x��b��'8�#9�:�:�H�H��!�����E�E����������1�2�2�2��r�	����c�#�h���J��3�s�3�w�<�(�(�H�#*�J��"A�C���9�9�;�;�	,��x���s�+�+�C�H��	/�c�h�i�/�/���|�c�h�.�C�H��
s�7J=�=
K�
Kc��	|j�t��}|�||j|j��}|j���tz
|_|�|��Sr�)	r�rkrr�r9r:r�r�_proc_member)r�r2rbr�s    r;�fromtarfilezTarInfo.fromtarfilesf��	��o�"�"�9�-�-���k�k�#�w�/���@�@���_�)�)�+�+�i�7��
�����(�(�(r=c�,�	|jttfvr|�|��S|jtkr|�|��S|jtttfvr|�	|��S|�
|��Sr�)rrr�r��
_proc_gnulongr��_proc_sparser�r��SOLARIS_XHDTYPE�	_proc_pax�
_proc_builtin)r�r2s  r;r�zTarInfo._proc_member s���	��9�)�+;�<�<�<��%�%�g�.�.�.�
�Y�.�
(�
(��$�$�W�-�-�-�
�Y�7�G�_�=�
=�
=��>�>�'�*�*�*��%�%�g�.�.�.r=c��	|j���|_|j}|���s|jt
vr||�|j��z
}||_|�	|j
|j|j��|�
��r|j�d��|_|S�NrR)r�r�r/rZrr�SUPPORTED_TYPES�_blockr(r�_apply_pax_inforur9r:r\r�r�)r�r2rs   r;r�zTarInfo._proc_builtin-s���	�#�?�/�/�1�1����!���:�:�<�<�	-�4�9�O�;�;��d�k�k�$�)�,�,�,�F����	
���W�0�'�2B�G�N�S�S�S��:�:�<�<�	.��	�(�(��-�-�D�I��r=c�8�	|j�|�|j����}	|�|��}n/#t
$r"}t
t|����d�d}~wwxYw|j|_|j	tkr!t||j|j
��|_n0|j	tkr t||j|j
��|_|���r|j�d��|_|Sr�)r�rkr�r(r�rr�r�rrrr�rCr9r:r�r�r^r\�removesuffix)r�r2rb�nextr�s     r;r�zTarInfo._proc_gnulongCs��	��o�"�"�4�;�;�t�y�#9�#9�:�:��	:��#�#�G�,�,�D�D���	:�	:�	:�'��A���/�/�T�9�����	:����
�k����9�(�(�(��C��!1�7�>�B�B�D�I�I�
�Y�*�
*�
*���W�%5�w�~�F�F�D�M��:�:�<�<�	4��	�.�.�s�3�3�D�I��s�A�
A7�A2�2A7c�4�	|j\}}}|`|r�|j�t��}d}t	d��D]l}	t|||dz���}t||dz|dz���}	n#t$rYn%wxYw|r|	r|�||	f��|dz
}�mt|d��}|��||_	|j�
��|_|j|�|j
��z|_||_
|S)Nr�r�r�i�)rvr�rkrrMrSr3r�r�r0r�r/r�r(r)
r�r2r�r�r�rbr�rRrr�s
          r;r�zTarInfo._proc_sparse^sK��	�)-�(<�%���X�� ��	(��/�&�&�y�1�1�C��C��2�Y�Y�
�
��� ��S��r��\�!2�3�3�F�"�3�s�R�x��b��'8�#9�:�:�H�H��!�����E�E������7�h�7��N�N�F�H�#5�6�6�6��r�	����c�#�h���J��	(����"�?�/�/�1�1����)�D�K�K��	�,B�,B�B�����	��s�7A<�<
B
�	B
c��	|j�|�|j����}|jt
kr|j}n|j���}d}d}g}t|��|k�r�||dk�rst�
||��x}std���	t|�
d����}n#t$rtd���wxYw|dkrtd���||zt|��krtd���|�d��|zdz
}	||�d��dz|	�}
|
�d��\}}}
|r|dks||	dkrtd���|�|||
f��|dkr|�|
dkr|j}nd	}||z
}t|��|kr
||dk��s|�d	}|D]q\}}}
|�|d	d	|j��}|t,vr#|�|
||j|j��}n|�|
d	d	|j��}|||<�r	|�|��}n/#t0$r"}t3t5|����d�d}~wwxYwd
|vr|�||��ndd|vr|�||��nI|�d��d
kr0|�d��dkr|�|||��|jt>t@fvr~|�!||j|j��|j"|_"d|vrM|j#}|�$��s|jtJvr||�|j��z
}||_"|S)NrrLr$�r�rs
hdrcharsetsBINARYr1�GNU.sparse.map�GNU.sparse.sizezGNU.sparse.major�1zGNU.sparse.minorrKr()&r�rkr�r(rrr�rur�r5�_header_length_prefix_re�matchrPrN�groupr3r'rw�	partitionr�r9�_decode_pax_fieldr:�PAX_NAME_FIELDSr�rr�r��_proc_gnusparse_01�_proc_gnusparse_00r��_proc_gnusparse_10r�r�r�rr/rZr�)r�r2rbrur�r9�raw_headersr�r8�header_value_end_offset�keyword_and_value�raw_keyword�equals�	raw_valuer�r�r�r�rs                   r;r�zTarInfo._proc_paxzsF��	��o�"�"�4�;�;�t�y�#9�#9�:�:��
�9����!�-�K�K�!�-�2�2�4�4�K��������#�h�h��n�n��S��T�!1�!1�5�;�;�C��E�E�E�E�
;�(�)9�:�:�:�
;��U�[�[��^�^�,�,�����
;�
;�
;�(�)9�:�:�:�
;������z�z�(�)9�:�:�:��V�|�c�#�h�h�&�&�(�)9�:�:�:�&+�k�k�!�n�n�v�&=��&A�#� #�E�I�I�a�L�L�1�$4�5L�$L� M��->�-H�-H��-N�-N�*�K����
;�&�D�.�.�C�8O�4P�TX�4X�4X�(�)9�:�:�:������Y�?�@�@�@��m�+�+��0@��	�)�)�&�/�H�H�&�H��6�M�C�M�#�h�h��n�n��S��T�!1�!1�R���H�/:�	)�	)�*�F�K���,�,�[�'�7��N�$�$�G��/�)�)��.�.�y�(�G�DT���(�(����.�.�y�'�7���(�(��$)�K�� � �	:��#�#�G�,�,�D�D���	:�	:�	:�'��A���/�/�T�9�����	:�����{�*�*��#�#�D�+�6�6�6�6�
�+�
-�
-��#�#�D�+�6�6�6�6�
�_�_�/�
0�
0�C�
7�
7�K�O�O�L^�<_�<_�cf�<f�<f��#�#�D�+�w�?�?�?��9��/�2�2�2�� � ��g�.>���O�O�O��+�D�K���$�$��)���:�:�<�<�5�4�9�O�#C�#C��d�k�k�$�)�4�4�4�F�!'����s$�9"C�C6�8J�
J:�J5�5J:c���	g}g}|D]�\}}}|dkrS	|�t|��������B#t$rt	d���wxYw|dkrS	|�t|���������#t$rt	d���wxYw��tt
||����|_dS)NsGNU.sparse.offsetrLsGNU.sparse.numbytes)r�rNrAr3rP�list�zipr0)r�r�r�offsetsr��_r�r�s        r;rzTarInfo._proc_gnusparse_00�s
��	�����!,�	?�	?��A�w���.�.�.�?��N�N�3�u�|�|�~�~�#6�#6�7�7�7�7��!�?�?�?�,�-=�>�>�>�?�����2�2�2�?��O�O�C������$7�$7�8�8�8�8��!�?�?�?�,�-=�>�>�>�?����3��3�w��1�1�2�2����s�4A
�
A$�.4B#�#B=c	��	d�|d�d��D��}tt|ddd�|ddd�����|_dS)Nc�,�g|]}t|����Sr�)rN)�.0�xs  r;�
<listcomp>z.TarInfo._proc_gnusparse_01.<locals>.<listcomp>
s��K�K�K�Q�#�a�&�&�K�K�Kr=r��,r%r$)r�r
rr0)r�r�rur0s    r;rzTarInfo._proc_gnusparse_01s_��	�K�K�+�.>�"?�"E�"E�c�"J�"J�K�K�K���3�v�c�c��c�{�F�1�4�a�4�L�9�9�:�:����r=c	�\�	d}g}|j�t��}|�dd��\}}t	|��}t|��|dzkrwd|vr"||j�t��z
}|�dd��\}}|�t	|����t|��|dzk�w|j���|_tt|ddd�|ddd�����|_dS)Nr�r$r%)r�rkrr�rNr5r�r�r/r
rr0)r�r�rur2�fieldsr0rb�numbers        r;rzTarInfo._proc_gnusparse_10
s��	������o�"�"�9�-�-���i�i��q�)�)�����V�����&�k�k�F�Q�J�&�&��C����w��+�+�I�6�6�6���)�)�E�1�-�-�K�F�C��M�M�#�f�+�+�&�&�&�	�&�k�k�F�Q�J�&�&�
#�?�/�/�1�1����3�v�c�c��c�{�F�1�4�a�4�L�9�9�:�:����r=c��	|���D]�\}}|dkrt|d|���|dkrt|dt|�����B|dkrt|dt|�����g|tvr^|tvr)	t	||��}n#t
$rd}YnwxYw|dkr|�d��}t|||����|���|_dS)NzGNU.sparse.namer&r�r(zGNU.sparse.realsizerrR)	r��setattrrN�
PAX_FIELDS�PAX_NUMBER_FIELDSr3r�r�ru)r�rur9r:r�r�s      r;r�zTarInfo._apply_pax_infos4��	�*�/�/�1�1�	.�	.�N�G�U��+�+�+���f�e�,�,�,�,��-�-�-���f�c�%�j�j�1�1�1�1��1�1�1���f�c�%�j�j�1�1�1�1��J�&�&��/�/�/�"� 1�'� :�5� A� A����%�"�"�"� !����"�����f�$�$�!�L�L��-�-�E���g�u�-�-�-��&�+�+�-�-����s�B&�&B5�4B5c�~�		|�|d��S#t$r|�||��cYSwxYw)NrJ)rA�UnicodeDecodeError)r�r�r9�fallback_encoding�fallback_errorss     r;r�zTarInfo._decode_pax_field4s[��	�	D��<�<��(�3�3�3��!�	D�	D�	D��<�<� 1�?�C�C�C�C�C�	D���s�� <�<c�V�	t|t��\}}|r|dz
}|tzS)Nr$)rjr)r�r�rqrrs    r;r�zTarInfo._block<s9��	�#�5�)�4�4���	��	��a�K�F��	�!�!r=c� �	|jtvSr�)rr�
REGULAR_TYPESr�s r;rZz
TarInfo.isregEs��>��y�M�)�)r=c�,�	|���Sr�)rZr�s r;�isfilezTarInfo.isfileIs��>��z�z�|�|�r=c�$�	|jtkSr�)rrr�r�s r;r\z
TarInfo.isdirM���+��y�G�#�#r=c�$�	|jtkSr�)rr�SYMTYPEr�s r;r]z
TarInfo.issymQs��/��y�G�#�#r=c�$�	|jtkSr�)rr�LNKTYPEr�s r;r[z
TarInfo.islnkUr%r=c�$�	|jtkSr�)rrr�r�s r;�ischrz
TarInfo.ischrYs��2��y�G�#�#r=c�$�	|jtkSr�)rrr�r�s r;�isblkz
TarInfo.isblk]s��.��y�G�#�#r=c�$�	|jtkSr�)rr�FIFOTYPEr�s r;�isfifozTarInfo.isfifoas��&��y�H�$�$r=c��|jduSr�)r0r�s r;�issparsezTarInfo.issparsees���{�$�&�&r=c�:�	|jtttfvSr�)rrr�r�r/r�s r;�isdevz
TarInfo.isdevhs��M��y�W�g�x�8�8�8r=r�)r�)3rr�r��dict�	__slots__r��propertyr&�setterr'r�r�r�r�rr
r�r�r�r��classmethodr�r��staticmethodr�r�r�r�r�r�r�r�r�r�r�rrrr�r�r�rZr#r\r]r[r+r-r0r2r4r�r=r;rrPsv���������
�
�
�,�,�
�!�!�
�G�F�
�H�G�	
�
 ��
�-�,�

�$�#�
�>�>�
�F�F�
���
��
�
�*�)�
� *�)�!
�"/�.�#
�$5�4�%
�&9�9�'
�*.�-�+
�,�$�-
�.�$�/
�0�t�1
�I�6����0����X��
�[����[������X���_�!�!��_�!�O�O�O��%�e�e��u�E���������8���8*�H�EV�/�/�/�/�"I�I�I�M�M�M�8Q�8Q�8Q�t�M�M��[�M�
��� �'�'��\�'�R����\���*�*��[�*� �0-�0-��[�0-�d�<�<��[�<�|�)�)��[�)�(/�/�/����,���6���8w�w�w�r3�3�3�(;�;�;�;�;�;� .�.�.�.D�D�D�"�"�"�*�*�*����$�$�$�$�$�$�$�$�$�$�$�$�$�$�$�%�%�%�'�'�'�9�9�9�9�9r=rc���eZdZ	dZdZdZdZeZe	Z
dZeZ
eZdZ				d<d�Zedddefd���Zed=d	���Zed>d���Zed>d���Zed?d
���Zddddd�Zd�Zd�Zd�Zd�Zd@d�ZdAdd�d�ZdBdd�d�Z dCd�Z!d�Z"dDddd �d!�Z#dEddd �d#�Z$d$�Z%d%�Z&d&�Z'd'�Z(d(�Z)		dFd)�Z*d*�Z+d+�Z,d,�Z-d-�Z.d.�Z/d/�Z0d0�Z1d1�Z2d2�Z3d3�Z4dGd4�Z5d5�Z6dCd6�Z7d7�Z8d8�Z9d9�Z:d:�Z;d;�Z<dS)HrrFr$Nr�r�c��	ddddd�}||vrtd���||_|||_|sU|jdkr-tj�|��sd|_d|_t
||j��}d	|_n]|�8t|d
��r(t|j
ttf��r|j
}t|d��r|j|_d|_|rtj�
|��nd|_
||_|�||_|�||_|�||_|�||_|�||_|	|_|
�|jt*kr|
|_ni|_|�||_|�||_|
|_d	|_g|_d	|_|j���|_i|_	|jd
kr d|_ |�!��|_ |jdkr�	|j�"|j��	|j�#|��}|j�$|��nY#tJ$r"|j�"|j��Yn/tL$r"}tOt|����d�d}~wwxYw��|jdvrxd|_|jrl|j�(|j�)����}|j�*|��|xjtW|��z
c_dSdSdS#|js|j�,��d|_�xYw)N�rbzr+b�wb�xb�r��ar�r�!mode must be 'r', 'a', 'w' or 'x'rAr�Fr�r�Tr��rAr�r)-r3r��_moder�r&�exists�	bltn_openr�r�r�r�r�rU�abspathr�rYr3�dereference�ignore_zerosr9r:rru�debug�
errorlevel�copybufsizer��members�_loadedr�r�inodes�firstmemberr�r�r�r�r�rrr�r�rlr5r�)r�r�r�r�rYr3rHrIr9r:rurJrKrL�modesr�rbs                 r;r�zTarFile.__init__�s���	���T��=�=���u����@�A�A�A���	��4�[��
��
	$��y�C�������t�(<�(<����	�!��
���d�j�1�1�G�$�D�������&�!9�!9���7�<�#�u��6�6���|���w��'�'�
*�$�\��
�#�D��-1�;�B�G�O�O�D�)�)�)�t��	������ �D�K���"�D�L��"�*�D���#� ,�D����$�D�M�����"�t�{�j�'@�'@�*�D���!�D�����D�J��!�(�D�O�'�������������l�'�'�)�)������	��y�C���#'�� �#'�9�9�;�;�� ��y�C���	:��L�%�%�d�k�2�2�2�:�"&�,�":�":�4�"@�"@����+�+�G�4�4�4�4��)������)�)�$�+�6�6�6���&�:�:�:�'��A���/�/�T�9�����:����	:��y�O�+�+�#����#�,��,�?�?��@P�@U�@U�@W�@W�X�X�C��L�&�&�s�+�+�+��K�K�3�s�8�8�+�K�K�K�K�
,�+�,�,��	��#�
%���"�"�$�$�$��D�K����s>�<AL'�4I�L'�)J�1L'�3	J�<J�J�BL'�'*Mc����	|s|std���|dvrՈfd�}g}t�j|���D]�}t��j|��}	|�|���}
	|	|d|fi|��cS#t
tf$r<}|�d|�d|����|�|�|
��Yd}~��d}~wwxYwd�	|��}td	|�����d
|vrc|�
d
d��\}
}|
pd}
|pd}|�jvrt��j|��}	nt
d
|z���|	||
|fi|��Sd|vrw|�
dd��\}
}|
pd}
|pd}|
dvrtd���t||
|||��}	�||
|fi|��}n#|����xYwd|_
|S|dvr�j|||fi|��Std���)Nznothing to open)r��r:*c�&���j|dkS)N�taropen)�	OPEN_METH)r�r�s �r;�not_compressedz$TarFile.open.<locals>.not_compressed"s����}�X�.�)�;�;r=)�keyr�z	- method z: �
z'file could not be opened successfully:
�:r$r�r��|r�zmode must be 'r' or 'w'FrCzundiscernible mode)r3�sortedrVrxr�rr	r�r�r�r�r�r�r�rU)r�r�r�r�rp�kwargsrW�
error_msgsr��func�	saved_posr��error_msgs_summary�filemode�streamr�s`               r;rzTarFile.open�s����!	�F�	0�G�	0��.�/�/�/��<���
<�
<�
<�
<�
<��J�"�3�=�n�E�E�E�

�

���s�C�M�(�$;�<�<���&� '�����I���4��c�7�=�=�f�=�=�=�=�=��!�#3�4�����%�%�&C�(�&C�&C�a�&C�&C�D�D�D��*����Y�/�/�/��H�H�H�H�����	����
"&���:�!6�!6���[�GY�[�[�\�\�\�
�D�[�[�!%���C��!3�!3��H�h���3�H��(�5�H��3�=�(�(��s�C�M�(�$;�<�<���&�'D�x�'O�P�P�P��4��h��:�:�6�:�:�:�
�D�[�[�!%���C��!3�!3��H�h���3�H��(�5�H��z�)�)� �!:�;�;�;��T�8�X�w��H�H�F�
��C��h��9�9�&�9�9����
�����������!�A�M��H�
�_�
$�
$��3�;�t�T�7�=�=�f�=�=�=��-�.�.�.s$�+
A8�8C�	2C�C�"F.�.Gc�@�	|dvrtd���||||fi|��S)Nr@rB)r3)r�r�r�r�r]s     r;rUzTarFile.taropenVs>��	��+�+�+��@�A�A�A��s�4��w�1�1�&�1�1�1r=r�c���	|dvrtd���	ddlm}n#t$rt	d��d�wxYw	|||dz||��}n+#t
$r}|�|dkrt
d��|��d}~wwxYw	|j|||fi|��}nR#t
$r0}|���|dkrt
d��|��d}~w|����xYwd	|_	|S)
N�r�r�r�mode must be 'r', 'w' or 'x'r)�GzipFilezgzip module is not availablersr�r�F)
r3�gziprhr�r	r�rrUr�r�)	r�r�r�r��
compresslevelr]rhr�r�s	         r;�gzopenzTarFile.gzopen^sX��	���&�&��;�<�<�<�	M�%�%�%�%�%�%�%���	M�	M�	M�"�#A�B�B��L�	M����	��h�t�T�C�Z���H�H�G�G���	�	�	��"�t�s�{�{�� 1�2�2��9������	����
		����D�$��:�:�6�:�:�A�A���	�	�	��M�M�O�O�O��s�{�{�� 1�2�2��9������	��M�M�O�O�O�������
��s7��8�A�
A6�A1�1A6�:B�
C�+C�Cc�~�	|dvrtd���	ddlm}n#t$rt	d��d�wxYw||p|||���}	|j|||fi|��}nY#ttf$r0}|���|dkrtd��|��d}~w|����xYwd	|_
|S)
Nrfrgr)�BZ2Filer�)rjr�znot a bzip2 fileF)r3r�rmr�r	rUr��EOFErrorr�rr�)	r�r�r�r�rjr]rmr�r�s	         r;�bz2openzTarFile.bz2opens��	���&�&��;�<�<�<�	L�#�#�#�#�#�#�#���	L�	L�	L�"�#@�A�A�t�K�	L�����'�'�/�T�4�}�M�M�M��		����D�$��:�:�6�:�:�A�A����"�	�	�	��M�M�O�O�O��s�{�{�� 2�3�3��:������	��M�M�O�O�O�������
��s ��8�A�B3�.+B�B3c�x�	|dvrtd���	ddlm}m}n#t$rtd��d�wxYw||p|||���}	|j|||fi|��}nT#|tf$r0}	|���|dkrtd��|	��d}	~	w|����xYwd	|_
|S)
Nrfrgr)�LZMAFiler�r�)�presetr�znot an lzma fileF)r3r�rqr�r�r	rUrnr�rr�)
r�r�r�r�rrr]rqr�r�r�s
          r;�xzopenzTarFile.xzopen�s��	���&�&��;�<�<�<�	M�0�0�0�0�0�0�0�0�0���	M�	M�	M�"�#A�B�B��L�	M�����(�7�?�d�D��@�@�@��		����D�$��:�:�6�:�:�A�A���8�$�	�	�	��M�M�O�O�O��s�{�{�� 2�3�3��:������	��M�M�O�O�O�������
��s ��:�A�B0�++B�B0rUrkrors)r�r�r�r�c���	|jrdSd|_	|jdvr�|j�tt
dzz��|xjt
dzz
c_t|jt��\}}|dkr*|j�tt|z
z��|j	s|j�
��dSdS#|j	s|j�
��wwxYw)NTrCr%r)r�r�r�rlr6rrrj�
RECORDSIZEr�r�)r�rqrrs   r;r�z
TarFile.close�s���	��;�	��F����	%��y�O�+�+���"�"�3�)�a�-�#8�9�9�9����	�A�
�.���%+�4�;�
�$C�$C�!��	��q�=�=��L�&�&�s�j�9�.D�'E�F�F�F��#�
%���"�"�$�$�$�$�$�
%�
%��4�#�
%���"�"�$�$�$�$�
%���s�BC�#C2c��	|�|�d����}|�td|z���|S)NrRzfilename %r not found)�
_getmemberr��KeyError)r�r�r3s   r;�	getmemberzTarFile.getmember�sD��	�
�/�/�$�+�+�c�"2�"2�3�3���?��2�T�9�:�:�:��r=c�p�	|���|js|���|jSr�)�_checkrN�_loadrMr�s r;�
getmemberszTarFile.getmembers�s5��	�	
���
�
�
��|�	��J�J�L�L�L��|�r=c�@�	d�|���D��S)Nc��g|]	}|j��
Sr�r|)rr3s  r;rz$TarFile.getnames.<locals>.<listcomp>�s��>�>�>����>�>�>r=)r}r�s r;�getnameszTarFile.getnames�s'��	�?�>�D�O�O�,=�,=�>�>�>�>r=c���	|�d��|�|j}|�|}tj�|��\}}|�tjd��}|�d��}|���}||_	|�1|j
stj|��}n;tj|��}n&tj
|�����}d}|j}tj|��ri|j|jf}	|j
s:|jdkr/|	|jvr&||j|	krt*}
|j|	}n�t,}
|	dr
||j|	<n�tj|��rt0}
n�tj|��rt4}
njtj|��rt8}
tj|��}n:tj|��rt>}
ntj |��rtB}
ndS||_||_"|j#|_$|j%|_&|
t,kr
|j'|_(nd|_(|j)|_*|
|_+||_,tZr6	t[j.|j$��d|_/n#t`$rYnwxYwtbr6	tcj2|j&��d|_3n#t`$rYnwxYw|
t>tBfvrftitd��rQtitd��r<tj5|j6��|_7tj8|j6��|_9|S)N�awxrRr�r$r�major�minor):r{r�r�r&�
splitdriver�rVrWr3r2rH�lstat�stat�fstat�fileno�st_mode�S_ISREG�st_ino�st_dev�st_nlinkrOr)ry�S_ISDIRr��S_ISFIFOr/�S_ISLNKr'�readlink�S_ISCHRr��S_ISBLKr�r��st_uidr*�st_gidr+�st_sizer(�st_mtimer)rrr^�pwd�getpwuidr,rx�grp�getgrgidr-r�r��st_rdevrsr�rt)r�r��arcnamer��drvr3�statresr^�stmd�inoderrs           r;�
gettarinfozTarFile.gettarinfo�sB��	�	
���E�������<�D�
�?��G��w�)�)�'�2�2���W��/�/�"�&�#�.�.���.�.��%�%���,�,�.�.������?��#�
(��(�4�.�.����'�$�-�-����h�w�~�~�/�/�0�0�G�������<����	��^�W�^�4�E��#�
1��(8�1�(<�(<��T�[�(�(�W���E�8J�-J�-J����;�u�-�������8�1�)0�D�K��&��
�\�$�
�
�	��D�D�
�]�4�
 �
 �
	��D�D�
�\�$�
�
�	��D��{�4�(�(�H�H�
�\�$�
�
�	��D�D�
�\�$�
�
�	��D�D��4��������n����n����7�?�?�"�?�G�L�L��G�L��(��
����#����	�
� #��W�[� 9� 9�!� <��
�
���
�
�
���
�����	�
� #��W�[� 9� 9�!� <��
�
���
�
�
���
�����G�W�%�%�%��r�7�#�#�
=���G�(<�(<�
=�#%�8�G�O�#<�#<�� �#%�8�G�O�#<�#<�� ��s$�>$J#�#
J0�/J0�;$K � 
K-�,K-T)rMc��	|���|�|}|D�]�}|�r|j�td��n&ttj|j����t|jp|j�d|jp|j����|�	��s|�
��r"tdd|j|jfzz��ntd|j
z��|j�td��n1tdtj|j��dd�z��t|j|���rdnd	z��|rV|���rtd
|jz��|���rtd|jz��t-�����dS)Nz
??????????rRz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02dr�r�z-> zlink to )r{r�r|r�rbr,r*r-r+r+r-rsrtr(r)r��	localtimer�r\r]r^r[r{)r��verboserMr3s    r;r
zTarFile.listUs���	�
	
���
�
�
��?��G��	�	�G��
E��<�'���-�-�-�-���
�g�l� ;� ;�<�<�<��w�}�'C���'C�'C�'.�}�'C���'C�E�F�F�F��=�=�?�?�7�g�m�m�o�o�7���$��(8�'�:J�'K�K�!M�N�N�N�N� ���� 5�6�6�6��=�(�� 5�6�6�6�6�� =�"&�.���"?�"?����"C�!D�E�E�E�
���w�}�}���(F���B�G�H�H�H��
?��=�=�?�?�:����(8� 8�9�9�9��=�=�?�?�?��
�W�-=� =�>�>�>��G�G�G�G�5	�	r=��filterc���	|�d��|�|}|j�Ctj�|��|jkr|�dd|z��dS|�d|��|�||��}|�|�dd|z��dS|�(||��}|�|�dd|z��dS|���rAt|d��5}|�	||��ddd��dS#1swxYwYdS|�
��r�|�	|��|ryttj|����D]Y}|�
tj�||��tj�||��||����XdSdS|�	|��dS)	Nr�r%ztarfile: Skipped %rr$ztarfile: Unsupported type %r�tarfile: Excluded %rr=r�)r{r�r�r&rG�_dbgr�rZrF�addfiler\r\�listdir�addr�)r�r�r��	recursiver�r3�fs       r;r�zTarFile.add{sI��	�	
���E�����?��G��9� �R�W�_�_�T�%:�%:�d�i�%G�%G��I�I�a�.��5�6�6�6��F��	�	�!�T�����/�/�$��0�0���?��I�I�a�7�$�>�?�?�?��F����f�W�o�o�G����	�	�!�3�d�:�;�;�;����=�=�?�?�	"��4��&�&�
)�!����W�a�(�(�(�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)����
)�
)�
)�
)�
)�
)��]�]�_�_�	"��L�L��!�!�!��
6���
�4� 0� 0�1�1�6�6�A��H�H�R�W�\�\�$��2�2�B�G�L�L��!�4L�4L�%�f��6�6�6�6�
6�
6�6�6�

�L�L��!�!�!�!�!s�<D � D$�'D$c�h�	|�d��tj|��}|�|j|j|j��}|j�|��|xjt|��z
c_|j
}|��t||j|j|���t|jt��\}}|dkr/|j�tt|z
z��|dz
}|xj|tzz
c_|j�|��dS)Nr�)rprr$)r{r�r�rYr9r:r�rlrr5rLrir(rjrr6rMr�)r�r3r�rbrprqrrs       r;r�zTarFile.addfile�s��	�
	
���E�����)�G�$�$���m�m�D�K�����D�D������3�������s�3�x�x����� ��������w�|�W�M�M�M�M� &�w�|�Y� ?� ?��F�I��1�}�}���"�"�3�)�i�*?�#@�A�A�A��!����K�K�6�I�-�-�K�K�����G�$�$�$�$�$r=c���|�6|j}|�tSt|t��rt	d���|St|��r|S	t|S#t$rtd|�d���d�wxYw)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z
 not found)	�extraction_filterrgr�r��	TypeError�callable�_NAMED_FILTERSrxr3)r�r�s  r;�_get_filter_functionzTarFile._get_filter_function�s����>��+�F��~�+�+��&�#�&�&�
7��6�7�7�7��M��F���	��M�	G�!�&�)�)���	G�	G�	G��;�v�;�;�;�<�<�$�F�	G���s�A�A7�.)�
numeric_ownerr�c��	g}|�|��}|�|}|D]q}|�|||��}|��|���r|�|��|�|||���|����r|�d�d���|D]�}tj�||j	��}		|�
||	|���|�||	��|�||	���m#t$r}
|�|
��Yd}
~
��d}
~
wwxYwdS)N��	set_attrsr�c��|jSr�r|)rAs r;�<lambda>z$TarFile.extractall.<locals>.<lambda>�s��q�v�r=T)rX�reverse)r�)r��_get_extract_tarinfor\r��_extract_one�sortr�r&r�r��chown�utime�chmodr�_handle_nonfatal_error)r�r&rMr�r��directories�filter_functionr`r3�dirpathr�s           r;�
extractallzTarFile.extractall�s���	����3�3�F�;�;���?��G��
	;�
	;�F��/�/����N�N�G�����}�}���
,��"�"�7�+�+�+����g�t�7�=�=�?�?�7J�,9�
�
;�
;�
;�
;�	���-�-�t��<�<�<�#�	/�	/�G��g�l�l�4���6�6�G�
/��
�
�7�G�=�
�I�I�I��
�
�7�G�,�,�,��
�
�7�G�,�,�,�,���
/�
/�
/��+�+�A�.�.�.�.�.�.�.�.�����
/����
	/�	/s�AD�
E�"D<�<Er�c��	|�|��}|�|||��}|�|�||||��dSdSr�)r�r�r�)r�r`r&r�r�r�r�r3s        r;�extractzTarFile.extract	sa��	��3�3�F�;�;���+�+�F�O�T�J�J�������g�t�Y�
�F�F�F�F�F��r=c��	t|t��r|�|��}n|}|}	|||��}nZ#ttf$r}|�|��Yd}~n/d}~wt$r}|�|��Yd}~nd}~wwxYw|� |�dd|j	z��dS|�
��r>tj|��}tj
�||j��|_|S)Nr%r�)r�r�ryr�r9�_handle_fatal_errorrr�r�r�r[r�r�r&r�r^rw)r�r`r�r&r3�
unfilteredr�s       r;r�zTarFile._get_extract_tarinfo	s2��N��f�c�"�"�	��n�n�V�,�,�G�G��G��
�	+�%�o�g�t�4�4�G�G����%�	(�	(�	(��$�$�Q�'�'�'�'�'�'�'�'������	+�	+�	+��'�'��*�*�*�*�*�*�*�*�����	+�����?��I�I�a�/�*�/�A�B�B�B��4��=�=�?�?�	H��i��(�(�G�#%�7�<�<��g�6F�#G�#G�G� ��s!�?�B�A*�*
B�7B�Bc�V�	|�d��	|�|tj�||j��||���dS#t$r }|�|��Yd}~dSd}~wt$r }|�	|��Yd}~dSd}~wwxYw)Nr�r�)
r{�_extract_memberr�r&r�r�r�r�rr�)r�r3r&r�r�r�s      r;r�zTarFile._extract_one0	s���3����C����	+�� � ��"�'�,�,�t�W�\�*J�*J�+4�/<�
!�
>�
>�
>�
>�
>���	(�	(�	(��$�$�Q�'�'�'�'�'�'�'�'�'������	+�	+�	+��'�'��*�*�*�*�*�*�*�*�*�����	+���s#�<A�
B(� A;�;
B(�B#�#B(c�R�	|jdkr�|�dd|z��dS)Nr$�tarfile: %s)rKr��r�r�s  r;r�zTarFile._handle_nonfatal_error=	s4��K��?�Q�����I�I�a���*�+�+�+�+�+r=c�D�	|jdkr�t|t��rO|j� |�dd|jz��dS|�dd|j�d|j����dS|�ddt
|��j�d|����dS)Nrr$r�z	tarfile: rv)rKr�r��filenamer��strerrorrrrr�s  r;r�zTarFile._handle_fatal_errorD	s���?��?�Q����
��7�
#�
#�	C��z�!��	�	�!�]�Q�Z�7�8�8�8�8�8��	�	�!�!�����Q�Z�Z�H�I�I�I�I�I��I�I�a�a�T�!�W�W�-=�-=�-=�q�q�A�B�B�B�B�Br=c���	|�d��t|t��r|�|��}n|}|���s|jtvr|�||��S|���s|�	��rQt|j
t��rtd���|�
|�|����SdS)Nr�z'cannot extract (sym)link as file object)r{r�r�ryrZrrr��
fileobjectr[r]r�r�r
�extractfile�_find_link_target)r�r`r3s   r;r�zTarFile.extractfileP	s���	�	
���C�����f�c�"�"�	��n�n�V�,�,�G�G��G��=�=�?�?�	�g�l�/�A�A��?�?�4��1�1�1�
�]�]�_�_�	��
�
���	��$�,��0�0�
I�"�"K�L�L�L��'�'��(>�(>�w�(G�(G�H�H�H��4r=c��	|�d��}|�dtj��}tj�|��}|r3tj�|��stj|��|���s|�	��r&|�
d|j�d|j����n|�
d|j��|�
��r|�||���n|���r|�||��n�|���r|�||��n�|���s|���r|�||��nz|���s|�	��r|�||��n;|jt0vr|�||��n|�||��|rY|�|||��|�	��s0|�||��|�||��dSdSdS)NrRr$z -> )r�r�r�rVr&r_rE�makedirsr[r]r�r�r^rZ�makefiler\�makedirr0�makefifor+r-�makedev�makelinkrrr��makeunknownr�r�r�)r�r3�
targetpathr�r��	upperdirss      r;r�zTarFile._extract_memberp	sa��	� �&�&�s�+�+�
��'�'��R�V�4�4�
��G�O�O�J�/�/�	��	#�R�W�^�^�I�6�6�	#�
�K�	�"�"�"��=�=�?�?�	'�g�m�m�o�o�	'��I�I�a�w�|�|�|�W�5E�5E�F�G�G�G�G��I�I�a���&�&�&��=�=�?�?�
	/��M�M�'�:�.�.�.�.�
�]�]�_�_�	/��L�L��*�-�-�-�-�
�^�^�
�
�		/��M�M�'�:�.�.�.�.�
�]�]�_�_�	/��
�
���	/��L�L��*�-�-�-�-�
�]�]�_�_�	/��
�
���	/��M�M�'�:�.�.�.�.�
�\��
0�
0����W�j�1�1�1�1��M�M�'�:�.�.�.��	0��J�J�w�
�M�:�:�:��=�=�?�?�
0��
�
�7�J�/�/�/��
�
�7�J�/�/�/�/�/�		0�	0�
0�
0r=c���		|j�tj|��dStj|d��dS#t$r$tj�|��s�YdSwxYw)Ni�)r�r��mkdir�FileExistsErrorr&r\�r�r3r�s   r;r�zTarFile.makedir�	s���	�
	��|�#����$�$�$�$�$����U�+�+�+�+�+���	�	�	��7�=�=��,�,�
��
�
�
�	���s�7�7�*A%�$A%c	���	|j}|�|j��|j}t	|d��5}|j�i|jD]2\}}|�|��t
|||t|���3|�|j��|�	��nt
|||jt|��ddd��dS#1swxYwYdS)Nr>)
r�r�r/rLrFr0rirr(�truncate)r�r3r��sourcerp�targetrr(s        r;r�zTarFile.makefile�	s8��	�������G�'�(�(�(��"��
�z�4�
(�
(�	N�F��~�)�$+�N�J�J�L�F�D��K�K��'�'�'�����i��I�I�I�I����G�L�)�)�)����!�!�!�!��F�F�G�L�)�W�M�M�M�	N�	N�	N�	N�	N�	N�	N�	N�	N�	N�	N�	N����	N�	N�	N�	N�	N�	Ns�BC�C�Cc�p�	|�||��|�dd|jz��dS)Nr$z9tarfile: Unknown file type %r, extracted as regular file.)r�r�rrr�s   r;r�zTarFile.makeunknown�	sT��	�	
�
�
�g�z�*�*�*��	�	�!�2�4;�L�A�	B�	B�	B�	B�	Br=c�x�	ttd��rtj|��dStd���)N�mkfifozfifo not supported by system)r�r�r�rr�s   r;r�zTarFile.makefifo�	s>��	��2�x� � �	?��I�j�!�!�!�!�!��=�>�>�>r=c�\�	ttd��rttd��std���|j}|�d}|���r|t
jz}n|t
jz}tj||tj	|j
|j����dS)N�mknodr�z'special devices not supported by systemrT)r�r�rr�r-r��S_IFBLK�S_IFCHRr�r�rsrt)r�r3r�r�s    r;r�zTarFile.makedev�	s���	��r�7�#�#�	J�7�2�y�+A�+A�	J��H�I�I�I��|���<��D��=�=�?�?�	!��D�L� �D�D��D�L� �D�
���T���G�,�g�.>�?�?�	A�	A�	A�	A�	Ar=c�T�		|���rOtj�|��rtj|��tj|j|��dStj�|j��rtj	|j|��dS|�
|�|��|��dS#t$rL	|�
|�|��|��YdS#t$rtd��d�wxYwwxYw)Nz%unable to resolve link inside archive)r]r�r&�lexists�unlink�symlinkr^rErw�linkr�r��symlink_exceptionrxrr�s   r;r�zTarFile.makelink�	sW��	�	V��}�}���

5��7�?�?�:�.�.�*��I�j�)�)�)��
�7�+�Z�8�8�8�8�8��7�>�>�'�"6�7�7�5��G�G�0�*�=�=�=�=�=��(�(��)?�)?��)H�)H�)3�5�5�5�5�5�� �	V�	V�	V�
V��$�$�T�%;�%;�G�%D�%D�%/�1�1�1�1�1�1���
V�
V�
V�"�#J�K�K�QU�U�
V����		V���s*�A!C�&>C�&)C�
D'�)D�D#�#D'c��	ttd���r*tj��dk�r|j}|j}|s~	t
r&|jrtj|j��d}n#t$rYnwxYw	tr&|j
rtj|j
��d}n#t$rYnwxYw|�d}|�d}	|���r-ttd��rtj
|||��dStj|||��dS#t$r}t!d��|�d}~wwxYwdSdS)N�geteuidrr%r?�lchownzcould not change owner)r�r�r�r+r*r�r-�getgrnamrxr�r,�getpwnamr]r�r�r�r)r�r3r�r��g�ur�s       r;r�z
TarFile.chown�	s���	�
�2�y�!�!�	D�b�j�l�l�a�&7�&7���A���A� �

���;�w�}�;��L���7�7��:���������D�������;�w�}�;��L���7�7��:���������D������y����y���
D��=�=�?�?�/�w�r�8�'<�'<�/��I�j�!�Q�/�/�/�/�/��H�Z��A�.�.�.�.�.���
D�
D�
D�"�#;�<�<�!�C�����
D����1	D�	D�&7�&7sB�-A/�/
A<�;A<�-B.�.
B;�:B;�?D �D � 
D?�*D:�:D?c��	|j�dS	tj||j��dS#t$r}t	d��|�d}~wwxYw)Nzcould not change mode)r�r�r�r�r)r�r3r�r�s    r;r�z
TarFile.chmod
sc��	��<���F�	?��H�Z���.�.�.�.�.���	?�	?�	?��6�7�7�Q�>�����	?���s�(�
A�A�Ac��	|j}|�dSttd��sdS	tj|||f��dS#t$r}td��|�d}~wwxYw)Nr�z"could not change modification time)r)r�r�r�r�r)r�r3r�r)r�s     r;r�z
TarFile.utime&
s���	��
���=��F��r�7�#�#�	��F�	L��H�Z�%���0�0�0�0�0���	L�	L�	L��C�D�D�!�K�����	L���s�>�
A�A�Ac�2�	|�d��|j�|j}d|_|S|j|j���krX|jdkrdS|j�|jdz
��|j�d��std���d}		|j�	|��}�n�#t$rL}|jr:|�dd|j|fz��|xjtz
c_Yd}~�iYd}~�nYd}~wt$rs}|jr:|�dd|j|fz��|xjtz
c_Yd}~��|jdkrtt|����d�Yd}~n�d}~wt $r|jdkrtd��d�Yn�t"$r2}|jdkrtt|����d�Yd}~n~d}~wt$$r"}tt|����d�d}~wt&$rD}	ddl}t+||j��rtd	|����d�|�#t.$r|�wxYwd}~wwxYw	|�|j�|��nd|_|S)
N�rarr$rgTr%z0x%X: %sz
empty filezzlib error: )r{rPrr�r�r�rkrr3r�r�rIr�rrPr�r�r�r��	Exceptionr�r�r�r�rMr�rN)r��mr3r�r�s     r;r�zTarFile.next4
s6��	�	
���D������'�� �A�#�D���H��;�$�,�+�+�-�-�-�-��{�a����t��L���d�k�A�o�.�.�.��<�$�$�Q�'�'�
:�� 8�9�9�9��� 	�
��,�2�2�4�8�8����!�
�
�
��$���I�I�a��t�{�A�.>�!>�?�?�?��K�K�9�,�K�K��H�H�H�H����������&�
6�
6�
6��$�6��I�I�a��t�{�A�.>�!>�?�?�?��K�K�9�,�K�K��H�H�H�H��[�A�%�%�#�C��F�F�+�+��5�&�%�%�%�%�����#�
<�
<�
<��;�!�#�#�#�L�1�1�t�;�$�#�'�
6�
6�
6��;�!�#�#�#�C��F�F�+�+��5�$�#�#�#�#�����(�
2�
2�
2���A���'�'�T�1������
�
�
���K�K�K�!�!�T�Z�0�0� �'�(:�q�(:�(:�;�;��E����"�����G���������
����
����L����(�(�(�(��D�L��s`�,C�
I/�<D�
I/�&<F�'(F�(I/�>	I/�(G4�4
I/�H�
I/�,.I�
I'�'I*�*I/c��	|���}d}|�3	|�|��}|d|�}n#t$rd}YnwxYw|rtj�|��}t
|��D]O}|r|j|jkrd}�|r%tj�|j��}n|j}||kr|cS�P|rt|���dS)NFT)	r}�indexr3r�r&�normpath�reversedrr�)	r�r�r3�	normalizerM�skippingr	r`�member_names	         r;rwzTarFile._getmemberu
s,��	��/�/�#�#������
*��
�
�g�.�.��"�&�5�&�/����
�
 �
 �
 � ����
 �����	*��7�#�#�D�)�)�D��w�'�'�	�	�F��
��>�V�]�2�2�$�H���
*� �g�.�.�v�{�;�;���$�k���{�"�"��
�
�
�#��	&��W�%�%�%�	&�	&s�;�A
�	A
c�H�		|���}|�n�d|_dSr)r�rN)r�r3s  r;r|z
TarFile._load�
s3��	�	��i�i�k�k�G����	�����r=c��	|jrtd|jjz���|� |j|vrtd|jz���dSdS)Nz%s is closedzbad operation for mode %r)r�r�r4rr�)r�r�s  r;r{zTarFile._check�
sb��	��;�	D��.�4�>�+B�B�C�C�C����	�� 5� 5��5��	�A�B�B�B��� 5� 5r=c�8�	|���rOd�tdtj�|j��|jf����}d}n	|j}|}|�||d���}|�td|z���|S)NrRT)r3rzlinkname %r not found)
r]r�r�r�r&r_r�r^rwrx)r�r3r^�limitr`s     r;r�zTarFile._find_link_target�
s���	��=�=�?�?�	��x�x��t�b�g�o�o�g�l�.K�.K�W�M]�-^� _� _�`�`�H��E�E��'�H��E�����5�D��I�I���>��2�X�=�>�>�>��
r=c#�4K�	|jr|jEd{V��dSd}|j�|���}|dz
}|V�	|t	|j��kr|j|}n)|js |���}|s	d|_dSndS|dz
}|V��Y)Nrr$T)rNrMrPr�r5)r�r	r3s   r;�__iter__zTarFile.__iter__�
s�����	��<�	��|�#�#�#�#�#�#�#��F�����'��i�i�k�k�G��Q�J�E��M�M�M�	��s�4�<�(�(�(�(��,�u�-����\�
��)�)�+�+����#'�D�L��F�����Q�J�E��M�M�M�	r=c�X�	||jkrt|tj���dSdS)N��file)rJr{ry�stderr)r��level�msgs   r;r�zTarFile._dbg�
s7��	��D�J����#�C�J�'�'�'�'�'�'��r=c�.�|���|Sr�)r{r�s r;�	__enter__zTarFile.__enter__�
s�����
�
�
��r=c��|�|���dS|js|j���d|_dSr)r�r�r�r�)r�rrr��	tracebacks    r;�__exit__zTarFile.__exit__�
sD���<��J�J�L�L�L�L�L��#�
%���"�"�$�$�$��D�K�K�Kr=)
Nr�NNNNNNr�NNNN)r�N)r�Nr�)r�NN)NNN�Trr�)r�N)r�T)TFr)=rr�r�rJrHrIrKrrYr
r9r:rr3r-r�r�r�r9rurrUrkrorsrVr�ryr}r�r�r
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rwr|r{r�rr�rrr�r=r;rrms��������
�E��K��L��J��F��H�
�F��G��J���AE�HL�>B�)-�b�b�b�b�^��#�t�Z�[/�[/�[/��[�[/�z�2�2�2��[�2������[��@�����[��6�����[��:����	��I�%�%�%�*	�	�	����?�?�?�a�a�a�a�F$�D�$�$�$�$�$�L1"��1"�1"�1"�1"�1"�f%�%�%�%�2G�G�G�$+/�%��+/�+/�+/�+/�+/�ZG���G�G�G�G�G�&���.+�+�+�,�,�,�
C�
C�
C����@>B�&+�*0�*0�*0�*0�b
�
�
�N�N�N� B�B�B�?�?�?�A�A�A�$V�V�V�2D�D�D�B?�?�?�L�L�L�<�<�<�B&&�&&�&&�&&�P���C�C�C�C����&���>(�(�(��������r=rc��		t|d��r:|���}t|���}|�|��nt|��}|���dS#t
$rYdSwxYw)Nrk)r�TF)r�r�rr�r�r)r�r�r�s   r;rr�
s����

��4�� � �	��)�)�+�+�C��T�"�"�"�A��I�I�c�N�N�N�N��T�
�
�A�	���	�	�	��t�������u�u����s�A-A2�2
B�?Bc	�z	�ddl}d}|�|���}|�ddddd�	��|�d
dtd�
��|�d���}|�dddd���|�ddddd���|�ddddd���|�dd dd!���|���}|jr|j�|�d"d#��|j	��|j	}t|��r�t|d$��5}|���t|���tj�%��ddd��n#1swxYwY|jr$td&�|����dSdS|�d"d'�|����dS|j��|j}t|��rQt&�|d(��5}|�|j�)��ddd��dS#1swxYwYdS|�d"d'�|����dS|j��Rt)|j��d"kr|jd}t*j}nKt)|j��d*kr|j\}}n(|�d"|�����t|��r�t&�|d(��5}|�||j�+��ddd��n#1swxYwY|jrC|d,krd-�|��}	nd.�||��}	t|	��dSdS|�d"d'�|����dS|j��|j�d��}
t*j�|
��\}}d/d/d0d0d1d1d1d1d2�}
||
vrd3|
|znd4}|j}t&�|
|��5}|D]}|�|���	ddd��n#1swxYwY|jr&td5�|
����dSdSdS)6Nrz3A simple command-line interface for tarfile module.)�descriptionz-vz	--verbose�
store_trueFzVerbose output)�action�default�helpz--filterz<filtername>zFilter for extraction)�metavar�choicesr'T)�requiredz-lz--list�	<tarfile>zShow listing of a tarfile)r(r'z-ez	--extract�+)r+z<output_dir>zExtract tarfile into target dir)�nargsr(r'z-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr$z&--filter is only valid for extraction
r�rz{!r} is a tar archive.z{!r} is not a tar archive.
rS)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:r�z{!r} file created.)�argparse�ArgumentParser�add_argumentr��add_mutually_exclusive_group�
parse_argsr�r��exit�testrrr}r{ryrr�rYr
rr5r��curdir�format_helpr��create�popr&�splitextr�)r.r#�parserr��argsrmr��tfr5r�tar_namer
�ext�compressions�tar_mode�	tar_files�	file_names                 r;�mainrCs$���O�O�O�G�K�
�
$�
$��
$�
=�
=�F�
����k�,��-��/�/�/�
���
�N� .�4��6�6�6�
�/�/��/�>�>�E�	���t�X�{�7��9�9�9�	���t�[��<�=��?�?�?�
���t�Z�s�3�9��;�;�;�
���t�X�{�8��:�:�:������D��{�B�t�|�+����A�@�A�A�A��y���i���c�?�?�	G��c�3���
9�3���� � � ��c�n�n�&�&�S�Z�8�8�8�8�
9�
9�
9�
9�
9�
9�
9�
9�
9�
9�
9����
9�
9�
9�
9��|�
<��.�5�5�c�:�:�;�;�;�;�;�
<�
<�
�K�K��9�@�@��E�E�F�F�F�F�F�	
��	��i���c�?�?�	G����c�5�)�)�
.�R�������-�-�-�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.����
.�
.�
.�
.�
.�
.�
�K�K��9�@�@��E�E�F�F�F�F�F�	
��	!��t�|����!�!��,�q�/�C��Y�F�F�
���
�
�!�
#�
#��,�K�C����K�K��6�-�-�/�/�0�0�0��c�?�?�	G����c�5�)�)�
?�R��
�
�6�$�+�
�>�>�>�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?�
?����
?�
?�
?�
?��|�
��S�=�=�3�:�:�3�?�?�C�C�2�39�6�#�v�3F�3F���c�
�
�
�
�
�

�
�
�K�K��9�@�@��E�E�F�F�F�F�F�	
��	 ��;�?�?�1�%�%����!�!�(�+�+���3���������
�
��03�l�/B�/B�4�,�s�+�+�+����K�	�
�\�\�(�H�
-�
-�	"��&�
"�
"�	����y�!�!�!�!�
"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"��<�	9��&�-�-�h�7�7�8�8�8�8�8�1
!�	 �.	9�	9sI�6AF�F�F�I�I�I�/M�M�M�R�R�
R�__main__r )l�version�
__author__�__credits__�builtinsrrFryr�rrhr�r�r`r��re�warningsr�r�r��AttributeError�NotImplementedErrorr�r��	NameError�__all__r6rrur�r�r�r�r�ryr�r)r'r�r�r�r/�CONTTYPEr�r�r�r�r�r�rrrrr�r!r�rr�r�rNrr�r
�getfilesystemencodingr<rCrSr[rerir|rrrrr	r
rr�r�r�rPr�r�r��objectr�r
�BufferedReaderr-r9r;r@rIrLrOrergrlrnr�r��compiler�rrrrCrr�r=r;�<module>rTs���:���6�
�H��
'�&�&�&�&�&�
�
�
�
�	�	�	�	�	�	�	�	�
�
�
�
���������
�
�
�
�����	�	�	�	�������J�J�J�J������
�C�C�C�������J�J�J�J������
�C�C�C�����$�%8�9��	��'��#�����	�	�	��D�	����%�%�%�����	�
��^�
��	��������
�
����
��
��
��
��
������������
��
������
�
�
�
����H�g��G�X��W�g�#�%5�!�	#���(��>�+�
��/�
�
�	�.�
�9�8�8��
�
�
����
����7�d�?�?��H�H�(�s�(�*�*�H�0�0�0�&�&�&�
�
�
�(�N�
�
�
�
�<*�*�*�"&��$�����2���	�	�	�	�	�y�	�	�	�	�	�	�	�	�8�	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	�x�	�	�	�	�	�	�	�	�(�	�	�	�	�	�	�	�	�(�	�	�	�	�	�	�	�	�{�	�	�	�	�	�	�	�	�;�	�	�	�	�	�	�	�	�[�	�	�	�	�	�	�	�	��	�	�	�	�	�	�	�	�K�	�	�	���������0p�p�p�p�p�p�p�p�f�����6����<e�e�e�e�e�&�e�e�e�P"�"�"�"�"�2�$�"�"�"�	�	�	�	�	�(�	�	�	�J�J�J�J�J��J�J�J�
?�?�?�?�?�k�?�?�?�@�@�@�@�@�{�@�@�@�
L�L�L�L�L��L�L�L�
?�?�?�?�?�+�?�?�?�=�=�=�=�~���������*������	�����&�2�:�&8�9�9��Z9�Z9�Z9�Z9�Z9�f�Z9�Z9�Z9�zG�G�G�G�G�f�G�G�G�Z$���$�|��]9�]9�]9�~�z����D�F�F�F�F�F��s3�<�A�A�
A�A�A�!A(�(A0�/A0

?>