Your IP : 216.73.217.32


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_tarfile.cpython-35.opt-1.pyc



��Yfn�@s�ddlZddlZddlZddlmZddlmZddlmZddl	Z	ddl
Z	ddlZddlm
Z
ddlmZyddlZWnek
r�dZYnXyddlZWnek
r�dZYnXyddlZWnek
rdZYnXdd�Zejje
j�d	Zed
Ze
jd�Zejjed�Zejjed
�Zejjed�Zejjed�Z ejjed�Z!dZ"dZ#Gdd�d�Z$e
j%Gdd�d��Z&e
j'Gdd�d��Z(e
j)Gdd�d��Z*Gdd�de$�Z+Gdd�de+e	j,�Z-Gdd �d e&e-�Z.Gd!d"�d"e(e-�Z/Gd#d$�d$e*e-�Z0Gd%d&�d&e+e	j,�Z1Gd'd(�d(e&e1�Z2Gd)d*�d*e(e1�Z3Gd+d,�d,e*e1�Z4Gd-d.�d.e+�Z5Gd/d0�d0e5�Z6Gd1d2�d2e6e	j,�Z7Gd3d4�d4e&e6e	j,�Z8Gd5d6�d6e(e6e	j,�Z9Gd7d8�d8e*e6e	j,�Z:Gd9d:�d:e5e	j,�Z;Gd;d<�d<e&e;�Z<Gd=d>�d>e(e;�Z=Gd?d@�d@e*e;�Z>GdAdB�dBe$e	j,�Z?GdCdD�dDe&e?�Z@GdEdF�dFe(e?�ZAGdGdH�dHe*e?�ZBGdIdJ�dJe+e	j,�ZCGdKdL�dL�ZDGdMdN�dNeDe+e	j,�ZEGdOdP�dPeDe+e	j,�ZFGdQdR�dRe$�ZGGdSdT�dTeGe	j,�ZHGdUdV�dVe&eH�ZIGdWdX�dXe(eH�ZJGdYdZ�dZe*eH�ZKGd[d\�d\eGe	j,�ZLGd]d^�d^e&eL�ZMGd_d`�d`e(eL�ZNGdadb�dbe*eL�ZOGdcdd�dde	j,�ZPGdedf�dfeGe	j,�ZQGdgdh�dhe&eQ�ZRGdidj�dje(eQ�ZSGdkdl�dle*eQ�ZTGdmdn�dneQ�ZUe	jVeWedo�dp�Gdqdr�dre	j,��ZXGdsdt�dteP�ZYGdudv�dv�ZZGdwdx�dxeZe	j,�Z[Gdydz�dzeZe	j,�Z\Gd{d|�d|eZe	j,�Z]Gd}d~�d~�Z^Gdd��d�e^e	j,�Z_Gd�d��d�e&e^e	j,�Z`Gd�d��d�e(e^e	j,�ZaGd�d��d�e*e^e	j,�ZbGd�d��d�e	j,�ZcGd�d��d�e	j,�ZdGd�d��d�e	j,�ZeGd�d��d�e	j,�Zfe	jgeWedo�d��Gd�d��d�e+e	j,��ZhGd�d��d�e(e	j,�Zid�d��Zje	jVeWed��d��e	jVeWed��d��Gd�d��d�e	j,���Zkd�d��Zld�d��Zmend�kr�e	jo�dS)��N)�md5)�contextmanager)�Random)�support)�
script_helpercCst|�j�S)N)rZ	hexdigest)�data�r�6/opt/alt/python35/lib64/python3.5/test/test_tarfile.py�md5sumsr
z-tardirz
-extract-testztesttar.tarztesttar.tar.gzztesttar.tar.bz2ztesttar.tar.xzztmp.tarZtesttarZ 65f477c818ad9e15f7feab0c6d37742fZ a54fbc4ca4f4399a90e1b27164012fc6c@sCeZdZeZdZejZej	j
Z
edd��ZdS)�TarTest�cCs|j|jS)N)�prefix�suffix)�selfrrr	�mode3szTarTest.modeN)
�__name__�
__module__�__qualname__�tarnamer�io�FileIO�open�tarfile�TarFile�taropen�propertyrrrrr	r-s
	rc@s=eZdZeZdZer'ejndZe	j
jZdS)�GzipTestZgzN)
rrr�gzipnamerr�gzipZGzipFilerrrZgzopenrrrrr	r7src@s=eZdZeZdZer'ejndZe	j
jZdS)�Bz2Test�bz2N)
rrr�bz2namerrr �BZ2FilerrrZbz2openrrrrr	r>src@s=eZdZeZdZer'ejndZe	j
jZdS)�LzmaTestZxzN)
rrr�xznamerr�lzmaZLZMAFilerrrZxzopenrrrrr	r#Esr#c@s.eZdZdZdd�Zdd�ZdS)�ReadTestzr:cCs(tj|jd|jdd�|_dS)Nr�encodingz	iso8859-1)rrrr�tar)rrrr	�setUpQszReadTest.setUpcCs|jj�dS)N)r(�close)rrrr	�tearDownUszReadTest.tearDownN)rrrr
r)r+rrrr	r&Msr&c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
UstarReadTestcCss|jjd�}|jj|��H}|j�}|jt|�|jd�|jt|�td�WdQRXdS)Nz
ustar/regtypezregular file extraction failed)	r(�	getmember�extractfile�read�assertEqual�len�sizer
�md5_regtype)r�tarinfo�fobjrrrr	�test_fileobj_regular_file[sz'UstarReadTest.test_fileobj_regular_filecCs�|jjdt�|jjd�}ttjjtd�d��}|j�}WdQRX|jj	|��e}t
j|�}|j�}|j||d�|jt
|�dd�|j|ddd�WdQRXdS)Nz
ustar/regtype�rzfileobj.readlines() failed�r�SzOI will gladly admit that Python is not the fastest running scripting language.
)r(�extract�TEMPDIRr-r�os�path�join�	readlinesr.r�
TextIOWrapperr0r1)rr4�fobj1�lines1r5�fobj2�lines2rrr	�test_fileobj_readlinesds!
z$UstarReadTest.test_fileobj_readlinescCs�|jjdt�|jjd�}ttjjtd�d��}|j�}WdQRX|jj	|��/}t
tj|��}|j
||d�WdQRXdS)Nz
ustar/regtyper7zfileobj.__iter__() failed)r(r:r;r-rr<r=r>r?r.�listrr@r0)rr4rArBrCrDrrr	�test_fileobj_itervs!zUstarReadTest.test_fileobj_iterc	Cs�|jjdt�ttjjtd�d��}|j�}WdQRX|jjd�}|jj	|�}|j�}|j
d�|jd|j�d�|j
dd�|jd|j�d�|j
dd�|jd|j�d	�|j
dd�|jd|j�d
�|jd�}|j||dd�d
�|j
dd�|j|j
|j�d�|j|j�dd�|j
|j
d�|jd|j�d�|j
d�|j�}|j
d�|j�}|j||d�|j
d�|jt|j��|j�d�|j
d�|jt|j��d|j�d�|j
d�|j�}|j|j�|t|�d�d�|j�dS)Nz
ustar/regtype�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 failedizreadlines() after seek failedztell() after readline() failedz)tell() after seek() and readline() failedzread() after readline() failedi���)r(r:r;rr<r=r>r/r-r.�seekr0�tellr2r?r1�readliner*)	rr5rr4�text�s�s1�s2�linerrr	�test_fileobj_seek�s\!




"
"zUstarReadTest.test_fileobj_seekcCs�|jjd��t}tj|�}|j�jd�}|jt|�t�y|j	d�Wnt
k
r�|jd�YnXWdQRXdS)Nz
ustar/regtypez	iso8859-1�dzseeking failed in text mode)r(r.rr@r/�encoder0r
r3rM�AttributeError�fail)rr5rrrr	�test_fileobj_text�s
zUstarReadTest.test_fileobj_textcCsR|jj|��9}|jj|��}|j|j|j�WdQRXWdQRXdS)N)r(r.r0�name)rZlnktype�regtype�a�brrr	�_test_fileobj_link�sz UstarReadTest._test_fileobj_linkcCs|jdd�dS)Nz
ustar/lnktypez
ustar/regtype)r_)rrrr	�test_fileobj_link1�sz UstarReadTest.test_fileobj_link1cCs|jdd�dS)Nz./ustar/linktest2/lnktypezustar/linktest1/regtype)r_)rrrr	�test_fileobj_link2�s	z UstarReadTest.test_fileobj_link2cCs|jdd�dS)Nz
ustar/symtypez
ustar/regtype)r_)rrrr	�test_fileobj_symlink1�sz#UstarReadTest.test_fileobj_symlink1cCs|jdd�dS)Nz./ustar/linktest2/symtypezustar/linktest1/regtype)r_)rrrr	�test_fileobj_symlink2�s	z#UstarReadTest.test_fileobj_symlink2cCs|jdd�dS)NZsymtype2z
ustar/regtype)r_)rrrr	�test_issue14160�szUstarReadTest.test_issue14160N)rrrr6rErGrUrZr_r`rarbrcrdrrrr	r,Ys	
2r,c@seZdZdS)�GzipUstarReadTestN)rrrrrrr	re�srec@seZdZdS)�Bz2UstarReadTestN)rrrrrrr	rf�srfc@seZdZdS)�LzmaUstarReadTestN)rrrrrrr	rg�srgc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ListTestcCs"tj|jd|j�|_dS)Nr)rrrrr()rrrr	r)�szListTest.setUpcs�tjtj�ddd�}tjtd|���jjdd�WdQRX|j�j	�}�j
d|��j
d|��j
d	|��j
d
ddd
|��j
d|��j
d|��j
d|��j
d|��fdd�}�j
|d�|��j
|d�|��j
|d�|��j
|d�|��j
|d�|��j|d��jd|��jd|�dS)N�ascii�newline�
�stdout�verboseFsustar/conttypes
ustar/regtypes
ustar/lnktypesustars/12345�(s67/longnames./ustar/linktest2/symtypes./ustar/linktest2/lnktypesustar/dirtype/sustar/dirtype-with-size/cs(|j�jjd�}|jdd�S)N�surrogateescaperi�backslashreplace)�decoder(r'rW)r^rQ)rrr	�conv�sz 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->)
rr@�BytesIOr�	swap_attr�sysr(rF�detach�getvalue�assertIn�assertRegex�assertNotIn)r�tio�outrrr)rr	�	test_list�s.zListTest.test_listcCs�tjtj�ddd�}tjtd|��|jjdd�WdQRX|j�j	�}|j
|dd�|jd	|�|jd
|�|jd|�|jdd
ddd
dd|�|jdd
ddd
dd|�dS)NrirjrkrlrmTsX\?rw-r--r-- tarfile/tarfile\s+7011 \d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ustar/\w+type ?\r?\nrKsustar/symtype -> regtypes1./ustar/linktest2/symtype -> ../linktest1/regtypes;./ustar/linktest2/lnktype link to ./ustar/linktest1/regtypesgnus/123�}s/longlink link to gnus	/longnamespaxs/longlink link to pax)rr@rsrrtrur(rFrvrwryrx)rr{r|rrr	�test_list_verboses	"zListTest.test_list_verbosec
Cs�tjtj�ddd�}dd�}tjtd|��'|jjddd	||j��WdQRX|j�j	�}|j
d
|�|jd|�dS)Nrirjrkcss/x(|j�D]}d|jkr
|Vq
WdS)NZreg)�
getmembersr[)r(r4rrr	�members&sz+ListTest.test_list_members.<locals>.membersrlrmFr�s
ustar/regtypesustar/conttype)rr@rsrrtrur(rFrvrwrxrz)rr{r�r|rrr	�test_list_members$s)zListTest.test_list_membersN)rrrr)r}rr�rrrr	rh�s%rhc@seZdZdS)�GzipListTestN)rrrrrrr	r�1sr�c@seZdZdS)�Bz2ListTestN)rrrrrrr	r�5sr�c@seZdZdS)�LzmaListTestN)rrrrrrr	r�9sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�CommonReadTestcCs�tjt|jjdd���WdQRXzby#tjt|j�}|j�Wn"tjk
rs|jd�YnX|j|j	�g�Wd|j
�XdS)Nr7�wz&tarfile.open() failed on empty archive)rr�tmpnamer�replace�getnames�	ReadErrorrY�assertListEqualr�r*)rr(rrr	�test_empty_tarfile?s"z!CommonReadTest.test_empty_tarfilec
Cs1|jtd��tjd|j�WdQRXdS)NZxxx)�assertRaisesRegex�FileNotFoundErrorrrr)rrrr	�test_non_existent_tarfilePsz(CommonReadTest.test_non_existent_tarfilecCsSttd��WdQRX|jtjtjt|j�|jtjtjt�dS)N�wb)rr��assertRaisesrr�r)rrrr	�test_null_tarfileVsz CommonReadTest.test_null_tarfilecCs�td�jd�jdd�}x�dD]�}|jtd��V}|j|d�tjd	�}t|�|_	|j|j
��|j|�WdQRXtjtd
ddd
�}z$|j|j�d	gd|�Wd|j
�Xq(WdS)Nri�Zbig��ar�i�foorr7Zignore_zerosTz3ignore_zeros=True should have skipped the %r-blocksi)r�r�)rZgetrandbits�to_bytesrr��writer�TarInfor1r2�tobufr�r�r*)rr�charr5r4r(rrr	�test_ignore_zeros_s!
z CommonReadTest.test_ignore_zerosc4CsUxNd
D]F}tjtd��<}tjd�}d|_|j|tjdd��WdQRXttd��}|j|�WdQRXtjt��5}|j	tj
d	��x|D]}q�WWdQRXWdQRXtjt��p}|j�}|j	tj
d	��|j|t
�WdQRX|j	tj
d	��|j|�j�WdQRXWdQRXqWdS)N��X��zw:r�r�zr+bzunexpected end of data)r�r�r�r�)rrr�r�r2�addfilerrs�truncater�r��nextr:r;r.r/)rr2r(�tr5rrr	�test_premature_end_of_archiveus"
	$
z,CommonReadTest.test_premature_end_of_archiveN)rrrr�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�Zejeed�d�ejdd���Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)(�MiscReadTestBasecCsdS)Nr)rrrr	�requires_name_attribute�sz(MiscReadTestBase.requires_name_attributecCs�|j�t|jd��t}|j|jt�tjd|d|j��<}|j|jt�|j|jt	j
j|j��WdQRXWdQRXdS)NrH�fileobjr)r�rr�assertIsInstancer[�strrrr0r<r=�abspath)rr5r(rrr	�test_no_name_argument�s
z&MiscReadTestBase.test_no_name_argumentcCs|t|jd��}|j�}WdQRXtj|�}|jtt|d�tjd|d|j	�}|j
|j�dS)NrHr[r�r)rrr/rrsr�rX�getattrrr�assertIsNoner[)rr5rr(rrr	�test_no_name_attribute�sz'MiscReadTestBase.test_no_name_attributecCsyt|jd��}|j�}WdQRXtj|�}d|_tjd|d|j��}|j|j�WdQRXdS)NrHrr�r)	rrr/rrsr[rrr�)rr5rr(rrr	�test_empty_name_attribute�s	z*MiscReadTestBase.test_empty_name_attributecCs}tj|jtj�}t|d��O}|j|jt�tjd|d|j��}|j	|j�WdQRXWdQRXdS)NrHr�r)
r<rr�O_RDONLYr�r[�intrrr�)r�fdr5r(rrr	�test_int_name_attribute�s
z(MiscReadTestBase.test_int_name_attributecCs�|j�tj|j�}t|d��t}|j|jt�tjd|d|j	��<}|j|jt�|j
|jtjj|j��WdQRXWdQRXdS)NrHr�r)
r�r<�fsencoderrr�r[�bytesrrr0r=r�)rrr5r(rrr	�test_bytes_name_attribute�s
z*MiscReadTestBase.test_bytes_name_attributecCs�ttd��WdQRX|jtd��|jtd�}WdQRX|jtd��|jtd�}WdQRX|jtd��|jtd�}WdQRXdS)Nr�z
mode must be �qZrwr)rr�r��
ValueErrorr)rr(rrr	�test_illegal_mode_arg�sz&MiscReadTestBase.test_illegal_mode_argcCstj|jd|j�}zQ|j�|j�}|j}|j}|j|��}|j�}WdQRXWd|j	�X|j|j���}|j
|�|j|jddd|�}|j�}|j|j|�|j�|j|j|�j�|d�|j	�WdQRXdS)Nrzr:r�zseek back did not work)
rrrrr�r[�offsetr.r/r*rMr0r�)rr(r�r[r��frr5rrr	�test_fileobj_with_offset�s$
		

z)MiscReadTestBase.test_fileobj_with_offsetcCsa|jtjtjt|j�ttd��,}|jtjtjd|d|j�WdQRXdS)NrHr�r)r�rr�rrr)rr5rrr	�test_fail_comp�szMiscReadTestBase.test_fail_compcCs/|jjd�}|j|jtjd�dS)Nzmisc/dirtype-old-v7zv7 dirtype failed)r(r-r0�typer�DIRTYPE)rr4rrr	�test_v7_dirtype�sz MiscReadTestBase.test_v7_dirtypecCs:y|jjd�Wntk
r5|jd�YnXdS)Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))r(r-�KeyErrorrY)rrrr	�test_xstar_type�s
z MiscReadTestBase.test_xstar_typecCsmxf|jD][}|jt|j�dd|j�|jjd�sHq
|j|jdd|j�q
WdS)Ni��>zwrong mtime for %szustar/rzwrong uname for %s)r(r0r��mtimer[�
startswith�uname)rr4rrr	�test_check_members�sz#MiscReadTestBase.test_check_memberscCs'|j|jj�djdd�dS)NrIzmisc/eofzcould not find all members���)r0r(r�r[)rrrr	�test_find_memberssz"MiscReadTestBase.test_find_members�linkzMissing hardlink implementationcCsStjtdddd��1}|jdt�|jtjtj	j
td��|jdt�|jtjtj	j
td��ttj	j
td�d��}|j�}WdQRX|jt
|�t�|jdt�|jtjtj	j
td��ttj	j
td�d��}|j�}WdQRX|jt
|�t�WdQRXdS)	NZ
errorlevelrIr'z	iso8859-1z
ustar/regtypez
ustar/lnktyperHz
ustar/symtype)rrrr:r;�
addCleanupr�unlinkr<r=r>r/r0r
r3)rr(r�rrrr	�test_extract_hardlinks""!"!z&MiscReadTestBase.test_extract_hardlinkc	Cs4tjtdd�}tjjtd�}tj|�z�dd�|D�}|j||�x�|D]�}tjj||j	�}t
jdkr�|j|j
d@tj|�jd@�dd	�}tjj|�}d
j||j�||�|�}|j|j||�qdWWd|j�tj|�XdS)Nr'z	iso8859-1�
extractallcSs"g|]}|j�r|�qSr)�isdir)�.0r�rrr	�
<listcomp>#s	z4MiscReadTestBase.test_extractall.<locals>.<listcomp>�win32i�cSs6t|t�r%dj||j��Sdj|�SdS)Nz{} ({})z
{!r} (int))�
isinstance�float�format�hex)r�rrr	�format_mtime+sz6MiscReadTestBase.test_extractall.<locals>.format_mtimez,tar mtime {0} != file time {1} of path {2!a})rrrr<r=r>r;�mkdirr�r[ru�platformr0r�stat�st_mode�getmtimer�r�r*r�rmtree)	rr(�DIRZdirectoriesr4r=r�Z
file_mtime�errmsgrrr	�test_extractalls(

		
z MiscReadTestBase.test_extractallcCs�d}tjjtd�}tj|�z�tjtdd���}|j|�}|j	|d|�tjj||�}|j
tjj|�|j�t
jdkr�|j
tj|�jd@d�WdQRXWdtj|�XdS)	Nz
ustar/dirtypeZ
extractdirr'z	iso8859-1r=r�i�i�)r<r=r>r;r�rrrr-r:r0r�r�rur�r�r�rr�)rZdirtyper�r(r4Z	extractedrrr	�test_extract_directory:s
+z'MiscReadTestBase.test_extract_directorycCs�tjjtd�}t|d��}|jd�WdQRXz_tjtj	�}y|j
|�Wn(tjk
r�|j|j
j�YnX|jd�Wdtj|�XdS)N�emptyr�rLzReadError not raised)r<r=r>r;rr��object�__new__rr�__init__r��
assertTruer��closedrYrr�)rr�r5r(rrr	�test_init_close_fobjIsz%MiscReadTestBase.test_init_close_fobjcCsrtj|j��Y}xOt||�D]>\}}|j|j|j�|j|j�|j��q%WWdQRXdS)N)rrr�zipr0r�Zget_info)rr(�m1�m2rrr	�test_parallel_iteration\sz(MiscReadTestBase.test_parallel_iterationN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r��unittest�
skipUnless�hasattrr<r�skip_unless_symlinkr�r�r�r�r�rrrr	r��s(		
		r�c@seZdZdZdS)�MiscReadTestN)rrrr�rrrr	r�dsr�c@seZdZdS)�GzipMiscReadTestN)rrrrrrr	r�gsr�c@seZdZdd�ZdS)�Bz2MiscReadTestcCs|jd�dS)NzBZ2File have no name attribute)�skipTest)rrrr	r�ksz'Bz2MiscReadTest.requires_name_attributeN)rrrr�rrrr	r�jsr�c@seZdZdd�ZdS)�LzmaMiscReadTestcCs|jd�dS)NzLZMAFile have no name attribute)r�)rrrr	r�osz(LzmaMiscReadTest.requires_name_attributeN)rrrr�rrrr	r�nsr�c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StreamReadTestzr|cCs�x�|jD]w}|j�sq
|jj|��M}xCy|jd�}Wn"tjk
rn|jd�YnX|s7Pq7WWdQRXq
WdS)Niz6simple read-through using TarFile.extractfile() failed)r(Zisregr.r/r�StreamErrorrY)rr4r5Zbufrrr	�test_read_throughwsz StreamReadTest.test_read_throughcCsp|jj�}|jj|��}|j�}WdQRX|jt|�|jd�|jt|�td�dS)Nzregular file extraction failed)	r(r�r.r/r0r1r2r
r3)rr4r5rrrr	r6�sz(StreamReadTest.test_fileobj_regular_filec
CsI|jj�}|jj|d��}|jtj|j�WdQRXdS)Nr)r(r�r.r�rr�r/)rZtarinfosr�rrr	�test_provoke_stream_error�sz(StreamReadTest.test_provoke_stream_errorcCstjtdd�}z�|j}x�|j�}|j�}|dkrIP|j|d�|j�sq|j�r�|jtj	��|j
|�WdQRXq$|j
|�}|j
|�}|dkr�q$|j|d�|j|j�|j�d�q$WWd|j
�XdS)Nr'z	iso8859-1zstream.next() failed.zstream.extractfile() failedzstream extraction failed)rrrr(r��assertIsNotNoneZislnkZissymr�r�r.r0r/r*)rZtar1Ztar2Zt1Zt2�v1�v2rrr	�test_compare_members�s*	z#StreamReadTest.test_compare_membersN)rrrr
r�r6r�r�rrrr	r�ss
	r�c@seZdZdS)�GzipStreamReadTestN)rrrrrrr	r��sr�c@seZdZdS)�Bz2StreamReadTestN)rrrrrrr	r�src@seZdZdS)�LzmaStreamReadTestN)rrrrrrr	r�src@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�DetectReadTestcCsYytj||�}Wn2tjk
rJ}z|j�WYdd}~XnX|j�dS)N)rrr�rYr*)rr[rr(�errr	�_testfunc_file�s
zDetectReadTest._testfunc_filecCsxy5t|d��}tj||d|�}WdQRXWn2tjk
ri}z|j�WYdd}~XnX|j�dS)NrHr�)rrr�rYr*)rr[rr�r(rrrr	�_testfunc_fileobj�s#z DetectReadTest._testfunc_fileobjc Cs3|jr�|jtj��tjtdd|j�WdQRX|jtj��tjtdd|j�WdQRX|jtj��tj|jdd�WdQRX|jtj��tj|jdd�WdQRX||jd�||jd|j�||jd�||jd|j�||jd�dS)Nrzr:zr|r7zr:*zr|*)rr�rr�rr)rZtestfuncrrr	�_test_modes�s	!!zDetectReadTest._test_modescCs|j|j�dS)N)rr)rrrr	�test_detect_file�szDetectReadTest.test_detect_filecCs|j|j�dS)N)rr)rrrr	�test_detect_fileobj�sz"DetectReadTest.test_detect_fileobjN)rrrrrrrrrrrr	r�s
	rc@seZdZdS)�GzipDetectReadTestN)rrrrrrr	r	�sr	c@seZdZdd�ZdS)�Bz2DetectReadTestcCshttd��}|j�}WdQRXtjtddd��}|j|�WdQRX|jtd�dS)NrHr�Z
compresslevelrIzr|*)rrr/r r"r�r�r)rr5rrrr	�test_detect_stream_bz2�s
z(Bz2DetectReadTest.test_detect_stream_bz2N)rrrrrrrr	r
�sr
c@seZdZdS)�LzmaDetectReadTestN)rrrrrrr	r�src@s�eZdZddd�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�|dk	rN|jj|��-}|jt|j��|d|j�WdQRXd|d<d|d<d|d<d|jkr�d	|d
<d	|d<xC|j�D]5\}}|jt||�|d||jf�q�WdS)
Nzwrong md5sum for %si��>r�i��uidrV�gidzold-v7rr��gnamezwrong value in %s field of %s)r(r.r0r
r/r[�itemsr�)rr4�chksum�kwargsr��k�vrrr	�_test_member�s




zMemberReadTest._test_membercCs/|jjd�}|j|dddt�dS)Nz
ustar/regtyper2icr)r(r-rr3)rr4rrr	�test_find_regtypesz MemberReadTest.test_find_regtypecCs/|jjd�}|j|dddt�dS)Nzustar/conttyper2icr)r(r-rr3)rr4rrr	�test_find_conttypesz!MemberReadTest.test_find_conttypecCs)|jjd�}|j|dd�dS)Nz
ustar/dirtyper2r)r(r-r)rr4rrr	�test_find_dirtypesz MemberReadTest.test_find_dirtypecCs)|jjd�}|j|dd�dS)Nzustar/dirtype-with-sizer2�)r(r-r)rr4rrr	�test_find_dirtype_with_sizesz*MemberReadTest.test_find_dirtype_with_sizecCs/|jjd�}|j|dddd�dS)Nz
ustar/lnktyper2r�linknamez
ustar/regtype)r(r-r)rr4rrr	�test_find_lnktypesz MemberReadTest.test_find_lnktypecCs/|jjd�}|j|dddd�dS)Nz
ustar/symtyper2rrr\)r(r-r)rr4rrr	�test_find_symtypesz MemberReadTest.test_find_symtypecCs5|jjd�}|j|dddddd�dS)Nz
ustar/blktyper2r�devmajor��devminor)r(r-r)rr4rrr	�test_find_blktype#sz MemberReadTest.test_find_blktypecCs5|jjd�}|j|dddddd�dS)Nz
ustar/chrtyper2rrrIr!r )r(r-r)rr4rrr	�test_find_chrtype'sz MemberReadTest.test_find_chrtypecCs)|jjd�}|j|dd�dS)Nzustar/fifotyper2r)r(r-r)rr4rrr	�test_find_fifotype+sz!MemberReadTest.test_find_fifotypecCs/|jjd�}|j|dddt�dS)Nzustar/sparser2iPr)r(r-r�
md5_sparse)rr4rrr	�test_find_sparse/szMemberReadTest.test_find_sparsecCs/|jjd�}|j|dddt�dS)Nz
gnu/sparser2iPr)r(r-rr%)rr4rrr	�test_find_gnusparse3sz"MemberReadTest.test_find_gnusparsecCs/|jjd�}|j|dddt�dS)Nzgnu/sparse-0.0r2iPr)r(r-rr%)rr4rrr	�test_find_gnusparse_007sz%MemberReadTest.test_find_gnusparse_00cCs/|jjd�}|j|dddt�dS)Nzgnu/sparse-0.1r2iPr)r(r-rr%)rr4rrr	�test_find_gnusparse_01;sz%MemberReadTest.test_find_gnusparse_01cCs/|jjd�}|j|dddt�dS)Nzgnu/sparse-1.0r2iPr)r(r-rr%)rr4rrr	�test_find_gnusparse_10?sz%MemberReadTest.test_find_gnusparse_10cCs/|jjd�}|j|dddt�dS)Nuustar/umlauts-ÄÖÜäöüßr2icr)r(r-rr3)rr4rrr	�test_find_umlautsCsz MemberReadTest.test_find_umlautscCs/dddd}|j||jj��dS)Nzustar/z12345/�'z1234567/longname)rxr(r�)rr[rrr	�test_find_ustar_longnameHsz'MemberReadTest.test_find_ustar_longnamecCs/|jjd�}|j|dddt�dS)Nzmisc/regtype-old-v7r2icr)r(r-rr3)rr4rrr	�test_find_regtype_oldv7Lsz&MemberReadTest.test_find_regtype_oldv7cCs`|jj�tj|jd|jdd�|_|jjd�}|j|dddt�dS)Nrr'z	iso8859-1upax/umlauts-ÄÖÜäöüßr2icr)	r(r*rrrrr-rr3)rr4rrr	�test_find_pax_umlautsPs

z$MemberReadTest.test_find_pax_umlauts)rrrrrrrrrrr"r#r$r&r'r(r)r*r+r-r.r/rrrr	r
�s&r
c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�LongnameTestcCsn|jdddd}y|jj|�}Wntk
rP|jd�YnX|j|jtjd�dS)N�/z123/r~�longnamezlongname not foundzread longname as dirtype)	�subdirr(r-r�rY�assertNotEqualr�rr�)rr2r4rrr	�test_read_longname[s
zLongnameTest.test_read_longnamecCs�|jdddd}|jdddd}y|jj|�}Wntk
ri|jd�YnX|j|j|d�dS)Nr1z123/r~r2�longlinkzlonglink not foundzlinkname wrong)r3r(r-r�rYr0r)rr2r6r4rrr	�test_read_longlinkes
zLongnameTest.test_read_longlinkcCs�|jdddd}|jj|�}|j}|jjj|�tj|jjjd
��}|j	t
j��t
jddd	|�WdQRXdS)Nr1z123/r~r2r ir[zfoo.tarr�i)
r3r(r-r�r�rMrrsr/r�rr�r)rr2r4r�r5rrr	�test_truncated_longnamens	z$LongnameTest.test_truncated_longnamecCs�|jdddd}|jj|�j}ttd��K}|j|�tjj	|j
d�dd�}|j|j|j
�WdQRXdS)	Nr1z123/r~r2rHiz	iso8859-1�strict)r3r(r-r�rrrMrr�Zfrombufr/r0r��longnametype)rr2r�r5r4rrr	�test_header_offsetws
zLongnameTest.test_header_offsetN)rrrr5r7r8r;rrrr	r0Ys
		r0c@smeZdZdZejZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zedd
��Z
dS)�GNUReadTestZgnucCs�|jj|t�tjjt|�}t|d��}|j�}WdQRX|jt	|�t
d|�|j�r�tj|�}|j
|jd|j�dS)NrHzwrong md5sum for %si)r(r:r;r<r=r>rr/r0r
r%�_fs_supports_holesr�Z
assertLess�	st_blocks�st_size)rr[�filenamer5rrQrrr	�_test_sparse_file�szGNUReadTest._test_sparse_filecCs|jd�dS)Nz
gnu/sparse)rA)rrrr	�test_sparse_file_old�sz GNUReadTest.test_sparse_file_oldcCs|jd�dS)Nzgnu/sparse-0.0)rA)rrrr	�test_sparse_file_00�szGNUReadTest.test_sparse_file_00cCs|jd�dS)Nzgnu/sparse-0.1)rA)rrrr	�test_sparse_file_01�szGNUReadTest.test_sparse_file_01cCs|jd�dS)Nzgnu/sparse-1.0)rA)rrrr	�test_sparse_file_10�szGNUReadTest.test_sparse_file_10c	Cs�tjjd�r�tjjtd�}t|d��}|jd�|j	�WdQRXtj
|�}tj|�|j
dkSdSdS)N�linuxzsparse-testr�irF)rur�r�r<r=r>r;rrMr�r�rr�r>)r[r5rQrrr	r=�s


zGNUReadTest._fs_supports_holesN)rrrr3rZGNUTYPE_LONGNAMEr:rArBrCrDrE�staticmethodr=rrrr	r<�s		r<c@s7eZdZdZejZdd�Zdd�ZdS)�PaxReadTestZpaxc
Cstjtdd�}z�|jd�}|j|jd�|j|jd�|j|jjd�d�|jd�}|j|jd	�|j|jd�|j|jjd�d�|jd
�}|j|jd�|j|jd�|j|jjd�d�Wd|j	�XdS)Nr'z	iso8859-1zpax/regtype1r��barzVENDOR.umlautsuÄÖÜäöüßzpax/regtype2rzpax/regtype3r)
rrrr-r0r�r�pax_headers�getr*)rr(r4rrr	�test_pax_global_headers�s$z#PaxReadTest.test_pax_global_headersc
Cs�tjtdd�}z�|jd�}|j|jd�|j|jd�|j|jd�|j|jd�|jt	|j�t
�|jt
|jd�d�|jt
|jd�d�Wd|j�XdS)	Nr'z	iso8859-1zpax/regtype4ic�{g��^�AZatimeZctime)
rrrr-r0r2rrr�r�r�rJr*)rr(r4rrr	�test_pax_number_fields�s!z"PaxReadTest.test_pax_number_fieldsN)	rrrr3rZXHDTYPEr:rLrNrrrr	rH�s	rHc@s(eZdZdd�Zdd�ZdS)�
WriteTestBasecCs�tj�}tjd|d|j�}|jtjd��|j�|j|j	d�|j
�}~tj�|j|j	�|j
||j
��dS)Nr�rr�z#external fileobjs must never closed)rrsrrrr�r�r*�assertFalser�rwrZ
gc_collectr0)rr5r(rrrr	�test_fileobj_no_close�s

z#WriteTestBase.test_fileobj_no_closecCs�tjt|j��I}tjd�}tjtj|_|j|t	j
d|j��WdQRX|jtd��*}|jt|j
��tjd�WdQRXdS)Nr�r�rHrK)rrr�rr��
RECORDSIZEZ	BLOCKSIZEr2r�rrsr0r1r/)rr(r�r5rrr	�test_eof_marker�s'zWriteTestBase.test_eof_markerN)rrrrQrSrrrr	rO�s
rOc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zej	e
ed
�d�dd
��Ze
jdd��Zdd�Zdd�Zdd�Zdddd�Ze
jdd��Zdd�Zdd�Zd d!�Zd"d#�ZdS)$�	WriteTestzw:cCs�dd}tjt|j�}z tj|�}|j|�Wd|j�Xtjt�}z!|j|j�d|d�Wd|j�XdS)N�
0123456789rJrz!failed to store 100 char filename)	rrr�rr�r�r*r0r�)rr[r(r�rrr	�test_100_char_names
zWriteTest.test_100_char_namecCs�tjt|j�}zLtjjtd�}t|d��}|jd�WdQRX|j	|�Wd|j
�X|jtjjt�dd�dS)N�filer�saaarztarfile is empty)
rrr�rr<r=r>r;r��addr*Z
assertGreater�getsize)rr(r=r5rrr	�
test_tar_sizeszWriteTest.test_tar_sizecCs�tjt|j�}z�tjjtd�}t|d��WdQRX|j|�}|j	|j
d�t|d��}|jd�WdQRX|j|�}|j	|j
d�Wd|j�XdS)NrWr�rsaaar )
rrr�rr<r=r>r;�
gettarinfor0r2r�r*)rr(r=r4r5rrr	�test_file_size*szWriteTest.test_file_sizecCs�tjjtd�}tj|�zMtjt|j�}z&|j	|�}|j
|jd�Wd|j�XWdt
j|�XdS)NZ	directoryr)r<r=r>r;r�rrr�rr[r0r2r*r�rmdir)rr=r(r4rrr	�test_directory_size:s
zWriteTest.test_directory_sizer�zMissing hardlink implementationcCs�tjjtd�}tjjtd�}t|d��}|jd�WdQRXtj||�zZtjt|j	�}z3|j
|�|j
|�}|j|jd�Wd|j
�XWdtj|�tj|�XdS)Nr��link_targetr�saaar)r<r=r>r;rr�r�rr�rr[r0r2r*rr�)rr��targetr5r(r4rrr	�test_link_sizeGs

zWriteTest.test_link_sizecCs�tjjtd�}tjd|�zMtjt|j�}z&|j	|�}|j
|jd�Wd|j�XWdt
j|�XdS)N�symlinkr_r)r<r=r>r;rbrrr�rr[r0r2r*rr�)rr=r(r4rrr	�test_symlink_size\szWriteTest.test_symlink_sizecCs�tjjt�}tjt|j�}z}|j|j|d�|j	|�|j|j
�gd�tjt
��|j	|�WdQRX|j|j
�gd�Wd|j�XdS)Nzarchive name must be absolutezadded the archive to itself)r<r=r�r�rrrr0r[rXr�r�
change_cwdr;r*)rZdstnamer(rrr	�
test_add_selfjs
zWriteTest.test_add_selfcCs7tjjtd�}tj|�zx0d
D](}tjj||�}tj|�q,Wtjj}tj	t
|jdd�}z:tjdt
f��|j|dd	d|�WdQRXWd|j�Xtj	t
d
�}z:|jt|j��d�|j|j�dd	�Wd|j�XWdtj|�XdS)N�excluder�rI�bazr'z	iso8859-1zuse the filter argument�arcname�	empty_dirr7rIr)r�rIrg)r<r=r>r;r�r�create_empty_file�isfilerrr�rZcheck_warnings�DeprecationWarningrXr*r0r1r�r�r�)r�tempdirr[rfr(rrr	�test_exclude|s&

	
$zWriteTest.test_excludec Csgtjjtd�}tj|�z0x0dD](}tjj||�}tj|�q,Wdd�}tjt	|j
dd�}z|j|d	d
d|�Wd|j�X|j
t��|j|d
dd|�WdQRXtjt	d�}zWx4|D],}|j|jd
�|j|jd�q�W|jt|j��d�Wd|j�XWdtj|�XdS)N�filterr�rIrgcSs5tjj|j�dkrdSd|_d|_|S)NrIrMr�)r<r=�basenamer[rr�)r4rrr	ro�s
		z%WriteTest.test_filter.<locals>.filterr'z	iso8859-1rhriTr7rMr )r�rIrg)r<r=r>r;r�rrjrrr�rrXr*r��	TypeErrorr0rr�r1r�r�)rrmr[ror(r4rrr	�test_filter�s*

 
 zWriteTest.test_filterNFcCs�tjjtd�}|s+tj|�n
tj|�tjt	|j
�}z|j|d|�Wd|j�Xtjt	d�}z|j
�}Wd|j�X|s�tj|�n
tj|�|j|j|p�|jtjd��dS)Nr�rhr7r1)r<r=r>r;rrjr�rrr�rrXr*r�r�r]r0r[r��sep)rr=Zcmp_path�dirr�r(r�rrr	�_test_pathname�s 

zWriteTest._test_pathnamecCsMtjjtd�}tjjtd�}tj|�z�tjj|d�}tjj|d�}t|d��}|jd�WdQRXtj||�tj|d�}|j	|�|j	|�|j
�tj|d�}z:y|jd|�Wntk
r|j
d	�YnXWd|j
�XWdtj|�tj|�XdS)
NZtestsymlinksztestsymlinks.tar�sourcerbr�z
something
r7r=z&extractall failed with symlinked files)r<r=r>r;r�rr�rbrrXr*r��OSErrorrYrr�r�)rrmZtemparchiveZsource_fileZtarget_filer�r(rrr	�test_extractall_symlinks�s*





z"WriteTest.test_extractall_symlinkscCs�|jd�|jtjjddd��|jtjjddd��|jtjjdd��|jtjjddd��|jtjjdddd��|jtjjdddd��|jtjjdddd��|jtjjdd��|jtjjddd��|jtjjdddd��|jtjjdddd��|jdtjtjd�|jdtjtjddd�dS)Nr��.rIz..rtT)rur<r=r>rs)rrrr	�test_pathnames�s
"""""zWriteTest.test_pathnamescCsFtjdkr"|jdd�n |jdd�|jdd�dS)Nr�zC:\foor�z/fooz///foo)rur�ru)rrrr	�test_abs_pathnames
szWriteTest.test_abs_pathnamescCs�tjt���tjt|j�}z|jd�Wd|j�Xtjtd�}zCx<|D]4}|j	dkr`|j
|j	jd�|j	�q`WWd|j�XWdQRXdS)Nryr7z./)rrdr;rrr�rrXr*r[r�r�)rr(r�rrr	�test_cwds
'zWriteTest.test_cwdcs�x�tttfD]��G�fdd�dtj�}|�}|j���5tjt|j	d|dtj
dddi�}WdQRX|j|j�qWdS)Ncs(eZdZdZ�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�r)r~rr	�BadFile$srr�r�rJZnonr�)
rw�EOFError�RuntimeErrorrrsr�rrr�r�
PAX_FORMATrPr�)rrr�r(r)r~r	�test_open_nonwritable_fileobj"s		z'WriteTest.test_open_nonwritable_fileobj)rrrr
rVrZr\r^r�r�r�r<rarr�rcrernrrrurxrzr{r|r�rrrr	rTs"
(rTc@seZdZdS)�
GzipWriteTestN)rrrrrrr	r�2sr�c@seZdZdS)�Bz2WriteTestN)rrrrrrr	r�5sr�c@seZdZdS)�
LzmaWriteTestN)rrrrrrr	r�8sr�c@s^eZdZdZdZdd�Zejej	dkoEe
ed�d�dd	��ZdS)
�StreamWriteTestzw|NcCs�tjt|j�}|j�|jr~|j�}ttd��}|j�}WdQRX|j|�}|j|j	d�n%|jt��}|j�}WdQRX|j
|jd�tjd�dS)NrHzfound trailing dataszincorrect zero padding)
rrr�rr*�decompressorr/Z
decompressrPZunused_datar0�countrR)rr(Zdecr5rrrr	�test_stream_paddingAs
	z#StreamWriteTest.test_stream_paddingr��umaskzMissing umask implementationcCs�tjjt�rtjt�tjd�}zLtjt|j	�}|j
�tjt�jd@}|j
|dd�Wdtj|�XdS)N�i�i�zwrong file permissions)r<r=�existsr�rr�r�rrrr*r�r�r0)rZoriginal_umaskr(rrrr	�test_file_modeQs

zStreamWriteTest.test_file_mode)
rrrr
r�r�r�r�rur�r�r<r�rrrr	r�<s
!r�c@seZdZdS)�GzipStreamWriteTestN)rrrrrrr	r�bsr�c@s%eZdZerejndZdS)�Bz2StreamWriteTestN)rrrr ZBZ2Decompressorr�rrrr	r�esr�c@s%eZdZerejndZdS)�LzmaStreamWriteTestN)rrrr%ZLZMADecompressorr�rrrr	r�hsr�c@s�eZdZdd�Zddd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�GNUWriteTestcCst|�dd}|dS)NirI)r1)rrQZblocksrrr	�_lengthpszGNUWriteTest._lengthNcCszd}t|�tjkr8|d7}||j|�7}|dk	rvt|�tjkrv|d7}||j|�7}|S)Ni)r1rZLENGTH_NAMEr�ZLENGTH_LINK)rr[r�r�rrr	�
_calc_sizets
!
zGNUWriteTest._calc_sizecCstj|�}|r*||_tj|_tjtd�}zKtj|_|j	|�|j
||�}|j}|j||d�Wd|j
�Xtjt�}zR|j�}|j|d�|j|j|jd�|j|j|jd�Wd|j
�XdS)Nr�z%GNU longname/longlink creation failedzunable to read longname member)rr�r�LNKTYPEr�rr��
GNU_FORMATr�r�r�r�r0r*r�r�r[)rr[r�r4r(r�r�Zmemberrrr	�_test�s,	
		zGNUWriteTest._testcCs|jddd�dS)Nzlongnam/��longnam)r�)rrrr	�test_longname_1023�szGNUWriteTest.test_longname_1023cCs|jddd�dS)Nzlongnam/r�r2)r�)rrrr	�test_longname_1024�szGNUWriteTest.test_longname_1024cCs|jddd�dS)Nzlongnam/r��	longname_)r�)rrrr	�test_longname_1025�szGNUWriteTest.test_longname_1025cCs|jdddd�dS)Nr[zlonglnk/r��longlnk)r�)rrrr	�test_longlink_1023�szGNUWriteTest.test_longlink_1023cCs|jdddd�dS)Nr[zlonglnk/r�r6)r�)rrrr	�test_longlink_1024�szGNUWriteTest.test_longlink_1024cCs|jdddd�dS)Nr[zlonglnk/r��	longlink_)r�)rrrr	�test_longlink_1025�szGNUWriteTest.test_longlink_1025cCs$|jdddddd�dS)Nzlongnam/r�r�zlonglnk/r�)r�)rrrr	�test_longnamelink_1023�sz#GNUWriteTest.test_longnamelink_1023cCs$|jdddddd�dS)Nzlongnam/r�r2zlonglnk/r6)r�)rrrr	�test_longnamelink_1024�sz#GNUWriteTest.test_longnamelink_1024cCs$|jdddddd�dS)Nzlongnam/r�r�zlonglnk/r�)r�)rrrr	�test_longnamelink_1025�sz#GNUWriteTest.test_longnamelink_1025)rrrr�r�r�r�r�r�r�r�r�r�r�r�rrrr	r�lsr�c@s�eZdZdZejjed�Zdd�Z	e
dd��Ze
dd��Zd	d
�Z
dd�Zd
d�Zdd�ZdS)�
CreateTestzx:�
spameggs42cCstjt�dS)N)rr�r�)rrrr	r)�szCreateTest.setUpc	Cs-t|jd��}|jd�WdQRXdS)Nr�saaa)r�	file_pathr�)�clsr5rrr	�
setUpClass�szCreateTest.setUpClasscCstj|j�dS)N)rr�r�)r�rrr	�
tearDownClass�szCreateTest.tearDownClasscCs�tjt|j��}|j|j�WdQRX|jt��}|j�}WdQRX|jt	|�d�|j
d|d�dS)NrIr�r)rrr�rrXr�rr�r0r1rx)r�tobj�namesrrr	�test_create�szCreateTest.test_createcCs�tjt|j��}|j|j�WdQRX|jt��tjt|j�}WdQRX|jt��}|j	�}WdQRX|j
t|�d�|jd|d�dS)NrIr�r)
rrr�rrXr�r��FileExistsErrorrr�r0r1rx)rr�r�rrr	�test_create_existing�szCreateTest.test_create_existingcCs|jtd��}|j|j�WdQRX|jt��}|j�}WdQRX|jt|�d�|jd|d�dS)N�xrIr�r)rr�rXr�r�r0r1rx)rr�r�rrr	�test_create_taropen�szCreateTest.test_create_taropenc Cs�|jtd��}|j|j�WdQRX|jt��|jtd��WdQRXWdQRX|jt��}|j�}WdQRX|jt|�d�|j	d|d�dS)Nr�rIr�r)
rr�rXr�r�r�r�r0r1rx)rr�r�rrr	�test_create_existing_taropen�sz'CreateTest.test_create_existing_taropenN)rrrr
r<r=r>r;r�r)�classmethodr�r�r�r�r�r�rrrr	r��s		r�c@seZdZdS)�GzipCreateTestN)rrrrrrr	r��sr�c@seZdZdS)�
Bz2CreateTestN)rrrrrrr	r�sr�c@seZdZdS)�LzmaCreateTestN)rrrrrrr	r�sr�c@s"eZdZdZdZdZdS)�CreateWithXModeTestr�N)rrrr
r�r�rrrr	r�sr�r�zMissing hardlink implementationc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�HardlinkTestc
Cs�tjjtd�|_tjjtd�|_t|jd��}|jd�WdQRXtj|j|j�t	jt
d�|_|jj|j�dS)Nr�rIr�sfoor�)
r<r=r>r;r�rIrr�r�rr�r(rX)rr5rrr	r)szHardlinkTest.setUpcCs1|jj�tj|j�tj|j�dS)N)r(r*rr�r�rI)rrrr	r+ s
zHardlinkTest.tearDowncCs2|jj|j�}|j|jtjd�dS)Nzadd file as regular failed)r(r[r�r0r�r�REGTYPE)rr4rrr	�test_add_twice%szHardlinkTest.test_add_twicecCs2|jj|j�}|j|jtjd�dS)Nzadd file as hardlink failed)r(r[rIr0r�rr�)rr4rrr	�test_add_hardlink,szHardlinkTest.test_add_hardlinkcCs>d|j_|jj|j�}|j|jtjd�dS)NTzdereferencing hardlink failed)r(Zdereferencer[rIr0r�rr�)rr4rrr	�test_dereference_hardlink1sz&HardlinkTest.test_dereference_hardlinkN)rrrr)r+r�r�r�rrrr	r�s
r�c@s7eZdZddd�Zdd�Zdd�ZdS)�PaxWriteTestNcCs�tj|�}|r*||_tj|_tjtddtj�}z|j|�Wd|j	�Xtjt�}zY|r�|j
�dj}|j||d�n&|j
�dj}|j||d�Wd|j	�XdS)Nr�r�rzPAX longlink creation failedzPAX longname creation failed)
rr�rr�r�rr�r�r�r*r�r0r[)rr[r�r4r(�l�nrrr	r�:s 	zPaxWriteTest._testcCs`ddddddddddi}tjtd	d
tjd|�}z|jtjd��Wd|j�Xtjtdd
�}z�|j|j|�|j|j	�dj|�x�|jj
�D]�\}}|jt|�t
�|jt|�t
�|tjkr�ytj||�Wq�ttfk
rH|jd�Yq�Xq�WWd|j�XdS)Nr�rIr�0r�z1.23�testuäöür�r�rJr'z	iso8859-1rz"unable to convert pax header field)rrr�r�r�r�r*r0rJr�rZassertIsNotr�r�ZPAX_NUMBER_FIELDSrqr�rY)rrJr(�key�valrrr	�test_pax_global_headerRs.	z#PaxWriteTest.test_pax_global_headercCs�ddddi}tjtddtjdd�}z8tj�}d	|_d
|_||_|j|�Wd|j	�Xtjtdd�}zM|j
�d}|j|j|�|j|jd�|j|jd�Wd|j	�XdS)Nr=r�rZ123r�r�r'z	iso8859-1uäöür�rrMi)rrr�r�r�r[rrJr�r*r�r0)rrJr(r�rrr	�test_pax_extended_headerrs"				z%PaxWriteTest.test_pax_extended_header)rrrr�r�r�rrrr	r�8s r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�UnicodeTestcCs|jd�dS)Nz	iso8859-1)�_test_unicode_filename)rrrr	�test_iso8859_1_filename�sz#UnicodeTest.test_iso8859_1_filenamecCs|jd�dS)N�utf7)r�)rrrr	�test_utf7_filename�szUnicodeTest.test_utf7_filenamecCs|jd�dS)Nzutf-8)r�)rrrr	�test_utf8_filename�szUnicodeTest.test_utf8_filenamecCs�tjtdd|jd|dd�}z d}|jtj|��Wd|j�Xtjtd|�}z!|j|j�dj	|�Wd|j�XdS)Nr�r�r'�errorsr9uäöür)
rrr�r�r�r�r*r0r�r[)rr'r(r[rrr	r��s!z"UnicodeTest._test_unicode_filenamec
Cs�tjtdd|jdddd�}zWtj�}d|_|jt|j|�d|_d|_	|jt|j|�Wd|j
�XdS)	Nr�r�r'rir�r9uäöür�)rrr�r�r�r[r��UnicodeErrorr�r�r*)rr(r4rrr	�test_unicode_filename_error�s			z'UnicodeTest.test_unicode_filename_errorc
Cs�tjtddddd�}zyxr|D]j}|jt|j�t�|jt|j�t�|jt|j�t�|jt|j	�t�q(WWd|j
�XdS)Nr7r'z	iso8859-1r�r9)rrrZassertIsr�r[r�rr�rr*)rr(r�rrr	�test_unicode_argument�s
!z!UnicodeTest.test_unicode_argumentcCs*tjd�}d|_d|_tjtddd|jdd�}z|j|�Wd|j�Xtjtdd�}z�|j	d�}|j
|jd�|j
|jd�|jtjkr|j�tjtdd�}|j	d�}|j
|jd	�|j
|jd	�Wd|j�XdS)
Nr�uäöürr�r�r'z	iso8859-1riu	���)rr�r�rrr�r�r�r*r-r0r�)rr�r(rrr	�test_uname_unicode�s(			
zUnicodeTest.test_uname_unicodeN)
rrrr�r�r�r�r�r�r�rrrr	r��sr�c@s�eZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
dd�Zdd�Z
dd�Zd
dd�Zd
S)�UstarUnicodeTestcCsZ|jdd�|jdddt�|jddd�|jdddt�dS)NrUrJr��	u
01234567ÿu012345678ÿ)�_test_ustar_namer�)rrrr	�test_unicode_name1�sz#UstarUnicodeTest.test_unicode_name1cCs1|jddd�|jdddt�dS)NrUr�u
012345ÿÿu0123456ÿÿ)r�r�)rrrr	�test_unicode_name2�sz#UstarUnicodeTest.test_unicode_name2cCs~|jddddd�|jdddddt�|jddddd�|jdddddt�dS)NrU�z01234/rJz0123/4u012ÿ/u0123ÿ/)r�r�)rrrr	�test_unicode_longname1�s z'UstarUnicodeTest.test_unicode_longname1cCsD|jdddddt�|jdddddt�dS)NrUr�u01ÿ/2rJu01ÿÿ/)r�r�)rrrr	�test_unicode_longname2�s z'UstarUnicodeTest.test_unicode_longname2cCsi|jdddddt�|jdddddd�|jddddddt�dS)	NrUr�u01ÿÿ/2rJz01234/r�u
01234567ÿu012345678ÿ)r�r�)rrrr	�test_unicode_longname3�s !z'UstarUnicodeTest.test_unicode_longname3cCsI|jdddddd�|jddddddt�dS)NrUr�z01234/r�u
012345ÿÿu0123456ÿÿ)r�r�)rrrr	�test_unicode_longname4�s!z'UstarUnicodeTest.test_unicode_longname4NcCs�tjtdd|jdd��H}tj|�}|dkrO|j|�n|j||j|�WdQRX|dkr�tjtddd��,}x"|D]}|j||j�Pq�WWdQRXdS)Nr�r�r'zutf-8r7)	rrr�r�r�r�r�r0r[)rr[�excr(r�rrr	r�s$
z!UstarUnicodeTest._test_ustar_namecCsZ|jdd�|jdddt�|jddd�|jdddt�dS)NrUrJr�r�u
01234567ÿu012345678ÿ)�_test_ustar_linkr�)rrrr	�test_unicode_link1sz#UstarUnicodeTest.test_unicode_link1cCs1|jddd�|jdddt�dS)NrUr�u
012345ÿÿu0123456ÿÿ)r�r�)rrrr	�test_unicode_link2sz#UstarUnicodeTest.test_unicode_link2cCs�tjtdd|jdd��Q}tjd�}||_|dkrX|j|�n|j||j|�WdQRX|dkr�tjtddd��,}x"|D]}|j||j�Pq�WWdQRXdS)Nr�r�r'zutf-8r�r7)	rrr�r�r�rr�r�r0)rr[r�r(r�rrr	r�s$	
z!UstarUnicodeTest._test_ustar_link)rrrr�USTAR_FORMATr�r�r�r�r�r�r�r�r�r�r�rrrr	r��s	r�c@s%eZdZejZdd�ZdS)�GNUUnicodeTestcCsuxndD]f\}}tjtd|dd��<}y|j|�}Wntk
re|jd�YnXWdQRXqWdS)N�utf-8�pax/bad-pax-����	iso8859-1�pax/bad-pax-äöür'r�roz%unable to read bad GNU tar pax header�r�r��r�r�)r�r�)rrrr-r�rY)rr'r[r(r�rrr	�test_bad_pax_header0s
z"GNUUnicodeTest.test_bad_pax_headerN)rrrrr�r�r�rrrr	r�,s	r�c@s+eZdZejZdZdd�ZdS)�PAXUnicodeTestNcCsuxndD]f\}}tjtd|dd��<}y|j|�}Wntk
re|jd�YnXWdQRXqWdS)N�utf-8�pax/hdrcharset-����	iso8859-1�pax/hdrcharset-äöür'r�roz)unable to read POSIX.1-2008 binary header�r�r��r�r�)r�r�)rrrr-r�rY)rr'r[r(r�rrr	�test_binary_headerEs
z!PAXUnicodeTest.test_binary_header)rrrrr�r�r�r�rrrr	r�>s	r�c@s7eZdZdd�Zddd�Zdd�ZdS)	�AppendTestBasecCs2t|_tjj|j�r.tj|j�dS)N)r�rr<r=r�rr�)rrrr	r)Us	zAppendTestBase.setUpzw:cCs�tjtdd��g}|jd�}d|_|j|��6}tj|j|��}|j||�WdQRXWdQRXWdQRXdS)Nr'z	iso8859-1z
ustar/regtyper�)rrrr-r[r.r�)rr�srcr�r�r(rrr	�_create_testtarZs	zAppendTestBase._create_testtarcCs4|jd|j�|jtjtjtd�dS)Nzw:r])r�rr�rr�rr�)rrrr	�test_append_compressedbsz%AppendTestBase.test_append_compressedN)rrrr)r�r�rrrr	r�Rsr�c@s�eZdZdZddd�Zdgddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�
AppendTestNc
Cs?tj|jdd|��}|jtjd��WdQRXdS)Nr]r�rI)rrrr�r�)rr�r(rrr	�
_add_testfileiszAppendTest._add_testfilerIc
Cs<tj|jd|��}|j|j�|�WdQRXdS)Nr�)rrrr0r�)rr�r�r(rrr	r�mszAppendTest._testcCs|j�|j�dS)N)r�r�)rrrr	�test_non_existingqs
zAppendTest.test_non_existingcCs1tj|jd�j�|j�|j�dS)Nzw:)rrrr*r�r�)rrrr	�
test_emptyus
zAppendTest.test_emptycCsAtjdd�}|j|�|jd�|jd|�dS)Nsirr�)rrsr�rMr�)rr5rrr	�test_empty_fileobjzs

zAppendTest.test_empty_fileobjcCs{|j�t|jd��}|j�}WdQRXtj|�}|j|�|jd�|jdddgd|�dS)NrHrr�r�rIr�)	r�rrr/rrsr�rMr�)rr5rrrr	�test_fileobj�s


zAppendTest.test_fileobjcCs.|j�|j�|jdddg�dS)Nr�r�rI)r�r�r�)rrrr	�
test_existing�s

zAppendTest.test_existingc
CsCt|jd��}|j|�WdQRX|jtj|j�dS)Nr�)rrr�r�rr�r�)rrr5rrr	�_test_error�szAppendTest._test_errorcCs|jd�dS)NrL)r�)rrrr	�	test_null�szAppendTest.test_nullcCs|jd�dS)Ns�
s
)r�)rrrr	�test_incomplete�szAppendTest.test_incompletecCs&tjd�j�}|j|�dS)Nr�)rr�r�r�)rrrrr	�test_premature_eof�szAppendTest.test_premature_eofcCs*tjd�j�}|j|d�dS)Nr�sr�s
)rr�r�r�)rrrrr	�test_trailing_garbage�sz AppendTest.test_trailing_garbagecCs|jdd�dS)Nr�i)r�)rrrr	�test_invalid�szAppendTest.test_invalid)rrrr�r�r�r�r�r�r�r�r�r�r�rrrrrrr	r�fs	r�c@seZdZdS)�GzipAppendTestN)rrrrrrr	r�src@seZdZdS)�
Bz2AppendTestN)rrrrrrr	r�src@seZdZdS)�LzmaAppendTestN)rrrrrrr	r�src@s4eZdZdd�Zdd�Zdd�ZdS)�
LimitsTestcCsHtjdd�}|jtj�tjddd�}|jt|jtj�tjddd�}|jtj�tjddd�}|jt|jtj�tjdd	d�}|jt|jtj�tjd
�}dd	d|_|jt|jtj�tjd�}d|_|jt|jtj�dS)
NrUrJr�z123/�>r2z1234567/��~r6r[i )rr�r�r�r�r�rr)rr4rrr	�test_ustar_limits�s 	zLimitsTest.test_ustar_limitscCs�tjddd�}|jtj�tjd�}ddd|_|jtj�tjd�}d|_|jt|jtj�dS)Nz123/r	r2r6r[l)rr�r�r�rrr�r�)rr4rrr	�test_gnu_limits�s	zLimitsTest.test_gnu_limitscCs�tjddd�}|jtj�tjd�}ddd|_|jtj�tjd�}d|_|jtj�dS)Nz123/r	r2r6r[l)rr�r�r�rr)rr4rrr	�test_pax_limits�s	zLimitsTest.test_pax_limitsN)rrrr
rrrrrr	r�s
rc@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�MiscTestcCs�|jtjdddd�d�|jtjdddd�d�|jtjddd�d�|jtjd	dd�d�dS)
Nr�r�rir9sfooZfoobarr sfoosfoobar)r0rZstnZnts)rrrr	�test_char_fields�szMiscTest.test_char_fieldscCs�|jtjd�d�|jtjd�d�|jtjd�d�|jtjd�d�|jtjd	�d�|jtjd
�d�|jtjd�d�|jtjd�d�|jtjd�d�dS)Ns0000001rIs7777777i��s� i s�����l��s��������s��������rVs�lsrs       r�i����l����)r0rZnti)rrrr	�test_read_number_fields�sz MiscTest.test_read_number_fieldscCs�|jtjd�d�|jtjd�d�|jtjd�d�|jtjd�d�|jtjd�d	�|jtjd�d�|jtjd�d
�dS)NrIs0000001i��s7777777i s� l��s�����s��������rVs��������ls�r�i����l����)r0r�itn)rrrr	�test_write_number_fieldssz!MiscTest.test_write_number_fieldsc Cs�|jt��tjddtj�WdQRX|jt��tjddtj�WdQRX|jt��tjddtj�WdQRX|jt��tjddtj�WdQRXdS)	NrIr�i l�lr�l����)r�r�rrr�r�)rrrr	�test_number_field_limitssz!MiscTest.test_number_field_limitsN)rrrrrrrrrrr	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%S)&�CommandLineTestcOs:tjdd||�\}}}|jtjj�d�S)Nz-mrs
)rZassert_python_okr�r<�lineseprW)r�argsr�rcr|�errrrr	�
tarfilecmd&szCommandLineTest.tarfilecmdcGstjdd|�S)Nz-mr)rZassert_python_failure)rrrrr	�tarfilecmd_failure+sz"CommandLineTest.tarfilecmd_failurec
Cs�tjd�tjd�g}|jtj|�tj|d��7}x-|D]%}|j|dtjj	|��qMWWdQRXdS)Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr�rh)
r�findfiler�r�rrrXr<r=rp)r�tar_name�files�tfZtardatarrr	�make_simple_tarfile.s
z#CommandLineTest.make_simple_tarfilecCsHxAtD]9}x0dD](}|j||�}|j|d�qWqWdS)N�-t�--testrL)r r!)�testtarnamesrr0)rr�optr|rrr	�test_test_command7s

z!CommandLineTest.test_test_commandcCsKxDtD]<}x3dD]+}|j|d|�}|jd|�qWqWdS)N�-v�	--verbosez-tsis a tar archive.
)r%r&)r"rrx)rrr#r|rrr	�test_test_command_verbose=s

z)CommandLineTest.test_test_command_verbosec Cs.tjd�}|jd|�\}}}|jd|�|j|d�|j|d�x�tD]�}|jd|���t|d��}|j�}WdQRXzott	d��}|j
|dd	��WdQRX|jdt	�\}}}|j|d�|j|d�Wdtjt	�XWdQRXqaWdS)
Nz
zipdir.zipz-ts is not a tar archive.rLrIrrHr�i�)rrrrxr0r"ZsubTestrr/r�r�r�)r�zipnamerr|rrr�rrrr	�test_test_command_invalid_fileCs 
z.CommandLineTest.test_test_command_invalid_filecCs�x�tD]�}tj��3}tj|d��}|jdd�WdQRXWdQRX|j�jdd�}x6d	D].}|j||dd�}|j	||�qnWqWdS)
Nr7rmFrirp�-l�--list�PYTHONIOENCODING)r*r+)
r"r�captured_stdoutrrrFrwrWrr0)rrr�r�expectedr#r|rrr	�test_list_commandWs

	z!CommandLineTest.test_list_commandcCs�x�tD]�}tj��3}tj|d��}|jdd�WdQRXWdQRX|j�jdd�}x9d
D]1}|j|d|d	d�}|j	||�qnWqWdS)Nr7rmTrirp�-v�	--verbosez-lr,)r0r1)
r"rr-rrrFrwrWrr0)rrr�rr.r#r|rrr	�test_list_command_verbosebs

	z)CommandLineTest.test_list_command_verbosecCs^tjd�}|jd|�\}}}|jd|�|j|d�|j|d�dS)Nz
zipdir.zipz-ls is not a tar archive.rLrI)rrrrxr0)rr(rr|rrrr	�test_list_command_invalid_filems
z.CommandLineTest.test_list_command_invalid_filecCs�tjd�tjd�g}xkdD]c}zL|j|t|�}|j|d�tjt��}|j�WdQRXWdtjt�Xq%WdS)Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt�-c�--createrL)r4r5)	rrrr�r0rrr�r�)rrr#r|r(rrr	�test_create_commandts
z#CommandLineTest.test_create_commandcCs�tjd�tjd�g}xndD]f}zO|j|dt|�}|jd|�tjt��}|j�WdQRXWdtjt�Xq%WdS)Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt�-v�	--verbosez-cs file created.)r7r8)	rrrr�rxrrr�r�)rrr#r|r(rrr	�test_create_command_verbose�s
z+CommandLineTest.test_create_command_verbosecCsstjd�g}zL|jdt|�}|j|d�tjt��}|j�WdQRXWdtjt�XdS)Nztokenize_tests.txtz-crL)	rrr�dotlessnamer0rrr�r�)rrr|r(rrr	�$test_create_command_dotless_filename�sz4CommandLineTest.test_create_command_dotless_filenamecCs�tjjtd�}tjd�g}zL|jd||�}|j|d�tj	|��}|j
�WdQRXWdtj|�XdS)Nz.testtarztokenize_tests.txtz-crL)r<r=r>r;rrrr0rrr�r�)rrrr|r(rrr	�(test_create_command_dot_started_filename�sz8CommandLineTest.test_create_command_dot_started_filenamecCs�tjd�tjd�g}x�tttfD]p}|js@q.zMtd|j}|jd||�}|j	|��}|j
�WdQRXWdtj|�Xq.WdS)Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtryz-c)rrrrr#rr�rrrr�r�)rrZfiletyperr|r(rrr	�test_create_command_compressed�s	z.CommandLineTest.test_create_command_compressedcCsp|jt�x\dD]T}z=tjt��|j|t�}WdQRX|j|d�Wdtjt�XqWdS)N�-e�	--extractrL)r>r?)rr�r�temp_cwd�	tarextdirrr0r�)rr#r|rrr	�test_extract_command�s

z$CommandLineTest.test_extract_commandcCss|jt�x_dD]W}z@tjt��|j|dt�}WdQRX|jd|�Wdtjt�XqWdS)N�-v�	--verbosez-es file is extracted.)rCrD)rr�rr@rArrxr�)rr#r|rrr	�test_extract_command_verbose�s

z,CommandLineTest.test_extract_command_verbosecCsb|jt�z@tjt��|jdtd�}WdQRX|j|d�Wdtjt�XdS)Nz-eZspamdirrL)rr�rr@rArr0r�)rr|rrr	�(test_extract_command_different_directory�s
z8CommandLineTest.test_extract_command_different_directoryc
Csutjd�}tjt�� |jd|�\}}}WdQRX|jd|�|j|d�|j|d�dS)Nz
zipdir.zipz-es is not a tar archive.rLrI)rrr@rArrxr0)rr(rr|rrrr	�!test_extract_command_invalid_file�s"z1CommandLineTest.test_extract_command_invalid_fileN)rrrrrrr$r'r)r/r2r3r6r9r;r<r=rBrErFrGrrrr	r$s$	




	rc@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ContextManagerTestc
CsCtjt��}|j|jd�WdQRX|j|jd�dS)Nzclosed inside runtime contextzcontext manager failed)rrrrPr�r�)rr(rrr	�
test_basic�szContextManagerTest.test_basiccCsBtjt�}|j�|jt��|�WdQRXWdQRXdS)N)rrrr*r�rw)rr(rrr	�test_closed�s

zContextManagerTest.test_closedcCse|jt��&}tjt��
}t�WdQRXWdQRX|j|jtd�|j|j	d�dS)Nz)wrong exception raised in context managerzcontext manager failed)
r��	Exceptionrrrrwr�Z	exceptionr�r�)rr�r(rrr	�test_exception�sz!ContextManagerTest.test_exceptioncCsgy&tjtd��
}t�WdQRXWnYnX|jtjjt�dd�|j|j	d�dS)Nr�rz-context manager wrote an end-of-archive blockzcontext manager failed)
rrr�rKr0r<r=rYr�r�)rr(rrr	�test_no_eof�szContextManagerTest.test_no_eofcCs=tjtd��WdQRX|jtjjt�dd�dS)Nr�rz-context manager wrote no end-of-archive block)rrr�r4r<r=rY)rrrr	�test_eof�szContextManagerTest.test_eofcCszttd��d}y,tjd|dd��
}t�WdQRXWnYnX|j|jd�|j|jd�WdQRXdS)Nr�r�rr�zexternal file object was closedzcontext manager failed)rr�rrKrPr�r�)rr5r(rrr	r�	szContextManagerTest.test_fileobjN)	rrrrIrJrLrMrNr�rrrr	rH�s		rHzrequires os.link to be missingc@s�eZdZdd�Zejeejd�d�dd��Z	ejeejd�d�dd��Z
ejeed	�d
�dd��Zejeed	�d
�d
d��ZdS)�LinkEmulationTestc
Csa|jj|t�ttjjt|�d��}|j�}WdQRX|jt	|�t
�dS)NrH)r(r:r;rr<r=r>r/r0r
r3)rr[r�rrrr	�_test_link_extraction	s!z'LinkEmulationTest._test_link_extraction�islinkz3Skip emulation - has os.path.islink but not os.linkcCs|jd�dS)Nz
ustar/lnktype)rP)rrrr	�test_hardlink_extraction1	sz+LinkEmulationTest.test_hardlink_extraction1cCs|jd�dS)Nz./ustar/linktest2/lnktype)rP)rrrr	�test_hardlink_extraction2$	sz+LinkEmulationTest.test_hardlink_extraction2rbz Skip emulation if symlink existscCs|jd�dS)Nz
ustar/symtype)rP)rrrr	�test_symlink_extraction1)	sz*LinkEmulationTest.test_symlink_extraction1cCs|jd�dS)Nz./ustar/linktest2/symtype)rP)rrrr	�test_symlink_extraction2.	sz*LinkEmulationTest.test_symlink_extraction2N)
rrrrPr��skipIfr�r<r=rRrSrTrUrrrr	rO	srOc@s4eZdZdd�Zdd�Zdd�ZdS)�Bz2PartialReadTestc
s�G�fdd�dtj��tjtjd�j��}x`tt|�d�D]H}y*tj	d�|d|��d|�WqTtj
k
r�YqTXqTWdS)Ncs@eZdZdZ��fdd�Z��fdd�Z�S)z9Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIOFcsL|jrtd��|j�t|j��k|_t�|�j|�S)Nz(infinite loop detected in tarfile.open())�hit_eof�AssertionErrorrNr1rw�superr/)rr�)�	MyBytesIO�	__class__rr	r/;	s	!z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.readcsd|_t�|�j|�S)NF)rXrZrM)rr)r[r\rr	rMA	s	z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek)rrrrXr/rMr)r[)r\r	r[9	sr[r�rIr�r)rrsr �compressrr�r��ranger1rr�)rrrr�r)r[r	�_test_partial_input8	s*z&Bz2PartialReadTest._test_partial_inputcCs|jd�dS)Nr7)r_)rrrr	�test_partial_inputL	sz%Bz2PartialReadTest.test_partial_inputcCs|jd�dS)Nzr:bz2)r_)rrrr	�test_partial_input_bz2O	sz)Bz2PartialReadTest.test_partial_input_bz2N)rrrr_r`rarrrr	rW4	srWcCssyddl}ddl}Wntk
r4dSYnX|jd�ddkrRdS|jd�ddkrodSdS)NrF�rootT)�pwd�grp�ImportError�getpwuidZgetgrgid)rcrdrrr	�root_is_uid_gid_0S	s
	rg�chownzmissing os.chown�geteuidzmissing os.geteuidc@s3eZdZedd��Zeedd���Zejj	d�ejj	d�ejj	d�dd	����Z
ejj	d�ejj	d�ejj	d�d
d����Zeje
�d�ejj	d�ejj	d�ejj	d�d
d�����Zejj	d�dd��ZdS)�NumericOwnerTestc
Cs�tjd�}|ddtj|f|ddtjdf|ddtj|fg}tjtd��s}xi|D]a\}}}}	}
tj|�}||_||_	d	|_
d	|_|	|_|j
||
�qpWWdQRXtS)
Nscontent�c�b�M�L�X�Wr�rb)rrsrr�r�rr�r�rrr�rr�r�)�
filename_1�	dirname_1�
filename_2r5r�tarflr[rr�typ�contentsr�rrr	�_make_test_archiveh	s					z#NumericOwnerTest._make_test_archiveccsyd|_d}d}|}|}tjj||�}tj|||�}tj|��}||||fVWdQRXdS)Nrznumeric-owner-testfilert)Zreturn_valuer<r=r>rjrwrr)�mock_geteuidZfname�dirnamerqrrrsZtar_filenamertrrr	�_setup_test�	s			zNumericOwnerTest._setup_testzos.chownzos.chmodz
os.geteuidc

Cs�|j|��?\}}}}|j|tdd�|j|tdd�WdQRXtjjt|�}tjjt|�}	|jtjj	|dd�tjj	|	dd�gdd�dS)N�
numeric_ownerTrkrlrorp�	any_order)
rzr:r;r<r=r>�assert_has_callsr��mock�call)
rrx�
mock_chmod�
mock_chownrtrq�_rs�f_filename_1�f_filename_2rrr	�test_extract_with_numeric_owner�	sz0NumericOwnerTest.test_extract_with_numeric_ownercCs�|j|��&\}}}}|jtdd�WdQRXtjjt|�}tjjt|�}	tjjt|�}
|jtjj	|dd�tjj	|	dd�tjj	|
dd�gd	d�dS)
Nr{Trkrlrmrnrorpr|)
rzr�r;r<r=r>r}r�r~r)rrxr�r�rtrqrrrsr�Zf_dirname_1r�rrr	�"test_extractall_with_numeric_owner�	sz3NumericOwnerTest.test_extractall_with_numeric_ownerz uid=0,gid=0 must be named "root"cCsg|j|��)\}}}}|j|tdd�WdQRXtjjt|�}|j|dd�dS)Nr{Fr)rzr:r;r<r=r>Zassert_called_with)rrxr�r�rtrqr�r�rrr	�"test_extract_without_numeric_owner�	sz3NumericOwnerTest.test_extract_without_numeric_ownercCsH|j|��2\}}}}|jt|j|tdd�WdQRXdS)NFT)rzr�rqr:r;)rrxrtrqr�rrr	�test_keyword_only�	s	z"NumericOwnerTest.test_keyword_onlyN)rrrrGrwrrzr�r~Zpatchr�r�r�rgr�r�rrrr	rj_	s	$$'rjcCs�tjt�tjt�tgattd��}|j�}WdQRXxlt	t
tfD][}|jrXtj|j�tj|j�|j|jd��}|j
|�WdQRXqXWdS)NrHr�)rr�r;r<�makedirsrr"rr/rrr#�appendr�)r5r�cr(rrr	�setUpModule�	s

		r�cCs#tjjt�rtjt�dS)N)r<r=r�r;rr�rrrr	�tearDownModule�	sr��__main__)prur<rZhashlibr�
contextlibrZrandomrr�Z
unittest.mockrr�rZtest.supportrrrer r%r
r=r�ZTESTFNr;rArrr>rr!r$r�r:r3r%rZ
requires_gziprZrequires_bz2rZ
requires_lzmar#r&ZTestCaser,rerfrgrhr�r�r�r�r�r�r�r�r�r�r�rrrr	r
rr
r0r<rHrOrTr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr
rrHrVrOrWrgrjr�r�r�mainrrrr	�<module>s�




~PP�=(a*6,�/&R>%'TQO@;9�:%!%v