Your IP : 216.73.216.196


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_zipfile.cpython-310.pyc

o

0�i�&�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlZddlmZddlZddlZddlmZddlmZmZmZddlmZddlmZmZmZmZm Z ddl!m"Z"m#Z#m$Z$m%Z%m&Z&e"dZ'e"d	Z(d
Z)dZ*gd�Z+d
d�Z,Gdd�d�Z-Gdd�de-ej.�Z/e�Gdd�de-ej.��Z0e�Gdd�de-ej.��Z1e�Gdd�de-ej.��Z2Gdd�d�Z3Gdd�de3ej.�Z4e�Gdd�de3ej.��Z5e�Gdd �d e3ej.��Z6e�Gd!d"�d"e3ej.��Z7Gd#d$�d$�Z8Gd%d&�d&e8ej.�Z9e�Gd'd(�d(e8ej.��Z:e�Gd)d*�d*e8ej.��Z;e�Gd+d,�d,e8ej.��Z<Gd-d.�d.ej.�Z=Gd/d0�d0ej.�Z>Gd1d2�d2ej.�Z?Gd3d4�d4�Z@Gd5d6�d6e@ej.�ZAe�Gd7d8�d8e@ej.��ZBe�Gd9d:�d:e@ej.��ZCe�Gd;d<�d<e@ej.��ZDGd=d>�d>ej.�ZEGd?d@�d@�ZFGdAdB�dBeFej.�ZGe�GdCdD�dDeFej.��ZHe�GdEdF�dFeFej.��ZIe�GdGdH�dHeFej.��ZJGdIdJ�dJ�ZKGdKdL�dL�ZLGdMdN�dNej.�ZMe�GdOdP�dPej.��ZNGdQdR�dRej.�ZOGdSdT�dTej.�ZPGdUdV�dVej.�ZQGdWdX�dXej.�ZReSZTGdYdZ�dZ�ZUd[d\�ZVd]d^�ZWd_d`�ZXGdadb�dbej.�ZYGdcdd�ddejZ�Z[Gdedf�dfej.�Z\e]dgk�rPe�^�dSdS)h�N)�assert_python_ok)�
TemporaryFile)�randint�random�	randbytes)�
script_helper)�findfile�
requires_zlib�requires_bz2�
requires_lzma�captured_stdout)�TESTFN�unlink�rmtree�temp_dir�temp_cwd�2�d��Zzipfile_datafiles))Z	_ziptest1Z
1q2w3e4r5t)zziptest2dir/_ziptest2Z
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3Z
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3Z
6y7u8i9o0pccs��tVt��}|V|�|j�Wd�n1swYt���}|V|�|j�Wd�dS1s9wYdS�N)�TESTFN2r�assertFalse�closed�io�BytesIO)�test�f�r�8/opt/alt/python310/lib64/python3.10/test/test_zipfile.py�	get_files(s��
"�rc@seZdZedd��Zdd�ZdBdd�ZdBdd	�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)C�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>4s���z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>�)�range�FIXEDTEST_SIZE�line_gen�join�data��clsrrr�
setUpClass2s�z&AbstractTestsWithSourceFile.setUpClasscC�<ttd��}|�|j�Wd�dS1swYdS�N�wb��openr
�writer,��self�fprrr�setUp9�"�z!AbstractTestsWithSourceFile.setUpNc	Cs�||d�}tj|dfi|���F}|�td�|�tt�|�d|j�|jddd��}|jD]}|�|�q.Wd�n1s@wYWd�dSWd�dS1sXwYdS)N)�compression�
compresslevel�w�another.name�strfile�written-open-w��mode)�zipfile�ZipFiler5r
�writestrr,r4r*)r7rr;r<�kwargs�zipfp�linerrr�make_test_archive>s

���"�z-AbstractTestsWithSourceFile.make_test_archivecCsB|�|||�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|�|
D]}|�|jt|j��q�tdddfD]}|�|�}|�|j|�|�|jt|j��q�|��Wd�dS1�swYdS)N�rr>r?)�file��	File Namer�Modified�Size��%Y-%m-%d�%H:%M:%S�r@cS�g|]}|j�qSr��filenamer#rrrr&m�z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>)rIrCrD�assertEqual�readr
r,r�StringIO�printdir�getvalue�
splitlines�len�assertIn�split�
assertTrue�time�strptime�str�namelist�infolist�	file_size�getinforV�testzip)r7rr;r<rGr8�	directory�lines�fn�date�time_�size�names�infosr%�nm�inforrr�zip_testIsN

$�z$AbstractTestsWithSourceFile.zip_testcC� t|�D]	}|�||j�qdSr�rrtr;�r7rrrr�
test_basic��z&AbstractTestsWithSourceFile.test_basicc		Cs|�||�t�|d|��i}g}|�t��}	|�d�}|sn|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEn|�|�q=Wd�n1sUwY|�d�|�|j	�|�d�|�|j	�Wd�dS1sywYdS�NrJT�r>r')
rIrCrDr4r
rY�appendrXr+r,)	r7rr;rG�zipdata1�zipopen1�	read_data�zipdata2�zipopen2rrr�
zip_open_test�s2

��

��"�z)AbstractTestsWithSourceFile.zip_open_testcCrur�rr�r;rwrrr�	test_open�ryz%AbstractTestsWithSourceFile.test_opencCs\t�t�}|�||j�t�|d|j��}|�|jt	�Wd�dS1s'wYdS�NrJ)
�pathlib�Pathrr�r;rCrD�assertIsInstancerVrd)r7�pathrGrrr�test_open_with_pathlike�s

"�z3AbstractTestsWithSourceFile.test_open_with_pathlikec	Cs�|�||�t�|d|��<}g}|�t��}	|�tdd��}|s"n|�|�qWd�n1s2wY|�d�	|�|j
�Wd�dS1sLwYdS�NrJTrP�r')rIrCrDr4r
rYrr|rXr+r,)r7rr;rGr}r~rrrr�zip_random_open_test�s
��"�z0AbstractTestsWithSourceFile.zip_random_open_testcCrur�rr�r;rwrrr�test_random_open�ryz,AbstractTestsWithSourceFile.test_random_openc	Cs�|�||�t�|d��.}|�t��}g}	|�d�}|sn|�|�qWd�n1s.wYWd�n1s=wY|�d�|�|j	�dS)NrJT���r')
rIrCrDr4r
�read1r|rXr+r,�r7rr;rG�zipopen�zipdatarrrr�zip_read1_test�s"�

���	z*AbstractTestsWithSourceFile.zip_read1_testcCrur)rr�r;rwrrr�
test_read1�ryz&AbstractTestsWithSourceFile.test_read1c	Cs�|�||�t�|d��6}|�t��!}g}	|�d�}|�t|�d�|s&n|�|�qWd�n1s6wYWd�n1sEwY|�	d�
|�|j�dS)NrJT�
r')rIrCrDr4r
r�ZassertLessEqualr^r|rXr+r,r�rrr�zip_read1_10_test�s$�

���
z-AbstractTestsWithSourceFile.zip_read1_10_testcCrur)rr�r;rwrrr�
test_read1_10�ryz)AbstractTestsWithSourceFile.test_read1_10c	Cs�|�||�t�|d��8}|�t��#}d}	|��}|sn||7}|�d�}|s)n||7}qWd�n1s8wYWd�n1sGwY|�||j�dS)NrJr'T�d)	rIrCrDr4r
�readlinerYrXr,)r7rr;rGr�r,rYrrr�zip_readline_read_test�s*�
����z2AbstractTestsWithSourceFile.zip_readline_read_testcCrur)rr�r;rwrrr�test_readline_read�s�z.AbstractTestsWithSourceFile.test_readline_readc	Cs�|�||�t�|d��6}|�t��}|jD]}|��}|�||�qWd�n1s-wYWd�dSWd�dS1sEwYdSr�)rIrCrDr4r
r*r�rX)r7rr;rGr�rHZlinedatarrr�zip_readline_test�s
���"�z-AbstractTestsWithSourceFile.zip_readline_testcCrur)rr�r;rwrrr�
test_readlineryz)AbstractTestsWithSourceFile.test_readlinec	Cs�|�||�t�|d��3}|�t��}|��}Wd�n1s!wYt|j|�D]
\}}|�||�q,Wd�dS1sBwYdSr�)	rIrCrDr4r
�	readlines�zipr*rX)r7rr;rGr�ZziplinesrH�ziplinerrr�zip_readlines_tests
��"�z.AbstractTestsWithSourceFile.zip_readlines_testcCrur)rr�r;rwrrr�test_readlinesryz*AbstractTestsWithSourceFile.test_readlinesc	Cs�|�||�t�|d��7}|�t��}t|j|�D]
\}}|�||�qWd�n1s.wYWd�dSWd�dS1sFwYdSr�)rIrCrDr4r
r�r*rX)r7rr;rGr�rHr�rrr�zip_iterlines_tests���"�z.AbstractTestsWithSourceFile.zip_iterlines_testcCrur)rr�r;rwrrr�test_iterlinesryz*AbstractTestsWithSourceFile.test_iterlinesc	Cs�t�td|j��}|�dd�Wd�n1swYt�td|j��8}|�d��}|�|�d�d�|�|�d�d�Wd�n1sIwYWd�dSWd�dS1sawYdS)	z>Check for cases where compressed data is larger than original.r=r?Z12NrJrP�1�2)rCrDrr;rEr4rXrY)r7rGZopenobjrrr�test_low_compression!s���"�z0AbstractTestsWithSourceFile.test_low_compressioncCs<t�td�}|jdd|jd�|�d�}|�|j|j�dS)Nr=�b.txt�hello world��
compress_type)rCrDrrEr;rhrXr�)r7rGrsrrr�test_writestr_compression-s
z5AbstractTestsWithSourceFile.test_writestr_compressioncCs�tjtddd�}|jdd|jd�|jdd|jdd	�|�d�}|�|j|j�|�|jd�|�d�}|�|j|j�|�|jd�dS)
Nr=rP�r<�a.txtr�r�r��)r�r<)	rCrDrrEr;rhrXr��_compresslevel)r7rGZa_infoZb_inforrr�test_writestr_compresslevel3s�

z7AbstractTestsWithSourceFile.test_writestr_compresslevelc
Cs�dD]M}|d}t|�}t�t��d|j��1}|�d|�|�dd��}|�|�}|�	t
|�|�Wd�n1s;wYWd�n1sJwYqdS)N)rPi�iii@rPr=�foorJ)rrCrDrrr;rEr4rYrXr^)r7Z	test_sizergZjunk�zipfr8Zbufrrr�test_read_return_sizeCs
�����z1AbstractTestsWithSourceFile.test_read_return_sizec
Cslt��}tj|dd��}|jd|j|jd�|��}Wd�n1s$wY|��}t�|�}t�|��=}|�	d��(}|�
|d�|�t��|�
�Wd�n1sYwYWd�n1shwYWd�n1swwYt�|�}t�|��D}|�	d��/}|�
|d�|�t��|�
d�r�	|�
d�s�Wd�n1s�wYWd�n1s�wYWd�n1s�wYt�|�}t�|��O}|�	d��0}|�
|d�|�t��|�d�r�	|�d�s�Wd�n	1�swYWd�n1�swYWd�dSWd�dS1�s/wYdS)Nr=rAr?r��r�)rrrCrDrEr,r;�tellr\r4�truncate�assertRaises�EOFErrorrYr�)r7r8r��
end_offset�zipfiledatar�rrr�test_truncated_zipfileOs\
�

�����


�������


���� ��$�z2AbstractTestsWithSourceFile.test_truncated_zipfilec
Cs�d}t|�D]�}t�|d|j��}|�t|�t|�}|�d|�Wd�n1s+wYt�|d���}t|�}t|t	�rI|�d||�n|�d||�|�d|�t|�
|��}|�d||�|�d|�|�d	|�|jtjkr�|�d
|�|�d|�|�|��&}t|�}|�d||�|�d|�|jtjkr�|�d
|�Wd�n1s�wY|�d
t|��Wd�n1s�wY|�d
t|��qdS)Nz	file.namer=zmode='w'rJzfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])
rrCrDr;r5r
�reprr_�
isinstancerdrh�
ZIP_STOREDr4)r7�fnamerrGrJr�rrr�	test_reprms@�
����z%AbstractTestsWithSourceFile.test_reprcCs$t|�D]}|j||jdd�qdS)N�	r�rvrwrrr�test_compresslevel_basic���z4AbstractTestsWithSourceFile.test_compresslevel_basiccCs�tjtddd��/}|�td�|jtddd�|�d�}|�d�}|�|jd�|�|jd�Wd�dS1s:wYdS)zTCheck that files within a Zip archive can have different
        compression levels.r=rPr�Z
compress_1Z
compress_9r�N)rCrDrr5r
rhrXr�)r7rGZone_infoZ	nine_inforrr�test_per_file_compresslevel�s

"�z7AbstractTestsWithSourceFile.test_per_file_compresslevelc	s�G��fdd�dtj�}d�	|�}d�t�|d|j��b}|�dd��
}|�d�Wd�n1s3wYd�z9z|�dd��
}|�d	�Wd�n1sRwYWn
tye�d
7�YnwWd�Wd�nCWd�nd�wWd�n1s�wYt�t�|�����}|�	|�
�dg�|�	|�d�d�Wd�n1s�wYqt�t�|�����%}|�	|�
�ddg�|�	|�d�d�|�	|�d�d	�Wd�dS1s�wYdS)Ncs eZdZ���fdd�Z�ZS)zCAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilecs,�dur��kr
t��d7�t��|�dS�NrP)�OSError�superr5�r7r,)�	__class__�count�stoprrr5�s
zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write)�__name__�
__module__�__qualname__r5�
__classcell__r�r�r��r�r�
BrokenFile�sr�rTr=Zfile1sdata1Zfile2sdata2rP)rrrCrDr;r4r5r�r\rXrerY)r7r�ZtestfilerGrrr�r�test_writing_errors�sD	������
��"�z/AbstractTestsWithSourceFile.test_writing_errorscC�tt�tt�dSr�rr
r�r7rrr�tearDown��z$AbstractTestsWithSourceFile.tearDownr)$r�r�r��classmethodr/r9rIrtrxr�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�rrrrr 1sD


6

	%r c@s�eZdZejZdZdd�Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�StoredTestsWithSourceFileNcCsn|�||�t�|d��!}|�d�}|�|jd�|�d�}|�|jd�Wd�dS1s0wYdS)NrJr?��r@)rIrCrDrhrX�
external_attr)r7rr;rG�zinfoZzinfo2rrr�zip_test_writestr_permissions�s

"�z7StoredTestsWithSourceFile.zip_test_writestr_permissionscCs t|�D]	}|�|tj�qdSr)rr�rCr�rwrrr�test_writestr_permissions�ryz3StoredTestsWithSourceFile.test_writestr_permissionscCs�t�tdtj��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s;wYdS)Nr=�	/absoluterJ�absolute�rCrDrr�r5r
rXre�r7rGrrr�test_absolute_arcnames�s�"�z0StoredTestsWithSourceFile.test_absolute_arcnamescCs�t�tdtj��}|�tt�Wd�n1swYt�tdtj��}|�d|j�|�|�	�tdg�Wd�dS1sCwYdS)z&Test appending to an existing zipfile.r=N�ar?)
rCrDrr�r5r
rEr,rXrer�rrr�test_append_to_zip_file�s�"�z1StoredTestsWithSourceFile.test_append_to_zip_filec	Cs�d}ttd��
}|�|�Wd�n1swYt�tdtj��}|�tt�Wd�n1s5wYttd��8}|�t|��t�|d��}|�	|�
�tg�|�	|�t�|j�Wd�n1skwYWd�n1szwYttd��}|�	|�t|��|�|��}Wd�n1s�wYt
�|��9}t�|��}|�	|�
�tg�|�	|�t�|j�Wd�n1s�wYWd�dSWd�dS1s�wYdS)z9Test appending to an existing file that is 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!I am not a ZipFile!r2Nr��rbrJ)r4rr5rCrDr�r
�seekr^rXrerYr,rr)r7r,rrGr��biorrr�test_append_to_non_zip_file�s.�����
�P�z5StoredTestsWithSourceFile.test_append_to_non_zip_filec	Cst���*}t�|dtj��}|�tt�Wd�n1swY|��}Wd�n1s1wYd}tt	d��}|�|�|�|�Wd�n1sRwYt�t	��}|�
|��tg�|�
|�t�|j
�Wd�dS1s{wYdS)Nr=r�r2)rrrCrDr�r5r
r\r4rrXrerYr,�r7r�rGr�r,rrrr�test_read_concatenated_zip_files
�
�
�"�z9StoredTestsWithSourceFile.test_read_concatenated_zip_filec	Cs�t���*}t�|dtj��}|�tt�Wd�n1swY|��}Wd�n1s1wYdd}tt	d��}|�|�|�|�Wd�n1sTwYt�t	d��}|�
|��tg�|�d|j
�Wd�n1szwYtt	d��}|�
|�t|��|�|��}Wd�n1s�wYt�|��D}t�|��&}|�
|��tdg�|�
|�t�|j
�|�
|�d�|j
�Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr=sI am not a ZipFile!i@Br2r�r?r�)rrrCrDr�r5r
r\r4rrXrerEr,rYr^r�rrr�$test_append_to_concatenated_zip_files0
�
�
��
�P�z>StoredTestsWithSourceFile.test_append_to_concatenated_zip_filecCs�t�tdtj��}|�tt�Wd�n1swYttddd��
}|�d�Wd�n1s5wYt�td��}|�|tj�Wd�dS1sSwYdS)Nr=r��utf-8��encodingz
rJ)rCrDrr�r5r
r4r��r7rGrrrr�test_ignores_newline_at_end&s��"�z5StoredTestsWithSourceFile.test_ignores_newline_at_endcCs�t�tdtj��}d|_|�tt�Wd�n1swYttddd��
}|�d�Wd�n1s8wYt�td��}|�|tj�|�	|jd�Wd�dS1s]wYdS)Nr=�this is a commentr�r�r�zabcdef
rJ)
rCrDrr��commentr5r
r4r�rXr�rrr�)test_ignores_stuff_appended_past_comments.s��"�zCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsc	Cs�t�td��6}|�t�ttd��}|�|�t�|���Wd�n1s'wYWd�dSWd�dS1s?wYdS)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.r=r�N)rCrDrr5r
r4rXrYr�rrr�test_write_default_name8s
��"�z1StoredTestsWithSourceFile.test_write_default_namec	Cs�d}tjtdd��}|�|d�Wd�n1swYtjtdd��N}|�|��0}|��|�t|j�|�t|j	d�|�t|j
�|�t|j�|�t|j�Wd�n1s_wYWd�dSWd�dS1swwYdS)N�somefile.txtr=rA�bogusrJr)
rCrDrrEr4�closer��
ValueErrorrYr�r��readable�seekable)r7r�rGZfidrrr�test_io_on_closed_zipextfile@s ���"�z6StoredTestsWithSourceFile.test_io_on_closed_zipextfilec	Cs�tjtdd��}|�dd�Wd�n1swYtjtdd��}|�t|jt�Wd�n1s7wYtjtdd��-}|�t��|jtdd�Wd�n1s[wYWd�dSWd�dS1sswYdS)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.r=rAr�r�NrJ)	rCrDrrEr�r�r5r
r4r�rrr�test_write_to_readonlyNs����"�z0StoredTestsWithSourceFile.test_write_to_readonlycCs�t�td�t�td��}|�t|jt�Wd�n1swYtjtddd��}|�t�|�	t�}|�
|jd�Wd�dS1sIwYdS)N)rrr=F�Zstrict_timestamps�i�rPrPrrr)�os�utimer
rCrDrr�r�r5rhrX�	date_time)r7rGr�rrr�test_add_file_before_1980[s�

"�z3StoredTestsWithSourceFile.test_add_file_before_1980cCs$d}zt�|�Wnty|�d|�d��Ynwz
t�t||f�Wnty4|�d�Ynwt�t�j}|dkrG|�d|���t	�
td��}|�t
j|jt�Wd�n1sawYt	j
tddd	��}|�t�|�t�}|�|jd
�Wd�dS1s�wYdS)Nl�&�
ztime.localtime(z) raises OverflowErrorz/Host fs cannot set timestamp to required value.l�b� �fz,Linux VFS/XFS kernel bug detected: mtime_ns=r=Fr)i;����;r)rb�	localtime�
OverflowError�skipTestrrr
�stat�st_mtime_nsrCrDrr��struct�errorr5rhrXr)r7ZtsZmtime_nsrGr�rrr�test_add_file_after_2107fs,��	�

"�z2StoredTestsWithSourceFile.test_add_file_after_2107)r�r�r�rCr�r;r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr��s"
	

r�c@seZdZejZdd�ZdS)�DeflateTestsWithSourceFilecCs�t�td��3}|�tdtj�|�tdtj�|�d�}|�d�}|�|j	tj�|�|j	tj�Wd�dS1s<wYdS)zUCheck that files within a Zip archive can have different
        compression options.r=ZstoremeZ	deflatemeN)
rCrDrr5r
r��ZIP_DEFLATEDrhrXr�)r7rGZsinfoZdinforrr�test_per_file_compression�s

"�z4DeflateTestsWithSourceFile.test_per_file_compressionN)r�r�r�rCrr;rrrrrr�src@�eZdZejZdS)�Bzip2TestsWithSourceFileN�r�r�r�rC�	ZIP_BZIP2r;rrrrr��
rc@r)�LzmaTestsWithSourceFileN�r�r�r�rC�ZIP_LZMAr;rrrrr�rrc@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#rrr�	<genexpr>�s��z;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>r�
)r(r)r+r,)r.r*rrrr/�s�z(AbstractTestZip64InSmallFiles.setUpClasscCsXtj|_tj|_dt_dt_ttd��}|�|j�Wd�dS1s%wYdS)Nrr�r2)	rC�ZIP64_LIMIT�_limit�ZIP_FILECOUNT_LIMIT�_filecount_limitr4r
r5r,r6rrrr9�s"�z#AbstractTestZip64InSmallFiles.setUpcCsptj|d|dd��}|�td�|�tt�|�d|j�Wd�n1s'wYt�|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|�|D]}
|�|
jt
|j��q�tddfD]}|�|�}|�|j|�|�|jt
|j���q|��Wd�dS1�s1wYdS)Nr=T�Z
allowZip64r>r?rJrSrMrrNrOrPrQrR�cSrTrrUr#rrrr&�rWz:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>)rCrDr5r
rEr,rXrYrrZr[r\r]r^r_r`rarbrcrdrerfrgrhrVri)r7rr;rGr8rjrkrlrmrnrorprqr%rrrsrrrrt�sR�


$�z&AbstractTestZip64InSmallFiles.zip_testcCrurrvrwrrrrx�ryz(AbstractTestZip64InSmallFiles.test_basiccCs�tjtd|jdd�}d|_d}t|�D]}|�d|d|dd	�q|�t|�	��|�|�
�t�td
|j�}|�t|�	��|�t|�D]}|�d|��d�}|�|d|dd	�qH|�
�dS)Nr=Tr'r���foo%08d�%dr(�9rJr!)
rCrDr
r;�debugr(rErXr^rer�rY�decode)r7r��numfilesr%�zipf2�contentrrr�test_too_many_files�s�z1AbstractTestZip64InSmallFiles.test_too_many_filescCstjtd|jdd�}d|_d}t|�D]}|�d|d|dd	�q|�t|�	��|�|�
tj��|�d|d
�Wd�n1sGwY|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�|�
tj��|�d|d
�Wd�n1s�wY|�t|�	��|�|��tjtd|jdd�}d|_|�t|�	��|�d
}t||�D]}|�d|d|dd	�q�|�t|�	��|�|��t�td|j�}|�t|�	��|�t|�D]}|�
d|��d�}|�|d|dd	�q�|��dS)Nr=Fr'r�r�r*r+r(r,r'r�Tr)rJr!)rCrDr
r;r-r(rErXr^rer��LargeZipFiler�rYr.)r7r�r/r%Z	numfiles2r0r1rrr�test_too_many_files_appendsN�����z8AbstractTestZip64InSmallFiles.test_too_many_files_appendcCs$|jt_|jt_tt�tt�dSr)r$rCr#r&r%rr
rr�rrrr�-sz&AbstractTestZip64InSmallFiles.tearDownN)r�r�r�r�r/r9rtrxr2r4r�rrrrr �s

9'r c@sveZdZejZdd�Zdd�Zdd�Zdd�Z	d	d
�Z
					
ddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd
S)�StoredTestZip64InSmallFilescCsLtj|d|dd��}|�tj|jtd�Wd�dS1swYdS�Nr=Fr'r>)rCrDr�r3r5r
�r7rr;rGrrr�large_file_exception_test8s
�"�z5StoredTestZip64InSmallFiles.large_file_exception_testcCsNtj|d|dd��}|�tj|jd|j�Wd�dS1s wYdSr6)rCrDr�r3rEr,r7rrr�large_file_exception_test2=s

�"�z6StoredTestZip64InSmallFiles.large_file_exception_test2cCs.t|�D]}|�|tj�|�|tj�qdSr)rr8rCr�r9rwrrr�test_large_file_exceptionBs�z5StoredTestZip64InSmallFiles.test_large_file_exceptioncCs�tjtdtjdd��}|�td�Wd�n1swYt�tdtj��}|�|��dg�Wd�dS1s=wYdS)Nr=Tr'r�rJr�r�r�rrrr�Gs��"�z2StoredTestZip64InSmallFiles.test_absolute_arcnamescCs
tjtddd��}|�d|j�Wd�n1swYtjtddd��}|�d�}|j}Wd�n1s:wYtjtddd��}|�d|j�Wd�n1sYwYtjtddd��}|�d�}|�|j|�Wd�dS1s~wYdS)Nr=Tr'r?rJr�Zstrfile2)rCrDrrEr,rh�extrarX)r7rGr�r;rrr�test_appendOs�
��
"�z'StoredTestZip64InSmallFiles.test_appendFr'Nc
Cs"d}
d}g}g}
|
}|rd}|r|�|
�|
�|
�t�d|�}|
}|r2d}|r2|�|
�|
�|
�t�d|�}|}|rEd}|rE|
�|�t�d|�}tjddt|�ddt|�g|�R�}tjddt|
�ddt|
�g|
�R�}t�dd	dt|
��}t�dd
dt|��}|dur�dt|�}|	dur�d
dt|�dt|
�}	t�dddt|��}t�dddt|
��}d}d}t�dt|��}d|||||||d||||d|||dt�d|�dd|||dt�d|	�ddd}|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
        �r����<L�<HH�QrPz<Q�:�2N�,�lz<HrSstest.txt�test1234sPK!�%��sPK--!�%��s
��PKs--s
sPKssPK:2�)r|r�packr^)r7�file_size_64_set�file_size_extra�compress_size_64_set�compress_size_extra�header_offset_64_set�header_offset_extra�extensible_data�end_of_central_dir_size�offset_to_end_of_central_dirZactual_sizeZactual_header_offsetZlocal_zip64_fieldsZcentral_zip64_fieldsrg�
compress_size�
header_offsetZlocal_extraZ
central_extraZcentral_dir_sizeZoffset_to_central_dirZlocal_extra_lengthZcentral_extra_lengthrVr1Zfilename_lengthZzip64_contentsrrr�make_zip64_file]s�





��
��
�
��������	�
���
������
�������
��� ��$z+StoredTestZip64InSmallFiles.make_zip64_filecCsR|jdd�}|�tj��}t�t�|��Wd�n1swY|�dt|j	��
��|�t�t�|���|jdddd�}|�tj��}t�t�|��Wd�n1s[wY|�dt|j	��
��|�t�t�|���|jdd�}|�tj��}t�t�|��Wd�n1s�wY|�dt|j	��
��|�t�t�|���|jdddddd�}|�tj��}t�t�|��Wd�n1s�wY|�d	t|j	��
��|�t�t�|���|jd
dddd�}|�tj��}t�t�|��Wd�n	1�swY|�d	t|j	��
��|�t�t�|���|jddd
dd�}|�tj��}t�t�|��Wd�n	1�sOwY|�d	t|j	��
��|�t�t�|���|jd
d
dd
�}|�tj��}t�t�|��Wd�n	1�s�wY|�d	t|j	��
��|�t�t�|���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)rJNz	file size)rJrKrLz
compress size)rL)rJrKrLrMrNz
header offsetF)rJrLrMrN)rJrKrLrN)rJrLrN)
rUr�rC�
BadZipFilerDrrr_rdZ	exception�lowerra�
is_zipfile)r7Zmissing_file_size_extra�eZmissing_compress_size_extraZmissing_header_offset_extrarrr�test_bad_zip64_extra�s���������������z0StoredTestZip64InSmallFiles.test_bad_zip64_extracCs�|jdd�}|�tjd��t�t�|��Wd�n1s wY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1sPwY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1s�wY|�t�t�|���|jdd�}|�tjd��t�t�|��Wd�n1s�wY|�t�t�|���dS)Nr)rQzCorrupt.*recordr�)rRrzCorrupt.*locator)	rU�assertRaisesRegexrCrVrDrrrrX�r7r�rrr�!test_bad_zip64_end_of_central_dir0s(����z=StoredTestZip64InSmallFiles.test_bad_zip64_end_of_central_dircCs�|��}|�dd�}|�tjd��t�t�|��Wd�n1s$wY|�t�	t�|���|jdd�}|�dd�}|�tjd��t�t�|��Wd�n1sZwY|�t�	t�|���dS)NrGrH�record not found�
�data�rP)
rU�replacer[rCrVrDrrrrXr\rrr�.test_zip64_end_of_central_dir_record_not_foundEs���zJStoredTestZip64InSmallFiles.test_zip64_end_of_central_dir_record_not_foundcCs
d}d}d}d}|jdd�}t�t�|���,}|��d}|�|j|�|�|j|�|�|j	|�|�|�
|�|�Wd�n1sEwY|�t�t�|���|�
tjd��t�t�d|��Wd�n1sqwY|�t�t�d|���dS)Nr=rrFr_r`r^s	prepended)rUrCrDrrrfrXrgrSrTrYrarXr[rVr)r7�expected_file_size�expected_compress_size�expected_header_offset�expected_contentr��zfr�rrr�test_zip64_extensible_dataSs&���z6StoredTestZip64InSmallFiles.test_zip64_extensible_datac
Cs�d}d}d}d}ddd�ddd�ddd�f}tdt|�d�D]Y}t�||�D]P}i}|D]}	|�|	�q-t�t�|j	d	i|�����,}
|
�
�d}|�|j|�|�|j
|�|�|j|�|�|
�|�|�Wd�n1srwYq'qdS)
Nr=rrFT)rJrK)rLrM)rNrOrPr)r(r^�	itertools�combinations�updaterCrDrrrUrfrXrgrSrTrY)r7rcrdrerf�paramsrJZcomborF�crgr�rrr� test_generated_valid_zip64_extrahs.�����z<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extra)	FFFFFFr'NN)r�r�r�rCr�r;r8r9r:r�r<rUrZr]rbrhrnrrrrr54s$
�ner5c@r)�DeflateTestZip64InSmallFilesN�r�r�r�rCrr;rrrrro�rroc@r)�Bzip2TestZip64InSmallFilesNrrrrrrq�rrqc@r)�LzmaTestZip64InSmallFilesNrrrrrrr�rrrc@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�AbstractWriterTestscC�tt�dSr�rrr�rrrr���zAbstractWriterTests.tearDowncCs�d}t�td|j��1}|�dd�}|�|�|��|�|j�|��|�|j�|�	|�
d�|�Wd�dS1s>wYdS)N�contentr=r)rCrDrr;r4r5r�rarrXrY�r7r,r�r=rrr�test_close_after_close�s
"�z*AbstractWriterTests.test_close_after_closecCs�d}t�td|j��/}|�dd�}|�|�|��|�|j�|�	t
|jd�|�|�d�|�Wd�dS1s<wYdS)Nrxr=rr')
rCrDrr;r4r5r�rarr�r�rXrYryrrr�test_write_after_close�s
"�z*AbstractWriterTests.test_write_after_closec	Cs�t�dgd��}t|�|j}t�t��d|j��2}|�dd��}|�	|�
|�|�Wd�n1s4wY|�	|�d�j|�Wd�dS1sNwYdS)NrA)rPr�r(rSrLr=r,)
�arrayr^�itemsizerCrDrrr;r4rXr5rhrg)r7�qZLENGTHr�r,rrr�test_issue44439�s�"�z#AbstractWriterTests.test_issue44439N)r�r�r�r�rzr{rrrrrrt�s

rtc@r)�StoredWriterTestsN�r�r�r�rCr�r;rrrrr��s
r�c@r)�DeflateWriterTestsNrprrrrr���
r�c@r)�Bzip2WriterTestsNrrrrrr��r�r�c@r)�LzmaWriterTestsNrrrrrr��r�r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�PyZipFileTestscCs$|d|vr|�|d|�dSdS)N�orm)r_)r7�namererrr�assertCompiledIn�r�zPyZipFileTests.assertCompiledIncCs~tj|tjtjtjvd�s|�d�tj�|d�}zt�|tjtj	B�}t�
|�Wnty8|�d�Ynwt|�dS)N)Z
effective_idsz/requires write access to the installed locationztest_zipfile.try)
r�access�W_OK�supports_effective_idsrr�r+r4�O_WRONLY�O_CREATr��	Exceptionr)r7r�rV�fdrrr�requiresWriteAccess�s

�
�z"PyZipFileTests.requiresWriteAccessc	Cs�|�tj�t��t��e}t�|d��O}t}|�d�r@|�	tj
�}tjdur/|�|�	tj��d|vr:t
j�|�}n|dd�}|�|�tj�|�}|�||���|�||���Wd�n1sewYWd�n1stwYt��T}t�|d��5}t}|�d�r�|dd�}|�|d�ddtj�|�f}|�||���|�||���Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr=�.pyc�__pycache__r�Ztestpackagez%s/%s)r�rr��dirname�__file__rrC�	PyZipFile�endswithr`�sep�altsep�extend�	importlib�util�source_from_cache�writepy�basename�assertNotInrer�)r7�trGrlZ
path_splitZbnrrr�test_write_pyfile�s4


��
P�z PyZipFileTests.test_write_pyfilec	Cs�ddl}tj�|j�}|�|�t��<}t�|d��}|�	|�|�
�}|�d|�|�d|�Wd�n1s:wYWd�dSWd�dS1sRwYdS)Nrr=zemail/__init__.pyzemail/mime/text.py)�emailrr�r�r�r�rrCr�r�rer�)r7r��
packagedirr�rGrprrr�test_write_python_package�s

P�z(PyZipFileTests.test_write_python_packagecCs�ddl}tj�|j�}|�|�t���}t�|d���}t	��
}|�
|�Wd�n1s.wY|��}|�d|v�t	��}|j
|dd�d�Wd�n1sUwY|��}|�d|v�dd�}t	��$}|�
t��|j
||d�Wd�n1s�wYWd�n1s�wY|��}|r�t|�|�d|v�Wd�n1s�wYWd�dSWd�dS1s�wYdS)	Nrr=�SyntaxErrorcSsdS)NFr)Zwhateverrrr�<lambda>�zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>�Z
filterfunccSstj�|��d�S)NZbad)rr�r��
startswith)r�rrr�filter�zAPyZipFileTests.test_write_filtered_python_package.<locals>.filter)rrr�r�r�r�rrCr�rr�r\ra�assertWarns�UserWarning�print)r7rr�r�rGZ	reportSIOZ	reportStrr�rrr�"test_write_filtered_python_packages2
����P�z1PyZipFileTests.test_write_filtered_python_packagec	Cs�ddl}tj�|j�}|�|�d}d}t��B}tj|d|d��!}|�	|�|�
�}|�d||�|�d||�Wd�n1sDwYWd�dSWd�dS1s\wYdS)	NrTrPr�r=)�optimizezemail/__init__zemail/mime/text)r�rr�r�r�r�rrCr�r�rer_)r7r�r�ZoptlevelZextr�rGrprrr�test_write_with_optimization"s
�
P�z+PyZipFileTests.test_write_with_optimizationc	Cs�t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYttj�td�ddd��
}|�d�Wd�n1sCwYttj�td�ddd��
}|�d	�Wd�n1sdwYt��9}t�	|d��#}|�
t�|��}|�d|�|�d|�|�
d|�Wd�n1s�wYWd�n1s�wYWtt�dSWtt�dStt�w)
N�mod1.pyr=r�r��
print(42)
�mod2.py�print(42 * 42)
zmod2.txtzbla bla bla
�r�mkdirrr4r�r+r5rrCr�r�rer�r�r�r7r8r�rGrprrr�test_write_python_directory1s.
���
��	�	z*PyZipFileTests.test_write_python_directoryc	Cs:t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYttj�td�ddd��
}|�d�Wd�n1sCwYt��7}t�	|d��!}|j
tdd	�d
�|��}|�d|�|�
d|�Wd�n1svwYWd�n1s�wYWtt�dSWtt�dStt�w)Nr�r=r�r�r�r�r�cSs|�d�S)Nr�)r�)rlrrrr�RrwzEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>r�r�r�rrr�$test_write_python_directory_filteredHs&
����	�	z3PyZipFileTests.test_write_python_directory_filteredc
Cs�t��O}t�|d��0}ttddd��
}|�d�Wd�n1s"wY|�t|jt�t	t�Wd�n1s=wYWd�dSWd�dS1sUwYdS)Nr=r�r�z!most definitely not a python file)
rrCr�r4r
r5r��RuntimeErrorr�r)r7r�rGrrrr�test_write_non_pyfile\s�
P�z$PyZipFileTests.test_write_non_pyfilec
Cs0t�t�z�ttj�td�ddd��
}|�d�Wd�n1s"wYt��S}t�	|d��=}t
��}|�tj�td��Wd�n1sJwY|�d|�
��|��}|�d|�|�d|�Wd�n1sqwYWd�n1s�wYWtt�dSWtt�dStt�w)Nr�r=r�r�zBad syntax in python file
r�zmod1.pyc)rr�rr4r�r+r5rrCr�rr�r_r\rer�r)r7r8r�rG�srprrr�test_write_pyfile_bad_syntaxcs&
�����z+PyZipFileTests.test_write_pyfile_bad_syntaxc	Cs�t�t�zlttj�td�ddd��
}|�d�Wd�n1s"wYt��2}t�	|d��}|�
t�t�d�|�
�}|�d|�Wd�n1sPwYWd�n1s_wYWtt�dSWtt�dStt�w)Nr�r=r�r�r�)rr�rr4r�r+r5rrCr�r�r�r�rer�rr�rrr�test_write_pathlikeys
����z"PyZipFileTests.test_write_pathlikeN)r�r�r�r�r�r�r�r�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dd�Z
dd�Ze�ejjdkd�dd��Ze�ejjdkd�dd ��Zd!d"�Zd#S)$�ExtractTestscCsPt�tdtj��}tD]
\}}|�||�qWd�dS1s!wYdS)Nr=)rCrDrr��SMALL_TEST_DATArE�r7rG�fpath�fdatarrr�make_test_file�s
�"�zExtractTests.make_test_filecCs�t��o|��t�td��L}tD]A\}}|�|�}tj�	t�
�|�}tj�|�}|�||�t
|d��}|�|��|���Wd�n1sIwYt|�qWd�n1s]wYWd�dSWd�dS1suwYdS�NrJr�)rr�rCrDrr��extractrr�r+�getcwd�normpathrXr4�encoderYr)r7rGr�r��writtenfile�correctfilerrrr�test_extract�s"
�
���"�zExtractTests.test_extractc
Cs�|��t�td��R}tD]G\}}|�||�}tj�||�}tj�	|�}|�
tj�||�||f�t|d��}|�
|��|���Wd�n1sKwYt|�q
Wd�n1s_wYtt�dSr�)r�rCrDrr�r�rr�r+r�ra�samefiler4rXr�rYr)r7�targetrGr�r�r�r�rrrr�_test_extract_with_target�s�
��z&ExtractTests._test_extract_with_targetcC�6t��}|�|�Wd�dS1swYdSr)rr��r7�extdirrrr�test_extract_with_target��"�z%ExtractTests.test_extract_with_targetcC�<t��}|�t�|��Wd�dS1swYdSr)rr�r�r�r�rrr�!test_extract_with_target_pathlike��"�z.ExtractTests.test_extract_with_target_pathlikecCs�t��b|��t�td��?}|��tD]0\}}tj�	t�
�|�}t|d��}|�|�
�|���Wd�n1s<wYt|�qWd�n1sPwYWd�dSWd�dS1shwYdSr�)rr�rCrDr�
extractallr�rr�r+r�r4rXr�rYr)r7rGr�r��outfilerrrr�test_extract_all�s�
���"�zExtractTests.test_extract_allc
Cs�|��t�td��>}|�|�tD].\}}tj�||�}t	|d��}|�
|��|���Wd�n1s7wYt
|�qWd�n1sKwYt
t�dSr�)r�rCrDrr�r�rr�r+r4rXr�rYr)r7r�rGr�r�r�rrrr�_test_extract_all_with_target�s
�
��
z*ExtractTests._test_extract_all_with_targetcCr�r)rr�r�rrr�test_extract_all_with_target�r�z)ExtractTests.test_extract_all_with_targetcCr�r)rr�r�r�r�rrr�%test_extract_all_with_target_pathlike�r�z2ExtractTests.test_extract_all_with_target_pathlikecCsR|�tj�|��t|d��}|�|��|�Wd�dS1s"wYdS)Nr�)rarr��isfiler4rXrY)r7rVr1rrrr�
check_file�s"�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_i�../../foo../../ba..r�/�	foo/ba..r)rCrDZ_sanitize_windows_namerX)r7Zsanrrr�test_sanitize_windows_name�sz'ExtractTests.test_sanitize_windows_namecC�gd�}|�|�dS)N))z
../foo/bar�foo/bar)z
foo/../barr�)z
foo/../../barr�)z
foo/bar/..r�)z./../foo/barr�)z/foo/barr�)z/foo/../barr�)z/foo/../../barr���_test_extract_hackers_arcnames)r7Zcommon_hacknamesrrr�*test_extract_hackers_arcnames_common_cases�s
z7ExtractTests.test_extract_hackers_arcnames_common_cases�\zRequires \ as path separator.cCsgd�}|�|�dS)z>Test combination of path fixing and windows name sanitization.))z
..\foo\barr�)z..\/foo\/barr�)zfoo/\..\/barr�)zfoo\/../\barr�)z	C:foo/barr�)z
C:/foo/barr�)zC://foo/barr�)z
C:\foo\barr�)z//conky/mountpoint/foo/barr�)z\\conky\mountpoint\foo\barr�)z///conky/mountpoint/foo/bar�conky/mountpoint/foo/bar)z\\\conky\mountpoint\foo\barr�)z//conky//mountpoint/foo/barr�)z\\conky\\mountpoint\foo\barr�)z//?/C:/foo/barr�)z\\?\C:\foo\barr�)zC:/../C:/foo/barz
C_/foo/bar)za:b\c<d>e|f"g?h*izb/c_d_e_f_g_h_i)r�r�Nr�)r7Zwindows_hacknamesrrr�*test_extract_hackers_arcnames_windows_only�sz7ExtractTests.test_extract_hackers_arcnames_windows_onlyr�zRequires / as path separator.cCr�)N))z	//foo/barr�)r�zfoo../ba..r)�
foo/..\barr�r�)r7Zposix_hacknamesrrr�(test_extract_hackers_arcnames_posix_onlysz5ExtractTests.test_extract_hackers_arcnames_posix_onlyc
	Cs:|D�]\}}d|��}t�tdtj��}t��}||_d|_|�||�Wd�n1s0wY|�	t
jd�}t
j�
ddd�}t
jj
|g|�d��R�}t�td��}|�||�}	|j|	|d	||	|fd
�Wd�n1suwY|�||�td�t�td��
}|�|�Wd�n1s�wY|�||�td�t
jj
t
��g|�d��R�}t�td��}|�|�}	|j|	|d|d
�Wd�n1s�wY|�||�t|�d�d�t�td��}|��Wd�n	1�swY|�||�t|�d�d�tt�qdS)
N�foobarr=r�r�r��subdirZsubsubrJzextract %r: %r != %r)�msgz
extract %rr)r�rCrDrr��ZipInforVr�rErarr�r�r+r`r�rXr�rr�r�r)
r7Z	hacknamesZarcnameZ	fixednamer1rGr�Z
targetpathr�r�rrrr�sT�����
��
�
�z+ExtractTests._test_extract_hackers_arcnamesN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfrr�r�r�r�r�rrrrr��s$


r�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��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&dGdH�Z'dIdJ�Z(dKdL�Z)e*�dMdN��Z+e�dOdP��Z,e�dQdR��Z-dSdT�Z.dUS)V�
OtherTestsc
CsBt�tdtj��4}|�dd�|�t��|�dd�Wd�n1s%wY|�|��dgd�Wd�n1s?wYt�td��M}|�	�}d}|D]}|�
|��}||��7}Wd�n1skwYqS|�|dd	h�d}|D]	}||�|�7}q}|�|dd	h�Wd�dS1s�wYdS)
Nr=r�r��barr�rJr'r�sbarfoo)
rCrDrr�rEr�r�rXrerfr4rYr_)r7rGrqr,rsr�rrr�test_open_via_zip_infoHs*����"�z!OtherTests.test_open_via_zip_infocCs`t�td�� }dD]}t�|�}|jdO_|�||�q	Wd�dS1s)wYdS)Nr=Zabcdefghijklmnopr=)rCrDrr��	flag_bitsrE)r7Zorig_zipr,r�rrr�-test_writestr_extended_local_header_issue1202\s
�"�z8OtherTests.test_writestr_extended_local_header_issue1202cCs�t�td��}tD]\}}|�||�|�|jd�q	Wd�n1s%wY|�|jd�t�td��}|�|jd�Wd�n1sIwY|�|jd�dS)z8Check that the zipfile is closed after the 'with' block.r=zzipfp is not openN�zipfp is not closedrJ)rCrDrr�rEZassertIsNotNoner8�assertIsNoner�rrr�
test_closecs���zOtherTests.test_closecCs�t�td��}tD]
\}}|�||�q	Wd�n1swYzt�td��}t���1s2wYWdStjyK|�|jd�YdSw)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.r=NrJr�)rCrDrr�rErVr�r8)r7rGr�r�Zzipfp2rrr�test_close_on_exceptionos����z"OtherTests.test_close_on_exceptioncCs d}|�ttjt�|�d�dS)NsdPKx!p�@xPKxx!p�@�xPK/rJ)r��NotImplementedErrorrCrDrrr�rrr�test_unsupported_version|s

�z#OtherTests.test_unsupported_versioncCsTtd�}t�|��}|��D]	}|�|���qWd�dS1s#wYdS)Nzzip_cp437_header.zip)rrCrDrer4r�)r7r�rGr�rrr�test_read_unicode_filenames�s�"�z&OtherTests.test_read_unicode_filenamescCs�t�td��}|�dd�|�dd�|�|��djt�Wd�n1s(wYt�td��}|�|j	djd�|�|j	djd�Wd�dS1sSwYdS)Nr=�foo.txtzTest for unicode filenameuö.txtrrJrP)
rCrDr
rEr�rfrVrdrX�filelist�r7rgrrr�test_write_unicode_filenames�s�"�z'OtherTests.test_write_unicode_filenamescCsPt�td��}|�dd�|�|�d�d�Wd�dS1s!wYdS)Nr=uприкладssample)rCrDrrErXrYr�rrr�'test_read_after_write_unicode_filenames�s"�z2OtherTests.test_read_after_write_unicode_filenamescCs�tt�d}d}t�tdtj��}|�||�Wd�n1s!wY|�t��t�tdtj�Wd�n1s>wYt�td��}|�|�	�|g�|�|�
|�|�Wd�dS1sgwYdS)z&Test exclusive creating a new zipfile.�testfile.txt�#hello, world. this is some content.�xNrJ)rrrCrDr�rEr��FileExistsErrorrXrerY)r7rVr1rGrrr�test_exclusive_create_zip_file�s��"�z)OtherTests.test_exclusive_create_zip_filecCs�tj�t�rt�t�d}d}zt�td��}|�||�Wd�n1s'wYWnty;|�	d�Ynw|�
tj�t��t�td��}|�|�|�|�Wd�dS1s`wYdS)Nrrr�z1Could not append data to a non-existent zip file.rJ)
rr��existsr
rrCrDrEr��failrarXrY)r7rVr1rgrrr�(test_create_non_existent_file_for_append�s 
���"�z3OtherTests.test_create_non_existent_file_for_appendcCs`ttddd��
}|�d�Wd�n1swYzt�t�}WdStjy/YdSw)Nr=r�r��this is not a legal zip file
)r4r
r5rCrDrV)r7r8rgrrr�test_close_erroneous_file�s��z$OtherTests.test_close_erroneous_filecCs�ttddd��
}|�d�Wd�n1swY|�t�t��|�t�t�t���ttd��}|�t�|��Wd�n1sGwYt�	�}|�d�|�t�|��|�
dd�|�t�|��dS)	z;Check that is_zipfile() correctly identifies non-zip files.r=r�r�rNr�sthis is not a legal zip file
r)r4r
r5rrCrXr�r�rrr�r6rrr�test_is_zip_erroneous_file�s��
z%OtherTests.test_is_zip_erroneous_filecCs�t��}tj|dd��}|�dd�Wd�n1swY|��}tt|��D]}t�|d|��}|�tj	tj|�q+dS)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.r=rAr�O, for a Muse of Fire!N)
rrrCrDrEr\r(r^r�rV)r7r8r�r��Nrrr�test_damaged_zipfile�s��zOtherTests.test_damaged_zipfilecCs�tjtdd��}|�dd�Wd�n1swY|�t�t��ttd��}|�t�|��|�dd�|��}Wd�n1sGwYt	�
�}|�|�|�t�|��|�dd�|�t�|��dS)z7Check that is_zipfile() correctly identifies zip files.r=rArrNr�r)rCrDr
rErarXr4r�rYrrr5)r7r�r8Zzip_contentsrrr�test_is_zip_valid_file�s�
�
z!OtherTests.test_is_zip_valid_filecCs|�ttjt�dSr)r�r�rCrDr
r�rrr�%test_non_existent_file_raises_OSError�sz0OtherTests.test_non_existent_file_raises_OSErrorcCsvttddd�}|��|�tjtjt�ttddd��
}|�d�Wd�n1s+wY|�tjtjt�dS)Nr=r�r�z
short file)r4r
r�r�rCrVrDr5)r7rr8rrr�!test_empty_file_raises_BadZipFile
s�z,OtherTests.test_empty_file_raises_BadZipFilecCsFtd�}dD]}t�d|�|dd�<t�|�}|�tjtj|�qdS)N�PK)rPr>r?r	�)	�	bytearrayrrIrrr�rCrVrD)r7�bufferZdirsizerrrr�8test_negative_central_directory_offset_raises_BadZipFiles
�zCOtherTests.test_negative_central_directory_offset_raises_BadZipFilecCs�t��}tj|dd��}|�dd�Wd�n1swY|�t|jd�|�t|jd�|�t|j	�|�t|jdd�tt
ddd	��
}|�d
�Wd�n1sXwY|�t|jt
�dS)z?Verify that testzip() doesn't swallow inappropriate exceptions.r=rAr�O, for a Muse of Fire!Nz	bogus.txtr�r�r�zzipfile test data)rrrCrDrEr�r�rYr4rir
r5)r7r,r�rrrr�!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.r~N)r�r�rCrDr
r�rrr�test_bad_constructor_mode3sz$OtherTests.test_bad_constructor_modecCs�tjtdd��}|�dd�Wd�n1swYtjtdd��)}|�d�|�t|jdd�|�t|jdd�|�t|jdd	�Wd�dS1sPwYdS)
z7Check that bad modes passed to ZipFile.open are caught.r=rArrNrJr~�UZrU)rCrDr
rErYr�r�r4�r7r�rrr�test_bad_open_mode7s�
"�zOtherTests.test_bad_open_modec	Cs�tjtdd��D}|�dd�|�d�� }tt�D]}|�|�d�d�q|�|��d�Wd�n1s6wYWd�dSWd�dS1sNwYdS)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.r=rArrrr'rN)	rCrDr
rEr4r(r)rXrY)r7r�rr%rrr�
test_read0Ds��"�zOtherTests.test_read0cCsFtjtdd��}|�t|jdd�Wd�dS1swYdS)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.r=rArrJN)rCrDr
r��KeyErrorr4r!rrr�test_open_non_existent_itemPs"�z&OtherTests.test_open_non_existent_itemcCs|�ttjtdd�dS)zMCheck that bad compression methods passed to ZipFile.open are
        caught.r=r�N)r�r�rCrDr
r�rrr�test_bad_compression_modeVsz$OtherTests.test_bad_compression_modecCsLd}t�t�|�d��}|�t|jd�Wd�dS1swYdS)NsfPK.�C�@xPK..�C�@�xPK/!rJr	)rCrDrrr�r�r4)r7r,r�rrr�test_unsupported_compression[s"�z'OtherTests.test_unsupported_compressioncCsRtjtdd��}|�dd�|�|��dg�Wd�dS1s"wYdS)zLCheck that a filename containing a null byte is properly
        terminated.r=rAzfoo.txtqqqrrN)rCrDr
rErXrer!rrr�test_null_byte_in_filenamefs"�z%OtherTests.test_null_byte_in_filenamecCs<|�tjd�|�tjd�|�tjd�|�tjd�dS)zACheck that ZIP internal structure sizes are calculated correctly.��.�8r�N)rXrCZsizeEndCentDirZsizeCentralDirZsizeEndCentDir64ZsizeEndCentDir64Locatorr�rrr�test_struct_sizesmszOtherTests.test_struct_sizesc	Cs�tjtdd��}|�|jd�|�dd�Wd�n1swYtjtdd��}|�|jd�Wd�n1s=wYd}tjtdd��}||_|�dd�Wd�n1s_wYtjtdd��}|�|j|�Wd�n1s}wYd	�d
d�td�D��}|�d
�}tjtdd��}||_|�dd�Wd�n1s�wYtjtdd��}|�|j|�Wd�n1s�wYtjtdd��(}|�	t
��
|d|_Wd�n1s�wY|�dd�Wd�n	1�swYtjtdd��}|�|j|�Wd�n	1�s#wYtjtdd��}d|_|�dd�Wd�n	1�sDwYtjtdd��}d|_Wd�n	1�s_wYtjtdd��}|�|jd�Wd�n	1�s~wYtjtdd��}d|_|�dd�Wd�n	1�s�wYtj�
t�}tjtdd��}d|_Wd�n	1�s�wY|�|tj�
t�k�tjtdd��}|�|jd�Wd�dS1�s�wYdS)z8Check that comments on the archive are handled properly.r=rAr'rrNrJs9Bravely taking to his feet, he beat a very brave retreat.�cSsg|]
}d|dd�qS)r+r(r�rr#rrrr&�sz,OtherTests.test_comments.<locals>.<listcomp>�r!soopssoriginal commentr�san updated commentsoriginal comment that's longersshorter comment)rCrDr
rXr�rEr+r(r�r�r�rr��getsizera)r7r�Zzipfrr�Zcomment2Zoriginal_zip_sizerrr�
test_commentstsn����
����������$�zOtherTests.test_commentsc	Cs�t�tdtj��/}|�dd�|�t��d|_Wd�n1s"wYWd�dSWd�dS1s:wYdS)Nr=rrzthis is an error)rCrDr
r�rEr��	TypeErrorr�r!rrr�test_unicode_comment�s��"�zOtherTests.test_unicode_commentcCs�t�tdtj��}|�|j�d|_Wd�n1swYt�td��}|�|jd�Wd�dS1s:wYdS)Nr�r�rJ)rCrDr
r�rrr�rXr!rrr�$test_change_comment_in_empty_archive�s�"�z/OtherTests.test_change_comment_in_empty_archivecCs�t�tdtj��}|�dd�Wd�n1swYt�tdtj��}|�|j�d|_Wd�n1s:wYt�td��}|�|jd�Wd�dS1sXwYdS)Nr=rrr�r�rJ)	rCrDr
r�rErarr�rXr!rrr�'test_change_comment_in_nonempty_archive�s��"�z2OtherTests.test_change_comment_in_nonempty_archivecCs�tjtdd�}|��z	tjtdd�}Wntjy#|�d�Ynwtjtdd�}|��z
tjtdd�}WdS|�d�YdS)Nr=rArJz+Unable to create empty ZIP file in 'w' moder�z+Unable to create empty ZIP file in 'a' mode)rCrDr
r�rVr
r!rrr�test_empty_zipfile�s�zOtherTests.test_empty_zipfilecCs.ttddd�}|��|�tjtjtd�dS)Nr=r�r�rJ)r4r
r�r�rCrVrDrwrrr�test_open_empty_file�szOtherTests.test_open_empty_filecCs|�ttjdd�dS)NZ	seventies)i�rPrPrrr)r�r�rCr�r�rrr�test_create_zipinfo_before_1980�s�z*OtherTests.test_create_zipinfo_before_1980cCs tjdd�}|�t|�d�dS)z=Before bpo-26185, repr() on empty ZipInfo object was failing.�emptyrUz&<ZipInfo filename='empty' file_size=0>N)rCr�rXr��r7�zirrr�test_create_empty_zipinfo_repr�sz)OtherTests.test_create_empty_zipinfo_reprcCs�t��}|�|jd�|�|jd�|�|jd�|�|jtj�|�|jd�|�|j	d�|�
|jd�|�|jtj
�|�|jtj
�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�dS)z'Ensure all required attributes are set.ZNoNamerr')rr(rN)rCr�rXZ
orig_filenamerVrr�r�r�r;r_Z
create_systemZcreate_versionZDEFAULT_VERSIONZextract_versionZreservedr�ZvolumeZ
internal_attrr�rgrSr9rrr�,test_create_empty_zipinfo_default_attributes�s"z7OtherTests.test_create_empty_zipinfo_default_attributescCsJd}t�t�|�d��}|�|���Wd�dS1swYdS)z>If an extra field in the header is less than 4 bytes, skip it.snPK���@����abcAPK���@������abcPK3%rJN)rCrDrrr�ri�r7r�r�rrr�#test_zipfile_with_short_extra_field�s
�	"�z.OtherTests.test_zipfile_with_short_extra_fieldc
Cspd}d}d}t�tdtj���}|jddd��
}|�|�Wd�n1s&wY|jddd���}|�t��|jddd�Wd�n1sJwY|�t��|jdd	d�Wd�n1sfwY|�t��|�d
d�Wd�n1s�wY|�t��|�t	d�Wd�n1s�wY|�t��|�
�Wd�n1s�wY|�|�Wd�n1s�wY|jd
dd��
}|�|�Wd�n1s�wYWd�n1s�wYt�td	��.}|�|�d�|�|�|�d�|�|�|�d
�|�|�|�
�gd��Wd�dS1�s1wYdS)Ns"It's fun to charter an accountant!s And sail the wide accountant seas#To find, explore the funds offshorer=r�rAr�ZhandlerJrdZabcderK�baz)r�r�r?)rCrDrr�r4r5r�r�rEr�r�rXrYre)r7Zmsg1Zmsg2Zmsg3r�Zw2�w1rrr�test_open_conflicting_handlessH�����
�����$�z(OtherTests.test_open_conflicting_handlesc	Cs�d}|�d�}t�td��}|�d|�Wd�n1swYt�td��{}|�dd��e}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1s�wYWd�n1s�wYt��}tj|dd��}|�d|�Wd�n1s�wYtj|dd���}|�dd��e}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�d�|||d��|�dtj
�|�	|�
�t|��|�dtj�|�	|�
�d�Wd�n1�sDwYWd�dSWd�dS1�s]wYdS)	NsWhere's Bruce?sBrucer=rrJrrLrA)�findrCrDr
rEr4r�r�SEEK_SETrXr��SEEK_CURrY�SEEK_ENDr^rr)r7�txt�blocr�r8r,rrr�test_seek_tell(sT
����� ��$�zOtherTests.test_seek_tellc	Cs�d}t�|�}tj|dtjd��}|�dd�Wd�n1s!wYt�dd��.t�|��}|�t	|j
d�Wd�n1sEwYWd�dSWd�dS1s]wYdS)Nrr=)r;r��azzipfile.bz2)rrrCrDrrE�mockZpatchr�r�r�)r7r,Zzip_filergrrr�)test_decompress_without_3rd_party_libraryNs
���"�z4OtherTests.test_decompress_without_3rd_party_libraryc	Csd}t�t�|�d��v}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd�|�|j	d�|�t
|�d��d�|�tj
d��
|�d�Wd�n1slwYWd�dSWd�dS1s�wYdS)	Ns�PK�lH�8�	a��0�K\d`PK�lH�8�	aPK�lH�8�	bPK^/rJr��brr�	zFile name.*differ)rCrDrrrXrerhrTrSrgr^rYr[rV�r7r,r�r:rrr�test_full_overlapXs&�


��"�zOtherTests.test_full_overlapc	Csd}t�t�|�d��n}|�|��ddg�|�d�}|�|jd�|�|jd�|�|j	d�|�d�}|�|jd�|�|jd	�|�|j	d
�|�
tjd��
|�d�Wd�n1sawY|�t
|�d��d
�Wd�dS1s|wYdS)Ns�PK�lHY�84(a�PK�lH�8�	b��0�K\d`PK�lHY�84(aPK�lH�8�	$bPK^SrJr�rLr�4i(�$rrMzOverlapped entries)rCrDrrrXrerhrTrSrgr[rVrYr^rNrrr�test_quoted_overlapus"�

�"�zOtherTests.test_quoted_overlapcCr�rr�r�rrrr��r�zOtherTests.tearDownN)/r�r�r�r�r�r�r�rr	rrrrrrrrrrrrrrr"r#r%r&r'r(r,r0r2r3r4r5r6r7r;r<r>rArHr
rKrOrRr�rrrrr�Gs^



	
:	&
	

r�c@seZdZdd�Zdd�ZdS)�AbstractBadCrcTestscCsP|j}tjt�|�dd��}|�d|���Wd�dS1s!wYdS)z>Tests that files with bad CRCs return their name from testzip.rJrA�afileN)�zip_with_bad_crcrCrDrrrXrir=rrr�test_testzip_with_bad_crc�s"�z-AbstractBadCrcTests.test_testzip_with_bad_crcc
Csz|j}tjt�|�dd��}|�tj|jd�Wd�n1s!wYtjt�|�dd��&}|�dd��}|�tj|j�Wd�n1sJwYWd�n1sYwYtjt�|�dd��K}|�dd��,}d|_	|�tj��|�d�r�	|�d�sWd�n1s�wYWd�n1s�wYWd�dSWd�dS1s�wYdS)zFTests that files with bad CRCs raise a BadZipFile exception when read.rJrArTNr�)
rUrCrDrrr�rVrYr4�
MIN_READ_SIZE)r7r�r�Zcorrupt_filerrr�test_read_with_bad_crc�s0����

������"�z*AbstractBadCrcTests.test_read_with_bad_crcN)r�r�r�rVrXrrrrrS�srSc@�eZdZejZdZdS)�StoredBadCrcTestssxPK ��;:r��afilehello,AworldPK ��;:r���afilePK3/N)r�r�r�rCr�r;rUrrrrrZ�s�rZc@rY)�DeflateBadCrcTestss|PKn}=FAKEnafile�H���W(�/�Iɠ=PKn}=FAKEn�afilePK33N)r�r�r�rCrr;rUrrrrr[���r[c@rY)�Bzip2BadCrcTestss�PKnu=FAKE8nafileBZh91AY&SYԨ��@D��  �P�!����u5:���"�(HjTe?�PKnu=FAKE8n ���afilePK3[N)r�r�r�rCrr;rUrrrrr]�r\r]c@rY)�LzmaBadCrcTestss�PKnu=FAKEnafile	]4I���:3`	q!.8PKnu=FAKEn ���afilePK3>N)r�r�r�rCrr;rUrrrrr^�r\r^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 testscCs�ttd��}|�|j�Wd�n1swYt�td�|_ttd��}|�|j�Wd�n1s8wYt�td�|_	dS)Nr2rJ)
r4r
r5r,rCrDr�r�data2�zip2r6rrrr9
	s��zDecryptionTests.setUpcCs,|j��t�t�|j��t�t�dSr)r�r�rrr
rarr�rrrr�	s


zDecryptionTests.tearDowncCs(|�t|jjd�|�t|jjd�dS)N�test.txt�zero)r�r�r�rYrar�rrr�test_no_password	sz DecryptionTests.test_no_passwordcCs@|j�d�|�t|jjd�|j�d�|�t|jjd�dS)Nsperlrbrc)r��setpasswordr�r�rYrar�rrr�test_bad_password	sz!DecryptionTests.test_bad_passwordcCsH|j�d�|�|j�d�|j�|j�d�|�|j�d�|j�dS)N�pythonrbs12345rc)r�rerXrY�plainra�plain2r�rrr�test_good_password$	sz"DecryptionTests.test_good_passwordcCsV|�t|jjd�|�t|jjdd�|jt|jjddd�|jt|jjddd�dS)NZunicoderbZpython)�pwd)r�r1r�rerYr4r�r�rrr�test_unicode_password+	sz%DecryptionTests.test_unicode_passwordcCs�|j�d�|j}d}|�|�}t|�}|j�dd���}|�|tj�|�	|�
�|�|�|tj�|�	|�
�d�|�|tj�|�	|�
�|�|�	|�|�||||��|j
}d|_
d|_d|_|�dtj�|�	|�
�d�|�|tj�|�	|�|�||||��||_
|�dtj�|�	|�
�t|��|�dtj�|�	|�
�d�|��Wd�dS1s�wYdS)Nrgs
encryptionrbrJrrPr')r�rerhrBr^r4r�rrCrXr�rDrYrWZ_readbufferZ_offsetrE)r7rFZ	test_wordrGZbloc_lenr8Z
old_read_sizerrrrH1	s8

"�zDecryptionTests.test_seek_tellN)r�r�r��__doc__r,r`rhrir9r�rdrfr	rjrlrHrrrrr_�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)Nr�@r�rPr'css(�|]}t�dt�tdd��VqdS)z<fi���rN)rrIrrr#rrrr![	s� �z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>)rr+r(r,)r.Z	datacountrrrr/X	s
�z-AbstractTestsWithRandomBinaryFiles.setUpClasscCr0r1r3r6rrrr9^	r:z(AbstractTestsWithRandomBinaryFiles.setUpcCr�rr�r�rrrr�c	r�z+AbstractTestsWithRandomBinaryFiles.tearDowncCsLt�|d|��}|�td�|�tt�Wd�dS1swYdS)Nr=r>)rCrDr5r
r7rrrrIg	s"�z4AbstractTestsWithRandomBinaryFiles.make_test_archivecCs�|�||�t�|d|��*}|�t�}|�t|�t|j��|�||j�|�|�d�|j�Wd�dS1s:wYdS)NrJr>)rIrCrDrYr
rXr^r,)r7rr;rG�testdatarrrrtm	s
"�z+AbstractTestsWithRandomBinaryFiles.zip_testcCrurrvrwrrr�	test_readw	ryz,AbstractTestsWithRandomBinaryFiles.test_readc	Cs4|�||�t�|d|���}g}|�t��}	|�d�}|sn|�|�qWd�n1s/wYg}|�d��}	|�d�}|sEn|�|�q=Wd�n1sUwYd�|�}	|�t	|	�t	|j
��|�|	|j
�d�|�}
|�t	|
�t	|j
��|�|
|j
�Wd�dS1s�wYdSrz)rIrCrDr4r
rYr|r+rXr^r,)r7rr;rGr}r~rr�r�Z	testdata1Z	testdata2rrrr�{	s:

��

��

"�z0AbstractTestsWithRandomBinaryFiles.zip_open_testcCrurr�rwrrrr��	ryz,AbstractTestsWithRandomBinaryFiles.test_openc	Cs�|�||�t�|d|��I}g}|�t��}	|�tdd��}|s"n|�|�qWd�n1s2wYd�|�}|�	t
|�t
|j��|�	||j�Wd�dS1sYwYdSr�)rIrCrDr4r
rYrr|r+rXr^r,)r7rr;rGr}r~rrprrrr��	s 
��
"�z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testcCrurr�rwrrrr��	ryz3AbstractTestsWithRandomBinaryFiles.test_random_openN)r�r�r�r�r/r9r�rIrtrqr�r�r�r�rrrrrnW	s

rnc@r)� StoredTestsWithRandomBinaryFilesNr�rrrrrr�	r�rrc@r)�!DeflateTestsWithRandomBinaryFilesNrprrrrrs�	rrsc@r)�Bzip2TestsWithRandomBinaryFilesNrrrrrrt�	rrtc@r)�LzmaTestsWithRandomBinaryFilesNrrrrrru�	rruc@rs)
�TellablecCs||_d|_dS�Nr)r8�offsetr6rrr�__init__�	s
zTellable.__init__cCs|j�|�}|j|7_|Sr)r8r5rx)r7r,�nrrrr5�	szTellable.writecCs|jSr)rxr�rrrr��	sz
Tellable.tellcC�|j��dSr�r8�flushr�rrrr}�	�zTellable.flushN)r�r�r�ryr5r�r}rrrrrv�	s
rvc@�$eZdZdd�Zdd�Zdd�ZdS)�
UnseekablecCs
||_dSr)r8r6rrrry�	s
zUnseekable.__init__cCs|j�|�Sr)r8r5r�rrrr5�	rwzUnseekable.writecCr{rr|r�rrrr}�	r~zUnseekable.flushN)r�r�r�ryr5r}rrrrr��	sr�c@r)�UnseekableTestscCsfdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��}|�
dd�|�
dd	�Wd�n1s?wY|�|��dd
�d�tj|dd
��B}|�
d��}|�|��d�Wd�n1spwY|�
d��}|�|��d	�Wd�n1s�wYWd�n1s�wYWd�n1s�wYqdS)NcS�|Srr�rrrrr��	r�z/UnseekableTests.test_writestr.<locals>.<lambda>��wrapper�abcr=�ones�111�twos�222rL�abcPKrJrA)rvr��subTestrrr5�BufferedWriterrCrDr�rErXr\r4rY)r7r�r�bfrGr��zopenrrr�
test_writestr�	s.

���������zUnseekableTests.test_writestrcCs�dd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��N}|�
tt�t
td��
}|�d�Wd�n1sDwY|�td�t
td��
}|�d	�Wd�n1sdwY|�td
�Wd�n1sywY|�|��dd�d�tj|d
d��B}|�
d��}|�|��d�Wd�n1s�wY|�
d
��}|�|��d	�Wd�n1s�wYWd�n1s�wYWd�n1s�wYqdS)NcSr�rrr�rrrr��	r�z,UnseekableTests.test_write.<locals>.<lambda>r�r�r=r2r�r�r�r�rLr�rJrA)rvr�r�rrr5r�rCrDr��
addCleanuprr
r4rXr\rY)r7r�rr�rG�f2r�r�rrr�
test_write�	s<

�����������zUnseekableTests.test_writecCsfdd�ttfD]�}|j|d���t��}|�d�t�|�}t�||�dtj	��>}|�
dd��
}|�d�Wd�n1s?wY|�
dd��
}|�d	�Wd�n1sZwYWd�n1siwY|�|��dd
�d�t�|��}|�|�
d�d�|�|�
d�d	�Wd�n1s�wYWd�n1s�wYqdS)NcSr�rrr�rrrr�
r�z1UnseekableTests.test_open_write.<locals>.<lambda>r�r�r=r�r�r�r�rLr�)rvr�r�rrr5r�rCrDr�r4rXr\rY)r7r�rr�r�r�rrr�test_open_write
s.

���������zUnseekableTests.test_open_writeN)r�r�r�r�r�r�rrrrr��	sr�c@sheZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestsWithMultipleOpenscCs dtd�|_dtd�|_dS)Nr��'r�)r�data1r`r-rrrr/
sz!TestsWithMultipleOpens.setUpClasscCsRt�|dtj��}|�d|j�|�d|j�Wd�dS1s"wYdS)Nr=r�r�)rCrDrrEr�r`)r7rrGrrrrI
s"�z(TestsWithMultipleOpens.make_test_archivecCs�t|�D]k}|�|�tj|dd��U}|�d��3}|�d��}|�d�}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||�|�||j�Wd�n1sjwYqdS)NrJrAr���)rrIrCrDr4rYrXr��r7rr��zopen1�zopen2r�r`rrr�test_same_file%
s 


�����z%TestsWithMultipleOpens.test_same_filecCs�t|�D]l}|�|�tj|dd��V}|�d��3}|�d��}|�d�}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||j�|�||j�Wd�n1skwYqdS)NrJrAr�r�r��	rrIrCrDr4rYrXr�r`r�rrr�test_different_file3
s 


�����z*TestsWithMultipleOpens.test_different_filecCs�t|�D]l}|�|�tj|dd��V}|�d��3}|�d�}|�d��}|�d�}||��7}||��7}Wd�n1s?wYWd�n1sNwY|�||j�|�||j�Wd�n1skwYqdS)NrJrAr�r�r�r�)r7rr�r�r�r�r`rrr�test_interleavedA
s"


������z'TestsWithMultipleOpens.test_interleavedc
Cs�t|�D]e}|�|�t���D}t�|d��}|�|�d��}|�|�d��}Wd�n1s1wY|�d�}|�d�}||��7}||��7}Wd�n1sVwY|�	||j
�|�	||j�qdS)NrJr�r�r�)rrI�
contextlib�	ExitStackrCrD�
enter_contextr4rYrXr�r`)r7r�stackr�r�r�r�r`rrr�test_read_after_closeP
s

�

��z,TestsWithMultipleOpens.test_read_after_closec
Cst|�D]{}t�|dtj��0}|�d|j�|�d|j�|�d��
}|�d�}Wd�n1s2wYWd�n1sAwY|�	||jdd��t�|d��}|�d�}|�d�}Wd�n1slwY|�	||j�|�	||j�qdS)Nr=r�r�r�rJ)
rrCrDrrEr�r`r4rYrX�r7rr�r�r�r`rrr�test_read_after_write^
s"���
��z,TestsWithMultipleOpens.test_read_after_writec
Cs�t|�D]p}t�|dtj��0}|�d|j�|�d��}|�d�|�d|j�Wd�n1s2wYWd�n1sAwYt�|d��}|�d�}|�d�}Wd�n1sawY|�	||j�|�	||j�qdS)Nr=r�r�r�rJ)
rrCrDrrEr�r4rYr`rXr�rrr�test_write_after_readl
s 
���
��z,TestsWithMultipleOpens.test_write_after_readc
Cs�|�t�tjtdd��)}td�D]}|�d�|�d��}Wd�n1s(wYqWd�n1s8wYttjd��}|�	|�
�d�Wd�dS1sWwYdS)NrJrAr�r�r�)rIrrCrDr(rYr4r�devnullZ
assertLess�fileno)r7r�r	r�rrrr�test_many_opensy
s

����"�z&TestsWithMultipleOpens.test_many_opensc
Cs:t�tdtj��}|�d|j�Wd�n1swYt�tdtj��E}|�dd��/}|�d�}|�dd��}|�|j	�Wd�n1sKwY||��7}Wd�n1s`wYWd�n1sowY|�
||j�t�t��}|�
|�d�|j	�Wd�dS1s�wYdS)Nr=r�r�rJr�r�)rCrDrrrEr�r4rYr5r`rX)r7r�Zr1r�r@rrr�test_write_while_reading�
s"�
����"�z/TestsWithMultipleOpens.test_write_while_readingcCrurrvr�rrrr��
rwzTestsWithMultipleOpens.tearDownN)r�r�r�r�r/rIr�r�r�r�r�r�r�r�r�rrrrr�
s


r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TestWithDirectorycCst�t�dSr)rr�rr�rrrr9�
r~zTestWithDirectory.setUpc
Cs�t�td���
}|�t�Wd�n1swY|�tj�tj�	td���|�tj�tj�	tdd���|�tj�
tj�	tddd���dS)N�
zipdir.zipr�rLrm)rCrDrr�rrarr��isdirr+rr!rrr�test_extract_dir�
s�$z"TestWithDirectory.test_extract_dircCs t�tj�td��|��dS�Nr�)rr�r�r+rr�r�rrr�
test_bug_6050�
szTestWithDirectory.test_bug_6050c	Cs�tj�td�}t�|�t�|�jd@}t�t	d��C}|�
|�|jd}|�|j
�d��|�|j|d>dB�|�
|d�|jd}|�|j
d	�|�|j|d>dB�Wd�n1s`wYt�t	d
��c}|jd}|�|j
�d��|�|j|d>dB�|jd}|�|j
d	�|�|j|d>dB�tj�td�}t�|�|�|�|�tj�tj�|d���|�tt�|��d�Wd�dS1s�wYdS)
Nr	r.r=rz/x/r�yrPzy/rJr�r�)rr�r+rr�r�st_moderCrDr
r5rrarVr�rXr�r�r�r^�listdir)r7�dirpathrBr�r�r�rrr�test_write_dir�
s4



�	



"�z TestWithDirectory.test_write_dirc	Cs t�tj�td��t�td��!}|�dd�|j	d}|�
|jd�|�
|jd�Wd�n1s4wYt�td��G}|j	d}|�
|j�d��|�
|jd�tj�td�}t�|�|�|�|�
tj�tj�|d���|�
t�|�dg�Wd�dS1s�wYdS)	Nr	r=zx/r'ri�ArJr�)rr�r�r+rrCrDr
rErrXrVr�rar�r�r�r�)r7r�r�r�rrr�test_writestr_dir�
s"
�


"�z#TestWithDirectory.test_writestr_dircCs$tt�tj�t�rtt�dSdSr)rrrr�rr
rr�rrrr��
s�zTestWithDirectory.tearDownN)	r�r�r�r9r�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)rCr��	from_filer�rX�	posixpathr�rVr�is_dirrgrr�r/r9rrr�test_from_file�
szZipInfoTests.test_from_filecCsNtj�t�t��}|�t�|j	�d�|�
|���|�|jt
j�t��dSr�)rCr�r�r�r�r�rXr�r�rVrr�rgrr�r/r9rrr�test_from_file_pathlike�
sz$ZipInfoTests.test_from_file_pathlikecCsPtj�t�t�d�}|�t�|j	�d�|�
|���|�|jtj
�t��dS)Nr)rCr�r�r�fsencoder�rXr�r�rVrr�rgr�r/r9rrr�test_from_file_bytes�
sz!ZipInfoTests.test_from_file_bytescCszttd��.}tj�|��d�}|�t�|j	�d�|�
|���|�|jt
j�t��Wd�dS1s6wYdS)Nr�r)r4r�rCr�r�r�rXr�r�rVrr�rgrr�r/)r7rr: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)rr�r��abspathr�rCr�r�rXrVrar�r�r�rg)r7r�r:rrr�
test_from_dir�
szZipInfoTests.test_from_dirN)r�r�r�r�r�r�r�r�rrrrr��
sr�c@sJeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�dd��Z	d
d�Z
dS)�CommandLineTestcOs2tjddg|�Ri|��\}}}|�tj��d�S)N�-mrCr")rrrar�linesepr�)r7�argsrF�rc�out�errrrr�
zipfilecmd�
s�zCommandLineTest.zipfilecmdcGstjddg|�R�S)Nr�rC)rZassert_python_failure)r7r�rrr�zipfilecmd_failurer�z"CommandLineTest.zipfilecmd_failurecCs||��\}}}|�|d�|�d|���|�d|���|�d|���|�dd�\}}}|�|d�|�|��d�dS)Nr'susageserrorsrequired�-lr-)r�rXr_rWZassertNotEqual�strip)r7r�r�r�rrr�test_bad_useszCommandLineTest.test_bad_usecCsXtd�}dD]}|�||�}|�|��d�qtd�}|�d|�\}}}|�|d�dS)Nr�)�-tz--testsDone testingztesttar.tarr�r')rr�rX�rstripr�)r7�zip_name�optr�r�r�rrr�test_test_commandsz!CommandLineTest.test_test_commandcCs�td�}t��}t�|d��
}|�|�Wd�n1swY|���dd�}dD]}|j||dd�}|�	||�q-dS)Nr�rJr!�backslashreplace)r�z--listzascii:backslashreplace)ZPYTHONIOENCODING)
rrrZrCrDr[r\r�r�rX)r7r�r�ZtfZexpectedr�r�rrr�test_list_commands���z!CommandLineTest.test_list_commandc	Cs`|�tt�ttddd��
}|�d�Wd�n1swYt�t�|�tt�ttj	�
td�ddd��
}|�d�Wd�n1sIwYttg}ttdtdg}d	D]P}zI|j|tg|�R�}|�
|d
�t�t��&}|�
|��|�|�
|�|d�d�|�
|�|d
�d�Wd�n1s�wYWtt�q]tt�wdS)Nr=r�r�ztest 1�file.txtztest 2r�z	/file.txt)�-cz--creater'rstest 1r�stest 2)r�rr
r4r5rr��	TESTFNDIRrr�r+r�rrXrCrDrerY)r7r�filesrer�r�rgrrr�test_create_command"s.�
����z#CommandLineTest.test_create_commandc	Cstd�}dD]�}t��u}|�|||�}|�|d�t�|��S}|��D]F}tj�	||j
�dtj��}|�
�r@|�tj�|��q#|�tj�|��t|d��}|�|��|�|��Wd�n1sdwYq#Wd�n1stwYWd�n1s�wYqdS)Nr�)z-ez	--extractr'r�r�)rrr�rXrCrDrfrr�r+rVrar�r�rar�r�r4rY)	r7r�r�r�r�rgr:r�rrrr�test_extract_command8s.���������z$CommandLineTest.test_extract_commandN)r�r�r�r�r�r�r�r�r	r�r�rrrrr��
s
	
r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
jd
�e�	e�
dej�d�d
d���Ze�	e
jd
�e�	e�
dej�d�dd���ZdS)�TestExecutablePrependedZipz@Test our ability to open zip files with an executable prepended.cCs tddd�|_tddd�|_dS)NZexe_with_zipZziptestdata)r�Zexe_with_z64)r�exe_zip�	exe_zip64r�rrrr9Msz TestExecutablePrependedZip.setUpcCsl|�t�|�d|���t�|��}|��D]
}|�|�}|�d|�qWd�dS1s/wYdS)Nzis_zipfile failed on sFAVORITE_NUMBER)rarCrXrDrerYr_)r7r�rGrzr,rrr�_test_zip_worksQs�
�"�z*TestExecutablePrependedZip._test_zip_workscC�|�|j�dSr)r�r�r�rrr� test_read_zip_with_exe_prepended[�z;TestExecutablePrependedZip.test_read_zip_with_exe_prependedcCr�r)r�r�r�rrr�"test_read_zip64_with_exe_prepended^r�z=TestExecutablePrependedZip.test_read_zip64_with_exe_prependedzsys.executable required.z	/bin/bashz#Test relies on #!/bin/bash working.cC�"t�|jtjg�}|�d|�dS�Nsnumber in executable: 5)�
subprocess�check_outputr��sys�
executabler_�r7�outputrrr�test_execute_zip2a�z,TestExecutablePrependedZip.test_execute_zip2cCr�r�)r�r�r�r�r�r_r�rrr�test_execute_zip64hr�z-TestExecutablePrependedZip.test_execute_zip64N)r�r�r�rmr9r�r�r�r�Z
skipUnlessr�r�rr��X_OKr�r�rrrrr�Js 
��r�c@�eZdZGdd�d�ZdS)�jaracoc@r�)zjaraco.itertoolsc@r)zjaraco.itertools.CountercCsd|_t|�|_dSrw)r��iter�
_orig_iter)r7r%rrrryxsz!jaraco.itertools.Counter.__init__cCr�rrr�rrr�__iter__|sz!jaraco.itertools.Counter.__iter__cCst|j�}|jd7_|Sr�)�nextr�r�)r7�resultrrr�__next__s
z!jaraco.itertools.Counter.__next__N)r�r�r�ryr�r�rrrr�Counterwsr�N)r�r�r�r�rrrrriv�riN)r�r�r�rirrrrr�ur�r�cCs&tj�|���D]}|�|d�q|S)z}
    Given a writable zip file zf, inject directory entries for
    any directories implied by the presence of children.
    r')rC�CompleteDirs�
_implied_dirsrerE)rgr�rrr�add_dirs�sr�cCsZt��}t�|d�}|�dd�|�dd�|�dd�|�dd	�|�d
d�d|_|S)
u:
    Create a zip file with this structure:

    .
    ├── a.txt
    ├── b
    │   ├── c.txt
    │   ├── d
    │   │   └── e.txt
    │   └── f.txt
    └── g
        └── h
            └── i.txt

    This fixture has the following key characteristics:

    - a file at the root (a)
    - a file two levels deep (b/d/e)
    - multiple files in a directory (b/c, b/f)
    - a directory containing only a directory (g/h)

    "alpha" because it uses alphabet
    "rep" because it's a representative example
    r=r��content of azb/c.txtscontent of cz	b/d/e.txtscontent of ezb/f.txtscontent of fz	g/h/i.txtscontent of i�alpharep.zip)rrrCrDrErV)r,rgrrr�build_alpharep_fixture�srcst����fdd��}|S)zZ
    Given a method, wrap it in a for loop that invokes method
    with each subtest.
    cs|��D]}�||d�qdS)N)�alpharep)�zipfile_alpharep)r7r��methrrr��s�zpass_alpharep.<locals>.wrapper)�	functools�wraps)rr�rrr�
pass_alpharep�src@s�eZdZdd�Zdd�Zdd�Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zedd��Zdd�Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��Zed1d2��Zed3d4��Zd5Zd6d7�Zd8d9�Z d:d;�Z!ed<d=��Z"ed>d?��Z#ed@dA��Z$edBdC��Z%edDdE��Z&edFdG��Z'edHdI��Z(edJdK��Z)dLdM�Z*dNdO�Z+dPdQ�Z,dRS)S�TestPathcCst��|_|�|jj�dSr)r�r��fixturesr�r�r�rrrr9�s
zTestPath.setUpccsl�|���t�VWd�n1swY|���tt��VWd�dS1s/wYdSr)r�rr�r�rrrr�s�

�
"�zTestPath.zipfile_alpharepcCsjt�|j�t���}|j}|��||j}|�d��}|�	|�
��Wd�|S1s.wY|Sr1)r�r�r	r�rr8r�rVr4r5r\)r7rZtmpdirrr��strmrrr�zipfile_ondisk�s

��zTestPath.zipfile_ondiskcCs�t�|�}|��sJ�|��\}}}|��sJ�|��sJ�|��s$J�|��\}}}|��r3|��s5J�|��\}	|	��s@J�|��\}
|
��\}|��sPJ�dSr)rCr�r��iterdir�is_file)r7r�rootr�rL�grmrrrY�hr%rrr�test_iterdir_and_types�s



zTestPath.test_iterdir_and_typescCs t�|�}|�d���rJ�dS)Nzmissing.txt)rCr��joinpathr
�r7rrrrr�test_is_file_missing�s
zTestPath.test_is_file_missingcCsPt�|�}|��\}}}|�t��
|��Wd�dS1s!wYdSr)rCr�rr�r��r7rrr�rLrrrr�test_iterdir_on_file�s


"�zTestPath.test_iterdir_on_filecCsNt�|�}|d��s
J�|d��sJ�|d��sJ�|d��s%J�dS)NrL�b/rzg/)rCr�r�rrrr�test_subdir_is_dir�s

zTestPath.test_subdir_is_dircCs�t�|�}|��\}}}|jdd��}|��}Wd�n1s!wY|�|d�|�dd��}|��}Wd�n1sAwY|�|d�dS)Nr�r��content of arJ)rCr�rr4rYrX)r7rrr�rLrr
r,rrrr��s

�
�zTestPath.test_opencCs�t��}t�|d�}|�dd�d��d|_t�|�}|��\}|�	d�}|�
dd��}|��}Wd�n1s:wY|�|d�|j
dd��}|��}Wd�n1sZwY|�|d�dS)	Nr=zpath/16.txtzThis was utf-16zutf-16ztest_open_utf16.zipz16.txtrJr�)
rrrCrDrEr�rVr�rrr4rYrX)r7�in_memory_filergrr��u16r
r,rrr�test_open_encoding_utf16s



�
�z!TestPath.test_open_encoding_utf16c	CsPt��}t�|d�}|�dd�d|_t�|�}|��\}|�d�}|j	ddd�}|�
|d	�|jd
ddd��}|�
|��d�Wd�n1sJwY|�
td
��|j	ddd�}Wd�n1sgwY|jd
ddd��*}|�t��|��Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr=zpath/bad-utf8.binsinvalid utf-8: ��.z"test_read_text_encoding_errors.zipzbad-utf8.binr��ignore)�errorszinvalid utf-8: .rJ�surrogateescapeuinvalid utf-8: ��.r�r��strict)r�r)rrrCrDrErVr�rr�	read_textrXr4rYr[r1r��UnicodeDecodeError)r7rrgrr�rr,rrrr�test_open_encoding_errorss,


��
��"�z"TestPath.test_open_encoding_errorscCsTd}tddd|�}|j��}|�t|�d|j�|�|dd�|�|dd	�d
S)z8EncodingWarning must blame the read_text and open calls.aimport io, zipfile
with zipfile.ZipFile(io.BytesIO(), "w") as zf:
    zf.filename = '<test_encoding_warnings in memory zip file>'
    zf.writestr("path/file.txt", b"Spanish Inquisition")
    root = zipfile.Path(zf)
    (path,) = root.iterdir()
    file_path = path.joinpath("file.txt")
    unused = file_path.read_text()  # should warn
    file_path.open("r").close()  # should warn
z-X�warn_default_encodingr�r�rs^<string>:8: EncodingWarning:rPs^<string>:9: EncodingWarning:N)rr�r]rXr^ZassertRegex)r7�code�proc�warningsrrr�test_encoding_warnings,s
zTestPath.test_encoding_warningscCs�t�tjt��dd��}|�d��d��
}|�d�Wd�n1s$wY|�d�jddd	��}|�d
�Wd�dS1sDwYdS)zo
        If the zipfile is open for write, it should be possible to
        write bytes or text to it.
        r=rAzfile.binr2sbinary contentsNr�r�r�z	text file)rCr�rDrrrr4r5)r7rgr
rrrr�?s�"�zTestPath.test_open_writecC�Nt�tt���}|�t��|�d���Wd�dS1s wYdS)zJ
        Attempting to open a directory raises IsADirectoryError.
        rLN)rCr�r�rr��IsADirectoryErrorrr4rrrr�test_open_extant_directoryJ�"�z#TestPath.test_open_extant_directorycCs�t�|�}|�t��|�d�jddd�Wd�n1swY|�t��|�d��dd�Wd�dS1s>wYdS)Nr�r�r�r�)rCr�r�r�rr4rrrr�test_open_binary_invalid_argsRs
�"�z&TestPath.test_open_binary_invalid_argscCr))zR
        Attempting to open a missing directory raises FileNotFoundError.
        �zN)rCr�r�rr��FileNotFoundErrorrr4rrrr�test_open_missing_directoryZr,z$TestPath.test_open_missing_directorycCsJt�|�}|��\}}}|jdd�dksJ�|�d�|��dks#J�dS)Nr�r�rr�)rCr�rr!�
read_bytesrrrrrqbs


zTestPath.test_readcCsNt�|�}|�d�}|��sJ�|�d��d��d�}|jdd�dks%J�dS�Nr�rLr�e.txtr�r��content of e)rCr�rr
r!�r7rrr�rYrrr�
test_joinpathjs


zTestPath.test_joinpathcCs0t�|�}|�ddd�}|jdd�dksJ�dS)NrLrr3r�r�r4)rCr�rr!)r7rrrYrrr�test_joinpath_multiplers
zTestPath.test_joinpath_multiplecCsFt�|�}|d}|��sJ�|ddd}|jdd�dks!J�dSr2)rCr�r
r!r5rrr�test_traverse_truedivxs

zTestPath.test_traverse_truedivcCstddddd�}t|�dS)zI
        Disable the __future__.division when testing traversal.
        zzipfile.Path(alpharep) / 'a'z(test)�evalT)�sourcerVrB�dont_inheritN)�compiler9)r7rr%rrr�test_traverse_simplediv�s�z TestPath.test_traverse_simpledivcCs&|�|�}t�t|��}t�|�dS)zN
        zipfile.Path should be constructable from a path-like object
        N)rr�r�rdrC)r7rrZpathlikerrr�test_pathlike_construction�s
z#TestPath.test_pathlike_constructioncCst�|�}|t�d�dSr�)rCr�r�rrrr�test_traverse_pathlike�s
zTestPath.test_traverse_pathlikecCs:t�|�}|djjdksJ�|ddjjdksJ�dS)Nr�r-rLza/�rCr��parentZatrrrr�test_parent�s
zTestPath.test_parentcCs6t�|�}|djjdksJ�|djjdksJ�dS)NrLr-rr@rrrr�test_dir_parent�s
zTestPath.test_dir_parentcCs"t�|�}|djjdksJ�dS)Nzmissing dir/r-r@rrrr�test_missing_dir_parent��
z TestPath.test_missing_dir_parentcCs�t�|�}|��\}}}|�dd�|�dd�tdd�|��D��s%J�|djdd�dks1J�|d	��\}|jdd�dksBJ�d
S)zk
        If the underlying zipfile is changed, the Path object should
        reflect that change.
        rr�zbar/baz.txtr?css�|]}|jdkVqdS)rN)r�)r$�childrrrr!�s�z+TestPath.test_mutability.<locals>.<genexpr>r�r�r�N)rCr�rrE�anyr!)r7rrr�rLrr?rrr�test_mutability�s
zTestPath.test_mutabilityi cCs@t��}t�|d�}ttt|j��D]}|�||�qd|_	|S)zACreate a read-only zipfile with a huge number of entries entries.r=rJ)
rrrCrD�maprdr(�HUGE_ZIPFILE_NUM_ENTRIESrErB)r7r
rg�entryrrr�huge_zipfile�szTestPath.huge_zipfilecCsFt�|���}tj�|���}|D]}|�d�q|j|j	ks!J�dS)zE
        Ensure joinpath on items in zipfile is linear time.
        �suffixN)
rCr�rLr�rir�rrr�rJ)r7r�entriesrKrrr�test_joinpath_constant_time�s
z$TestPath.test_joinpath_constant_timecCs"dd�td�D�}tj�|�dS)NcSs g|]}d�tjt|���qS)r�)r+�stringZascii_lowercaserd)r$rzrrrr&�s z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>r�)r(rCr�r�r�rrr�test_implied_dirs_performance�sz&TestPath.test_implied_dirs_performancecCs\|�|�}t�|��}td�D]}t�|d�jdd�qWd�dS1s'wYdS)Nr�r�r�r�)rrCrDr(r�r!)r7rrKZreprrr�test_read_does_not_close�s
�"�z!TestPath.test_read_does_not_closecCs0Gdd�dtj�}||�}t|d|�sJ�dS)Nc@seZdZdS)z(TestPath.test_subclass.<locals>.SubclassN)r�r�r�rrrr�Subclass�srSrL)rCr�r�)r7rrSrrrr�
test_subclass�szTestPath.test_subclasscCs"t�|�}|jt�d�ksJ�dS)Nr�)rCr�rVr�rrrr�
test_filename�rEzTestPath.test_filenamecCs0t�|�}|jdkr|jjksJ�J�dS)zH
        The name of the root should be the name of the zipfile
        r�N)rCr�r�rVrrrr�test_root_name�s
&zTestPath.test_root_namecCs>t�|�}|jt�d�ksJ�d|j_|jt�d�ksJ�dS)N�.zfoo/bar.zipr�)rCr�rAr�rrVrrrr�test_root_parent�s
zTestPath.test_root_parentcCs�d|_t�|�}|�t��|jWd�n1swY|�t��|jWd�n1s3wY|d}|jdksCJ�|jsHJ�dS)zd
        It is an error to attempt to get the name
        or parent of an unnamed zipfile.
        NrL)rVrCr�r�r1r�rA)r7rr�subrrr�test_root_unnamed�s
��zTestPath.test_root_unnamedcCs@tdtjfi�}|��D]}||��d�j}t||�sJ�qdS)NZ	PathChildzsome dir)�typerCr�rrrAr�)r7rr.rKrrr�test_inheritance
s
�zTestPath.test_inheritancecCs.|�|�}t�|�}t�|�|�|j�dS)zU
        A zip file wrapped in a Path should extract even with implied dirs.
        N)rrCrDr�r�rA)r7r�source_pathrgrrr�#test_extract_orig_with_implied_dirs
s


z,TestPath.test_extract_orig_with_implied_dirscCs�t��}t�|d�}|�dd�|�dd�|�dd�d|_t�|�}ttt	|�
���dgks2J�|�d��d	���dks@J�d
S)z�
        Path should handle malformed paths gracefully.

        Paths with leading slashes are not visible.

        Paths with dots are treated like regular files.
        r=z/one-slash.txtrxz//two-slash.txtz
../parent.txtr-z../z..z
parent.txtN)
rrrCrDrErVr��listrIrdrrr1)r7r,rgrrrr�test_malformed_paths
s
 zTestPath.test_malformed_pathscCs�t��}t�|d�}|�dd�|�dd�d|_t�|�}|��}t|�j	dks+J�t|�}|j	dks9J|j	��|�
d���dksDJ�dS)z�
        Path segments with special characters are readable.

        On some platforms or file systems, characters like
        ``:`` and ``?`` are not allowed, but they are valid
        in the zip file.
        r=zpath?rxzV: NMS.flacsfLaC...r-N)rrrCrDrErVr�rr�r�rr1)r7r,rgr�contents�itemrrr�test_unsupported_names/
s
zTestPath.test_unsupported_namescCsft��}t�|d�}|�t�d|�d�d|_t�|�}|�	�\}|�
�r'J�|jdks1J|j��dS)z@
        In a zip file, backslashes are not separators.
        r=zfoo\barrxr-N)rrrCrDrE�DirtyZipInfo�for_namerVr�rr�r�)r7r,rgr�firstrrr�test_backslash_not_separatorC
s

z%TestPath.test_backslash_not_separatorN)-r�r�r�r9rrrrrrrr�rr#r(r�r+r-r0rqr6r7r8r=r>r?rBrCrDrHrJrLrOrQrRrTrUrVrXrZr\r^r`rcrgrrrrr�s�	

















	








rcs,eZdZdZ�fdd�Zedd��Z�ZS)rdz#
    Bypass name sanitization.
    cs$t�j|g|�Ri|��||_dSr)r�ryrV)r7rVr�rFr�rrryV
s
zDirtyZipInfo.__init__cCs\||t�t���dd�d�}|j|_|j|_|j�d�r)d|_|jdO_|Sd|_|S)zy
        Construct the same way that ZipFile.writestr does.

        TODO: extract this functionality and re-use
        N�)rVrr�i�Arr�)	rbr
r;r�r<Zcompress_levelrVr�r�)r.r��archiver7rrrreZ
s�zDirtyZipInfo.for_name)r�r�r�rmryr�rer�rrr�rrdQ
s
rdc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�StripExtraTestsrPcCs�t�d�}|�|jd�}|�dd�}|�dd�}|�dt�||jf��|�|t�||jf��|�|dt�|d|jf��|�||t�||||jf��|�||t�||||jf��|�||t�||||jf��dS)Nr@rr�r(r'�z�rZStructrI�ZIP64_EXTRArXrC�_strip_extra�r7r�r�rLrmrrr�test_no_datas
s
�$$(zStripExtraTests.test_no_datacCs�t�d�}|�|jd�d}|�dd�d}|�dd�d}|�dt�||jf��|�|t�||jf��|�|d	t�|d	|jf��|�||t�||||jf��|�||t�||||jf��|�||t�||||jf��dS)
Nr@rPrIr��bbr(scccr'rkrlrorrr�test_with_data�
s
�$$(zStripExtraTests.test_with_datacCst�d�}|�|jd�d}|�dd�d}|�dt�|||jf��|�dt�||||jf��|�dt�||d|jf��|�|dt�|||d|jf��|�|t�||||jf��|�|t�||||jf��|�|t�||||jf��dS)Nr@rPrIr�rqr'rkrl)r7r�r�rLrrr�test_multiples�
s
 � �  $zStripExtraTests.test_multiplescCsd|�dt�d|jf��|�dt�d|jf��|�dt�d|jf��|�dt�d|jf��dS)Nr'rkszzszzz)rXrCrnrmr�rrr�test_too_short�
s��zStripExtraTests.test_too_shortN)r�r�r�rmrprrrsrtrrrrrjl
srj�__main__)_r|r��importlib.utilr�rrirr�r�rPrr�r�Ztest.support.script_helperrrbr�Z
unittest.mockrJrCrZtempfilerrrrZtest.supportrrr	r
rrZtest.support.os_helperr
rrrrrr�r)Z
DATAFILES_DIRr�rr ZTestCaser�rrrr r5rorqrrrtr�r�r�r�r�r�r�rSrZr[r]r^r_rnrrrsrtrurvr�r�r�r�r�r�r��tupleZconsumer�r�rrrr�rdrjr��mainrrrr�<module>s
	�C����R���"BAVg[����
7}A#P'
$
>�