Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 18.118.146.157
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_tarfile.cpython-310.pyc
o

ab���@s�ddlZddlZddlZddlmZddlmZddlmZddl	Z	ddl
Z
ddlZ
ddlZddl
mZddlmZddlmZzddlZWneyQdZYnwzddlZWneycdZYnwzddlZWneyudZYnwzddlZWney�dZYnwdd	�Zej�ej�d
ZedZe�d�Zej�ed
�Z ej�ed�Z!ej�ed�Z"ej�ed�Z#ej�ed�Z$dZ%dZ&Gdd�d�Z'e�(�Gdd�d��Z)e�*�Gdd�d��Z+e�,�Gdd�d��Z-Gdd�de'�Z.Gdd�de.e
j/�Z0Gd d!�d!e)e0�Z1Gd"d#�d#e+e0�Z2Gd$d%�d%e-e0�Z3Gd&d'�d'e.e
j/�Z4Gd(d)�d)e)e4�Z5Gd*d+�d+e+e4�Z6Gd,d-�d-e-e4�Z7Gd.d/�d/e.�Z8Gd0d1�d1e8�Z9Gd2d3�d3e9e
j/�Z:Gd4d5�d5e)e9e
j/�Z;Gd6d7�d7e+e9e
j/�Z<Gd8d9�d9e-e9e
j/�Z=Gd:d;�d;e8e
j/�Z>Gd<d=�d=e)e>�Z?Gd>d?�d?e+e>�Z@Gd@dA�dAe-e>�ZAGdBdC�dCe'e
j/�ZBGdDdE�dEe)eB�ZCGdFdG�dGe+eB�ZDGdHdI�dIe-eB�ZEGdJdK�dKe.e
j/�ZFGdLdM�dM�ZGGdNdO�dOeGe.e
j/�ZHGdPdQ�dQeGe.e
j/�ZIGdRdS�dSe'�ZJGdTdU�dUeJe
j/�ZKGdVdW�dWe)eK�ZLGdXdY�dYe+eK�ZMGdZd[�d[e-eK�ZNGd\d]�d]eJe
j/�ZOGd^d_�d_e)eO�ZPGd`da�dae+eO�ZQGdbdc�dce-eO�ZRGddde�dee
j/�ZSGdfdg�dgeJe
j/�ZTGdhdi�dieJe
j/�ZUGdjdk�dke)eU�ZVGdldm�dme+eU�ZWGdndo�doe-eU�ZXGdpdq�dqeU�ZYe
�Ze[edr�ds�Gdtdu�due
j/��Z\Gdvdw�dweS�Z]Gdxdy�dy�Z^Gdzd{�d{e^e
j/�Z_Gd|d}�d}e^e
j/�Z`Gd~d�de^e
j/�ZaGd�d��d��ZbGd�d��d�ebe
j/�ZcGd�d��d�e)ebe
j/�ZdGd�d��d�e+ebe
j/�ZeGd�d��d�e-ebe
j/�ZfGd�d��d�e
j/�ZgGd�d��d�e
j/�ZhGd�d��d�e
j/�ZiGd�d��d�e
j/�Zje
�ke[edr�d��Gd�d��d�e.e
j/��ZlGd�d��d�e+e
j/�Zmd�d��Zne
�Ze[ed��d��e
�Ze[ed��d��Gd�d��d�e
j/���Zod�d��Zpd�d��Zqerd�k�rae
�s�dSdS)��N)�sha256)�contextmanager)�Random)�support)�	os_helper)�
script_helpercCst|���S�N)r�	hexdigest)�data�r�:/usr/local/python-3.10/lib/python3.10/test/test_tarfile.py�	sha256sum#sr
z-tardirz
-extract-testztesttar.tarztesttar.tar.gzztesttar.tar.bz2�testtar.tar.xzztmp.tarZtesttarZ@e09e4bc8b3c9d9177e77256353b36c159f5f040531bbd4b024a8f9b9196c71ceZ@4f05a776071146756345ceee937b33fc5644f5a96b9780d1c7d6a32cdf164d7bc@s.eZdZeZdZejZej	j
Z
edd��ZdS)�TarTest�cCs|j|jSr)�prefix�suffix��selfrrr�mode=szTarTest.modeN)
�__name__�
__module__�__qualname__�tarnamer�io�FileIO�open�tarfile�TarFile�taropen�propertyrrrrrr7src@�*eZdZeZdZer
ejndZe	j
jZdS)�GzipTest�gzN)
rrr�gzipnamerr�gzipZGzipFilerrrZgzopenrrrrrr"A�
r"c@r!)�Bz2Test�bz2N)
rrr�bz2namerrr(�BZ2FilerrrZbz2openrrrrrr'Hr&r'c@r!)�LzmaTest�xzN)
rrr�xznamerr�lzma�LZMAFilerrr�xzopenrrrrrr+Or&r+c@s eZdZdZdd�Zdd�ZdS)�ReadTest�r:cCstj|j|jdd�|_dS)N�	iso8859-1�r�encoding�rrrr�tarrrrr�setUp[s�zReadTest.setUpcCs|j��dSr)r7�closerrrr�tearDown_�zReadTest.tearDownN)rrrrr8r:rrrrr1Wsr1c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
UstarReadTestcCsl|j�d�}|j�|�� }|��}|�t|�|jd�|�t|�td�Wd�dS1s/wYdS)N�
ustar/regtype�regular file extraction failed)	r7�	getmember�extractfile�read�assertEqual�len�sizer
�sha256_regtype�r�tarinfo�fobjr
rrr�test_fileobj_regular_filees��"�z'UstarReadTest.test_fileobj_regular_filecCs�|j�dt�|j�d�}ttj�td�d��}|��}Wd�n1s&wY|j�	|��+}t
�|�}|��}|�||d�|�t
|�dd�|�|ddd�Wd�dS1s_wYdS)Nr=�rzfileobj.readlines() failed�r�SzOI will gladly admit that Python is not the fastest running scripting language.
)r7�extract�TEMPDIRr?r�os�path�join�	readlinesr@r�
TextIOWrapperrBrC)rrG�fobj1�lines1rH�fobj2�lines2rrr�test_fileobj_readlinesns&
�
��
�"�z$UstarReadTest.test_fileobj_readlinescCs�|j�dt�|j�d�}ttj�td�d��}|��}Wd�n1s&wY|j�	|��}t
t�|��}|�
||d�Wd�dS1sKwYdS)Nr=rJzfileobj.__iter__() failed)r7rMrNr?rrOrPrQrRr@�listrrSrB)rrGrTrUrVrWrrr�test_fileobj_iter�s
��"�zUstarReadTest.test_fileobj_iterc	Cs*|j�dt�ttj�td�d��}|��}Wd�n1s wY|j�d�}|j�	|���}|��}|�
d�|�d|��d�|�
dd�|�d|��d�|�
dd�|�d	|��d
�|�
d	d�|�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=�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)r7rMrNrrOrPrQrAr?r@�seekrB�tellrDrRrC�readline)	rrHr
rG�text�s�s1�s2�linerrr�test_fileobj_seek�sv
�
����
����

�
�
�
�$�zUstarReadTest.test_fileobj_seekc	Cs�|j�d��;}t�|�}|���d�}|�t|�t�z|�	d�Wnt
y0|�d�Yn	wWd�dSWd�dS1sDwYdS)Nr=r3�dzseeking failed in text mode)r7r@rrSrA�encoderBr
rErb�AttributeError�fail�rrHr
rrr�test_fileobj_text�s
���	"�zUstarReadTest.test_fileobj_textc	Cs~|j�|��/}|j�|��}|�|j|j�Wd�n1s wYWd�dSWd�dS1s8wYdSr)r7r@rB�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_issue14160N)rrrrIrXrZrjrpruryr}r�r�r�rrrrr<cs	
0r<c@�eZdZdS)�GzipUstarReadTestN�rrrrrrrr���r�c@r�)�Bz2UstarReadTestNr�rrrrr��r�r�c@r�)�LzmaUstarReadTestNr�rrrrr��r�r�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ListTestcCstj|j|jd�|_dS)N�rr6rrrrr8�szListTest.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)�decoder7r5rl)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�sysr7rY�detach�getvalue�assertIn�assertRegex�assertNotIn)r�tio�outr�rrr�	test_list�s4�
�
�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�r7rYr�r�r�r�)rr�r�rrr�test_list_verboses"����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)r7rGrrr�members.s�
��z+ListTest.test_list_members.<locals>.membersr�F)r�r�r�r�)rrSr�rr�r�r7rYr�r�r�r�)rr�r�r�rrr�test_list_members,s�zListTest.test_list_membersN)rrrr8r�r�r�rrrrr��s
%r�c@r�)�GzipListTestNr�rrrrr�9r�r�c@r�)�Bz2ListTestNr�rrrrr�=r�r�c@r�)�LzmaListTestNr�rrrrr�Ar�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)	r�tmpname�assertFalser�
is_tarfile�pathlib�Pathrr��rrHrrr�test_is_tarfile_erroneousGs��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�rAr�rrr�test_is_tarfile_validXs�"�z$CommonReadTest.test_is_tarfile_validcCs�t�t|j�dd���Wd�n1swYz3z
t�t|j�}|��Wntjy8|�d�Ynw|�|�	�g�W|�
�dSW|�
�dS|�
�w)NrJ�wz&tarfile.open() failed on empty archive)rrr�r�replace�getnames�	ReadErrorrn�assertListEqualr�r9�rr7rrr�test_empty_tarfilegs���z!CommonReadTest.test_empty_tarfilecCs@|�td��t�d|j�Wd�dS1swYdS)NZxxx)�assertRaisesRegex�FileNotFoundErrorrrrrrrr�test_non_existent_tarfilexs"�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)rZignore_zerosz3ignore_zeros=True should have skipped the %r-blocks)
r�	randbytesrr��writer�TarInforCrD�tobufr�r�r9)rr
�charrHrGr7rrr�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��G}|��}|�	tj
d��|�|t
�Wd�n1s�wY|�	tj
d��|�|���Wd�n1s�wYWd�n1s�wYqdS)N)raiXr]i��w:r�r]saaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazr+bzunexpected end of data)rrr�r�rD�addfilerr��truncater�r��nextrMrNr@rA)rrDr7�trHrrr�test_premature_end_of_archive�s:
������������z,CommonReadTest.test_premature_end_of_archivec	Cst|�tjd��)t�t�d���}Wd�n1swYWd�dSWd�dS1s3wYdS)Nz%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�Es	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�MiscReadTestBasecCsdSrrrrrr�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�strrrrBrOrP�abspath�rrHr7rrr�test_no_name_argument�s��"�z&MiscReadTestBase.test_no_name_argumentcCsnt|jd��}|��}Wd�n1swYt�|�}|�tt|d�tj||j	d�}|�
|j�dS)Nr[rqr�)rrrArr�r�rm�getattrrr�assertIsNonerq�rrHr
r7rrr�test_no_name_attribute�s
�
z'MiscReadTestBase.test_no_name_attributecCs�t|jd��}|��}Wd�n1swYt�|�}d|_tj||jd��}|�|j�Wd�dS1s<wYdS)Nr[rr�)	rrrArr�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�fdrHr7rrr�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�bytesrrrBrPr�)rrrHr7rrr�test_bytes_name_attribute�s��"�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�rBrOrPr��fspathrrr)rrr7rrr�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��
ValueErrorrr�rrr�test_illegal_mode_arg�s���"�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�r2)rr�zseek back did not work)
rrrrr�rq�offsetr@rAr9rbrBr�)rr7r�rqr��fr
rHrrr�test_fileobj_with_offsets0
��
���"�z)MiscReadTestBase.test_fileobj_with_offsetcCs^|�tjtjt|j�ttd��}|jtjtj||jd�Wd�dS1s(wYdSr�)r�rr�rrrr�rrr�test_fail_comp s�"�zMiscReadTestBase.test_fail_compcCs"|j�d�}|�|jtjd�dS)Nzmisc/dirtype-old-v7zv7 dirtype failed)r7r?rB�typer�DIRTYPE�rrGrrr�test_v7_dirtype's�z MiscReadTestBase.test_v7_dirtypecCs2z	|j�d�WdSty|�d�YdSw)Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))r7r?�KeyErrorrnrrrr�test_xstar_type/s
�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)r7rBr��mtimerq�
startswith�unamer�rrr�test_check_members8s
�
��z#MiscReadTestBase.test_check_memberscCs|�|j��djdd�dS)N���zmisc/eofzcould not find all members)rBr7r�rqrrrr�test_find_membersAs�z"MiscReadTestBase.test_find_members�link�Missing hardlink implementationc	Cs:tjtddd���}|�dt�|�tjtj	�
td��|�dt�|�tjtj	�
td��ttj	�
td�d��}|��}Wd�n1sFwY|�t
|�t�|�dt�|�tjtj	�
td��ttj	�
td�d��}|��}Wd�n1s~wY|�t
|�t�Wd�dS1s�wYdS)Nr\r3)�
errorlevelr5r=rwr[r)rrrrMrN�
addCleanupr�unlinkrOrPrQrArBr
rE)rr7r�r
rrr�test_extract_hardlinkEs 
�
�"�z&MiscReadTestBase.test_extract_hardlinkc		Cs�tjtdd�}tj�td�}t�|�zXdd�|D�}|�||�|D]<}tj�||j	�}t
jdkrA|�|j
d@t�|�jd@�dd	�}tj�|�}d
�||j�||�|�}|�|j||�q#W|��t�|�dS|��t�|�w)Nr3�r5�
extractallcS�g|]}|��r|�qSr��isdir��.0r�rrr�
<listcomp>a�z4MiscReadTestBase.test_extractall.<locals>.<listcomp>�win32�cSs$t|t�r
d�||���Sd�|�S)Nz{} ({})z
{!r} (int))�
isinstance�float�format�hex)r�rrr�format_mtimeis

z6MiscReadTestBase.test_extractall.<locals>.format_mtimez,tar mtime {0} != file time {1} of path {2!a})rrrrOrPrQrN�mkdirr
rqr��platformrBr�stat�st_mode�getmtimerr�r9r�rmtree)	rr7�DIR�directoriesrGrPrZ
file_mtime�errmsgrrr�test_extractallZs2

����z MiscReadTestBase.test_extractallc	Cs�d}tj�td�}t�|�zVtjtdd��7}|�|�}|j	||d�tj�||�}|�
tj�|�|j�t
jdkrF|�
t�|�jd@d�Wd�n1sPwYWt�|�dSWt�|�dSt�|�w)	N�
ustar/dirtypeZ
extractdirr3r	�rPrri�)rOrPrQrNrrrrr?rMrBrr�r�rrrrr�rZdirtyperr7rGZ	extractedrrr�test_extract_directoryxs 


���z'MiscReadTestBase.test_extract_directoryc	Cs�t�t�d}t�|��Jtjtdd��*}dd�|D�}|�||�|D]}||j	}|�
tj�
|�|j�q$Wd�n1sAwYWd�dSWd�dS1sYwYdS)Nr
r3r	cSrrrrrrrr�rzBMiscReadTestBase.test_extractall_pathlike_name.<locals>.<listcomp>)r�r�rNr�temp_dirrrrr
rqrBrOrPrr�)rrr7r rGrPrrr�test_extractall_pathlike_name�s�
�P�z.MiscReadTestBase.test_extractall_pathlike_namec	Cs�d}t�t�d}t�|��Ctjtdd��#}|�|�}|j	||d�||}|�
tj�
|�|j�Wd�n1s<wYWd�dSWd�dS1sTwYdS)Nr#r
r3r	r$)r�r�rNrr'rrrr?rMrBrOrPrr�r%rrr�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*rHr7rrr�test_init_close_fobj�s���z%MiscReadTestBase.test_init_close_fobjcCsjt�|j��%}t||�D]\}}|�|j|j�|�|��|���qWd�dS1s.wYdSr)rrr�ziprBr�Zget_info)rr7Zm1Zm2rrr�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)�unittest�mock�patch�zlib�error�side_effectr�rr�rr)rr3rrr�test_zlib_error_does_not_leak�s��"�z.MiscReadTestBase.test_zlib_error_does_not_leak)!rrrr�r�r�r�r�r�r�r�r�r�r�r�rrr2�
skipUnless�hasattrrOr�skip_unless_symlinkrr"r&r(r)r/r1�skipIfr5r8rrrrr��s8		
		�

r�c@seZdZdZdS)�MiscReadTestN)rrrr�rrrrr=�sr=c@r�)�GzipMiscReadTestNr�rrrrr>�r�r>c@�eZdZdd�ZdS)�Bz2MiscReadTestcC�|�d�dS)NzBZ2File have no name attribute��skipTestrrrrr��r;z'Bz2MiscReadTest.requires_name_attributeN�rrrr�rrrrr@��r@c@r?)�LzmaMiscReadTestcCrA)NzLZMAFile have no name attributerBrrrrr��r;z(LzmaMiscReadTest.requires_name_attributeNrDrrrrrF�rErFc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StreamReadTest�r|c
Cs~|jD]9}|��s
q|j�|��$}	z|�d�}Wntjy(|�d�Ynw|s,q-qWd�n1s7wYqdS)NTraz6simple read-through using TarFile.extractfile() failed)r7Zisregr@rAr�StreamErrorrn)rrGrH�bufrrr�test_read_through�s"
�����z StreamReadTest.test_read_throughcCsh|j��}|j�|��}|��}Wd�n1swY|�t|�|jd�|�t|�td�dS)Nr>)	r7r�r@rArBrCrDr
rErFrrrrI�s

���z(StreamReadTest.test_fileobj_regular_filecCsP|j��}|j�|d��}|�tj|j�Wd�dS1s!wYdS)Nr)r7r�r@r�rrIrA)rZtarinfosr�rrr�test_provoke_stream_error�s
"�z(StreamReadTest.test_provoke_stream_errorcCs�tjtdd�}zc|j}	|��}|��}|durqd|�|d�|��s'|��rC|�tj	��
|�
|�Wd�n1s=wYq|�
|�}|�
|�}|durRq|�|d�|�|��|��d�qW|�
�dS|�
�w)Nr3r	Tzstream.next() failed.zstream.extractfile() failedzstream extraction failed)rrrr7r��assertIsNotNoneZislnkZissymr�rIr@rBrAr9)rZtar1Ztar2�t1�t2�v1�v2rrr�test_compare_members�s2�

��z#StreamReadTest.test_compare_membersN)rrrrrKrIrLrRrrrrrG�s	rGc@r�)�GzipStreamReadTestNr�rrrrrSr�rSc@r�)�Bz2StreamReadTestNr�rrrrrTr�rTc@r�)�LzmaStreamReadTestNr�rrrrrUr�rUc@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�DetectReadTestc
CsNzt�||�}Wntjy }z|��WYd}~dSd}~ww|��dSr)rrr�rnr9)rrqrr7�errr�_testfunc_files��zDetectReadTest._testfunc_filec
Cs|zt|d��}tj|||d�}Wd�n1swYWntjy7}z|��WYd}~dSd}~ww|��dS)Nr[�r�)rrr�rnr9)rrqrr�r7rXrrr�_testfunc_fileobjs����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)Nr2r�rHrJzr:*�r|*)rr�rr�rr)rZtestfuncrrr�_test_modes(s$����zDetectReadTest._test_modescC�|�|j�dSr)r]rYrrrr�test_detect_file8rzzDetectReadTest.test_detect_filecCr^r)r]r[rrrr�test_detect_fileobj;rzz"DetectReadTest.test_detect_fileobjN)rrrrYr[r]r_r`rrrrrWs	rWc@r�)�GzipDetectReadTestNr�rrrrra>r�rac@r?)�Bz2DetectReadTestcCs|ttd��}|��}Wd�n1swYtjtddd��
}|�|�Wd�n1s1wY|�td�dS)Nr[r�r\��
compresslevelr\)rrrAr(r*r�r�rYrorrr�test_detect_stream_bz2Bs
��z(Bz2DetectReadTest.test_detect_stream_bz2N)rrrrerrrrrbArErbc@r�)�LzmaDetectReadTestNr�rrrrrfPr�rfc@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 %sr�r�i��uidrk�gidzold-v7rr��gnamezwrong value in %s field of %s)r7r@rBr
rArq�itemsr�)rrG�chksum�kwargsr��k�vrrr�_test_memberVs"��
��zMemberReadTest._test_membercC� |j�d�}|j|dtd�dS)Nr=�c�rDrm�r7r?rqrEr�rrr�test_find_regtypeg�z MemberReadTest.test_find_regtypecCrr)Nzustar/conttypersrtrur�rrr�test_find_conttypekrwz!MemberReadTest.test_find_conttypecC�|j�d�}|j|dd�dS)Nr#r�rD�r7r?rqr�rrr�test_find_dirtypeo�z MemberReadTest.test_find_dirtypecCry)Nzustar/dirtype-with-size�rzr{r�rrr�test_find_dirtype_with_sizesr}z*MemberReadTest.test_find_dirtype_with_sizecC� |j�d�}|j|ddd�dS)Nrwrr=�rD�linknamer{r�rrr�test_find_lnktypewrwz MemberReadTest.test_find_lnktypecCr�)Nrrrrr�r{r�rrr�test_find_symtype{rwz MemberReadTest.test_find_symtypecCs"|j�d�}|j|dddd�dS)Nz
ustar/blktyper��rD�devmajor�devminorr{r�rrr�test_find_blktype�z MemberReadTest.test_find_blktypecCs"|j�d�}|j|dddd�dS)Nz
ustar/chrtyperr\r�r�r{r�rrr�test_find_chrtype�r�z MemberReadTest.test_find_chrtypecCry)Nzustar/fifotyperrzr{r�rrr�test_find_fifotype�r}z!MemberReadTest.test_find_fifotypecCrr)Nzustar/sparse�Prt�r7r?rq�
sha256_sparser�rrr�test_find_sparse�rwzMemberReadTest.test_find_sparsecCrr)N�
gnu/sparser�rtr�r�rrr�test_find_gnusparse�rwz"MemberReadTest.test_find_gnusparsecCrr)N�gnu/sparse-0.0r�rtr�r�rrr�test_find_gnusparse_00�rwz%MemberReadTest.test_find_gnusparse_00cCrr)N�gnu/sparse-0.1r�rtr�r�rrr�test_find_gnusparse_01�rwz%MemberReadTest.test_find_gnusparse_01cCrr)N�gnu/sparse-1.0r�rtr�r�rrr�test_find_gnusparse_10�rwz%MemberReadTest.test_find_gnusparse_10cCrr)Nuustar/umlauts-ÄÖÜäöüßrsrtrur�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�r7r�)rrqrrr�test_find_ustar_longname�sz'MemberReadTest.test_find_ustar_longnamecCrr)Nzmisc/regtype-old-v7rsrtrur�rrr�test_find_regtype_oldv7�rwz&MemberReadTest.test_find_regtype_oldv7cCs@|j��tj|j|jdd�|_|j�d�}|j|dtd�dS)Nr3r4upax/umlauts-ÄÖÜäöüßrsrt)	r7r9rrrrr?rqrEr�rrr�test_find_pax_umlauts�s
�z$MemberReadTest.test_find_pax_umlautsr)rrrrqrvrxr|rr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrgTs(
rgc@r�)
�LongnameTestcCsV|jddd}z|j�|�}Wnty|�d�Ynw|�|jtjd�dS)N�/��123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/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)	�subdirr7r?r�rn�assertNotEqualr�rr�)rr�rGrrr�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�r7r?r�rnrBr�)rr�r�rGrrr�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�r7r?r�r�rbrr�rAr�rr�r)rr�rGr�rHrrr�test_truncated_longname�s"�z$LongnameTest.test_truncated_longnamecCs�|jddd}|j�|�j}ttd��!}|�|�tj�	|�
d�dd�}|�|j|j
�Wd�dS1s9wYdS)Nr�r�r�r[rar3�strict)r�r7r?r�rrrbrr�ZfrombufrArBr��longnametype)rr�r�rHrGrrr�test_header_offset�s
�"�zLongnameTest.test_header_offsetN)rrrr�r�r�r�rrrrr��s

		r�c@sJeZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zedd
��Z
dS)�GNUReadTestZgnucCs�|j�|t�tj�t|�}t|d��}|��}Wd�n1s"wY|�t	|�t
d|�|��rGt�|�}|�
|jd|j�dSdS)Nr[rhra)r7rMrNrOrPrQrrArBr
r��_fs_supports_holesrZ
assertLess�	st_blocks�st_size)rrq�filenamerHr
rfrrr�_test_sparse_file�s
��
�zGNUReadTest._test_sparse_filecCrA)Nr��r�rrrr�test_sparse_file_old�r;z GNUReadTest.test_sparse_file_oldcCrA)Nr�r�rrrr�test_sparse_file_00�r;zGNUReadTest.test_sparse_file_00cCrA)Nr�r�rrrr�test_sparse_file_01�r;zGNUReadTest.test_sparse_file_01cCrA)Nr�r�rrrr�test_sparse_file_10r;zGNUReadTest.test_sparse_file_10cCs�tj�d�rBtj�td�}t|d��}|�d�|�	d�|�
�Wd�n1s+wYt�|�}t�
|�|jd|jkSdS)N�linuxzsparse-testr�isxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxraF)r�rr�rOrPrQrNrrbr�r�rrrr�r�)rqrHrfrrrr�s


�

zGNUReadTest._fs_supports_holesN)rrrr�r�GNUTYPE_LONGNAMEr�r�r�r�r�r��staticmethodr�rrrrr��s	r�c@s&eZdZdZejZdd�Zdd�ZdS)�PaxReadTestZpaxcCs�tjtdd�}z^|�d�}|�|jd�|�|jd�|�|j�d�d�|�d�}|�|jd	�|�|jd�|�|j�d�d�|�d
�}|�|jd�|�|jd�|�|j�d�d�W|�	�dS|�	�w)Nr3r	zpax/regtype1r��barzVENDOR.umlautsuÄÖÜäöüßzpax/regtype2rzpax/regtype3r)
rrrr?rBr�rk�pax_headers�getr9�rr7rGrrr�test_pax_global_headerss*
�
�
�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)	Nr3r	zpax/regtype4rs�{g��^�AZatime�ctime)
rrrr?rBrDrirjr�r�rr�r9r�rrr�test_pax_number_fields6s
z"PaxReadTest.test_pax_number_fieldsN)	rrrr�r�XHDTYPEr�r�r�rrrrr�s
r�c@seZdZdd�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�r�
gc_collectrB)rrHr7r
rrr�test_fileobj_no_closeJs�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�	BLOCKSIZErDr�rr�rBrCrA)rr7r�rHrrr�test_eof_markerVs
�"�zWriteTestBase.test_eof_markerN)rrrr�r�rrrrr�Fs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�r9rBr�)rrqr7r�rrr�test_100_char_namehs

�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��addr9Z
assertGreater�getsize)rr7rPrHrrr�
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�
gettarinforBrDr�r9)rr7rPrGrHrrr�test_file_size�s�
�
zWriteTest.test_file_sizec	Csttj�td�}t�|�z't�t|j�}z|�	|�}|�
|jd�W|��n|��wWt
�|�dSt
�|�w)N�	directoryr)rOrPrQrNrrrr�rr�rBrDr9r�rmdir�rrPr7rGrrr�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�)rOrPrQrNrrr9rr�rr2r3r4�return_valuer�r��append�splitrqrBrrr�)rrPr7Zmock_listdir�paths�mrrr�test_ordered_recursion�s,

��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�rBrD)rr7rPrHrGZtarinfo2rrr�test_gettarinfo_pathlike_name�s�
"�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�PermissionErrorrCrr�rr�rBrDr9rr)rr�targetrHrXr7rGrrr�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�rBrDr9rrr�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�rrrrBrqr�r�r�
change_cwdrNr9)r�dstnamer7rrr�
test_add_self�s"
�
���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)N�filter)r�r�ZbazcSs&tj�|j�dkrdSd|_d|_|S)Nr�r�r�)rOrP�basenamerqrir�)rGrrrr�
s
z%WriteTest.test_filter.<locals>.filterr3r	Z	empty_dir)�arcnamer�TrJr�r�r�)rOrPrQrNrr�create_empty_filerrr�rr�r9r��	TypeErrorrBrir�rCr�r)r�tempdirrqr�r7rGrrr�test_filters,
�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��r�rJr�)rOrPrQrNrr�rrrr�rr�r9r�rr�rBrqr��sep)rrPZcmp_path�dirr�r7r�rrr�_test_pathname*s 


 zWriteTest._test_pathnamec	Csrtj�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
�Wnty�|�d�YnwWd�n1s�wYWt
�|�t
�|�dSWt
�|�t
�|�dSt
�|�t
�|�w)NZtestsymlinksztestsymlinks.tar�sourcer�r�z
something
r�r_)rr$z&extractall failed with symlinked files)rOrPrQrNrrr�r�rr�r
�OSErrorrnrrr)rr�ZtemparchiveZsource_fileZtarget_filer�r7rrr�test_extractall_symlinksGs:
�����
�

�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�z..T)r�)r�rOrPrQr�rrrr�test_pathnamesas
 zWriteTest.test_pathnamescCs6tjdkr
|�dd�dS|�dd�|�dd�dS)NrzC:\foor�z/fooz///foo)r�rr�rrrr�test_abs_pathnamesrs
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)Nr�rJz./)rr�rNrrr�rr�r9rqr�r��rr7r�rrr�test_cwdys
��"�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)rrrr�r�rr�rr�BadFile�srZnonr*)r�rr�)
r��EOFError�RuntimeErrorrr�r�rrr�r�
PAX_FORMATr�r.)rrr�r7rr�r�test_open_nonwritable_fileobj�s���z'WriteTest.test_open_nonwritable_fileobjr�)rrrrr�r�r�r�r�r�r2r9r:rOr�rr;r�r�r�r�r�r�r�r�rrrrrr�ds.�



(
r�c@r�)�
GzipWriteTestNr�rrrrr�r�rc@r�)�Bz2WriteTestNr�rrrrr�r�rc@r�)�
LzmaWriteTestNr�rrrrr�r�rc@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�rr9�decompressorrA�
decompressr��unused_datarB�countr�)rr7ZdecrHr
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�ri�zwrong file permissions)rOrP�existsr�rrrrrrr9rrrB)rZoriginal_umaskr7rrrr�test_file_mode�s

zStreamWriteTest.test_file_mode)
rrrrr
rr2r9r�rr:rOrrrrrr	�s�r	c@r?)�GzipStreamWriteTestcCs<t�t|j���t�t�jdd�}tj	�
t�|vsJ�dS)zf
        Ensure the source directory is not included in the tar header
        per bpo-41316.
        zlatin-1r	N)rrr�rr9r�r��	read_textrOrP�dirname)r�payloadrrr� test_source_directory_not_leaked�sz4GzipStreamWriteTest.test_source_directory_not_leakedN)rrrrrrrrr�rErc@�eZdZerejZdSdZdS)�Bz2StreamWriteTestN)rrrr(�BZ2Decompressorr
rrrrr��rc@r)�LzmaStreamWriteTestN)rrrr.�LZMADecompressorr
rrrrr�rrc@speZdZdd�Zddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�GNUWriteTestcCst|�dd}|dS)Nrar\)rC)rrfZblocksrrr�_length�szGNUWriteTest._lengthNcCsXd}t|�tjkr|d7}||�|�7}|dur*t|�tjkr*|d7}||�|�7}|S)Nra)rCr�LENGTH_NAMEr�LENGTH_LINK)rrqrr
rrr�
_calc_size�szGNUWriteTest._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��LNKTYPEr�rr��
GNU_FORMATrr�r"r�rBr9r�rMrq)rrqrrGr7rPrQ�memberrrr�_test�s2


���zGNUWriteTest._testcCrA)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_1023r;zGNUWriteTest.test_longname_1023cCrA)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_1024r;zGNUWriteTest.test_longname_1024cCrA)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_1025r;zGNUWriteTest.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_1023rzzGNUWriteTest.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_1024rzzGNUWriteTest.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'r.r(rrrr�test_longnamelink_1023%r~z#GNUWriteTest.test_longnamelink_1023cCrv)Nr*r0r(rrrr�test_longnamelink_1024)r~z#GNUWriteTest.test_longnamelink_1024cCrv)Nr,r2r(rrrr�test_longnamelink_1025-r~z#GNUWriteTest.test_longnamelink_1025r)rrrrr"r&r)r+r-r/r1r3r4r5r6rrrrr�s

rc@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)rOrPrQrNrrrr�rr��BLKTYPEr��REGTYPEr�r9r?rBr�r�rAr�Zoffset_data�slicerr)rr�r7Z	input_blkZ	input_regZ
output_blkZ
output_regZinfilerJZbuf_blkZbuf_regZdevice_headersrrr�*test_headers_written_only_for_device_files6s<



�
z;DeviceHeaderTest.test_headers_written_only_for_device_filesN)rrrrr;rrrrr72sr7c@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r8fr;zCreateTest.setUpcCs<t|jd��}|�d�Wd�dS1swYdS)Nr�r�)r�	file_pathr�)�clsrHrrr�
setUpClassis"�zCreateTest.setUpClasscCst�|j�dSr)rrr>)r?rrr�
tearDownClassnszCreateTest.tearDownClasscCs�t�t|j��}|�|j�Wd�n1swY|�t��}|��}Wd�n1s1wY|�t	|�d�|�
d|d�dS�Nr\r=r)rrr�rr�r>rr�rBrCr��r�tobj�namesrrr�test_creaters�
�zCreateTest.test_createcCs�t�t|j��}|�|j�Wd�n1swY|�t��t�t|j�}Wd�n1s4wY|�t��}|�	�}Wd�n1sMwY|�
t|�d�|�d|d�dSrB)
rrr�rr�r>r��FileExistsErrorrr�rBrCr�rCrrr�test_create_existing{s��
�zCreateTest.test_create_existingcCs�|�td��}|�|j�Wd�n1swY|�t��}|��}Wd�n1s0wY|�t|�d�|�d|d�dS�N�xr\r=r)rr�r�r>r�rBrCr�rCrrr�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�dSrI)
rr�r�r>r�rGr�rBrCr�rCrrr�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�dSrB)rrr�r�r�rr�rqr�rBrOrPr�r�r>r�rCr�rrCrrr�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�dSrI)rr�r�r�r�rqr�rBrOrPr�r�r>r�rCr�rCrrr�!test_create_taropen_pathlike_name�s
�
�z,CreateTest.test_create_taropen_pathlike_nameN)rrrrrOrPrQrNr>r8�classmethodr@rArFrHrKrLrMrNrrrrr<`s

		
r<c@r?)�GzipCreateTestcC�ttjt|jdd��}|�|j�Wd�n1swYtjtddd��	}Wd�dS1s3wYdS)Nr\rczr:gz�rrr�rr�r>�rrDrrr�test_create_with_compresslevel���"�z-GzipCreateTest.test_create_with_compresslevelN�rrrrTrrrrrP��rPc@r?)�
Bz2CreateTestcCrQ)Nr\rc�r:bz2rRrSrrrrT�rUz,Bz2CreateTest.test_create_with_compresslevelNrVrrrrrX�rWrXc@r?)�LzmaCreateTestcCsDtjt|jdd��}|�|j�Wd�dS1swYdS)Nr\)�presetrRrSrrr�test_create_with_preset�s"�z&LzmaCreateTest.test_create_with_presetN)rrrr\rrrrrZ�srZc@seZdZdZdZdZdS)�CreateWithXModeTestrJN)rrrrrKrLrrrrr]�sr]rrc@rV)�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�rCrr�r7r�)rrHrXrrrr8�s���zHardlinkTest.setUpcCs&|j��t�|j�t�|j�dSr)r7r9rrr�r�rrrrr:�s
zHardlinkTest.tearDowncC�$|j�|j�}|�|jtjd�dS)Nzadd file as regular failed)r7r�r�rBr�rr9r�rrr�test_add_twice�s�zHardlinkTest.test_add_twicecCr`)Nzadd file as hardlink failed)r7r�r�rBr�rr#r�rrr�test_add_hardlink�s�zHardlinkTest.test_add_hardlinkcCs,d|j_|j�|j�}|�|jtjd�dS)NTzdereferencing hardlink failed)r7Zdereferencer�r�rBr�rr9r�rrr�test_dereference_hardlinks
�z&HardlinkTest.test_dereference_hardlinkN)rrrr8r:rarbrcrrrrr^�sr^c@s&eZdZddd�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��rrzPAX longlink creation failedzPAX longname creation failed)
rr�r�r#r�rr�rr�r9r�rBrq)rrqrrGr7�l�nrrrr&
s$

�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�rir�rjrir�)rr�r3r	rz"unable to convert pax header field)rrr�rr�r�r9rBr�r�rlZassertIsNotr�r��PAX_NUMBER_FIELDSr�r�rn)rr�r7�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)rPrir�r3�rr5riir	rr�)rrr�rr�rqrir�r�r9r�rB)rr�r7r�rrr�test_pax_extended_headerBs$
�z%PaxWriteTest.test_pax_extended_headerr)rrrr&rnrprrrrrds
 rdc@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�UnicodeTestcCrA)Nr3��_test_unicode_filenamerrrr�test_iso8859_1_filename^r;z#UnicodeTest.test_iso8859_1_filenamecCrA)N�utf7rrrrrr�test_utf7_filenamear;zUnicodeTest.test_utf7_filenamecCrA)N�utf-8rrrrrr�test_utf8_filenamedr;zUnicodeTest.test_utf8_filenamecCs�tjtd|j|dd�}zd}|�t�|��W|��n|��wtjt|d�}z|�|��dj	|�W|��dS|��w)Nr�r��rr5�errorsrir	r)
rrr�rr�r�r9rBr�rq)rr5r7rqrrrrsgs�z"UnicodeTest._test_unicode_filenamecCsjtjtd|jddd�}z$t��}d|_|�t|j|�d|_d|_	|�t|j|�W|�
�dS|�
�w)Nr�r�r�ryrir�)rrr�rr�rqr��UnicodeErrorr�r�r9r�rrr�test_unicode_filename_errorvs�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)NrJr3r��r5rz)rrrZassertIsr�rqr�r�r�rkr9r�rrr�test_unicode_argument�s��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�rir�r3)rrr5r	r�u	���)rr�r�rkrr�rr�r9r?rBr)rr�r7rrr�test_uname_unicode�s.
�

�zUnicodeTest.test_uname_unicodeN)
rrrrtrvrxrsr|r~rrrrrrq\srqc@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_namer�rrrr�test_unicode_name1��

z#UstarUnicodeTest.test_unicode_name1cC�|�d�|�dt�dS�Nud012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿue0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr�rrrr�test_unicode_name2��
z#UstarUnicodeTest.test_unicode_name2cCr�)Na01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123/40123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r�rrrr�test_unicode_longname1�r�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_longname4�r�z'UstarUnicodeTest.test_unicode_longname4NcCs�tjtd|jdd��}t�|�}|dur|�|�n|�||j|�Wd�n1s,wY|durdtjtddd��}|D]}|�||j�Wd�dSWd�dS1s]wYdSdS)Nr�rwrorJr	)	rrr�rr�r�r�rBrq�rrq�excr7r�rrrr��s 
���"��z!UstarUnicodeTest._test_ustar_namecCr�r���_test_ustar_linkr�rrrr�test_unicode_link1�r�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�rwror�rJr	)	rrr�rr�r�r�r�rBr�rrrr��s"
���"��z!UstarUnicodeTest._test_ustar_linkr)rrrr�USTAR_FORMATrr�r�r�r�r�r�r�r�r�r�rrrrr��s
r�c@seZdZejZdd�ZdS)�GNUUnicodeTestc
C�ndD]2\}}tjt|dd��}z|�|�}Wnty$|�d�YnwWd�n1s/wYqdS)N))rwupax/bad-pax-���)r3upax/bad-pax-äöür�r}z%unable to read bad GNU tar pax header�rrrr?r�rn�rr5rqr7r�rrr�test_bad_pax_headers������z"GNUUnicodeTest.test_bad_pax_headerN)rrrrr$rr�rrrrr��sr�c@seZdZejZdZdd�ZdS)�PAXUnicodeTestNc
Cr�)N))rwupax/hdrcharset-���)r3upax/hdrcharset-äöür�r}z)unable to read POSIX.1-2008 binary headerr�r�rrr�test_binary_headers������z!PAXUnicodeTest.test_binary_header)rrrrrrr|r�rrrrr�sr�c@s&eZdZdd�Zd	dd�Zdd�ZdS)
�AppendTestBasecCs(t|_tj�|j�rt�|j�dSdSr)r�rrOrPrrrrrrrr8%s�zAppendTestBase.setUpr�c
Cs�tjtdd��K}|�d�}d|_|�|��%}t�|j|��}|�||�Wd�n1s.wYWd�n1s=wYWd�dSWd�dS1sUwYdS)Nr3r	r=r�)rrrr?rqr@r�)rr�srcr�r�r7rrr�_create_testtar*s
����"�zAppendTestBase._create_testtarcCs(|�d|j�|�tjtjtd�dS)Nr�rs)r�rr�rr�rr�rrrr�test_append_compressed2sz%AppendTestBase.test_append_compressedN)r�)rrrr8r�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)NrsrZr�)rrrr�r�)rr�r7rrr�
_add_testfile9s"�zAppendTest._add_testfiler�cCsFtj|j|d��}|�|��|�Wd�dS1swYdS)NrZ)rrrrBr�)rrEr�r7rrrr&=s"�zAppendTest._testcCs|��|��dSr)r�r&rrrr�test_non_existingAszAppendTest.test_non_existingcCs&t�|jd���|��|��dS)Nr�)rrrr9r�r&rrrr�
test_emptyEszAppendTest.test_emptycCs.t�d�}|�|�|�d�|j|d�dS)NsrrZ)rr�r�rbr&r�rrr�test_empty_fileobjJs


zAppendTest.test_empty_fileobjcCsp|��t|jd��}|��}Wd�n1swYt�|�}|�|�|�d�|jddg|d�dS)Nr[rr�r�)rEr�)	r�rrrArr�r�rbr&rorrr�test_fileobjPs
�


zAppendTest.test_fileobjcCs$|��|��|jddgd�dS)Nr�r�)rE)r�r�r&rrrr�
test_existingYszAppendTest.test_existingcCsJt|jd��
}|�|�Wd�n1swY|�tj|j�dSr�)rrr�r�rr�r�)rr
rHrrr�_test_error`s�zAppendTest._test_errorcCrA)Nr`�r�rrrr�	test_nuller;zAppendTest.test_nullcCrA)N�
r�rrrr�test_incompletehr;zAppendTest.test_incompletecCst�d���}|�|�dS)Nr��rr�r�r�r�rrr�test_premature_eofkszAppendTest.test_premature_eofcCs t�d���}|�|d�dS)Nr�r�r�r�rrr�test_trailing_garbageosz AppendTest.test_trailing_garbagecCrA)Nsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar�rrrr�test_invalidsr;zAppendTest.test_invalidr)rrrr�r�r&r�r�r�r�r�r�r�r�r�r�r�rrrrr�6s
	r�c@r�)�GzipAppendTestNr�rrrrr�vr�r�c@r�)�
Bz2AppendTestNr�rrrrr�yr�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�r�r�rir�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�rir�r�r�rrr�test_gnu_limits�s


zLimitsTest.test_gnu_limitscCsRt�d�}|�tj�t�d�}d|_|�tj�t�d�}d|_|�tj�dSr�)rr�r�rr�rir�rrr�test_pax_limits�s


zLimitsTest.test_pax_limitsN)rrrr�r�r�rrrrr��s
r�c@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MiscTestcCs`|�t�dddd�d�|�t�dddd�d�|�t�ddd�d�|�t�d	dd�d�dS)
Nr��r�r�sfooZfoobarr�r_sfoobar)rBr�stn�ntsrrrr�test_char_fields�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       )rBr�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�rer�r�r�rr�r�r�r�r�gY�g0Bs�g��������r)rBr�itnr$r�rrrr�test_write_number_fields�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�r�rr�r�r$rrrr�test_number_field_limits�s���"�z!MiscTest.test_number_field_limitscCshd�}tj|t|d�dS)N>/�grpZExFileObjectr!�copyfileobjr��filemoder ZEOFHeaderErrorr9r�r�Z	GNU_MAGICZSYMTYPEZcalc_chksumsZGNUTYPE_SPARSEZGNUTYPE_LONGLINKZAREGTYPEZFIFOTYPEZCHRTYPEr�ZEmptyHeaderError�pwdr8ZCONTTYPEZ
PAX_FIELDSZsymlink_exceptionZ
LENGTH_PREFIXr�ZSubsequentHeaderErrorr��mainZPAX_NAME_FIELDSZSOLARIS_XHDTYPEr��versionZXGLTYPEZ
REGULAR_TYPESrk�NULZSUPPORTED_TYPESZPOSIX_MAGICZInvalidHeaderErrorZ	GNU_TYPESr�ZTruncatedHeaderErrorr�r#)�not_exported)rZcheck__all__r)rr�rrr�test__all__�szMiscTest.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 availabler0)r7z?
- method xz: CompressionError('lzma module is not available')
)rOrPrQr�__file__r�rr�ZCompressionErrorr2r3r4r+rrr�r��	exception)r�fname�excinfor6rrr�.test_useful_error_message_when_modules_missing	s����z7MiscTest.test_useful_error_message_when_modules_missingN)	rrrr�r�r�r�r�r�rrrrr��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'S)(�CommandLineTestcOs2tjddg|�Ri|��\}}}|�tj��d�S)N�-mr�
)rZassert_python_okr�rO�lineseprl)r�argsrn�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||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr`susageserrorsrequired�-lr)r�rBr��lowerr��strip)rr�r�r�rrr�test_bad_use+	szCommandLineTest.test_bad_usecCs0tD]}dD]}|�||�}|�|d�qqdS)N)�-tz--testr`)�testtarnamesr�rB�rr��optr�rrr�test_test_command5	s��z!CommandLineTest.test_test_commandcCs6tD]}dD]}|j|d|dd�}|�d|�qqdS)N�z-vz	--verboser�rw��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.zipr�� is not a tar archive.r`r\)r�r[r�r)
rr�r�r�rBr�ZsubTestrrAr�r�rr)r�zipnamer�r�r�r�r�r
rrr�test_test_command_invalid_fileB	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�)r�z--listr��
r�rZcaptured_stdoutrrrYr�rlr�rB�rr�r�r�Zexpectedr�r�rrr�test_list_commandV	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�r�r�rrrrr�test_list_command_verbosea	s
���
���z)CommandLineTest.test_list_command_verbosecCsDt�d�}|�d|�\}}}|�d|�|�|d�|�|d�dS)Nr�r�rr`r\)rr�r�r�rB�rrr�r�r�rrr�test_list_command_invalid_filel	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�rBrrr�rr�rr�r�r�r7rrr�test_create_commands	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�r	r�rws file created.)
rr�r�r�r�rrr�rrr
rrr�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�r	r`)
rr�r��dotlessnamerBrrr�rr)rr�r�r7rrr�$test_create_command_dotless_filename�	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�r	r`)
rOrPrQrNrr�r�rBrrr�rr)rr�r�r�r7rrr�(test_create_command_dot_started_filename�	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�r�r	)
rr�r"r'r+rr�rr�rr�rr)rr�Zfiletyper�r�r7rrr�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`�r�r�r�temp_cwd�	tarextdirr�rBr�rr�r�rrr�test_extract_command�	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�rrwr�s file is extracted.)r�r�rrrr�r�rrrrr�test_extract_command_verbose�	s

���z,CommandLineTest.test_extract_command_verbosec	Csl|�t�z*t�t��|�dtd�}Wd�n1swY|�|d�Wt�t�dSt�t�w)NrZspamdirr`r)rr�rrr�(test_extract_command_different_directory�	s
�z8CommandLineTest.test_extract_command_different_directorycCsnt�d�}t�t��|�d|�\}}}Wd�n1swY|�d|�|�|d�|�|d�dS)Nr�rrr`r\)rr�rrrr�r�rBrrrr�!test_extract_command_invalid_file�	s
�z1CommandLineTest.test_extract_command_invalid_fileN)rrrr�r�r�r�r�r�rrrrrrrrrrrrrrrrrr�	s(	



	r�c@r�)�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)rrrr9r�r�r�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 managerr)
r��	Exceptionrrrr�r�r�r�r.)rr�r7rrr�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 blockr)
rrr�rrBrOrPr�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 closedr)rr�rrr�r.r�r�rrrr�
s�"�zContextManagerTest.test_fileobjN)	rrrrrrr r!r�rrrrr�	s		rzrequires 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)�LinkEmulationTestcCs^|j�|t�ttj�t|�d��}|��}Wd�n1s wY|�t	|�t
�dSr�)r7rMrNrrOrPrQrArBr
rE)rrqr�r
rrr�_test_link_extraction
s

�z'LinkEmulationTest._test_link_extraction�islinkz3Skip emulation - has os.path.islink but not os.linkcCrA)Nrw�r#rrrr�test_hardlink_extraction1 
�z+LinkEmulationTest.test_hardlink_extraction1cCrA)Nr{r%rrrr�test_hardlink_extraction2%
r'z+LinkEmulationTest.test_hardlink_extraction2r�z Skip emulation if symlink existscCrA)Nrr%rrrr�test_symlink_extraction1*
r'z*LinkEmulationTest.test_symlink_extraction1cCrA)Nr�r%rrrr�test_symlink_extraction2/
r'z*LinkEmulationTest.test_symlink_extraction2N)
rrrr#r2r<r:rOrPr&r(r)r*rrrrr"
s$�
�
�
�r"c@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�AssertionErrorrcrCr��superrA)rrg��	MyBytesIO�	__class__rrrA<
sz>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.readcsd|_t�|�j|�Sr�)r,r.rbr�r/rrrbB
sz>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek)rrrr,rArb�
__classcell__r�r0)r1rr0:
sr0r�r\r�)rr�r(�compressrr�r��rangerCrr�)rrr
rJrr3r�_test_partial_input9
s��z&Bz2PartialReadTest._test_partial_inputcCrA)NrJ�r6rrrr�test_partial_inputM
r;z%Bz2PartialReadTest.test_partial_inputcCrA)NrYr7rrrr�test_partial_input_bz2P
r;z)Bz2PartialReadTest.test_partial_input_bz2N)rrrr6r8r9rrrrr+5
sr+cCsZz
ddl}ddl}Wn
tyYdSw|�d�ddkr dS|�d�ddkr+dSdS)NrF�rootT)r�r��ImportError�getpwuid�getgrgid)r�r�rrr�root_is_uid_gid_0T
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�rr9r�rr�r�rirjr�rkr�r�)�
filename_1�	dirname_1�
filename_2rHrl�tarflrqrirj�typ�contentsr�rrr�_make_test_archivei
s&
�
�
��z#NumericOwnerTest._make_test_archiveccsr�d|_d}d}|}|}tj�||�}t�|||�}t�|��}||||fVWd�dS1s2wYdS)Nrznumeric-owner-testfiler�)r�rOrPrQrArNrr)�mock_geteuidr�rrHrIrJZtar_filenamerKrrr�_setup_test�
s��"�zNumericOwnerTest._setup_testzos.chownzos.chmodz
os.geteuidc
Cs�|�|��\}}}}|j|tdd�|j|tdd�Wd�n1s$wYtj�t|�}tj�t|�}	|jtj�	|dd�tj�	|	dd�gdd�dS)NT�Z
numeric_ownerrBrCrFrG�Z	any_order)
rPrMrNrOrPrQ�assert_has_callsr2r3�call)
rrO�
mock_chmod�
mock_chownrKrH�_rJ�f_filename_1�f_filename_2rrr�test_extract_with_numeric_owner�
s��
�z0NumericOwnerTest.test_extract_with_numeric_ownercCs�|�|��\}}}}|jtdd�Wd�n1swYtj�t|�}tj�t|�}	tj�t|�}
|jtj�	|dd�tj�	|	dd�tj�	|
dd�gdd	�dS)
NTrQrBrCrDrErFrGrR)
rPr
rNrOrPrQrSr2r3rT)rrOrUrVrKrHrIrJrXZf_dirname_1rYrrr�"test_extractall_with_numeric_owner�
s��
�z3NumericOwnerTest.test_extractall_with_numeric_ownerz uid=0,gid=0 must be named "root"cCsb|�|��\}}}}|j|tdd�Wd�n1swYtj�t|�}|�|dd�dS)NFrQr)rPrMrNrOrPrQZassert_called_with)rrOrUrVrKrHrWrXrrr�"test_extract_without_numeric_owner�
s
�z3NumericOwnerTest.test_extract_without_numeric_ownerc	CsN|�|��\}}}}|�t|j|tdd�Wd�dS1s wYdS)NFT)rPr�r�rMrN)rrOrKrHrWrrr�test_keyword_only�
s
�"�z"NumericOwnerTest.test_keyword_onlyN)rrrr�rNrrPr2r3r4rZr[r9r>r\r]rrrrrA`
s.	






�




rAc	Cs�t�t�t�t�tgattd��}|��}Wd�n1s!wYt	t
tfD]-}|jrXt�|j�t�|j�|�|jd��
}|�
|�Wd�n1sSwYq+dS)Nr[r�)rrrNrO�makedirsrr�rrAr"r'r+r�r�)rHr
�cr7rrr�setUpModule�
s


����r`cCstj�t�r
t�t�dSdSr)rOrPrrNrrrrrr�tearDownModule�
s�ra�__main__)tr�rOrZhashlibr�
contextlibr�randomrr�r2Z
unittest.mockrrjrZtest.supportrrr%r;r5r(r.r
rPr�ZTESTFNrNrr�rrQr$r)r-r�r
rEr�rZ
requires_gzipr"Zrequires_bz2r'Z
requires_lzmar+r1ZTestCaser<r�r�r�r�r�r�r�r�r�r=r>r@rFrGrSrTrUrWrarbrfrgr�r�r�r�r�rrrr	rrrrr7r<rPrXrZr]r9r:r^rdrqr�r�r�r�r�r�r�r�r�r�r�rr<r"r+r>rAr`rarr�rrrr�<module>s����
��
|Pw=(a*;,9'R.Z			*TQO@;]B:!v
�
© 2025 GrazzMean