HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_zipfile.cpython-37.pyc
B

��g��@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZddlmZddlmZmZmZmZmZmZmZmZmZmZedZedZdZd	Z d
ddd
gZ!dd�Z"dd�Z#Gdd�d�Z$Gdd�de$ej%�Z&eGdd�de$ej%��Z'eGdd�de$ej%��Z(eGdd�de$ej%��Z)Gdd�d�Z*Gdd�de*ej%�Z+eGd d!�d!e*ej%��Z,eGd"d#�d#e*ej%��Z-eGd$d%�d%e*ej%��Z.Gd&d'�d'�Z/Gd(d)�d)e/ej%�Z0eGd*d+�d+e/ej%��Z1eGd,d-�d-e/ej%��Z2eGd.d/�d/e/ej%��Z3Gd0d1�d1ej%�Z4Gd2d3�d3ej%�Z5Gd4d5�d5ej%�Z6Gd6d7�d7�Z7Gd8d9�d9e7ej%�Z8eGd:d;�d;e7ej%��Z9eGd<d=�d=e7ej%��Z:eGd>d?�d?e7ej%��Z;Gd@dA�dAej%�Z<GdBdC�dC�Z=GdDdE�dEe=ej%�Z>eGdFdG�dGe=ej%��Z?eGdHdI�dIe=ej%��Z@eGdJdK�dKe=ej%��ZAGdLdM�dM�ZBGdNdO�dO�ZCGdPdQ�dQej%�ZDeGdRdS�dSej%��ZEGdTdU�dUej%�ZFGdVdW�dWej%�ZGGdXdY�dYej%�ZHeIdZk�r�e�J�dS)[�N)�
TemporaryFile)�randint�random�getrandbits)�
script_helper)
�TESTFN�findfile�unlink�rmtree�temp_dir�temp_cwd�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout�2�di�Zzipfile_datafiles)Z	_ziptest1Z
1q2w3e4r5t)zziptest2dir/_ziptest2Z
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3Z
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3Z
6y7u8i9o0pcCstd|��|d�S)N��little)r�to_bytes)�size�r�-/usr/local/lib/python3.7/test/test_zipfile.py�getrandbytes src	csTtVt��}|V|�|j�WdQRXt���}|V|�|j�WdQRXdS)N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�frrr�	get_files#s
r!c@seZdZedd��Zdd�ZdBdd�ZdCdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dS)D�AbstractTestsWithSourceFilecCs&dd�tt�D�|_d�|j�|_dS)NcSs g|]}td|t�fd��qS)z'Zipfile test line %d. random float: %f
�ascii)�bytesr)�.0�irrr�
<listcomp>/sz:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data)�clsrrr�
setUpClass-sz&AbstractTestsWithSourceFile.setUpClassc	Cs&ttd��}|�|j�WdQRXdS)N�wb)�openr�writer-)�self�fprrr�setUp4sz!AbstractTestsWithSourceFile.setUpNc
Cs�||d�}tj|df|��`}|�td�|�tt�|�d|j�|jddd�� }x|jD]}|�|�qZWWdQRXWdQRXdS)N)�compression�
compresslevel�wzanother.name�strfilezwritten-open-w)�mode)�zipfile�ZipFiler2r�writestrr-r1r+)r3r r6r7�kwargs�zipfp�linerrr�make_test_archive9s
z-AbstractTestsWithSourceFile.make_test_archivec	Cs6|�|||�t�|d|���}|�|�t�|j�|�|�d�|j�|�|�d�|j�t��}|j	|d�|�
�}|��}|�t|�d�|�
d|d�|�
d|d�|�
d	|d�|d
��\}}	}
}|�|d�|�t�|	d��|�t�|
d��|�|tt|j���|��}|�t|�d
�|�
t|�|�
d|�|�
d|�|�
d|�|��}
dd�|
D�}|�t|�d
�|�
t|�|�
d|�|�
d|�|�
d|�x"|
D]}|�|jt|j���q�WxBtdddfD]2}|�|�}|�|j|�|�|jt|j���q�W|��WdQRXdS)N�rzanother.namer9)�file�z	File Namer�Modified�Size�z%Y-%m-%dz%H:%M:%S�zwritten-open-wcSsg|]
}|j�qSr)�filename)r%r&rrrr'hsz8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rAr;r<�assertEqual�readrr-r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforI�testzip)r3r r6r7r?r4�	directory�lines�fn�date�time_r�names�infosr&�nm�inforrr�zip_testDsL

z$AbstractTestsWithSourceFile.zip_testcCs$xt|�D]}|�||j�q
WdS)N)r!rer6)r3r rrr�
test_basiczsz&AbstractTestsWithSourceFile.test_basicc	
Cs�|�||�t�|d|���}g}|�t��&}x|�d�}|s>P|�|�q.WWdQRXg}|�d��&}x|�d�}|sxP|�|�qhWWdQRX|�d�|�|j	�|�d�|�|j	�WdQRXdS)NrB�zanother.namer()
rAr;r<r1rrK�appendrJr,r-)	r3r r6r?�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_test~s$

z)AbstractTestsWithSourceFile.zip_open_testcCs$xt|�D]}|�||j�q
WdS)N)r!rnr6)r3r rrr�	test_open�sz%AbstractTestsWithSourceFile.test_openc	CsFt�t�}|�||j�t�|d|j��}|�|jt	�WdQRXdS)NrB)
�pathlib�Pathrrnr6r;r<�assertIsInstancerIrV)r3�pathr?rrr�test_open_with_pathlike�s
z3AbstractTestsWithSourceFile.test_open_with_pathlikec
Cs~|�||�t�|d|��Z}g}|�t��,}x$|�tdd��}|sDP|�|�q.WWdQRX|�d�	|�|j
�WdQRXdS)NrBrGir()rAr;r<r1rrKrrhrJr,r-)r3r r6r?rirjrkrrr�zip_random_open_test�sz0AbstractTestsWithSourceFile.zip_random_open_testcCs$xt|�D]}|�||j�q
WdS)N)r!rur6)r3r rrr�test_random_open�sz,AbstractTestsWithSourceFile.test_random_openc
Csv|�||�t�|d��@}|�t��*}g}x|�d�}|s<P|�|�q,WWdQRXWdQRX|�d�|�|j	�dS)NrB���r()
rAr;r<r1r�read1rhrJr,r-)r3r r6r?�zipopen�zipdatarkrrr�zip_read1_test�s
"z*AbstractTestsWithSourceFile.zip_read1_testcCs$xt|�D]}|�||j�q
WdS)N)r!r{r6)r3r rrr�
test_read1�sz&AbstractTestsWithSourceFile.test_read1c
Cs�|�||�t�|d��P}|�t��:}g}x.|�d�}|�t|�d�|sLP|�|�q,WWdQRXWdQRX|�	d�
|�|j�dS)NrB�
r()rAr;r<r1rrxZassertLessEqualrPrhrJr,r-)r3r r6r?ryrzrkrrr�zip_read1_10_test�s
"z-AbstractTestsWithSourceFile.zip_read1_10_testcCs$xt|�D]}|�||j�q
WdS)N)r!r~r6)r3r rrr�
test_read1_10�sz)AbstractTestsWithSourceFile.test_read1_10c
Cs�|�||�t�|d��T}|�t��>}d}x2|��}|s:P||7}|�d�}|sRP||7}q,WWdQRXWdQRX|�||j�dS)NrBr(�d)	rAr;r<r1r�readlinerKrJr-)r3r r6r?ryr-rKrrr�zip_readline_read_test�s
 z2AbstractTestsWithSourceFile.zip_readline_read_testcCs$xt|�D]}|�||j�q
WdS)N)r!r�r6)r3r rrr�test_readline_read�sz.AbstractTestsWithSourceFile.test_readline_readc
Csb|�||�t�|d��@}|�t��*}x"|jD]}|��}|�||�q.WWdQRXWdQRXdS)NrB)rAr;r<r1rr+r�rJ)r3r r6r?ryr@Zlinedatarrr�zip_readline_test�sz-AbstractTestsWithSourceFile.zip_readline_testcCs$xt|�D]}|�||j�q
WdS)N)r!r�r6)r3r rrr�
test_readline�sz)AbstractTestsWithSourceFile.test_readlinec
Csl|�||�t�|d��J}|�t��}|��}WdQRXx$t|j|�D]\}}|�||�qFWWdQRXdS)NrB)	rAr;r<r1r�	readlines�zipr+rJ)r3r r6r?ryZziplinesr@�ziplinerrr�zip_readlines_testsz.AbstractTestsWithSourceFile.zip_readlines_testcCs$xt|�D]}|�||j�q
WdS)N)r!r�r6)r3r rrr�test_readlinessz*AbstractTestsWithSourceFile.test_readlinesc
Csd|�||�t�|d��B}|�t��,}x$t|j|�D]\}}|�||�q4WWdQRXWdQRXdS)NrB)rAr;r<r1rr�r+rJ)r3r r6r?ryr@r�rrr�zip_iterlines_tests
z.AbstractTestsWithSourceFile.zip_iterlines_testcCs$xt|�D]}|�||j�q
WdS)N)r!r�r6)r3r rrr�test_iterlinessz*AbstractTestsWithSourceFile.test_iterlinesc
Cs�t�td|j��}|�dd�WdQRXt�td|j��@}|�d��*}|�|�d�d�|�|�d�d�WdQRXWdQRXdS)	z>Check for cases where compressed data is larger than original.r8r9Z12NrBrG�1�2)r;r<rr6r=r1rJrK)r3r?Zopenobjrrr�test_low_compressionsz0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)Nr8zb.txtzhello world)�
compress_type)r;r<rr=r6rZrJr�)r3r?rdrrr�test_writestr_compression(s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
Nr8rG)r7za.txtzhello world)r�zb.txt�)r�r7)	r;r<rr=r6rZrJr��_compresslevel)r3r?Za_infoZb_inforrr�test_writestr_compresslevel.s

z7AbstractTestsWithSourceFile.test_writestr_compresslevelcCs�xzdD]r}|d}t|�}t�t��d|j��D}|�d|�|�dd�� }|�|�}|�	t
|�|�WdQRXWdQRXqWdS)N)rGi�iii@rGr8�foorB)rr;r<rrr6r=r1rKrJrP)r3Z	test_sizerYZjunk�zipfr4�bufrrr�test_read_return_size>s

z1AbstractTestsWithSourceFile.test_read_return_sizecCs�t��}tj|dd��"}|jd|j|jd�|��}WdQRX|��}t�|�}t�|��H}|�	d��2}|�
|d�|�t��|�
�WdQRXWdQRXWdQRXt�|�}t�|��P}|�	d��:}|�
|d�|�t��x|�
d�r�q�WWdQRXWdQRXWdQRXt�|�}t�|��T}|�	d��>}|�
|d�|�t��x|�d��r`�qPWWdQRXWdQRXWdQRXdS)Nr8)r:r9)r��r�)rrr;r<r=r-r6�tellrNr1�truncate�assertRaises�EOFErrorrKrx)r3r4r�Z
end_offset�zipfiledataryrrr�test_truncated_zipfileJs2
&
"
z2AbstractTestsWithSourceFile.test_truncated_zipfilecCs�d}�xvt|�D�]h}t�|d|j��&}|�t|�t|�}|�d|�WdQRXt�|d���}t|�}t|t	�r�|�d||�n|�d||�|�d|�t|�
|��}|�d||�|�d|�|�d	|�|jtjkr�|�d
|�|�d|�|�|��D}t|�}|�d||�|�d|�|jtjk�rF|�d
|�WdQRX|�d
t|��WdQRX|�d
t|��qWdS)Nz	file.namer8zmode='w'rBzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
r!r;r<r6r2r�reprrQ�
isinstancerVrZ�
ZIP_STOREDr1)r3�fnamer r?rBryrrr�	test_reprhs6
z%AbstractTestsWithSourceFile.test_reprcCs(x"t|�D]}|j||jdd�q
WdS)N�	)r7)r!rer6)r3r rrr�test_compresslevel_basic�sz4AbstractTestsWithSourceFile.test_compresslevel_basicc	Csltjtddd��R}|�td�|jtddd�|�d�}|�d�}|�|jd�|�|jd�WdQRXdS)zTCheck that files within a Zip archive can have different
        compression levels.r8rG)r7Z
compress_1Z
compress_9r�N)r;r<rr2rrZrJr�)r3r?Zone_infoZ	nine_inforrr�test_per_file_compresslevel�s

z7AbstractTestsWithSourceFile.test_per_file_compresslevelc
s`G��fdd�dtj�}d�x�|�}d�t�|d|j��~}|�dd��}|�d�WdQRXd�zJy&|�dd��}|�d�WdQRXWntk
r��d	7�YnXPWdd�XWdQRXt�t�|�����*}|�	|�
�dg�|�	|�d�d�WdQRXqWt�t�|�����>}|�	|�
�ddg�|�	|�d�d�|�	|�d�d�WdQRXdS)
Ncs eZdZ���fdd�Z�ZS)zCAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilecs,�dk	r��krt��d7�t��|�dS)NrG)�OSError�superr2)r3r-)�	__class__�count�stoprrr2�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r2�
__classcell__r)r�r�)r�r�
BrokenFile�sr�rr8Zfile1sdata1Zfile2sdata2rG)rrr;r<r6r1r2r�rNrJrWrK)r3r�Ztestfiler?r r)r�r�r�test_writing_errors�s.	 z/AbstractTestsWithSourceFile.test_writing_errorscCstt�tt�dS)N)r	rr)r3rrr�tearDown�sz$AbstractTestsWithSourceFile.tearDown)N)N)$r�r�r��classmethodr/r5rArerfrnrortrurvr{r|r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr",s@

6

	%r"c@sveZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNc	CsX|�||�t�|d��6}|�d�}|�|jd�|�d�}|�|jd�WdQRXdS)NrBr9i�zwritten-open-w)rAr;r<rZrJ�
external_attr)r3r r6r?�zinfoZzinfo2rrr�zip_test_writestr_permissions�s

z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs$xt|�D]}|�|tj�q
WdS)N)r!r�r;r�)r3r rrr�test_writestr_permissions�sz3StoredTestsWithSourceFile.test_writestr_permissionsc	CsZt�tdtj��}|�td�WdQRXt�tdtj��}|�|��dg�WdQRXdS)Nr8z	/absoluterB�absolute)r;r<rr�r2rrJrW)r3r?rrr�test_absolute_arcnames�sz0StoredTestsWithSourceFile.test_absolute_arcnamesc	Csjt�tdtj��}|�tt�WdQRXt�tdtj��(}|�d|j�|�|�	�tdg�WdQRXdS)z&Test appending to an existing zipfile.r8N�ar9)
r;r<rr�r2rr=r-rJrW)r3r?rrr�test_append_to_zip_file�s
z1StoredTestsWithSourceFile.test_append_to_zip_filec
Cs8d}ttd��}|�|�WdQRXt�tdtj��}|�tt�WdQRXttd��R}|�t|��t�|d��,}|�	|�
�tg�|�	|�t�|j�WdQRXWdQRXttd��$}|�	|�t|��|�|��}WdQRXt
�|��B}t�|��,}|�	|�
�tg�|�	|�t�|j�WdQRXWdQRXdS)z9Test appending to an existing file that is not a zipfile.s�I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!r0Nr��rbrB)r1rr2r;r<r�r�seekrPrJrWrKr-rr)r3r-r r?r��biorrr�test_append_to_non_zip_file�s (z5StoredTestsWithSourceFile.test_append_to_non_zip_filec
Cs�t���6}t�|dtj��}|�tt�WdQRX|��}WdQRXd}tt	d��}|�|�|�|�WdQRXt�t	��,}|�
|��tg�|�
|�t�|j
�WdQRXdS)Nr8s�I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!I am not a ZipFile!r0)rrr;r<r�r2rrNr1rrJrWrKr-)r3r�r?r�r-r rrr�test_read_concatenated_zip_file�s

z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec
CsNt���6}t�|dtj��}|�tt�WdQRX|��}WdQRXdd}tt	d��}|�|�|�|�WdQRXt�t	d��&}|�
|��tg�|�d|j
�WdQRXtt	d��$}|�
|�t|��|�|��}WdQRXt�|��X}t�|��B}|�
|��tdg�|�
|�t�|j
�|�
|�d�|j
�WdQRXWdQRXdS)Nr8sI am not a ZipFile!i@Br0r�r9r�)rrr;r<r�r2rrNr1rrJrWr=r-rKrP)r3r�r?r�r-r rrr�$test_append_to_concatenated_zip_files$

z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filec	Csrt�tdtj��}|�tt�WdQRXttd��}|�d�WdQRXt�td��}|�|tj�WdQRXdS)Nr8r�z
rB)r;r<rr�r2rr1rr)r3r?r rrr�test_ignores_newline_at_end!sz5StoredTestsWithSourceFile.test_ignores_newline_at_endc	Cs�t�tdtj��}d|_|�tt�WdQRXttd��}|�d�WdQRXt�td��"}|�|tj�|�	|jd�WdQRXdS)Nr8sthis is a commentr�zabcdef
rB)
r;r<rr��commentr2rr1rrrJ)r3r?r rrr�)test_ignores_stuff_appended_past_comments)szCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc
CsRt�td��<}|�t�ttd��}|�|�t�|���WdQRXWdQRXdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r8r�N)r;r<rr2rr1rJrK)r3r?r rrr�test_write_default_name3s
z1StoredTestsWithSourceFile.test_write_default_namec
Cs�tjtdd��}|�dd�WdQRXtjtdd��}|�t|jt�WdQRXtjtdd��*}|�t��|jtdd�WdQRXWdQRXdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r8)r:zsomefile.txt�bogusNrB)	r;r<rr=r��
ValueErrorr2rr1)r3r?rrr�test_write_to_readonly;sz0StoredTestsWithSourceFile.test_write_to_readonlyc	Cs8t�td�t�td��}|�t|jt�WdQRXdS)N)rrr8)	�os�utimerr;r<rr�r�r2)r3r?rrr�test_add_file_before_1980Hsz3StoredTestsWithSourceFile.test_add_file_before_1980)r�r�r�r;r�r6r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilec	Cspt�td��Z}|�tdtj�|�tdtj�|�d�}|�d�}|�|j	tj�|�|j	tj�WdQRXdS)zUCheck that files within a Zip archive can have different
        compression options.r8ZstoremeZ	deflatemeN)
r;r<rr2rr��ZIP_DEFLATEDrZrJr�)r3r?ZsinfoZdinforrr�test_per_file_compressionTs

z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�r;r�r6r�rrrrr�Osr�c@seZdZejZdS)�Bzip2TestsWithSourceFileN)r�r�r�r;�	ZIP_BZIP2r6rrrrr�_sr�c@seZdZejZdS)�LzmaTestsWithSourceFileN)r�r�r�r;�ZIP_LZMAr6rrrrr�dsr�c@sHeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�AbstractTestZip64InSmallFilescCs$dd�tdt�D�}d�|�|_dS)Ncss|]}td|d�VqdS)zTest of zipfile line %d.r#N)r$)r%r&rrr�	<genexpr>psz;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>r�
)r)r*r,r-)r.r+rrrr/nsz(AbstractTestZip64InSmallFiles.setUpClassc	CsBtj|_tj|_dt_dt_ttd��}|�|j�WdQRXdS)Ni�r�r0)	r;�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr1rr2r-)r3r4rrrr5tsz#AbstractTestZip64InSmallFiles.setUpc	CsPtj|d|dd��,}|�td�|�tt�|�d|j�WdQRXt�|d|����}|�|�t�|j�|�|�d�|j�|�|�d�|j�t�	�}|�
|�|��}|��}|�t
|�d�|�d|d	�|�d
|d	�|�d|d	�|d��\}}}	}
|�|d�|�t�|d
��|�t�|	d��|�|
tt
|j���|��}|�t
|�d�|�t|�|�d|�|�d|�|��}dd�|D�}|�t
|�d�|�t|�|�d|�|�d|�x"|D]}
|�|
jt
|j���q�Wx@tddfD]2}|�|�}|�|j|�|�|jt
|j���qW|��WdQRXdS)Nr8T)�
allowZip64zanother.namer9rBrHz	File NamerrErFrGz%Y-%m-%dz%H:%M:%S�cSsg|]
}|j�qSr)rI)r%r&rrrr'�sz:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)r;r<r2rr=r-rJrKrrLrMrNrOrPrQrRrSrTrUrVrWrXrYrZrIr[)r3r r6r?r4r\r]r^r_r`rrarbr&rcrdrrrre~sN


z&AbstractTestZip64InSmallFiles.zip_testcCs$xt|�D]}|�||j�q
WdS)N)r!rer6)r3r rrrrf�sz(AbstractTestZip64InSmallFiles.test_basiccCs�tjtd|jdd�}d|_d}x,t|�D] }|�d|d|dd	�q(W|�t|�	��|�|�
�t�td
|j�}|�t|�	��|�x<t|�D]0}|�d|��d�}|�|d|dd	�q�W|�
�dS)Nr8T)r�r��zfoo%08dz%dr��9rBr#)
r;r<rr6�debugr)r=rJrPrW�closerK�decode)r3r��numfilesr&�zipf2�contentrrr�test_too_many_files�s z1AbstractTestZip64InSmallFiles.test_too_many_filesc	Cstjtd|jdd�}d|_d}x,t|�D] }|�d|d|dd	�q(W|�t|�	��|�|�
tj��|�d|d
�WdQRX|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�|�
tj��|�d|d
�WdQRX|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�d
}x0t||�D]"}|�d|d|dd	��qTW|�t|�	��|�|��t�td|j�}|�t|�	��|�x>t|�D]2}|�
d|��d�}|�|d|dd	��q�W|��dS)Nr8F)r�r�r�zfoo%08dz%dr�r�r(r�Tr�rBr#)r;r<rr6r�r)r=rJrPrWr��LargeZipFiler�rKr�)r3r�r�r&Z	numfiles2r�r�rrr�test_too_many_files_append�sD "z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dS)N)r�r;r�r�r�r	rr)r3rrrr��sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r/r5rerfr�r�r�rrrrr�js
9'r�c@sTeZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
ddd
�Zdd�Zdd�Z
dS)�StoredTestZip64InSmallFilesc	Cs6tj|d|dd��}|�tj|jtd�WdQRXdS)Nr8F)r�zanother.name)r;r<r�r�r2r)r3r r6r?rrr�large_file_exception_testsz5StoredTestZip64InSmallFiles.large_file_exception_testc	Cs8tj|d|dd��}|�tj|jd|j�WdQRXdS)Nr8F)r�zanother.name)r;r<r�r�r=r-)r3r r6r?rrr�large_file_exception_test2sz6StoredTestZip64InSmallFiles.large_file_exception_test2cCs2x,t|�D] }|�|tj�|�|tj�q
WdS)N)r!r�r;r�r�)r3r rrr�test_large_file_exception
sz5StoredTestZip64InSmallFiles.test_large_file_exceptionc	Cs^tjtdtjdd��}|�td�WdQRXt�tdtj��}|�|��dg�WdQRXdS)Nr8T)r�z	/absoluterBr�)r;r<rr�r2rrJrW)r3r?rrrr�s

z2StoredTestZip64InSmallFiles.test_absolute_arcnamesc	Cs�tjtddd��}|�d|j�WdQRXtjtddd��}|�d�}|j}WdQRXtjtddd��}|�d|j�WdQRXtjtddd��}|�d�}|�|j|�WdQRXdS)Nr8T)r�r9rBr�Zstrfile2)r;r<rr=r-rZ�extrarJ)r3r?r�r�rrr�test_appends

z'StoredTestZip64InSmallFiles.test_appendFcCs�d}d}g}	g}
|}|r4d}|r4|	�|�|
�|�t�d|�}|}|rdd}|rd|	�|�|
�|�t�d|�}|}
|r�d}
|r�|
�|�t�d|
�}
tjddt|	�ddt|	�f|	��}tjddt|
�ddt|
�f|
��}t�dd	dt|
��}t�dd
dt|	��}t�dddt|	��}t�dddt|
��}d
}d}t�dt|��}d|||||||d||||d|
||ddd||dddd}|S)z�Generate bytes sequence for a zip with (incomplete) zip64 data.

        The actual values (not the zip 64 0xffffffff values) stored in the file
        are:
        file_size: 8
        compress_size: 8
        header_offset: 0
        rrl��z<Lz<HH�QrGz<Q�:�2z<HrHstest.txtstest1234sPK!�%��sPK--!�%��s
�sPK,--ss
sPKlssPK:2s)rh�struct�packrP)r3�file_size_64_set�file_size_extra�compress_size_64_set�compress_size_extra�header_offset_64_set�header_offset_extraZactual_sizeZactual_header_offsetZlocal_zip64_fieldsZcentral_zip64_fieldsrY�
compress_size�
header_offsetZlocal_extraZ
central_extraZcentral_dir_sizeZoffset_to_central_dirZlocal_extra_lengthZcentral_extra_lengthrIr�Zfilename_lengthZzip64_contentsrrr�make_zip64_file%sV





 hz+StoredTestZip64InSmallFiles.make_zip64_filec	Cs&|jdd�}|�tj��}t�t�|��WdQRX|�dt|j	��
��|jdddd�}|�tj��}t�t�|��WdQRX|�dt|j	��
��|jdd�}|�tj��}t�t�|��WdQRX|�dt|j	��
��|jdddddd�}|�tj��}t�t�|��WdQRX|�d	t|j	��
��|jd
dddd�}|�tj��}t�t�|��WdQRX|�d	t|j	��
��|jddd
dd�}|�tj��}t�t�|��WdQRX|�d	t|j	��
��|jd
d
dd
�}|�tj��}t�t�|��WdQRX|�d	t|j	��
��dS)a
Missing zip64 extra records raises an exception.

        There are 4 fields that the zip64 format handles (the disk number is
        not used in this module and so is ignored here). According to the zip
        spec:
              The order of the fields in the zip64 extended
              information record is fixed, but the fields MUST
              only appear if the corresponding Local or Central
              directory record field is set to 0xFFFF or 0xFFFFFFFF.

        If the zip64 extra content doesn't contain enough entries for the
        number of fields marked with 0xFFFF or 0xFFFFFFFF, we raise an error.
        This test mismatches the length of the zip64 extra field and the number
        of fields set to indicate the presence of zip64 data.
        T)r�Nz	file size)r�r�r�z
compress size)r�)r�r�r�r�r�z
header offsetF)r�r�r�r�)r�r�r�r�)r�r�r�)r�r�r;�
BadZipFiler<rrrQrVZ	exception�lower)r3Zmissing_file_size_extra�eZmissing_compress_size_extraZmissing_header_offset_extrarrr�test_bad_zip64_extra�sbz0StoredTestZip64InSmallFiles.test_bad_zip64_extracCs�d}d}d}d}ddd�ddd�ddd�f}x�tdt|�d�D]�}x�t�||�D]�}i}x|D]}	|�|	�q`Wt�t�|j	f|����N}
|
�
�d}|�|j|�|�|j
|�|�|j|�|�|
�|�|�WdQRXqRWq@WdS)	Nrrstest1234T)r�r�)r�r�)r�r�rG)r)rP�	itertools�combinations�updater;r<rrr�rXrJrYr�r�rK)r3Zexpected_file_sizeZexpected_compress_sizeZexpected_header_offsetZexpected_content�paramsrBZcombor>�c�zfr�rrr� test_generated_valid_zip64_extra�s$
z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extraN)FFFFFF)r�r�r�r;r�r6r�r�r�r�r�r�rrrrrrr��s
`^r�c@seZdZejZdS)�DeflateTestZip64InSmallFilesN)r�r�r�r;r�r6rrrrrsrc@seZdZejZdS)�Bzip2TestZip64InSmallFilesN)r�r�r�r;r�r6rrrrr	sr	c@seZdZejZdS)�LzmaTestZip64InSmallFilesN)r�r�r�r;r�r6rrrrr
sr
c@s$eZdZdd�Zdd�Zdd�ZdS)�AbstractWriterTestscCstt�dS)N)r	r)r3rrrr�szAbstractWriterTests.tearDownc	Cstd}t�td|j��V}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�WdQRXdS)Nscontentr8r)r;r<rr6r1r2r�rSrrJrK)r3r-r�r8rrr�test_close_after_closes
z*AbstractWriterTests.test_close_after_closec	Cspd}t�td|j��R}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�WdQRXdS)Nscontentr8rr()
r;r<rr6r1r2r�rSrr�r�rJrK)r3r-r�r8rrr�test_write_after_close"s
z*AbstractWriterTests.test_write_after_closeN)r�r�r�r�rr
rrrrrsrc@seZdZejZdS)�StoredWriterTestsN)r�r�r�r;r�r6rrrrr,src@seZdZejZdS)�DeflateWriterTestsN)r�r�r�r;r�r6rrrrr/src@seZdZejZdS)�Bzip2WriterTestsN)r�r�r�r;r�r6rrrrr3src@seZdZejZdS)�LzmaWriterTestsN)r�r�r�r;r�r6rrrrr7src@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs |d|kr|�|d|�dS)N�or)rQ)r3�namerWrrr�assertCompiledIn=szPyZipFileTests.assertCompiledIncCs�tj|tjtjtjkd�s$|�d�tj�|d�}y"t�|tjtj	B�}t�
|�Wntk
rr|�d�YnXt|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r��access�W_OK�supports_effective_idsZskipTestrsr,r1�O_WRONLY�O_CREATr��	Exceptionr	)r3rsrI�fdrrr�requiresWriteAccessAs

z"PyZipFileTests.requiresWriteAccessc
CsR|�tj�t��t���}t�|d���}t}|�d�r�|�	tj
�}tjdk	r^|�|�	tj��d|krtt
j�|�}n|dd�}|�|�tj�|�}|�||���|�||���WdQRXWdQRXt��x}t�|d��`}t}|�d�r�|dd�}|�|d�ddtj�|�f}|�||���|�||���WdQRXWdQRXdS)Nr8z.pyc�__pycache__rwZtestpackagez%s/%s)rr�rs�dirname�__file__rr;�	PyZipFile�endswithrR�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrWr)r3�tr?r^Z
path_splitZbnrrr�test_write_pyfileNs,


$
z PyZipFileTests.test_write_pyfilec
Csxddl}tj�|j�}|�|�t��H}t�|d��0}|�	|�|�
�}|�d|�|�d|�WdQRXWdQRXdS)Nrr8zemail/__init__.pyzemail/mime/text.py)�emailr�rsrr rrr;r!r)rWr)r3r.�
packagedirr,r?rarrr�test_write_python_packagels

z(PyZipFileTests.test_write_python_packagecCsddl}tj�|j�}|�|�t���}t�|d���}t	��}|�
|�WdQRX|��}|�d|k�t	��}|j
|dd�d�WdQRX|��}|�d|k�dd�}t	��*}|�
t��|j
||d�WdQRXWdQRX|��}|r�t|�|�d|k�WdQRXWdQRXdS)	Nrr8�SyntaxErrorcSsdS)NFr)Zwhateverrrr�<lambda>�r(zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>)�
filterfunccSstj�|��d�S)NZbad)r�rsr*�
startswith)rsrrr�filter�szAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rr�rsrr rrr;r!rr)rNrS�assertWarns�UserWarning�print)r3rr/r,r?Z	reportSIOZ	reportStrr5rrr�"test_write_filtered_python_packagezs&
"z1PyZipFileTests.test_write_filtered_python_packagec
Cs�ddl}tj�|j�}|�|�dnd}d}t��T}tj|d|d��8}|�	|�|�
�}|�d||�|�d||�WdQRXWdQRXdS)	NrTrGz.pycr8)�optimizezemail/__init__zemail/mime/text)r.r�rsrr rrr;r!r)rWrQ)r3r.r/ZoptlevelZextr,r?rarrr�test_write_with_optimization�s

z+PyZipFileTests.test_write_with_optimizationc
Cs�t�t�z�ttj�td�d��}|�d�WdQRXttj�td�d��}|�d�WdQRXttj�td�d��}|�d�WdQRXt��T}t�	|d��<}|�
t�|��}|�d|�|�d|�|�
d|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr8z
print(42)
zmod2.pyzprint(42 * 42)
zmod2.txtzbla bla bla
)r��mkdirrr1rsr,r2rr;r!r)rWrr+r
)r3r4r,r?rarrr�test_write_python_directory�s

$z*PyZipFileTests.test_write_python_directoryc
Cs�t�t�z�ttj�td�d��}|�d�WdQRXttj�td�d��}|�d�WdQRXt��P}t�	|d��8}|j
tdd�d�|��}|�d|�|�
d|�WdQRXWdQRXWdtt�XdS)	Nzmod1.pyr8z
print(42)
zmod2.pyzprint(42 * 42)
cSs|�d�S)Nzmod2.py)r")r^rrrr2�szEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>)r3)r�r<rr1rsr,r2rr;r!r)rWrr+r
)r3r4r,r?rarrr�$test_write_python_directory_filtered�s
$z3PyZipFileTests.test_write_python_directory_filteredcCsft��V}t�|d��>}ttd��}|�d�WdQRX|�t|jt�t	t�WdQRXWdQRXdS)Nr8z!most definitely not a python file)
rr;r!r1rr2r��RuntimeErrorr)r	)r3r,r?r rrr�test_write_non_pyfile�s
z$PyZipFileTests.test_write_non_pyfilecCs�t�t�z�ttj�td�d��}|�d�WdQRXt��t}t�	|d��\}t
��}|�tj�td��WdQRX|�d|�
��|��}|�d|�|�d|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr8zBad syntax in python file
r1zmod1.pyc)r�r<rr1rsr,r2rr;r!rr)rQrNrWr+r
)r3r4r,r?�srarrr�test_write_pyfile_bad_syntax�s
$z+PyZipFileTests.test_write_pyfile_bad_syntaxc
Cs�t�t�z�ttj�td�d��}|�d�WdQRXt��F}t�	|d��.}|�
t�t�d�|�
�}|�d|�WdQRXWdQRXWdtt�XdS)Nzmod1.pyr8z
print(42)
)r�r<rr1rsr,r2rr;r!r)rprqrWrr
)r3r4r,r?rarrr�test_write_pathlike�s
$z"PyZipFileTests.test_write_pathlikeN)r�r�r�rrr-r0r9r;r=r>r@rBrCrrrrr<s
rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Ze�ejjdkd�dd��Ze�ejjdkd�dd ��Zd!d"�Zd#S)$�ExtractTestsc	Cs>t�tdtj��$}xtD]\}}|�||�qWWdQRXdS)Nr8)r;r<rr��SMALL_TEST_DATAr=)r3r?�fpath�fdatarrr�make_test_file�szExtractTests.make_test_filecCs�t���|��t�td��~}xvtD]n\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��}|�|��|���WdQRXt|�q$WWdQRXWdQRXdS)NrBr�)rrHr;r<rrE�extractr�rsr,�getcwd�normpathrJr1�encoderKr	)r3r?rFrG�writtenfile�correctfiler rrr�test_extracts
zExtractTests.test_extractcCs�|��t�td���}x�tD]z\}}|�||�}tj�||�}tj�	|�}|�
tj�||�||f�t|d��}|�
|��|���WdQRXt|�qWWdQRXtt�dS)NrBr�)rHr;r<rrErIr�rsr,rKrS�samefiler1rJrLrKr	)r3�targetr?rFrGrMrNr rrr�_test_extract_with_targetsz&ExtractTests._test_extract_with_targetc	Cs t��}|�|�WdQRXdS)N)rrR)r3�extdirrrr�test_extract_with_target*sz%ExtractTests.test_extract_with_targetc	Cs&t��}|�t�|��WdQRXdS)N)rrRrprq)r3rSrrr�!test_extract_with_target_pathlike.sz.ExtractTests.test_extract_with_target_pathlikecCs�t���|��t�td��d}|��xTtD]L\}}tj�	t�
�|�}t|d��}|�|�
�|���WdQRXt|�q,WWdQRXWdQRXdS)NrBr�)rrHr;r<r�
extractallrEr�rsr,rJr1rJrLrKr	)r3r?rFrG�outfiler rrr�test_extract_all2szExtractTests.test_extract_allcCs�|��t�td��b}|�|�xPtD]H\}}tj�||�}t	|d��}|�
|��|���WdQRXt
|�q&WWdQRXt
t�dS)NrBr�)rHr;r<rrVrEr�rsr,r1rJrLrKr	)r3rQr?rFrGrWr rrr�_test_extract_all_with_target?s
z*ExtractTests._test_extract_all_with_targetc	Cs t��}|�|�WdQRXdS)N)rrY)r3rSrrr�test_extract_all_with_targetMsz)ExtractTests.test_extract_all_with_targetc	Cs&t��}|�t�|��WdQRXdS)N)rrYrprq)r3rSrrr�%test_extract_all_with_target_pathlikeQsz2ExtractTests.test_extract_all_with_target_pathlikec	Cs<|�tj�|��t|d��}|�|��|�WdQRXdS)Nr�)rSr�rs�isfiler1rJrK)r3rIr�r rrr�
check_fileUszExtractTests.check_filecCsBtjj}|�|dd�d�|�|dd�d�|�|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)r;r<Z_sanitize_windows_namerJ)r3Zsanrrr�test_sanitize_windows_nameZsz'ExtractTests.test_sanitize_windows_namecCs"ddddddddg}|�|�dS)	N)z
../foo/barzfoo/bar)z
foo/../barzfoo/bar)z
foo/../../barzfoo/bar)z
foo/bar/..zfoo/bar)z./../foo/barzfoo/bar)z/foo/barzfoo/bar)z/foo/../barzfoo/bar)z/foo/../../barzfoo/bar)�_test_extract_hackers_arcnames)r3Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_casesasz7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCs8ddddddddd	d
ddd
ddddddg}|�|�dS)z>Test combination of path fixing and windows name sanitization.)z
..\foo\barzfoo/bar)z..\/foo\/barzfoo/bar)zfoo/\..\/barzfoo/bar)zfoo\/../\barzfoo/bar)z	C:foo/barzfoo/bar)z
C:/foo/barzfoo/bar)zC://foo/barzfoo/bar)z
C:\foo\barzfoo/bar)z//conky/mountpoint/foo/barzfoo/bar)z\\conky\mountpoint\foo\barzfoo/bar)z///conky/mountpoint/foo/barzconky/mountpoint/foo/bar)z\\\conky\mountpoint\foo\barzconky/mountpoint/foo/bar)z//conky//mountpoint/foo/barzconky/mountpoint/foo/bar)z\\conky\\mountpoint\foo\barzconky/mountpoint/foo/bar)z//?/C:/foo/barzfoo/bar)z\\?\C:\foo\barzfoo/bar)zC:/../C:/foo/barz
C_/foo/bar)za:b\c<d>e|f"g?h*izb/c_d_e_f_g_h_i)z../../foo../../ba..rz	foo/ba..rN)ra)r3Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_onlyns(z7ExtractTests.test_extract_hackers_arcnames_windows_onlyr_zRequires / as path separator.cCsdddg}|�|�dS)N)z	//foo/barzfoo/bar)z../../foo../../ba..rzfoo../ba..r)z
foo/..\barz
foo/..\bar)ra)r3Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_only�sz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc

Cs��x�|D�]�\}}d|��}t�tdtj��&}t��}||_d|_|�||�WdQRX|�	t
jd�}t
j�
ddd�}t
jj
|f|�d���}t�td��,}|�||�}	|j|	|d	||	|fd
�WdQRX|�||�td�t�td��}|�|�WdQRX|�||�td�t
jj
t
��f|�d���}t�td��$}|�|�}	|j|	|d|d
�WdQRX|�||�t|�d�d�t�td��}|��WdQRX|�||�t|�d�d�tt�qWdS)
Nsfoobarr8i�r_rQZsubdirZsubsubrBzextract %r: %r != %r)�msgz
extract %rr)rLr;r<rr��ZipInforIr�r=�replacer�r#rsr,rRrIrJr]r
rVrJr	)
r3Z	hacknamesZarcnameZ	fixednamer�r?r�Z
targetpathrNrMrrrra�sB
z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�rHrOrRrTrUrXrYrZr[r]r`rb�unittestZskipIfr�rsr#rdrerarrrrrD�s

	rDc@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%dEdF�Z&dGS)H�
OtherTestscCs�t�tdtj��J}|�dd�|�t��|�dd�WdQRX|�|��dgd�WdQRXt�td���}|�	�}d}x.|D]&}|�
|��}||��7}WdQRXq�W|�|dd	h�d}x|D]}||�|�7}q�W|�|dd	h�WdQRXdS)
Nr8rr��barr�rBr(sfoobarsbarfoo)
r;r<rr�r=r6r7rJrWrXr1rKrQ)r3r?rbr-rdryrrr�test_open_via_zip_info�s  

z!OtherTests.test_open_via_zip_infoc	CsNt�td��8}x0dD](}t�|�}|jdO_|�||�qWWdQRXdS)Nr8Zabcdefghijklmnopr)r;r<rrgZ	flag_bitsr=)r3Zorig_zipr-r�rrr�-test_writestr_extended_local_header_issue1202�s


z8OtherTests.test_writestr_extended_local_header_issue1202c	Cs�t�td��2}x*tD]"\}}|�||�|�|jd�qWWdQRX|�|jd�t�td��}|�|jd�WdQRX|�|jd�dS)z8Check that the zipfile is closed after the 'with' block.r8zzipfp is not openNzzipfp is not closedrB)r;r<rrEr=ZassertIsNotNoner4�assertIsNone)r3r?rFrGrrr�
test_close�szOtherTests.test_closec	Cs�t�td��$}xtD]\}}|�||�qWWdQRXy$t�td��}t���WdQRXWn$tjk
r~|�|jd�YnXdS)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r8NrBzzipfp is not closed)r;r<rrEr=r�rnr4)r3r?rFrGZzipfp2rrr�test_close_on_exception�sz"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rB)r��NotImplementedErrorr;r<rr)r3r-rrr�test_unsupported_version�s
z#OtherTests.test_unsupported_versionc	CsBtd�}t�|��&}x|��D]}|�|���qWWdQRXdS)Nzzip_cp437_header.zip)rr;r<rWr1r�)r3r�r?rrrr�test_read_unicode_filenames�sz&OtherTests.test_read_unicode_filenamesc	Cs�t�td��4}|�dd�|�dd�|�|��djt�WdQRXt�td��.}|�|j	djd�|�|j	djd�WdQRXdS)Nr8zfoo.txtzTest for unicode filenameuö.txtrrBrG)
r;r<rr=rrrXrIrVrJ�filelist)r3rrrr�test_write_unicode_filenamess z'OtherTests.test_write_unicode_filenamesc	Cs�tt�d}d}t�tdtj��}|�||�WdQRX|�t��t�tdtj�WdQRXt�td��*}|�|�	�|g�|�|�
|�|�WdQRXdS)z&Test exclusive creating a new zipfile.ztestfile.txts#hello, world. this is some content.�xNrB)r	rr;r<r�r=r��FileExistsErrorrJrWrK)r3rIr�r?rrr�test_exclusive_create_zip_filesz)OtherTests.test_exclusive_create_zip_filec	Cs�tj�t�rt�t�d}d}y(t�td��}|�||�WdQRXWntk
rd|�	d�YnX|�
tj�t��t�td��}|�|�|�|�WdQRXdS)Nztestfile.txts#hello, world. this is some content.r�z1Could not append data to a non-existent zip file.rB)
r�rs�existsrr	r;r<r=r��failrSrJrK)r3rIr�rrrr�(test_create_non_existent_file_for_appends
z3OtherTests.test_create_non_existent_file_for_appendc	CsJttd��}|�d�WdQRXyt�t�}Wntjk
rDYnXdS)Nr8zthis is not a legal zip file
)r1rr2r;r<r�)r3r4rrrr�test_close_erroneous_file.sz$OtherTests.test_close_erroneous_filec	Cs�ttd��}|�d�WdQRX|�t�t��|�t�t�t���ttd��}|�t�|��WdQRXt�	�}|�d�|�t�|��|�
dd�|�t�|��dS)z;Check that is_zipfile() correctly identifies non-zip files.r8zthis is not a legal zip file
Nr�sthis is not a legal zip file
r)r1rr2rr;�
is_zipfilerprqrrr�)r3r4rrr�test_is_zip_erroneous_file=s
z%OtherTests.test_is_zip_erroneous_filec	Cstt��}tj|dd��}|�dd�WdQRX|��}x8tt|��D](}t�|d|��}|�tj	tj|�qDWdS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r8)r:zfoo.txtsO, for a Muse of Fire!N)
rrr;r<r=rNr)rPr�r�)r3r4r�r��Nrrr�test_damaged_zipfileOszOtherTests.test_damaged_zipfilec	Cs�tjtdd��}|�dd�WdQRX|�t�t��ttd��*}|�t�|��|�dd�|��}WdQRXt	�
�}|�|�|�t�|��|�dd�|�t�|��dS)z7Check that is_zipfile() correctly identifies zip files.r8)r:zfoo.txtsO, for a Muse of Fire!Nr�r)r;r<rr=rSr}r1r�rKrrr2)r3r�r4Zzip_contentsrrr�test_is_zip_valid_file]s
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dS)N)r�r�r;r<r)r3rrr�%test_non_existent_file_raises_OSErrorpsz0OtherTests.test_non_existent_file_raises_OSErrorc	CsZttd�}|��|�tjtjt�ttd��}|�d�WdQRX|�tjtjt�dS)Nr8z
short file)r1rr�r�r;r�r<r2)r3r r4rrr�!test_empty_file_raises_BadZipFile~s
z,OtherTests.test_empty_file_raises_BadZipFilec	Cs�t��}tj|dd��}|�dd�WdQRX|�t|jd�|�t|jd�|�t|j	�|�t|jdd�tt
d��}|�d�WdQRX|�t|jt
�dS)	z?Verify that testzip() doesn't swallow inappropriate exceptions.r8)r:zfoo.txtzO, for a Muse of Fire!Nz	bogus.txtr�zzipfile test data)rrr;r<r=r�r�rKr1r[rr2)r3r-r�r rrr�!test_closed_zip_raises_ValueError�sz,OtherTests.test_closed_zip_raises_ValueErrorcCs|�ttjtd�dS)z>Check that bad modes passed to ZipFile constructor are caught.�qN)r�r�r;r<r)r3rrr�test_bad_constructor_mode�sz$OtherTests.test_bad_constructor_modec	Cs�tjtdd��}|�dd�WdQRXtjtdd��F}|�d�|�t|jdd�|�t|jdd�|�t|jdd	�WdQRXdS)
z7Check that bad modes passed to ZipFile.open are caught.r8)r:zfoo.txtzO, for a Muse of Fire!NrBr��UZrU)r;r<rr=rKr�r�r1)r3r�rrr�test_bad_open_mode�s
zOtherTests.test_bad_open_modec
Csttjtdd��\}|�dd�|�d��:}x"tt�D]}|�|�d�d�q2W|�|��d�WdQRXWdQRXdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r8)r:zfoo.txtzO, for a Muse of Fire!rr(sO, for a Muse of Fire!N)	r;r<rr=r1r)r*rJrK)r3r�r r&rrr�
test_read0�szOtherTests.test_read0c	Cs0tjtdd��}|�t|jdd�WdQRXdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r8)r:zfoo.txtrBN)r;r<rr��KeyErrorr1)r3r�rrr�test_open_non_existent_item�sz&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.r8rwN)r�rqr;r<r)r3rrr�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modec	Cs6d}t�t�|�d��}|�t|jd�WdQRXdS)NsfPK.�C�@xPK..�C�@�xPK/!rBrv)r;r<rrr�rqr1)r3r-r�rrr�test_unsupported_compression�sz'OtherTests.test_unsupported_compressionc	Cs<tjtdd��$}|�dd�|�|��dg�WdQRXdS)zLCheck that a filename containing a null byte is properly
        terminated.r8)r:zfoo.txtqqqsO, for a Muse of Fire!zfoo.txtN)r;r<rr=rJrW)r3r�rrr�test_null_byte_in_filename�sz%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rJr;ZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locator)r3rrr�test_struct_sizes�szOtherTests.test_struct_sizesc
Cs�tjtdd�� }|�|jd�|�dd�WdQRXtjtdd��}|�|jd�WdQRXd}tjtdd��}||_|�dd�WdQRXtjtdd��}|�|j|�WdQRXd	�d
d�td�D��}|�d
�}tjtdd��}||_|�dd�WdQRXtjtdd��}|�|j|�WdQRXtjtdd��2}|�	t
��|d|_WdQRX|�dd�WdQRXtjtdd��}|�|j|�WdQRXtjtdd��}d|_|�dd�WdQRXtjtdd��}d|_WdQRXtjtdd��}|�|jd�WdQRXtjtdd��}d|_|�dd�WdQRXtjtdd��}d|_WdQRXtjtdd��}|�|jd�WdQRXdS)z8Check that comments on the archive are handled properly.r8)r:r(zfoo.txtzO, for a Muse of Fire!NrBs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]}d|dd�qS)z%dr�r}r)r%r&rrrr'�sz,OtherTests.test_comments.<locals>.<listcomp>i��r#soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter comment)r;r<rrJr�r=r,r)rLr6r7)r3r�Zzipfrr�Zcomment2rrr�
test_comments�sL
zOtherTests.test_commentsc
CsHt�tdtj��.}|�dd�|�t��d|_WdQRXWdQRXdS)Nr8zfoo.txtzO, for a Muse of Fire!zthis is an error)r;r<rr�r=r��	TypeErrorr�)r3r�rrr�test_unicode_commentszOtherTests.test_unicode_commentc	CsXt�tdtj��}|�|j�d|_WdQRXt�td��}|�|jd�WdQRXdS)Nr�sthis is a commentrB)r;r<rr�rrtr�rJ)r3r�rrr�$test_change_comment_in_empty_archives
z/OtherTests.test_change_comment_in_empty_archivec	Cs�t�tdtj��}|�dd�WdQRXt�tdtj��}|�|j�d|_WdQRXt�td��}|�|jd�WdQRXdS)Nr8zfoo.txtzO, for a Muse of Fire!r�sthis is a commentrB)	r;r<rr�r=rSrtr�rJ)r3r�rrr�'test_change_comment_in_nonempty_archivesz2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|��ytjtdd�}Wn tjk
rH|�d�YnXtjtdd�}|��ytjtdd�}Wn|�d�YnXdS)Nr8)r:rBz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)r;r<rr�r�rz)r3r�rrr�test_empty_zipfile'szOtherTests.test_empty_zipfilecCs*ttd�}|��|�tjtjtd�dS)Nr8rB)r1rr�r�r;r�r<)r3r rrr�test_open_empty_file8s
zOtherTests.test_open_empty_filecCs|�ttjdd�dS)NZ	seventies)i�rGrGrrr)r�r�r;rg)r3rrr�test_create_zipinfo_before_1980@sz*OtherTests.test_create_zipinfo_before_1980c	Cs4d}t�t�|�d��}|�|���WdQRXdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rBN)r;r<rrrnr[)r3rzr�rrr�#test_zipfile_with_short_extra_fieldDsz.OtherTests.test_zipfile_with_short_extra_fieldcCs�d}d}d}t�tdtj���}|jddd��}|�|�WdQRX|jddd���}|�t��|jddd�WdQRX|�t��|jdd	d�WdQRX|�t��|�d
d�WdQRX|�t��|�t	d�WdQRX|�t��|�
�WdQRX|�|�WdQRX|jd
dd��}|�|�WdQRXWdQRXt�td	��R}|�|�d�|�|�|�d�|�|�|�d
�|�|�|�
�ddd
g�WdQRXdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer8r�)r:rkZhandlerBrVZabcderCZbaz)r;r<rr�r1r2r�r�r=r r�rJrKrW)r3Zmsg1Zmsg2Zmsg3r�Zw2�w1rrr�test_open_conflicting_handlesSs2z(OtherTests.test_open_conflicting_handlesc
Cs:d}|�d�}t�td��}|�d|�WdQRXt�td���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�WdQRXWdQRXt��}tj|dd��}|�d|�WdQRXtj|dd���}|�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�WdQRXWdQRXdS)	NsWhere's Bruce?sBrucer8zfoo.txtrBrrD)r:)�findr;r<rr=r1r�r��SEEK_SETrJr��SEEK_CURrK�SEEK_ENDrPrr)r3�txt�blocr�r4r-rrr�test_seek_tellpsB
$zOtherTests.test_seek_tellcCstt�tt�dS)N)r	rr)r3rrrr��szOtherTests.tearDownN)'r�r�r�rlrmrorprrr
rsrurxr{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�rrrrrj�sF


	
7	&rjc@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestsc	Cs:|j}tjt�|�dd��}|�d|���WdQRXdS)z>Tests that files with bad CRCs return their name from testzip.rB)r:�afileN)�zip_with_bad_crcr;r<rrrJr[)r3rzr�rrr�test_testzip_with_bad_crc�sz-AbstractBadCrcTests.test_testzip_with_bad_crccCs�|j}tjt�|�dd��}|�tj|jd�WdQRXtjt�|�dd��.}|�dd��}|�tj|j�WdQRXWdQRXtjt�|�dd��L}|�dd��4}d|_	|�tj��x|�d�r�q�WWdQRXWdQRXWdQRXdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rB)r:r�Nr�)
r�r;r<rrr�r�rKr1�
MIN_READ_SIZE)r3rzr�Zcorrupt_filerrr�test_read_with_bad_crc�s$z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r�r�rrrrr��sr�c@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�r;r�r6r�rrrrr��sr�c@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�r;r�r6r�rrrrr��sr�c@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�r;r�r6r�rrrrr��sr�c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�r;r�r6r�rrrrr��sr�c@s\eZdZdZdZdZdZdZdd�Zdd	�Z	d
d�Z
dd
�Zedd��Z
dd�Zdd�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 testsc	Csdttd��}|�|j�WdQRXt�td�|_ttd��}|�|j�WdQRXt�td�|_	dS)Nr0rB)
r1rr2r-r;r<r�r�data2�zip2)r3r4rrrr5szDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dS)N)r�r�r�r	rr�r)r3rrrr�s


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)Nztest.txt�zero)r�r?r�rKr�)r3rrr�test_no_passwordsz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlztest.txtr�)r��setpasswordr�r?rKr�)r3rrr�test_bad_password sz!DecryptionTests.test_bad_passwordcCsH|j�d�|�|j�d�|j�|j�d�|�|j�d�|j�dS)Nspythonztest.txts12345r�)r�r�rJrK�plainr��plain2)r3rrr�test_good_password&sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)NZunicodeztest.txtZpython)�pwd)r�r�r�r�rKr1rI)r3rrr�test_unicode_password-sz%DecryptionTests.test_unicode_passwordc	Csr|j�d�|j}d}|�|�}t|�}|j�dd���0}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�|�||||��|j
}d|_
d|_d|_|�dtj�|�	|�
�d�|�|tj�|�	|�|�||||��||_
|�dtj�|�	|�
�t|��|�dtj�|�	|�
�d�|��WdQRXdS)Nspythons
encryptionztest.txtrBrrGr()r�r�r�r�rPr1r�r�r�rJr�r�rKr�Z_readbufferZ_offsetr�)r3r�Z	test_wordr�Zbloc_lenr4Z
old_read_sizerrrr�3s6
zDecryptionTests.test_seek_tellN)r�r�r��__doc__r-r�r�r�r5r�r�r�r
r�r�r�rrrrr��s	r�c@s`eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�"AbstractTestsWithRandomBinaryFilescCs6tdd�dtdd�}d�dd�t|�D��|_dS)N��@irGr(css&|]}t�dt�tdd��VqdS)z<fi���i�N)r�r�rr)r%r&rrrr�]sz@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr,r)r-)r.Z	datacountrrrr/Zs
z-AbstractTestsWithRandomBinaryFiles.setUpClassc	Cs&ttd��}|�|j�WdQRXdS)Nr0)r1rr2r-)r3r4rrrr5`sz(AbstractTestsWithRandomBinaryFiles.setUpcCstt�tt�dS)N)r	rr)r3rrrr�esz+AbstractTestsWithRandomBinaryFiles.tearDownc	Cs6t�|d|��}|�td�|�tt�WdQRXdS)Nr8zanother.name)r;r<r2r)r3r r6r?rrrrAisz4AbstractTestsWithRandomBinaryFiles.make_test_archivec	Csl|�||�t�|d|��H}|�t�}|�t|�t|j��|�||j�|�|�d�|j�WdQRXdS)NrBzanother.name)rAr;r<rKrrJrPr-)r3r r6r?�testdatarrrreos
z+AbstractTestsWithRandomBinaryFiles.zip_testcCs$xt|�D]}|�||j�q
WdS)N)r!rer6)r3r rrr�	test_readysz,AbstractTestsWithRandomBinaryFiles.test_readc
Cs�|�||�t�|d|���}g}|�t��&}x|�d�}|s>P|�|�q.WWdQRXg}|�d��&}x|�d�}|sxP|�|�qhWWdQRXd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�WdQRXdS)NrBrgzanother.namer()rAr;r<r1rrKrhr,rJrPr-)r3r r6r?rirjrkrlrmZ	testdata1Z	testdata2rrrrn}s,



z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs$xt|�D]}|�||j�q
WdS)N)r!rnr6)r3r rrrro�sz,AbstractTestsWithRandomBinaryFiles.test_openc
Cs�|�||�t�|d|��t}g}|�t��,}x$|�tdd��}|sDP|�|�q.WWdQRXd�|�}|�	t
|�t
|j��|�	||j�WdQRXdS)NrBrGir()rAr;r<r1rrKrrhr,rJrPr-)r3r r6r?rirjrkr�rrrru�s
z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs$xt|�D]}|�||j�q
WdS)N)r!rur6)r3r rrrrv�sz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r/r5r�rArer�rnrorurvrrrrr�Ys
r�c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesN)r�r�r�r;r�r6rrrrr��sr�c@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesN)r�r�r�r;r�r6rrrrr��sr�c@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesN)r�r�r�r;r�r6rrrrr��sr�c@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesN)r�r�r�r;r�r6rrrrr��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TellablecCs||_d|_dS)Nr)r4�offset)r3r4rrr�__init__�szTellable.__init__cCs|j�|�}|j|7_|S)N)r4r2r�)r3r-�nrrrr2�szTellable.writecCs|jS)N)r�)r3rrrr��sz
Tellable.tellcCs|j��dS)N)r4�flush)r3rrrr��szTellable.flushN)r�r�r�r�r2r�r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dS)N)r4)r3r4rrrr��szUnseekable.__init__cCs|j�|�S)N)r4r2)r3r-rrrr2�szUnseekable.writecCs|j��dS)N)r4r�)r3rrrr��szUnseekable.flushN)r�r�r�r�r2r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�UnseekableTestscCs�xdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��}|�
dd�|�
dd	�WdQRX|�|��dd
�d�tj|dd
��R}|�
d��}|�|��d�WdQRX|�
d��}|�|��d	�WdQRXWdQRXWdQRXqWdS)NcSs|S)Nr)r rrrr2�r(z/UnseekableTests.test_writestr.<locals>.<lambda>)�wrappersabcr8�oness111�twoss222rDsabcPKrB)r:)r�r��subTestrrr2�BufferedWriterr;r<r�r=rJrNr1rK)r3r�r �bfr?r��zopenrrr�
test_writestr�s

zUnseekableTests.test_writestrcCsX�xPdd�ttfD�]<}|j|d���$t��}|�d�t�|�}t�||�dtj	��j}|�
tt�t
td��}|�d�WdQRX|�td�t
td��}|�d	�WdQRX|�td
�WdQRX|�|��dd�d�tj|d
d��R}|�
d��}|�|��d�WdQRX|�
d
��}|�|��d	�WdQRXWdQRXWdQRXqWdS)NcSs|S)Nr)r rrrr2�r(z,UnseekableTests.test_write.<locals>.<lambda>)r�sabcr8r0s111r�s222r�rDsabcPKrB)r:)r�r�r�rrr2r�r;r<r��
addCleanupr	rr1rJrNrK)r3r�r r�r?�f2r�r�rrr�
test_write�s&

zUnseekableTests.test_writecCs�xdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��J}|�
dd��}|�d�WdQRX|�
dd��}|�d	�WdQRXWdQRX|�|��dd
�d�t�|��*}|�|�
d�d�|�|�
d�d	�WdQRXWdQRXqWdS)NcSs|S)Nr)r rrrr2
	r(z1UnseekableTests.test_open_write.<locals>.<lambda>)r�sabcr8r�s111r�s222rDsabcPK)r�r�r�rrr2r�r;r<r�r1rJrNrK)r3r�r r�r�r�rrr�test_open_write		s

zUnseekableTests.test_open_writeN)r�r�r�r�r�r�rrrrr��sr�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�)r.rrrr/	sz!TestsWithMultipleOpens.setUpClassc	Cs<t�|dtj��"}|�d|j�|�d|j�WdQRXdS)Nr8r�r�)r;r<r�r=r�r�)r3r r?rrrrA!	sz(TestsWithMultipleOpens.make_test_archivecCs�x�t|�D]�}|�|�tj|dd��x}|�d��H}|�d��2}|�d�}|�d�}||��7}||��7}WdQRXWdQRX|�||�|�||j�WdQRXq
WdS)NrB)r:r�i�)r!rAr;r<r1rKrJr�)r3r r��zopen1�zopen2r�r�rrr�test_same_file'	s


 z%TestsWithMultipleOpens.test_same_filecCs�x�t|�D]�}|�|�tj|dd��z}|�d��H}|�d��2}|�d�}|�d�}||��7}||��7}WdQRXWdQRX|�||j�|�||j�WdQRXq
WdS)NrB)r:r�r�i�)	r!rAr;r<r1rKrJr�r�)r3r r�r�r�r�r�rrr�test_different_file5	s


 z*TestsWithMultipleOpens.test_different_filecCs�x�t|�D]�}|�|�tj|dd��z}|�d��H}|�d�}|�d��(}|�d�}||��7}||��7}WdQRXWdQRX|�||j�|�||j�WdQRXq
WdS)NrB)r:r�i�r�)	r!rAr;r<r1rKrJr�r�)r3r r�r�r�r�r�rrr�test_interleavedC	s


 z'TestsWithMultipleOpens.test_interleavedcCs�x�t|�D]�}|�|�t���j}t�|d��&}|�|�d��}|�|�d��}WdQRX|�d�}|�d�}||��7}||��7}WdQRX|�	||j
�|�	||j�q
WdS)NrBr�r�i�)r!rA�
contextlib�	ExitStackr;r<�
enter_contextr1rKrJr�r�)r3r �stackr�r�r�r�r�rrr�test_read_after_closeR	s



z,TestsWithMultipleOpens.test_read_after_closecCs�x�t|�D]�}t�|dtj��B}|�d|j�|�d|j�|�d��}|�d�}WdQRXWdQRX|�	||jdd��t�|d��}|�d�}|�d�}WdQRX|�	||j�|�	||j�q
WdS)Nr8r�r�i�rB)
r!r;r<r�r=r�r�r1rKrJ)r3r r�r�r�r�rrr�test_read_after_write`	s
z,TestsWithMultipleOpens.test_read_after_writecCs�x�t|�D]�}t�|dtj��B}|�d|j�|�d��}|�d�|�d|j�WdQRXWdQRXt�|d��}|�d�}|�d�}WdQRX|�	||j�|�	||j�q
WdS)Nr8r�i�r�rB)
r!r;r<r�r=r�r1rKr�rJ)r3r r�r�r�r�rrr�test_write_after_readn	s
"
z,TestsWithMultipleOpens.test_write_after_readcCs�|�t�tjtdd��8}x0td�D]$}|�d�|�d��}WdQRXq$WWdQRXttj��}|�	|�
�d�WdQRXdS)NrB)r:r�r�)rArr;r<r)rKr1r��devnullZ
assertLess�fileno)r3r�rvr�r rrr�test_many_opens{	s

z&TestsWithMultipleOpens.test_many_openscCs�t�tdtj��}|�d|j�WdQRXt�tdtj��X}|�dd��@}|�d�}|�dd��}|�|j	�WdQRX||��7}WdQRXWdQRX|�
||j�t�t��}|�
|�d�|j	�WdQRXdS)Nr8r�r�rBi�r�)r;r<rr�r=r�r1rKr2r�rJ)r3r�Zr1r�r�rrr�test_write_while_reading�	s
 z/TestsWithMultipleOpens.test_write_while_readingcCstt�dS)N)r	r)r3rrrr��	szTestsWithMultipleOpens.tearDownN)r�r�r�r�r/rAr�r�r�r�r�r�r�r�r�rrrrr�	s

r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dS)N)r�r<r)r3rrrr5�	szTestWithDirectory.setUpc
Cs�t�td���}|�t�WdQRX|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)Nz
zipdir.zipr��br)r;r<rrVrrSr�rs�isdirr,ry)r3r�rrr�test_extract_dir�	s
z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS)Nr�)r�r<rsr,rr�)r3rrr�
test_bug_6050�	szTestWithDirectory.test_bug_6050c	Cs�tj�td�}t�|�t�|�jd@}t�t	d��|}|�
|�|jd}|�|j
�d��|�|j|d>dB�|�
|d�|jd}|�|j
d	�|�|j|d>dB�WdQRXt�t	d
���}|jd}|�|j
�d��|�|j|d>dB�|jd}|�|j
d	�|�|j|d>dB�tj�td�}t�|�|�|�|�tj�tj�|d���|�tt�|��d�WdQRXdS)
Nrvi��r8rz/x/r��yrGzy/rBrQr�)r�rsr,rr<�stat�st_moder;r<rr2rtrSrIr"rJr�rVr�rP�listdir)r3�dirpathr:r�r�rQrrr�test_write_dir�	s0



 



z TestWithDirectory.test_write_dirc	Cs�t�tj�td��t�td��8}|�dd�|j	d}|�
|jd�|�
|jd�WdQRXt�td���}|j	d}|�
|j�d��|�
|jd�tj�td�}t�|�|�|�|�
tj�tj�|d���|�
t�|�dg�WdQRXdS)	Nrvr8zx/r(ri�ArBrQ)r�r<rsr,rr;r<rr=rtrJrIr�rSr"rVr�r�)r3r�r�rQrrr�test_writestr_dir�	s



z#TestWithDirectory.test_writestr_dircCs tt�tj�t�rtt�dS)N)r
rr�rsryrr	)r3rrrr��	szTestWithDirectory.tearDownN)	r�r�r�r5r�r�r�r�r�rrrrr��	sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ZipInfoTestscCsHtj�t�}|�t�|j�d�|�|�	��|�|j
tj�
t��dS)Nztest_zipfile.py)r;rg�	from_filer rJ�	posixpathr*rIr�is_dirrYr�rs�getsize)r3�zirrr�test_from_file�	szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dS)Nztest_zipfile.py)r;rgr�rprqr rJr�r*rIrr�rYr�rsr�)r3r�rrr�test_from_file_pathlike�	sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr)r;rgr�r��fsencoder rJr�r*rIrr�rYrsr�)r3r�rrr�test_from_file_bytes�	sz!ZipInfoTests.test_from_file_bytesc	Csdttd��P}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��WdQRXdS)Nr�r)r1r r;rgr�r�rJr�r*rIrr�rYr�rsr�)r3r r�rrr�test_from_file_fileno�	s
z"ZipInfoTests.test_from_file_filenocCs`tj�tj�t��}tj�|d�}|�|j	d�|�
|���|�|jtj
�|�|jd�dS)NZstdlib_testsz
stdlib_tests/r)r�rsr�abspathr r;rgr�rJrIrSr�r�r�rY)r3r�r�rrr�
test_from_dir�	szZipInfoTests.test_from_dirN)r�r�r�r�r�rrrrrrrr��	s
r�c@sHeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
dS)�CommandLineTestcOs(tjd|�|�\}}}|�tj��d�S)N�-mr;r�)rr;)rZassert_python_okrhr��lineseprL)r3�argsr>�rc�out�errrrr�
zipfilecmd�	s
zCommandLineTest.zipfilecmdcGstjd|��S)N�-mr;)rr;)rZassert_python_failure)r3rrrr�zipfilecmd_failure
sz"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr(susageserrorsrequiredz-lr�)r
rJrQr�ZassertNotEqual�strip)r3rr	r
rrr�test_bad_use
szCommandLineTest.test_bad_usecCs\td�}x(dD] }|�||�}|�|��d�qWtd�}|�d|�\}}}|�|d�dS)Nz
zipdir.zip)z-tz--testsDone testingztesttar.tarz-tr()rrrJ�rstripr
)r3�zip_name�optr	rr
rrr�test_test_command
s
z!CommandLineTest.test_test_commandc	Csptd�}t��}t�|d��}|�|�WdQRX|���dd�}x(dD] }|j||dd�}|�	||�qHWdS)Nz
zipdir.ziprBr#�backslashreplace)z-lz--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrLr;r<rMrNrLrrJ)r3rr,ZtfZexpectedrr	rrr�test_list_command
s
z!CommandLineTest.test_list_commandc
Cs|�tt�ttd��}|�d�WdQRXt�t�|�tt�ttj	�
td�d��}|�d�WdQRXttg}ttdtdg}x�dD]�}zt|j|tf|��}|�
|d�t�t��B}|�
|��|�|�
|�|d	�d
�|�
|�|d�d�WdQRXWdtt�Xq�WdS)
Nr8ztest 1zfile.txtztest 2r_z	/file.txt)z-cz--creater(rstest 1r�stest 2)r�r	rr1r2r�r<�	TESTFNDIRr
rsr,rrrJr;r<rWrK)r3r �filesrWrr	rrrr�test_create_command$
s$

$z#CommandLineTest.test_create_commandc	
Cs�td�}x�dD]�}t���}|�|||�}|�|d�t�|���}x�|��D]x}tj�	||j
�dtj��}|�
�r�|�tj�|��qJ|�tj�|��t|d��}|�|��|�|��WdQRXqJWWdQRXWdQRXqWdS)Nz
zipdir.zip)z-ez	--extractr(r_r�)rrrrJr;r<rXr�rsr,rIrhr#r�rSr�r\r1rK)	r3rrrSr	rr�rsr rrr�test_extract_command:
s
z$CommandLineTest.test_extract_commandN)r�r�r�rr
rrrr
rrrrrrr�	s
	r�__main__)Kr�rrr��importlib.utilr&rpr�rTr�r;riZtempfilerrrrZtest.supportrrrr	r
rrr
rrrrrr*Z
DATAFILES_DIRrErr!r"ZTestCaser�r�r�r�r�r�rr	r
rrrrrrrDrjr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr��mainrrrr�<module>s�0	





BAag[



7
}A#O