Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_zipfile.cpython-34.pyo

�
f f�0�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZmZddlmZmZmZmZmZmZmZmZmZedZedZdZdZd	d
fddfd
dfddfgZdd�Zdd�Zdd�Z Gdd�d�Z!Gdd�de!e	j"�Z#eGdd�de!e	j"��Z$eGdd�de!e	j"��Z%eGdd �d e!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,e	j"�Z,Gd-d.�d.e	j"�Z-Gd/d0�d0e	j"�Z.Gd1d2�d2�Z/Gd3d4�d4e/e	j"�Z0eGd5d6�d6e/e	j"��Z1eGd7d8�d8e/e	j"��Z2eGd9d:�d:e/e	j"��Z3Gd;d<�d<e	j"�Z4Gd=d>�d>�Z5Gd?d@�d@e5e	j"�Z6eGdAdB�dBe5e	j"��Z7eGdCdD�dDe5e	j"��Z8eGdEdF�dFe5e	j"��Z9eGdGdH�dHe	j"��Z:GdIdJ�dJe	j"�Z;GdKdL�dL�Z<GdMdN�dNe<e	j"�Z=eGdOdP�dPe<e	j"��Z>eGdQdR�dRe<e	j"��Z?eGdSdT�dTe<e	j"��Z@eAdUkr�e	jB�ndS)V�N)�
TemporaryFile)�randint�random�getrandbits)	�TESTFN�findfile�unlink�rmtree�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout�check_warnings�2�di�Zzipfile_datafilesZ	_ziptest1Z
1q2w3e4r5tzziptest2dir/_ziptest2Z
qawsedrftgz!ziptest2dir/ziptest3dir/_ziptest3Z
azsxdcfvgbz-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3Z
6y7u8i9o0pcCstd|�j|d�S)N��little)r�to_bytes)�size�r�6/opt/alt/python34/lib64/python3.4/test/test_zipfile.py�getrandbytessrccsZtVt��}|V|j|j�WdQXtj��}|V|j|j�WdQXdS)N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�frrr�	get_files src
Cs-tdtf��|j|d�SWdQXdS)N��rU)r�DeprecationWarning�open)�zipfp�fnrrr�openU)sr&c@sNeZdZedd��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�Zd5S)6�AbstractTestsWithSourceFilecCs5dd�tt�D�|_dj|j�|_dS)NcSs,g|]"}td|t�fd��qS)z'Zipfile test line %d. random float: %f
�ascii)�bytesr)�.0�irrr�
<listcomp>0s	z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data)�clsrrr�
setUpClass.s	z&AbstractTestsWithSourceFile.setUpClassc	Cs,ttd��}|j|j�WdQXdS)N�wb)r#r�writer2)�self�fprrr�setUp5sz!AbstractTestsWithSourceFile.setUpc
CsUtj|d|��:}|jtd�|jtt�|jd|j�WdQXdS)N�wzanother.name�strfile)�zipfile�ZipFiler6r�writestrr2)r7r�compressionr$rrr�make_test_archive:sz-AbstractTestsWithSourceFile.make_test_archivecCs�|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�}dd�|D�}|jt|�d
�|j
t|�|j
d|�|j
d|�x*|D]"}
|j|
jt|j��q=WxUtddfD]D}|j|�}|j|j|�|j|jt|j��qsW|j�WdQXdS)N�rzanother.namer;�file�z	File Namer�Modified�Size�z%Y-%m-%dz%H:%M:%S�cSsg|]}|j�qSr)�filename)r*r+rrrr,ds	z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)r@r<r=�assertEqual�readrr2r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforH�testzip)r7rr?r$r8�	directory�linesr%�date�time_r�names�infosr+�nm�inforrr�zip_testAsH
  z$AbstractTestsWithSourceFile.zip_testcCs.x't|�D]}|j||j�q
WdS)N)rrcr?)r7rrrr�
test_basicusz&AbstractTestsWithSourceFile.test_basicc	Cs|j||�tj|d|���}g}|jt��4}x*|jd�}|s\Pn|j|�qCWWdQXg}|jd��4}x*|jd�}|s�Pn|j|�q�WWdQX|jdj|�|j	�|jdj|�|j	�WdQXdS)NrA�zanother.namer-)
r@r<r=r#rrJ�appendrIr1r2)	r7rr?r$�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_testys$z)AbstractTestsWithSourceFile.zip_open_testcCs.x't|�D]}|j||j�q
WdS)N)rrlr?)r7rrrr�	test_open�sz%AbstractTestsWithSourceFile.test_opencCs�|j||�tj|d|��w}g}|jt��=}x3|jtdd��}|sePn|j|�qCWWdQX|jdj	|�|j
�WdQXdS)NrArFir-)r@r<r=r#rrJrrfrIr1r2)r7rr?r$rgrhrirrr�zip_random_open_test�sz0AbstractTestsWithSourceFile.zip_random_open_testcCs.x't|�D]}|j||j�q
WdS)N)rrnr?)r7rrrr�test_random_open�sz,AbstractTestsWithSourceFile.test_random_opencCs�|j||�tj|d��R}|jt��:}g}x*|jd�}|sYPn|j|�q@WWdQXWdQX|jdj|�|j	�dS)NrArFr-���)
r@r<r=r#r�read1rfrIr1r2)r7rr?r$�zipopen�zipdatarirrr�zip_read1_test�sz*AbstractTestsWithSourceFile.zip_read1_testcCs.x't|�D]}|j||j�q
WdS)N)rrtr?)r7rrrr�
test_read1�sz&AbstractTestsWithSourceFile.test_read1cCs�|j||�tj|d��h}|jt��P}g}x@|jd�}|jt|�d�|soPn|j|�q@WWdQXWdQX|j	dj
|�|j�dS)NrA�
r-)r@r<r=r#rrqZassertLessEqualrOrfrIr1r2)r7rr?r$rrrsrirrr�zip_read1_10_test�sz-AbstractTestsWithSourceFile.zip_read1_10_testcCs.x't|�D]}|j||j�q
WdS)N)rrwr?)r7rrrr�
test_read1_10�sz)AbstractTestsWithSourceFile.test_read1_10cCs�|j||�tj|d��o}|jt��W}d}xG|j�}|sVPn||7}|jd�}|syPn||7}q@WWdQXWdQX|j||j�dS)NrAr-�d)	r@r<r=r#r�readlinerJrIr2)r7rr?r$rrr2rJrrr�zip_readline_read_test�s
z2AbstractTestsWithSourceFile.zip_readline_read_testcCs.x't|�D]}|j||j�q
WdS)N)rr{r?)r7rrrr�test_readline_read�sz.AbstractTestsWithSourceFile.test_readline_readcCsw|j||�tj|d��O}|jt��7}x-|jD]"}|j�}|j||�qAWWdQXWdQXdS)NrA)r@r<r=r#rr0rzrI)r7rr?r$rr�line�linedatarrr�zip_readline_test�sz-AbstractTestsWithSourceFile.zip_readline_testcCs.x't|�D]}|j||j�q
WdS)N)rrr?)r7rrrr�
test_readline�sz)AbstractTestsWithSourceFile.test_readlinecCs�|j||�tj|d��^}|jt��}|j�}WdQXx0t|j|�D]\}}|j||�q\WWdQXdS)NrA)	r@r<r=r#r�	readlines�zipr0rI)r7rr?r$rr�ziplinesr}�ziplinerrr�zip_readlines_test�sz.AbstractTestsWithSourceFile.zip_readlines_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrr�test_readlinessz*AbstractTestsWithSourceFile.test_readlinescCsz|j||�tj|d��R}|jt��:}x0t|j|�D]\}}|j||�qJWWdQXWdQXdS)NrA)r@r<r=r#rr�r0rI)r7rr?r$rrr}r�rrr�zip_iterlines_tests
z.AbstractTestsWithSourceFile.zip_iterlines_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrr�test_iterlines
sz*AbstractTestsWithSourceFile.test_iterlinescCs�tjtd|j��}|jdd�WdQXtjtd|j��Q}|jd��9}|j|jd�d�|j|jd�d�WdQXWdQXdS)	z>Check for cases where compressed data is larger than original.r:r;Z12NrArF�1�2)r<r=rr?r>r#rIrJ)r7r$Zopenobjrrr�test_low_compressionsz0AbstractTestsWithSourceFile.test_low_compressioncCsTtjtd�}|jddd|j�|jd�}|j|j|j�dS)Nr:zb.txtzhello world�
compress_type)r<r=rr>r?rYrIr�)r7r$rbrrr�test_writestr_compressionsz5AbstractTestsWithSourceFile.test_writestr_compressioncCs�x�d	D]�}|d}t|�}tjtj�d|j��W}|jd|�|jdd��,}|j|�}|j	t
|�|�WdQXWdQXqWdS)
NrF����@r:�foorA)rFr�r�r�r�)rr<r=rrr?r>r#rJrIrO)r7Z	test_sizerXZjunk�zipfr8Zbufrrr�test_read_return_size#s

!z1AbstractTestsWithSourceFile.test_read_return_sizecACs�tj�}tj|dd��/}|jd|jd|j�|j�}WdQX|j�}tj|�}tj|��P}|j	d��8}|j
|d�|jt��|j
�WdQXWdQXWdQXtj|�}tj|��\}|j	d��D}|j
|d�|jt��x|j
d�r7q%WWdQXWdQXWdQXtj|�}tj|��\}|j	d��D}|j
|d�|jt��x|jd�r�q�WWdQXWdQXWdQXdS)N�moder:r;r��ry)rrr<r=r>r2r?�tellrMr#�truncate�assertRaises�EOFErrorrJrq)r7r8r�Z
end_offset�zipfiledatarrrrr�test_truncated_zipfile/s2z2AbstractTestsWithSourceFile.test_truncated_zipfilecCstt�tt�dS)N)rrr)r7rrr�tearDownMs
z$AbstractTestsWithSourceFile.tearDownN)�__name__�
__module__�__qualname__�classmethodr4r9r@rcrdrlrmrnrortrurwrxr{r|rr�r�r�r�r�r�r�r�r�r�rrrrr'-s44

	r'c@s�eZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNcCsQ|j||�tj|d��)}|jd�}|j|jd�WdQXdS)NrAr;i��i�)r@r<r=rYrI�
external_attr)r7rr?r$�zinforrr�zip_test_writestr_permissionsWsz7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs.x't|�D]}|j|tj�q
WdS)N)rr�r<�
ZIP_STORED)r7rrrr�test_writestr_permissions`sz3StoredTestsWithSourceFile.test_writestr_permissionscCsotjtdtj��}|jtd�WdQXtjtdtj�� }|j|j�dg�WdQXdS)Nr:z	/absoluterA�absolute)r<r=rr�r6rrIrV)r7r$rrr�test_absolute_arcnamesdsz0StoredTestsWithSourceFile.test_absolute_arcnamescCs�tjtdtj��}|jtt�WdQXtjtdtj��6}|jd|j�|j|j	�tdg�WdQXdS)z&Test appending to an existing zipfile.r:N�ar;)
r<r=rr�r6rr>r2rIrV)r7r$rrr�test_append_to_zip_fileks
z1StoredTestsWithSourceFile.test_append_to_zip_filecCs�dd}ttd��}|j|�WdQXtjtdtj��}|jtt�WdQXttd��N}|jt|��tj|d�� }|j	|j
�tg�WdQXWdQXdS)z9Test appending to an existing file that is not a zipfile.sI am not a ZipFile!rvr5Nr��rbrA)r#rr6r<r=r�r�seekrOrIrV)r7r2rr$rrr�test_append_to_non_zip_filets
z5StoredTestsWithSourceFile.test_append_to_non_zip_filecCs�tjtdtj��}|jtt�WdQXttd��}|jd�WdQXtjtd��}|j|tj�WdQXdS)Nr:r�z
rA)r<r=rr�r6rr#�assertIsInstance)r7r$rrrr�test_ignores_newline_at_end�sz5StoredTestsWithSourceFile.test_ignores_newline_at_endcCs�tjtdtj�� }d|_|jtt�WdQXttd��}|jd�WdQXtjtd��-}|j|tj�|j	|jd�WdQXdS)Nr:sthis is a commentr�zabcdef
rA)
r<r=rr��commentr6rr#r�rI)r7r$rrrr�)test_ignores_stuff_appended_past_comments�s	zCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentscCsctjtd��K}|jt�ttd��&}|j|jt�|j��WdQXWdQXdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r:r�N)r<r=rr6rr#rIrJ)r7r$rrrr�test_write_default_name�s
z1StoredTestsWithSourceFile.test_write_default_namecCsftjtdd��}|jdd�WdQXtjtdd��}|jt|jt�WdQXdS)z]Check that trying to call write() on a readonly ZipFile object
        raises a RuntimeError.r�r:zsomefile.txt�bogusNrA)r<r=rr>r��RuntimeErrorr6r)r7r$rrr�test_write_to_readonly�sz0StoredTestsWithSourceFile.test_write_to_readonlycCsEtjtd�tjtd��}|jt|jt�WdQXdS)Nrr:)rr)	�os�utimerr<r=rr��
ValueErrorr6)r7r$rrr�test_add_file_before_1980�sz3StoredTestsWithSourceFile.test_add_file_before_1980)r�r�r�r<r�r?r�r�r�r�r�r�r�r�r�r�r�rrrrr�Rs			
	r�c@s%eZdZejZdd�ZdS)�DeflateTestsWithSourceFilecCs�tjtd��}}|jtdtj�|jtdtj�|jd�}|jd�}|j|j	tj�|j|j	tj�WdQXdS)zUCheck that files within a Zip archive can have different
        compression options.r:ZstoremeZ	deflatemeN)
r<r=rr6rr��ZIP_DEFLATEDrYrIr�)r7r$ZsinfoZdinforrr�test_per_file_compression�sz4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�r<r�r?r�rrrrr��s	r�c@seZdZejZdS)�Bzip2TestsWithSourceFileN)r�r�r�r<�	ZIP_BZIP2r?rrrrr��sr�c@seZdZejZdS)�LzmaTestsWithSourceFileN)r�r�r�r<�ZIP_LZMAr?rrrrr��sr�c@sjeZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�AbstractTestZip64InSmallFilescCs2dd�tdt�D�}dj|�|_dS)Ncss"|]}td|d�VqdS)zTest of zipfile line %d.r(N)r))r*r+rrr�	<genexpr>�sz;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>rs
)r.r/r1r2)r3r0rrrr4�s	z(AbstractTestZip64InSmallFiles.setUpClassc	CsVtj|_tj|_dt_dt_ttd��}|j|j�WdQXdS)Ni��	r5)	r<�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr#rr6r2)r7r8rrrr9�s		z#AbstractTestZip64InSmallFiles.setUpcCstj|d|dd��:}|jtd�|jtt�|jd|j�WdQXtj|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�WxUtddfD]D}|j|�}|j|j|�|j|jt
|j��q�W|j�WdQXdS)Nr:�
allowZip64Tzanother.namer;rArCz	File NamerrDrErFz%Y-%m-%dz%H:%M:%SrGcSsg|]}|j�qSr)rH)r*r+rrrr,s	z:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)r<r=r6rr>r2rIrJrrKrLrMrNrOrPrQrRrSrTrUrVrWrXrYrHrZ)r7rr?r$r8r[r\r%r]r^rr_r`r+rarbrrrrc�sN

  z&AbstractTestZip64InSmallFiles.zip_testcCs.x't|�D]}|j||j�q
WdS)N)rrcr?)r7rrrrrdsz(AbstractTestZip64InSmallFiles.test_basiccCstjtd|jdd�}d|_d}x4t|�D]&}|jd|d|dd	�q:W|jt|j	��|�|j
�tjtd
|j�}|jt|j	��|�xLt|�D]>}|jd|�jd�}|j|d|dd	�q�W|j
�dS)Nr:r�Try�zfoo%08dz%drG�9rAr()
r<r=rr?�debugr.r>rIrOrV�closerJ�decode)r7r��numfilesr+�zipf2�contentrrr�test_too_many_filess		$
 z1AbstractTestZip64InSmallFiles.test_too_many_filescCs�tjtd|jdd�}d|_d}x4t|�D]&}|jd|d|dd	�q:W|jt|j	��|�|j
tj��|jd|d
�WdQX|jt|j	��|�|j�tjtd|jdd�}d|_|jt|j	��|�|j
tj��|jd|d
�WdQX|jt|j	��|�|j�tjtd|jdd�}d|_|jt|j	��|�d
}x7t||�D]&}|jd|d|dd	�q�W|jt|j	��|�|j�tjtd|j�}|jt|j	��|�xLt|�D]>}|j
d|�jd�}|j|d|dd	�qSW|j�dS)Nr:r�Fryr�zfoo%08dz%drGr�r-r�Tr�rAr()r<r=rr?r�r.r>rIrOrVr��LargeZipFiler�rJr�)r7r�r�r+Z	numfiles2r�r�rrr�test_too_many_files_append-sD		$
		
		$
 z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs0|jt_|jt_tt�tt�dS)N)r�r<r�r�r�rrr)r7rrrr�Ts
z&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r4r9rcrdr�r�r�rrrrr��s
9'r�c@sIeZdZejZdd�Zdd�Zdd�Zdd�Z	d	S)
�StoredTestZip64InSmallFilescCsDtj|d|dd��#}|jtj|jtd�WdQXdS)Nr:r�Fzanother.name)r<r=r�r�r6r)r7rr?r$rrr�large_file_exception_test_sz5StoredTestZip64InSmallFiles.large_file_exception_testcCsGtj|d|dd��&}|jtj|jd|j�WdQXdS)Nr:r�Fzanother.name)r<r=r�r�r>r2)r7rr?r$rrr�large_file_exception_test2dsz6StoredTestZip64InSmallFiles.large_file_exception_test2cCsAx:t|�D],}|j|tj�|j|tj�q
WdS)N)rr�r<r�r�)r7rrrr�test_large_file_exceptionisz5StoredTestZip64InSmallFiles.test_large_file_exceptioncCsutjtdtjdd��}|jtd�WdQXtjtdtj�� }|j|j�dg�WdQXdS)Nr:r�Tz	/absoluterAr�)r<r=rr�r6rrIrV)r7r$rrrr�ns
z2StoredTestZip64InSmallFiles.test_absolute_arcnamesN)
r�r�r�r<r�r?r�r�r�r�rrrrr�[s
	r�c@seZdZejZdS)�DeflateTestZip64InSmallFilesN)r�r�r�r<r�r?rrrrr�vsr�c@seZdZejZdS)�Bzip2TestZip64InSmallFilesN)r�r�r�r<r�r?rrrrr�{sr�c@seZdZejZdS)�LzmaTestZip64InSmallFilesN)r�r�r�r<r�r?rrrrr��sr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�PyZipFileTestscCs+|d|kr'|j|d|�ndS)N�o�c)rP)r7�namerVrrr�assertCompiledIn�szPyZipFileTests.assertCompiledIncCs�tj|tjdtjtjk�s7|jd�ntjj|d�}y-tj|tjtj	B�}tj
|�Wntk
r�|jd�YnXt|�dS)NZ
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r��access�W_OK�supports_effective_idsZskipTest�pathr1r#�O_WRONLY�O_CREATr��	Exceptionr)r7r�rH�fdrrr�requiresWriteAccess�s
z"PyZipFileTests.requiresWriteAccesscCs�|jtjjt��t��}tj|d���}t}|jd�s^|jd�r�|j	tj
�}tjdk	r�|j|j	tj��nd|kr�t
jj|�}q�|dd�}n|j|�tjj|�}|j||j��|j||j��WdQXWdQXt���}tj|d���}t}|jd	�ro|dd
�}n|j|d�ddtjj|�f}|j||j��|j||j��WdQXWdQXdS)Nr:�.pyc�.pyo�__pycache__rFZtestpackagez%s/%srp)r�r�rp)r�r�r��dirname�__file__rr<�	PyZipFile�endswithrQ�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrVr�)r7�tr$r%Z
path_splitZbnrrr�test_write_pyfile�s,!
"!z PyZipFileTests.test_write_pyfilecCs�ddl}tjj|j�}|j|�t��[}tj|d��@}|j	|�|j
�}|jd|�|jd|�WdQXWdQXdS)Nrr:zemail/__init__.pyzemail/mime/text.py)�emailr�r�r�r�r�rr<r�r�rVr�)r7r��
packagedirr�r$r_rrr�test_write_python_package�s
!
z(PyZipFileTests.test_write_python_packagec,Cs`ddl}tjj|j�}|j|�t��#}tj|d��}t	��}|j
|�WdQX|j�}|jd|k�t	�� }|j
|ddd��WdQX|j�}|jd|k�dd�}t	��0}|j
t��|j
|d|�WdQXWdQX|j�}|r=t|�n|jd|k�WdQXWdQXdS)	Nrr:�SyntaxError�
filterfunccSsdS)NFr)Zwhateverrrr�<lambda>�szCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>cSstjj|�jd�S)NZbad)r�r�r��
startswith)r�rrr�filter�szAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rr�r�r�r�r�rr<r�r
r�rMrR�assertWarns�UserWarning�print)r7rr�r�r$Z	reportSIOZ	reportStrrrrr�"test_write_filtered_python_package�s&
!
z1PyZipFileTests.test_write_filtered_python_packagecCs�ddl}tjj|j�}|j|�tr:dnd}|dkrRdnd}t��i}tj	|dd|��H}|j
|�|j�}|jd||�|jd||�WdQXWdQXdS)	NrrFz.pyoz.pycr:�optimizezemail/__init__zemail/mime/text)
r�r�r�r�r�r��	__debug__rr<r�r�rVrP)r7r�r�ZoptlevelZextr�r$r_rrr�test_write_with_optimization�s

z+PyZipFileTests.test_write_with_optimizationc)Cs5tjt�zttjjtd�d��}|jd�WdQXttjjtd�d��}|jd�WdQXttjjtd�d��}|jd�WdQXt��k}tj	|d��P}|j
t�|j�}|jd|�|jd|�|j
d|�WdQXWdQXWdtt�XdS)Nzmod1.pyr:z
print(42)
zmod2.pyzprint(42 * 42)
zmod2.txtzbla bla bla
)r��mkdirrr#r�r1r6rr<r�r�rVr�r�r	)r7r8r�r$r_rrr�test_write_python_directory�s
!!!!
 z*PyZipFileTests.test_write_python_directoryc%Cs�tjt�z�ttjjtd�d��}|jd�WdQXttjjtd�d��}|jd�WdQXt��g}tj	|d��L}|j
tddd��|j�}|jd|�|j
d|�WdQXWdQXWdtt�XdS)	Nzmod1.pyr:z
print(42)
zmod2.pyzprint(42 * 42)
rcSs|jd�S)Nzmod2.py)r�)r%rrrrszEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>)r�rrr#r�r1r6rr<r�r�rVr�r�r	)r7r8r�r$r_rrr�$test_write_python_directory_filtered
s
!!! z3PyZipFileTests.test_write_python_directory_filteredcCsvt��g}tj|d��L}ttd��}|jd�WdQX|jt|jt�t	t�WdQXWdQXdS)Nr:z!most definitely not a python file)
rr<r�r#rr6r�r�r�r)r7r�r$rrrr�test_write_non_pyfiles
!z$PyZipFileTests.test_write_non_pyfilec%Cstjt�z�ttjjtd�d��}|jd�WdQXt���}tj	|d���}t
��#}|jtjjtd��WdQX|jd|j
��|j�}|jd|�|jd|�|jd|�WdQXWdQXWdtt�XdS)Nzmod1.pyr:zBad syntax in python file
rzmod1.pyczmod1.pyo)r�rrr#r�r1r6rr<r�r
r�rPrMrVr�r	)r7r8r�r$�sr_rrr�test_write_pyfile_bad_syntax%s
!!" z+PyZipFileTests.test_write_pyfile_bad_syntaxN)
r�r�r�r�r�r�r�rrr
rrrrrrrr��s
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	e
jjdkd�d
d��Z
ej	e
jjdkd�dd��Zdd�ZdS)�ExtractTestscCs'tjtdtj��.}x$tD]\}}|j||�q"WWdQXtjtd���}x�tD]�\}}|j|�}tjj	tj
�|�}tjj|�}|j||�t
|d��#}|j|j�|j��WdQXt|�qdWWdQXttjj	tj
�d��dS)Nr:rAr��ziptest2dir)r<r=rr��SMALL_TEST_DATAr>�extractr�r�r1�getcwd�normpathrIr#�encoderJrr	)r7r$�fpath�fdata�writtenfile�correctfilerrrr�test_extract>s"zExtractTests.test_extractcCstjtdtj��.}x$tD]\}}|j||�q"WWdQXtjtd���}|j�xmtD]e\}}tjj	tj
�|�}t|d��#}|j|j
�|j��WdQXt|�qnWWdQXttjj	tj
�d��dS)Nr:rAr�r)r<r=rr�rr>�
extractallr�r�r1rr#rIrrJrr	)r7r$rrZoutfilerrrr�test_extract_allVs
"zExtractTests.test_extract_allc
CsK|jtjj|��t|d��}|j|j�|�WdQXdS)Nr�)rRr�r��isfiler#rIrJ)r7rHr�rrrr�
check_filehszExtractTests.check_filecCs[tjj}|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)r<r=Z_sanitize_windows_namerI)r7Zsanrrr�test_sanitize_windows_namemsz'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)r%r&)r'r&)r(r&)r)r&)r*r&)r+r&)r,r&)r-r&)�_test_extract_hackers_arcnames)r7Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_casests	z7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCsPddddddd 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)r1r2)r3r2)r4r2)r5r2)r6r2)r7r2)r8r2)r9r2)r:r2)r;r2)r<r=)r>r=)r?r=)r@r=)rAr2)rBr2)rCrD)rErF)rGrH)r.)r7Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_only�s(	z7ExtractTests.test_extract_hackers_arcnames_windows_onlyr#zRequires / as path separator.cCs dddg}|j|�dS)	N�	//foo/bar�foo/bar�../../foo../../ba..r�foo../ba..r�
foo/..\bar)rJrK)rLrM)rNrN)r.)r7Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_only�s	z5ExtractTests.test_extract_hackers_arcnames_posix_onlyc
"CsVxO|D]G\}}d|j�}tjtdtj��5}tj�}||_d|_|j||�WdQX|j	t
jd�}t
jj
ddd�}t
jj
||jd��}tjtd	��<}|j||�}	|j|	|d
d||	|f�WdQX|j||�td�tjtd	��}|j|�WdQX|j||�td�t
jj
t
j�|jd��}tjtd	��0}|j|�}	|j|	|d
d|�WdQX|j||�t|jd�d
�tjtd	��}|j�WdQX|j||�t|jd�d
�tt�qWdS)Nsfoobarr:i�r�r#�targetZsubdirZsubsubrA�msgzextract %r: %r != %rz
extract %rri�)rr<r=rr��ZipInforHr�r>�replacer�r�r�r1rQrrIr!r	rrr)
r7Z	hacknamesZarcnameZ	fixednamer�r$r�Z
targetpathrrrrrr.�sB		

$z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�rrr!r$r/�unittestZskipIfr�r�r�rIrOr.rrrrr=s
**	rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
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�
OtherTestscCs4tjtdtj��Z}|jdd�|jt��|jdd�WdQX|j|j�dgd�WdQXtjtd���}|j	�}d}x6|D].}|j
|��}||j�7}WdQXq�W|j|dd	h�d}x!|D]}||j|�7}q�W|j|dd	h�WdQXdS)
Nr:r�r�Zbar�rAr-sfoobarsbarfoo)
r<r=rr�r>rrrIrVrWr#rJrP)r7r$r`r2rbrrrrr�test_open_via_zip_info�s #

z!OtherTests.test_open_via_zip_infocCs�tj�}tj|d��}|jdd�WdQXtj|d��J}x@dD]8}|jt��|jd|�}WdQX|j�qSWWdQXdS)Nr:zspam.txts
ababagalamagarA�Ur!)rXzrU)	rrr<r=r>rr"r#r�)r7rr$r�rrrrr�test_universal_deprecation�s
z%OtherTests.test_universal_deprecationcCs�tj�}ddd}tj|dtj��}|jt|�WdQXd}tj|d��:}t|t��"}x|D]}||7}qWWdQXWdQX|j||j	dd��dS)	Nsa
r�ir:r-rAs
s
)
rrr<r=r�r>rr&rIrS)r7rr2r$�data2rrr}rrr�test_universal_readaheads�s
z$OtherTests.test_universal_readaheadscCs^tjtd��F}x<dD]4}tj|�}|jdO_|j||�qWWdQXdS)Nr:Zabcdefghijklmnopr)r<r=rrRZ	flag_bitsr>)r7Zorig_zipr2r�rrr�-test_writestr_extended_local_header_issue1202�s

z8OtherTests.test_writestr_extended_local_header_issue1202cCs�tjtd��A}x7tD]/\}}|j||�|j|jd�qWWdQX|j|jd�tjtd��}|j|jd�WdQX|j|jd�dS)z8Check that the zipfile is closed after the 'with' block.r:zzipfp is not openNzzipfp is not closedrA)r<r=rrr>ZassertIsNotNoner8�assertIsNone)r7r$rrrrr�
test_closeszOtherTests.test_closecCs�tjtd��.}x$tD]\}}|j||�qWWdQXy+tjtd��}tj��WdQXWn(tjk
r�|j|jd�YnXdS)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r:NrAzzipfp is not closed)r<r=rrr>�
BadZipFiler]r8)r7r$rrZzipfp2rrr�test_close_on_exceptionsz"OtherTests.test_close_on_exceptioncCs,d}|jttjtj|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rA)r��NotImplementedErrorr<r=rr)r7r2rrr�test_unsupported_versionsz#OtherTests.test_unsupported_versionc
CsRtd�}tj|��1}x'|j�D]}|j|�j�q+WWdQXdS)Nzzip_cp437_header.zip)rr<r=rVr#r�)r7Zfnamer$r�rrr�test_read_unicode_filenames*sz&OtherTests.test_read_unicode_filenamescCs�tjtd��D}|jdd�|jdd�|j|j�djt�WdQXtjtd��;}|j|j	djd�|j|j	djd�WdQXdS)Nr:zfoo.txtzTest for unicode filenameuö.txtrrArF)
r<r=rr>r�rWrHrUrI�filelist)r7�zfrrr�test_write_unicode_filenames2s#z'OtherTests.test_write_unicode_filenamescCs�tjjt�r"tjt�nd}d}y/tjtd��}|j||�WdQXWntk
r~|j	d�YnX|j
tjjt��tjtd�� }|j|j|�|�WdQXdS)Nztestfile.txts#hello, world. this is some content.r�z1Could not append data to a non-existent zip file.rA)
r�r��existsrrr<r=r>�OSError�failrRrIrJ)r7rHr�rerrr�(test_create_non_existent_file_for_append<s
z3OtherTests.test_create_non_existent_file_for_appendcCsTttd��}|jd�WdQXytjt�}Wntjk
rOYnXdS)Nr:zthis is not a legal zip file
)r#rr6r<r=r_)r7r8rerrr�test_close_erroneous_fileNsz$OtherTests.test_close_erroneous_filecCs�ttd��}|jd�WdQX|jtjt��ttd��}|jtj|��WdQXtj�}|jd�|jtj|��|jdd�|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#rr6rr<�
is_zipfilerrr�)r7r8rrr�test_is_zip_erroneous_file]s
z%OtherTests.test_is_zip_erroneous_filecCs�tj�}tj|dd��}|jdd�WdQX|j�}xLtt|��D]8}tj|d|��}|jtj	tj|�qYWdS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r�r:zfoo.txtsO, for a Muse of Fire!N)
rrr<r=r>rMr.rOr�r_)r7r8r�r��Nrrr�test_damaged_zipfilemszOtherTests.test_damaged_zipfilecCs�tjtdd��}|jdd�WdQX|jtjt��ttd��9}|jtj|��|jdd�|j�}WdQXt	j
�}|j|�|jtj|��|jdd�|jtj|��dS)z7Check that is_zipfile() correctly identifies zip files.r�r:zfoo.txtsO, for a Muse of Fire!Nr�r)r<r=rr>rRrlr#r�rJrrr6)r7r�r8Zzip_contentsrrr�test_is_zip_valid_file{s
z!OtherTests.test_is_zip_valid_filecCs|jttjt�dS)N)r�rhr<r=r)r7rrr�%test_non_existent_file_raises_OSError�sz0OtherTests.test_non_existent_file_raises_OSErrorc
Cstttd�}|j�|jtjtjt�ttd��}|jd�WdQX|jtjtjt�dS)Nr:z
short file)r#rr�r�r<r_r=r6)r7rr8rrr�!test_empty_file_raises_BadZipFile�s
z,OtherTests.test_empty_file_raises_BadZipFilecCs�tj�}tj|dd��}|jdd�WdQX|jt|jd�|jt|jd�|jt|j	�|jt|jdd�tt
d��}|jd�WdQX|jt|jt
�dS)	z?Verify that testzip() doesn't swallow inappropriate exceptions.r�r:zfoo.txtzO, for a Muse of Fire!Nz	bogus.txtr�zzipfile test data)rrr<r=r>r�r�rJr#rZrr6)r7r2r�rrrr�#test_closed_zip_raises_RuntimeError�sz.OtherTests.test_closed_zip_raises_RuntimeErrorcCs|jttjtd�dS)z>Check that bad modes passed to ZipFile constructor are caught.�qN)r�r�r<r=r)r7rrr�test_bad_constructor_mode�sz$OtherTests.test_bad_constructor_modecCsvtjtdd��}|jdd�WdQXtjtdd��-}|jd�|jt|jdd�WdQXdS)z7Check that bad modes passed to ZipFile.open are caught.r�r:zfoo.txtzO, for a Muse of Fire!NrArt)r<r=rr>rJr�r�r#)r7r�rrr�test_bad_open_mode�s

zOtherTests.test_bad_open_modecCs�tjtdd��u}|jdd�|jd��M}x-tt�D]}|j|jd�d�qGW|j|j�d�WdQXWdQXdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r�r:zfoo.txtzO, for a Muse of Fire!rr-sO, for a Muse of Fire!N)	r<r=rr>r#r.r/rIrJ)r7r�rr+rrr�
test_read0�szOtherTests.test_read0cCs;tjtdd�� }|jt|jdd�WdQXdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r�r:zfoo.txtrAN)r<r=rr��KeyErrorr#)r7r�rrr�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:rFNrp)r�r�r<r=r)r7rrr�test_bad_compression_mode�sz$OtherTests.test_bad_compression_modecCsDd}tjtj|�d��}|jt|jd�WdQXdS)NsfPK.�C�@xPK..�C�@�xPK/!rA�x)r<r=rrr�rar#)r7r2r�rrr�test_unsupported_compression�sz'OtherTests.test_unsupported_compressionc
CsKtjtdd��0}|jdd�|j|j�dg�WdQXdS)zLCheck that a filename containing a null byte is properly
        terminated.r�r:zfoo.txtqqqsO, for a Muse of Fire!zfoo.txtN)r<r=rr>rIrV)r7r�rrr�test_null_byte_in_filename�sz%OtherTests.test_null_byte_in_filenamecCsP|jtjd�|jtjd�|jtjd�|jtjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rIr<ZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locator)r7rrr�test_struct_sizes�szOtherTests.test_struct_sizesc^Cstjtdd��*}|j|jd�|jdd�WdQXtjtdd��}|j|jd�WdQXd}tjtdd�� }||_|jdd�WdQXtjtdd��}|j|j|�WdQXd	jd
d�td�D��}|jd�}tjtdd�� }||_|jdd�WdQXtjtdd��}|j|j|�WdQXtjtdd��:}|j	t
��|d|_WdQX|jdd�WdQXtjtdd��}|j|j|�WdQXtjtdd�� }d|_|jdd�WdQXtjtdd��}d|_WdQXtjtdd��}|j|jd�WdQXtjtdd�� }d|_|jdd�WdQXtjtdd��}d|_WdQXtjtdd��}|j|jd�WdQXdS)z8Check that comments on the archive are handled properly.r�r:r-zfoo.txtzO, for a Muse of Fire!NrAs9Bravely taking to his feet, he beat a very brave retreat.r cSs"g|]}d|dd�qS)z%drGrvr)r*r+rrrr,	s	z,OtherTests.test_comments.<locals>.<listcomp>rFr�r(soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter commentii��)r<r=rrIr�r>r1r.rrr)r7r�Zzipfrr�Zcomment2rrr�
test_comments�sL	"			zOtherTests.test_commentscCsTtjtdtj��6}|jdd�|jt��d|_WdQXWdQXdS)Nr:zfoo.txtzO, for a Muse of Fire!zthis is an error)r<r=rr�r>r��	TypeErrorr�)r7r�rrr�test_unicode_comment,szOtherTests.test_unicode_commentcCsltjtdtj�� }|j|j�d|_WdQXtjtd��}|j|jd�WdQXdS)Nr�sthis is a commentrA)r<r=rr�rrdr�rI)r7r�rrr�$test_change_comment_in_empty_archive2s
z/OtherTests.test_change_comment_in_empty_archivecCs�tjtdtj��}|jdd�WdQXtjtdtj�� }|j|j�d|_WdQXtjtd��}|j|jd�WdQXdS)Nr:zfoo.txtzO, for a Muse of Fire!r�sthis is a commentrA)	r<r=rr�r>rRrdr�rI)r7r�rrr�'test_change_comment_in_nonempty_archive9sz2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|j�ytjtdd�}Wn"tjk
r\|jd�YnXtjtdd�}|j�ytjtdd�}Wn|jd�YnXdS)Nr�r:rAz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)r<r=rr�r_ri)r7r�rrr�test_empty_zipfileBs

zOtherTests.test_empty_zipfilecCs9ttd�}|j�|jtjtjtd�dS)Nr:rA)r#rr�r�r<r_r=)r7rrrr�test_open_empty_fileSs
zOtherTests.test_open_empty_filec
Cs|jttjdd�dS)NZ	seventies�rFr)r�rFrFrrr)r�r�r<rR)r7rrr�test_create_zipinfo_before_1980[s	z*OtherTests.test_create_zipinfo_before_1980c	CsAd}tjtj|�d��}|j|j��WdQXdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rAN)r<r=rrr]rZ)r7rsr�rrr�#test_zipfile_with_short_extra_field_sz.OtherTests.test_zipfile_with_short_extra_fieldcCstt�tt�dS)N)rrr)r7rrrr�ns
zOtherTests.tearDownN)&r�r�r�rWrYr[r\r^r`rbr
rcrfrjrkrmrorprqrrrsrurvrwryrzr|r}r�r�r�r�r�r�r�r�r�r�rrrrrU�sD

	
7	rUc@s(eZdZdd�Zdd�ZdS)�AbstractBadCrcTestsc
CsJ|j}tjtj|�dd��}|jd|j��WdQXdS)z>Tests that files with bad CRCs return their name from testzip.r�rA�afileN)�zip_with_bad_crcr<r=rrrIrZ)r7rsr�rrr�test_testzip_with_bad_crcts	!z-AbstractBadCrcTests.test_testzip_with_bad_crcc)Cs|j}tjtj|�dd�� }|jtj|jd�WdQXtjtj|�dd��8}|jdd��}|jtj|j�WdQXWdQXtjtj|�dd��Z}|jdd��?}d|_	|jtj��x|jd�rq�WWdQXWdQXWdQXdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.r�rAr�NrV)
r�r<r=rrr�r_rJr#Z
MIN_READ_SIZE)r7rsr�Zcorrupt_filerrr�test_read_with_bad_crc|s	!!"!	z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�r�r�rrrrr�ssr�c@seZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�r<r�r?r�rrrrr��s	r�c@seZdZejZdZdS)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�r<r�r?r�rrrrr��s	r�c@seZdZejZdZdS)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�r<r�r?r�rrrrr��s	r�c@seZdZejZdZdS)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�r<r�r?r�rrrrr��s	r�c@s�eZdZdZdZdZdZddZdd�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 testsicCs~ttd��}|j|j�WdQXtjtd�|_ttd��}|j|j�WdQXtjtd�|_	dS)Nr5rA)
r#rr6r2r<r=r�rrZ�zip2)r7r8rrrr9�szDecryptionTests.setUpcCs8|jj�tjt�|jj�tjt�dS)N)r�r�r�rrr�r)r7rrrr��s


zDecryptionTests.tearDowncCs6|jt|jjd�|jt|jjd�dS)Nztest.txt�zero)r�r�r�rJr�)r7rrr�test_no_password�sz DecryptionTests.test_no_passwordcCsV|jjd�|jt|jjd�|jjd�|jt|jjd�dS)Nsperlztest.txtr�)r��setpasswordr�r�rJr�)r7rrr�test_bad_password�sz!DecryptionTests.test_bad_passwordcCsb|jjd�|j|jjd�|j�|jjd�|j|jjd�|j�dS)Nspythonztest.txts12345r�)r�r�rIrJ�plainr��plain2)r7rrr�test_good_password�sz"DecryptionTests.test_good_passwordcCsw|jt|jjd�|jt|jjdd�|jt|jjddd�|jt|jjddd�dS)NZunicodeztest.txt�python�pwd)r�r�r�r�rJr#r)r7rrr�test_unicode_passwordsz%DecryptionTests.test_unicode_passwordN)r�r�r��__doc__r2rZr�r�r9r�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)�"AbstractTestsWithRandomBinaryFilescCsItdd�dtdd�}djdd�t|�D��|_dS)Nr��@irFr-css1|]'}tjdt�tdd��VqdS)z<fi�Ni���)�structZpackrr)r*r+rrrr�sz@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr1r.r2)r3Z	datacountrrrr4s z-AbstractTestsWithRandomBinaryFiles.setUpClassc	Cs,ttd��}|j|j�WdQXdS)Nr5)r#rr6r2)r7r8rrrr9sz(AbstractTestsWithRandomBinaryFiles.setUpcCstt�tt�dS)N)rrr)r7rrrr�s
z+AbstractTestsWithRandomBinaryFiles.tearDownc
CsBtj|d|��'}|jtd�|jtt�WdQXdS)Nr:zanother.name)r<r=r6r)r7rr?r$rrrr@sz4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs�|j||�tj|d|��d}|jt�}|jt|�t|j��|j||j�|j|jd�|j�WdQXdS)NrAzanother.name)r@r<r=rJrrIrOr2)r7rr?r$�testdatarrrrc!sz+AbstractTestsWithRandomBinaryFiles.zip_testcCs.x't|�D]}|j||j�q
WdS)N)rrcr?)r7rrrr�	test_read+sz,AbstractTestsWithRandomBinaryFiles.test_readcCsJ|j||�tj|d|��}g}|jt��4}x*|jd�}|s\Pn|j|�qCWWdQXg}|jd��4}x*|jd�}|s�Pn|j|�q�WWdQXdj|�}	|jt	|	�t	|j
��|j|	|j
�dj|�}
|jt	|
�t	|j
��|j|
|j
�WdQXdS)NrArezanother.namer-)r@r<r=r#rrJrfr1rIrOr2)r7rr?r$rgrhrirjrkZ	testdata1Z	testdata2rrrrl/s,z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCs.x't|�D]}|j||j�q
WdS)N)rrlr?)r7rrrrrmLsz,AbstractTestsWithRandomBinaryFiles.test_opencCs�|j||�tj|d|���}g}|jt��=}x3|jtdd��}|sePn|j|�qCWWdQXdj|�}|j	t
|�t
|j��|j	||j�WdQXdS)NrArFir-)r@r<r=r#rrJrrfr1rIrOr2)r7rr?r$rgrhrir�rrrrnPsz7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCs.x't|�D]}|j||j�q
WdS)N)rrnr?)r7rrrrroasz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r4r9r�r@rcr�rlrmrnrorrrrr�s
r�c@seZdZejZdS)� StoredTestsWithRandomBinaryFilesN)r�r�r�r<r�r?rrrrr�fsr�c@seZdZejZdS)�!DeflateTestsWithRandomBinaryFilesN)r�r�r�r<r�r?rrrrr�jsr�c@seZdZejZdS)�Bzip2TestsWithRandomBinaryFilesN)r�r�r�r<r�r?rrrrr�osr�c@seZdZejZdS)�LzmaTestsWithRandomBinaryFilesN)r�r�r�r<r�r?rrrrr�tsr�c@s�eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dS)�TestsWithMultipleOpenscCs*dtd�|_dtd�|_dS)Ns111i's222)r�data1rZ)r3rrrr4|sz!TestsWithMultipleOpens.setUpClassc
CsKtj|dtj��-}|jd|j�|jd|j�WdQXdS)Nr:�ones�twos)r<r=r�r>r�rZ)r7rr$rrrr@�sz(TestsWithMultipleOpens.make_test_archivecCs�|jt�tjtdd���}|jd��]}|jd��E}|jd�}|jd�}||j�7}||j�7}WdQXWdQX|j||�|j||j�WdQXdS)Nr�rAr�i�)r@rr<r=r#rJrIr�)r7r��zopen1�zopen2r�rZrrr�test_same_file�s
$z%TestsWithMultipleOpens.test_same_filecCs�|jt�tjtdd���}|jd��]}|jd��E}|jd�}|jd�}||j�7}||j�7}WdQXWdQX|j||j�|j||j�WdQXdS)Nr�rAr�r�i�)	r@rr<r=r#rJrIr�rZ)r7r�r�r�r�rZrrr�test_different_file�s
$z*TestsWithMultipleOpens.test_different_filecCs�|jt�tjtdd���}|jd��]}|jd��E}|jd�}|jd�}||j�7}||j�7}WdQXWdQX|j||j�|j||j�WdQXdS)Nr�rAr�r�i�)	r@rr<r=r#rJrIr�rZ)r7r�r�r�r�rZrrr�test_interleaved�s
$z'TestsWithMultipleOpens.test_interleavedcCs�|jt�tj���}tjtd��7}|j|jd��}|j|jd��}WdQX|jd�}|jd�}||j�7}||j�7}WdQX|j	||j
�|j	||j�dS)NrAr�r�i�)r@r�
contextlib�	ExitStackr<r=�
enter_contextr#rJrIr�rZ)r7�stackr�r�r�r�rZrrr�test_read_after_close�s
z,TestsWithMultipleOpens.test_read_after_closecCs�tjtdtj��T}|jd|j�|jd|j�|jd��}|jd�}WdQXWdQX|j	||jdd��tjtd��%}|jd�}|jd�}WdQX|j	||j�|j	||j�dS)Nr:r�r�i�rA)
r<r=rr�r>r�rZr#rJrI)r7r�r�r�rZrrr�test_read_after_write�sz,TestsWithMultipleOpens.test_read_after_writecCs�tjtdtj��R}|jd|j�|jd��'}|jd�|jd|j�WdQXWdQXtjtd��%}|jd�}|jd�}WdQX|j	||j�|j	||j�dS)Nr:r�i�r�rA)
r<r=rr�r>r�r#rJrZrI)r7r�r�r�rZrrr�test_write_after_read�s
z,TestsWithMultipleOpens.test_write_after_readcCs�|jt�tjtdd��C}x9td�D]+}|jd�|jd��}WdQXq2WWdQXttj��}|j	|j
�d�WdQXdS)Nr�rAryr�)r@rr<r=r.rJr#r��devnullZ
assertLess�fileno)r7r�r{r�rrrr�test_many_opens�s

z&TestsWithMultipleOpens.test_many_openscCstt�dS)N)rr)r7rrrr��szTestsWithMultipleOpens.tearDownN)r�r�r�r�r4r@r�r�r�r�r�r�r�r�rrrrr�zs




r�c@sXeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCstjt�dS)N)r�rr)r7rrrr9�szTestWithDirectory.setUpc
Cs�tjtd���}|jt�WdQX|jtjjtjj	td���|jtjjtjj	tdd���|jtjj
tjj	tddd���dS)Nz
zipdir.zipr��br�)r<r=rrrrRr�r��isdirr1rg)r7r�rrr�test_extract_dir�s
(+z"TestWithDirectory.test_extract_dircCs*tjtjjtd��|j�dS)Nr�)r�rr�r1rr�)r7rrr�
test_bug_6050�szTestWithDirectory.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�WdQXtjt	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�WdQXdS)
Nr{i��r:rz/x/r��yrFzy/rArPrV)r�r�r1rr�stat�st_moder<r=rr6rdrRrHr�rIr�rr�rO�listdir)r7�dirpathr�r�r�rPrrr�test_write_dir�s0



!



(z TestWithDirectory.test_write_dircCsEtjtjjtd��tjtd��J}|jdd�|j	d}|j
|jd�|j
|jd�WdQXtjtd���}|j	d}|j
|jjd��|j
|jd
�tjjtd	�}tj|�|j|�|j
tjjtjj|d���|j
tj|�dg�WdQXdS)Nr{r:zx/r-ri�Ar�rArPi�Ai�Ai�Ai�A)r�rr�r1rr<r=rr>rdrIrHr�rRr�rr�r�)r7r�r�rPrrr�test_writestr_dirs



(z#TestWithDirectory.test_writestr_dircCs-tt�tjjt�r)tt�ndS)N)r	rr�r�rgrr)r7rrrr�s
zTestWithDirectory.tearDownN)	r�r�r�r9r�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
dd�Zdd�Zdd�Zdd�ZdS)�AbstractUniversalNewlineTestscCsodd�tt�D�|_d|_i|_x:t|j�D])\}}|j|j�||j|<q>WdS)NcSs#g|]}td|d��qS)zTest of zipfile line %d.r()r))r*r+rrrr,(s	z<AbstractUniversalNewlineTests.setUpClass.<locals>.<listcomp>�
�
�
)r�r�r�)r.r/r0�seps�arcdata�	enumerater1)r3�nrrrrr4&s			z(AbstractUniversalNewlineTests.setUpClasscCswi|_xgt|j�D]V\}}dt|f|j|<t|j|d��}|j|j|�WdQXqWdS)Nz%s-%dr5)�arcfilesr�r�rr#r6r�)r7r�rrrrrr9/s
	z#AbstractUniversalNewlineTests.setUpcCsLtj|d|��1}x'|jj�D]}|j||�q(WWdQXdS)Nr:)r<r=r��valuesr6)r7rr?r$r%rrrr@6sz/AbstractUniversalNewlineTests.make_test_archivecCs�|j||�tj|d��b}xX|jj�D]G\}}t||��}|j�}WdQX|j|j||�q5WWdQXdS)NrA)	r@r<r=r��itemsr&rJrIr�)r7rr?r$r�r%r8rsrrr�	read_test<sz'AbstractUniversalNewlineTests.read_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrrr�Fsz'AbstractUniversalNewlineTests.test_readc	Cs�|j||�tj|d���}x�|jj�D]t\}}t||��W}d}xG|j�}|srPn||7}|jd�}|s�Pn||7}q\WWdQXq5W|j||j	d�WdQXdS)NrAr-�s
)
r@r<r=r�r�r&rzrJrIr�)	r7rr?r$r�r%rrr2rJrrr�readline_read_testJs
z0AbstractUniversalNewlineTests.readline_read_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrrr|_sz0AbstractUniversalNewlineTests.test_readline_readc	Cs�|j||�tj|d��s}xi|jj�D]X\}}t||��;}x1|jD]&}|j�}|j||d�q]WWdQXq5WWdQXdS)NrAs
)	r@r<r=r�r�r&r0rzrI)	r7rr?r$r�r%rrr}r~rrr�
readline_testcsz+AbstractUniversalNewlineTests.readline_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrrr�nsz+AbstractUniversalNewlineTests.test_readlinec
Cs�|j||�tj|d���}xx|jj�D]g\}}t||��}|j�}WdQXx4t|j|�D] \}}	|j	|	|d�qxWq5WWdQXdS)NrAs
)
r@r<r=r�r�r&r�r�r0rI)
r7rr?r$r�r%r8r�r}r�rrr�readlines_testrsz,AbstractUniversalNewlineTests.readlines_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrrr�}sz,AbstractUniversalNewlineTests.test_readlinesc	Cs�|j||�tj|d��v}xl|jj�D][\}}t||��>}x4t|j|�D] \}}|j||d�qfWWdQXq5WWdQXdS)NrAs
)	r@r<r=r�r�r&r�r0rI)	r7rr?r$r�r%r8r}r�rrr�iterlines_test�sz,AbstractUniversalNewlineTests.iterlines_testcCs.x't|�D]}|j||j�q
WdS)N)rr�r?)r7rrrrr��sz,AbstractUniversalNewlineTests.test_iterlinescCsBx'|jj�D]\}}t|�qWtt�tt�dS)N)r�r�rrr)r7r�r%rrrr��s
z&AbstractUniversalNewlineTests.tearDownN)r�r�r�r�r4r9r@r�r�r�r|r�r�r�r�r�r�r�rrrrr�%s	

r�c@seZdZejZdS)�StoredUniversalNewlineTestsN)r�r�r�r<r�r?rrrrr��sr�c@seZdZejZdS)�DeflateUniversalNewlineTestsN)r�r�r�r<r�r?rrrrr��sr�c@seZdZejZdS)�Bzip2UniversalNewlineTestsN)r�r�r�r<r�r?rrrrr��sr�c@seZdZejZdS)�LzmaUniversalNewlineTestsN)r�r�r�r<r�r?rrrrr��sr��__main__)Cr�rr��sys�importlib.utilr�rSr�r<rTZtempfilerrrrZtest.supportrrrr	r
rrr
rrZ	TESTFNDIRr/Z
DATAFILES_DIRrrrr&r'ZTestCaser�r�r�r�r�r�r�r�r�r�rrUr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��mainrrrr�<module>s�@

				�&[�����A[iAq