403Webshell
Server IP : 118.27.122.248  /  Your IP : 216.73.216.15
Web Server : Apache
System : Linux web0264.sh.tyo1 4.18.0-553.79.1.lve.el7h.x86_64 #1 SMP Wed Oct 15 16:34:46 UTC 2025 x86_64
User : c9415830 ( 11735)
PHP Version : 8.4.17
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python36/lib64/python3.6/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python36/lib64/python3.6/test/__pycache__/test_zipfile.cpython-36.pyc
3

x2_�c�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZm
Z
mZddlmZddlmZmZmZmZmZmZmZmZmZmZmZedZedZdZd	Z d_d`dadbgZ!dd�Z"dd�Z#Gdd�d�Z$Gdd�de$e
j%�Z&eGdd�de$e
j%��Z'eGdd�de$e
j%��Z(eGdd�de$e
j%��Z)Gd d!�d!�Z*Gd"d#�d#e*e
j%�Z+eGd$d%�d%e*e
j%��Z,eGd&d'�d'e*e
j%��Z-eGd(d)�d)e*e
j%��Z.Gd*d+�d+�Z/Gd,d-�d-e/e
j%�Z0eGd.d/�d/e/e
j%��Z1eGd0d1�d1e/e
j%��Z2eGd2d3�d3e/e
j%��Z3Gd4d5�d5e
j%�Z4Gd6d7�d7e
j%�Z5Gd8d9�d9e
j%�Z6Gd:d;�d;�Z7Gd<d=�d=e7e
j%�Z8eGd>d?�d?e7e
j%��Z9eGd@dA�dAe7e
j%��Z:eGdBdC�dCe7e
j%��Z;GdDdE�dEe
j%�Z<GdFdG�dG�Z=GdHdI�dIe=e
j%�Z>eGdJdK�dKe=e
j%��Z?eGdLdM�dMe=e
j%��Z@eGdNdO�dOe=e
j%��ZAGdPdQ�dQ�ZBGdRdS�dS�ZCGdTdU�dUe
j%�ZDeGdVdW�dWe
j%��ZEGdXdY�dYe
j%�ZFGdZd[�d[e
j%�ZGGd\d]�d]e
j%�ZHeId^k�r�e
jJ�dS)c�N)�
TemporaryFile)�randint�random�getrandbits)�
script_helper)�TESTFN�findfile�unlink�rmtree�temp_dir�temp_cwd�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout�check_warnings�2�di�Zzipfile_datafiles�	_ziptest1�
1q2w3e4r5t�ziptest2dir/_ziptest2�
qawsedrftg�!ziptest2dir/ziptest3dir/_ziptest3�
azsxdcfvgb�-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3�
6y7u8i9o0pcCstd|�j|d�S)N��little)r�to_bytes)�size�r �6/opt/alt/python36/lib64/python3.6/test/test_zipfile.py�getrandbytessr"ccsTtVt��}|V|j|j�WdQRXtj��}|V|j|j�WdQRXdS)N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�fr r r!�	get_files"s
r*c@s�eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9S):�AbstractTestsWithSourceFilecCs&dd�tt�D�|_dj|j�|_dS)NcSs g|]}td|t�fd��qS)z'Zipfile test line %d. random float: %f
�ascii)�bytesr)�.0�ir r r!�
<listcomp>.sz:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data)�clsr r r!�
setUpClass,sz&AbstractTestsWithSourceFile.setUpClassc	Cs&ttd��}|j|j�WdQRXdS)N�wb)�openr�writer6)�self�fpr r r!�setUp3sz!AbstractTestsWithSourceFile.setUpcCsxtj|d|��`}|jtd�|jtt�|jd|j�|jddd�� }x|jD]}|j|�qNWWdQRXWdQRXdS)N�wzanother.name�strfilezwritten-open-w)�mode)�zipfile�ZipFiler;r�writestrr6r:r4)r<r)�compression�zipfp�liner r r!�make_test_archive8sz-AbstractTestsWithSourceFile.make_test_archivecCs4|j||�tj|d|���}|j|jt�|j�|j|jd�|j�|j|jd�|j�tj�}|j	|d�|j
�}|j�}|jt|�d�|j
d|d�|j
d|d�|j
d	|d�|d
j�\}}}	}
|j|d�|jtj|d��|jtj|	d��|j|
tt|j���|j�}|jt|�d
�|j
t|�|j
d|�|j
d|�|j
d|�|j�}dd�|D�}|jt|�d
�|j
t|�|j
d|�|j
d|�|j
d|�x"|D]}
|j|
jt|j���q�WxBtdddfD]2}|j|�}|j|j|�|j|jt|j���q�W|j�WdQRXdS)N�rzanother.namer@)�file�z	File Namer�Modified�Size�z%Y-%m-%dz%H:%M:%S�zwritten-open-wcSsg|]
}|j�qSr )�filename)r.r/r r r!r0fsz8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rHrBrC�assertEqual�readrr6r&�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforP�testzip)r<r)rErFr=�	directory�lines�fn�date�time_r�names�infosr/�nm�infor r r!�zip_testBsL

z$AbstractTestsWithSourceFile.zip_testcCs$xt|�D]}|j||j�q
WdS)N)r*rlrE)r<r)r r r!�
test_basicxsz&AbstractTestsWithSourceFile.test_basicc	Cs�|j||�tj|d|���}g}|jt��&}x|jd�}|s>P|j|�q.WWdQRXg}|jd��&}x|jd�}|sxP|j|�qhWWdQRX|jdj|�|j	�|jdj|�|j	�WdQRXdS)NrI�zanother.namer1)
rHrBrCr:rrR�appendrQr5r6)	r<r)rErF�zipdata1�zipopen1�	read_data�zipdata2�zipopen2r r r!�
zip_open_test|s$

z)AbstractTestsWithSourceFile.zip_open_testcCs$xt|�D]}|j||j�q
WdS)N)r*rurE)r<r)r r r!�	test_open�sz%AbstractTestsWithSourceFile.test_openc
CsFtjt�}|j||j�tj|d|j��}|j|jt	�WdQRXdS)NrI)
�pathlib�Pathr#rurErBrC�assertIsInstancerPr])r<�pathrFr r r!�test_open_with_pathlike�s
z3AbstractTestsWithSourceFile.test_open_with_pathlikecCs~|j||�tj|d|��Z}g}|jt��,}x$|jtdd��}|sDP|j|�q.WWdQRX|jdj	|�|j
�WdQRXdS)NrIrNir1)rHrBrCr:rrRrrorQr5r6)r<r)rErFrprqrrr r r!�zip_random_open_test�sz0AbstractTestsWithSourceFile.zip_random_open_testcCs$xt|�D]}|j||j�q
WdS)N)r*r|rE)r<r)r r r!�test_random_open�sz,AbstractTestsWithSourceFile.test_random_opencCsv|j||�tj|d��@}|jt��*}g}x|jd�}|s<P|j|�q,WWdQRXWdQRX|jdj|�|j	�dS)NrIrNr1���)
rHrBrCr:r�read1rorQr5r6)r<r)rErF�zipopen�zipdatarrr r r!�zip_read1_test�s
"z*AbstractTestsWithSourceFile.zip_read1_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�
test_read1�sz&AbstractTestsWithSourceFile.test_read1cCs�|j||�tj|d��P}|jt��:}g}x.|jd�}|jt|�d�|sLP|j|�q,WWdQRXWdQRX|j	dj
|�|j�dS)NrI�
r1)rHrBrCr:rrZassertLessEqualrWrorQr5r6)r<r)rErFr�r�rrr r r!�zip_read1_10_test�s
"z-AbstractTestsWithSourceFile.zip_read1_10_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�
test_read1_10�sz)AbstractTestsWithSourceFile.test_read1_10cCs�|j||�tj|d��T}|jt��>}d}x2|j�}|s:P||7}|jd�}|sRP||7}q,WWdQRXWdQRX|j||j�dS)NrIr1�d)	rHrBrCr:r�readlinerRrQr6)r<r)rErFr�r6rRr r r!�zip_readline_read_test�s
 z2AbstractTestsWithSourceFile.zip_readline_read_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�test_readline_read�sz.AbstractTestsWithSourceFile.test_readline_readcCsb|j||�tj|d��@}|jt��*}x"|jD]}|j�}|j||�q.WWdQRXWdQRXdS)NrI)rHrBrCr:rr4r�rQ)r<r)rErFr�rGZlinedatar r r!�zip_readline_test�sz-AbstractTestsWithSourceFile.zip_readline_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�
test_readline�sz)AbstractTestsWithSourceFile.test_readlinecCsl|j||�tj|d��J}|jt��}|j�}WdQRXx$t|j|�D]\}}|j||�qFWWdQRXdS)NrI)	rHrBrCr:r�	readlines�zipr4rQ)r<r)rErFr�ZziplinesrG�zipliner r r!�zip_readlines_test�sz.AbstractTestsWithSourceFile.zip_readlines_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�test_readlines	sz*AbstractTestsWithSourceFile.test_readlinescCsd|j||�tj|d��B}|jt��,}x$t|j|�D]\}}|j||�q4WWdQRXWdQRXdS)NrI)rHrBrCr:rr�r4rQ)r<r)rErFr�rGr�r r r!�zip_iterlines_test
s
z.AbstractTestsWithSourceFile.zip_iterlines_testcCs$xt|�D]}|j||j�q
WdS)N)r*r�rE)r<r)r r r!�test_iterlinessz*AbstractTestsWithSourceFile.test_iterlinescCs�tjtd|j��}|jdd�WdQRXtjtd|j��@}|jd��*}|j|jd�d�|j|jd�d�WdQRXWdQRXdS)	z>Check for cases where compressed data is larger than original.r?r@Z12NrIrN�1�2)rBrCr#rErDr:rQrR)r<rFZopenobjr r r!�test_low_compressionsz0AbstractTestsWithSourceFile.test_low_compressioncCs<tjtd�}|jdd|jd�|jd�}|j|j|j�dS)Nr?zb.txtzhello world)�
compress_type)rBrCr#rDrErarQr�)r<rFrkr r r!�test_writestr_compression&s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�xzd	D]r}|d}t|�}tjtj�d|j��D}|jd|�|jdd�� }|j|�}|j	t
|�|�WdQRXWdQRXqWdS)
NrN����@r?�foorI)rNr�r�r�r�)r"rBrCr&r'rErDr:rRrQrW)r<Z	test_sizer`Zjunk�zipfr=Zbufr r r!�test_read_return_size,s

z1AbstractTestsWithSourceFile.test_read_return_sizecHCs�tj�}tj|dd��"}|jd|j|jd�|j�}WdQRX|j�}tj|�}tj|��H}|j	d��2}|j
|d�|jt��|j
�WdQRXWdQRXWdQRXtj|�}tj|��P}|j	d��:}|j
|d�|jt��x|j
d�r�q�WWdQRXWdQRXWdQRXtj|�}tj|��T}|j	d��>}|j
|d�|jt��x|jd��r`�qPWWdQRXWdQRXWdQRXdS)Nr?)rAr@)r��r�)r&r'rBrCrDr6rE�tellrUr:�truncate�assertRaises�EOFErrorrRr)r<r=r�Z
end_offset�zipfiledatar�r r r!�test_truncated_zipfile8s2
&
"
z2AbstractTestsWithSourceFile.test_truncated_zipfilecCs�d}�xvt|�D�]h}tj|d|j��&}|jt|�t|�}|jd|�WdQRXtj|d���}t|�}t|t	�r�|jd||�n|jd||�|jd|�t|j
|��}|jd||�|jd|�|jd	|�|jtjkr�|jd
|�|jd|�|j|��D}t|�}|jd||�|jd|�|jtjk�rF|jd
|�WdQRX|jd
t|��WdQRX|jd
t|��qWdS)Nz	file.namer?zmode='w'rIzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
r*rBrCrEr;r�reprrX�
isinstancer]ra�
ZIP_STOREDr:)r<�fnamer)rFrIr�r r r!�	test_reprVs6
z%AbstractTestsWithSourceFile.test_reprcCstt�tt�dS)N)r	rr#)r<r r r!�tearDownusz$AbstractTestsWithSourceFile.tearDownN) �__name__�
__module__�__qualname__�classmethodr8r>rHrlrmrurvr{r|r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r r r r!r++s8
6

	r+c@sveZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNcCsX|j||�tj|d��6}|jd�}|j|jd�|jd�}|j|jd�WdQRXdS)NrIr@i��zwritten-open-wi�i�)rHrBrCrarQ�
external_attr)r<r)rErF�zinfoZzinfo2r r r!�zip_test_writestr_permissionss

z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs$xt|�D]}|j|tj�q
WdS)N)r*r�rBr�)r<r)r r r!�test_writestr_permissions�sz3StoredTestsWithSourceFile.test_writestr_permissionscCsZtjtdtj��}|jtd�WdQRXtjtdtj��}|j|j�dg�WdQRXdS)Nr?z	/absoluterI�absolute)rBrCr#r�r;rrQr^)r<rFr r r!�test_absolute_arcnames�sz0StoredTestsWithSourceFile.test_absolute_arcnamescCsjtjtdtj��}|jtt�WdQRXtjtdtj��(}|jd|j�|j|j	�tdg�WdQRXdS)z&Test appending to an existing zipfile.r?N�ar@)
rBrCr#r�r;rrDr6rQr^)r<rFr r r!�test_append_to_zip_file�s
z1StoredTestsWithSourceFile.test_append_to_zip_filec4Cs<dd}ttd��}|j|�WdQRXtjtdtj��}|jtt�WdQRXttd��R}|jt|��tj|d��,}|j	|j
�tg�|j	|jt�|j�WdQRXWdQRXttd��$}|j	|jt|��|�|j�}WdQRXt
j|��B}tj|��,}|j	|j
�tg�|j	|jt�|j�WdQRXWdQRXdS)z9Test appending to an existing file that is not a zipfile.sI am not a ZipFile!r�r9Nr��rbrI)r:r#r;rBrCr�r�seekrWrQr^rRr6r&r')r<r6r)rFr��bior r r!�test_append_to_non_zip_file�s (z5StoredTestsWithSourceFile.test_append_to_non_zip_filecCs�tj��6}tj|dtj��}|jtt�WdQRX|j�}WdQRXdd}tt	d��}|j|�|j|�WdQRXtjt	��,}|j
|j�tg�|j
|jt�|j
�WdQRXdS)Nr?sI am not a ZipFile!r�r9)r&r'rBrCr�r;rrUr:r#rQr^rRr6)r<r�rFr�r6r)r r r!�test_read_concatenated_zip_file�s

z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec5CsNtj��6}tj|dtj��}|jtt�WdQRX|j�}WdQRXdd}tt	d��}|j|�|j|�WdQRXtjt	d��&}|j
|j�tg�|jd|j
�WdQRXtt	d��$}|j
|jt|��|�|j�}WdQRXtj|��X}tj|��B}|j
|j�tdg�|j
|jt�|j
�|j
|jd�|j
�WdQRXWdQRXdS)Nr?sI am not a ZipFile!i@Br9r�r@r�)r&r'rBrCr�r;rrUr:r#rQr^rDr6rRrW)r<r�rFr�r6r)r r r!�$test_append_to_concatenated_zip_file�s$

z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filecCsrtjtdtj��}|jtt�WdQRXttd��}|jd�WdQRXtjtd��}|j|tj�WdQRXdS)Nr?r�z
rI)rBrCr#r�r;rr:ry)r<rFr)r r r!�test_ignores_newline_at_end�sz5StoredTestsWithSourceFile.test_ignores_newline_at_endcCs�tjtdtj��}d|_|jtt�WdQRXttd��}|jd�WdQRXtjtd��"}|j|tj�|j	|jd�WdQRXdS)Nr?sthis is a commentr�zabcdef
rI)
rBrCr#r��commentr;rr:ryrQ)r<rFr)r r r!�)test_ignores_stuff_appended_past_comments�szCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentscCsRtjtd��<}|jt�ttd��}|j|jt�|j��WdQRXWdQRXdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r?r�N)rBrCr#r;rr:rQrR)r<rFr)r r r!�test_write_default_name�s
z1StoredTestsWithSourceFile.test_write_default_namec Cs�tjtdd��}|jdd�WdQRXtjtdd��}|jt|jt�WdQRXtjtdd��*}|jt��|jtdd�WdQRXWdQRXdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r?)rAzsomefile.txt�bogusNrI)	rBrCr#rDr��
ValueErrorr;rr:)r<rFr r r!�test_write_to_readonly�sz0StoredTestsWithSourceFile.test_write_to_readonlycCs8tjtd�tjtd��}|jt|jt�WdQRXdS)Nrr?)rr)	�os�utimerrBrCr#r�r�r;)r<rFr r r!�test_add_file_before_1980sz3StoredTestsWithSourceFile.test_add_file_before_1980)r�r�r�rBr�rEr�r�r�r�r�r�r�r�r�r�r�r�r�r r r r!r�zs
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilecCsptjtd��Z}|jtdtj�|jtdtj�|jd�}|jd�}|j|j	tj�|j|j	tj�WdQRXdS)zUCheck that files within a Zip archive can have different
        compression options.r?ZstoremeZ	deflatemeN)
rBrCr#r;rr��ZIP_DEFLATEDrarQr�)r<rFZsinfoZdinfor r r!�test_per_file_compressions

z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�rBr�rEr�r r r r!r�	sr�c@seZdZejZdS)�Bzip2TestsWithSourceFileN)r�r�r�rB�	ZIP_BZIP2rEr r r r!r�sr�c@seZdZejZdS)�LzmaTestsWithSourceFileN)r�r�r�rB�ZIP_LZMArEr r r r!r�sr�c@sHeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�AbstractTestZip64InSmallFilescCs$dd�tdt�D�}dj|�|_dS)Ncss|]}td|d�VqdS)zTest of zipfile line %d.r,N)r-)r.r/r r r!�	<genexpr>*sz;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>r�
)r2r3r5r6)r7r4r r r!r8(sz(AbstractTestZip64InSmallFiles.setUpClassc	CsBtj|_tj|_dt_dt_ttd��}|j|j�WdQRXdS)Ni��	r9)	rB�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr:rr;r6)r<r=r r r!r>.sz#AbstractTestZip64InSmallFiles.setUpcCsPtj|d|dd��,}|jtd�|jtt�|jd|j�WdQRXtj|d|����}|j|jt�|j�|j|jd�|j�|j|jd�|j�tj	�}|j
|�|j�}|j�}|jt
|�d�|jd|d	�|jd
|d	�|jd|d	�|dj�\}}}	}
|j|d�|jtj|d
��|jtj|	d��|j|
tt
|j���|j�}|jt
|�d�|jt|�|jd|�|jd|�|j�}dd�|D�}|jt
|�d�|jt|�|jd|�|jd|�x"|D]}
|j|
jt
|j���q�Wx@tddfD]2}|j|�}|j|j|�|j|jt
|j���qW|j�WdQRXdS)Nr?T)�
allowZip64zanother.namer@rIrOz	File NamerrLrMrNz%Y-%m-%dz%H:%M:%S�cSsg|]
}|j�qSr )rP)r.r/r r r!r0`sz:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)rBrCr;rrDr6rQrRr&rSrTrUrVrWrXrYrZr[r\r]r^r_r`rarPrb)r<r)rErFr=rcrdrerfrgrrhrir/rjrkr r r!rl8sN


z&AbstractTestZip64InSmallFiles.zip_testcCs$xt|�D]}|j||j�q
WdS)N)r*rlrE)r<r)r r r!rmqsz(AbstractTestZip64InSmallFiles.test_basiccCs�tjtd|jdd�}d|_d}x,t|�D] }|jd|d|dd	�q(W|jt|j	��|�|j
�tjtd
|j�}|jt|j	��|�x<t|�D]0}|jd|�jd�}|j|d|dd	�q�W|j
�dS)Nr?T)r�r��zfoo%08dz%dr��9rIr,)
rBrCrrE�debugr2rDrQrWr^�closerR�decode)r<r��numfilesr/�zipf2�contentr r r!�test_too_many_filesus z1AbstractTestZip64InSmallFiles.test_too_many_filescCstjtd|jdd�}d|_d}x,t|�D] }|jd|d|dd	�q(W|jt|j	��|�|j
tj��|jd|d
�WdQRX|jt|j	��|�|j�tjtd|jdd�}d|_|jt|j	��|�|j
tj��|jd|d
�WdQRX|jt|j	��|�|j�tjtd|jdd�}d|_|jt|j	��|�d
}x0t||�D]"}|jd|d|dd	��qTW|jt|j	��|�|j�tjtd|j�}|jt|j	��|�x>t|�D]2}|j
d|�jd�}|j|d|dd	��q�W|j�dS)Nr?F)r�r�r�zfoo%08dz%dr�r�r1r�Tr�rIr,)rBrCrrEr�r2rDrQrWr^r��LargeZipFiler�rRr�)r<r�r�r/Z	numfiles2r�r�r r r!�test_too_many_files_append�sD "z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dS)N)r�rBr�r�r�r	rr#)r<r r r!r��sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r8r>rlrmr�r�r�r r r r!r�$s
9'r�c@s:eZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dS)�StoredTestZip64InSmallFilescCs6tj|d|dd��}|jtj|jtd�WdQRXdS)Nr?F)r�zanother.name)rBrCr�r�r;r)r<r)rErFr r r!�large_file_exception_test�sz5StoredTestZip64InSmallFiles.large_file_exception_testcCs8tj|d|dd��}|jtj|jd|j�WdQRXdS)Nr?F)r�zanother.name)rBrCr�r�rDr6)r<r)rErFr r r!�large_file_exception_test2�sz6StoredTestZip64InSmallFiles.large_file_exception_test2cCs2x,t|�D] }|j|tj�|j|tj�q
WdS)N)r*r�rBr�r�)r<r)r r r!�test_large_file_exception�sz5StoredTestZip64InSmallFiles.test_large_file_exceptioncCs^tjtdtjdd��}|jtd�WdQRXtjtdtj��}|j|j�dg�WdQRXdS)Nr?T)r�z	/absoluterIr�)rBrCr#r�r;rrQr^)r<rFr r r!r��s

z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCs�tjtddd��}|jd|j�WdQRXtjtddd��}|jd�}|j}WdQRXtjtddd��}|jd|j�WdQRXtjtddd��}|jd�}|j|j|�WdQRXdS)Nr?T)r�r@rIr�Zstrfile2)rBrCr#rDr6ra�extrarQ)r<rFr�r�r r r!�test_append�s

z'StoredTestZip64InSmallFiles.test_appendN)r�r�r�rBr�rEr�r�r�r�r�r r r r!r��sr�c@seZdZejZdS)�DeflateTestZip64InSmallFilesN)r�r�r�rBr�rEr r r r!r��sr�c@seZdZejZdS)�Bzip2TestZip64InSmallFilesN)r�r�r�rBr�rEr r r r!r��sr�c@seZdZejZdS)�LzmaTestZip64InSmallFilesN)r�r�r�rBr�rEr r r r!r��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�AbstractWriterTestscCstt�dS)N)r	r#)r<r r r!r��szAbstractWriterTests.tearDownc
Cstd}tjtd|j��V}|jdd�}|j|�|j�|j|j�|j�|j|j�|j	|j
d�|�WdQRXdS)Nscontentr?r()rBrCr#rEr:r;r�rZr%rQrR)r<r6r�r?r r r!�test_close_after_close�s
z*AbstractWriterTests.test_close_after_closecCspd}tjtd|j��R}|jdd�}|j|�|j�|j|j�|j	t
|jd�|j|jd�|�WdQRXdS)Nscontentr?r(r1)
rBrCr#rEr:r;r�rZr%r�r�rQrR)r<r6r�r?r r r!�test_write_after_close�s
z*AbstractWriterTests.test_write_after_closeN)r�r�r�r�r�r�r r r r!r��sr�c@seZdZejZdS)�StoredWriterTestsN)r�r�r�rBr�rEr r r r!r�	sr�c@seZdZejZdS)�DeflateWriterTestsN)r�r�r�rBr�rEr r r r!r�sr�c@seZdZejZdS)�Bzip2WriterTestsN)r�r�r�rBr�rEr r r r!r�sr�c@seZdZejZdS)�LzmaWriterTestsN)r�r�r�rBr�rEr r r r!r�sr�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs |d|kr|j|d|�dS)N�o�c)rX)r<�namer^r r r!�assertCompiledInszPyZipFileTests.assertCompiledIncCs�tj|tjtjtjkd�s$|jd�tjj|d�}y"tj|tjtj	B�}tj
|�Wntk
rr|jd�YnXt|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r��access�W_OK�supports_effective_idsZskipTestrzr5r:�O_WRONLY�O_CREATr��	Exceptionr	)r<rzrP�fdr r r!�requiresWriteAccesss

z"PyZipFileTests.requiresWriteAccessc CsR|jtjjt��t���}tj|d���}t}|jd�r�|j	tj
�}tjdk	r^|j|j	tj��d|krtt
jj|�}n|dd�}|j|�tjj|�}|j||j��|j||j��WdQRXWdQRXt��x}tj|d��`}t}|jd�r�|dd�}|j|d�ddtjj|�f}|j||j��|j||j��WdQRXWdQRXdS)	Nr?z.pyc�__pycache__rNZtestpackagez%s/%sr~r~)rr�rz�dirname�__file__rrB�	PyZipFile�endswithrY�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInr^r�)r<�trFreZ
path_splitZbnr r r!�test_write_pyfile+s,


$
z PyZipFileTests.test_write_pyfilecCsxddl}tjj|j�}|j|�t��H}tj|d��0}|j	|�|j
�}|jd|�|jd|�WdQRXWdQRXdS)Nrr?zemail/__init__.pyzemail/mime/text.py)�emailr�rzrrrrrBrrr^r�)r<r�
packagedirrrFrhr r r!�test_write_python_packageIs

z(PyZipFileTests.test_write_python_packagec.Csddl}tjj|j�}|j|�t���}tj|d���}t	��}|j
|�WdQRX|j�}|jd|k�t	��}|j
|dd�d�WdQRX|j�}|jd|k�dd�}t	��*}|j
t��|j
||d�WdQRXWdQRX|j�}|r�t|�|jd|k�WdQRXWdQRXdS)	Nrr?�SyntaxErrorcSsdS)NFr )Zwhateverr r r!�<lambda>gszCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>)�
filterfunccSstjj|�jd�S)NZbad)r�rzr�
startswith)rzr r r!�filterlszAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)r(r�rzrrrrrBrrrrUrZ�assertWarns�UserWarning�print)r<r(rrrFZ	reportSIOZ	reportStrrr r r!�"test_write_filtered_python_packageWs&
"z1PyZipFileTests.test_write_filtered_python_packagecCs�ddl}tjj|j�}|j|�dnd}d}t��T}tj|d|d��8}|j	|�|j
�}|jd||�|jd||�WdQRXWdQRXdS)	NrTrNz.pycr?)�optimizezemail/__init__zemail/mime/text)rr�rzrrrrrBrrr^rX)r<rrZoptlevelZextrrFrhr r r!�test_write_with_optimizationus

z+PyZipFileTests.test_write_with_optimizationc,Cs�tjt�z�ttjjtd�d��}|jd�WdQRXttjjtd�d��}|jd�WdQRXttjjtd�d��}|jd�WdQRXt��T}tj	|d��<}|j
t�|j�}|jd|�|jd|�|j
d|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr?z
print(42)
zmod2.pyzprint(42 * 42)
zmod2.txtzbla bla bla
)r��mkdirr#r:rzr5r;rrBrrr^r�rr
)r<r=rrFrhr r r!�test_write_python_directory�s

$z*PyZipFileTests.test_write_python_directoryc&Cs�tjt�z�ttjjtd�d��}|jd�WdQRXttjjtd�d��}|jd�WdQRXt��P}tj	|d��8}|j
tdd�d�|j�}|jd|�|j
d|�WdQRXWdQRXWdtt�XdS)	Nzmod1.pyr?z
print(42)
zmod2.pyzprint(42 * 42)
cSs|jd�S)Nzmod2.py)r)rer r r!r�szEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>)r)r�r"r#r:rzr5r;rrBrrr^r�rr
)r<r=rrFrhr r r!�$test_write_python_directory_filtered�s
$z3PyZipFileTests.test_write_python_directory_filteredcCsft��V}tj|d��>}ttd��}|jd�WdQRX|jt|jt�t	t�WdQRXWdQRXdS)Nr?z!most definitely not a python file)
rrBrr:rr;r��RuntimeErrorrr	)r<rrFr)r r r!�test_write_non_pyfile�s
z$PyZipFileTests.test_write_non_pyfilec&Cs�tjt�z�ttjjtd�d��}|jd�WdQRXt��t}tj	|d��\}t
��}|jtjjtd��WdQRX|jd|j
��|j�}|jd|�|jd|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr?zBad syntax in python file
rzmod1.pyc)r�r"r#r:rzr5r;rrBrrrrXrUr^rr
)r<r=rrF�srhr r r!�test_write_pyfile_bad_syntax�s
$z+PyZipFileTests.test_write_pyfile_bad_syntaxcCs�tjt�z�ttjjtd�d��}|jd�WdQRXt��F}tj	|d��.}|j
tjt�d�|j
�}|jd|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr?z
print(42)
)r�r"r#r:rzr5r;rrBrrrwrxr^r�r
)r<r=rrFrhr r r!�test_write_pathlike�s
$z"PyZipFileTests.test_write_pathlikeN)r�r�r�r�rrrrr!r#r$r&r(r)r r r r!r�s
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zejejjdkd�dd��Zejejjdkd�dd ��Zd!d"�Zd#S)$�ExtractTestscCs>tjtdtj��$}xtD]\}}|j||�qWWdQRXdS)Nr?)rBrCr#r��SMALL_TEST_DATArD)r<rF�fpath�fdatar r r!�make_test_file�szExtractTests.make_test_filecCs�t���|j�tjtd��~}xvtD]n\}}|j|�}tjj	tj
�|�}tjj|�}|j||�t
|d��}|j|j�|j��WdQRXt|�q$WWdQRXWdQRXdS)NrIr�)rr.rBrCr#r+�extractr�rzr5�getcwd�normpathrQr:�encoderRr	)r<rFr,r-�writtenfile�correctfiler)r r r!�test_extract�s
zExtractTests.test_extractcCs�|j�tjtd���}x�tD]z\}}|j||�}tjj||�}tjj	|�}|j
tjj||�||f�t|d��}|j
|j�|j��WdQRXt|�qWWdQRXtt�dS)NrIr�)r.rBrCr#r+r/r�rzr5r1rZ�samefiler:rQr2rRr	)r<�targetrFr,r-r3r4r)r r r!�_test_extract_with_target�sz&ExtractTests._test_extract_with_targetc	Cs t��}|j|�WdQRXdS)N)rr8)r<�extdirr r r!�test_extract_with_targetsz%ExtractTests.test_extract_with_targetc
Cs&t��}|jtj|��WdQRXdS)N)rr8rwrx)r<r9r r r!�!test_extract_with_target_pathlikesz.ExtractTests.test_extract_with_target_pathlikecCs�t���|j�tjtd��d}|j�xTtD]L\}}tjj	tj
�|�}t|d��}|j|j
�|j��WdQRXt|�q,WWdQRXWdQRXdS)NrIr�)rr.rBrCr#�
extractallr+r�rzr5r0r:rQr2rRr	)r<rFr,r-�outfiler)r r r!�test_extract_allszExtractTests.test_extract_allcCs�|j�tjtd��b}|j|�xPtD]H\}}tjj||�}t	|d��}|j
|j�|j��WdQRXt
|�q&WWdQRXt
t�dS)NrIr�)r.rBrCr#r<r+r�rzr5r:rQr2rRr	)r<r7rFr,r-r=r)r r r!�_test_extract_all_with_targets
z*ExtractTests._test_extract_all_with_targetc	Cs t��}|j|�WdQRXdS)N)rr?)r<r9r r r!�test_extract_all_with_target*sz)ExtractTests.test_extract_all_with_targetc
Cs&t��}|jtj|��WdQRXdS)N)rr?rwrx)r<r9r r r!�%test_extract_all_with_target_pathlike.sz2ExtractTests.test_extract_all_with_target_pathlikec
Cs<|jtjj|��t|d��}|j|j�|�WdQRXdS)Nr�)rZr�rz�isfiler:rQrR)r<rPr�r)r r r!�
check_file2szExtractTests.check_filecCsBtjj}|j|dd�d�|j|dd�d�|j|dd�d�dS)	Nz,,?,C:,foo,bar/z�,z_,C_,foo,bar/zza\b,c<d>e|f"g?h*iza\b,c_d_e_f_g_h_iz../../foo../../ba..r�/z	foo/ba..r)rBrCZ_sanitize_windows_namerQ)r<Zsanr r r!�test_sanitize_windows_name7sz'ExtractTests.test_sanitize_windows_namec	Cs"d
ddd
ddddg}|j|�dS)N�
../foo/bar�foo/bar�
foo/../bar�
foo/../../bar�
foo/bar/..�./../foo/bar�/foo/bar�/foo/../bar�/foo/../../bar)rGrH)rIrH)rJrH)rKrH)rLrH)rMrH)rNrH)rOrH)�_test_extract_hackers_arcnames)r<Zcommon_hacknamesr r r!�*test_extract_hackers_arcnames_common_cases>sz7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCs8ddddddd d!d"d#d$d%d&d'd(d)d*d+d,g}|j|�dS)-z>Test combination of path fixing and windows name sanitization.�
..\foo\bar�foo/bar�..\/foo\/bar�foo/\..\/bar�foo\/../\bar�	C:foo/bar�
C:/foo/bar�C://foo/bar�
C:\foo\bar�//conky/mountpoint/foo/bar�\\conky\mountpoint\foo\bar�///conky/mountpoint/foo/bar�conky/mountpoint/foo/bar�\\\conky\mountpoint\foo\bar�//conky//mountpoint/foo/bar�\\conky\\mountpoint\foo\bar�//?/C:/foo/bar�\\?\C:\foo\bar�C:/../C:/foo/bar�
C_/foo/bar�a:b\c<d>e|f"g?h*i�b/c_d_e_f_g_h_i�../../foo../../ba..r�	foo/ba..rN)rSrT)rUrT)rVrT)rWrT)rXrT)rYrT)rZrT)r[rT)r\rT)r]rT)r^r_)r`r_)rar_)rbr_)rcrT)rdrT)rerf)rgrh)rirj)rP)r<Zwindows_hacknamesr r r!�*test_extract_hackers_arcnames_windows_onlyKs(z7ExtractTests.test_extract_hackers_arcnames_windows_onlyrEzRequires / as path separator.cCsdddg}|j|�dS)	N�	//foo/bar�foo/bar�../../foo../../ba..r�foo../ba..r�
foo/..\bar)rlrm)rnro)rprp)rP)r<Zposix_hacknamesr r r!�(test_extract_hackers_arcnames_posix_onlyesz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc
'Cs��x�|D�]�\}}d|j�}tjtdtj��&}tj�}||_d|_|j||�WdQRX|j	t
jd�}t
jj
ddd�}t
jj
|f|jd���}tjtd	��,}|j||�}	|j|	|d
||	|fd�WdQRX|j||�td�tjtd	��}|j|�WdQRX|j||�td�t
jj
t
j�f|jd���}tjtd	��$}|j|�}	|j|	|d|d�WdQRX|j||�t|jd�d
�tjtd	��}|j�WdQRX|j||�t|jd�d
�tt�qWdS)Nsfoobarr?i�r�rEr7ZsubdirZsubsubrIzextract %r: %r != %r)�msgz
extract %rri�)r2rBrCr#r��ZipInforPr�rD�replacer�r	rzr5rYr/rQrCr
r<r0r	)
r<Z	hacknamesZarcnameZ	fixednamer�rFr�Z
targetpathr4r3r r r!rPnsB
z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�r.r5r8r:r;r>r?r@rArCrFrQ�unittestZskipIfr�rzr	rkrqrPr r r r!r*�s

	r*c@s eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dAdB�Z$dCdD�Z%dES)F�
OtherTestscCs�tjtdtj��J}|jdd�|jt��|jdd�WdQRX|j|j�dgd�WdQRXtjtd���}|j	�}d}x.|D]&}|j
|��}||j�7}WdQRXq�W|j|dd	h�d}x|D]}||j|�7}q�W|j|dd	h�WdQRXdS)
Nr?r�r��bar�rIr1sfoobarsbarfoo)
rBrCr#r�rDrrrQr^r_r:rRrX)r<rFrir6rkr�r r r!�test_open_via_zip_info�s  

z!OtherTests.test_open_via_zip_infocCsNtjtd��8}x0dD](}tj|�}|jdO_|j||�qWWdQRXdS)Nr?Zabcdefghijklmnopr)rBrCr#rsZ	flag_bitsrD)r<Zorig_zipr6r�r r r!�-test_writestr_extended_local_header_issue1202�s


z8OtherTests.test_writestr_extended_local_header_issue1202cCs�tjtd��2}x*tD]"\}}|j||�|j|jd�qWWdQRX|j|jd�tjtd��}|j|jd�WdQRX|j|jd�dS)z8Check that the zipfile is closed after the 'with' block.r?zzipfp is not openNzzipfp is not closedrI)rBrCr#r+rDZassertIsNotNoner=�assertIsNone)r<rFr,r-r r r!�
test_close�szOtherTests.test_closecCs�tjtd��$}xtD]\}}|j||�qWWdQRXy$tjtd��}tj��WdQRXWn$tjk
r~|j|jd�YnXdS)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r?NrIzzipfp is not closed)rBrCr#r+rD�
BadZipFiler{r=)r<rFr,r-Zzipfp2r r r!�test_close_on_exception�sz"OtherTests.test_close_on_exceptioncCs d}|jttjtj|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rI)r��NotImplementedErrorrBrCr&r')r<r6r r r!�test_unsupported_version�s
z#OtherTests.test_unsupported_versionc
CsBtd�}tj|��&}x|j�D]}|j|�j�qWWdQRXdS)Nzzip_cp437_header.zip)rrBrCr^r:r�)r<r�rFr�r r r!�test_read_unicode_filenames�sz&OtherTests.test_read_unicode_filenamescCs�tjtd��4}|jdd�|jdd�|j|j�djt�WdQRXtjtd��.}|j|j	djd�|j|j	djd�WdQRXdS)Nr?zfoo.txtzTest for unicode filenameuö.txtrrIrN)
rBrCrrDryr_rPr]rQ�filelist)r<�zfr r r!�test_write_unicode_filenames�s z'OtherTests.test_write_unicode_filenamescCs�tt�d}d}tjtdtj��}|j||�WdQRX|jt��tjtdtj�WdQRXtjtd��*}|j|j	�|g�|j|j
|�|�WdQRXdS)z&Test exclusive creating a new zipfile.ztestfile.txts#hello, world. this is some content.�xNrI)r	r#rBrCr�rDr��FileExistsErrorrQr^rR)r<rPr�rFr r r!�test_exclusive_create_zip_file�sz)OtherTests.test_exclusive_create_zip_filecCs�tjjt�rtjt�d}d}y(tjtd��}|j||�WdQRXWntk
rd|j	d�YnX|j
tjjt��tjtd��}|j|j|�|�WdQRXdS)Nztestfile.txts#hello, world. this is some content.r�z1Could not append data to a non-existent zip file.rI)
r�rz�existsrr	rBrCrD�OSError�failrZrQrR)r<rPr�r�r r r!�(test_create_non_existent_file_for_append�s
z3OtherTests.test_create_non_existent_file_for_appendcCsJttd��}|jd�WdQRXytjt�}Wntjk
rDYnXdS)Nr?zthis is not a legal zip file
)r:rr;rBrCr})r<r=r�r r r!�test_close_erroneous_filesz$OtherTests.test_close_erroneous_filecCs�ttd��}|jd�WdQRX|jtjt��|jtjtjt���ttd��}|jtj|��WdQRXtj	�}|jd�|jtj|��|j
dd�|jtj|��dS)z;Check that is_zipfile() correctly identifies non-zip files.r?zthis is not a legal zip file
Nr�sthis is not a legal zip file
r)r:rr;r$rB�
is_zipfilerwrxr&r'r�)r<r=r r r!�test_is_zip_erroneous_files
z%OtherTests.test_is_zip_erroneous_filecCsttj�}tj|dd��}|jdd�WdQRX|j�}x8tt|��D](}tj|d|��}|jtj	tj|�qDWdS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r?)rAzfoo.txtsO, for a Muse of Fire!N)
r&r'rBrCrDrUr2rWr�r})r<r=r�r��Nr r r!�test_damaged_zipfile,szOtherTests.test_damaged_zipfilecCs�tjtdd��}|jdd�WdQRX|jtjt��ttd��*}|jtj|��|jdd�|j�}WdQRXt	j
�}|j|�|jtj|��|jdd�|jtj|��dS)z7Check that is_zipfile() correctly identifies zip files.r?)rAzfoo.txtsO, for a Muse of Fire!Nr�r)rBrCrrDrZr�r:r�rRr&r'r;)r<r�r=Zzip_contentsr r r!�test_is_zip_valid_file:s
z!OtherTests.test_is_zip_valid_filecCs|jttjt�dS)N)r�r�rBrCr)r<r r r!�%test_non_existent_file_raises_OSErrorMsz0OtherTests.test_non_existent_file_raises_OSErrorcCsZttd�}|j�|jtjtjt�ttd��}|jd�WdQRX|jtjtjt�dS)Nr?z
short file)r:rr�r�rBr}rCr;)r<r)r=r r r!�!test_empty_file_raises_BadZipFile[s
z,OtherTests.test_empty_file_raises_BadZipFilecCs�tj�}tj|dd��}|jdd�WdQRX|jt|jd�|jt|jd�|jt|j	�|jt|jdd�tt
d��}|jd�WdQRX|jt|jt
�dS)	z?Verify that testzip() doesn't swallow inappropriate exceptions.r?)rAzfoo.txtzO, for a Muse of Fire!Nz	bogus.txtr�zzipfile test data)r&r'rBrCrDr�r�rRr:rbrr;)r<r6r�r)r r r!�!test_closed_zip_raises_ValueErrordsz,OtherTests.test_closed_zip_raises_ValueErrorcCs|jttjtd�dS)z>Check that bad modes passed to ZipFile constructor are caught.�qN)r�r�rBrCr)r<r r r!�test_bad_constructor_modevsz$OtherTests.test_bad_constructor_modecCs�tjtdd��}|jdd�WdQRXtjtdd��F}|jd�|jt|jdd�|jt|jdd�|jt|jdd	�WdQRXdS)
z7Check that bad modes passed to ZipFile.open are caught.r?)rAzfoo.txtzO, for a Muse of Fire!NrIr��UZrU)rBrCrrDrRr�r�r:)r<r�r r r!�test_bad_open_modezs
zOtherTests.test_bad_open_modecCsttjtdd��\}|jdd�|jd��:}x"tt�D]}|j|jd�d�q2W|j|j�d�WdQRXWdQRXdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r?)rAzfoo.txtzO, for a Muse of Fire!rr1sO, for a Muse of Fire!N)	rBrCrrDr:r2r3rQrR)r<r�r)r/r r r!�
test_read0�szOtherTests.test_read0cCs0tjtdd��}|jt|jdd�WdQRXdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r?)rAzfoo.txtrIN)rBrCrr��KeyErrorr:)r<r�r r r!�test_open_non_existent_item�sz&OtherTests.test_open_non_existent_itemcCs|jttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.r?rNNr~)r�rrBrCr)r<r r r!�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modecCs6d}tjtj|�d��}|jt|jd�WdQRXdS)NsfPK.�C�@xPK..�C�@�xPK/!rIr�)rBrCr&r'r�rr:)r<r6r�r r r!�test_unsupported_compression�sz'OtherTests.test_unsupported_compressionc
Cs<tjtdd��$}|jdd�|j|j�dg�WdQRXdS)zLCheck that a filename containing a null byte is properly
        terminated.r?)rAzfoo.txtqqqsO, for a Muse of Fire!zfoo.txtN)rBrCrrDrQr^)r<r�r r r!�test_null_byte_in_filename�sz%OtherTests.test_null_byte_in_filenamecCs<|jtjd�|jtjd�|jtjd�|jtjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rQrBZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locator)r<r r r!�test_struct_sizes�szOtherTests.test_struct_sizesclCs�tjtdd�� }|j|jd�|jdd�WdQRXtjtdd��}|j|jd�WdQRXd}tjtdd��}||_|jdd�WdQRXtjtdd��}|j|j|�WdQRXd	jd
d�td�D��}|jd�}tjtdd��}||_|jdd�WdQRXtjtdd��}|j|j|�WdQRXtjtdd��2}|j	t
��|d|_WdQRX|jdd�WdQRXtjtdd��}|j|j|�WdQRXtjtdd��}d|_|jdd�WdQRXtjtdd��}d|_WdQRXtjtdd��}|j|jd�WdQRXtjtdd��}d|_|jdd�WdQRXtjtdd��}d|_WdQRXtjtdd��}|j|jd�WdQRXdS)z8Check that comments on the archive are handled properly.r?)rAr1zfoo.txtzO, for a Muse of Fire!NrIs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]}d|dd�qS)z%dr�r�r )r.r/r r r!r0�sz,OtherTests.test_comments.<locals>.<listcomp>rNr�r,soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter commentii��)rBrCrrQr�rDr5r2r2rr)r<r�Zzipfrr�Zcomment2r r r!�
test_comments�sL
zOtherTests.test_commentscCsHtjtdtj��.}|jdd�|jt��d|_WdQRXWdQRXdS)Nr?zfoo.txtzO, for a Muse of Fire!zthis is an error)rBrCrr�rDr��	TypeErrorr�)r<r�r r r!�test_unicode_comment�szOtherTests.test_unicode_commentcCsXtjtdtj��}|j|j�d|_WdQRXtjtd��}|j|jd�WdQRXdS)Nr�sthis is a commentrI)rBrCrr�r$r�r�rQ)r<r�r r r!�$test_change_comment_in_empty_archive�s
z/OtherTests.test_change_comment_in_empty_archivecCs�tjtdtj��}|jdd�WdQRXtjtdtj��}|j|j�d|_WdQRXtjtd��}|j|jd�WdQRXdS)Nr?zfoo.txtzO, for a Muse of Fire!r�sthis is a commentrI)	rBrCrr�rDrZr�r�rQ)r<r�r r r!�'test_change_comment_in_nonempty_archive�sz2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|j�ytjtdd�}Wn tjk
rH|jd�YnXtjtdd�}|j�ytjtdd�}Wn|jd�YnXdS)Nr?)rArIz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)rBrCrr�r}r�)r<r�r r r!�test_empty_zipfileszOtherTests.test_empty_zipfilecCs*ttd�}|j�|jtjtjtd�dS)Nr?rI)r:rr�r�rBr}rC)r<r)r r r!�test_open_empty_files
zOtherTests.test_open_empty_filec
Cs|jttjdd�dS)NZ	seventies�rNr)r�rNrNrrr)r�r�rBrs)r<r r r!�test_create_zipinfo_before_1980sz*OtherTests.test_create_zipinfo_before_1980c	Cs4d}tjtj|�d��}|j|j��WdQRXdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rIN)rBrCr&r'r{rb)r<r�r�r r r!�#test_zipfile_with_short_extra_field!sz.OtherTests.test_zipfile_with_short_extra_fieldcKCs�d}d}d}tjtdtj���}|jddd��}|j|�WdQRX|jddd���}|jt��|jddd�WdQRX|jt��|jdd	d�WdQRX|jt��|jd
d�WdQRX|jt��|jt	d�WdQRX|jt��|j
�WdQRX|j|�WdQRX|jd
dd��}|j|�WdQRXWdQRXtjtd	��R}|j|jd�|�|j|jd�|�|j|jd
�|�|j|j
�ddd
g�WdQRXdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer?r�)rArwZhandlerIr]ZabcderJZbaz)rBrCr#r�r:r;r�r�rDrr�rQrRr^)r<Zmsg1Zmsg2Zmsg3r�Zw2�w1r r r!�test_open_conflicting_handles0s2z(OtherTests.test_open_conflicting_handlescCstt�tt�dS)N)r	rr#)r<r r r!r�MszOtherTests.tearDownN)&r�r�r�ryrzr|r~r�r
r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r r r r!rv�sD


	
7	rvc@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestsc
Cs:|j}tjtj|�dd��}|jd|j��WdQRXdS)z>Tests that files with bad CRCs return their name from testzip.rI)rA�afileN)�zip_with_bad_crcrBrCr&r'rQrb)r<r�r�r r r!�test_testzip_with_bad_crcSsz-AbstractBadCrcTests.test_testzip_with_bad_crcc,Cs�|j}tjtj|�dd��}|jtj|jd�WdQRXtjtj|�dd��.}|jdd��}|jtj|j�WdQRXWdQRXtjtj|�dd��L}|jdd��4}d|_	|jtj��x|jd�r�q�WWdQRXWdQRXWdQRXdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rI)rAr�Nrx)
r�rBrCr&r'r�r}rRr:Z
MIN_READ_SIZE)r<r�r�Zcorrupt_filer r r!�test_read_with_bad_crc[s$z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r�r�r r r r!r�Rsr�c@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�rBr�rEr�r r r r!r�qsr�c@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�rBr�rEr�r r r r!r�}sr�c@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�rBr�rEr�r r r r!r��sr�c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�rBr�rEr�r r r r!r��sr�c@sXeZdZdZdZdZdZddZdd�Zd	d
�Z	dd�Z
d
d�Zedd��Z
dd�ZdS)�DecryptionTestsz�Check that ZIP decryption works. Since the library does not
    support encryption at the moment, we use a pre-generated encrypted
    ZIP file.s�PKn�i.#y�?&test.txt��gly|�-�=�y�r�Z}Lg���|�䋺�)���lPKn�i.#y�?& ��test.txtPK6Ls�PK	�}38xu��zeroUT	֋�Gڋ�GUx���<M�a�X�Y&�{oEם���PKxu��PK	�}38xu��
��zeroUT֋�GUxPK?[szipfile.py encryption test�icCsdttd��}|j|j�WdQRXtjtd�|_ttd��}|j|j�WdQRXtjtd�|_	dS)Nr9rI)
r:rr;r6rBrCr�r#�data2�zip2)r<r=r r r!r>�szDecryptionTests.setUpcCs,|jj�tjt�|jj�tjt�dS)N)r�r�r�r	rr�r#)r<r r r!r��s


zDecryptionTests.tearDowncCs(|jt|jjd�|jt|jjd�dS)Nztest.txt�zero)r�r%r�rRr�)r<r r r!�test_no_password�sz DecryptionTests.test_no_passwordcCs@|jjd�|jt|jjd�|jjd�|jt|jjd�dS)Nsperlztest.txtr�)r��setpasswordr�r%rRr�)r<r r r!�test_bad_password�sz!DecryptionTests.test_bad_passwordcCsH|jjd�|j|jjd�|j�|jjd�|j|jjd�|j�dS)Nspythonztest.txts12345r�)r�r�rQrR�plainr��plain2)r<r r r!�test_good_password�sz"DecryptionTests.test_good_passwordcCsV|jt|jjd�|jt|jjdd�|jt|jjddd�|jt|jjddd�dS)NZunicodeztest.txt�python)�pwd)r�r�r�r�rRr:r/)r<r r r!�test_unicode_password�sz%DecryptionTests.test_unicode_passwordN)r�r�r��__doc__r6r�r�r�r>r�r�r�r
r�r�r r r r!r��s	r�c@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�"AbstractTestsWithRandomBinaryFilescCs6tdd�dtdd�}djdd�t|�D��|_dS)Nr��@irNr1css&|]}tjdt�tdd��VqdS)z<fi�Ni���)�structZpackrr)r.r/r r r!r��sz@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr5r2r6)r7Z	datacountr r r!r8�s
z-AbstractTestsWithRandomBinaryFiles.setUpClassc	Cs&ttd��}|j|j�WdQRXdS)Nr9)r:rr;r6)r<r=r r r!r>�sz(AbstractTestsWithRandomBinaryFiles.setUpcCstt�tt�dS)N)r	rr#)r<r r r!r��sz+AbstractTestsWithRandomBinaryFiles.tearDownc
Cs6tj|d|��}|jtd�|jtt�WdQRXdS)Nr?zanother.name)rBrCr;r)r<r)rErFr r r!rH�sz4AbstractTestsWithRandomBinaryFiles.make_test_archivecCsl|j||�tj|d|��H}|jt�}|jt|�t|j��|j||j�|j|jd�|j�WdQRXdS)NrIzanother.name)rHrBrCrRrrQrWr6)r<r)rErF�testdatar r r!rls
z+AbstractTestsWithRandomBinaryFiles.zip_testcCs$xt|�D]}|j||j�q
WdS)N)r*rlrE)r<r)r r r!�	test_read
sz,AbstractTestsWithRandomBinaryFiles.test_readcCs�|j||�tj|d|���}g}|jt��&}x|jd�}|s>P|j|�q.WWdQRXg}|jd��&}x|jd�}|sxP|j|�qhWWdQRXdj|�}	|jt	|	�t	|j
��|j|	|j
�dj|�}
|jt	|
�t	|j
��|j|
|j
�WdQRXdS)NrIrnzanother.namer1)rHrBrCr:rrRror5rQrWr6)r<r)rErFrprqrrrsrtZ	testdata1Z	testdata2r r r!rus,



z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs$xt|�D]}|j||j�q
WdS)N)r*rurE)r<r)r r r!rv+sz,AbstractTestsWithRandomBinaryFiles.test_opencCs�|j||�tj|d|��t}g}|jt��,}x$|jtdd��}|sDP|j|�q.WWdQRXdj|�}|j	t
|�t
|j��|j	||j�WdQRXdS)NrIrNir1)rHrBrCr:rrRrror5rQrWr6)r<r)rErFrprqrrr�r r r!r|/s
z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs$xt|�D]}|j||j�q
WdS)N)r*r|rE)r<r)r r r!r}@sz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r8r>r�rHrlr�rurvr|r}r r r r!r��s
r�c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesN)r�r�r�rBr�rEr r r r!r�Esr�c@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesN)r�r�r�rBr�rEr r r r!r�Isr�c@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesN)r�r�r�rBr�rEr r r r!r�Nsr�c@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesN)r�r�r�rBr�rEr r r r!r�Ssr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS)Nr)r=�offset)r<r=r r r!�__init__[szTellable.__init__cCs|jj|�}|j|7_|S)N)r=r;r�)r<r6�nr r r!r;_szTellable.writecCs|jS)N)r�)r<r r r!r�dsz
Tellable.tellcCs|jj�dS)N)r=�flush)r<r r r!r�gszTellable.flushN)r�r�r�r�r;r�r�r r r r!r�Zsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dS)N)r=)r<r=r r r!r�kszUnseekable.__init__cCs|jj|�S)N)r=r;)r<r6r r r!r;nszUnseekable.writecCs|jj�dS)N)r=r�)r<r r r!r�qszUnseekable.flushN)r�r�r�r�r;r�r r r r!r�jsr�c@s$eZdZdd�Zdd�Zdd�ZdS)�UnseekableTestsc'Cs�xdd�ttfD]�}|j|d���tj�}|jd�tj|�}tj||�dtj	��}|j
dd�|j
dd	�WdQRX|j|j�dd
�d�tj|dd
��R}|j
d��}|j|j�d�WdQRX|j
d��}|j|j�d	�WdQRXWdQRXWdQRXqWdS)NcSs|S)Nr )r)r r r!rvsz/UnseekableTests.test_writestr.<locals>.<lambda>)�wrappersabcr?�oness111�twoss222rKsabcPKrI)rA)r�r��subTestr&r'r;�BufferedWriterrBrCr�rDrQrUr:rR)r<r�r)�bfrFr��zopenr r r!�
test_writestrus

zUnseekableTests.test_writestrc5CsX�xPdd�ttfD�]<}|j|d���$tj�}|jd�tj|�}tj||�dtj	��j}|j
tt�t
td��}|jd�WdQRX|jtd�t
td��}|jd	�WdQRX|jtd
�WdQRX|j|j�dd�d�tj|d
d��R}|j
d��}|j|j�d�WdQRX|j
d
��}|j|j�d	�WdQRXWdQRXWdQRXqWdS)NcSs|S)Nr )r)r r r!r�sz,UnseekableTests.test_write.<locals>.<lambda>)r�sabcr?r9s111r�s222r�rKsabcPKrI)rA)r�r�r�r&r'r;r�rBrCr��
addCleanupr	rr:rQrUrR)r<r�r)r�rF�f2r�r�r r r!�
test_write�s&

zUnseekableTests.test_writec'Cs�xdd�ttfD]�}|j|d���tj�}|jd�tj|�}tj||�dtj	��J}|j
dd��}|jd�WdQRX|j
dd��}|jd	�WdQRXWdQRX|j|j�dd
�d�tj|��*}|j|j
d�d�|j|j
d�d	�WdQRXWdQRXqWdS)NcSs|S)Nr )r)r r r!r�sz1UnseekableTests.test_open_write.<locals>.<lambda>)r�sabcr?r�s111r�s222rKsabcPK)r�r�r�r&r'r;r�rBrCr�r:rQrUrR)r<r�r)r�r�r�r r r!�test_open_write�s

zUnseekableTests.test_open_writeN)r�r�r�r�r�r�r r r r!r�tsr�c@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)Ns111i's222)r"�data1r�)r7r r r!r8�sz!TestsWithMultipleOpens.setUpClassc
Cs<tj|dtj��"}|jd|j�|jd|j�WdQRXdS)Nr?r�r�)rBrCr�rDr�r�)r<r)rFr r r!rH�sz(TestsWithMultipleOpens.make_test_archivecCs�x�t|�D]�}|j|�tj|dd��x}|jd��H}|jd��2}|jd�}|jd�}||j�7}||j�7}WdQRXWdQRX|j||�|j||j�WdQRXq
WdS)NrI)rAr�i�)r*rHrBrCr:rRrQr�)r<r)r��zopen1�zopen2r�r�r r r!�test_same_file�s


 z%TestsWithMultipleOpens.test_same_filecCs�x�t|�D]�}|j|�tj|dd��z}|jd��H}|jd��2}|jd�}|jd�}||j�7}||j�7}WdQRXWdQRX|j||j�|j||j�WdQRXq
WdS)NrI)rAr�r�i�)	r*rHrBrCr:rRrQr�r�)r<r)r�r�r�r�r�r r r!�test_different_file�s


 z*TestsWithMultipleOpens.test_different_filecCs�x�t|�D]�}|j|�tj|dd��z}|jd��H}|jd�}|jd��(}|jd�}||j�7}||j�7}WdQRXWdQRX|j||j�|j||j�WdQRXq
WdS)NrI)rAr�i�r�)	r*rHrBrCr:rRrQr�r�)r<r)r�r�r�r�r�r r r!�test_interleaved�s


 z'TestsWithMultipleOpens.test_interleavedcCs�x�t|�D]�}|j|�tj��j}tj|d��&}|j|jd��}|j|jd��}WdQRX|jd�}|jd�}||j�7}||j�7}WdQRX|j	||j
�|j	||j�q
WdS)NrIr�r�i�)r*rH�
contextlib�	ExitStackrBrC�
enter_contextr:rRrQr�r�)r<r)�stackr�r�r�r�r�r r r!�test_read_after_close�s



z,TestsWithMultipleOpens.test_read_after_closecCs�x�t|�D]�}tj|dtj��B}|jd|j�|jd|j�|jd��}|jd�}WdQRXWdQRX|j	||jdd��tj|d��}|jd�}|jd�}WdQRX|j	||j�|j	||j�q
WdS)Nr?r�r�i�rI)
r*rBrCr�rDr�r�r:rRrQ)r<r)r�r�r�r�r r r!�test_read_after_write�s
z,TestsWithMultipleOpens.test_read_after_writecCs�x�t|�D]�}tj|dtj��B}|jd|j�|jd��}|jd�|jd|j�WdQRXWdQRXtj|d��}|jd�}|jd�}WdQRX|j	||j�|j	||j�q
WdS)Nr?r�i�r�rI)
r*rBrCr�rDr�r:rRr�rQ)r<r)r�r�r�r�r r r!�test_write_after_read�s
"
z,TestsWithMultipleOpens.test_write_after_readcCs�|jt�tjtdd��8}x0td�D]$}|jd�|jd��}WdQRXq$WWdQRXttj��}|j	|j
�d�WdQRXdS)NrI)rAr�r�)rHr#rBrCr2rRr:r��devnullZ
assertLess�fileno)r<r�r�r�r)r r r!�test_many_openss

z&TestsWithMultipleOpens.test_many_opensc&Cs�tjtdtj��}|jd|j�WdQRXtjtdtj��X}|jdd��@}|jd�}|jdd��}|j|j	�WdQRX||j�7}WdQRXWdQRX|j
||j�tjt��}|j
|jd�|j	�WdQRXdS)Nr?r�r�rIi�r�)rBrCr#r�rDr�r:rRr;r�rQ)r<r�Zr1r�r�r r r!�test_write_while_readings
 z/TestsWithMultipleOpens.test_write_while_readingcCstt�dS)N)r	r#)r<r r r!r�%szTestsWithMultipleOpens.tearDownN)r�r�r�r�r8rHr�r�r�r�r�r�r�r�r�r r r r!r��s

r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCstjt�dS)N)r�r"r#)r<r r r!r>*szTestWithDirectory.setUpcCs�tjtd���}|jt�WdQRX|jtjjtjj	td���|jtjjtjj	tdd���|jtjj
tjj	tddd���dS)Nz
zipdir.zipr��br�)rBrCrr<r#rZr�rz�isdirr5r�)r<r�r r r!�test_extract_dir-s
z"TestWithDirectory.test_extract_dircCs tjtjjtd��|j�dS)Nr�)r�r"rzr5r#r�)r<r r r!�
test_bug_60504szTestWithDirectory.test_bug_6050cCs�tjjtd�}tj|�tj|�jd@}tjt	d��|}|j
|�|jd}|j|j
jd��|j|j|d>dB�|j
|d�|jd}|j|j
d	�|j|j|d>dB�WdQRXtjt	d
���}|jd}|j|j
jd��|j|j|d>dB�|jd}|j|j
d	�|j|j|d>dB�tjjtd�}tj|�|j|�|jtjjtjj|d���|jttj|��d�WdQRXdS)
Nr�i��r?rz/x/r��yrNzy/rIr7rx)r�rzr5r#r"�stat�st_moderBrCrr;r�rZrPrrQr�r<r�rW�listdir)r<�dirpathrAr�r�r7r r r!�test_write_dir9s0



 



z TestWithDirectory.test_write_dircCs�tjtjjtd��tjtd��8}|jdd�|j	d}|j
|jd�|j
|jd�WdQRXtjtd���}|j	d}|j
|jjd��|j
|jd
�tjjtd	�}tj|�|j|�|j
tjjtjj|d���|j
tj|�dg�WdQRXdS)Nr�r?zx/r1ri�Ar�rIr7i�Ai�Ai�Ai�A)r�r"rzr5r#rBrCrrDr�rQrPr�rZrr<r�r�)r<r�r�r7r r r!�test_writestr_dirSs



z#TestWithDirectory.test_writestr_dircCs tt�tjjt�rtt�dS)N)r
r#r�rzr�rr	)r<r r r!r�dszTestWithDirectory.tearDownN)	r�r�r�r>r�r�rrr�r r r r!r�)sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtjjt�}|jtj|j�d�|j|j	��|j|j
tjj
t��dS)Nztest_zipfile.py)rBrs�	from_filerrQ�	posixpathrrPr$�is_dirr`r�rz�getsize)r<�zir r r!�test_from_filekszZipInfoTests.test_from_filecCsNtjjtjt��}|jtj|j	�d�|j
|j��|j|jt
jjt��dS)Nztest_zipfile.py)rBrsrrwrxrrQrrrPr$rr`r�rzr)r<rr r r!�test_from_file_pathlikeqsz$ZipInfoTests.test_from_file_pathlikecCsPtjjtjt�d�}|jtj|j	�d�|j
|j��|j|jtj
jt��dS)Nr()rBrsrr��fsencoderrQrrrPr$rr`rzr)r<rr r r!�test_from_file_byteswsz!ZipInfoTests.test_from_file_bytescCsdttd��P}tjj|j�d�}|jtj|j	�d�|j
|j��|j|jt
jjt��WdQRXdS)Nr�r()r:rrBrsrr�rQrrrPr$rr`r�rzr)r<r)rr r r!�test_from_file_fileno}s
z"ZipInfoTests.test_from_file_filenocCs`tjjtjjt��}tjj|d�}|j|j	d�|j
|j��|j|jtj
�|j|jd�dS)NZstdlib_testsz
stdlib_tests/r)r�rzr�abspathrrBrsrrQrPrZrr�r�r`)r<r�rr r r!�
test_from_dir�szZipInfoTests.test_from_dirN)r�r�r�rr	rrrr r r r!rjs
rc@s@eZdZdd�Zdd�Zdd�Zdd�Zed	d
��Zdd�Z	d
S)�CommandLineTestcOs(tjd|�|�\}}}|jtjj�d�S)N�-mrBr�)rrB)rZassert_python_okrtr��linesepr2)r<�args�kwargs�rc�out�errr r r!�
zipfilecmd�s
zCommandLineTest.zipfilecmdcGstjd|��S)N�-mrB)rrB)rZassert_python_failure)r<rr r r!�zipfilecmd_failure�sz"CommandLineTest.zipfilecmd_failurecCsNtd�}|jd|�}|j|j�d�td�}|jd|�\}}}|j|d�dS)Nz
zipdir.zipz-tsDone testingztesttar.tarr1)rrrQ�rstripr)r<�zip_namerrrr r r!�test_test_command�sz!CommandLineTest.test_test_commandcCsbtd�}tj�}tj|d��}|j|�WdQRX|j�jdd�}|jd|dd�}|j	||�dS)Nz
zipdir.ziprIr,�backslashreplacez-lzascii:backslashreplace)ZPYTHONIOENCODING)
rr&rSrBrCrTrUr2rrQ)r<rrZtfZexpectedrr r r!�test_list_command�sz!CommandLineTest.test_list_commandcCs
|jtt�ttd��}|jd�WdQRXtjt�|jtt�ttj	j
td�d��}|jd�WdQRXttg}ttdtdg}zt|jdtf|��}|j
|d�tjt��B}|j
|j�|�|j
|j|d	�d
�|j
|j|d�d�WdQRXWdtt�XdS)
Nr?ztest 1zfile.txtztest 2rEz	/file.txtz-cr1rstest 1rxstest 2)r�r	rr:r;r�r"�	TESTFNDIRr
rzr5rr#rQrBrCr^rR)r<r)�filesr^rr�r r r!�test_create_command�s"
$z#CommandLineTest.test_create_commandcCs�td�}t���}|jd||�}|j|d�tj|���}x�|j�D]x}tjj	||j
jdtj��}|j
�rz|jtjj|��q@|jtjj|��t|d��}|j|j�|j|��WdQRXq@WWdQRXWdQRXdS)Nz
zipdir.zipz-er1rEr�)rrrrQrBrCr_r�rzr5rPrtr	rrZr�rBr:rR)r<rr9rr�rrzr)r r r!�test_extract_command�sz$CommandLineTest.test_extract_commandN)
r�r�r�rrrrr
r!r"r r r r!r�s
r�__main__)rr)rr)rr)rr)Kr�r&r��importlib.utilrrwrr[r�rBruZtempfilerrrrZtest.supportrrrr	r
rrr
rrrrr#rr3Z
DATAFILES_DIRr+r"r*r+ZTestCaser�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r*rvr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr��mainr r r r!�<module>s�4	Q


(


BA;A[



7
}A#A


Youez - 2016 - github.com/yon3zu
LinuXploit