Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_tarfile.cpython-310.opt-1.pyc

o

0�iq��@s�ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZddlmZddlmZddlmZzddlZWneykdZYnwzddlZWney}dZYnwzddlZWney�dZYnwzddlZWney�dZYnwd	d
�Zej�ej �dZ!e!dZ"e�#d
�Z$ej�%e!d�Z&ej�%e!d�Z'ej�%e!d�Z(ej�%e!d�Z)ej�%e!d�Z*dZ+dZ,dZ-Gdd�d�Z.e�/�Gdd�d��Z0e�1�Gdd�d��Z2e�3�Gdd�d��Z4Gdd�de.�Z5Gd d!�d!e5ej6�Z7Gd"d#�d#e0e7�Z8Gd$d%�d%e2e7�Z9Gd&d'�d'e4e7�Z:Gd(d)�d)e5ej6�Z;Gd*d+�d+e0e;�Z<Gd,d-�d-e2e;�Z=Gd.d/�d/e4e;�Z>Gd0d1�d1e5�Z?Gd2d3�d3e?�Z@Gd4d5�d5e@ej6�ZAGd6d7�d7e0e@ej6�ZBGd8d9�d9e2e@ej6�ZCGd:d;�d;e4e@ej6�ZDGd<d=�d=e?ej6�ZEGd>d?�d?e0eE�ZFGd@dA�dAe2eE�ZGGdBdC�dCe4eE�ZHGdDdE�dEe.ej6�ZIGdFdG�dGe0eI�ZJGdHdI�dIe2eI�ZKGdJdK�dKe4eI�ZLGdLdM�dMe5ej6�ZMGdNdO�dO�ZNGdPdQ�dQeNe5ej6�ZOGdRdS�dSeNe5ej6�ZPGdTdU�dUe.�ZQGdVdW�dWeQej6�ZRGdXdY�dYe0eR�ZSGdZd[�d[e2eR�ZTGd\d]�d]e4eR�ZUGd^d_�d_eQej6�ZVGd`da�dae0eV�ZWGdbdc�dce2eV�ZXGddde�dee4eV�ZYGdfdg�dgej6�ZZGdhdi�dieQej6�Z[Gdjdk�dkeQej6�Z\Gdldm�dme0e\�Z]Gdndo�doe2e\�Z^Gdpdq�dqe4e\�Z_Gdrds�dse\�Z`e�aebedt�du�Gdvdw�dwej6��ZcGdxdy�dyeZ�ZdGdzd{�d{�ZeGd|d}�d}eeej6�ZfGd~d�deeej6�ZgGd�d��d�eeej6�ZhGd�d��d��ZiGd�d��d�eiej6�ZjGd�d��d�e0eiej6�ZkGd�d��d�e2eiej6�ZlGd�d��d�e4eiej6�ZmGd�d��d�ej6�ZnGd�d��d�ej6�ZoGd�d��d�ej6�ZpGd�d��d�ej6�Zqe�rebedt�d��Gd�d��d�e5ej6��ZsGd�d��d�e2ej6�Ztd�d��Zue�aebed��d��e�aebed��d��Gd�d��d�ej6���ZvGd�d��d�e5ej6�ZwGd�d��d�e5�ZxGd�d��d�exej6�ZyGd�d��d�exej6�ZzGd�d��d�exej6�Z{Gd�d��d�exej6�Z|Gd�d��d�ej6�Z}d�d��Z~Gd�d��d��ZGd�d��d�ej6�Z�Gd�d��d�ej6�Z�d�d��Z�d�d��Z�e�d�k�r�e���dSdS)��N)�sha256)�contextmanager)�Random)�support)�	os_helper)�
script_helper)�warnings_helpercCst|���S�N)rZ	hexdigest)�data�r�8/opt/alt/python310/lib64/python3.10/test/test_tarfile.py�	sha256sum)sr
z-tardirz
-extract-testztesttar.tarztesttar.tar.gzztesttar.tar.bz2�testtar.tar.xzztmp.tarZtesttar� Z@e09e4bc8b3c9d9177e77256353b36c159f5f040531bbd4b024a8f9b9196c71ceZ@4f05a776071146756345ceee937b33fc5644f5a96b9780d1c7d6a32cdf164d7bc@s.eZdZeZdZejZej	j
Z
edd��ZdS)�TarTest�cCs|j|jSr	)�prefix�suffix��selfrrr�modeDszTarTest.modeN)
�__name__�
__module__�__qualname__�tarnamer�io�FileIO�open�tarfile�TarFile�taropen�propertyrrrrrr>src@�*eZdZeZdZer
ejndZe	j
jZdS)�GzipTestZgzN)
rrr�gzipnamerr�gzipZGzipFilerrrZgzopenr rrrrr#H�
r#c@r")�Bz2Test�bz2N)
rrr�bz2namerrr(�BZ2FilerrrZbz2openr rrrrr'Or&r'c@r")�LzmaTestZxzN)
rrr�xznamerr�lzmaZLZMAFilerrr�xzopenr rrrrr+Vr&r+c@s eZdZdZdd�Zdd�ZdS)�ReadTest�r:cCstj|j|jdd�|_dS)N�	iso8859-1�r�encoding�rrrr�tarrrrr�setUpbs�zReadTest.setUpcCs|j��dSr	)r5�closerrrr�tearDownf�zReadTest.tearDownN)rrrrr6r8rrrrr/^sr/c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Ze�eed�o?eed�d�dd��ZdS)�
UstarReadTestcCsl|j�d�}|j�|�� }|��}|�t|�|jd�|�t|�td�Wd�dS1s/wYdS)N�
ustar/regtype�regular file extraction failed)	r5�	getmember�extractfile�read�assertEqual�len�sizer
�sha256_regtype�r�tarinfo�fobjr
rrr�test_fileobj_regular_filels��"�z'UstarReadTest.test_fileobj_regular_filecCs�|jjdtdd�|j�d�}ttj�td�d��}|��}Wd�n1s(wY|j�	|��+}t
�|�}|��}|�||d�|�t
|�dd�|�|ddd�Wd�dS1sawYdS)	Nr;r
��filter�rzfileobj.readlines() failed�r�SzOI will gladly admit that Python is not the fastest running scripting language.
)r5�extract�TEMPDIRr=r�os�path�join�	readlinesr>r�
TextIOWrapperr@rA)rrE�fobj1�lines1rF�fobj2�lines2rrr�test_fileobj_readlinesus&
�
��
�"�z$UstarReadTest.test_fileobj_readlinescCs�|jjdtdd�|j�d�}ttj�td�d��}|��}Wd�n1s(wY|j�	|��}t
t�|��}|�
||d�Wd�dS1sMwYdS)Nr;r
rHrJzfileobj.__iter__() failed)r5rMrNr=rrOrPrQrRr>�listrrSr@)rrErTrUrVrWrrr�test_fileobj_iter�s
��"�zUstarReadTest.test_fileobj_iterc	Cs.|jjdtdd�ttj�td�d��}|��}Wd�n1s"wY|j�d�}|j�	|���}|��}|�
d�|�d|��d�|�
dd�|�d|��d�|�
d	d
�|�d|��d�|�
dd
�|�d|��d
�|�d�}|�||dd�d�|�
dd�|�|j
|��d�|�|��dd�|�
|j
d�|�d|��d�|�
d�|��}|�
d�|��}|�||d�|�
d�|�t|���|��d�|�
d�|�t|���d|��d�|�
d�|��}|�|��|t|�d�d�Wd�dS1�swYdS)Nr;r
rH�rbrzseek() to file's start failediz"seek() to absolute position failedi�����z+seek() to negative relative position failedz+seek() to positive relative position failed�
i
zread() after seek failed�zseek() to file's end failed�z0read() at file's end did not return empty stringz$relative seek() to file's end failed�zreadlines() after seek failedztell() after readline() failedz)tell() after seek() and readline() failedzread() after readline() failed)r5rMrNrrOrPrQr?r=r>�seekr@�tellrBrRrA�readline)	rrFr
rE�text�s�s1�s2�linerrr�test_fileobj_seek�sz
�
�
����
����

�
�
�
�$�zUstarReadTest.test_fileobj_seekc	Cs�|j�d��;}t�|�}|���d�}|�t|�t�z|�	d�Wnt
y0|�d�Yn	wWd�dSWd�dS1sDwYdS)Nr;r1�dzseeking failed in text mode)r5r>rrSr?�encoder@r
rCrb�AttributeError�fail�rrFr
rrr�test_fileobj_text�s
���	"�zUstarReadTest.test_fileobj_textc	Cs~|j�|��/}|j�|��}|�|j|j�Wd�n1s wYWd�dSWd�dS1s8wYdSr	)r5r>r@�name)rZlnktype�regtype�a�brrr�_test_fileobj_link�s
�P�z UstarReadTest._test_fileobj_linkcC�|�dd�dS)N�
ustar/lnktyper;�rurrrr�test_fileobj_link1��z UstarReadTest.test_fileobj_link1cCrv)N�./ustar/linktest2/lnktype�ustar/linktest1/regtyperxrrrr�test_fileobj_link2���z UstarReadTest.test_fileobj_link2cCrv)N�
ustar/symtyper;rxrrrr�test_fileobj_symlink1�rzz#UstarReadTest.test_fileobj_symlink1cCrv)N�./ustar/linktest2/symtyper|rxrrrr�test_fileobj_symlink2�r~z#UstarReadTest.test_fileobj_symlink2cCrv)NZsymtype2r;rxrrrr�test_issue14160�rzzUstarReadTest.test_issue14160cCs|�d�|�d�dS)N�barZeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)�add_dir_and_getmemberrrrr�test_add_dir_getmember�s
z$UstarReadTest.test_add_dir_getmember�getuid�getgidz'Missing getuid or getgid implementationcCs�dd�}t���ht�td��&}tj|_zt�|�|j	||d�Wt�
|�nt�
|�wWd�n1s8wYt�t��}|�|�|�|�|d��Wd�n1s[wYWd�dSWd�dS1sswYdS)NcSsd|_|_|S)Nrk)�uid�gid�rErrrrI�sz3UstarReadTest.add_dir_and_getmember.<locals>.filter�wrH�/)
r�temp_cwdrr�tmpname�USTAR_FORMAT�formatrO�mkdir�add�rmdirr@r=)rrqrIr5rrrr��s$

����"�z#UstarReadTest.add_dir_and_getmemberN)rrrrGrXrZrjrpruryr}r�r�r�r��unittest�
skipUnless�hasattrrOr�rrrrr:js"	
1�r:c@�eZdZdS)�GzipUstarReadTestN�rrrrrrrr��r�c@r�)�Bz2UstarReadTestNr�rrrrr�r�r�c@r�)�LzmaUstarReadTestNr�rrrrr�r�r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ListTestcCstj|j|jd�|_dS)N�rr4rrrrr6szListTest.setUpcs@tjt��ddd�}t�td|���jjdd�Wd�n1s#wY|���	�}��
d|���
d|���
d	|���
d
|���
d|���
d|���
d
|���
d|��fdd�}��
|d�|���
|d�|���
|d�|���
|d�|���
|d�|���|d���d|���d|�dS)N�ascii�
��newline�stdoutF��verbose�ustar/conttype�
ustar/regtypes
ustar/lnktypesustar/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/1234567/longnames./ustar/linktest2/symtypes./ustar/linktest2/lnktypesustar/dirtype/sustar/dirtype-with-size/cs|��jjd�}|�dd�S)N�surrogateescaper��backslashreplace)�decoder5r3rl)rtrfrrr�conv sz ListTest.test_list.<locals>.convsustar/umlauts-�����s'misc/regtype-hpux-signed-chksum-�����s)misc/regtype-old-v7-signed-chksum-�����spax/bad-pax-�spax/hdrcharset-�s)ustar/conttype ?\r?\nustar/regtype ?\r?\nslink tos->)
rrS�BytesIOr�	swap_attr�sysr5rY�detach�getvalue�assertIn�assertRegex�assertNotIn)r�tio�outr�rrr�	test_lists4�
�
�zListTest.test_listcCs�tjt��ddd�}t�td|��|jjdd�Wd�n1s#wY|���	�}|�
|d�|�d|�|�d	|�|�d
|�|�d|�|�d|�dS)
Nr�r�r�r�Tr�s�\?rw-r--r-- tarfile/tarfile\s+7011 \d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ustar/\w+type ?\r?\n\?rw-r--r-- tarfile/tarfile\s+7011 \d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ustar/\w+type ?\r?\nsustar/symtype -> regtypes1./ustar/linktest2/symtype -> ../linktest1/regtypes;./ustar/linktest2/lnktype link to ./ustar/linktest1/regtypes	gnu/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longlink link to gnu/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnames	pax/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longlink link to pax/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longname)rrSr�rr�r�r5rYr�r�r�r�)rr�r�rrr�test_list_verbose6s"����zListTest.test_list_verbosecCs�tjt��ddd�}dd�}t�td|��|jjd||j�d�Wd�n1s+wY|���	�}|�
d	|�|�d
|�dS)Nr�r�r�css$�|��D]
}d|jvr|VqdS)NZreg)�
getmembersrq)r5rErrr�membersPs�
��z+ListTest.test_list_members.<locals>.membersr�F)r�r�r�r�)rrSr�rr�r�r5rYr�r�r�r�)rr�r�r�rrr�test_list_membersNs�zListTest.test_list_membersN)rrrr6r�r�r�rrrrr�s
%r�c@r�)�GzipListTestNr�rrrrr�[r�r�c@r�)�Bz2ListTestNr�rrrrr�_r�r�c@r�)�LzmaListTestNr�rrrrr�cr�r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�CommonReadTestcCs�ttd��Wd�n1swY|�t�t��|�t�t�t���ttd��}|�t�|��Wd�n1s@wY|�t�t�d���dS)N�wbr[sinvalid)	rr��assertFalser�
is_tarfile�pathlib�Pathrr��rrFrrr�test_is_tarfile_erroneousis��z(CommonReadTest.test_is_tarfile_erroneousc	Cs�|�t�|j��|�t�t�|j���t|jd��}|�t�|��Wd�n1s.wYt|jd��}|�t�t�|�	����Wd�dS1sRwYdS)Nr[)
�
assertTruerr�rr�r�rrr�r?r�rrr�test_is_tarfile_validzs�"�z$CommonReadTest.test_is_tarfile_validcCs�t�t|j�dd���Wd�n1swYz3z
t�t|j�}|��Wntjy8|�d�Ynw|�|�	�g�W|�
�dSW|�
�dS|�
�w)NrJr�z&tarfile.open() failed on empty archive)rrr�r�replace�getnames�	ReadErrorrn�assertListEqualr�r7�rr5rrr�test_empty_tarfile�s���z!CommonReadTest.test_empty_tarfilecCs@|�td��t�d|j�Wd�dS1swYdS)NZxxx)�assertRaisesRegex�FileNotFoundErrorrrrrrrr�test_non_existent_tarfile�s"�z(CommonReadTest.test_non_existent_tarfilecCsVttd��Wd�n1swY|�tjtjt|j�|�tjtjt�dS�Nr�)rr��assertRaisesrr�rrrrr�test_null_tarfile�s
�z CommonReadTest.test_null_tarfilec	Cs�td��d�}dD]T}|�td��%}|�|d�t�d�}t|�|_|�|�	��|�|�Wd�n1s9wYtjtddd	�}z|�
|��dgd
|�W|��q	|��wdS)Nrra)��ar�r]�foorJT)r�ignore_zerosz3ignore_zeros=True should have skipped the %r-blocks)
rZ	randbytesrr��writer�TarInforArB�tobufr�r�r7)rr
�charrFrEr5rrr�test_ignore_zeros�s$

����z CommonReadTest.test_ignore_zerosc
Cs�dD]�}t�td��}t�d�}d|_|�|t�d��Wd�n1s&wYttd��
}|�|�Wd�n1s@wYt�t��$}|�	tj
d��
|D]}qUWd�n1sbwYWd�n1sqwYt�t��I}|��}|�	tj
d��|j|t
dd	�Wd�n1s�wY|�	tj
d��|�|���Wd�n1s�wYWd�n1s�wYqdS)
N)raiXr]i��w:r�r]saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazr+bzunexpected end of datar
rH)rrr�r�rB�addfilerr��truncater�r��nextrMrNr>r?)rrBr5�trFrrr�test_premature_end_of_archive�s:
������������z,CommonReadTest.test_premature_end_of_archivec	Cst|�tjd��)t�t�d���}Wd�n1swYWd�dSWd�dS1s3wYdS)N�%file could not be opened successfullyz
recursion.tar)r�rr�rr�findfiler�rrr�test_length_zero_header�s��"�z&CommonReadTest.test_length_zero_headerN)rrrr�r�r�r�r�r�r�r�rrrrr�gs	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Ze�eed�d�ejdd ���Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Ze�ed-ud.�d/d0��Z d-S)1�MiscReadTestBasecCsdSr	rrrrr�requires_name_attribute�sz(MiscReadTestBase.requires_name_attributec	Cs�|��t|jd��C}|�|jt�tj||jd��}|�|jt�|�|jt	j
�|j��Wd�n1s8wYWd�dSWd�dS1sPwYdS�Nr[��fileobjr)r�rr�assertIsInstancerq�strrrr@rOrP�abspath�rrFr5rrr�test_no_name_argument�s��"�z&MiscReadTestBase.test_no_name_argumentcCsnt|jd��}|��}Wd�n1swYt�|�}|�tt|d�tj||j	d�}|�
|j�dS)Nr[rqr�)rrr?rr�r�rm�getattrrr�assertIsNonerq�rrFr
r5rrr�test_no_name_attribute�s
�
z'MiscReadTestBase.test_no_name_attributecCs�t|jd��}|��}Wd�n1swYt�|�}d|_tj||jd��}|�|j�Wd�dS1s<wYdS)Nr[rr�)	rrr?rr�rqrrr�r�rrr�test_empty_name_attribute�s
�
"�z*MiscReadTestBase.test_empty_name_attributec	Cs�t�|jtj�}t|d��6}|�|jt�tj||jd��}|�	|j�Wd�n1s.wYWd�dSWd�dS1sFwYdSr�)
rOrr�O_RDONLYr�rq�intrrr�)r�fdrFr5rrr�test_int_name_attribute�s��"�z(MiscReadTestBase.test_int_name_attributec	Cs�|��t�|j�}t|d��C}|�|jt�tj||j	d��}|�|jt�|�
|jtj�|j��Wd�n1s=wYWd�dSWd�dS1sUwYdSr�)
r�rO�fsencoderrr�rq�bytesrrr@rPr�)rrrFr5rrr�test_bytes_name_attributes��"�z*MiscReadTestBase.test_bytes_name_attributec	Cs�t�|j�}tj||jd��}|�|jt�|�	|jt
j�t
�
|���Wd�n1s.wY|�|��}|�|jt�|�	|jt
j�t
�
|���Wd�n1sXwYtjj||jd��}|�|jt�|�	|jt
j�t
�
|���Wd�n1s�wY|jdkr�tj|dd��}|�|jt�|�	|jt
j�t
�
|���Wd�dS1s�wYdSdS)Nr�rrJ)r�r�rrrrr�rqr�r@rOrPr��fspathr rr)rrr5rrr�test_pathlike_names&���
"��z#MiscReadTestBase.test_pathlike_namecCs�ttd��Wd�n1swY|�td��|�td�}Wd�n1s,wY|�td��|�td�}Wd�n1sHwY|�td��|�td�}Wd�dS1sewYdS)Nr�z
mode must be �q�rwr)rr�r��
ValueErrorr r�rrr�test_illegal_mode_args���"�z&MiscReadTestBase.test_illegal_mode_argc	Cs,tj|j|jd�}z-|��|��}|j}|j}|�|��}|��}Wd�n1s,wYW|�	�n|�	�w|�|j��J}|�
|�|j|jd|d��#}|��}|�|j|�|��|�|�|���|d�Wd�n1swwYWd�dSWd�dS1s�wYdS)Nr�r0�rr�zseek back did not work)
rrrrr�rq�offsetr>r?r7rbr@r�)rr5r�rqr�fr
rFrrr�test_fileobj_with_offset&s0
��
���"�z)MiscReadTestBase.test_fileobj_with_offsetcCs^|�tjtjt|j�ttd��}|jtjtj||jd�Wd�dS1s(wYdSr�)r�rr�rrrr�rrr�test_fail_compBs�"�zMiscReadTestBase.test_fail_compcCs"|j�d�}|�|jtjd�dS)Nzmisc/dirtype-old-v7zv7 dirtype failed)r5r=r@�typer�DIRTYPE�rrErrr�test_v7_dirtypeIs�z MiscReadTestBase.test_v7_dirtypecCs2z	|j�d�WdSty|�d�YdSw)Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))r5r=�KeyErrorrnrrrr�test_xstar_typeQs
�z MiscReadTestBase.test_xstar_typecCsN|jD]!}|�t|j�dd|j�|j�d�sq|�|jdd|j�qdS)N鏽>zwrong mtime for %szustar/rzwrong uname for %s)r5r@r��mtimerq�
startswith�unamer
rrr�test_check_membersZs
�
��z#MiscReadTestBase.test_check_memberscCs|�|j��djdd�dS)N���zmisc/eofzcould not find all members)r@r5r�rqrrrr�test_find_memberscs�z"MiscReadTestBase.test_find_members�link�Missing hardlink implementationc	CsFtjtddd���}|jdtdd�|�tjtj	�
td��|jdtdd�|�tjtj	�
td��ttj	�
td�d��}|��}Wd�n1sJwY|�t
|�t�|jd	tdd�|�tjtj	�
td	��ttj	�
td	�d��}|��}Wd�n1s�wY|�t
|�t�Wd�dS1s�wYdS)
Nr\r1)�
errorlevelr3r;r
rHrwr[r)rrrrMrN�
addCleanupr�unlinkrOrPrQr?r@r
rC)rr5rr
rrr�test_extract_hardlinkgs 
�
�"�z&MiscReadTestBase.test_extract_hardlinkc		Cs�tjtdd�}tj�td�}t�|�z\dd�|D�}|j||dd�|D]>}tj�||j	�}t
jdkrE|�|j
d	@t�|�jd	@|j	�d
d�}tj�|�}d�||j�||�|�}|�|j||�q%W|��t�|�dS|��t�|�w)
Nr1�r3�
extractallcS�g|]}|��r|�qSr��isdir��.0r�rrr�
<listcomp>��z4MiscReadTestBase.test_extractall.<locals>.<listcomp>�
fully_trustedrH�win32�cSs$t|t�r
d�||���Sd�|�S)Nz{} ({})z
{!r} (int))�
isinstance�floatr��hex)rrrr�format_mtime�s

z6MiscReadTestBase.test_extractall.<locals>.format_mtimez,tar mtime {0} != file time {1} of path {2!a})rrrrOrPrQrNr�rrqr��platformr@r�stat�st_mode�getmtimer�rr7r�rmtree)	rr5�DIR�directoriesrErPr*Z
file_mtime�errmsgrrr�test_extractall|s4

����z MiscReadTestBase.test_extractallc	Cs�d}tj�td�}t�|�zWtjtdd��8}|�|�}|j	||dd�tj�||�}|�
tj�|�|j�t
jdkrG|�
t�|�jd@d	�Wd�n1sQwYWt�|�dSWt�|�dSt�|�w)
N�
ustar/dirtypeZ
extractdirr1rr$�rPrIr%r&i�)rOrPrQrNr�rrrr=rMr@r.rr�r+r,r-rr/�rZdirtyper0r5rEZ	extractedrrr�test_extract_directory�s 


���z'MiscReadTestBase.test_extract_directoryc	Cs�t�t�d}t�|��Ltjtdd��,}dd�|D�}|j||dd�|D]}||j	}|�
tj�
|�|j�q&Wd�n1sCwYWd�dSWd�dS1s[wYdS)Nrr1rcSrrrr rrrr"�r#zBMiscReadTestBase.test_extractall_pathlike_name.<locals>.<listcomp>r$rH)r�r�rNr�temp_dirrrrrrqr@rOrPr.r)rr0r5r1rErPrrr�test_extractall_pathlike_name�s�
�P�z.MiscReadTestBase.test_extractall_pathlike_namec	Cs�d}t�t�d}t�|��Dtjtdd��$}|�|�}|j	||dd�||}|�
tj�
|�|j�Wd�n1s=wYWd�dSWd�dS1sUwYdS)Nr4rr1rr$r5)r�r�rNrr8rrrr=rMr@rOrPr.rr6rrr�test_extract_pathlike_name�s�
P�z+MiscReadTestBase.test_extract_pathlike_namec	Cs�tj�td�}t|d��
}|�d�Wd�n1swYz4t�tj	�}z|�
|�Wntjy@|�|j
j�Ynw|�d�Wt�|�dSWt�|�dSt�|�w)N�emptyr�r`zReadError not raised)rOrPrQrNrr��object�__new__rr�__init__r�r�r��closedrnrr)rr;rFr5rrr�test_init_close_fobj�s���z%MiscReadTestBase.test_init_close_fobjcCsjt�|j��%}t||�D]\}}|�|j|j�|�|��|���qWd�dS1s.wYdSr	)rrr�zipr@r�get_info)rr5Zm1Zm2rrr�test_parallel_iteration�s�"�z(MiscReadTestBase.test_parallel_iterationNz
requires zlibc	Cs�tj�d��1}tj|_|�tj��t�	|j
�Wd�n1s"wYWd�dSWd�dS1s:wYdS)Nztarfile.TarInfo.fromtarfile)r��mock�patch�zlib�error�side_effectr�rr�rr)rrDrrr�test_zlib_error_does_not_leak�s��"�z.MiscReadTestBase.test_zlib_error_does_not_leak)!rrrr�r�r�r�r�r�r�rrrrr
rrr�r�r�rOr�skip_unless_symlinkrr3r7r9r:r@rC�skipIfrFrIrrrrr��s8		
		�

r�c@�eZdZdZdS)�MiscReadTestN)rrrrrrrrrM��rMc@r�)�GzipMiscReadTestNr�rrrrrO�r�rOc@�eZdZdd�ZdS)�Bz2MiscReadTestcC�|�d�dS)NzBZ2File have no name attribute��skipTestrrrrr��r9z'Bz2MiscReadTest.requires_name_attributeN�rrrr�rrrrrQ��rQc@rP)�LzmaMiscReadTestcCrR)NzLZMAFile have no name attributerSrrrrr��r9z(LzmaMiscReadTest.requires_name_attributeNrUrrrrrW�rVrWc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StreamReadTest�r|c
Cs~|jD]9}|��s
q|j�|��$}	z|�d�}Wntjy(|�d�Ynw|s,nqWd�n1s7wYqdS)NTraz6simple read-through using TarFile.extractfile() failed)r5�isregr>r?r�StreamErrorrn)rrErF�bufrrr�test_read_through�s"
�����z StreamReadTest.test_read_throughcCsh|j��}|j�|��}|��}Wd�n1swY|�t|�|jd�|�t|�td�dS)Nr<)	r5r�r>r?r@rArBr
rCrDrrrrGs

���z(StreamReadTest.test_fileobj_regular_filecCsP|j��}|j�|d��}|�tj|j�Wd�dS1s!wYdS�Nr)r5r�r>r�rr[r?)rZtarinfosrrrr�test_provoke_stream_errors
"�z(StreamReadTest.test_provoke_stream_errorcCs�tjtdd�}zc|j}	|��}|��}|durnK|�|d�|��s'|��rC|�tj	��
|�
|�Wd�n1s=wYq|�
|�}|�
|�}|durRq|�|d�|�|��|��d�qW|�
�dS|�
�w)Nr1rTzstream.next() failed.zstream.extractfile() failedzstream extraction failed)rrrr5r��assertIsNotNoneZislnkZissymr�r[r>r@r?r7)rZtar1Ztar2�t1�t2�v1�v2rrr�test_compare_memberss2�

��z#StreamReadTest.test_compare_membersN)rrrrr]rGr_rerrrrrX�s	rXc@r�)�GzipStreamReadTestNr�rrrrrf/r�rfc@r�)�Bz2StreamReadTestNr�rrrrrg2r�rgc@r�)�LzmaStreamReadTestNr�rrrrrh5r�rhc@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�DetectReadTestc
CsNzt�||�}Wntjy }z|��WYd}~dSd}~ww|��dSr	)rrr�rnr7)rrqrr5�errr�_testfunc_file:s��zDetectReadTest._testfunc_filec
Cs|zt|d��}tj|||d�}Wd�n1swYWntjy7}z|��WYd}~dSd}~ww|��dS)Nr[�r�)rrr�rnr7)rrqrrr5rkrrr�_testfunc_fileobjBs����z DetectReadTest._testfunc_fileobjcCsJ|jr|�tj��tjtd|jd�Wd�n1swY|�tj��tjtd|jd�Wd�n1s>wY|�tj��tj|jdd�Wd�n1s\wY|�tj��tj|jdd�Wd�n1szwY||jd�||jd|j�||jd�||jd|j�||jd�dS)Nr0r�rYrJzr:*�r|*)rr�rr�rr)rZtestfuncrrr�_test_modesKs$����zDetectReadTest._test_modescC�|�|j�dSr	)rprlrrrr�test_detect_file[rzzDetectReadTest.test_detect_filecCrqr	)rprnrrrr�test_detect_fileobj^rzz"DetectReadTest.test_detect_fileobjN)rrrrlrnrprrrsrrrrrj9s	rjc@r�)�GzipDetectReadTestNr�rrrrrtar�rtc@rP)�Bz2DetectReadTestcCs|ttd��}|��}Wd�n1swYtjtddd��
}|�|�Wd�n1s1wY|�td�dS)Nr[r�r\�Z
compresslevelro)rrr?r(r*r�r�rlrorrr�test_detect_stream_bz2es
��z(Bz2DetectReadTest.test_detect_stream_bz2N)rrrrwrrrrrudrVruc@r�)�LzmaDetectReadTestNr�rrrrrxsr�rxc@s�eZdZd(dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS))�MemberReadTestNcKs�|dur(|j�|��}|�t|���|d|j�Wd�n1s#wYd|d<d|d<d|d<d|jvrAd	|d
<d	|d<|��D]\}}|�t||�|d||jf�qEdS)
N�wrong sha256sum for %srr��r�rkr�zold-v7rr�gnamezwrong value in %s field of %s)r5r>r@r
r?rq�itemsr�)rrE�chksum�kwargsr�k�vrrr�_test_memberys"��
��zMemberReadTest._test_membercC� |j�d�}|j|dtd�dS)Nr;�c�rBr~�r5r=r�rCr
rrr�test_find_regtype��z MemberReadTest.test_find_regtypecCr�)Nzustar/conttyper�r�r�r
rrr�test_find_conttype�r�z!MemberReadTest.test_find_conttypecC�|j�d�}|j|dd�dS)Nr4r�rB�r5r=r�r
rrr�test_find_dirtype��z MemberReadTest.test_find_dirtypecCr�)Nzustar/dirtype-with-size�r�r�r
rrr�test_find_dirtype_with_size�r�z*MemberReadTest.test_find_dirtype_with_sizecC� |j�d�}|j|ddd�dS)Nrwrr;�rB�linknamer�r
rrr�test_find_lnktype�r�z MemberReadTest.test_find_lnktypecCr�)Nrrrrr�r�r
rrr�test_find_symtype�r�z MemberReadTest.test_find_symtypecCs"|j�d�}|j|dddd�dS)N�
ustar/blktyper��rB�devmajor�devminorr�r
rrr�test_find_blktype��z MemberReadTest.test_find_blktypecCs"|j�d�}|j|dddd�dS)N�
ustar/chrtyperr\r�r�r�r
rrr�test_find_chrtype�r�z MemberReadTest.test_find_chrtypecCr�)N�ustar/fifotyperr�r�r
rrr�test_find_fifotype�r�z!MemberReadTest.test_find_fifotypecCr�)Nzustar/sparse�Pr��r5r=r��
sha256_sparser
rrr�test_find_sparse�r�zMemberReadTest.test_find_sparsecCr�)N�
gnu/sparser�r�r�r
rrr�test_find_gnusparse�r�z"MemberReadTest.test_find_gnusparsecCr�)N�gnu/sparse-0.0r�r�r�r
rrr�test_find_gnusparse_00�r�z%MemberReadTest.test_find_gnusparse_00cCr�)N�gnu/sparse-0.1r�r�r�r
rrr�test_find_gnusparse_01�r�z%MemberReadTest.test_find_gnusparse_01cCr�)N�gnu/sparse-1.0r�r�r�r
rrr�test_find_gnusparse_10�r�z%MemberReadTest.test_find_gnusparse_10cCr�)Nuustar/umlauts-ÄÖÜäöüßr�r�r�r
rrr�test_find_umlauts�sz MemberReadTest.test_find_umlautscCsd}|�||j���dS)Naustar/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/1234567/longname)r�r5r��rrqrrr�test_find_ustar_longname�sz'MemberReadTest.test_find_ustar_longnamecCr�)Nzmisc/regtype-old-v7r�r�r�r
rrr�test_find_regtype_oldv7�r�z&MemberReadTest.test_find_regtype_oldv7cCs@|j��tj|j|jdd�|_|j�d�}|j|dtd�dS)Nr1r2upax/umlauts-ÄÖÜäöüßr�r�)	r5r7rrrrr=r�rCr
rrr�test_find_pax_umlauts�s
�z$MemberReadTest.test_find_pax_umlautsr	)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrryws(
ryc@ri)�LongnameTestcCsV|jddd}z|j�|�}Wnty|�d�Ynw|�|jtjd�dS)Nr���123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/�longnamezlongname not foundzread longname as dirtype)	�subdirr5r=rrn�assertNotEqualrrr	)rr�rErrr�test_read_longname�s��zLongnameTest.test_read_longnamecCsf|jddd}|jddd}z|j�|�}Wnty(|�d�Ynw|�|j|d�dS)Nr�r�r��longlinkzlonglink not foundzlinkname wrong)r�r5r=rrnr@r�)rr�r�rErrr�test_read_longlink�s�zLongnameTest.test_read_longlinkcCs�|jddd}|j�|�}|j}|jj�|�t�|jj�d��}|�	t
j��t
jd|d�Wd�dS1s<wYdS)Nr�r�r�izfoo.tar)rqr�)
r�r5r=rr�rbrr�r?r�rr�r)rr�rErrFrrr�test_truncated_longname�s"�z$LongnameTest.test_truncated_longnamecCs�|jddd}|j�|�j}ttd��!}|�|�tj�	|�
d�dd�}|�|j|j
�Wd�dS1s9wYdS)Nr�r�r�r[rar1�strict)r�r5r=rrrrbrr�Zfrombufr?r@r�longnametype)rr�rrFrErrr�test_header_offset�s
�"�zLongnameTest.test_header_offsetcCs�d}t���kt�td��$}|j|_zt�|�|�|�Wt�	|�nt�	|�wWd�n1s4wYt�t��}|�
|�|��|�
|�|�d���Wd�n1s\wYWd�dSWd�dS1stwYdS)Nzfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/r�r�)
rr�rrr�r�rOr�r�r�r`r=�removesuffix)rZlongdirr5rrr�test_longname_directorys 

���"�z$LongnameTest.test_longname_directoryN)rrrr�r�r�r�r�rrrrr��s
		r�c@sPeZdZdZejZejZdd�Z	dd�Z
dd�Zdd	�Zd
d�Z
edd
��ZdS)�GNUReadTest�gnucCs�|jj|tdd�tj�t|�}t|d��}|��}Wd�n1s$wY|�t	|�t
d|�|��rIt�|�}|�
|jd|j�dSdS)Nr
rHr[rzra)r5rMrNrOrPrQrr?r@r
r��_fs_supports_holesr,Z
assertLess�	st_blocks�st_size)rrq�filenamerFr
rfrrr�_test_sparse_files
��
�zGNUReadTest._test_sparse_filecCrR)Nr��r�rrrr�test_sparse_file_old)r9z GNUReadTest.test_sparse_file_oldcCrR)Nr�r�rrrr�test_sparse_file_00,r9zGNUReadTest.test_sparse_file_00cCrR)Nr�r�rrrr�test_sparse_file_01/r9zGNUReadTest.test_sparse_file_01cCrR)Nr�r�rrrr�test_sparse_file_102r9zGNUReadTest.test_sparse_file_10cCs�tj�d�rBtj�td�}t|d��}|�d�|�	d�|�
�Wd�n1s+wYt�|�}t�
|�|jd|jkSdS)NZlinuxzsparse-testr�isxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxraF)r�r+rrOrPrQrNrrbr�r�r,rrr�r�)rqrFrfrrrr�5s


�

zGNUReadTest._fs_supports_holesN)rrrr�r�GNUTYPE_LONGNAMEr��
GNU_FORMATr�r�r�r�r�r��staticmethodr�rrrrr�s	r�c@s4eZdZdZejZejZdd�Z	dd�Z
dd�ZdS)	�PaxReadTest�paxcCs�tjtdd�}z^|�d�}|�|jd�|�|jd�|�|j�d�d�|�d�}|�|jd	�|�|jd�|�|j�d�d�|�d
�}|�|jd�|�|jd�|�|j�d�d�W|�	�dS|�	�w)Nr1r�pax/regtype1r�r�zVENDOR.umlautsuÄÖÜäöüßzpax/regtype2rzpax/regtype3r)
rrrr=r@rr|�pax_headers�getr7�rr5rErrr�test_pax_global_headersRs*
�
�
�z#PaxReadTest.test_pax_global_headerscCs�tjtdd�}zG|�d�}|�|jd�|�|jd�|�|jd�|�|jd�|�t	|j�t
�|�t
|jd�d�|�t
|jd�d�W|��dS|��w)	Nr1rzpax/regtype4r��{g��^�AZatime�ctime)
rrrr=r@rBr�r�rrr(r�r7r�rrr�test_pax_number_fieldsis
z"PaxReadTest.test_pax_number_fieldsc
CsXd}ddi}|D]�}|j|d���tjtdtjdd�}zt��}d|_d	|_||_|�	|�W|�
�n|�
�wttd
��}|��}|�d|�|�
d|�}Wd�n1sYwYttd��}|��|�|�Wd�n1swwY|�tjd
��tjtdd�Wd�n1s�wYWd�n1s�wYqdS)N)
s	 foo=bar
s0 
s1 
s2 
s3 =
s4 =a
s1000000 foo=bar
s
0 foo=bar
s-12 foo=bar
s$000000000000000000000000036 foo=bar
r�r�)�headerr�r1�r�r3r�r\r[s11 foo=bar
r�z)method tar: ReadError\('invalid header'\)r)�subTestrrr��
PAX_FORMATr�rqr�r�r�r7r?r�r�r�r�r�r�)rZpax_header_replacementsr�Zreplacementr5r�rr
rrr�test_pax_header_bad_formatsxs<��������z'PaxReadTest.test_pax_header_bad_formatsN)rrrr�r�XHDTYPEr�r�r�r�r�r�rrrrr�Lsr�c@�eZdZdd�Zdd�ZdS)�
WriteTestBasecCs�t��}tj||jd��}|�t�d��Wd�n1swY|�|jd�|�	�}~t
��|�|j�|�||�	��dS)Nr�r�z#external fileobjs must never closed)
rr�rrrr�r�r�r?r�rZ
gc_collectr@)rrFr5r
rrr�test_fileobj_no_close�s�z#WriteTestBase.test_fileobj_no_closecCs�t�t|j�� }t�d�}tjtj|_|�|t	�
d|j��Wd�n1s*wY|�td��}|�t|�
��tjd�Wd�dS1sNwYdS)Nr�r�r[r_)rrr�rr��
RECORDSIZE�	BLOCKSIZErBr�rr�r@rAr?)rr5r�rFrrr�test_eof_marker�s
�"�zWriteTestBase.test_eof_markerN)rrrr�r�rrrrr��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
�ee
d�d�dd��Zejdd��Zdd�Zdd�Zd&dd�Zejdd��Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)'�	WriteTestr�cCsxd}t�t|j�}zt�|�}|�|�W|��n|��wt�t�}z|�|��d|d�W|��dS|��w)N�d0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789rz!failed to store 100 char filename)	rrr�rr�r�r7r@r�)rrqr5r�rrr�test_100_char_name�s

�zWriteTest.test_100_char_namecCs�t�t|j�}z,tj�td�}t|d��
}|�d�Wd�n1s$wY|�	|�W|�
�n|�
�w|�tj�t�dd�dS)N�filer��aaarztarfile is empty)
rrr�rrOrPrQrNr�r�r7Z
assertGreater�getsize)rr5rPrFrrr�
test_tar_size�s��zWriteTest.test_tar_sizecCs�t�t|j�}zUtj�td�}t|d��Wd�n1swY|�|�}|�	|j
d�t|d��
}|�d�Wd�n1sEwY|�|�}|�	|j
d�W|��dS|��w)Nr�r�rr�r�)
rrr�rrOrPrQrN�
gettarinfor@rBr�r7)rr5rPrErFrrr�test_file_size�s�
�
zWriteTest.test_file_sizec	Csttj�td�}t�|�z't�t|j�}z|�	|�}|�
|jd�W|��n|��wWt
�|�dSt
�|�w)N�	directoryr)rOrPrQrNr�rrr�rr�r@rBr7rr��rrPr5rErrr�test_directory_size�s

zWriteTest.test_directory_sizecCsVtj�td�}t�|�ttj�|d�d���ttj�|d�d���zlt�t|j	�}zCt
j�d��}ddg|_
|�|�Wd�n1sHwYg}|��D]}|�tj�|j�d�qS|�|gd��W|��n|��wWt�tj�|d��t�tj�|d��t�|�dSt�tj�|d��t�tj�|d��t�|�w)Nr��1rs�2z
os.listdirr)r�r�r�)rOrPrQrNr�rr7rr�rr�rDrE�return_valuer�r��append�splitrqr@rrr�)rrPr5Zmock_listdir�paths�mrrr�test_ordered_recursions,

��z WriteTest.test_ordered_recursionc	Cs�t�t|j��M}t�t�d}t|d��
}|�d�Wd�n1s$wY|�|�}|�t	�
|��}|�|jt
�|�|j|j�|�|jd�Wd�dS1sWwYdS)Nr�r�r�r�)rrr�rr�r�rNr�r�rOr�r�rqr�r@rB)rr5rPrFrEZtarinfo2rrr�test_gettarinfo_pathlike_names�
"�z'WriteTest.test_gettarinfo_pathlike_namerrc
Cstj�td�}tj�td�}t|d��
}|�d�Wd�n1s#wYzt�||�WntyI}z
|�d|�WYd}~nd}~wwz1t	�t
|j�}z|�|�|�|�}|�
|jd�W|��n|��wWt�|�t�|�dSt�|�t�|�w)Nr�link_targetr�r��
os.link(): %sr)rOrPrQrNrr�r�PermissionErrorrTrr�rr�r@rBr7rr)rr�targetrFrkr5rErrr�test_link_size's,���



�zWriteTest.test_link_sizec	Csvtj�td�}t�d|�z't�t|j�}z|�	|�}|�
|jd�W|��n|��wWt
�|�dSt
�|�w)N�symlinkr�r)rOrPrQrNr�rrr�rr�r@rBr7rrr�rrr�test_symlink_size?s
zWriteTest.test_symlink_sizecCs�tj�t�}t�t|j�}z@|�|j|d�|�	|�|�|�
�gd�t�t
��
|�	|�Wd�n1s9wY|�|�
�gd�W|��dS|��w)Nzarchive name must be absolutezadded the archive to itself)rOrPr�r�rrrr@rqr�r�r�
change_cwdrNr7)rZdstnamer5rrr�
test_add_selfMs"
�
���zWriteTest.test_add_selfc	Cs4tj�td�}t�|�z�dD]}tj�||�}t�|�qdd�}tjt	|j
dd�}z|j|d|d�W|��n|��w|�
t��|�|dd	d|�Wd�n1sXwYt�t	d
�}z#|D]}|�|jd�|�|jd�qf|�t|���d
�W|��n|��wWt�|�dSt�|�w)NrI)r�r�ZbazcSs&tj�|j�dkrdSd|_d|_|S)Nr�r�r�)rOrP�basenamerqr�rr�rrrrIgs
z%WriteTest.test_filter.<locals>.filterr1rZ	empty_dir)�arcnamerITrJr�r�r�)rOrPrQrNr�r�create_empty_filerrr�rr�r7r��	TypeErrorr@r�rrAr�r/)r�tempdirrqrIr5rErrr�test_filter_s,
�zWriteTest.test_filterNFcCs�tj�td�}|st�|�nt�|�t�t	|j
�}z
|j||d�W|��n|��wt�t	d�}z
|�
�}W|��n|��w|sLt�|�nt�|�|�|j|p]|�tjd��dS)Nr��rrJr�)rOrPrQrNrrr�rrr�rr�r7r�rr�r@rqr��sep)rrPZcmp_path�dirr�r5r�rrr�_test_pathname�s 


 zWriteTest._test_pathnamec	Csttj�td�}tj�td�}t�|�z�tj�|d�}tj�|d�}t|d��
}|�d�Wd�n1s7wYt�||�t�|d��}|j	|dd�|j	|dd�Wd�n1sawYtj|dd	�� }z	|j
|d
d�Wnty�|�d�YnwWd�n1s�wYWt
�|�t
�|�dSWt
�|�t
�|�dSt
�|�t
�|�w)
NZtestsymlinksztestsymlinks.tar�sourcer�r�z
something
r	r_�rr$r5z&extractall failed with symlinked files)rOrPrQrNr�rr�r�rr�r�OSErrorrnrrr/)rrZtemparchiveZsource_fileZtarget_filerr5rrr�test_extractall_symlinks�s>
��
����
�

�z"WriteTest.test_extractall_symlinkscCs<|�d�|�tj�ddd��|�tj�ddd��|�tj�dd��|�tj�ddd��|�tj�dddd��|�tj�dddd��|�tj�dddd��|�tj�dd��|�tj�ddd��|�tj�dddd��|�tj�dddd��|�dtjtjd�|jdtjtjddd�dS)Nr��.r��..T)r)rrOrPrQr
rrrr�test_pathnames�s
 zWriteTest.test_pathnamescCs6tjdkr
|�dd�dS|�dd�|�dd�dS)Nr%zC:\foor�z/fooz///foo)r�r+rrrrr�test_abs_pathnames�s
zWriteTest.test_abs_pathnamesc	Cs�t�t��Ht�t|j�}z|�d�W|��n|��wt�td�}z|D]}|j	dkr9|�
|j	�d�|j	�q'W|��n|��wWd�dS1sPwYdS)NrrJ�./)rrrNrrr�rr�r7rqr�r�rr5r�rrr�test_cwd�s
��"�zWriteTest.test_cwdc	s�tttfD]9�G�fdd�dtj�}|�}|����tjt|j	|tj
ddid�}Wd�n1s3wY|�|j�qdS)NcseZdZdZ�fdd�ZdS)z8WriteTest.test_open_nonwritable_fileobj.<locals>.BadFileTcs|jrd|_��dS�NF)�first�rr
��exctyperrr��s�z>WriteTest.test_open_nonwritable_fileobj.<locals>.BadFile.writeN)rrrrr�rrrr�BadFile�srZnonr;)r�r�r�)
r�EOFError�RuntimeErrorrr�r�rrr�rr�r�r?)rrrr5rrr�test_open_nonwritable_fileobj�s���z'WriteTest.test_open_nonwritable_fileobjr)rrrrr�r�r�r�r�r�r�r�r�rOr�rrJrrrrrrrrr rrrrr��s.�



(
r�c@r�)�
GzipWriteTestNr�rrrrr!�r�r!c@r�)�Bz2WriteTestNr�rrrrr"�r�r"c@r�)�
LzmaWriteTestNr�rrrrr#r�r#c@s@eZdZdZdZdd�Ze�ej	dkoe
ed�d�dd	��ZdS)
�StreamWriteTestzw|NcCs�t�t|j�}|��|jr8|��}ttd��}|��}Wd�n1s&wY|�|�}|�|j	d�n|�t��}|��}Wd�n1sLwY|�
|�d�tjd�dS)Nr[zfound trailing datar�zincorrect zero padding)
rrr�rr7�decompressorr?�
decompressr�Zunused_datar@�countr�)rr5ZdecrFr
rrr�test_stream_padding
s
�

��z#StreamWriteTest.test_stream_paddingr%�umaskzMissing umask implementationc	Csrtj�t�rt�t�t�d�}z"t�t|j	�}|�
�t�t�jd@}|�
|dd�Wt�|�dSt�|�w)N�r&i�zwrong file permissions)rOrP�existsr�rrr)rrrr7r,r-r@)rZoriginal_umaskr5rrrr�test_file_modes

zStreamWriteTest.test_file_mode)
rrrrr%r(r�r�r�r+r�rOr,rrrrr$s�r$c@rP)�GzipStreamWriteTestcCs(t�t|j���t�t�jdd�}dS)zf
        Ensure the source directory is not included in the tar header
        per bpo-41316.
        zlatin-1rN)rrr�rr7r�r��	read_text)rZpayloadrrr� test_source_directory_not_leaked-sz4GzipStreamWriteTest.test_source_directory_not_leakedN)rrrr/rrrrr-,rVr-c@�eZdZerejZdSdZdS)�Bz2StreamWriteTestN)rrrr(ZBZ2Decompressorr%rrrrr17�r1c@r0)�LzmaStreamWriteTestN)rrrr-ZLZMADecompressorr%rrrrr3:r2r3c@speZdZdd�Zddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�GNUWriteTestcCst|�dd}|dS)Nrar\)rA)rrfZblocksrrr�_lengthBszGNUWriteTest._lengthNcCsXd}t|�tjkr|d7}||�|�7}|dur*t|�tjkr*|d7}||�|�7}|S)Nra)rAr�LENGTH_NAMEr5�LENGTH_LINK)rrqrr'rrr�
_calc_sizeFszGNUWriteTest._calc_sizecCs�t�|�}|r||_tj|_t�td�}ztj|_|�	|�|�
||�}|j}|�||d�W|�
�n|�
�wt�t�}z#|��}|�|d�|�|j|jd�|�|j|jd�W|�
�dS|�
�w)Nr�z%GNU longname/longlink creation failedzunable to read longname member)rr�r��LNKTYPErrr�r�r�r�r8rr@r7r�r`rq)rrqrrEr5rcrd�memberrrr�_testTs2


���zGNUWriteTest._testcCrR)N�longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam�r;rrrr�test_longname_1023qr9zGNUWriteTest.test_longname_1023cCrR)N�longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnamer=rrrr�test_longname_1024tr9zGNUWriteTest.test_longname_1024cCrR)N�longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longname_r=rrrr�test_longname_1025wr9zGNUWriteTest.test_longname_1025cCrv)Nrq�longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnkr=rrrr�test_longlink_1023zrzzGNUWriteTest.test_longlink_1023cCrv)Nrq�longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlinkr=rrrr�test_longlink_1024}rzzGNUWriteTest.test_longlink_1024cCrv)Nrq�longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink_r=rrrr�test_longlink_1025�rzzGNUWriteTest.test_longlink_1025cCrv)Nr<rCr=rrrr�test_longnamelink_1023�r~z#GNUWriteTest.test_longnamelink_1023cCrv)Nr?rEr=rrrr�test_longnamelink_1024�r~z#GNUWriteTest.test_longnamelink_1024cCrv)NrArGr=rrrr�test_longnamelink_1025�r~z#GNUWriteTest.test_longnamelink_1025r	)rrrr5r8r;r>r@rBrDrFrHrIrJrKrrrrr4>s

r4c@seZdZdZdd�ZdS)�DeviceHeaderTestr�c	Cs�tj�td�}t�|�z�t�t|j�}z$tj	dd�}tj	dd�}tj
|_tj|_|�
|�|�
|�W|��n|��wt�td�}z|�d�}|�d�}W|��n|��w|�|jd�|�|jd�|�|jd�|�|jd�ttd��}|��}Wd�n1s�wY||j|j�}	||j|j�}
tdd	�}|�|	|d
�|�|
|d�Wt�|�dSt�|�w)NZdevice_header_testZmy_block_device�rqZmy_regular_filerJrr[iIiYs00000000000000s)rOrPrQrNr�rrr�rr��BLKTYPEr�REGTYPEr�r7r=r@r�r�r?rZoffset_data�slicerr/)rrr5Z	input_blkZ	input_regZ
output_blkZ
output_regZinfiler\Zbuf_blkZbuf_regZdevice_headersrrr�*test_headers_written_only_for_device_files�s<



�
z;DeviceHeaderTest.test_headers_written_only_for_device_filesN)rrrrrQrrrrrL�srLc@sneZdZdZej�ed�Zdd�Z	e
dd��Ze
dd��Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�ZdS)�
CreateTestzx:�
spameggs42cCst�t�dSr	)rrr�rrrrr6�r9zCreateTest.setUpcCs<t|jd��}|�d�Wd�dS1swYdS)Nr�r�)r�	file_pathr�)�clsrFrrr�
setUpClass�s"�zCreateTest.setUpClasscC�t�|j�dSr	)rrrT�rUrrr�
tearDownClass��zCreateTest.tearDownClasscCs�t�t|j��}|�|j�Wd�n1swY|�t��}|��}Wd�n1s1wY|�t	|�d�|�
d|d�dS�Nr\rSr)rrr�rr�rTr r�r@rAr��r�tobj�namesrrr�test_create�s�
�zCreateTest.test_createcCs�t�t|j��}|�|j�Wd�n1swY|�t��t�t|j�}Wd�n1s4wY|�t��}|�	�}Wd�n1sMwY|�
t|�d�|�d|d�dSr[)
rrr�rr�rTr��FileExistsErrorr r�r@rAr�r\rrr�test_create_existing�s��
�zCreateTest.test_create_existingcCs�|�td��}|�|j�Wd�n1swY|�t��}|��}Wd�n1s0wY|�t|�d�|�d|d�dS�N�xr\rSr)r r�r�rTr�r@rAr�r\rrr�test_create_taropen�s�
�zCreateTest.test_create_taropenc	Cs�|�td��}|�|j�Wd�n1swY|�t��|�td��Wd�n1s3wYWd�n1sBwY|�t��}|��}Wd�n1s[wY|�t|�d�|�	d|d�dSrb)
r r�r�rTr�r`r�r@rAr�r\rrr�test_create_existing_taropen�s����
�z'CreateTest.test_create_existing_taropencCs�t�t�t�|j��'}|�|jt�|�	|jt
j�t��|�
t�|j��|��}Wd�n1s4wY|�	t|�d�|�d|d�|�t��}|��}Wd�n1s]wY|�	t|�d�|�d|d�dSr[)rrr�r�r�rr�rqr�r@rOrPr�r�rTr�rAr�r r\rrr�test_create_pathlike_name�s
�
�z$CreateTest.test_create_pathlike_namecCs�|�t�t�d��'}|�|jt�|�|jtj	�
t��|�t�|j��|�
�}Wd�n1s3wY|�t|�d�|�d|d�|�t��}|�
�}Wd�n1s\wY|�t|�d�|�d|d�dSrb)r r�r�r�r�rqr�r@rOrPr�r�rTr�rAr�r\rrr�!test_create_taropen_pathlike_name	s
�
�z,CreateTest.test_create_taropen_pathlike_nameN)rrrrrOrPrQrNrTr6�classmethodrVrYr_rardrerfrgrrrrrR�s

		
rRc@rP)�GzipCreateTestcC�ttjt|jdd��}|�|j�Wd�n1swYtjtddd��	}Wd�dS1s3wYdS)Nr\rvzr:gz�rrr�rr�rT�rr]rrr�test_create_with_compresslevel��"�z-GzipCreateTest.test_create_with_compresslevelN�rrrrmrrrrri�ric@rP)�
Bz2CreateTestcCrj)Nr\rv�r:bz2rkrlrrrrm#rnz,Bz2CreateTest.test_create_with_compresslevelNrorrrrrq!rprqc@rP)�LzmaCreateTestcCsDtjt|jdd��}|�|j�Wd�dS1swYdS)Nr\)Zpresetrkrlrrr�test_create_with_preset.s"�z&LzmaCreateTest.test_create_with_presetN)rrrrtrrrrrs*srsc@seZdZdZdZdZdS)�CreateWithXModeTestrcN)rrrrrdrerrrrru3srurrc@ri)�HardlinkTestc
Cs�tj�td�|_tj�td�|_t|jd��
}|�d�Wd�n1s&wYz
t�|j|j�Wnt	yN}z
|�
d|�WYd}~nd}~wwt�td�|_
|j
�|j�dS)Nr�r�r��foor�r�)rOrPrQrNr�r�rr�rr�rTrr�r5r�)rrFrkrrrr6?s���zHardlinkTest.setUpcCs&|j��t�|j�t�|j�dSr	)r5r7rrr�r�rrrrr8Ns
zHardlinkTest.tearDowncC�$|j�|j�}|�|jtjd�dS)Nzadd file as regular failed)r5r�r�r@rrrOr
rrr�test_add_twiceSs�zHardlinkTest.test_add_twicecCrx)Nzadd file as hardlink failed)r5r�r�r@rrr9r
rrr�test_add_hardlinkZs�zHardlinkTest.test_add_hardlinkcCs,d|j_|j�|j�}|�|jtjd�dS)NTzdereferencing hardlink failed)r5Zdereferencer�r�r@rrrOr
rrr�test_dereference_hardlink_s
�z&HardlinkTest.test_dereference_hardlinkN)rrrr6r8ryrzr{rrrrrv;srvc@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)�PaxWriteTestNcCs�t�|�}|r||_tj|_tjtdtjd�}z|�|�W|�	�n|�	�wt�t�}z-|r?|�
�dj}|�||d�n|�
�dj}|�||d�W|�	�dSW|�	�dS|�	�w)Nr��r�rzPAX longlink creation failedzPAX longname creation failed)
rr�r�r9rrr�r�r�r7r�r@rq)rrqrrEr5�l�nrrrr;hs$

�zPaxWriteTest._testc
Cs
dddddd�}tjtdtj|d�}z|�t�d��W|��n|��wtjtd	d
�}zR|�|j|�|�|�	�dj|�|j�
�D]3\}}|�t|�t
�|�t|�t
�|tjvrxz	tj||�WqEttfyw|�d�YqEwqEW|��dS|��w)
Nr��0z1.23�äöü�test)r�r�rr�r�r�)r�r�r1rrz"unable to convert pax header field)rrr�r�r�r�r7r@r�r�r}ZassertIsNotrr��PAX_NUMBER_FIELDSrrrn)rr�r5�key�valrrr�test_pax_global_header�s8��
���	z#PaxWriteTest.test_pax_global_headercCs�ddd�}tjtdtjdd�}zt��}d|_d|_||_|�|�W|�	�n|�	�wtjtdd	�}z"|�
�d
}|�|j|�|�|jd�|�|jd�W|�	�dS|�	�w)Nr�Z123)rPr�r�r1r�r��rrr�)rrr�r�r�rqr�r�r�r7r�r@)rr�r5r�rrr�test_pax_extended_header�s$
�z%PaxWriteTest.test_pax_extended_headercCs�t��}d|_d|_d|_d|_d|_|��}|j|dd�}|�	|dd�|�
|d	t�|�	|d	d
�|�	|dd�|�	|dd�|�	|d
d�|�	|dtd�dtd�dtd�dtd�dtd�dtd�dtd��t��}d|_d|_d|_d|_d|_|��}|j|dd�}|�	|dd�|�	|d	d�|�	|dd�|�	|dd�|�	|d
d�|�	|dtd�dtd�dtd�ddd td!�d"td#�d$td�dtd��dS)%Nr�g�����@�@rkr��|r1rrqrr{rBr�r�s././@PaxHeader�Vs90000000000000000000000000000002000000000000010205 xsustar00�s16 mtime=1000.1
i�rw�as90000644000017300001740000000014400000001750006516 0ufoo㍴ld(	r�irs90000000000000000000000000000013000000000000010207 xs15 path=foo㍴
16 uid=16777216
s$16 gid=16777217
20 size=10000000000
s21 mtime=10000000000
i�sfoo?�`s90000644000000000000000000000000000000000000006540 0)
rr�rqrrBr�r�rBZcreate_pax_headerr@r�r�r�)rr��infor�rrr�test_create_pax_header�s�
�������������	
���������������z#PaxWriteTest.test_create_pax_headerr	)rrrr;r�r�r�rrrrr|fs

 r|c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�UnicodeTestcCrR)Nr1��_test_unicode_filenamerrrr�test_iso8859_1_filename�r9z#UnicodeTest.test_iso8859_1_filenamecCrR)N�utf7r�rrrr�test_utf7_filename�r9zUnicodeTest.test_utf7_filenamecCrR)N�utf-8r�rrrr�test_utf8_filename�r9zUnicodeTest.test_utf8_filenamecCs�tjtd|j|dd�}zd}|�t�|��W|��n|��wtjt|d�}z|�|��dj	|�W|��dS|��w)Nr�r��r�r3�errorsr�rr)
rrr�r�r�r�r7r@r�rq)rr3r5rqrrrr��s�z"UnicodeTest._test_unicode_filenamecCsjtjtd|jddd�}z$t��}d|_|�t|j|�d|_d|_	|�t|j|�W|�
�dS|�
�w)Nr�r�r�r�r�r�)rrr�r�r�rqr��UnicodeErrorr�rr7r�rrr�test_unicode_filename_errors�z'UnicodeTest.test_unicode_filename_errorcCs~tjtdddd�}z0|D]&}|�t|j�t�|�t|j�t�|�t|j�t�|�t|j	�t�qW|�
�dS|�
�w)NrJr1r��r3r�)rrr�assertIsrrqr�r�rr|r7rrrr�test_unicode_arguments��z!UnicodeTest.test_unicode_argumentcCs�t�d�}d|_d|_tjtd|jdd�}z|�|�W|��n|��wtjtdd�}zE|�	d�}|�
|jd�|�
|jd�|jtjkrl|��tjtdd�}|�	d�}|�
|jd�|�
|jd�W|��dSW|��dS|��w)	Nr�r�r�r1)rr�r3rr�u	���)rr�rr|rr�r�r�r7r=r@r�)rr�r5rrr�test_uname_unicode&s.
�

�zUnicodeTest.test_uname_unicodeN)
rrrr�r�r�r�r�r�r�rrrrr��sr�c@sfeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zddd�Zdd�Z
dd�Zddd�Zd
S)�UstarUnicodeTestcC�0|�d�|�dt�|�d�|�dt�dS�Nr��e01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890ud01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿue012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿ��_test_ustar_namerrrrr�test_unicode_name1I�

z#UstarUnicodeTest.test_unicode_name1cC�|�d�|�dt�dS�Nud012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿue0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr�rrrr�test_unicode_name2O�
z#UstarUnicodeTest.test_unicode_name2cCr�)Na01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123/40123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r�rrrr�test_unicode_longname1Ur�z'UstarUnicodeTest.test_unicode_longname1cCs|�dt�|�dt�dS)Nu01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r�rrrr�test_unicode_longname2[sz'UstarUnicodeTest.test_unicode_longname2cCs&|�dt�|�d�|�dt�dS)Nu01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿu01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿr�rrrr�test_unicode_longname3_s
z'UstarUnicodeTest.test_unicode_longname3cCr�)Nu01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿu01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr�rrrr�test_unicode_longname4dr�z'UstarUnicodeTest.test_unicode_longname4NcCs�tjtd|jdd��}t�|�}|dur|�|�n|�||j|�Wd�n1s,wY|durdtjtddd��}|D]}|�||j�Wd�dSWd�dS1s]wYdSdS)Nr�r�r�rJr)	rrr�r�r�r�r�r@rq�rrq�excr5r�rrrr�hs 
���"��z!UstarUnicodeTest._test_ustar_namecCr�r���_test_ustar_linkrrrrr�test_unicode_link1wr�z#UstarUnicodeTest.test_unicode_link1cCr�r�r�rrrr�test_unicode_link2}r�z#UstarUnicodeTest.test_unicode_link2cCs�tjtd|jdd��"}t�d�}||_|dur|�|�n|�||j|�Wd�n1s/wY|durgtjtddd��}|D]}|�||j�Wd�dSWd�dS1s`wYdSdS)Nr�r�r�r�rJr)	rrr�r�r�r�r�r�r@r�rrrr��s"
���"��z!UstarUnicodeTest._test_ustar_linkr	)rrrrr�r�r�r�r�r�r�r�r�r�r�r�rrrrr�Bs
r�c@seZdZejZdd�ZdS)�GNUUnicodeTestc
C�ndD]2\}}tjt|dd��}z|�|�}Wnty$|�d�YnwWd�n1s/wYqdS)N))r�upax/bad-pax-���)r1upax/bad-pax-äöür�r�z%unable to read bad GNU tar pax header�rrrr=rrn�rr3rqr5r�rrr�test_bad_pax_header�s������z"GNUUnicodeTest.test_bad_pax_headerN)rrrrr�r�r�rrrrr��sr�c@seZdZejZdZdd�ZdS)�PAXUnicodeTestNc
Cr�)N))r�upax/hdrcharset-���)r1upax/hdrcharset-äöür�r�z)unable to read POSIX.1-2008 binary headerr�r�rrr�test_binary_header�s������z!PAXUnicodeTest.test_binary_header)rrrrr�r�r�r�rrrrr��sr�c@s&eZdZdd�Zd	dd�Zdd�ZdS)
�AppendTestBasecCs(t|_tj�|j�rt�|j�dSdSr	)r�rrOrPr+rrrrrrr6�s�zAppendTestBase.setUpr�c
Cs�tjtdd��K}|�d�}d|_|�|��%}t�|j|��}|�||�Wd�n1s.wYWd�n1s=wYWd�dSWd�dS1sUwYdS)Nr1rr;r�)rrrr=rqr>r�)rr�srcr�rr5rrr�_create_testtar�s
����"�zAppendTestBase._create_testtarcCs(|�d|j�|�tjtjtd�dS)Nr�rs)r�rr�rr�rr�rrrr�test_append_compressed�sz%AppendTestBase.test_append_compressedN)r�)rrrr6r�r�rrrrr��s
r�c@s�eZdZdZddd�Zdgdfdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�
AppendTestNcCsHtj|jd|d��}|�t�d��Wd�dS1swYdS)Nrsrmr�)rrrr�r�)rr�r5rrr�
_add_testfile�s"�zAppendTest._add_testfiler�cCsFtj|j|d��}|�|��|�Wd�dS1swYdS)Nrm)rrrr@r�)rr^r�r5rrrr;�s"�zAppendTest._testcCs|��|��dSr	)r�r;rrrr�test_non_existing�szAppendTest.test_non_existingcCs&t�|jd���|��|��dS)Nr�)rrrr7r�r;rrrr�
test_empty�szAppendTest.test_emptycCs.t�d�}|�|�|�d�|j|d�dS)Nsrrm)rr�r�rbr;r�rrr�test_empty_fileobj�s


zAppendTest.test_empty_fileobjcCsp|��t|jd��}|��}Wd�n1swYt�|�}|�|�|�d�|jddg|d�dS)Nr[rr�r�)r^r�)	r�rrr?rr�r�rbr;rorrr�test_fileobj�s
�


zAppendTest.test_fileobjcCs$|��|��|jddgd�dS)Nr�r�)r^)r�r�r;rrrr�
test_existing�szAppendTest.test_existingcCsJt|jd��
}|�|�Wd�n1swY|�tj|j�dSr�)rrr�r�rr�r�)rr
rFrrr�_test_error�s�zAppendTest._test_errorcCrR)Nr`�r�rrrr�	test_null�r9zAppendTest.test_nullcCrR)N�
r�rrrr�test_incomplete�r9zAppendTest.test_incompletecCst�d���}|�|�dS)Nr��rr�r�r�rrrr�test_premature_eof	szAppendTest.test_premature_eofcCs t�d���}|�|d�dS)Nr�r�r�rrrr�test_trailing_garbage	sz AppendTest.test_trailing_garbagecCrR)Nsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar�rrrr�test_invalid	r9zAppendTest.test_invalidr	)rrrr�r�r;r�r�r�r�r�r�r�r�r�r�r�rrrrr��s
	r�c@r�)�GzipAppendTestNr�rrrrr�	r�r�c@r�)�
Bz2AppendTestNr�rrrrr�	r�r�c@r�)�LzmaAppendTestNr�rrrrr�	r�r�c@�$eZdZdd�Zdd�Zdd�ZdS)�
LimitsTestcCs�t�d�}|�tj�t�d�}|�t|jtj�t�d�}|�tj�t�d�}|�t|jtj�t�d�}|�t|jtj�t�d�}d|_|�t|jtj�t�d�}d|_|�t|jtj�dS)	Nr�r�a123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamea1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/longname�123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamer�rq� )rr�r�r�r�rr�r�r
rrr�test_ustar_limits	s 






zLimitsTest.test_ustar_limitscCsXt�d�}|�tj�t�d�}d|_|�tj�t�d�}d|_|�t|jtj�dS�Nr�r�rql)rr�r�r�r�r�r�rr
rrr�test_gnu_limits6	s


zLimitsTest.test_gnu_limitscCsRt�d�}|�tj�t�d�}d|_|�tj�t�d�}d|_|�tj�dSr�)rr�r�r�r�r�r
rrr�test_pax_limitsC	s


zLimitsTest.test_pax_limitsN)rrrr�r�r�rrrrr�	s
r�c@sreZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�
e��d
�e	�
e
ed�d�e	j�d�dd����ZdS)�MiscTestcCs`|�t�dddd�d�|�t�dddd�d�|�t�ddd�d�|�t�d	dd�d�dS)
Nr��r�r�sfooZfoobarr�rwsfoobar)r@r�stn�ntsrrrr�test_char_fieldsR	s����zMiscTest.test_char_fieldscCs�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d�d�|�t�d	�d
�|�t�d�d�|�t�d
�d�|�t�d�d�|�t�d�d�dS)N�0000001r\�7777777��� r�������������������r�����������������r�rs       )r@r�ntirrrr�test_read_number_fields\	s&�����z MiscTest.test_read_number_fieldscCs�|�t�d�d�|�t�d�d�|�tjdtjd�d�|�tjdtjd�d	�|�tjd
tjd�d�|�tjdtjd�d
�|�tjdtjd�d�|�tjdtjd�d
�|�tjdtjd�d�|�t�tjdtjd��d�dS)Nr\r�r�r�r�r}r�r�r�rr�r�r�r�r�gY�g0Bs�g��������r)r@r�itnr�r�rrrr�test_write_number_fieldsp	s4����
����"z!MiscTest.test_write_number_fieldscCs�|�t��t�ddtj�Wd�n1swY|�t��t�ddtj�Wd�n1s5wY|�t��t�ddtj�Wd�n1sRwY|�t��t�ddtj�Wd�dS1spwYdS)Nrr�r�l�����l)r�rrr�r�r�rrrr�test_number_field_limits�	s���"�z!MiscTest.test_number_field_limitscCshd�}tj|t|d�dS)N>9r�r7ZCONTTYPE�grp�data_filterZSOLARIS_XHDTYPE�mainr6ZGNUTYPE_SPARSEZEmptyHeaderErrorZSubsequentHeaderErrorr9rOr�Zcalc_chksums�LinkOutsideDestinationErrorZsymlink_exceptionr��SpecialFileError�
LENGTH_PREFIXZEOFHeaderErrorZExFileObject�AbsolutePathErrorZPAX_NAME_FIELDSr��OutsideDestinationError�LinkFallbackErrorZInvalidHeaderError�CHRTYPEr	rNZXGLTYPE�filemoder��NUL�FilterError�version�	GNU_MAGICr��pwdZSUPPORTED_TYPESZAREGTYPE�FIFOTYPEZ
REGULAR_TYPESZ
PAX_FIELDSr�Zcopyfileobj�SYMTYPEZ	GNU_TYPES�fully_trusted_filterZTruncatedHeaderErrorr��
tar_filterZGNUTYPE_LONGLINK�POSIX_MAGICr��AbsoluteLinkError)�not_exported)rZcheck__all__r)rrrrr�test__all__�	szMiscTest.test__all__c	Cs�tj�tj�t�d�}|�tj��.}t�d�f}t	j
jjtj
d|d��
t�|�Wd�n1s3wYWd�n1sBwY|�dt|j��dS)Nrzlzma module is not availabler.)rHz?
- method xz: CompressionError('lzma module is not available')
)rOrPrQ�dirname�__file__r�rr�ZCompressionErrorr�rDrEr<rrr�r��	exception)r�fname�excinforGrrr�.test_useful_error_message_when_modules_missing�	s����z7MiscTest.test_useful_error_message_when_modules_missingzrequires symlink support�chmodzmissing os.chmod�os.chmodc	s�tj�td���fdd�}||_tj�td�}t��}|jddd�|jdtjdd	�|jd|d�Wd�n1s<wYt�	|�z|�
�j�d
d�Wt�
|�t�
��dSt�
|�t�
��w)NZ
test127987cs.tj�|�}tj�|�g��krtd|��dS)Nz8should not try to chmod anything outside the destination)rOrP�realpath�
commonpath�	Exception)rPrrZtarget_path�rrr�mock_chmod_side_effect�	s
�zRMiscTest.test_deferred_directory_attributes_update.<locals>.mock_chmod_side_effect�outside_tree_dirrcr��
symlink_to�
?rwsrwsrwt�rrr5r5)rOrPrQrNrH�ArchiveMakerr�rr	�makedirsrrrr/)r�
mock_chmodrr�arcrrr�)test_deferred_directory_attributes_update�	s �


�z2MiscTest.test_deferred_directory_attributes_updateN)rrrr�r�r�r�r	rr�r�r�can_symlinkr�rOrDrEr rrrrr�P	s


r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+S),�CommandLineTestcOs2tjddg|�Ri|��\}}}|�tj��d�S)N�-mr�
)rZassert_python_okr�rO�lineseprl)r�argsr�rcr��errrrr�
tarfilecmd�	s�zCommandLineTest.tarfilecmdcGstjddg|�R�S)Nr#r)rZassert_python_failure�rr&rrr�tarfilecmd_failure�	sz"CommandLineTest.tarfilecmd_failurecCstt�d�t�d�g}|�tj|�t�|d��}|D]
}|j|tj	�
|�d�qWd�dS1s3wYdS)N�tokenize_tests.txt�9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr�r	)rr�rrrrrr�rOrPr)r�tar_name�files�tfZtardatarrr�make_simple_tarfile�	s��"�z#CommandLineTest.make_simple_tarfilecCs�t�d�g}|�tj|�t�|d��'}t�d�}|j|t	�
d�d�t�d�}|j|t	�
d�d�Wd�dS1s=wYdS)Nr,r��benignr`rm�../evil)rr�rrrrrr�r�rr�)rr.r/r0r2Zevilrrr�make_evil_tarfile�	s

"�z!CommandLineTest.make_evil_tarfilecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr`susageserrorsrequired�-lr)r+r@r��lowerr��strip)rr'r�r(rrr�test_bad_use�	szCommandLineTest.test_bad_usecCs0tD]}dD]}|�||�}|�|d�qqdS)N)�-tz--testr`)�testtarnamesr)r@�rr.�optr�rrr�test_test_command�	s��z!CommandLineTest.test_test_commandcCs6tD]}dD]}|j|d|dd�}|�d|�qqdS)N��-vz	--verboser9r���PYTHONIOENCODINGsis a tar archive.
)r:r)r�r;rrr�test_test_command_verbose�	s
���z)CommandLineTest.test_test_command_verbosecCs.t�d�}|�d|�\}}}|�d|�|�|d�|�|d�tD]r}|j|d��bt|d��}|��}Wd�n1s?wYz:tt	d��}|�
|dd	��Wd�n1s^wY|�dt	�\}}}|�|d�|�|d�Wt�t	�nt�t	�wWd�n1s�wYq"dS)
N�
zipdir.zipr9� is not a tar archive.r`r\)r.r[r�r&)
rr�r+r�r@r:r�rr?r�r�rr)r�zipnamer'r�r(r.rr
rrr�test_test_command_invalid_file�	s*

�����z.CommandLineTest.test_test_command_invalid_filec
Cs�tD]M}t���$}t�|d��}|jdd�Wd�n1s wYWd�n1s/wY|���dd�}dD]}|j||dd�}|�	||�q>qdS)NrJFr�r�r�)r5z--listr@�
r:rZcaptured_stdoutrrrYr�rlr)r@�rr.r�r0�expectedr<r�rrr�test_list_command
s
������z!CommandLineTest.test_list_commandc
Cs�tD]N}t���$}t�|d��}|jdd�Wd�n1s wYWd�n1s/wY|���dd�}dD]}|j|d|dd�}|�	||�q>qdS)	NrJTr�r�r�r>r5r@rGrHrrr�test_list_command_verbose
s
���
���z)CommandLineTest.test_list_command_verbosecCsDt�d�}|�d|�\}}}|�d|�|�|d�|�|d�dS)NrCr5rDr`r\)rr�r+r�r@�rrEr'r�r(rrr�test_list_command_invalid_file(
s

z.CommandLineTest.test_list_command_invalid_filec
Cs�t�d�t�d�g}dD]8}z0|j|tg|�R�}|�|d�t�t��}|��Wd�n1s3wYWt�	t�qt�	t�wdS)Nr,r-)�-cz--creater`)
rr�r)r�r@rrr�rr�rr/r<r�r5rrr�test_create_command/
s�
���z#CommandLineTest.test_create_commandc
Cs�t�d�t�d�g}dD]<}z4|j|dtg|�Rddi�}|�d|�t�t��}|��Wd�n1s7wYWt�	t�qt�	t�wdS)Nr,r-r>rNrAr�s file created.)
rr�r)r�r�rrr�rrrOrrr�test_create_command_verbose<
s��
���z+CommandLineTest.test_create_command_verbosec	Cs�t�d�g}z9|jdtg|�R�}|�|d�t�t��}|��Wd�n1s+wYWt�	t�dSWt�	t�dSt�	t�w)Nr,rNr`)
rr�r)�dotlessnamer@rrr�rr)rr/r�r5rrr�$test_create_command_dotless_filenameJ
s
��z4CommandLineTest.test_create_command_dotless_filenamec	Cs�tj�td�}t�d�g}z9|jd|g|�R�}|�|d�t�	|��}|�
�Wd�n1s2wYWt�|�dSWt�|�dSt�|�w)Nz.testtarr,rNr`)
rOrPrQrNrr�r)r@rrr�rr)rr.r/r�r5rrr�(test_create_command_dot_started_filenameT
s
��z8CommandLineTest.test_create_command_dot_started_filenamec
Cs�t�d�t�d�g}tttfD]=}|jsqz1td|j}|jd|g|�R�}|�	|��}|�
�Wd�n1s;wYWt�|�qt�|�wdS)Nr,r-rrN)
rr�r#r'r+rr�rr)r r�rr)rr/Zfiletyper.r�r5rrr�test_create_command_compressed_
s�
���z.CommandLineTest.test_create_command_compressedc
Cst|�t�dD]0}z(t�t��|�|t�}Wd�n1s wY|�|d�Wt�t�qt�t�wdS)N)�-ez	--extractr`�r1r�rr��	tarextdirr)r@r/�rr<r�rrr�test_extract_commandn
s
��z$CommandLineTest.test_extract_commandc
Csz|�t�dD]3}z+t�t��|j|dtdd�}Wd�n1s#wY|�d|�Wt�t�qt�t�wdS)Nr>rVr�r@� file is extracted.)r1r�rr�rXr)r�r/rYrrr�test_extract_command_verbosex
s

���z,CommandLineTest.test_extract_command_verbosec	Cs�|�t�tj�td�}t�t�z?t�|��"|�	dtddd�|j
dtddddd�}|�d	|�Wd�n1s<wYWt�t�dSWt�t�dSt�t�w)
N�destrVr?z--filterr
r$r�r@r[)
r4r�rOrPrQrXr�rr�r+r)r�r/)r�destdirr�rrr�test_extract_command_filter�
s&

���
�
z+CommandLineTest.test_extract_command_filterc	Csl|�t�z*t�t��|�dtd�}Wd�n1swY|�|d�Wt�t�dSt�t�w)NrVZspamdirr`rW)rr�rrr�(test_extract_command_different_directory�
s
�z8CommandLineTest.test_extract_command_different_directorycCsnt�d�}t�t��|�d|�\}}}Wd�n1swY|�d|�|�|d�|�|d�dS)NrCrVrDr`r\)rr�rr�rXr+r�r@rLrrr�!test_extract_command_invalid_file�
s
�z1CommandLineTest.test_extract_command_invalid_fileN)rrrr)r+r1r4r8r=rBrFrJrKrMrPrQrSrTrUrZr\r_r`rarrrrr"�	s,		



	r"c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ContextManagerTestcCsJt�t��}|�|jd�Wd�n1swY|�|jd�dS)Nzclosed inside runtime context�context manager failed)rrrr�r?r�r�rrr�
test_basic�
s�zContextManagerTest.test_basicc	Csvt�t�}|��|�t��#|�Wd�n1swYWd�dSWd�dS1s4wYdSr	)rrrr7r�rr�rrr�test_closed�
s
��"�zContextManagerTest.test_closedc	Csl|�t��}t�t��}t�1swYWd�n1s wY|�|jtd�|�|j	d�dS)Nz)wrong exception raised in context managerrc)
r�rrrrrr�rr�r?)rr�r5rrr�test_exception�
s��
�z!ContextManagerTest.test_exceptioncCsXzt�td��}t�1s
wYWnY|�tj�t�dd�|�|j	d�dS)Nr�rz-context manager wrote an end-of-archive blockrc)
rrr�rr@rOrPr�r�r?r�rrr�test_no_eof�
s��zContextManagerTest.test_no_eofcCsFt�td��Wd�n1swY|�tj�t�dd�dS)Nr�rz-context manager wrote no end-of-archive block)rrr�r�rOrPr�rrrr�test_eof�
s��zContextManagerTest.test_eofc	Cs~ttd��0}ztj|dd��}t�1swYWnY|�|jd�|�|jd�Wd�dS1s8wYdS)Nr�r�r�zexternal file object was closedrc)rr�rrr�r?r�r�rrrr��
s�"�zContextManagerTest.test_fileobjN)	rrrrdrerfrgrhr�rrrrrb�
s		rbzrequires os.link to be missingc@s�eZdZdd�Ze�eejd�d�dd��Z	e�eejd�d�dd��Z
e�eed	�d
�dd��Ze�eed	�d
�d
d��ZdS)�LinkEmulationTestcCsb|jj|tdd�ttj�t|�d��}|��}Wd�n1s"wY|�t	|�t
�dS)Nr$rHr[)r5rMrNrrOrPrQr?r@r
rC)rrqrr
rrr�_test_link_extraction�
s

�z'LinkEmulationTest._test_link_extraction�islinkz3Skip emulation - has os.path.islink but not os.linkcCrR)Nrw�rjrrrr�test_hardlink_extraction1�
�z+LinkEmulationTest.test_hardlink_extraction1cCrR)Nr{rlrrrr�test_hardlink_extraction2�
rnz+LinkEmulationTest.test_hardlink_extraction2r�z Skip emulation if symlink existscCrR)Nrrlrrrr�test_symlink_extraction1�
rnz*LinkEmulationTest.test_symlink_extraction1cCrR)Nr�rlrrrr�test_symlink_extraction2�
rnz*LinkEmulationTest.test_symlink_extraction2N)
rrrrjr�rKr�rOrPrmrorprqrrrrri�
s$�
�
�
�ric@r�)�Bz2PartialReadTestc	svG�fdd�dtj��t�t�d����}tt|�d�D]}ztj	�|d|��|d�Wqtj
y8YqwdS)Ncs0eZdZdZ��fdd�Z��fdd�Z�ZS)z9Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIOFcs4|jrtd��|��t|���k|_t�|��|�S)Nz(infinite loop detected in tarfile.open())�hit_eof�AssertionErrorrcrAr��superr?)rr��	MyBytesIO�	__class__rrr?sz>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.readcsd|_t�|�j|�Sr)rsrurbr*rvrrrbsz>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek)rrrrsr?rb�
__classcell__r�rw)rxrrw	srwr�r\r�)rr�r(�compressrr�r��rangerArr�)rrr
rcrrzr�_test_partial_inputs��z&Bz2PartialReadTest._test_partial_inputcCrR)NrJ�r}rrrr�test_partial_inputr9z%Bz2PartialReadTest.test_partial_inputcCrR)Nrrr~rrrr�test_partial_input_bz2r9z)Bz2PartialReadTest.test_partial_input_bz2N)rrrr}rr�rrrrrrsrrcCsZz
ddl}ddl}Wn
tyYdSw|�d�ddkr dS|�d�ddkr+dSdS)NrF�rootT)rr��ImportError�getpwuidZgetgrgid)rr�rrr�root_is_uid_gid_0#s�r��chownzmissing os.chown�geteuidzmissing os.geteuidc@s�eZdZedd��Zeedd���Zej�	d�ej�	d�ej�	d�dd	����Z
ej�	d�ej�	d�ej�	d�d
d����Ze�e
�d�ej�	d�ej�	d�ej�	d�d
d�����Zej�	d�dd��ZdS)�NumericOwnerTestcCs�t�d�}|ddtj|f|ddtjdf|ddtj|fg}t�td��-}|D]!\}}}}	}
t�|�}||_||_	d	|_
d	|_|	|_|�
||
�q%Wd�tS1sRwYtS)
Nscontent�c�b�M�L�X�Wr�r�)rr�rrOr	rr�r�r�r�rr|rr�)�
filename_1�	dirname_1�
filename_2rFr}�tarflrqr�r��typ�contentsr�rrr�_make_test_archive8s&
�
�
��z#NumericOwnerTest._make_test_archiveccsr�d|_d}d}|}|}tj�||�}t�|||�}t�|��}||||fVWd�dS1s2wYdS)Nrznumeric-owner-testfiler)r�rOrPrQr�r�rr)�mock_geteuidr
r
r�r�r�Ztar_filenamer�rrr�_setup_testPs��"�zNumericOwnerTest._setup_testzos.chownrz
os.geteuidc
Cs�|�|��\}}}}|j|tddd�|j|tddd�Wd�n1s&wYtj�t|�}tj�t|�}	|jtj�	|dd�tj�	|	dd�gdd�dS)	NTr$�Z
numeric_ownerrIr�r�r�r��Z	any_order)
r�rMrNrOrPrQ�assert_has_callsr�rD�call)
rr�r�
mock_chownr�r��_r��f_filename_1�f_filename_2rrr�test_extract_with_numeric_ownerfs 
�
���
�z0NumericOwnerTest.test_extract_with_numeric_ownercCs�|�|��\}}}}|jtddd�Wd�n1swYtj�t|�}tj�t|�}	tj�t|�}
|jtj�	|dd�tj�	|	dd�tj�	|
dd	�gdd
�dS)NTr$r�r�r�r�r�r�r�r�)
r�rrNrOrPrQr�r�rDr�)rr�rr�r�r�r�r�r�Zf_dirname_1r�rrr�"test_extractall_with_numeric_owner{s���
�z3NumericOwnerTest.test_extractall_with_numeric_ownerz uid=0,gid=0 must be named "root"cCsd|�|��\}}}}|j|tddd�Wd�n1swYtj�t|�}|�|dd�dS)NFr$r�r)r�rMrNrOrPrQZassert_called_with)rr�rr�r�r�r�r�rrr�"test_extract_without_numeric_owner�s
��z3NumericOwnerTest.test_extract_without_numeric_ownerc	CsN|�|��\}}}}|�t|j|tdd�Wd�dS1s wYdS)NFT)r�r�rrMrN)rr�r�r�r�rrr�test_keyword_only�s
�"�z"NumericOwnerTest.test_keyword_onlyN)rrrr�r�rr�r�rDrEr�r�r�r�r�r�rrrrr�/s.	






�



r�c@ri)�ReplaceTestscCsN|j�d�}|jdd�}|�|jd�|�|jd�|�|j�d�jd�dS)Nr;z
misc/otherrM)r5r=r�r@rq�rr:�replacedrrr�test_replace_name�s�zReplaceTests.test_replace_namecCsN|j�d�}|��}d|jd<|�|jdd�|�|j�d�jdd�dS)Nr��not-barr|r��r5r=r�r�r@r�rrr�test_replace_deep�s
�zReplaceTests.test_replace_deepcCsR|j�d�}|jdd�}d|jd<|�|jdd�|�|j�d�jdd�dS)Nr�F)Zdeepr�r|r�r�rrr�test_replace_shallow�s
�z!ReplaceTests.test_replace_shallowc	Cs~|j�d�}dD]4}|j|d��$|jdi|di��}|�t||�d�|�t||�d�Wd�n1s7wYqdS)Nr;)rqrrr�r�r�rr|��	attr_namer)r5r=r�r�r@r�r�)rr:r�r�rrr�test_replace_all�s���zReplaceTests.test_replace_allcCsH|j�d�}|�t��|jdd�Wd�dS1swYdS)Nr;i�[)r)r5r=r�rr�)rr:rrr�test_replace_internal�s"�z"ReplaceTests.test_replace_internalN)rrrr�r�r�r�r�rrrrr��s	r�c@steZdZdZedd��Zedd��Zdd�Zedd	��Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�NoneInfoExtractTestsNcsjtjtddd�}t�t�d�_d|_|j�j�j	d�|�
�t�fdd�t��j��d	�D���_
dS)
NrJr1r2Zextractall_ctrlrrHc3s�|]	}|��j�VqdSr	)�relative_to�control_dir�r!�prXrr�	<genexpr>�s
�
�
�z2NoneInfoExtractTests.setUpClass.<locals>.<genexpr>�**/*)rrrr�r�rNr�rr�extraction_filterr7�set�glob�
control_paths)rUr5rrXrrV�s�zNoneInfoExtractTests.setUpClasscCrWr	)�shutilr/r�rXrrrrY�rZz"NoneInfoExtractTests.tearDownClasscsXt�fdd�t����d�D��}|jdkr#dD]
}|�t�|��q|�|j|�dS)Nc3s�|]}|���VqdSr	)r�r��r�rrr��s
��
�z;NoneInfoExtractTests.check_files_present.<locals>.<genexpr>r�r
)r�r�r�)r�r�r�r�r��discardr@r�)rr�Z	got_pathsrPrr�r�check_files_present�s�
z(NoneInfoExtractTests.check_files_presentcgs��t�t�d}d|j_|j��D]
}|D]}t||d�qqt�|��|jj	|dd�|�
|�|VWd�dS1s@wYdS)NZextractall_nonerr$rH)r�r�rNr5rr��setattrrr8rr�)r�
attr_namesr0r:r�rrr�extract_with_none�s��
"�z&NoneInfoExtractTests.extract_with_nonecCs�t�t���j}|�d��I}t�|��d�D]7}|j|d��'z|��j}Wnty4|�	�s2�Yn
w|�
|��j|�Wd�n1sHwYqWd�dS1sYwYdS)Nrr��rP)r�r�rNr,�st_mtimer�r�r�r�
is_symlinkZassertGreaterEqual)rZnowr0rPrrrr�test_extractall_none_mtimes"������"�z/NoneInfoExtractTests.test_extractall_none_mtimec
Cs�t�t���j}t�t�d}|�d�|��j}|�d��E}t�|��d�D]3}|j|d��#|�	�r>|�
|��j|�n
|��rK|�
|��j|�Wd�n1sUwYq'Wd�dS1sfwYdS)N�regular_filerrr�r�)r�r�rNr,r-�
write_textr�r�r��is_dirr@�is_file)rZdir_moder�Zregular_file_moder0rPrrr�test_extractall_none_modes$

�����"�z.NoneInfoExtractTests.test_extractall_none_modecC�0|�d��	Wd�dS1swYdS)Nr��r�rrrr�test_extractall_none_uid!�"�z-NoneInfoExtractTests.test_extractall_none_uidcCr�)Nr�r�rrrr�test_extractall_none_gid%r�z-NoneInfoExtractTests.test_extractall_none_gidcCr�)Nrr�rrrr�test_extractall_none_uname)r�z/NoneInfoExtractTests.test_extractall_none_unamecCr�)Nr|r�rrrr�test_extractall_none_gname-r�z/NoneInfoExtractTests.test_extractall_none_gnamecCs6|�dddd��	Wd�dS1swYdS)Nr�r�rr|r�rrrr�test_extractall_none_ownership1s"�z3NoneInfoExtractTests.test_extractall_none_ownership)rrrr�rhrVrYr�rr�r�r�r�r�r�r�r�rrrrr��s 




r�c@�eZdZdZdS)�NoneInfoExtractTests_Datar
N�rrrr�rrrrr�5rNr�c@r�)�!NoneInfoExtractTests_FullyTrustedr$Nr�rrrrr�8�r�c@r�)�NoneInfoExtractTests_Tarr5Nr�rrrrr�<rNr�c@rL)�NoneInfoExtractTests_DefaultNr�rrrrr�?r�r�c@r�)�NoneInfoTests_MisccCst��}tjtjtjfD]~}|j|d��ntj|d|d�}|�t	�}z|�
|�Wnty9|tjkr6n�YnBwdD]>}|j|d��.|jdi|di��}|�
t|���
|�
|�Wd�n1sfwYWd�n1suwYq<Wd�n1s�wYqdS)N)�	tarformatr�)r�rr�)rrr�r�rr|r�r)rr�rr�r�r�r�rr�rr�rr�r�r)r�bior�r5rEr�r�rrr�test_addDs:�

����������zNoneInfoTests_Misc.test_addc
Cs�dhdhdhdhdhdhddhddhfD�]�}|j|d����tjtdd	����}tjt��d
dd�}t�t	d
|��|�
�Wd�n1sHwY|��D]
}|D]}t||d�qUqQtjt��d
dd�}t�t	d
|��|�
�Wd�n1swYt
|������|�������D�]*\}}|dhkr�t�d|�r�|�|d�q�|dhkr�t�d|�r�|�|d�q�|dhkr�t�d|�r�|�|d�q�|dhkr�|�d�r�|�d�\}	}
|�d�\}}|�||
�|�|d�q�|dhk�r|�d��r|�d�\}	}
|�d�\}}|�||	�|�|d�q�|dhk�rC|�d��rC|�d�\}	}
|�d�\}}|�||
�|�|d�q�|dhk�rj|�d��rj|�d�\}	}
|�d�\}}|�||	�|�|d�q�|ddhk�r�|�d��r�|�d�\}	}
|�d�\}}|�||
�|�|d�q�|ddhk�r�|�d��r�|�d�\}	}
|�d�\}}|�||	�|�|d�q�|�||�q�Wd�n	1�s�wYWd�n	1�s�wYqdS)Nrrr�r�rr|)r�r1rr�r�r�r�s2003-01-\d\ds
????-??-??s\d\d:\d\d:\d\ds??:??:??s.([r-][w-][x-]){3}s
??????????)�tarfile/�lars/�foo/�/s[0-9]+)�/tarfile�/users�/bar�1000/sNone�/100)r�r�r�r�)r�r�r�r�)r�rrrrrSr�rr�r�rYr�r�rAr�r�r��re�matchr@rr��endswith)
rr�r5Ztio_prevr:r�Ztio_newrI�gotZexp_userZ	exp_groupZgot_userZ	got_grouprrrr�^s�
��
��
�������������zNoneInfoTests_Misc.test_listN)rrrr�r�rrrrr�Csr�cCs�|dd�}tjdd�|dtjdd�|dBtjdtjtjBtjd�|dBtjdd�|dBtjdd�|d	BtjdtjtjBtjd�|d
Btj	dd�|dBtj
dd�|dBtjdtjtjBtjd
�|dB}|S)z�Inverse of `stat.filemode` (for permission bits)

    Using mode strings rather than numbers makes the later tests more readable.
    r\Nr)rJ�-)r�r�)rcr�rf�Sr_r���r��)rcr�r��Tr�)
r,�S_IRUSR�S_IWUSR�S_IXUSR�S_ISUID�S_IRGRP�S_IWGRP�S_IXGRP�S_ISGID�S_IROTH�S_IWOTH�S_IXOTH�S_ISVTX)rZstr_mode�resultrrr�_filemode_to_int�sF�
�����
���
��
����r�c@sHeZdZdZdd�Zdd�Zdd�Zddddddd	�d
d�Zdd
�ZdS)rz�Helper to create a tar file with specific contents

    Usage:

        with ArchiveMaker() as t:
            t.add('filename', ...)

        with t.open() as tar:
            ... # `tar` is now a TarFile with 'filename' in it!
    cCst��|_dSr	)rr�r�rrrrr>�r9zArchiveMaker.__init__cCstjd|jd�|_|S)Nr�r)rrr��tar_wrrrr�	__enter__�szArchiveMaker.__enter__cGs |j��|j��|_d|_dSr	)r�r7r�r�r�)rr�rrr�__exit__�s

zArchiveMaker.__exit__N)rr�hardlink_torrB�contentcKs�t|�}t�|�jdi|��}	|dur t|t�r|��}t|�}|dur0||	_|dur0t|	j�}|r7t	|�|	_
|durCtj}t|�|	_|durOtj
}t|�|	_|�d�r[|dur[tj}|durb||	_|	��rlt�|�}
nd}
|j�|	|
�dS)a�Add a member to the test archive. Call within `with`.

        Provides many shortcuts:
        - default `type` is based on symlink_to, hardlink_to, and trailing `/`
          in name (which is stripped)
        - size & content defaults are based on each other
        - content can be str or bytes
        - mode should be textual ('-rwxrwxrwx')

        (add more! this is unstable internal test-only API)
        Nr�r)r�rr�r�r'rlrArBr�r�rrr�r9r�r	rrZrr�r�r�)rrqrrrrrBrrrEr�rrrr��s4





zArchiveMaker.addcKs t�|j�}tjdd|i|��S)z9Open the resulting archive as TarFile. Call after `with`.r�Nr)rr�r�rr)rrr�rrrr�szArchiveMaker.open)	rrr�__doc__r>r�rr�rrrrrr�s
�)rc@sLeZdZe�e�dZedZeddd�dd��Z			dLd	d
�Z
dd�ZdMdd�Zdd�Z
dd�Zdd�Zejdd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Z d4d5�Z!d6d7�Z"d8d9�Z#d:d;�Z$d<d=�Z%d>d?�Z&d@dA�Z'dBdC�Z(dDdE�Z)dFdG�Z*dHdI�Z+dJdK�Z,dS)N�TestExtractionFilters�outerdirr]Tr)�
check_flag�
ignored_treesccsJ�t�|j���|jd}|�d�z
|j|j|d�Wnty8}z||_d|_t	�|_
WYd}~n0d}~ww|D]}t�|j|���q;d|_d|_t	|j�
d��|_
|j
�|j�|j
�|�z	|VW|��n|��w|jry|j�|�|j
t	��|r�|�|��d�Wd�dSWd�dS1s�wYdS)aExtracts `tar` to `self.destdir` and allows checking the result

        If an error occurs, it must be checked using `expect_exception`

        Otherwise, all resulting files must be checked using `expect_file`,
        except the destination directory itself and parent directories of
        other files.
        When checking directories, do so before their contents.

        A file called 'flag' is made in outerdir (i.e. outside destdir)
        before extraction; it should not be altered nor should its contents
        be read/copied.

        *ignored_trees* is a set of directories to remove (including their
        contents) right after the archive is extracted. It is a workaround
        for Path.glob() failing to get all files in Python 3.10 and below.
        �flagz
capture merHTNFr�)rr8rr�rr^r�raised_exception�reraise_exceptionr��expected_pathsr/�resolver�r�r7r@r.)rr5rIrrZ	flag_pathr�Zignored_treerrr�
check_context

s<�

���"�z#TestExtractionFilters.check_contextNc
Cs�|jr|j�t�tj�|j|��}|�||j�|j�	|�|dur9t
jdkr9t�
t�|��j��}|�||�|durJt|t�rJ|�d�rJtj}|dur�|j|��}t�|�}	z|	|krg|�|�|	��WnTty�}
z|
�d|	�d|����d}
~
ww|tjks�|dur�|�|���n+|tjkr�|�|���n|tjkr�|�|���n|tj kr�|�|�!��nt"|��|dur�|�|��j#|�|dur�|�|�$�|�|j%D]}|j�&|�q�dS)z'Check a single file. See check_context.Nr%r�z	expected=z, got=)'r	r�r�rOrP�normpathr^r�r�remover�r+r,r��S_IMODEr-r@r'r�r�rr	�readlinkr��samefilerZadd_noterOr�r�rZis_fiforr��NotImplementedErrorr�r.�parentsr�)rrqrrrrBrrPr�rIrk�parentrrr�expect_file=
sL
���



�z!TestExtractionFilters.expect_filecs8|j|���|j�tjd��fdd�|jD�|_dS)z-Check a directory; forget about its contents.�rcsh|]	}�|jvr|�qSr)rr��Z	tree_pathrr�	<setcomp>r
s

�z8TestExtractionFilters.expect_any_tree.<locals>.<setcomp>N)r^rrrr	rr�rrr�expect_any_treen
s

�z%TestExtractionFilters.expect_any_treercCsH|�||��|jdur|j�Wd�n1swYd|_|jSr)r�r	r
)r�exc_typeZ
message_rerrr�expect_exceptionw
s
��z&TestExtractionFilters.expect_exceptionc	Csxt��
}|�d�Wd�n1swYdD]}|�|��|��
|�d�Wd�n1s4wYqdS)Nz
benign.txt)r$r5r
�rr�r
rr�rrrIrrr�test_benign_file~
s����z&TestExtractionFilters.test_benign_filec	Cs�t��}|�|jd�Wd�n1swY|�|��d��
|�d�Wd�n1s3wYdD]:}|�|��|��(t|j��d�r^t|j��d�}|�|�d��n|�	t
jd�Wd�n1sowYq:dS)Nzescaped.evilr$z../escaped.evil�r5r
r�z
/escaped.evilz+['"].*escaped.evil['"] has an absolute path)rr�rr
rrr�r�lstriprrr�)rrrIZouterdir_strippedrrr�
test_absolute�
s&�������z#TestExtractionFilters.test_absolutecCst��}|jddd�|jddd�|�d�Wd�n1s!wYt��r�|�|��d��.|jdurF|�t�	Wd�dS|j	ddd�|j	ddd�|�	d�Wd�n1scwY|�|��d	��|�t
jd
�Wd�n1s�wY|�|��d��|�t
jd�Wd�dS1s�wYdS|�|��d��
|�	d�Wd�n1s�wY|�|��d	��
|�	d�Wd�n1s�wY|�|��d��|�	d�Wd�dS1s�wYdS)
N�currentrrrz
current/..�parent/evilr$r3r5�T'parent/evil' would be extracted to ['"].*evil['"], which is outside the destinationr
zK'parent' would link to ['"].*outerdir['"], which is outside the destination)
rr�rr!r
rr	rr`rrr�r��rrrrr�test_parent_symlink�
sH�

�	�
���"���"�z)TestExtractionFilters.test_parent_symlinkc
Cs�t���}d}tjdkrd}n+dtjvr5t�|jjd�}d}tt	|j
��|}||t|�|}d|}ntd��d}d}	|D]*}
|jtj
�||�tjd	d
�|jtj
�||
�|d�tj
�||�}tj
�|	|
�}	q?tj
jg|�d�R�}d
gt|�}|j|tj
j|�d�|jdtj
�|d
�d�|jdtj
�dd�d�|jddd�|jddd�Wd�n1s�wY|�d��X|j|��dd|hd��;tjdkr�|�ttf�n&|jr�|�t�n|jddd�|jddd�|jdtjd�|jd|d�Wd�n	1�s
wYWd�n	1�swYdD]V}
|�|
��E|j|��|
d��+|�ttf�}t|t��rYtjdk�rQ|�|jd�n|�|j t j!�Wd�n	1�sdwYWd�n	1�stwY�q$dS)NZabcdefghijklmnopr%Zddddddddddddddddddddddddd�PC_PATH_MAXr\�dz1Need to guess component length for {sys.platform}r�
drwxrwxrwxrrZ�llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllr�escapeZflaglinkr�rZ	overwrite)rzescape/newfile�newr$F)rIrrz
../newfilerrsr rH)r�r���)"rr�r+rO�pathconf_names�pathconfrrrAr�r^rr�rPrQrr	r�r
rrr�r`r	rrrrr'r�Zwinerrorr@�errnoZENAMETOOLONG)rrZstepsZ	componentZmax_path_lenZpath_sep_lenZdest_lenZ
component_lenrPZ	step_path�iZlinkpathZparent_segmentsrIr�rrr�test_realpath_limit_attack�
st


��)��
��� �����z0TestExtractionFilters.test_realpath_limit_attackcCsft��rXtj�td�}t�|�t�dtj�|d��ttj�|ddd�d��Wd�n1s2wYtj�	tj�|d��rEd}ntj�	tj�|dd��rTd}nt
d	��t��}|jddd
�|jddd
�|�d�Wd�n1sywY|�
|��d
��*t��r�|jddd
�|jddd
�|�d�n
|�d�|�d�Wd�n1s�wY|�
|��d��t��r�|�tjd�n
|�d�|�d�Wd�n1s�wY|�
|��d��:t���r|r�|�tjd�n"|�tjd�n|�d�|�d�Wd�dSWd�dSWd�dS1�s,wYdS)NZresolution_testrr#rr�r�TFz#Could not determine link resolutionrzcurrent/parentr$r$rr3zcurrent/r5r%r
zS'current/parent' would link to ['"].*outerdir['"], which is outside the destination)rr!rOrPrQrNr�r�rr+rtrr�r
rrrr�r�)rZtestpathZdotdot_resolves_earlyrrrr�test_parent_symlink2sl
��

��	�

��
��
��$�z*TestExtractionFilters.test_parent_symlink2cCs4t��}|jd|jd�|�d�Wd�n1swY|�|��d��t��r;|jd|jd�|�d�n|�d�Wd�n1sJwY|�|��d��t��rd|�t	j
d�n|�d�Wd�n1sswY|�|��d��|�t	jd	�Wd�dS1s�wYdS)
Nrrr$r$r3r5r%r
�&'parent' is a link to an absolute path)rr�rr
rrr!rrrr�rr&rrr�test_absolute_symlinkns4�
���
��
�"�z+TestExtractionFilters.test_absolute_symlinkcCs�t��}|jd|jdd�Wd�n1swY|�|��d��|�td�Wd�n1s6wY|�|��d��|�td�Wd�n1sTwY|�|��d��|�tjd�Wd�dS1stwYdS)	Nrr�r,r$z.*foo. not foundr5r
r5)	rr�rr
rrrrrr&rrr�test_absolute_hardlink�s����"�z,TestExtractionFilters.test_absolute_hardlinkc	Cs�t��}|jddd�Wd�n1swYz4|j|��dd��!t��r=t|jt�r5|�	t�n	|j
ddd�n	Wd�n1sHwYWn	tyWYnwdD]!}|�|��|��|�	tjd�Wd�n1svwYqZdS)N�../mooz..//tmp/moorr$rHr zH'../moo' would be extracted to '.*moo', which is outside the destination)
rr�r
rrr!r'r	r`rrrr�rrrr�test_sly_relative0�s2���������z(TestExtractionFilters.test_sly_relative0c	Cs�t��}|�d�|jddd�Wd�n1swY|�|��d��|jdtjd�t��r;|jdd	d�Wd�n1sEwYd
D]!}|�|��|��|�	tj
d�Wd�n1shwYqLdS)Nztmp/z
tmp/../../mooztmp/../..//tmp/moorr$�tmprr8ztmp/../../tmp/moor zU'tmp/../../moo' would be extracted to ['"].*moo['"], which is outside the destination)rr�r
rrrr	rr!rr�rrrr�test_sly_relative2�s&
�������z(TestExtractionFilters.test_sly_relative2c	Cs�t��(}|jddd�|jdtj�dd�d�|jdtj�d	dd�d
�Wd�n1s.wYdD]<}|�|��|��*|jddd�|jddd�t�	�r[|jdddd
�n|jddd�Wd�n1slwYq5dS)N�targetdir/targetr�r��linkdir/hardlink�	targetdirr�r,�linkdir/symlinkrr�r5r
r$z../targetdir/target�rBr�
rr�rOrPrQr
rrrr!rrrr�test_deep_symlink�s,�
��	�����z'TestExtractionFilters.test_deep_symlinkc	Cs8t��:}|jddd�|jdtj�dd�d�|jddd	�|jd
tj�dd�d
�|jdtj�dd�d
�Wd�n1s@wYdD]R}|�|��|��@|jddd	�|jd
dd	�|jddd	�t�	�r||jdddd�|jdddd�n|jddd	�|jddd	�Wd�n1s�wYqGdS)Nr?ZhardlinkrZsymlink2ZlinkdirZ	hardlink2r<r�r�r=r>r�r,zlinkdir/hardlink2r�r@rArBrrrr�test_chains�s6��������z!TestExtractionFilters.test_chainsc
Cs�t��>}|�d�|�d�|jdtj�dd�d�|jdtj�ddd	�d�|jdd
d�|jdtj�dd�d
�Wd�n1sDwY|�|��d��.t��s]|�	t
j�ntj
dkri|�	t
j�n|�	t
jd�}|�|jt
j�Wd�n1s�wYdD]b}|�|��S|�|��|��;t��s�|�d�|�d�|�d�n|�d�|�d�|jddd�|jddd�|jdd
d�Wd�n1s�wYWd�n1s�wYq�dS)Nz	a/t/dummyzb/�crsr�rzc/escaperZ	link_herertZboomr+r,r
r%zJlink 'boom' would be extracted as a copy of 'c/escape', which was rejected)r5r$zc/z
a/t/escapez../../link_here)rr�rOrPrQr
rrr!rrr�r�r+r�r��	__cause__r�r)rrrkrIrrr�test_sneaky_hardlink_fallbacksV

���
����



�����z3TestExtractionFilters.test_sneaky_hardlink_fallbackc
Cs�t��}|jdtj�ddddd�d�|jddd�Wd�n1s$wYdD]:}|�|��|��(t��rU|j	ddd�|dkrM|j	ddd�n	|j	dd	d�n	Wd�n1s`wYq+dS)
Nr+rrz	link-hererrr@r
zlink/link/../../link-here)
rr�rOrPrQr
rrr!rrrrr�test_exfiltration_via_symlink4s$������z3TestExtractionFilters.test_exfiltration_via_symlinkc	Cst��$}|jddd�|jddd�|jddd�|jdd	d�Wd�n1s*wYd
D]X}|�|��|��F}t��sF|�d�n!|dkrY|jdd	d�|jddd�n|jdd	d�|jddd�tjdkrz|j	�
�j}|�|d
@d
�Wd�n1s�wYq1dS)Nza/pwnrrza/pwn/r*r�zx/../za/xz../r@r
r%r&)
rr�r
rrr!rr�r+rr,r-r�)rrrI�ccr-rrr�test_chmod_outside_dirJs,�

����z,TestExtractionFilters.test_chmod_outside_dirc	Cs�t�� }|�d�|�d�|jddd�|jddd�Wd�n1s&wYdD].}|�|��|��}|�d�|�d�|�d�|�d�Wd�n1sVwYq-dS)	N�dir/zdir/../afileZlink1r,Zlink2zdir/../dir/../afiler@Zafiler)rrrIrIrrr�test_link_fallback_normalizesis

�


���z3TestExtractionFilters.test_link_fallback_normalizesc

Cst��9}|jddd�|jddd�|jddd�|jdd	d�|jd
dd�|jdd
d�|jddd�Wd�n1s?wYtj�td�}t|d��Wd�n1s[wYzbt�|�jtj	Btj
BtjB}zt�||�Wn"t
y�}z|jttdd�kr�|�d�n�WYd}~nd}~wwt�|�j}|tj	@r�dnd}|tj@r�dnd}|tj
@r�dnd}Wt�|�nt�|�wt�|�t�|�jtj	Btj
BtjB}t�||�t�|�j}|tj	@r�dnd}	|tj@r�dnd}
|tj
@�rdnd}t�|�|�|��d��Q|jdd|�d|�d|��d�|jddd�|jddd�|jdd	d�|jd
dd�|jdd|�d|	��d�|jdd|
�d|�d|	��d�Wd�n	1�sgwY|�|��d��9|jddd�|jddd�|jddd�|jdd	d�|jd
dd�|jddd�|jddd�Wd�n	1�s�wY|�|��d��Ft�t�|j��j��}|jddd�|jddd�|jdd d�|jdd!d�|jd
d"d�|jd|d�|jd|d�Wd�dS1�swYdS)#NZall_bitsrr�Z	perm_bitsz
?rwxrwxrwxZexec_group_otherz
?rw-rwxrwxZread_group_onlyz
?---r-----Zno_bitsz
?---------rKz
?---rwsrwtz
dir_all_bits/ztmp.filer�ZEFTYPErz?chmod() failed with EFTYPE: regular users cannot set sticky bitr�rcrfr$z?rwrz?---rwr5z
?rwxr-xr-xz
?rw-r-xr-xz
?---r-xr-xr
z
?rw-r--r--z
?rw-r-----z
?rw-------)rr�rOrPrQrNrr,r-r�r�r�rrr1r�rTrr�r�r
rr�rr)
rrZtmp_filenameZnew_moder�Zgot_modeZ_t_fileZ
_suid_fileZ
_sgid_fileZ_t_dirZ	_suid_dirZ	_sgid_dirZnormal_dir_moderrr�
test_modesys���
������	

���
����	
�$�z TestExtractionFilters.test_modesc	Cs�t��}|jdtjd�Wd�n1swYdD])}|�|��|��ttd�r6|jdtjd�n	Wd�n1sAwYq|�|��d��|�	tj
d�Wd�dS1sbwYdS)Nr�r)r$r5�mkfifor
z'foo' is a special file)rr�rrr
rr�rOrrr�rrrr�	test_pipe�s"�
����"�zTestExtractionFilters.test_pipec	Cs�tjtjtjfD]Q}t�d�}||_t�|d�}|�||�t�|d�}|�	|j|�|�
tj��}t�|d�Wd�n1sBwY|�
|jjtj�|�	|jjjd�qdS)Nr�r)rrr�rNr�rrr�rr@r�r�r�r�rrErq)rZspecial_typerEZtrustedr5�cmrrr�test_special_files�s
��z(TestExtractionFilters.test_special_filescCsXtj�t��}|��D]}t�|d�}|�||�qWd�dS1s%wYdS)Nr)rrrrr�rr��rr5rEZfilteredrrr�test_fully_trusted_filter�s�"�z/TestExtractionFilters.test_fully_trusted_filtercCsptjjtdd��&}|��D]}t�|d�}|�|j|j�|�|j|j�q
Wd�dS1s1wYdS�Nr1rr)	rrrrr�rr�rqrrRrrr�test_tar_filter�s�"�z%TestExtractionFilters.test_tar_filterc
Cs�tjjtdd��3}|��D]%}zt�|d�}Wn
tjy!Yq
w|�|j|j�|�|j	|j	�q
Wd�dS1s>wYdSrT)
rrrrr�r�r�r�rqrrRrrr�test_data_filter�s��"�z&TestExtractionFilters.test_data_filterc	Cs�t��
}|�d�Wd�n1swYt�|��.|�|��d��
|�d�Wd�n1s6wYWd�dSWd�dS1sNwYdS)z6Ensure the default filter does not warn (like in 3.12)r�N)rr�rZcheck_no_warningsr
rrr&rrr�test_default_filter_warns_nots���"�z3TestExtractionFilters.test_default_filter_warns_notcCsVt�td�}dd�}||_|�|d��|�d�Wd�dS1s$wYdS)NrJcS�|jdkr|SdS�Nr;rM�rErPrrr�
strict_filter�
zSTestExtractionFilters.test_change_default_filter_on_instance.<locals>.strict_filterr;)rrrr�r
r)rr5r[rrr�&test_change_default_filter_on_instances"�z<TestExtractionFilters.test_change_default_filter_on_instancec	Cs�dd�}t�td�}t�tjdt|���,|�|d��
|�d�Wd�n1s+wYWd�dSWd�dS1sCwYdS)NcSrXrYrMrZrrrr[r\zPTestExtractionFilters.test_change_default_filter_on_class.<locals>.strict_filterrJr�r;)rrrrr�r�r
r)rr[r5rrr�#test_change_default_filter_on_classs
���"�z9TestExtractionFilters.test_change_default_filter_on_classcCsXGdd�dtj�}|td�}|�|d��|�d�Wd�dS1s%wYdS)Nc@rP)zQTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclasscSs|jdkr|SdSrYrM�rrErPrrrr�(r\zcTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclass.extraction_filterNr�rrrr�TarSubclass'rVr`rJr;)rrrr
r)rr`r5rrr�&test_change_default_filter_on_subclass&s

"�z<TestExtractionFilters.test_change_default_filter_on_subclasscCsNt�td�}d|_|�|d��|�t�Wd�dS1s wYdS)NrJr
)rrrr�r
rrr�rrr�$test_change_default_filter_to_string2s
"�z:TestExtractionFilters.test_change_default_filter_to_stringcs��fdd�}t��}|�d�|�d�|�d�Wd�n1s#wY��|��|����d���d�Wd�dS1sFwYdS)Ncs6��|�j�|jdkr|jdd�S|jdkrdS|S)N�	move_this�movedrM�ignore_this)r�r^rqr�rZrrr�
custom_filter9s

z?TestExtractionFilters.test_custom_filter.<locals>.custom_filterrcreZkeeprdr)rrfrrrr�test_custom_filter8s

�
"�z(TestExtractionFilters.test_custom_filtercCspt��
}|�d�Wd�n1swY|�|��d��|�t�Wd�dS1s1wYdS)Nr�zbad filter name)rr�r
rrrr&rrr�test_bad_filter_nameIs�"�z*TestExtractionFilters.test_bad_filter_namec	Cs�Gdd�d�}t��}|�d�|jddd�|�d�Wd�n1s&wY|��%}|�|��|��
|�d�Wd�n1sGwYWd�n1sVwY|�|jd�|�|jd�dS)	Nc@r�)zBTestExtractionFilters.test_stateful_filter.<locals>.StatefulFiltercSs
d|_|Sr^)�num_files_processedrrrrr�TszLTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__enter__cSs:zt�||�}WntjyYdSw|jd7_|S)Nr\)rr�r�rir_rrr�__call__Xs�zKTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__call__cWs
d|_dS)NT)�done)r�exc_inforrrr`�
zKTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__exit__N)rrrr�rjrrrrr�StatefulFilterSsrnZgoodZbadr�rr_T)rr�r
rrr@rirk)rrnrrfrrr�test_stateful_filterOs
����z*TestExtractionFilters.test_stateful_filtercCs4dd�}dd�}dd�}dd�}d	d
�}t��
}|�d�Wd�n1s'wY|�|jdd
�|��Wd�n1sAwY|�|jdd
�|��Wd�n1s[wY|�|jdd
�|��Wd�n1suwY|�|jdd
�|��|�tj�Wd�n1s�wY|�|jdd
�|��
|�t�Wd�n1s�wY|�|jdd
�|��Wd�n1s�wY|�|jdd
�|��|�tj�Wd�n1s�wY|�|jdd
�|��
|�t	�Wd�n	1�swY|�|jdd
�|��|�tj�Wd�n	1�s/wY|�|jdd
�|��
|�t�Wd�n	1�sOwY|�|jdd
�|��|�tj
�Wd�n	1�spwY|�|jdd
�|��|�tj�Wd�n	1�s�wY|�|jdd
�|��
|�t	�Wd�n	1�s�wY|�|jdd
�|��|�tj�Wd�n	1�s�wY|�|jdd
�|��
|�t�Wd�n	1�s�wY|�|jdd
�|��|�t�Wd�dS1�swYdS)NcS�
t�d��)Nzfailed with ExtractError)r�ExtractErrorrZrrr�extracterror_filternrmzBTestExtractionFilters.test_errorlevel.<locals>.extracterror_filtercSrp)Nzfailed with FilterError)rr�rZrrr�filtererror_filterprmzATestExtractionFilters.test_errorlevel.<locals>.filtererror_filtercS�td��)Nzfailed with OSError)rrZrrr�oserror_filterr�z=TestExtractionFilters.test_errorlevel.<locals>.oserror_filtercSrp)Nzfailed with base TarError)r�TarErrorrZrrr�tarerror_filtertrmz>TestExtractionFilters.test_errorlevel.<locals>.tarerror_filtercSrt)Nzfailed with ValueError)rrZrrr�valueerror_filtervrvz@TestExtractionFilters.test_errorlevel.<locals>.valueerror_filterr�rrr\r_zboo!)rr�r
rrrrwrr�rrqr)rrrrsrurxryrrrr�test_errorlevelmsp����������������$�z%TestExtractionFilters.test_errorlevel)NNNNN)r)-rrrr�r�rNrr^rr
rrrrr"r'rrJr3r4r6r7r9r;rCrDrGrHrJrLrMrOrQrSrUrVrWr]r^rarbrgrhrorzrrrrr
sR/
�1
	2
GV"3P
rc@s,eZdZeZejejdeejdeejdeejdeejdedejej	ejej
ejejdejdejdeejejdeejejejejdZ
ejejd	ejd
ejd
ejdeejdedejej	ejej
ejejdejdejdejdejd
Zejejdeejdeejdeejdeejdedejej	ejej
ejdZe�d��ej�ZdejZdd�Zd!dd�Zdd�Zdd�Zdd�Zdd�Zdd �ZdS)"�OffsetValidationTestss000755s000001s������������s0011407� r��s0000755s0000001s0011327r��s0010070r�r���cCs<t|jd��}|�|�Wd�dS1swYdSr�)rrr�)r�bufferrrrr�
_write_buffers"�z#OffsetValidationTests._write_bufferNc	Csxt|jd��,}tjd||d��}|��Wd�Wd�S1s%wYWd�dS1s5wYdS)Nr[rJ)rr�r�)rrrr�)rr�rr5rrr�_get_memberss���"�z"OffsetValidationTests._get_memberscCs<|�tjd��
|��Wd�dS1swYdS)Nr�)r�rr�r�rrrr�#_assert_raises_read_error_exceptions
�
"�z9OffsetValidationTests._assert_raises_read_error_exceptionc	Cshd|jfd|jfd|jffD]#\}}|j|d��|�|�|��Wd�n1s,wYqdS)N�posixr�Zv7r})�invalid_posix_header�invalid_gnu_header�invalid_v7_headerr�r�r�)rZ
tar_formatZinvalid_headerrrr�&test_invalid_offset_header_validations#s�

���z<OffsetValidationTests.test_invalid_offset_header_validationscCs\|j|j|j}|�|�|��}|�t|�d�|�|djd�|�|djd�dS)Nr\rr�)�valid_gnu_headerr�r�r�r@rArqr�rr�r�rrr�(test_early_stop_at_invalid_offset_header-s
z>OffsetValidationTests.test_early_stop_at_invalid_offset_headercCs:|j|jd}|�|�|jdd�}|�t|�d�dS)Nr�T�r�r)r��
data_blockr�r�r@rAr�rrr�test_ignore_invalid_archive5s
z1OffsetValidationTests.test_ignore_invalid_archivecCs�|j|j|jdf|j|j|jdffD],\}}}|�||�|jdd�}|�t|�d�|�|djd�|�|dj|�qdS)Nrr]Tr�r\r�)	r�r�r�r�r�r@rArqr)rZfirst_blockZsecond_blockZexpected_offsetr�rrr�"test_ignore_invalid_offset_headers<s
�
���z8OffsetValidationTests.test_ignore_invalid_offset_headersr	)rrrr�rrr�r6�SPACErOr7rr�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr{�s*
�����������
�
����
����������
���
$��������
�
����
��������
"�����������
�
����
���


r{c	Cs�t�t�t�t�tgattd��}|��}Wd�n1s!wYt	t
tfD]-}|jrXt�|j�t�|j�|�|jd��
}|�
|�Wd�n1sSwYq+dS)Nr[r�)rrrNrOrrr:rr?r#r'r+r�r�)rFr
rEr5rrr�setUpModulePs


����r�cCstj�t�r
t�t�dSdSr	)rOrPr+rNrr/rrrr�tearDownModuleas�r��__main__)�r1r�rOrZhashlibr�
contextlibrZrandomrr�r�r��warningsr,r�Z
unittest.mockrr�rZtest.supportrrrr%r�rFr(r-r
rPr�ZTESTFNrNrXr�rrQr$r)r,r�rRr�rCr�rZ
requires_gzipr#Zrequires_bz2r'Z
requires_lzmar+r/ZTestCaser:r�r�r�r�r�r�r�r�r�rMrOrQrWrXrfrgrhrjrtrurxryr�r�r�r�r�r!r"r#r$r-r1r3r4rLrRrirqrsrur�r�rvr|r�r�r�r�r�r�r�r�r�r�r�r"rbrKrirrr�r�r�r�r�r�r�r�r�r�rrr{r�r�rr�rrrr�<module>sB����
��
Pw=(a8<W:'R.Z			*QO@;{^:!z(b��^F9
�