
    <eN                    Z	   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ d dlZd dlZd dlmZ d dlZd dlZd dlmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZm Z m!Z!m"Z" d dl#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) e$dz   Z*e$d	z   Z+d
Z,dZ-g dZ.d Z/ G d d          Z0 G d de0ej1                  Z2 e             G d de0ej1                              Z3 e             G d de0ej1                              Z4 e             G d de0ej1                              Z5 G d d          Z6 G d de6ej1                  Z7 e             G d de6ej1                              Z8 e             G d de6ej1                              Z9 e             G d  d!e6ej1                              Z: G d" d#          Z; G d$ d%e;ej1                  Z< e             G d& d'e;ej1                              Z= e             G d( d)e;ej1                              Z> e             G d* d+e;ej1                              Z? G d, d-ej1                  Z@ G d. d/ej1                  ZA G d0 d1ej1                  ZB G d2 d3          ZC G d4 d5eCej1                  ZD e             G d6 d7eCej1                              ZE e             G d8 d9eCej1                              ZF e             G d: d;eCej1                              ZG G d< d=ej1                  ZH G d> d?          ZI G d@ dAeIej1                  ZJ e             G dB dCeIej1                              ZK e             G dD dEeIej1                              ZL e             G dF dGeIej1                              ZM G dH dI          ZN G dJ dK          ZO G dL dMej1                  ZP e             G dN dOej1                              ZQ G dP dQej1                  ZR G dR dSej1                  ZS G dT dUej1                  ZT G dV dWej1                  ZUeVZW G dX dY          ZXdZ ZYd[ ZZd\ Z[ G d] d^ej1                  Z\ G d_ d`ej1                  Z] G da dbej1                  Z^e_dck    r ej`                     dS dS )d    N)assert_python_ok)TemporaryFile)randintrandom	randbytes)script_helper)findfilerequires_zlibrequires_bz2requires_lzmacaptured_stdoutcaptured_stderrrequires_subprocess)TESTFNunlinkrmtreetemp_dirtemp_cwdfd_count2d  zipfile_datafiles))	_ziptest1
1q2w3e4r5t)zziptest2dir/_ziptest2
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3
6y7u8i9o0pc              #   8  K   t           V  t                      5 }|V  |                     |j                   d d d            n# 1 swxY w Y   t	          j                    5 }|V  |                     |j                   d d d            d S # 1 swxY w Y   d S N)TESTFN2r   assertFalseclosedioBytesIO)testfs     (/usr/lib/python3.11/test/test_zipfile.py	get_filesr)   ,   s     
MMM	 #A"""# # # # # # # # # # # # # # # 
 #"""# # # # # # # # # # # # # # # # # #s#   AA	A	#BBBc                       e Zd Zed             Zd Zd"dZd"dZd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#dS )#AbstractTestsWithSourceFilec                     d t          t                    D             | _        d                    | j                  | _        d S )Nc                 P    g | ]#}t          d |t                      fz  d          $S )z'Zipfile test line %d. random float: %f
ascii)bytesr   .0is     r(   
<listcomp>z:AbstractTestsWithSourceFile.setUpClass.<locals>.<listcomp>8   sH     8 8 8 H &((m,-46 6 8 8 8    r4   )rangeFIXEDTEST_SIZEline_genjoindataclss    r(   
setUpClassz&AbstractTestsWithSourceFile.setUpClass6   sE    8 8!&~!6!68 8 8 88CL))r4   c                     t          t          d          5 }|                    | j                   d d d            d S # 1 swxY w Y   d S Nwbopenr   writer9   selffps     r(   setUpz!AbstractTestsWithSourceFile.setUp=       &$ 	 2HHTY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	    >AANc                    ||d}t          j        |dfi |5 }|                    t          d           |                    t          t                     |                    d| j                   |                    dd          5 }| j        D ]}|                    |           	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N)compressioncompresslevelwanother.namestrfilewritten-open-wmode)zipfileZipFilerB   r   writestrr9   rA   r7   )rD   r'   rJ   rK   kwargszipfplines          r(   make_test_archivez-AbstractTestsWithSourceFile.make_test_archiveB   sX   !,}MM_Q..v.. 	"%KK///KK'''NN9di000,377 "1 M " "DGGDMMMM"" " " " " " " " " " " " " " "		" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s6   A.C B4(C4B8	8C;B8	<CCCc           	      ~   |                      |||           t          j        |d|          5 }|                     |                    t
                    | j                   |                     |                    d          | j                   |                     |                    d          | j                   t          j                    }|	                    |           |
                                }|                                }|                     t          |          d           |                     d|d                    |                     d|d                    |                     d	|d                    |d
                                         \  }}	}
}|                     |d           |                     t!          j        |	d                     |                     t!          j        |
d                     |                     |t%          t          | j                                       |                                }|                     t          |          d           |                     t
          |           |                     d|           |                     d|           |                     d|           |                                }d |D             }|                     t          |          d           |                     t
          |           |                     d|           |                     d|           |                     d|           |D ]/}|                     |j        t          | j                             0t
          dddfD ]_}|                    |          }|                     |j        |           |                     |j        t          | j                             `|                                 d d d            d S # 1 swxY w Y   d S )NrrM   rN   )file   	File Namer   ModifiedSize   %Y-%m-%d%H:%M:%S   rO   c                     g | ]	}|j         
S  filenamer0   s     r(   r3   z8AbstractTestsWithSourceFile.zip_test.<locals>.<listcomp>q       ///AQZ///r4   )rX   rR   rS   assertEqualreadr   r9   r$   StringIOprintdirgetvalue
splitlineslenassertInsplit
assertTruetimestrptimestrnamelistinfolist	file_sizegetinforg   testzip)rD   r'   rJ   rK   rV   rE   	directorylinesfndatetime_sizenamesinfosr2   nminfos                    r(   zip_testz$AbstractTestsWithSourceFile.zip_testM   s   q+}=== _Q[11 0	UUZZ//;;;UZZ77CCCUZZ	22DI>>> BNNN###I((**ESZZ+++MM+uQx000MM*eAh///MM&%(+++$)!HNN$4$4!BeTR000OODM$
;;<<<OODM%<<===T3s49~~#6#6777 NN$$ESZZ+++MM&%(((MM.%000MM)U+++MM*E222 NN$$E/////ESZZ+++MM&%(((MM.%000MM)U+++MM*E222 > >  c$)nn==== ~y:JK A A}}R((  333  TY@@@@ MMOOOa0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	 0	s   O7P22P69P6c                 `    t          |           D ]}|                     || j                   d S r    r)   r   rJ   rD   r'   s     r(   
test_basicz&AbstractTestsWithSourceFile.test_basic   ;    4 	/ 	/AMM!T-....	/ 	/r4   c                    |                      ||           t          j        |d|          5 }g }|                    t                    5 }	 |                    d          }|sn|                    |           .	 d d d            n# 1 swxY w Y   g }|                    d          5 }	 |                    d          }|sn|                    |           .	 d d d            n# 1 swxY w Y   |                     d                    |          | j	                   |                     d                    |          | j	                   d d d            d S # 1 swxY w Y   d S NrZ   T   rM   r4   )
rX   rR   rS   rA   r   rj   appendri   r8   r9   )	rD   r'   rJ   rV   zipdata1zipopen1	read_datazipdata2zipopen2s	            r(   zip_open_testz)AbstractTestsWithSourceFile.zip_open_test   s'   q+... _Q[11 	<UHF## /x/ (c 2 2I$ OOI...	/ 	/ / / / / / / / / / / / / / / HN++ /x/ (c 2 2I$ OOI...	/ 	/ / / / / / / / / / / / / / / SXXh//;;;SXXh//;;;%	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sZ   E
0B;EB	EB	E)0C&E&C*	*E-C*	.AEE!Ec                 `    t          |           D ]}|                     || j                   d S r    r)   r   rJ   r   s     r(   	test_openz%AbstractTestsWithSourceFile.test_open   =    4 	4 	4Aq$"23333	4 	4r4   c                    t          j        t                    }|                     || j                   t          j        |d| j                  5 }|                     |j        t                     d d d            d S # 1 swxY w Y   d S NrZ   )
pathlibPathr!   r   rJ   rR   rS   assertIsInstancerg   ru   )rD   pathrV   s      r(   test_open_with_pathlikez3AbstractTestsWithSourceFile.test_open_with_pathlike   s    |G$$4!1222_T3(899 	7U!!%.#666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   !A>>BBc                    |                      ||           t          j        |d|          5 }g }|                    t                    5 }	 |                    t          dd                    }|sn|                    |           <	 d d d            n# 1 swxY w Y   |                     d	                    |          | j
                   d d d            d S # 1 swxY w Y   d S NrZ   Tr`      r4   )rX   rR   rS   rA   r   rj   r   r   ri   r8   r9   )rD   r'   rJ   rV   r   r   r   s          r(   zip_random_open_testz0AbstractTestsWithSourceFile.zip_random_open_test   se   q+... _Q[11 		<UHF## /x/ (ga.>.> ? ?I$ OOI...	/ 	/ / / / / / / / / / / / / / / SXXh//;;;		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		< 		<s5   C
>B	CB	CB	1CC"Cc                 `    t          |           D ]}|                     || j                   d S r    r)   r   rJ   r   s     r(   test_random_openz,AbstractTestsWithSourceFile.test_random_open   =    4 	; 	;A%%a)9::::	; 	;r4   c                    |                      ||           t          j        |d          5 }|                    t                    5 }g }	 |                    d          }|sn|                    |           .	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     d                    |          | j	                   d S )NrZ   Tr4   )
rX   rR   rS   rA   r   read1r   ri   r8   r9   rD   r'   rJ   rV   zipopenzipdatar   s          r(   zip_read1_testz*AbstractTestsWithSourceFile.zip_read1_test   sQ   q+... _Q$$ 	*ZZ	*#*G*#MM"--	  y)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	'**DI66666s5   B2B:BB
	
BB
	BB!$B!c                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   
test_read1z&AbstractTestsWithSourceFile.test_read1   s=    4 	5 	5A4#34444	5 	5r4   c                    |                      ||           t          j        |d          5 }|                    t                    5 }g }	 |                    d          }|                     t          |          d           |sn|                    |           Q	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 	                    d
                    |          | j                   d S )NrZ   T
   r4   )rX   rR   rS   rA   r   r   assertLessEqualro   r   ri   r8   r9   r   s          r(   zip_read1_10_testz-AbstractTestsWithSourceFile.zip_read1_10_test   sm   q+... _Q$$ 	*ZZ	*#*G*#MM"--	$$S^^R888  y)))* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	'**DI66666s6   C AB)C )B-	-C 0B-	1C  CCc                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   test_read1_10z)AbstractTestsWithSourceFile.test_read1_10   =    4 	8 	8A""1d&67777	8 	8r4   c                    |                      ||           t          j        |d          5 }|                    t                    5 }d}	 |                                }|sn#||z  }|                    d          }|sn||z  }:d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     || j                   d S )NrZ   r4   Td   )	rX   rR   rS   rA   r   readlinerj   ri   r9   )rD   r'   rJ   rV   r   r9   rj   s          r(   zip_readline_read_testz2AbstractTestsWithSourceFile.zip_readline_read_test   s\   q+... _Q$$ 	ZZ	#*D	'')) ||C(( 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	ty)))))s5   B(>BB(B	B(B	B((B,/B,c                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   test_readline_readz.AbstractTestsWithSourceFile.test_readline_read   s=    4 	= 	=A''4+;<<<<	= 	=r4   c                 \   |                      ||           t          j        |d          5 }|                    t                    5 }| j        D ],}|                                }|                     ||           -	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r   )rX   rR   rS   rA   r   r7   r   ri   )rD   r'   rJ   rV   r   rW   linedatas          r(   zip_readline_testz-AbstractTestsWithSourceFile.zip_readline_test   s1   q+... _Q$$ 	5F## 5w M 5 5D&//11H$$Xt444455 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s5   B!5B	=B!	B	B!B	B!!B%(B%c                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   test_readlinez)AbstractTestsWithSourceFile.test_readline  r   r4   c                 ~   |                      ||           t          j        |d          5 }|                    t                    5 }|                                }d d d            n# 1 swxY w Y   t          | j        |          D ]\  }}|                     ||           	 d d d            d S # 1 swxY w Y   d S r   )	rX   rR   rS   rA   r   	readlineszipr7   ri   )rD   r'   rJ   rV   r   ziplinesrW   ziplines           r(   zip_readlines_testz.AbstractTestsWithSourceFile.zip_readlines_test
  s?   q+... _Q$$ 	0F## /w",,../ / / / / / / / / / / / / / /!$T]H!=!= 0 0g  $////0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s5   B2A(B2(A,	,B2/A,	04B22B69B6c                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   test_readlinesz*AbstractTestsWithSourceFile.test_readlines  =    4 	9 	9A##At'78888	9 	9r4   c                 V   |                      ||           t          j        |d          5 }|                    t                    5 }t          | j        |          D ]\  }}|                     ||           	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r   )rX   rR   rS   rA   r   r   r7   ri   )rD   r'   rJ   rV   r   rW   r   s          r(   zip_iterlines_testz.AbstractTestsWithSourceFile.zip_iterlines_test  s.   q+... _Q$$ 	4F## 4w%(%@%@ 4 4MD'$$Wd333344 4 4 4 4 4 4 4 4 4 4 4 4 4 4	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s5   B2B:BB
	
BB
	BB"%B"c                 `    t          |           D ]}|                     || j                   d S r    )r)   r   rJ   r   s     r(   test_iterlinesz*AbstractTestsWithSourceFile.test_iterlines!  r   r4   c                    t          j        t          d| j                  5 }|                    dd           ddd           n# 1 swxY w Y   t          j        t          d| j                  5 }|                    d          5 }|                     |                    d          d           |                     |                    d          d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	z>Check for cases where compressed data is larger than original.rL   rN   12NrZ   r`      1   2)rR   rS   r!   rJ   rT   rA   ri   rj   )rD   rV   openobjs      r(   test_low_compressionz0AbstractTestsWithSourceFile.test_low_compression%  s    _Wc4+;<< 	,NN9d+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, _Wc4+;<< 	8I&& 8'  a$777  a$7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8sH   AAA/C<AC$C<$C(	(C<+C(	,C<<D D c                     t          j        t          d          }|                    dd| j                   |                    d          }|                     |j        | j                   d S )NrL   b.txthello worldcompress_type)rR   rS   r!   rT   rJ   ry   ri   r   )rD   rV   r   s      r(   test_writestr_compressionz5AbstractTestsWithSourceFile.test_writestr_compression1  sa    --wT=MNNN}}W%%+T-=>>>>>r4   c                    t          j        t          dd          }|                    dd| j                   |                    dd| j        d	           |                    d          }|                     |j        | j                   |                     |j        d           |                    d          }|                     |j        | j                   |                     |j        d           d S )
NrL   r`   rK   a.txtr   r   r      )r   rK   )	rR   rS   r!   rT   rJ   ry   ri   r   _compresslevel)rD   rV   a_infob_infos       r(   test_writestr_compresslevelz7AbstractTestsWithSourceFile.test_writestr_compresslevel7  s    A>>>wT=MNNNwT=M%& 	 	( 	( 	( w''-t/?@@@.222 w''-t/?@@@.22222r4   c                    dD ]}|dz   }t          |          }t          j        t          j                    d| j                  5 }|                    d|           |                    dd          5 }|                    |          }| 	                    t          |          |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N)r`   i  i   i  i @  r`   rL   foorZ   )r   rR   rS   r$   r%   rJ   rT   rA   rj   ri   ro   )rD   	test_sizerx   junkzipfrE   bufs          r(   test_read_return_sizez1AbstractTestsWithSourceFile.test_read_return_sizeG  sJ    6 	: 	:I!AIY''DsD4DEE :eT***YYuc** :b''),,C$$SXXy999: : : : : : : : : : : : : : :: : : : : : : : : : : : : : :	: 	:s6   -C29B7+C7B;;C>B;?CC	C	c                 <   t          j                    }t          j        |d          5 }|                    d| j        | j                   |                                }d d d            n# 1 swxY w Y   |                                }t          j        |          }t          j        |          5 }|	                    d          5 }|
                    |dz
             |                     t                    5  |                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |          }t          j        |          5 }|	                    d          5 }|
                    |dz
             |                     t                    5  |                    d          r	 |                    d          d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |          }t          j        |          5 }|	                    d          5 }|
                    |dz
             |                     t                    5  |                    d          r	 |                    d          d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   rP   rN   r      r   )r$   r%   rR   rS   rT   r9   rJ   tellrm   rA   truncateassertRaisesEOFErrorrj   r   )rD   rE   r   
end_offsetzipfiledatar   s         r(   test_truncated_zipfilez2AbstractTestsWithSourceFile.test_truncated_zipfileS  s#   Z\\_Rc*** 	#dMM)TYd>NMOOOJ	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# kkmmZ$$_R   	#D9%% #JO,,,&&x00 # #LLNNN# # # # # # # # # # # # # # ## # # # # # # # # # # # # # #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# Z$$_R   	D9%% JO,,,&&x00  !,,s++  ",,s++                             	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Z$$_R   	D9%% JO,,,&&x00  !--,,  "--,,                             	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s  7A--A14A14E
3D5=DD5D""D5%D"&D5)E5D9	9E<D9	=EEE?H.3H,H 4H HHHHH.H	H.H	H..H25H2!L73K9*,K"K9"K&&K9)K&*K9-L9K=	=L K=	LLLc                 T   d}t          |           D ]}t          j        |d| j                  5 }|                    t
          |           t          |          }|                     d|           d d d            n# 1 swxY w Y   t          j        |d          5 }t          |          }t          |t                    r|                     d|z  |           n|                     d|z  |           |                     d|           t          |
                    |                    }|                     d|z  |           |                     d|           |                     d	|           | j        t          j        k    r,|                     d
|           |                     d|           |                    |          5 }t          |          }|                     d|z  |           |                     d|           | j        t          j        k    r|                     d
|           d d d            n# 1 swxY w Y   |                     dt          |                     d d d            n# 1 swxY w Y   |                     dt          |                     d S )Nz	file.namerL   zmode='w'rZ   zfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])r)   rR   rS   rJ   rB   r   reprrp   
isinstanceru   ry   
ZIP_STOREDrA   )rD   fnamer'   rV   rZ   r   s         r(   	test_reprz%AbstractTestsWithSourceFile.test_reprq  s   4 	3 	3AC)9:: -eFE***KKj!,,,- - - - - - - - - - - - - - -
 C(( 9EKKa%% 4MM-!"3Q7777MM)a-333j!,,,u--..me3Q777k1---lA...#w'999MM"2A666MM"2A666ZZ&& ;'WAMM)e"3Q777MM*a000'7+===&6:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; j$w--888)9 9 9 9 9 9 9 9 9 9 9 9 9 9 9* MM*d5kk22227	3 	3sJ   AA==B	B	D+I8A*H>2I8>II8I&I88I<	?I<	c                 d    t          |           D ]}|                     || j        d            d S )N	   r   r   r   s     r(   test_compresslevel_basicz4AbstractTestsWithSourceFile.test_compresslevel_basic  sC    4 	@ 	@AMM!T-QM????	@ 	@r4   c                    t          j        t          dd          5 }|                    t          d           |                    t          dd           |                    d          }|                    d          }|                     |j        d           |                     |j        d           ddd           dS # 1 swxY w Y   dS )zTCheck that files within a Zip archive can have different
        compression levels.rL   r`   r   
compress_1
compress_9r   N)rR   rS   r!   rB   r   ry   ri   r   )rD   rV   one_info	nine_infos       r(   test_per_file_compresslevelz7AbstractTestsWithSourceFile.test_per_file_compresslevel  s     _Wc;;; 	:uKK---KKAK>>>}}\22Hl33IX4a888Y5q999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   BCC
Cc                     G fddt           j                  }d	  |            }d t          j        |d| j                  5 }|                    dd          5 }|                    d           d d d            n# 1 swxY w Y   d	 |                    dd          5 }|                    d	           d d d            n# 1 swxY w Y   	 d d d d            n# t          $ r d
z  Y nw xY w	 d n# d w xY w	 d d d            n# 1 swxY w Y   t          j        t          j        |                                                    5 }| 	                    |
                                dg           | 	                    |                    d          d           d d d            n# 1 swxY w Y   t          j        t          j        |                                                    5 }| 	                    |
                                ddg           | 	                    |                    d          d           | 	                    |                    d          d	           d d d            d S # 1 swxY w Y   d S )Nc                   $     e Zd Z fdZ xZS )CAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilec                 r    k    rt           dz  t                                          |           d S Nr`   )OSErrorsuperrB   )rD   r9   	__class__countstops     r(   rB   zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write  s<    $}}%QJEd#####r4   )__name__
__module____qualname__rB   __classcell__)r
  r  r  s   @r(   
BrokenFiler    sC        $ $ $ $ $ $ $ $ $ $ $r4   r  r   TrL   file1s   data1file2s   data2r`   )r$   r%   rR   rS   rJ   rA   rB   r  rm   ri   rv   rj   )rD   r  testfilerV   r'   r  r  s        @@r(   test_writing_errorsz/AbstractTestsWithSourceFile.test_writing_errors  s   	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	@!z||HE30@AA !UZZ-- &GGH%%%& & & & & & & & & & & & & & &!GS11 *Q)))* * * * * * * * * * * * * * *
  E! ! ! ! ! ! !    AIDDD !EEDELLLLE! ! ! ! ! ! ! ! ! ! ! ! ! ! ! H,=,=,?,?!@!@AA @U  !1!1G9===  G!4!4h???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @!	@( _RZ(9(9(;(;<<== 	<U^^--/ABBBUZZ00(;;;UZZ00(;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   DB5DB	DB		DC!%C;C!C	C!C	C!D!C30C:2C33C:7D:C>>DDDAF00F47F45A=I??JJc                 V    t          t                     t          t                     d S r    r   r   r!   rD   s    r(   tearDownz$AbstractTestsWithSourceFile.tearDown      vwr4   r    )$r  r  r  classmethodr<   rF   rX   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  re   r4   r(   r+   r+   5   s       * * [*     
	" 	" 	" 	"4 4 4 4l/ / /< < <04 4 47 7 7< < <; ; ;7 7 75 5 57 7 7 8 8 8* * *(= = =
5 5 58 8 80 0 09 9 94 4 49 9 9
8 
8 
8? ? ?3 3 3 
: 
: 
:  <3 3 3>@ @ @	: 	: 	:"< "< "<J    r4   r+   c                   t    e Zd Zej        ZdZd Zd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd ZdS )StoredTestsWithSourceFileNc                 N   |                      ||           t          j        |d          5 }|                    d          }|                     |j        d           |                    d          }|                     |j        d           d d d            d S # 1 swxY w Y   d S )NrZ   rN     rO   )rX   rR   rS   ry   ri   external_attr)rD   r'   rJ   rV   zinfozinfo2s         r(   zip_test_writestr_permissionsz7StoredTestsWithSourceFile.zip_test_writestr_permissions  s    
 	q+..._Q$$ 	@MM),,EU0+>>>]]#344FV1;???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   A!BB!Bc                 j    t          |           D ]"}|                     |t          j                   #d S r    )r)   r#  rR   r   r   s     r(   test_writestr_permissionsz3StoredTestsWithSourceFile.test_writestr_permissions  sA    4 	F 	FA..q'2DEEEE	F 	Fr4   c                    t          j        t          dt           j                  5 }|                    t
          d           d d d            n# 1 swxY w Y   t          j        t          dt           j                  5 }|                     |                                dg           d d d            d S # 1 swxY w Y   d S )NrL   	/absoluterZ   absoluterR   rS   r!   r   rB   r   ri   rv   rD   rV   s     r(   test_absolute_arcnamesz0StoredTestsWithSourceFile.test_absolute_arcnames  s   _Wc7+=>> 	-%KK,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- _Wc7+=>> 	=%U^^--
|<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s#   AAA>*B55B9<B9c                    t          j        t          dt           j                  5 }|                    t
          t
                     ddd           n# 1 swxY w Y   t          j        t          dt           j                  5 }|                    d| j                   |                     |	                                t
          dg           ddd           dS # 1 swxY w Y   dS )z&Test appending to an existing zipfile.rL   NarN   )
rR   rS   r!   r   rB   r   rT   r9   ri   rv   r*  s     r(   test_append_to_zip_filez1StoredTestsWithSourceFile.test_append_to_zip_file  sG   _Wc7+=>> 	(%KK'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( _Wc7+=>> 	D%NN9di000U^^--	/BCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds$   !AAAACC"Cc                 d   d}t          t          d          5 }|                    |           ddd           n# 1 swxY w Y   t          j        t          dt          j                  5 }|                    t          t                     ddd           n# 1 swxY w Y   t          t          d          5 }|                    t          |                     t          j        |d          5 }| 	                    |
                                t          g           | 	                    |                    t                    | j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          t          d          5 }| 	                    |                    t          |                    |           |                                }ddd           n# 1 swxY w Y   t          j        |          5 }t          j        |          5 }| 	                    |
                                t          g           | 	                    |                    t                    | j                   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )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!r?   Nr-  rbrZ   )rA   r!   rB   rR   rS   r   r   seekro   ri   rv   rj   r9   r$   r%   )rD   r9   r'   rV   r   bios         r(   test_append_to_non_zip_filez5StoredTestsWithSourceFile.test_append_to_non_zip_file  s    )'4   	AGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 _Wc7+=>> 	(%KK'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( '4   	@AFF3t99C(( @E  !1!1F8<<<  F!3!3TY???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@
 '4   	#AQVVCII..555&&((K	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# Z$$ 	<W_S-A-A 	<UU^^--x888UZZ//;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   :>>*!BBB78E4/A"EE4E!	!E4$E!	%E44E8;E8AG++G/2G/
J%A"JJ%J	J%J	J%%J),J)c                    t          j                    5 }t          j        |dt          j                  5 }|                    t          t                     d d d            n# 1 swxY w Y   |                                }d d d            n# 1 swxY w Y   d}t          t          d          5 }|                    |           |                    |           d d d            n# 1 swxY w Y   t          j        t                    5 }| 
                    |                                t          g           | 
                    |                    t                    | j                   d d d            d S # 1 swxY w Y   d S )NrL   r0  r?   )r$   r%   rR   rS   r   rB   r   rm   rA   r!   ri   rv   rj   r9   rD   r3  rV   r   r9   r'   s         r(   test_read_concatenated_zip_filez9StoredTestsWithSourceFile.test_read_concatenated_zip_file  s-   Z\\ 	)Sc7+=>> ,%FF+++, , , , , , , , , , , , , , ,,,..K	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) )'4   	!AGGDMMMGGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! _W%% 	<U^^--x888UZZ//;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sY   !B!A"B"A&	&B)A&	*BBB/+C&&C*-C*
A"E99E= E=c                    t          j                    5 }t          j        |dt          j                  5 }|                    t          t                     d d d            n# 1 swxY w Y   |                                }d d d            n# 1 swxY w Y   ddz  }t          t          d          5 }|                    |           |                    |           d d d            n# 1 swxY w Y   t          j        t          d          5 }| 
                    |                                t          g           |                    d| j                   d d d            n# 1 swxY w Y   t          t          d          5 }| 
                    |                    t          |                    |           |                                }d d d            n# 1 swxY w Y   t          j        |          5 }t          j        |          5 }| 
                    |                                t          dg           | 
                    |                    t                    | j                   | 
                    |                    d          | j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   s   I am not a ZipFile!i@B r?   r-  rN   r1  )r$   r%   rR   rS   r   rB   r   rm   rA   r!   ri   rv   rT   r9   rj   ro   r6  s         r(   $test_append_to_concatenated_zip_filez>StoredTestsWithSourceFile.test_append_to_concatenated_zip_file  s   Z\\ 	)Sc7+=>> ,%FF+++, , , , , , , , , , , , , , ,,,..K	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) &g-'4   	!AGGDMMMGGK   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! _Wc** 	1eU^^--x888NN9di000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 '4   	#AQVVCII..555&&((K	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# Z$$ 	?W_S-A-A 	?UU^^--	/BCCCUZZ//;;;UZZ	22DI>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   !B!A"B"A&	&B)A&	*BBB2+C))C-0C-A
E$$E(+E(AGG"G:KBJ, K,J0	0K3J0	4KKKc                    t          j        t          dt           j                  5 }|                    t
          t
                     d d d            n# 1 swxY w Y   t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          j        t          d          5 }|                     |t           j                   d d d            d S # 1 swxY w Y   d S )NrL   r-  utf-8encodingz
   rZ   )rR   rS   r!   r   rB   r   rA   r   rD   rV   r'   s      r(   test_ignores_newline_at_endz5StoredTestsWithSourceFile.test_ignores_newline_at_end*  s   _Wc7+=>> 	(%KK'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	('3111 	%QGGO$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%_Wc** 	:e!!%999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s5   !AAA5BBB<!C**C.1C.c                 2   t          j        t          dt           j                  5 }d|_        |                    t          t                     d d d            n# 1 swxY w Y   t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          j        t          d          5 }|                     |t           j                   | 	                    |j        d           d d d            d S # 1 swxY w Y   d S )NrL      this is a commentr-  r;  r<  zabcdef
rZ   )
rR   rS   r!   r   commentrB   r   rA   r   ri   r>  s      r(   )test_ignores_stuff_appended_past_commentszCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_comments2  s   _Wc7+=>> 	(%0EMKK'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( '3111 	"QGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"_Wc** 	Be!!%999U],@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs5   (AA!A<BB"%B"<DDDc                 z   t          j        t          d          5 }|                    t                     t          t          d          5 }|                     |                    t                    |                                           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z`Check that calling ZipFile.write without arcname specified
        produces the expected result.rL   r1  N)rR   rS   r!   rB   r   rA   ri   rj   r>  s      r(   test_write_default_namez1StoredTestsWithSourceFile.test_write_default_name<  s    _Wc** 	?eKKfd## ?q  F!3!3QVVXX>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s6   0B0ABB0B	B0B	 B00B47B4c                    d}t          j        t          d          5 }|                    |d           d d d            n# 1 swxY w Y   t          j        t          d          5 }|                    |          5 }|                                 |                     t          |j                   |                     t          |j	        d           |                     t          |j
                   |                     t          |j                   |                     t          |j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nsomefile.txtrL   rP   bogusrZ   r   )rR   rS   r!   rT   rA   closer   
ValueErrorrj   r2  r   readableseekable)rD   r   rV   fids       r(   test_io_on_closed_zipextfilez6StoredTestsWithSourceFile.test_io_on_closed_zipextfileD  s   _W3/// 	+5NN5'***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ _W3/// 	<5E"" <c		!!*ch777!!*ch:::!!*ch777!!*cl;;;!!*cl;;;< < < < < < < < < < < < < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<sH   AAA'E=B6D?3E?E	EE	EEEc                 N   t          j        t          d          5 }|                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     t
          |j        t                     ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     t
                    5  |                    t          d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.rL   rP   rG  rH  NrZ   )	rR   rS   r!   rT   r   rJ  rB   r   rA   r*  s     r(   test_write_to_readonlyz0StoredTestsWithSourceFile.test_write_to_readonlyR  s    _W3/// 	45NN>7333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 _W3/// 	?5j%+v>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _W3/// 	-5"":.. - -

6
,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-sW   ?AA%'BBB>DD6DD	D	D	
DD!Dc                    t          j        t          d           t          j        t
          d          5 }|                     t          |j        t                     d d d            n# 1 swxY w Y   t          j        t
          dd          5 }|                    t                     |	                    t                    }| 
                    |j        d           d d d            d S # 1 swxY w Y   d S )N)r   r   rL   Fstrict_timestampsi  r`   r`   r   r   r   )osutimer   rR   rS   r!   r   rJ  rB   ry   ri   	date_time)rD   rV   r!  s      r(   test_add_file_before_1980z3StoredTestsWithSourceFile.test_add_file_before_1980_  s[   
   _Wc** 	?ej%+v>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _WcUCCC 	EuKKMM&))EU_.CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es$   'A((A,/A,AC,,C03C0c                 H   d}	 t          j        |           n)# t          $ r |                     d| d           Y nw xY w	 t	          j        t          ||f           n%# t          $ r |                     d           Y nw xY wt	          j        t                    j        }|dk    r|                     d|           t          j
        t          d          5 }|                     t          j        |j        t                     d d d            n# 1 swxY w Y   t          j
        t          dd	          5 }|                    t                     |                    t                    }|                     |j        d
           d d d            d S # 1 swxY w Y   d S )Nl   &
 ztime.localtime(z) raises OverflowErrorz/Host fs cannot set timestamp to required value.l     b f z,Linux VFS/XFS kernel bug detected: mtime_ns=rL   FrR  )i;           ;   r]  )rs   	localtimeOverflowErrorskipTestrU  rV  r   statst_mtime_nsrR   rS   r!   r   structerrorrB   ry   ri   rW  )rD   tsmtime_nsrV   r!  s        r(   test_add_file_after_2107z2StoredTestsWithSourceFile.test_add_file_after_2107j  sN   	HN2 	H 	H 	HMMFBFFFGGGGG	H	MHVb"X&&&& 	M 	M 	MMMKLLLLL	M 76??.*++ MMKKKLLL_Wc** 	AeflEK@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A _WcUCCC 	JuKKMM&))EU_.HIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	JsC    #??A   BB,DDD:AFFF)r  r  r  rR   r   rJ   r   r#  r%  r+  r.  r4  r7  r9  r?  rC  rE  rN  rP  rX  rg  re   r4   r(   r  r    s       $K@ @ @F F F= = =D D D< < <.< < <? ? ?,: : :B B B? ? ?< < <- - -	E 	E 	EJ J J J Jr4   r  c                   "    e Zd Zej        Zd ZdS )DeflateTestsWithSourceFilec                    t          j        t          d          5 }|                    t          dt           j                   |                    t          dt           j                   |                    d          }|                    d          }|                     |j	        t           j                   |                     |j	        t           j                   ddd           dS # 1 swxY w Y   dS )zUCheck that files within a Zip archive can have different
        compression options.rL   storeme	deflatemeN)
rR   rS   r!   rB   r   r   ZIP_DEFLATEDry   ri   r   )rD   rV   sinfodinfos       r(   test_per_file_compressionz4DeflateTestsWithSourceFile.test_per_file_compression  s    _Wc** 	HeKK	7+=>>>KKW-ABBBMM),,EMM+..EU0'2DEEEU0'2FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   CC))C-0C-N)r  r  r  rR   rm  rJ   rp  re   r4   r(   ri  ri    s2         &K	H 	H 	H 	H 	Hr4   ri  c                       e Zd Zej        ZdS )Bzip2TestsWithSourceFileNr  r  r  rR   	ZIP_BZIP2rJ   re   r4   r(   rr  rr             #KKKr4   rr  c                       e Zd Zej        ZdS )LzmaTestsWithSourceFileNr  r  r  rR   ZIP_LZMArJ   re   r4   r(   rw  rw             "KKKr4   rw  c                   H    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
dS )	AbstractTestZip64InSmallFilesc                 x    d t          dt                    D             }d                    |          | _        d S )Nc              3   <   K   | ]}t          d |z  d          V  dS )zTest of zipfile line %d.r.   N)r/   r0   s     r(   	<genexpr>z;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>  sF       7 7 4q8'BB 7 7 7 7 7 7r4   r      
)r5   r6   r8   r9   )r;   r7   s     r(   r<   z(AbstractTestZip64InSmallFiles.setUpClass  sA    7 7"1n557 7 7::h''r4   c                 
   t           j        | _        t           j        | _        dt           _        dt           _        t          t          d          5 }|                    | j                   d d d            d S # 1 swxY w Y   d S )Nr   r   r?   )	rR   ZIP64_LIMIT_limitZIP_FILECOUNT_LIMIT_filecount_limitrA   r   rB   r9   rC   s     r(   rF   z#AbstractTestZip64InSmallFiles.setUp  s    ) ' ;"&'# &$ 	 2HHTY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   A88A<?A<c           	       	   t          j        |d|d          5 }|                    t          d           |                    t          t                     |                    d| j                   d d d            n# 1 swxY w Y   t          j        |d|          5 }|                     |                    t                    | j                   |                     |                    d          | j                   |                     |                    d          | j                   t          j	                    }|
                    |           |                                }|                                }|                     t          |          d           |                     d|d	                    |                     d
|d	                    |                     d|d	                    |d                                         \  }}}	}
|                     |d           |                     t#          j        |d                     |                     t#          j        |	d                     |                     |
t'          t          | j                                       |                                }|                     t          |          d           |                     t          |           |                     d|           |                     d|           |                                }d |D             }|                     t          |          d           |                     t          |           |                     d|           |                     d|           |D ]/}|                     |j        t          | j                             0t          ddfD ]_}|                    |          }|                     |j        |           |                     |j        t          | j                             `|                                 d d d            d S # 1 swxY w Y   d S )NrL   T
allowZip64rM   rN   rZ   rc   r]   r   r^   r_   r`   ra   rb      c                     g | ]	}|j         
S re   rf   r0   s     r(   r3   z:AbstractTestZip64InSmallFiles.zip_test.<locals>.<listcomp>  rh   r4   )rR   rS   rB   r   rT   r9   ri   rj   r$   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rg   rz   )rD   r'   rJ   rV   rE   r{   r|   r}   r~   r   r   r   r   r2   r   r   s                   r(   r   z&AbstractTestZip64InSmallFiles.zip_test  sP   _Q[TBBB 	1eKK///KK'''NN9di000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 _Q[11 /	UUZZ//;;;UZZ77CCCUZZ	22DI>>> BNN2I((**ESZZ+++MM+uQx000MM*eAh///MM&%(+++$)!HNN$4$4!BeTR000OODM$
;;<<<OODM%<<===T3s49~~#6#6777 NN$$ESZZ+++MM&%(((MM.%000MM)U+++ NN$$E/////ESZZ+++MM&%(((MM.%000MM)U+++ > >  c$)nn==== ~y9 A A}}R((  333  TY@@@@ MMOOO_/	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	 /	s%   AA<<B B O	Q33Q7:Q7c                 `    t          |           D ]}|                     || j                   d S r    r   r   s     r(   r   z(AbstractTestZip64InSmallFiles.test_basic  r   r4   c                    t          j        t          d| j        d          }d|_        d}t          |          D ]$}|                    d|z  d|dz  d	z  z             %|                     t          |	                                          |           |
                                 t          j        t          d
| j                  }|                     t          |	                                          |           t          |          D ]L}|                    d|z                                d          }|                     |d|dz  d	z  z             M|
                                 d S )NrL   Tr  r      foo%08d%dr  9   rZ   r.   )rR   rS   r   rJ   debugr5   rT   ri   ro   rv   rI  rj   decode)rD   r   numfilesr2   zipf2contents         r(   test_too_many_filesz1AbstractTestZip64InSmallFiles.test_too_many_files  sO    vsD,<*.0 0 0
x 	= 	=AMM)a-A);<<<<T]]__--x888

T-=>>U^^--..999x 	: 	:AjjQ//66w??GWdadRi&89999r4   c                    t          j        t          d| j        d          }d|_        d}t          |          D ]$}|                    d|z  d|dz  d	z  z             %|                     t          |	                                          |           | 
                    t           j                  5  |                    d|z  d
           d d d            n# 1 swxY w Y   |                     t          |	                                          |           |                                 t          j        t          d| j        d          }d|_        |                     t          |	                                          |           | 
                    t           j                  5  |                    d|z  d
           d d d            n# 1 swxY w Y   |                     t          |	                                          |           |                                 t          j        t          d| j        d          }d|_        |                     t          |	                                          |           d}t          ||          D ]$}|                    d|z  d|dz  d	z  z             %|                     t          |	                                          |           |                                 t          j        t          d| j                  }|                     t          |	                                          |           t          |          D ]L}|                    d|z                                d          }|                     |d|dz  d	z  z             M|                                 d S )NrL   Fr  r   r   r  r  r  r  r4   r-  Tr  rZ   r.   )rR   rS   r   rJ   r  r5   rT   ri   ro   rv   r   LargeZipFilerI  rj   r  )rD   r   r  r2   	numfiles2r  r  s          r(   test_too_many_files_appendz8AbstractTestZip64InSmallFiles.test_too_many_files_append
  s   vsD,<*/1 1 1
x 	= 	=AMM)a-A);<<<<T]]__--x888w344 	5 	5MM)h.444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5T]]__--x888

vsD,<*/1 1 1
T]]__--x888w344 	5 	5MM)h.444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5T]]__--x888

vsD,<*.0 0 0
T]]__--x888	x++ 	= 	=AMM)a-A);<<<<T]]__--y999

T-=>>U^^--..	:::y!! 	: 	:AjjQ//66w??GWdadRi&89999s$   4CC!C+GGGc                     | j         t          _        | j        t          _        t          t                     t          t                     d S r    )r  rR   r  r  r  r   r   r!   r  s    r(   r  z&AbstractTestZip64InSmallFiles.tearDown1  s1    "k&*&;#vwr4   N)r  r  r  r  r<   rF   r   r   r  r  r  re   r4   r(   r|  r|    s         ( ( [(
     7 7 7r/ / /  &% % %N    r4   r|  c                   l    e Zd Zej        Zd Zd Zd Zd Z	d Z
	 	 	 ddZd Zd	 Zd
 Zd Zd Zd ZdS )StoredTestZip64InSmallFilesc                     t          j        |d|d          5 }|                     t           j        |j        t
          d           d d d            d S # 1 swxY w Y   d S NrL   Fr  rM   )rR   rS   r   r  rB   r   rD   r'   rJ   rV   s       r(   large_file_exception_testz5StoredTestZip64InSmallFiles.large_file_exception_test<  s    _Q[UCCC 	Cug2#k6>C C C	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C   -AAAc                     t          j        |d|d          5 }|                     t           j        |j        d| j                   d d d            d S # 1 swxY w Y   d S r  )rR   rS   r   r  rT   r9   r  s       r(   large_file_exception_test2z6StoredTestZip64InSmallFiles.large_file_exception_test2A  s    _Q[UCCC 	Iug2#nndiI I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Ir  c                     t          |           D ]B}|                     |t          j                   |                     |t          j                   Cd S r    )r)   r  rR   r   r  r   s     r(   test_large_file_exceptionz5StoredTestZip64InSmallFiles.test_large_file_exceptionF  sZ    4 	C 	CA**1g.@AAA++Aw/ABBBB	C 	Cr4   c                    t          j        t          dt           j        d          5 }|                    t
          d           d d d            n# 1 swxY w Y   t          j        t          dt           j                  5 }|                     |                                dg           d d d            d S # 1 swxY w Y   d S )NrL   Tr  r'  rZ   r(  r)  r*  s     r(   r+  z2StoredTestZip64InSmallFiles.test_absolute_arcnamesK  s(   _Wc7+=(,. . . 	-16KK,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- _Wc7+=>> 	=%U^^--
|<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s#   AAA *B77B;>B;c                    t          j        t          dd          5 }|                    d| j                   d d d            n# 1 swxY w Y   t          j        t          dd          5 }|                    d          }|j        }d d d            n# 1 swxY w Y   t          j        t          dd          5 }|                    d| j                   d d d            n# 1 swxY w Y   t          j        t          dd          5 }|                    d          }|                     |j        |           d d d            d S # 1 swxY w Y   d S )NrL   Tr  rN   rZ   r-  strfile2)rR   rS   r!   rT   r9   ry   extrari   )rD   rV   r!  r  s       r(   test_appendz'StoredTestZip64InSmallFiles.test_appendS  s&    _Wcd;;; 	1uNN9di000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1_Wcd;;; 	 uMM),,EKE	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  _Wcd;;; 	2uNN:ty111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2_Wcd;;; 	1uMM),,EU[%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1sG   AA	A	,BBB<C$$C(+C(1E		EEFc                    d}d}g }	g }
|}|r.d}|r*|	                     |           |
                     |           t          j        d|          }|}|r.d}|r*|	                     |           |
                     |           t          j        d|          }|}|rd}|r|
                     |           t          j        d|          }t          j        ddt          |	          z  z   ddt          |	          z  g|	R  }t          j        ddt          |
          z  z   ddt          |
          z  g|
R  }t          j        dd	dt          |
          z  z             }t          j        dd
dt          |	          z  z             }t          j        dddt          |	          z  z             }t          j        dddt          |
          z  z             }d}d}t          j        dt          |                    }d|z   |z   |z   |z   |z   |z   |z   dz   |z   |z   |z   |z   dz   |z   |z   |z   dz   dz   dz   |z   |z   dz   dz   dz   dz   }|S )zGenerate 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Qr`   z<Q:   2   z<Hrc   s   test.txt   test1234s   PK       ! %s   PK--       ! %s
           s   PK,       - -s                 s
            s   PK    l       s      s   PK      :   2 s       )r   rc  packro   )rD   file_size_64_setfile_size_extracompress_size_64_setcompress_size_extraheader_offset_64_setheader_offset_extraactual_sizeactual_header_offsetlocal_zip64_fieldscentral_zip64_fieldsrx   compress_sizeheader_offsetlocal_extracentral_extracentral_dir_sizeoffset_to_central_dirlocal_extra_lengthcentral_extra_lengthrg   r  filename_lengthzip64_contentss                           r(   make_zip64_filez+StoredTestZip64InSmallFiles.make_zip64_filea  sb     !	 	9"I 9"))+666$++K888Ki00	# 	9&M" 9"))+666$++K888D-88, 	B&M" B$++,@AAAD-88kC.////c$%%%
  	
 
 
 C01111c&'''
 "	
 
 
 ";tR!c:N6O6O2O-OPP &D"q3?Q;R;R7R2R S S#[q1s;M7N7N3N/NOO%{4Q=Q9R9R5R1RSS +dCMM:: L  !	!
    P	P 
   ## ::   !" #& ?'?( N)N* :+:, -. $/$2 M3M4 58 N9N: ";" 	B r4   c                 	   |                      d          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     dt          |j	                  
                                           |                      ddd          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     dt          |j	                  
                                           |                      d          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     dt          |j	                  
                                           |                      ddddd          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     d	t          |j	                  
                                           |                      d
ddd          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     d	t          |j	                  
                                           |                      ddd
d          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     d	t          |j	                  
                                           |                      d
d
d          }|                     t          j                  5 }t          j        t          j        |                     ddd           n# 1 swxY w Y   |                     d	t          |j	                  
                                           dS )a
  Missing zip64 extra records raises an exception.

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

        If the zip64 extra content doesn't contain enough entries for the
        number of fields marked with 0xFFFF or 0xFFFFFFFF, we raise an error.
        This test mismatches the length of the zip64 extra field and the number
        of fields set to indicate the presence of zip64 data.
        T)r  Nz	file size)r  r  r  zcompress size)r  )r  r  r  r  r  zheader offsetF)r  r  r  r  )r  r  r  r  )r  r  r  )r  r   rR   
BadZipFilerS   r$   r%   rp   ru   	exceptionlower)rD   missing_file_size_extraemissing_compress_size_extramissing_header_offset_extras        r(   test_bad_zip64_extraz0StoredTestZip64InSmallFiles.test_bad_zip64_extra  sR   $ #'"6"6! #7 #
 #
 w122 	AaOBJ'>??@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	Ak3q{#3#3#9#9#;#;<<< '+&:&:! !% '; '
 '
#
 w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@ '+&:&:!% '; '
 '
# w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@
 '+&:&:! !% $!% '; '
 '
# w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@ '+&:&:"!% $!%	 '; '
 '
# w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@ '+&:&:! !&!%	 '; '
 '
# w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@ '+&:&:"!&!% '; '
 '
#
 w122 	EaOBJ'BCCDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Eos1;'7'7'='='?'?@@@@@s}   'A))A-0A-%'DDD'GG	G	'I66I:=I:3'L&&L*-L*#'OOO'RR	R	c                    d}d}d}d}dddddddddf}t          dt          |          dz             D ]}t          j        ||          D ]}i }|D ]}	|                    |	           t          j        t          j         | j	        d	i |                    5 }
|

                                d         }|                     |j        |           |                     |j        |           |                     |j        |           |                     |
                    |          |           d d d            n# 1 swxY w Y   d S )
Nr  r   r  T)r  r  )r  r  )r  r  r`   re   )r5   ro   	itertoolscombinationsupdaterR   rS   r$   r%   r  rw   ri   rx   r  r  rj   )rD   expected_file_sizeexpected_compress_sizeexpected_header_offsetexpected_contentparamsrZ   comborU   czfr!  s               r(    test_generated_valid_zip64_extraz<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extra"  s   !"!"&
 "&$??%)$GG%)$GG
 q#f++/** 
	G 
	GA"/:: 	G 	G % %AMM!$$$$_RZ0D0D0N0Nv0N0N%O%OPP GTVKKMM!,E$$U_6HIII$$U%8:PQQQ$$U%8:PQQQ$$RWWU^^5EFFFG G G G G G G G G G G G G G G		G
	G 
	Gs   BD??EEc                 "   t          j                    }t          j        |dd          5 }|                    ddd          5 }|                    d           ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |                                }t          j        d|dd	                   \  }}}}}	}
}}}}}}}}}| 	                    |d
           | 
                    |t          j                   | 	                    |d           | 	                    |d           | 	                    |	d           | 	                    |
d           | 	                    |d           | 	                    |d           | 	                    |d           | 	                    |d           | 	                    |d           | 	                    |d           | 	                    |d           | 	                    |d           t          j        t          j        |                    }|                                }| 	                    t          |          d           | 
                    |d         j        t          j                   dS )zGTest that forcing zip64 extensions correctly notes this in the zip filerL   TrQ   r  text.txtrQ   force_zip64   _Nz<4sBBHH8xIIHH8shhQQx4s?      PKr   r  r  r   r`         PK)r$   r%   rR   rS   rA   rB   rm   rc  unpackri   assertGreaterEqualZIP64_VERSIONrw   ro   extract_version)rD   r9   r  zir   headerversrU  flagscompcsizeusizefn_lenex_total_lenrg   ex_idex_lenex_usizeex_csizecd_sigzzinfoss                         r(   test_force_zip64z,StoredTestZip64InSmallFiles.test_force_zip64=  s   * z||_T=== 	#4@@ B              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 --// M2GCRCLAA	
D"eT5%(E68Xv 	///g&;<<<Q"""q!!!
+++
+++###r***"""$$$1%%%1%%%///OBJw//00Va(((q	 97;PQQQQQs5   A=A&A=&A*	*A=-A*	.A==BBc                     d }|                      t          |t          j                               |                      t          |t	          t          j                                         dS )zjTest that creating a zip with/without seeking will raise a RuntimeError if zip64 was required but not usedc                    t          j        | dd          5 }|                    ddd          5 }|                    dt           j        dz   z             d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	NrL   Tr  r  Fr  r  r`   )rR   rS   rA   rB   r  )rE   r  r  s      r(   make_zipzRStoredTestZip64InSmallFiles.test_unseekable_zip_unknown_filesize.<locals>.make_zipv  s   #$??? ?2WWZcuWEE ?HHTW%81%<=>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?s4   A;&A#A;#A'	'A;*A'	+A;;A?A?N)r   RuntimeErrorr$   r%   
UnseekablerD   r  s     r(   $test_unseekable_zip_unknown_filesizez@StoredTestZip64InSmallFiles.test_unseekable_zip_unknown_filesizes  s]    	? 	? 	?
 	,"*,,???,*RZ\\2J2JKKKKKr4   c                     d }|                      t          j        |t          j                               |                      t          j        |t          t          j                                         dS )z^Test that trying to add a large file to a zip that doesn't allow zip64 extensions fails on addc                     t          j        | dd          5 }t          j        d          }t           j        dz   |_        |                    |d           d d d            d S # 1 swxY w Y   d S )NrL   Fr  r  r`   rP   )rR   rS   ZipInfor  rx   rA   )rE   r  r   s      r(   r  zRStoredTestZip64InSmallFiles.test_zip64_required_not_allowed_fail.<locals>.make_zip  s    #%@@@ (Bz22!(!4q!83'''	( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   A A%%A),A)N)r   rR   r  r$   r%   r  r  s     r(   $test_zip64_required_not_allowed_failz@StoredTestZip64InSmallFiles.test_zip64_required_not_allowed_fail~  sc    	( 	( 	( 	'."*,,GGG'.*RZ\\:R:RSSSSSr4   c                    t           j        dz   fd} |t          j                                                              }t          j        d                              |ddz                      \  }}}}}}}	}
}}}}}}}|                     |d           | 	                    |t           j
                   |                     |d           |                     |d           |                     |d           |                     |d           |                     |	d           |                     |
d	           |                     |d
           |                     |d           |                     |d           |                     |           |                     |           |                     |d            |t          t          j                                        j                                        }t          j        d                              |ddz                      \  }}}}}}}	}
}}}}}}}}}}|                     |d           | 	                    |t           j
                   |                     |d           |                     d                    |          d           |                     |d           |                     |d           |                     |	d           |                     |
d	           |                     |d
           |                     |d           |                     |d           |                     |d           |                     |d           |                     |d           |                     |           |                     |           |                     |d           dS )zhTest that creating a zip without seeking will use zip64 extensions if the file size is provided up-frontr`   c                 ,   t          j        | dd          5 }t          j        d          }|_        |                    |dd          5 }|                    dz             d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | S )NrL   Tr  r  Fr  r  )rR   rS   r	  rx   rA   rB   )rE   r  r   r  rx   s       r(   r  zPStoredTestZip64InSmallFiles.test_unseekable_zip_known_filesize.<locals>.make_zip  s
   #$??? /2z22!*WWTW?? /2HHTI-.../ / / / / / / / / / / / / / /	/ / / / / / / / / / / / / / / Is5   4B	A2&B	2A6	6B	9A6	:B		BBz<4sBBHH8xIIHH8shhQQ{}x4sN>   r  r   r  r  r   r  r  z<4sBBHH8xIIHH8shhQQ{}x4s4xQQ4sV   z{:b}1000s   PK)rR   r  r$   r%   rm   rc  r  formatri   r  r  r  rE   )rD   r  seekable_datar  r  rU  r  r  r  r  r  r  rg   r  r  r  r  r  unseekable_data	dd_headerdd_usizedd_csizerx   s                         @r(   "test_unseekable_zip_known_filesizez>StoredTestZip64InSmallFiles.test_unseekable_zip_known_filesize  s     '!+		 	 	 	 	 !..7799
 M4;;IFFVeWY\eWeVeHfgg		
D"eT5%(E68X 	///g&;<<<Q"""q!!!
+++
+++###r***"""$$$9---9---/// #(:bjll#;#;<<?HHJJ
 M:AA)LLo^m_adm_m^mNnoo		
D"eT5%(E68Xx6 	///g&;<<<Qu--v666q!!!
+++
+++###r***"""$$$1%%%1%%%L1119---9---/////r4   N)FFFFFF)r  r  r  rR   r   rJ   r  r  r  r+  r  r  r  r  r  r  r
  r  re   r4   r(   r  r  8  s       $KC C C
I I I
C C C
= = =1 1 1 7<8=8=a a a aF\A \A \A|G G G64R 4R 4Rl	L 	L 	L
T 
T 
TJ0 J0 J0 J0 J0r4   r  c                       e Zd Zej        ZdS )DeflateTestZip64InSmallFilesNr  r  r  rR   rm  rJ   re   r4   r(   r  r             &KKKr4   r  c                       e Zd Zej        ZdS )Bzip2TestZip64InSmallFilesNrs  re   r4   r(   r  r    ru  r4   r  c                       e Zd Zej        ZdS )LzmaTestZip64InSmallFilesNrx  re   r4   r(   r  r    rz  r4   r  c                   &    e Zd Zd Zd Zd Zd ZdS )AbstractWriterTestsc                 .    t          t                     d S r    r   r!   r  s    r(   r  zAbstractWriterTests.tearDown      wr4   c                    d}t          j        t          d| j                  5 }|                    dd          }|                    |           |                                 |                     |j                   |                                 |                     |j                   | 	                    |
                    d          |           d d d            d S # 1 swxY w Y   d S )N   contentrL   r&   )rR   rS   r!   rJ   rA   rB   rI  rr   r#   ri   rj   rD   r9   r   rL   s       r(   test_close_after_closez*AbstractWriterTests.test_close_after_close  s   _Wc4+;<< 	6		&#&&AGGDMMMGGIIIOOAH%%%GGIIIOOAH%%%TYYv..555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   B1C!!C%(C%c                    d}t          j        t          d| j                  5 }|                    dd          }|                    |           |                                 |                     |j                   | 	                    t          |j        d           |                     |                    d          |           d d d            d S # 1 swxY w Y   d S )Nr%  rL   r&   r4   )rR   rS   r!   rJ   rA   rB   rI  rr   r#   r   rJ  ri   rj   r&  s       r(   test_write_after_closez*AbstractWriterTests.test_write_after_close  s    _Wc4+;<< 	6		&#&&AGGDMMMGGIIIOOAH%%%j!'3777TYYv..555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   B$CCCc                    t          j         dg d          }t          |          |j        z  }t          j        t          j                    d| j                  5 }|                    dd          5 }| 	                    |
                    |          |           d d d            n# 1 swxY w Y   | 	                    |                    d          j        |           d d d            d S # 1 swxY w Y   d S )Nr  )r`   r   r  rc   r\   rL   r9   )arrayro   itemsizerR   rS   r$   r%   rJ   rA   ri   rB   ry   rx   )rD   qLENGTHr   r9   s        r(   test_issue44439z#AbstractWriterTests.test_issue44439  se   K___--Q!*$_RZ\\30@AA 	DS&#&& 8$  A7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8S[[00:FCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds6   C.2*B(C.(B,	,C./B,	01C..C25C2N)r  r  r  r  r'  r)  r/  re   r4   r(   r   r     sU          	6 	6 	66 6 6D D D D Dr4   r   c                       e Zd Zej        ZdS )StoredWriterTestsNr  r  r  rR   r   rJ   re   r4   r(   r1  r1  	  s        $KKKr4   r1  c                       e Zd Zej        ZdS )DeflateWriterTestsNr  re   r4   r(   r4  r4    s        &KKKr4   r4  c                       e Zd Zej        ZdS )Bzip2WriterTestsNrs  re   r4   r(   r6  r6    s        #KKKr4   r6  c                       e Zd Zej        ZdS )LzmaWriterTestsNrx  re   r4   r(   r8  r8    s        "KKKr4   r8  c                   P    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd ZdS )PyZipFileTestsc                 J    |dz   |vr|                      |dz   |           d S d S )Nor  )rp   )rD   namerv   s      r(   assertCompiledInzPyZipFileTests.assertCompiledIn  s7    #:X%%MM$*h///// &%r4   c                    t          j        |t           j        t           j        t           j        v           s|                     d           t           j                            |d          }	 t          j        |t           j        t           j	        z            }t          j
        |           n%# t          $ r |                     d           Y nw xY wt          |           d S )N)effective_idsz/requires write access to the installed locationztest_zipfile.try)rU  accessW_OKsupports_effective_idsr`  r   r8   rA   O_WRONLYO_CREATrI  	Exceptionr   )rD   r   rg   fds       r(   requiresWriteAccessz"PyZipFileTests.requiresWriteAccess  s    yrw')yB4M'MO O O 	MMMKLLL7<<&899	M2;#;<<BHRLLLL 	M 	M 	MMMKLLLLL	Mxs   .A B/ /CCc                 x   |                      t          j                            t                               t                      5 }t          j        |d          5 }t          }|                    d          r|	                    t          j
                  }t          j        2|                    |	                    t          j                             d|v r t          j                            |          }n
|d d         }|                    |           t          j                            |          }|                     ||                                           |                     ||                                           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t                      5 }t          j        |d          5 }t          }|                    d          r
|d d         }|                    |d           ddt          j                            |          }|                     ||                                           |                     ||                                           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   .pyc__pycache__r   testpackage/)rH  rU  r   dirname__file__r   rR   	PyZipFileendswithrq   sepaltsepextend	importlibutilsource_from_cachewritepybasenameassertNotInrv   r>  )rD   trV   r}   
path_splitbns         r(   test_write_pyfilez PyZipFileTests.test_write_pyfile+  s<     !:!:;;;__ 	87#4Q#<#< 	8B{{6"" !XXbf--
9(%%bhhry&9&9::: J.."99"==BBCRCBMM"!!"%%BR!1!1222!!"enn&6&6777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8" __ 		87#4Q#<#< 		8B{{6"" WMM"m,,,)MM27+;+;B+?+?+?@BR!1!1222!!"enn&6&6777		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8 		8sn   F+D,FF+F	F+F	F++F/2F/J/B1JJ/J	J/J	J//J36J3c                    dd l }t          j                            |j                  }|                     |           t                      5 }t          j        |d          5 }|	                    |           |
                                }|                     d|           |                     d|           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   rL   zemail/__init__.pyzemail/mime/text.py)emailrU  r   rN  rO  rH  r   rR   rP  rX  rv   r>  )rD   r`  
packagedirr[  rV   r   s         r(   test_write_python_packagez(PyZipFileTests.test_write_python_packageI  sT   W__U^44
  ,,,__ 	?7#4Q#<#< 	?MM*%%% NN$$E!!"5u===!!"6>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s7   C"AC8CC	CC	CC #C c           	      "   dd l }t          j                            |j                  }|                     |           t                      5 }t          j        |d          5 }t                      5 }|
                    |           d d d            n# 1 swxY w Y   |                                }|                     d|v            t                      5 }|
                    |d            d d d            n# 1 swxY w Y   |                                }|                     d|v           d }t                      5 }|                     t                    5  |
                    ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                }|rt          |           |                     d|v           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   rL   SyntaxErrorc                     dS )NFre   )whatevers    r(   <lambda>zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>g  s    e r4   
filterfuncc                 h    t           j                            |                               d           S )Nbad)rU  r   rY  
startswith)r   s    r(   filterzAPyZipFileTests.test_write_filtered_python_package.<locals>.filterl  s)    7++D11<<UCCCCr4   )r&   rU  r   rN  rO  rH  r   rR   rP  r   rX  rm   rr   assertWarnsUserWarningprint)rD   r&   ra  r[  rV   	reportSIO	reportStrrm  s           r(   "test_write_filtered_python_packagez1PyZipFileTests.test_write_filtered_python_packageW  s{   W__T]33
  ,,,__ 	<7#4Q#<#< 	< !"" *ij)))* * * * * * * * * * * * * * *!**,,IOOMY6777 !"" Mij5K5KLLLM M M M M M M M M M M M M M M!**,,IOOM:;;;D D D "" =i1A1A+1N1N = =jV<<<= = = = = = = = = = = = = = = = = = = = = = = = = = = = = =!**,,I !i   OOM:;;;/	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   H"G,1BG,BG,B<G,C<0G,<D  G,D ?G,FF	6FFF	F
FG,FG, F!?G, H,G0	0H3G0	4HHHc                    dd l }t          j                            |j                  }|                     |           d}d}t                      5 }t          j        |d|          5 }|	                    |           |
                                }|                     d|z   |           |                     d|z   |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	Nr   Fr`   rJ  rL   )optimizezemail/__init__zemail/mime/text)r`  rU  r   rN  rO  rH  r   rR   rP  rX  rv   rp   )rD   r`  ra  optlevelextr[  rV   r   s           r(   test_write_with_optimizationz+PyZipFileTests.test_write_with_optimizationu  si   W__U^44
  ,,,'(__ 	:q#999	:=BMM*%%%NN$$EMM*S0%888MM+c15999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s7   C((ACC(C	C(C	C((C,/C,c                 f   t          j        t                     	 t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          t           j                            t          d          dd          5 }|                    d	           d d d            n# 1 swxY w Y   t                      5 }t          j	        |d          5 }|
                    t                     |                                }|                     d|           |                     d|           |                     d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          t                     d S # t          t                     w xY w)
Nmod1.pyrL   r;  r<  
print(42)
mod2.pyprint(42 * 42)
zmod2.txtzbla bla bla
rU  mkdirr!   rA   r   r8   rB   r   rR   rP  rX  rv   r>  rZ  r   rD   rE   r[  rV   r   s        r(   test_write_python_directoryz*PyZipFileTests.test_write_python_directory  s    
	bgll7I66gNNN (RT'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( bgll7I66gNNN -RT+,,,- - - - - - - - - - - - - - - bgll7J77wOOO *SU)))* * * * * * * * * * * * * * *  4Aw'8C'@'@ 4Eg&&&((%%i777%%i777  U3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 7OOOOOF7OOOOs   5H A2&H 2A66H 9A6:8H 2CH CH C8H D6*H 6D::H =D:>H G9%A1G"G9"G&	&G9)G&	*G9-H 9G==H  G=H H0c                 |   t          j        t                     	 t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t                      5 }t          j	        |d          5 }|
                    t          d 	           |                                }|                     d|           |                     d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          t                     d S # t          t                     w xY w)
Nrz  rL   r;  r<  r{  r|  r}  c                 .    |                      d           S )Nr|  )rQ  )r}   s    r(   rg  zEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>  s    68kk)6L6L2L r4   rh  r~  r  s        r(   $test_write_python_directory_filteredz3PyZipFileTests.test_write_python_directory_filtered  sw   
	bgll7I66gNNN (RT'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( bgll7I66gNNN -RT+,,,- - - - - - - - - - - - - - -  3Aw'8C'@'@ 3Eg 3M 3M N N N ((%%i777  E2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 7OOOOOF7OOOOs   5F% A2&F% 2A66F% 9A6:8F% 2CF% CF% CF% -FAE-!F-E1	1F4E1	5F8F% FF% FF% %F;c                    t                      5 }t          j        |d          5 }t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   |                     t          |j        t                     t          t                     d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   r;  r<  z!most definitely not a python file)
r   rR   rP  rA   r   rB   r   r  rX  r   )rD   r[  rV   r'   s       r(   test_write_non_pyfilez$PyZipFileTests.test_write_non_pyfile  sp   __ 	7#4Q#<#< 	fcG444 =;<<<= = = = = = = = = = = = = = =lEM6BBB6NNN		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sW   CB0AB0A##B0&A#'=B0$C0B4	4C7B4	8CCCc           	         t          j        t                     	 t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t                      5 }t          j	        |d          5 }t                      5 }|                    t           j                            t          d                     d d d            n# 1 swxY w Y   |                     d|                                           |                                }|                     d|           |                     d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t!          t                     d S # t!          t                     w xY w)Nrz  rL   r;  r<  zBad syntax in python file
rd  zmod1.pyc)rU  r  r!   rA   r   r8   rB   r   rR   rP  r   rX  rp   rm   rv   rZ  r   )rD   rE   r[  rV   sr   s         r(   test_write_pyfile_bad_syntaxz+PyZipFileTests.test_write_pyfile_bad_syntax  sn   
	bgll7I66gNNN 8RT67778 8 8 8 8 8 8 8 8 8 8 8 8 8 8  4Aw'8C'@'@ 4E$&& D!MM"',,w	"B"BCCCD D D D D D D D D D D D D D D mQZZ\\::: ((i///  U3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 7OOOOOF7OOOOs   5F, A2&F, 2A66F, 9A6:F, F!E409C5)E45C99E4<C9=A+E4(F4E8	8F;E8	<F?F, FF, FF, ,Gc                    t          j        t                     	 t          t           j                            t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t                      5 }t          j	        |d          5 }|
                    t          j        t                    dz             |                                }|                     d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          t                     d S # t          t                     w xY w)Nrz  rL   r;  r<  r{  )rU  r  r!   rA   r   r8   rB   r   rR   rP  rX  r   r   rv   r>  r   r  s        r(   test_write_pathlikez"PyZipFileTests.test_write_pathlike  s   
		bgll7I66gNNN (RT'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (  8Aw'8C'@'@ 8Egl733i?@@@((%%i7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
 7OOOOOF7OOOOsx   5D? A2&D? 2A66D? 9A6:D? D!AD;DD	DD	DD? D""D? %D"&D? ?EN)r  r  r  r>  rH  r^  rb  rs  rx  r  r  r  r  r  re   r4   r(   r:  r:    s        0 0 0  8 8 8<? ? ?< < <<: : :  .  (    ,    r4   r:  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z ej        ej        j        dk    d          d             Z ej        ej        j        dk    d          d             Zd ZdS )ExtractTestsc                     t          j        t          dt           j                  5 }t          D ]\  }}|                    ||           	 d d d            d S # 1 swxY w Y   d S )NrL   )rR   rS   r!   r   SMALL_TEST_DATArT   rD   rV   fpathfdatas       r(   make_test_filezExtractTests.make_test_file  s    _Wc7+=>> 	-% / - -uue,,,,-	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   $AAAc           	         t                      5  |                                  t          j        t          d          5 }t
          D ]\  }}|                    |          }t          j        	                    t          j
                    |          }t          j                            |          }|                     ||           t          |d          5 }|                     |                                |                                           d d d            n# 1 swxY w Y   t!          |           	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S NrZ   r1  )r   r  rR   rS   r!   r  extractrU  r   r8   getcwdnormpathri   rA   encoderj   r   )rD   rV   r  r  writtenfilecorrectfiler'   s          r(   test_extractzExtractTests.test_extract  s   ZZ 	( 	(!!!#.. (%$3 ( (LE5"'--"6"6K #%',,ry{{E"B"BK"$'"2"2;"?"?K$$[+>>> k400 CA((BBBC C C C C C C C C C C C C C C ;''''(( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(sY   /EBE;D	ED!!E$D!%E9EE			EE		EE!$E!c                    |                                   t          j        t          d          5 }t          D ]\  }}|                    ||          }t          j                            ||          }t          j        	                    |          }| 
                    t          j                            ||          ||f           t          |d          5 }|                     |                                |                                           d d d            n# 1 swxY w Y   t!          |           	 d d d            n# 1 swxY w Y   t!          t                     d S r  )r  rR   rS   r!   r  r  rU  r   r8   r  rr   samefilerA   ri   r  rj   r   )rD   targetrV   r  r  r  r  r'   s           r(   _test_extract_with_targetz&ExtractTests._test_extract_with_target  s   _Wc** 	$e / $ $u#mmE6:: !gll6599 g..{;; 0 0k J J[Z`Labbb +t,, ?$$U\\^^QVVXX>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {####$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	ws6   B)E;DED##E&D#'EEEc                 ~    t                      5 }|                     |           d d d            d S # 1 swxY w Y   d S r    )r   r  rD   extdirs     r(   test_extract_with_targetz%ExtractTests.test_extract_with_target  s    ZZ 	36**6222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3   266c                     t                      5 }|                     t          j        |                     d d d            d S # 1 swxY w Y   d S r    )r   r  r   r   r  s     r(   !test_extract_with_target_pathlikez.ExtractTests.test_extract_with_target_pathlike  s    ZZ 	A6**7<+?+?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A   (AAAc           	      h   t                      5  |                                  t          j        t          d          5 }|                                 t          D ]\  }}t          j        	                    t          j
                    |          }t          |d          5 }|                     |                                |                                           d d d            n# 1 swxY w Y   t          |           	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  )r   r  rR   rS   r!   
extractallr  rU  r   r8   r  rA   ri   r  rj   r   )rD   rV   r  r  outfiler'   s         r(   test_extract_allzExtractTests.test_extract_all  s   ZZ 
	$ 
	$!!!#.. $%  """$3 $ $LE5 gll29;;>>Ggt,, C((BBBC C C C C C C C C C C C C C C 7OOOO$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$ 
	$sY   /D'A"D ;C'	D'C++D.C+/DD'D	D'D	D''D+.D+c                 "   |                                   t          j        t          d          5 }|                    |           t
          D ]\  }}t          j                            ||          }t          |d          5 }| 
                    |                                |                                           d d d            n# 1 swxY w Y   t          |           	 d d d            n# 1 swxY w Y   t          t                     d S r  )r  rR   rS   r!   r  r  rU  r   r8   rA   ri   r  rj   r   )rD   r  rV   r  r  r  r'   s          r(   _test_extract_all_with_targetz*ExtractTests._test_extract_all_with_target  sa   _Wc** 	 eV$$$ /    u',,vu55'4(( ?A$$U\\^^QVVXX>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ? w 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	ws6   AC0;C<C0CC0CC00C47C4c                 ~    t                      5 }|                     |           d d d            d S # 1 swxY w Y   d S r    )r   r  r  s     r(   test_extract_all_with_targetz)ExtractTests.test_extract_all_with_target*  s    ZZ 	76..v666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7r  c                     t                      5 }|                     t          j        |                     d d d            d S # 1 swxY w Y   d S r    )r   r  r   r   r  s     r(   %test_extract_all_with_target_pathlikez2ExtractTests.test_extract_all_with_target_pathlike.  s    ZZ 	E6..w|F/C/CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Er  c                    |                      t          j                            |                     t	          |d          5 }|                     |                                |           d d d            d S # 1 swxY w Y   d S )Nr1  )rr   rU  r   isfilerA   ri   rj   )rD   rg   r  r'   s       r(   
check_filezExtractTests.check_file2  s    x00111(D!! 	0QQVVXXw///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   )A99A= A=c                     t           j        j        }|                      |dd          d           |                      |dd          d           |                      |dd          d           d S )	Nz,,?,C:,foo,bar/z,z_,C_,foo,bar/zza\b,c<d>e|f"g?h*iza\b,c_d_e_f_g_h_i../../foo../../ba..rrM  	foo/ba..r)rR   rS   _sanitize_windows_nameri   )rD   sans     r(   test_sanitize_windows_namez'ExtractTests.test_sanitize_windows_name7  s}    o40#668IJJJ13779MNNN3S99<HHHHHr4   c                 8    g d}|                      |           d S )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)rD   common_hacknamess     r(   *test_extract_hackers_arcnames_common_casesz7ExtractTests.test_extract_hackers_arcnames_common_cases>  s1    	
 	
 	
 	++,<=====r4   \zRequires \ as path separator.c                 8    g d}|                      |           dS )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  )zC://foo/barr  )z
C:\foo\barr  )z//conky/mountpoint/foo/barr  )z\\conky\mountpoint\foo\barr  )z///conky/mountpoint/foo/bar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  )zC:/../C:/foo/barz
C_/foo/bar)za:b\c<d>e|f"g?h*izb/c_d_e_f_g_h_i)r  r  Nr  )rD   windows_hacknamess     r(   *test_extract_hackers_arcnames_windows_onlyz7ExtractTests.test_extract_hackers_arcnames_windows_onlyK  s1    
 
 
* 	++,=>>>>>r4   rM  zRequires / as path separator.c                 8    g d}|                      |           d S )N))z	//foo/barr  )r  zfoo../ba..r)
foo/..\barr  r  )rD   posix_hacknamess     r(   (test_extract_hackers_arcnames_posix_onlyz5ExtractTests.test_extract_hackers_arcnames_posix_onlye  s/    
 
 

 	++O<<<<<r4   c                    |D ]i\  }}d|                                 z   }t          j        t          dt          j                  5 }t          j                    }||_        d|_        |                    ||           d d d            n# 1 swxY w Y   |	                    t          j        d          }t          j                            ddd          }t          j        j        |g|                    d          R  }t          j        t          d          5 }|                    ||          }	|                     |	|d	|d
|	d|           d d d            n# 1 swxY w Y   |                     ||           t%          d           t          j        t          d          5 }|                    |           d d d            n# 1 swxY w Y   |                     ||           t%          d           t          j        j        t          j                    g|                    d          R  }t          j        t          d          5 }|                    |          }	|                     |	|d|z             d d d            n# 1 swxY w Y   |                     ||           t%          |                    d          d                    t          j        t          d          5 }|                                 d d d            n# 1 swxY w Y   |                     ||           t%          |                    d          d                    t+          t                     kd S )N   foobarrL   r  rM  r  subdirsubsubrZ   zextract z: z != )msgz
extract %rr   )r  rR   rS   r!   r   r	  rg   r   rT   replacerU  rR  r   r8   rq   r  ri   r  r   r  r  r   )
rD   	hacknamesarcname	fixednamer  rV   r!  
targetpathr  r  s
             r(   r  z+ExtractTests._test_extract_hackers_arcnamesn  sW   "+ (	 (	GY'.."2"22G#w/ABB /e))!(&1#ug.../ / / / / / / / / / / / / / / oobfc22Gh(CCJ',zIIOOC4H4HIIIK#.. F%#mmGZ@@  kk")'';;;&E ! F F FF F F F F F F F F F F F F F F
 OOK1118#.. -%  ,,,- - - - - - - - - - - - - - -OOK1118',ry{{JY__S5I5IJJJK#.. =%#mmG44  k%1G%; ! = = == = = = = = = = = = = = = = = OOK1119??3''*+++#.. #%  """# # # # # # # # # # # # # # #OOK1119??3''*+++7OOOOQ(	 (	sZ   8B		B	B	8EE!	$E!	'G		G	G	1JJ	J	.LL	L	N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  unittestskipIfrU  r   rR  r  r  r  re   r4   r(   r  r    sJ       - - -
( ( (&  &3 3 3A A A$ $ $  7 7 7E E E0 0 0
I I I> > > X_RW[D(*JKK? ? LK?2 X_RW[C')IJJ= = KJ=) ) ) ) )r4   r  c                   >   e Zd Zd Zd Zd Zd Zd Z e            d             Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d  Z#d! Z$d" Z%d# Z&d$ Z'd% Z(d& Z) e*            d'             Z+d( Z,d)S )*
OtherTestsc                 V   t          j        t          dt           j                  5 }|                    dd           |                     t                    5  |                    dd           d d d            n# 1 swxY w Y   |                     |                                dgdz             d d d            n# 1 swxY w Y   t          j        t          d          5 }|	                                }d}|D ]F}|
                    |          5 }||                                z  }d d d            n# 1 swxY w Y   G|                     |dd	h           d}|D ]}||                    |          z  }|                     |dd	h           d d d            d S # 1 swxY w Y   d S )
NrL   r=  r   barr   rZ   r4   r  s   barfoo)rR   rS   r!   r   rT   rn  ro  ri   rv   rw   rA   rj   rp   )rD   rV   r   r9   r   r   s         r(   test_open_via_zip_infoz!OtherTests.test_open_via_zip_info  s   _Wc7+=>> 	=%NN65)))!!+.. . .vu---. . . . . . . . . . . . . . .U^^--x!|<<<		= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= _Wc** 
	8eNN$$ED + +ZZ%% +GLLNN*D+ + + + + + + + + + + + + + +MM$I 6777D ) )

4(((MM$I 6777
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8 
	8sl   1B=A:.B=:A>	>B=A>	/B==CC"0FD6*F6D::F=D:>AFF"%F"c                     t          j        t          d          5 }dD ]F}t          j        |          }|xj        t           j        z  c_        |                    ||           G	 d d d            d S # 1 swxY w Y   d S )NrL   abcdefghijklmnop)rR   rS   r!   r	  	flag_bits_MASK_USE_DATA_DESCRIPTORrT   )rD   orig_zipr9   r!  s       r(   -test_writestr_extended_local_header_issue1202z8OtherTests.test_writestr_extended_local_header_issue1202  s    _Wc** 	/h* / /--7#DD!!%..../	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   A
A33A7:A7c                    t          j        t          d          5 }t          D ]6\  }}|                    ||           |                     |j        d           7	 ddd           n# 1 swxY w Y   |                     |j        d           t          j        t          d          5 }|                     |j        d           ddd           n# 1 swxY w Y   |                     |j        d           dS )z8Check that the zipfile is closed after the 'with' block.rL   zzipfp is not openNzipfp is not closedrZ   )rR   rS   r!   r  rT   assertIsNotNonerE   assertIsNoner  s       r(   
test_closezOtherTests.test_close  s   _Wc** 	De / D Duue,,,$$UX/BCCCCD	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	%($9:::_Wc** 	@e  +>???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@%($9:::::s#   ?A''A+.A+'CCCc                    t          j        t          d          5 }t          D ]\  }}|                    ||           	 ddd           n# 1 swxY w Y   	 t          j        t          d          5 }t          j                    # 1 swxY w Y   dS # t           j        $ r |                     |j        d           Y dS w xY w)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.rL   NrZ   r  )rR   rS   r!   r  rT   r  r  rE   )rD   rV   r  r  zipfp2s        r(   test_close_on_exceptionz"OtherTests.test_close_on_exception  s;    _Wc** 	-e / - -uue,,,,-	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-	@#.. +&(***+ + + + + + + + + +! 	@ 	@ 	@fi)>??????	@sA   $AAAB 2BB

B B
B *C Cc                 |    d}|                      t          t          j        t	          j        |          d           d S )Nsd   PKx     !p@               xPKxx     !p@                           xPK      /        rZ   )r   NotImplementedErrorrR   rS   r$   r%   rD   r9   s     r(   test_unsupported_versionz#OtherTests.test_unsupported_version  sD    Y 	-w*T**C	1 	1 	1 	1 	1r4   c                     t          d          }t          j        |          5 }|                                D ])}|                    |                                           *	 d d d            d S # 1 swxY w Y   d S )Nzzip_cp437_header.zip)r	   rR   rS   rv   rA   rI  )rD   r   rV   r=  s       r(   test_read_unicode_filenamesz&OtherTests.test_read_unicode_filenames  s     /00_U## 	)u(( ) )

4  &&(((()	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)s   ?A11A58A5c                 0   t          j        t          d          5 }|                    dd           |                    dd           |                     |                                d         j        t                     d d d            n# 1 swxY w Y   t          j        t          d          5 }|                     |j	        d         j        d           |                     |j	        d         j        d           d d d            d S # 1 swxY w Y   d S )NrL   foo.txtzTest for unicode filenameu   ö.txtr   rZ   r`   )
rR   rS   r   rT   r   rw   rg   ru   ri   filelistrD   r  s     r(   test_write_unicode_filenamesz'OtherTests.test_write_unicode_filenames  s   _VS)) 	BRKK	#>???KK
$?@@@!!"++--"2";SAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
 _VS)) 	BRR[^4i@@@R[^4jAAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs%   A%BBB1ADDDc                     t          j        t          d          5 }|                    dd           |                     |                    d          d           d d d            d S # 1 swxY w Y   d S )NrL   u   прикладs   sample)rR   rS   r!   rT   ri   rj   r*  s     r(   'test_read_after_write_unicode_filenamesz2OtherTests.test_read_after_write_unicode_filenames  s    _Wc** 	FeNN+Y777UZZ(8999EEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   A A((A,/A,c                    t          t                     d}d}t          j        t          dt          j                  5 }|                    ||           ddd           n# 1 swxY w Y   |                     t                    5  t          j        t          dt          j                   ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |	                                |g           |                     |
                    |          |           ddd           dS # 1 swxY w Y   dS )z&Test exclusive creating a new zipfile.testfile.txt#   hello, world. this is some content.xNrZ   )r   r!   rR   rS   r   rT   r   FileExistsErrorri   rv   rj   )rD   rg   r  rV   s       r(   test_exclusive_create_zip_filez)OtherTests.test_exclusive_create_zip_file  s   w!8_Wc7+=>> 	.%NN8W---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.// 	> 	>OGS'*<===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>_Wc** 	<eU^^--z:::UZZ117;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s6   A!!A%(A%&B88B<?B<AD==EEc                    t           j                            t                    rt          j        t                     d}d}	 t          j        t          d          5 }|                    ||           d d d            n# 1 swxY w Y   n%# t          $ r | 	                    d           Y nw xY w| 
                    t           j                            t                               t          j        t          d          5 }|                     |                    |          |           d d d            d S # 1 swxY w Y   d S )Nr  r  r-  z1Could not append data to a non-existent zip file.rZ   )rU  r   existsr   r   rR   rS   rT   r  failrr   ri   rj   )rD   rg   r  r  s       r(   (test_create_non_existent_file_for_appendz3OtherTests.test_create_non_existent_file_for_append  s   7>>&!! 	If!8	K-- /Hg.../ / / / / / / / / / / / / / / 	K 	K 	KIIIJJJJJ	K 	v..///_VS)) 	9RRWWX..888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9sH   B B 4B  BB BB B.-B.*D99D= D=c                     t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   	 t          j        t                    }d S # t          j        $ r Y d S w xY w)NrL   r;  r<  this is not a legal zip file
)rA   r   rB   rR   rS   r  )rD   rE   r  s      r(   test_close_erroneous_filez$OtherTests.test_close_erroneous_file  s     &#000 	7BHH5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7	((BBB! 	 	 	DD	s   :>>A! !A43A4c                 "   t          t          dd          5 }|                    d           ddd           n# 1 swxY w Y   |                     t	          j        t                               |                     t	          j        t          j        t                                         t          t          d          5 }|                     t	          j        |                     ddd           n# 1 swxY w Y   t          j	                    }|                    d           |                     t	          j        |                     |
                    dd           |                     t	          j        |                     dS )	z;Check that is_zipfile() correctly identifies non-zip files.rL   r;  r<  r  Nr1  s   this is not a legal zip file
r   )rA   r   rB   r"   rR   
is_zipfiler   r   r$   r%   r2  rC   s     r(   test_is_zip_erroneous_filez%OtherTests.test_is_zip_erroneous_file  s    &#000 	7BHH5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7+F33444+GL,@,@AABBB&$ 	52W/33444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 Z\\
2333+B//000
1+B//00000s   :>>(C88C<?C<c                    t          j                    }t          j        |d          5 }|                    dd           ddd           n# 1 swxY w Y   |                                }t          t          |                    D ]I}t          j        |d|                   }|                     t          j	        t          j        |           JdS )zCCheck that zipfiles with missing bytes at the end raise BadZipFile.rL   rP   r     O, for a Muse of Fire!N)
r$   r%   rR   rS   rT   rm   r5   ro   r   r  )rD   rE   r   r   Ns        r(   test_damaged_zipfilezOtherTests.test_damaged_zipfile1  s    Z\\_Rc*** 	@dMM)%>???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@kkmm s;''(( 	G 	GAKO,,Bg0'/2FFFF	G 	Gs   AAAc                    t          j        t          d          5 }|                    dd           ddd           n# 1 swxY w Y   |                     t          j        t                               t          t          d          5 }|                     t          j        |                     |                    dd           |                                }ddd           n# 1 swxY w Y   t          j
                    }|                    |           |                     t          j        |                     |                    dd           |                     t          j        |                     dS )z7Check that is_zipfile() correctly identifies zip files.rL   rP   r  r	  Nr1  r   )rR   rS   r   rT   rr   r  rA   r2  rj   r$   r%   rB   )rD   r   rE   zip_contentss       r(   test_is_zip_valid_filez!OtherTests.test_is_zip_valid_file?  s    _V#... 	@$MM)%>???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	*622333&$ 	%2OOG.r22333GGAqMMM7799L	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%
 Z\\
*2..///
1*2../////s"   ?AAAC))C-0C-c                 \    |                      t          t          j        t                     d S r    )r   r  rR   rS   r   r  s    r(   %test_non_existent_file_raises_OSErrorz0OtherTests.test_non_existent_file_raises_OSErrorR  s$     	'7?F;;;;;r4   c                    t          t          dd          }|                                 |                     t          j        t          j        t                     t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   |                     t          j        t          j        t                     d S )NrL   r;  r<  z
short file)rA   r   rI  r   rR   r  rS   rB   )rD   r'   rE   s      r(   !test_empty_file_raises_BadZipFilez,OtherTests.test_empty_file_raises_BadZipFile`  s    w///				',govFFF&#000 	#BHH\"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#',govFFFFFs   3BBBc                     t          d          }dD ][}t          j        d|          |dd<   t          j        |          }|                     t          j        t          j        |           \d S )N   PK                  )r`   r  r  rZ  r  )		bytearrayrc  r  r$   r%   r   rR   r  rS   )rD   bufferdirsizer'   s       r(   8test_negative_central_directory_offset_raises_BadZipFilezCOtherTests.test_negative_central_directory_offset_raises_BadZipFilei  sw    344 " 	F 	FG"Kg66F2b5M
6""Ag0'/1EEEE	F 	Fr4   c                    t          j                    }t          j        |d          5 }|                    dd           ddd           n# 1 swxY w Y   |                     t          |j        d           |                     t          |j        d           |                     t          |j	                   |                     t          |j        dd           t          t          dd	          5 }|                    d
           ddd           n# 1 swxY w Y   |                     t          |j        t                     dS )z?Verify that testzip() doesn't swallow inappropriate exceptions.rL   rP   r  O, for a Muse of Fire!Nz	bogus.txtrH  r;  r<  zzipfile test data)r$   r%   rR   rS   rT   r   rJ  rj   rA   rz   r   rB   )rD   r9   r   r'   s       r(   !test_closed_zip_raises_ValueErrorz,OtherTests.test_closed_zip_raises_ValueErrort  s   z||_T,,, 	?MM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	*di;;;*di;;;*dl333*dm['JJJ&#000 	)AGG'(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)*dj&99999s#   AAA3DDDc                 ^    |                      t          t          j        t          d           dS )z>Check that bad modes passed to ZipFile constructor are caught.r-  N)r   rJ  rR   rS   r   r  s    r(   test_bad_constructor_modez$OtherTests.test_bad_constructor_mode  s$    *govsCCCCCr4   c                    t          j        t          d          5 }|                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                    d           |                     t          |j        dd           |                     t          |j        dd           |                     t          |j        dd	           ddd           dS # 1 swxY w Y   dS )
z7Check that bad modes passed to ZipFile.open are caught.rL   rP   r  r  NrZ   r-  UrU)rR   rS   r   rT   rj   r   rJ  rA   rD   r   s     r(   test_bad_open_modezOtherTests.test_bad_open_mode  so   _V#... 	?$MM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V#... 	F$IIi   j$)YDDDj$)YDDDj$)YEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs"   ?AA%A<C..C25C2c                    t          j        t          d          5 }|                    dd           |                    d          5 }t          t                    D ]+}|                     |                    d          d           ,|                     |                                d           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.rL   rP   r  r  r   r4   r	  N)	rR   rS   r   rT   rA   r5   r6   ri   rj   )rD   r   r'   r2   s       r(   
test_read0zOtherTests.test_read0  so    _V#... 	F$MM)%=>>>9%% F~.. 5 5A$$QVVAYY4444  +DEEE	F F F F F F F F F F F F F F F	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs6   ,CA)B=1C=C	CC	CCCc                     t          j        t          d          5 }|                     t          |j        dd           ddd           dS # 1 swxY w Y   dS )zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.rL   rP   r  rZ   N)rR   rS   r   r   KeyErrorrA   r!  s     r(   test_open_non_existent_itemz&OtherTests.test_open_non_existent_item  s     _V#... 	C$h	9cBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   #AAAc                 `    |                      t          t          j        t          dd           dS )zMCheck that bad compression methods passed to ZipFile.open are
        caught.rL   r   N)r   r  rR   rS   r   r  s    r(   test_bad_compression_modez$OtherTests.test_bad_compression_mode  s)     	-wRPPPPPr4   c                     d}t          j        t          j        |          d          5 }|                     t
          |j        d           d d d            d S # 1 swxY w Y   d S )Nsf   PK.    C@              x PK..    C@                          xPK      /   !     rZ   r  )rR   rS   r$   r%   r   r  rA   )rD   r9   r   s      r(   test_unsupported_compressionz'OtherTests.test_unsupported_compression  s    6 _RZ--s33 	Ct149cBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   "AA Ac                     t          j        t          d          5 }|                    dd           |                     |                                dg           ddd           dS # 1 swxY w Y   dS )zLCheck that a filename containing a null byte is properly
        terminated.rL   rP   zfoo.txt qqqr	  r  N)rR   rS   r   rT   ri   rv   r!  s     r(   test_null_byte_in_filenamez%OtherTests.test_null_byte_in_filename  s     _V#... 	;$MM*,EFFFT]]__yk:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   A A))A-0A-c                    |                      t          j        d           |                      t          j        d           |                      t          j        d           |                      t          j        d           dS )zACheck that ZIP internal structure sizes are calculated correctly.   .   8   r   N)ri   rR   sizeEndCentDirsizeCentralDirsizeEndCentDir64sizeEndCentDir64Locatorr  s    r(   test_struct_sizeszOtherTests.test_struct_sizes  sl    /444/444126668"=====r4   c                 .
   t          j        t          d          5 }|                     |j        d           |                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |j        d           ddd           n# 1 swxY w Y   d}t          j        t          d          5 }||_        |                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |j        |           ddd           n# 1 swxY w Y   d	                    d
 t          d          D                       }|                    d          }t          j        t          d          5 }||_        |                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |j        |           ddd           n# 1 swxY w Y   t          j        t          d          5 }| 	                    t                    5  |dz   |_        ddd           n# 1 swxY w Y   |                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |j        |           ddd           n# 1 swxY w Y   t          j        t          d          5 }d|_        |                    dd           ddd           n# 1 swxY w Y   t          j        t          d          5 }d|_        ddd           n# 1 swxY w Y   t          j        t          d          5 }|                     |j        d           ddd           n# 1 swxY w Y   t          j        t          d          5 }d|_        |                    dd           ddd           n# 1 swxY w Y   t          j                            t                    }t          j        t          d          5 }d|_        ddd           n# 1 swxY w Y   |                     |t          j                            t                    k               t          j        t          d          5 }|                     |j        d           ddd           dS # 1 swxY w Y   dS )z8Check that comments on the archive are handled properly.rL   rP   r4   r  r  NrZ   s9   Bravely taking to his feet, he beat a very brave retreat. c                 $    g | ]}d |dz  dz  z  S )r  r  r   re   r0   s     r(   r3   z,OtherTests.test_comments.<locals>.<listcomp>  s%    KKK1DAqD2I.KKKr4     r.   s   oopss   original commentr-  s   an updated comments   original comment that's longers   shorter comment)rR   rS   r   ri   rB  rT   r8   r5   r  rn  ro  rU  r   getsizerr   )rD   r   zipfrrB  comment2original_zip_sizes         r(   test_commentszOtherTests.test_comments  s    _V#... 	?$T\3///MM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V#... 	1%U]C000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 O_V#... 	?$"DLMM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V#... 	4%T\7333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 77KKk8J8JKKKLL??7++_V#... 	?$#DLMM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V#... 	6%U]H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 _V#... 	?$!!+.. 2 2''12 2 2 2 2 2 2 2 2 2 2 2 2 2 2MM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V#... 	6%U]H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 _V--- 	?.DLMM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? _V--- 	10DL	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1_V--- 	BT\+@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B
 _V--- 	?<DLMM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? GOOF33_V--- 	.-DL	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.)BGOOF,C,CCDDD_V--- 	?T\+=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s  2AA!A B((B,/B,C::C>C> EEE/GG G?H''H+.H+J,(I?3J,?J	J,J	J,,J03J0K::K>K> M

MM0NNN*OOO8P""P&)P&,R  RR!T

TTc                     t          j        t          dt           j                  5 }|                    dd           |                     t                    5  d|_        d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   r  r  zthis is an error)rR   rS   r   r   rT   r   	TypeErrorrB  r!  s     r(   test_unicode_commentzOtherTests.test_unicode_comment  s    _VS'*<== 	2MM)%=>>>""9-- 2 212 2 2 2 2 2 2 2 2 2 2 2 2 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s5   1BA+B+A/	/B2A/	3BB
Bc                 ^   t          j        t          dt           j                  5 }|                     |j                   d|_        d d d            n# 1 swxY w Y   t          j        t          d          5 }|                     |j        d           d d d            d S # 1 swxY w Y   d S )Nr-  rA  rZ   )rR   rS   r   r   r"   r  rB  ri   r!  s     r(   $test_change_comment_in_empty_archivez/OtherTests.test_change_comment_in_empty_archive  s)   _VS'*<== 	0T]+++/DL	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 _VS)) 	ATT\+?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As#   "AAA9B""B&)B&c                    t          j        t          dt           j                  5 }|                    dd           d d d            n# 1 swxY w Y   t          j        t          dt           j                  5 }|                     |j                   d|_        d d d            n# 1 swxY w Y   t          j        t          d          5 }|                     |j        d           d d d            d S # 1 swxY w Y   d S )NrL   r  r  r-  rA  rZ   )	rR   rS   r   r   rT   rr   r  rB  ri   r!  s     r(   'test_change_comment_in_nonempty_archivez2OtherTests.test_change_comment_in_nonempty_archive  s   _VS'*<== 	?MM)%=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?_VS'*<== 	0OODM***/DL	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 _VS)) 	ATT\+?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As5   A		AA9"B''B+.B+C55C9<C9c                    t          j        t          d          }|                                 	 t          j        t          d          }n*# t           j        $ r |                     d           Y nw xY wt          j        t          d          }|                                 	 t          j        t          d          }d S #  |                     d           Y d S xY w)NrL   rP   rZ   z+Unable to create empty ZIP file in 'w' moder-  z+Unable to create empty ZIP file in 'a' mode)rR   rS   r   rI  r  r   r!  s     r(   test_empty_zipfilezOtherTests.test_empty_zipfile  s     vC000

	E?6444DD! 	E 	E 	EIICDDDDD	E vC000

	E?6444DDD	EIICDDDDDDs   A $A43A4'C Cc                     t          t          dd          }|                                 |                     t          j        t          j        t          d           d S )NrL   r;  r<  rZ   )rA   r   rI  r   rR   r  rS   r   s     r(   test_open_empty_filezOtherTests.test_open_empty_file(  sJ     w///				',govsKKKKKr4   c                 T    |                      t          t          j        dd           d S )N	seventies)i  r`   r`   r   r   r   )r   rJ  rR   r	  r  s    r(   test_create_zipinfo_before_1980z*OtherTests.test_create_zipinfo_before_19800  s5    *!/;8M	O 	O 	O 	O 	Or4   c                 v    t          j        d          }|                     t          |          d           dS )z=Before bpo-26185, repr() on empty ZipInfo object was failing.emptyrf   z&<ZipInfo filename='empty' file_size=0>N)rR   r	  ri   r   rD   r  s     r(   test_create_empty_zipinfo_reprz)OtherTests.test_create_empty_zipinfo_repr4  s7    _g...b#KLLLLLr4   c                    t          j                    }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        t           j                   |                     |j        d           |                     |j	        d           | 
                    |j        d           |                     |j        t           j                   |                     |j        t           j                   |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           dS )z'Ensure all required attributes are set.NoNamerT  r4   )r   r  r   N)rR   r	  ri   orig_filenamerg   rW  r   r   rB  r  rp   create_systemcreate_versionDEFAULT_VERSIONr  reservedr  volumeinternal_attrr   rx   r  rP  s     r(   ,test_create_empty_zipinfo_default_attributesz7OtherTests.test_create_empty_zipinfo_default_attributes9  s   _)8444h///'<===)7+=>>>S)))3'''b&///*G,CDDD+W-DEEEa(((q)))A&&&)1---)1--- 	q))))1-----r4   c                     d}t          j        t          j        |          d          5 }|                     |                                           ddd           dS # 1 swxY w Y   dS )z>If an extra field in the header is less than 4 bytes, skip it.sn   PK     @        abc   APK     @                    abc  PK      3   %     rZ   N)rR   rS   r$   r%   r  rz   rD   r   r   s      r(   #test_zipfile_with_short_extra_fieldz.OtherTests.test_zipfile_with_short_extra_fieldO  s    B 	 _RZ00#66 	.$dllnn---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   (AA#&A#c                    d}d}d}t          j        t          dt           j                  5 }|                    dd          5 }|                    |           d d d            n# 1 swxY w Y   |                    dd          5 }|                     t                    5  |                    dd           d d d            n# 1 swxY w Y   |                     t                    5  |                    dd	           d d d            n# 1 swxY w Y   |                     t                    5  |                    d
d           d d d            n# 1 swxY w Y   |                     t                    5  |                    t          d           d d d            n# 1 swxY w Y   |                     t                    5  |
                                 d d d            n# 1 swxY w Y   |                    |           d d d            n# 1 swxY w Y   |                    dd          5 }|                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        t          d	          5 }|                     |                    d          |           |                     |                    d          |           |                     |                    d          |           |                     |                                g d           d d d            d S # 1 swxY w Y   d S )Ns"   It's fun to charter an accountant!s    And sail the wide accountant seas#   To find, explore the funds offshorerL   r   rP   r  handlerZ   ru   abcder[   baz)r   r  rb  )rR   rS   r!   r   rA   rB   r   rJ  rT   rO  rI  ri   rj   rv   )rD   msg1msg2msg3r   w2w1s          r(   test_open_conflicting_handlesz(OtherTests.test_open_conflicting_handles^  sb   425_Wc7+=>> 	$5s++ r              5s++ r&&z22 2 2IIhSI1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2&&z22 / /IIe#I.../ / / / / / / / / / / / / / /&&z22 2 2MM%1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2&&z22 1 1JJx0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1&&z22 ! !JJLLL! ! ! ! ! ! ! ! ! ! ! ! ! ! !               5s++ r              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	$ _Wc** 	EdTYYu--t444TYYu--t444TYYu--t444T]]__.C.C.CDDD		E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	EsD  I2A&I2&A*	*I2-A*	.I2H#C;HCHCH,DHDHDH5EHEHE H=F%H%F))H,F)-H
G+H+G//H2G/3HI2H	I2H	I29II2I	I2"I	#I22I69I6B&M

MMc           	      	   d}|                     d          }t          j        t          d          5 }|                    d|           d d d            n# 1 swxY w Y   t          j        t          d          5 }|                    dd          5 }|                    |t          j                   | 	                    |
                                |           |                    | t          j                   | 	                    |
                                d           |                    |t          j                   | 	                    |
                                |           | 	                    |                    d          |||dz                       |                    dt          j                   | 	                    |
                                t          |                     |                    dt          j                   | 	                    |
                                d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j                    }t          j        |d          5 }|                    d|           d d d            n# 1 swxY w Y   t          j        |d          5 }|                    dd          5 }|                    |t          j                   | 	                    |
                                |           |                    | t          j                   | 	                    |
                                d           |                    |t          j                   | 	                    |
                                |           | 	                    |                    d          |||dz                       |                    dt          j                   | 	                    |
                                t          |                     |                    dt          j                   | 	                    |
                                d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )	Ns   Where's Bruce?s   BrucerL   r  rZ   r   r\   rP   )findrR   rS   r   rT   rA   r2  rU  SEEK_SETri   r   SEEK_CURrj   SEEK_ENDro   r$   r%   )rD   txtblocr   rE   r9   s         r(   test_seek_tellzOtherTests.test_seek_tell{  s0   xx!!_VS)) 	*TMM)S)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*_VS)) 	/T9c** /bbk***  D111r{+++  A...bk***  D111  Sd1f-=>>>2;'''  CHH5552;'''  A.../ / / / / / / / / / / / / / /	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ z||_T,,, 	*MM)S)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*_T,,, 	/9c** /bbk***  D111r{+++  A...bk***  D111  Sd1f-=>>>2;'''  CHH5552;'''  A.../ / / / / / / / / / / / / / /	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   AAA:IF+I<II	II	II#&I#J66J:=J:R=.F+R%R=%R)	)R=,R)	-R==SSc                    d}t          j        |          }t          j        |dt          j                  5 }|                    dd           d d d            n# 1 swxY w Y   t          j        dd           5  t          j        |          5 }|                     t          |j
        d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  rL   )rJ   r      azzipfile.bz2)r$   r%   rR   rS   rt  rT   mockpatchr   r  r  )rD   r9   zip_filer  s       r(   )test_decompress_without_3rd_party_libraryz4OtherTests.test_decompress_without_3rd_party_library  s   d:d##_Xs8IJJJ 	'bKK&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'Zt,, 	E 	E** Eb!!,
GDDDE E E E E E E E E E E E E E E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	EsG   AA"A;C"B>2C>C	CC	CCCc                 V    t          t                     t          t                     d S r    r  r  s    r(   r  zOtherTests.tearDown  r  r4   N)-r  r  r  r  r  r  r  r  r
   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r$  r'  r)  r+  r-  r6  r?  rB  rD  rF  rH  rJ  rM  rQ  r[  r^  rh  rp  r   rv  r  re   r4   r(   r  r    s       8 8 8(/ / /
; 
; 
;@ @ @	1 	1 	1 ]__) ) _)B B BF F F
< < <9 9 9$  1 1 1$G G G0 0 0&< < <G G G	F 	F 	F: : :$D D DF F F
F 
F 
FC C CQ Q Q
	C 	C 	C; ; ;> > >8? 8? 8?t2 2 2A A AA A AE E E"L L LO O OM M M
. . .,. . .E E E:$/ $/ $/L \^^E E ^E    r4   r  c                       e Zd Zd Zd ZdS )AbstractBadCrcTestsc                     | j         }t          j        t          j        |          d          5 }|                     d|                                           ddd           dS # 1 swxY w Y   dS )z>Tests that files with bad CRCs return their name from testzip.rZ   rP   afileN)zip_with_bad_crcrR   rS   r$   r%   ri   rz   r]  s      r(   test_testzip_with_bad_crcz-AbstractBadCrcTests.test_testzip_with_bad_crc  s    '_RZ00s;;; 	6tWdllnn555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   )A&&A*-A*c                    | j         }t          j        t          j        |          d          5 }|                     t          j        |j        d           ddd           n# 1 swxY w Y   t          j        t          j        |          d          5 }|                    dd          5 }|                     t          j        |j                   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t          j        t          j        |          d          5 }|                    dd          5 }d|_	        |                     t          j                  5  |                    d          r	 |                    d          ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )zFTests that files with bad CRCs raise a BadZipFile exception when read.rZ   rP   r{  Nr   )
r|  rR   rS   r$   r%   r   r  rj   rA   MIN_READ_SIZE)rD   r   r   corrupt_files       r(   test_read_with_bad_crcz*AbstractBadCrcTests.test_read_with_bad_crc  sL   ' _RZ00s;;; 	Ftg0$)WEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F _RZ00s;;; 	It7C(( IL!!'"4l6GHHHI I I I I I I I I I I I I I I	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I
 _RZ00s;;; 	t7C(( L-.*&&w'9::  &++A..  '++A..                             	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   'A##A'*A'C6-&CC6C#	#C6&C#	'C66C:=C:)G 'F6',FF6F##F6&F#'F6*G6F:	:G=F:	>GGGN)r  r  r  r}  r  re   r4   r(   ry  ry    s2        6 6 6    r4   ry  c                        e Zd Zej        ZdZdS )StoredBadCrcTestssx   PK      ;:r         afilehello,AworldPK      ;:r                     afilePK      3   /     N)r  r  r  rR   r   rJ   r|  re   r4   r(   r  r    s"        $K	 r4   r  c                        e Zd Zej        ZdZdS )DeflateBadCrcTestss|   PK    n}=FAKE   n      afileHW(/Iɠ= PK    n}=FAKE   n                  afilePK      3   3     N)r  r  r  rR   rm  rJ   r|  re   r4   r(   r  r    s"        &K	6 r4   r  c                        e Zd Zej        ZdZdS )Bzip2BadCrcTestss   PK   nu=FAKE8   n      afileBZh91AY&SYԨ  @ D   P!u5:"(HjTe?PK   nu=FAKE8   n                 afilePK      3   [     N)r  r  r  rR   rt  rJ   r|  re   r4   r(   r  r    s"        #K
	 r4   r  c                        e Zd Zej        ZdZdS )LzmaBadCrcTestss   PK   nu=FAKE   n      afile	 ]    4I:3`	q!.8 PK   nu=FAKE   n                 afilePK      3   >     N)r  r  r  rR   ry  rJ   r|  re   r4   r(   r  r    s"        "K	% r4   r  c                   l    e Zd ZdZdZdZdZdZd Zd Z	d Z
d	 Z e            d
             Zd Zd ZdS )DecryptionTestszCheck that ZIP decryption works. Since the library does not
    support encryption at the moment, we use a pre-generated encrypted
    ZIP file.s   PK    ni.#y?&         test.txtgly|-=yrZ}Lg|䋺)lPK     ni.#y?&                    test.txtPK      6   L     s   PK 	  }38xu        zeroUT	 ֋GڋGUx <MaXY&{oEםPKxu      PK 	  }38xu                    zeroUT ֋GUx  PK      ?   [     s   zipfile.py encryption tests                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   c                    t          t          d          5 }|                    | j                   d d d            n# 1 swxY w Y   t	          j        t          d          | _        t          t          d          5 }|                    | j                   d d d            n# 1 swxY w Y   t	          j        t          d          | _	        d S )Nr?   rZ   )
rA   r   rB   r9   rR   rS   r   r!   data2zip2rC   s     r(   rF   zDecryptionTests.setUp!	  s   &$ 	 2HHTY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ?63//'4   	!BHHTZ   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!OGS11			s!   =AA<B##B'*B'c                     | j                                          t          j        t                     | j                                         t          j        t                     d S r    )r   rI  rU  r   r   r  r!   r  s    r(   r  zDecryptionTests.tearDown)	  sL    
	&	
	'r4   c                     |                      t          | j        j        d           |                      t          | j        j        d           d S )Ntest.txtzero)r   r  r   rj   r  r  s    r(   test_no_passwordz DecryptionTests.test_no_password/	  sB     	,zBBB,	?????r4   c                    | j                             d           |                     t          | j         j        d           | j                            d           |                     t          | j        j        d           d S )Ns   perlr  r  )r   setpasswordr   r  rj   r  r  s    r(   test_bad_passwordz!DecryptionTests.test_bad_password5	  sl    W%%%,zBBB	g&&&,	?????r4   c                 :   | j                             d           |                     | j                             d          | j                   | j                            d           |                     | j                            d          | j                   d S )N   pythonr  s   12345r  )r   r  ri   rj   plainr  plain2r  s    r(   test_good_passwordz"DecryptionTests.test_good_password;	  s    Y'''z22DJ???	h'''//=====r4   c                 0   d}|                      t          |          5  | j                            d           d d d            n# 1 swxY w Y   |                      t          |          5  | j                            dd           d d d            n# 1 swxY w Y   |                      t          |          5  | j                            dd           d d d            n# 1 swxY w Y   |                      t          |          5  | j                            dd           d d d            n# 1 swxY w Y   |                      t          |          5  d| j        _        | j                            d           d d d            d S # 1 swxY w Y   d S )Nzpwd: expected bytes, got strunicoder  python)pwd)assertRaisesRegexrA  r   r  rj   rA   r  r  )rD   expected_msgs     r(   test_unicode_passwordz%DecryptionTests.test_unicode_passwordB	  s   5##I|<< 	, 	,H  +++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, ##I|<< 	0 	0HMM*h///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 ##I|<< 	4 	4HMM*(M333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 ##I|<< 	7 	7HZX666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 ##I|<< 	& 	&#DHLHMM*%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&sY   AA	A	+BBB9C""C&)C&D11D58D5'FFFc                    | j                             d           | j        }d}|                    |          }t	          |          }| j                             dd          5 }|                    |t          j                   | 	                    |
                                |           |                    | t          j                   | 	                    |
                                d           |                    |t          j                   | 	                    |
                                |           | 	                    |                    |          ||||z                       |j        }d|_        d|_        d|_        |                    dt          j                   | 	                    |
                                d           |                    |t          j                   | 	                    |                    |          ||||z                       ||_        |                    dt          j                   | 	                    |
                                t	          |                     |                    dt          j                   | 	                    |
                                d           |                                 d d d            d S # 1 swxY w Y   d S )Nr  s
   encryptionr  rZ   r   r`   r4   )r   r  r  rj  ro   rA   r2  rU  rk  ri   r   rl  rj   r  _readbuffer_offsetrm  )rD   rn  	test_wordro  bloc_lenrE   old_read_sizes          r(   rp  zDecryptionTests.test_seek_tellU	  s   Y'''j!	xx	""y>>X]]:s++ 	rGGD"+&&&RWWYY---GGTE2;'''RWWYY***GGD"+&&&RWWYY---RWWX..Dh4F0GHHH
 ,M B BNBJGGAr{###RWWYY***GGD"+&&&RWWX..Dh4F0GHHH,BGGAr{###RWWYYC111GGAr{###RWWYY*** GGIII;	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   #I>K..K25K2N)r  r  r  __doc__r9   r  r  r  rF   r  r  r  r
   r  r  rp  re   r4   r(   r  r  	  s         
	) 		: 
 *EF2 2 2  @ @ @@ @ @ ]__> > _>& & &&# # # # #r4   r  c                   Z    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 ZdS )"AbstractTestsWithRandomBinaryFilesc                     t          dd          dz  t          dd          z   }d                    d t          |          D                       | _        d S )Nr  @   r   r`   r4   c           	   3   z   K   | ]6}t          j        d t                      t          dd          z            V  7dS )z<fir   N)rc  r  r   r   r0   s     r(   r  z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>	  sU       7 7 ! #Kfhhwud7K7K.KLL 7 7 7 7 7 7r4   )r   r8   r5   r9   )r;   	datacounts     r(   r<   z-AbstractTestsWithRandomBinaryFiles.setUpClass|	  s`    BOOD(71d+;+;;	88 7 7%*9%5%57 7 7 7 7r4   c                     t          t          d          5 }|                    | j                   d d d            d S # 1 swxY w Y   d S r>   r@   rC   s     r(   rF   z(AbstractTestsWithRandomBinaryFiles.setUp	  rG   rH   c                 V    t          t                     t          t                     d S r    r  r  s    r(   r  z+AbstractTestsWithRandomBinaryFiles.tearDown	  r  r4   c                     t          j        |d|          5 }|                    t          d           |                    t          t                     d d d            d S # 1 swxY w Y   d S )NrL   rM   )rR   rS   rB   r   r  s       r(   rX   z4AbstractTestsWithRandomBinaryFiles.make_test_archive	  s    _Q[11 	(UKK///KK'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   <A  A$'A$c                    |                      ||           t          j        |d|          5 }|                    t                    }|                     t          |          t          | j                             |                     || j                   |                     |                    d          | j                   d d d            d S # 1 swxY w Y   d S )NrZ   rM   )rX   rR   rS   rj   r   ri   ro   r9   )rD   r'   rJ   rV   testdatas        r(   r   z+AbstractTestsWithRandomBinaryFiles.zip_test	  s   q+... _Q[11 	DUzz&))HS]]C	NN;;;Xty111UZZ77CCC		D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   BCCCc                 `    t          |           D ]}|                     || j                   d S r    r   r   s     r(   	test_readz,AbstractTestsWithRandomBinaryFiles.test_read	  r   r4   c                    |                      ||           t          j        |d|          5 }g }|                    t                    5 }	 |                    d          }|sn|                    |           .	 d d d            n# 1 swxY w Y   g }|                    d          5 }	 |                    d          }|sn|                    |           .	 d d d            n# 1 swxY w Y   d                    |          }	|                     t          |	          t          | j
                             |                     |	| j
                   d                    |          }
|                     t          |
          t          | j
                             |                     |
| j
                   d d d            d S # 1 swxY w Y   d S r   )rX   rR   rS   rA   r   rj   r   r8   ri   ro   r9   )rD   r'   rJ   rV   r   r   r   r   r   	testdata1	testdata2s              r(   r   z0AbstractTestsWithRandomBinaryFiles.zip_open_test	  sy   q+... _Q[11 	3UHF## /x/ (c 2 2I$ OOI...	/ 	/ / / / / / / / / / / / / / / HN++ /x/ (c 2 2I$ OOI...	/ 	/ / / / / / / / / / / / / / / **IS^^S^^<<<Y	222**IS^^S^^<<<Y	222/	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3sZ   G
0B;GB	GB	G)0C&G&C*	*G-C*	.CGGGc                 `    t          |           D ]}|                     || j                   d S r    r   r   s     r(   r   z,AbstractTestsWithRandomBinaryFiles.test_open	  r   r4   c                 >   |                      ||           t          j        |d|          5 }g }|                    t                    5 }	 |                    t          dd                    }|sn|                    |           <	 d d d            n# 1 swxY w Y   d                    |          }| 	                    t          |          t          | j                             | 	                    || j                   d d d            d S # 1 swxY w Y   d S r   )rX   rR   rS   rA   r   rj   r   r   r8   ri   ro   r9   )rD   r'   rJ   rV   r   r   r   r  s           r(   r   z7AbstractTestsWithRandomBinaryFiles.zip_random_open_test	  s   q+... _Q[11 	2UHF## /x/ (ga.>.> ? ?I$ OOI...	/ 	/ / / / / / / / / / / / / / / xx))HS]]C	NN;;;Xty111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s6   D
>B	DB	DB	A(DDDc                 `    t          |           D ]}|                     || j                   d S r    r   r   s     r(   r   z3AbstractTestsWithRandomBinaryFiles.test_random_open	  r   r4   N)r  r  r  r  r<   rF   r  rX   r   r  r   r   r   r   re   r4   r(   r  r  {	  s        7 7 [7
     
  ( ( (D D D/ / /3 3 3:4 4 42 2 2"; ; ; ; ;r4   r  c                       e Zd Zej        ZdS ) StoredTestsWithRandomBinaryFilesNr2  re   r4   r(   r  r  	  s        $KKKr4   r  c                       e Zd Zej        ZdS )!DeflateTestsWithRandomBinaryFilesNr  re   r4   r(   r  r  	  r  r4   r  c                       e Zd Zej        ZdS )Bzip2TestsWithRandomBinaryFilesNrs  re   r4   r(   r  r  	  ru  r4   r  c                       e Zd Zej        ZdS )LzmaTestsWithRandomBinaryFilesNrx  re   r4   r(   r  r  	  rz  r4   r  c                   &    e Zd Zd Zd Zd Zd ZdS )Tellablec                 "    || _         d| _        d S Nr   )rE   offsetrC   s     r(   __init__zTellable.__init__	  s    r4   c                 Z    | j                             |          }| xj        |z  c_        |S r    )rE   rB   r  )rD   r9   ns      r(   rB   zTellable.write	  s*    GMM$qr4   c                     | j         S r    )r  r  s    r(   r   zTellable.tell	  s
    {r4   c                 8    | j                                          d S r    rE   flushr  s    r(   r  zTellable.flush	      r4   N)r  r  r  r  rB   r   r  re   r4   r(   r  r  	  sP            
      r4   r  c                        e Zd Zd Zd Zd ZdS )r  c                     || _         d S r    )rE   rC   s     r(   r  zUnseekable.__init__	  s    r4   c                 6    | j                             |          S r    )rE   rB   r  s     r(   rB   zUnseekable.write	  s    w}}T"""r4   c                 8    | j                                          d S r    r  r  s    r(   r  zUnseekable.flush
  r  r4   N)r  r  r  r  rB   r  re   r4   r(   r  r  	  sA          # # #    r4   r  c                        e Zd Zd Zd Zd ZdS )UnseekableTestsc           	         d t           t          fD ]}|                     |          5  t          j                    }|                    d           t          j        |          }t          j         ||          dt          j	                  5 }|
                    dd           |
                    dd           d d d            n# 1 swxY w Y   |                     |                                d d	         d
           t          j        |d          5 }|                    d          5 }|                     |                                d           d d d            n# 1 swxY w Y   |                    d          5 }|                     |                                d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nc                     | S r    re   r'   s    r(   rg  z/UnseekableTests.test_writestr.<locals>.<lambda>
      ! r4   wrapper   abcrL   ones   111twos   222r\      abcPKrZ   rP   )r  r  subTestr$   r%   rB   BufferedWriterrR   rS   r   rT   ri   rm   rA   rj   )rD   r  r'   bfrV   r   zopens          r(   test_writestrzUnseekableTests.test_writestr
  s   #h
: 	? 	?Gg.. ? ?JLL&q))_WWR[[#w7IJJ 3eNN66222NN662223 3 3 3 3 3 3 3 3 3 3 3 3 3 3   bqb!18<<<_QS111 ?T6** ?e((v>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?6** ?e((v>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	?s   A&G(-C	=G(	CG(CA	G(G0)E%	G%E))G,E)-G)F:	.G:F>>GF>GG(GG(GG((G,	/G,	c           	      J   d t           t          fD ]}|                     |          5  t          j                    }|                    d           t          j        |          }t          j         ||          dt          j	                  5 }| 
                    t          t                     t          t          d          5 }|                    d           d d d            n# 1 swxY w Y   |                    t          d           t          t          d          5 }|                    d           d d d            n# 1 swxY w Y   |                    t          d	           d d d            n# 1 swxY w Y   |                     |                                d d
         d           t          j        |d          5 }|                    d          5 }|                     |                                d           d d d            n# 1 swxY w Y   |                    d	          5 }|                     |                                d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nc                     | S r    re   r  s    r(   rg  z,UnseekableTests.test_write.<locals>.<lambda>
  r  r4   r  r  rL   r?   r  r  r  r  r\   r  rZ   rP   )r  r  r  r$   r%   rB   r  rR   rS   r   
addCleanupr   r   rA   ri   rm   rj   )rD   r  r'   r  rV   f2r   r  s           r(   
test_writezUnseekableTests.test_write
  s   #h
: 	? 	?Gg.. ? ?JLL&q))_WWR[[#w7IJJ 0eOOFF333fd++ )r((() ) ) ) ) ) ) ) ) ) ) ) ) ) )KK///fd++ )r((() ) ) ) ) ) ) ) ) ) ) ) ) ) )KK///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0   bqb!18<<<_QS111 ?T6** ?e((v>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?6** ?e((v>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	?s   A&J6E7C(	E7(C,,E7/C,03E7#E	9E7E		E7E	E7+J7E;;J>E;?A	JI?)H	I?HI?HI?3)I(	I?(I,,I?/I,0I?3J?JJJJJ	J	c           	         d t           t          fD ]}|                     |          5  t          j                    }|                    d           t          j        |          }t          j         ||          dt          j	                  5 }|
                    dd          5 }|                    d           d d d            n# 1 swxY w Y   |
                    dd          5 }|                    d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |                                d d	         d
           t          j        |          5 }|                     |                    d          d           |                     |                    d          d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nc                     | S r    re   r  s    r(   rg  z1UnseekableTests.test_open_write.<locals>.<lambda>,
  r  r4   r  r  rL   r  r  r  r  r\   r  )r  r  r  r$   r%   rB   r  rR   rS   r   rA   ri   rm   rj   )rD   r  r'   r  r   r  s         r(   test_open_writezUnseekableTests.test_open_write+
  s   #h
: 	@ 	@Gg.. @ @JLL&q))_WWR[[#w7IJJ ,d63// ,5F+++, , , , , , , , , , , , , , ,63// ,5F+++, , , , , , , , , , , , , , ,, , , , , , , , , , , , , , ,
   bqb!18<<<_Q'' @4$$TYYv%6%6???$$TYYv%6%6???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@s   A&G(D#'C		=D#	CD#CD#*D	 D#DD#DD#G(#D''G(*D'+AG(2AGG(GG(GG((G,	/G,	N)r  r  r  r  r  r  re   r4   r(   r  r  
  sF        ? ? ? ? ? ?*@ @ @ @ @r4   r  c                   `    e Zd Zed             Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd ZdS )TestsWithMultipleOpensc                 b    dt          d          z   | _        dt          d          z   | _        d S )Nr  '  r  )r   data1r  r:   s    r(   r<   z!TestsWithMultipleOpens.setUpClass>
  s.    Yu---	Yu---			r4   c                     t          j        |dt           j                  5 }|                    d| j                   |                    d| j                   d d d            d S # 1 swxY w Y   d S )NrL   r  r  )rR   rS   rm  rT   r  r  )rD   r'   rV   s      r(   rX   z(TestsWithMultipleOpens.make_test_archiveC
  s    _QW%9:: 	/eNN64:...NN64:...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   7A%%A),A)c           	      z   t          |           D ])}|                     |           t          j        |d          5 }|                    d          5 }|                    d          5 }|                    d          }|                    d          }||                                z  }||                                z  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     ||           |                     || j                   d d d            n# 1 swxY w Y   +d S )NrZ   rP   r    )r)   rX   rR   rS   rA   rj   ri   r  rD   r'   r   zopen1zopen2r  r  s          r(   test_same_filez%TestsWithMultipleOpens.test_same_fileI
  s    4 		4 		4A""1%%%--- 4YYv&& +&$))F2C2C +v"KK,,E"KK,,EV[[]]*EV[[]]*E	+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   ...  
3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4		4 		4sZ   D.C&*AC	C&CC&CC&D.&C**D.-C*.4D..D2	5D2	c           	         t          |           D ].}|                     |           t          j        |d          5 }|                    d          5 }|                    d          5 }|                    d          }|                    d          }||                                z  }||                                z  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     || j                   |                     || j                   d d d            n# 1 swxY w Y   0d S )NrZ   rP   r  r  r  	r)   rX   rR   rS   rA   rj   ri   r  r  r  s          r(   test_different_filez*TestsWithMultipleOpens.test_different_fileW
  s    4 		4 		4A""1%%%--- 4YYv&& +&$))F2C2C +v"KK,,E"KK,,EV[[]]*EV[[]]*E	+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
333  
3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4		4 		4sZ   D3C&*AC	C&CC&CC&D3&C**D3-C*.9D33D7	:D7	c           	         t          |           D ].}|                     |           t          j        |d          5 }|                    d          5 }|                    d          }|                    d          5 }|                    d          }||                                z  }||                                z  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     || j                   |                     || j                   d d d            n# 1 swxY w Y   0d S )NrZ   rP   r  r  r  r  )rD   r'   r   r  r  r  r  s          r(   test_interleavedz'TestsWithMultipleOpens.test_interleavede
  s    4 
	4 
	4A""1%%%--- 4YYv&& /&"KK,,E6** /f &C 0 0../ / / / / / / / / / / / / / // / / / / / / / / / / / / / /   
333  
3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4
	4 
	4sZ   D3+C&?AC	C&CC&CC&D3&C**D3-C*.9D33D7	:D7	c                    t          |           D ]N}|                     |           t          j                    5 }t	          j        |d          5 }|                    |                    d                    }|                    |                    d                    }d d d            n# 1 swxY w Y   |                    d          }|                    d          }||                                z  }||                                z  }d d d            n# 1 swxY w Y   | 	                    || j
                   | 	                    || j                   Pd S )NrZ   r  r  r  )r)   rX   
contextlib	ExitStackrR   rS   enter_contextrA   rj   ri   r  r  )rD   r'   stackr   r  r  r  r  s           r(   test_read_after_closez,TestsWithMultipleOpens.test_read_after_closet
  s   4 	0 	0A""1%%%%'' '5_Q,, D"0061B1BCCF"0061B1BCCFD D D D D D D D D D D D D D D C((C((&&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' UDJ///UDJ////	0 	0s7   DAB."D.B22D5B26ADD!	$D!	c                    t          |           D ]c}t          j        |dt          j                  5 }|                    d| j                   |                    d| j                   |                    d          5 }|                    d          }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 	                    || j        d d                    t          j        |d          5 }|                    d          }|                    d          }d d d            n# 1 swxY w Y   | 	                    || j                   | 	                    || j                   ed S )NrL   r  r  r  rZ   )
r)   rR   rS   rm  rT   r  r  rA   rj   ri   rD   r'   r   r  r  r  s         r(   test_read_after_writez,TestsWithMultipleOpens.test_read_after_write
  s	   4 	0 	0AC)=>> -$fdj111fdj111YYv&& -&"KK,,E- - - - - - - - - - - - - - -- - - - - - - - - - - - - - -
 UDJtt$4555C(( *D		&))		&))* * * * * * * * * * * * * * * UDJ///UDJ////	0 	0sH   AB8?B!B8!B%%B8(B%)B88B<	?B<	;+D22D6	9D6	c                    t          |           D ]@}t          j        |dt          j                  5 }|                    d| j                   |                    d          5 }|                    d           |                    d| j                   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |d          5 }|                    d          }|                    d          }d d d            n# 1 swxY w Y   | 	                    || j                   | 	                    || j                   Bd S )NrL   r  r  r  rZ   )
r)   rR   rS   rm  rT   r  rA   rj   r  ri   r	  s         r(   test_write_after_readz,TestsWithMultipleOpens.test_write_after_read
  s   4 
	0 
	0AC)=>> 6$fdj111YYv&& 6&KK$$$MM&$*5556 6 6 6 6 6 6 6 6 6 6 6 6 6 66 6 6 6 6 6 6 6 6 6 6 6 6 6 6
 C(( *D		&))		&))* * * * * * * * * * * * * * * UDJ///UDJ////
	0 
	0sG   1B8$1B!B8!B%%B8(B%)B88B<	?B<	+DD	D	c                    t                      }|                     t                     t          j        t          d          5 }t          d          D ]E}|                    d           |                    d          5 }	 d d d            n# 1 swxY w Y   F	 d d d            n# 1 swxY w Y   |                     |t                                 d S )NrZ   rP   r   r  )	r   rX   r!   rR   rS   r5   rj   rA   ri   )rD   
startcountr   r  r  s        r(   test_many_opensz&TestsWithMultipleOpens.test_many_opens
  s>    ZZ
w'''_W3/// 	43ZZ  		&!!!YYv&& &              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 	XZZ00000s6   <B' BB'BB'BB''B+.B+c                 j   t          j        t          dt           j                  5 }|                    d| j                   d d d            n# 1 swxY w Y   t          j        t          dt           j                  5 }|                    dd          5 }|                    d          }|                    dd          5 }|                    | j	                   d d d            n# 1 swxY w Y   ||                                z  }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 
                    || j                   t          j        t                    5 }| 
                    |                    d          | j	                   d d d            d S # 1 swxY w Y   d S )NrL   r  r-  rZ   r  r  )rR   rS   r!   rm  rT   r  rA   rj   rB   r  ri   )rD   r   r1r  rg  s        r(   test_write_while_readingz/TestsWithMultipleOpens.test_write_while_reading
  s   _Wc7+?@@ 	.DMM&$*---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	._Wc7+?@@ 	#D63'' #2YYvs++ )rHHTZ((() ) ) ) ) ) ) ) ) ) ) ) ) ) )"	# # # # # # # # # # # # # # #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	
+++_W%% 	<TYYv..
;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s}   AAA>D-,DC(D(C,,D/C,0D
D-D	D-D	D--D14D1,/F((F,/F,c                 .    t          t                     d S r    r"  r  s    r(   r  zTestsWithMultipleOpens.tearDown
  r#  r4   N)r  r  r  r  r<   rX   r  r  r  r  r
  r  r  r  r  re   r4   r(   r  r  <
  s        . . [./ / /4 4 44 4 44 4 40 0 00 0 00 0 0
1 
1 
1< < <    r4   r  c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
TestWithDirectoryc                 8    t          j        t                     d S r    )rU  r  r!   r  s    r(   rF   zTestWithDirectory.setUp
  s    
r4   c           
         t          j        t          d                    5 }|                    t                     d d d            n# 1 swxY w Y   |                     t          j                            t          j        	                    t          d                               |                     t          j                            t          j        	                    t          dd                               |                     t          j        
                    t          j        	                    t          ddd                               d S )N
zipdir.zipr-  br  )rR   rS   r	   r  r!   rr   rU  r   isdirr8   r  r!  s     r(   test_extract_dirz"TestWithDirectory.test_extract_dir
  s   _Xl3344 	%OOG$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%bgll7C&@&@AABBBbgll7C&E&EFFGGGrw||GS#s'K'KLLMMMMMs   A		AAc                     t          j        t           j                            t          d                     |                                  d S Nr-  )rU  r  r   r8   r!   r  r  s    r(   test_bug_6050zTestWithDirectory.test_bug_6050
  s:    
gs++,,,r4   c           	         t           j                            t          d          }t          j        |           t          j        |          j        dz  }t          j        t          d          5 }|
                    |           |j        d         }|                     |j                            d                     |                     |j        |dz  dz             |
                    |d           |j        d         }|                     |j        d	           |                     |j        |dz  dz             d d d            n# 1 swxY w Y   t          j        t          d
          5 }|j        d         }|                     |j                            d                     |                     |j        |dz  dz             |j        d         }|                     |j        d	           |                     |j        |dz  dz             t           j                            t          d          }t          j        |           |                    |           |                     t           j                            t           j                            |d                               |                     t'          t          j        |                    d           d d d            d S # 1 swxY w Y   d S )Nr  r:  rL   r   z/x/r  yr`   zy/rZ   r  r   )rU  r   r8   r!   r  ra  st_moderR   rS   r   rB   r  rr   rg   rQ  ri   r   r  r  ro   listdir)rD   dirpathrQ   r   r!  r  s         r(   test_write_dirz TestWithDirectory.test_write_dir
  s   ',,w,,
ww'&0_VS)) 	GTJJwM!$EOOEN33E::;;;U042:2EFFFJJw$$$M!$EOOEND111U042:2EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G _VS)) 	9TM!$EOOEN33E::;;;U042:2EFFFM!$EOOEND111U042:2EFFFW\\'844FHVOOF###OOBGMM"',,vs*C*CDDEEESF!3!344a888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s&   0CEEE1E8K66K:=K:c           	      (   t          j        t           j                            t          d                     t          j        t          d          5 }|                    dd           |j	        d         }| 
                    |j        d           | 
                    |j        d           d d d            n# 1 swxY w Y   t          j        t          d          5 }|j	        d         }|                     |j                            d                     | 
                    |j        d           t           j                            t          d          }t          j        |           |                    |           |                     t           j                            t           j                            |d                               | 
                    t          j        |          dg           d d d            d S # 1 swxY w Y   d S )	Nr  rL   zx/r4   r   i ArZ   r  )rU  r  r   r8   r!   rR   rS   r   rT   r  ri   rg   r   rr   rQ  r  r  r"  )rD   r   r!  r  s       r(   test_writestr_dirz#TestWithDirectory.test_writestr_dir
  s.   
gs++,,,_VS)) 	JTMM$$$$M!$EU^T222U02HIII		J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J
 _VS)) 	8TM!$EOOEN33D99:::U02HIIIW\\'844FHVOOF###OOBGMM"',,vs*C*CDDEEERZ//#777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s&   AB88B<?B<DHHHc                    t          j        t          d          5 }|                    d           |j        d         }|                     |j        d           |                     |j        d           |                    d           |j        d         }|                     |j        d           |                     |j        d           |                    dd	
           |j        d         }|                     |j        d           |                     |j        d           t          j        d          }d|_        d|_	        d|_
        d|_        |                    |           |j        d         }|                     |j        d           |                     |j        |j                   t          j                            t          d          }t          j        |           |                    |           |                     t#          t          j        |                    h d           d d d            d S # 1 swxY w Y   d S )NrL   r{   r   
directory/i Adirectory2/r`   
directory3i  rP   r   zdirectory3/zdirectory4/r  r  >   r{   
directory2r*  
directory4)rR   rS   r   r  r  ri   rg   r   r	  CRCrx   r  rU  r   r8   r!   r  setr"  )rD   r  r!  	old_zinfo	new_zinfor  s         r(   
test_mkdirzTestWithDirectory.test_mkdir
  s_   _VS)) 	oRHH[!!!KNEU^\:::U02HIIIHH]###KNEU^];;;U02HIIIHH\H...KNEU^];;;U02HIII66I&<I#IM"#I&'I#HHYAIY/???Y4i6MNNNW\\'844FHVMM&!!!SF!3!3446m6m6mnnn;	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	o 	os   HII	I	c                 z   t          j        t          d          5 }|                    t          j        d          d           |j        d         }|                     |j        d           t          j	        
                    t          d          }t          j        |           t          j        |          j        }|                    |d           |j        d         }|                     |j        d           |                     |j        |d	z  d	z             t          j	        
                    t          d
          }t          j        |           |                    |           |                     t%          t          j        |                    ddh           d d d            d S # 1 swxY w Y   d S )NrL   r(  r8  r   r+  r)  )r  r`   r  r  r{   )rR   rS   r   rT   r	  r  ri   rg   rU  r   r8   r!   r  ra  r!  rB   r   r  r.  r"  )rD   r  r!  r{   rQ   r  s         r(    test_create_directory_with_writez2TestWithDirectory.test_create_directory_with_write  s   _VS)) 	SRKK55r:::KNEU^\:::Wl;;IHY79%%-DHHYH666KNEU^];;;U042:2EFFFW\\'844FHVMM&!!!SF!3!344{L6QRRR%	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	Ss   FF00F47F4c                     t          t                     t          j                            t
                    rt          t
                     d S d S r    )r   r!   rU  r   r  r   r   r  s    r(   r  zTestWithDirectory.tearDown*  s<    w7>>&!! 	6NNNNN	 	r4   N)r  r  r  rF   r  r  r$  r&  r1  r3  r  re   r4   r(   r  r  
  s          N N N     
9 9 948 8 8"o o o@S S S*    r4   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )ZipInfoTestsc                 p   t           j                            t                    }|                     t          j        |j                  d           |                     |	                                           |                     |j
        t          j                            t                               d S Nztest_zipfile.py)rR   r	  	from_filerO  ri   	posixpathrY  rg   r"   is_dirrx   rU  r   r;  rP  s     r(   test_from_filezZipInfoTests.test_from_file1  s    _&&x00+BK88:KLLL%%%rwx'@'@AAAAAr4   c                    t           j                            t          j        t
                              }|                     t          j        |j	                  d           | 
                    |                                           |                     |j        t          j                            t
                               d S r8  )rR   r	  r9  r   r   rO  ri   r:  rY  rg   r"   r;  rx   rU  r   r;  rP  s     r(   test_from_file_pathlikez$ZipInfoTests.test_from_file_pathlike7  s    _&&w|H'='=>>+BK88:KLLL%%%rwx'@'@AAAAAr4   c                    t           j                            t          j        t
                    d          }|                     t          j        |j	                  d           | 
                    |                                           |                     |j        t          j                            t
                               d S )Nr&   )rR   r	  r9  rU  fsencoderO  ri   r:  rY  rg   r"   r;  rx   r   r;  rP  s     r(   test_from_file_bytesz!ZipInfoTests.test_from_file_bytes=  s    _&&r{8'<'<fEE+BK88&AAA%%%rwx'@'@AAAAAr4   c                    t          t          d          5 }t          j                            |                                d          }|                     t          j        |j	                  d           | 
                    |                                           |                     |j        t          j                            t                               d d d            d S # 1 swxY w Y   d S )Nr1  r&   )rA   rO  rR   r	  r9  filenori   r:  rY  rg   r"   r;  rx   rU  r   r;  )rD   r'   r  s      r(   test_from_file_filenoz"ZipInfoTests.test_from_file_filenoC  s
   (D!! 	FQ**188::v>>BY/<<fEEERYY[[)))R\27??8+D+DEEE		F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   CC''C+.C+c                    t           j                            t           j                            t                              }t
          j                            |d          }|                     |j	        d           | 
                    |                                           |                     |j        t
          j                   |                     |j        d           d S )Nstdlib_testszstdlib_tests/r   )rU  r   rN  abspathrO  rR   r	  r9  ri   rg   rr   r;  r   r   rx   )rD   r#  r  s      r(   test_from_dirzZipInfoTests.test_from_dirJ  s    '//"'//(";";<<_&&w??o666		$$$)7+=>>>q)))))r4   N)r  r  r  r<  r>  rA  rD  rH  re   r4   r(   r6  r6  0  sk        B B BB B BB B BF F F* * * * *r4   r6  c                   X    e Zd Zd Zd Zd Zd Zd Z e            d             Z	d Z
dS )	CommandLineTestc                     t          j        ddg|R i |\  }}}|                    t          j                                        d          S )N-mrR   r  )r   r   r  rU  linesepr  )rD   argsrU   rcouterrs         r(   
zipfilecmdzCommandLineTest.zipfilecmdU  s_    $5dI @ @ @ @8>@ @C{{2:,,..666r4   c                 (    t          j        ddg|R  S )NrL  rR   )r   assert_python_failure)rD   rN  s     r(   zipfilecmd_failurez"CommandLineTest.zipfilecmd_failureZ  s    24JTJJJJr4   c                    |                                  \  }}}|                     |d           |                     d|                                           |                     d|                                           |                     d|                                           |                      dd          \  }}}|                     |d           |                     |                                d           d S )Nr4   s   usages   errors   required-lr8  )rU  ri   rp   r  assertNotEqualstrip)rD   rO  rP  rQ  s       r(   test_bad_usezCommandLineTest.test_bad_use]  s    ..00Cc"""h		,,,h		,,,k399;;///..tR88Cc"""CIIKK-----r4   c                 (   t          d          }dD ]@}|                     ||          }|                     |                                d           At          d          }|                     d|          \  }}}|                     |d           d S )Nr  )-tz--tests   Done testingztesttar.tarr\  r4   )r	   rR  ri   rstriprU  )rD   zip_nameoptrP  rO  rQ  s         r(   test_test_commandz!CommandLineTest.test_test_commandg  s    L))! 	< 	<C//#x00CSZZ\\?;;;;M**..tX>>Cc"""""r4   c                    t          d          }t          j                    }t          j        |d          5 }|                    |           d d d            n# 1 swxY w Y   |                                                    dd          }dD ]0}|                     ||d          }| 	                    ||           1d S )Nr  rZ   r.   backslashreplace)rW  z--listzascii:backslashreplace)PYTHONIOENCODING)
r	   r$   rk   rR   rS   rl   rm   r  rR  ri   )rD   r^  r[  tfexpectedr_  rP  s          r(   test_list_commandz!CommandLineTest.test_list_commandp  s    L))KMM_Xs++ 	rKKNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	::<<&&w0BCC! 	, 	,C//#x3K " M MCS(++++	, 	,s   AA!Ac                 ~   |                      t          t                     t          t          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          j        t                     |                      t          t                     t          t
          j	        
                    t          d          dd          5 }|                    d           d d d            n# 1 swxY w Y   t          t          g}t          t          dz   t          dz   g}d	D ]}	  | j        |t          g|R  }|                     |d
           t          j        t                    5 }|                     |                                |           |                     |                    |d                   d           |                     |                    |d                   d           d d d            n# 1 swxY w Y   t          t                     # t          t                     w xY wd S )NrL   r;  r<  ztest 1file.txtztest 2rM  z	/file.txt)-cz--creater4   r   s   test 1r   s   test 2)r  r   r   rA   rB   rU  r  	TESTFNDIRr   r   r8   rR  r!   ri   rR   rS   rv   rj   )rD   r'   filesrv   r_  rP  r  s          r(   test_create_commandz#CommandLineTest.test_create_command{  s   '''&#000 	AGGH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
	***"',,y*55sWMMM 	QRGGH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#IOY-DE# 		  		 C %doc7;U;;;  c***_W-- F$$R[[]]H===$$RWWXa[%9%99EEE$$RWWXa[%9%99EEEF F F F F F F F F F F F F F F
 ww		  		 sU   AA!AC55C9<C9.AH$1BH8H$H	H$H	H$$H:c                    t          d          }dD ]}t                      5 }|                     |||          }|                     |d           t	          j        |          5 }|                                D ]"}t          j        	                    ||j
                            dt          j                            }|                                r3|                     t          j                            |                     |                     t          j                            |                     t#          |d          5 }|                     |                                |                    |                     d d d            n# 1 swxY w Y   $	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nr  )-ez	--extractr4   rM  r1  )r	   r   rR  ri   rR   rS   rw   rU  r   r8   rg   r  rR  r;  rr   r  r  rA   rj   )	rD   r^  r_  r  rP  r  r  r   r'   s	            r(   test_extract_commandz$CommandLineTest.test_extract_command  st   L))$ 	H 	HC Hvooc8V<<  c***_X.. 	H" kkmm H H!w||F$&K$7$7RV$D$D F  F99;; H OOBGMM$,?,?@@@@ OOBGNN4,@,@AAA!%dD!1!1 HQ $ 0 02772;; G G GH H H H H H H H H H H H H H HH	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	HH H H H H H H H H H H H H H H	H 	Hs[   AG%C$F+	<FF+FF+FF+G+F//G2F/3GG		G	N)r  r  r  rR  rU  rZ  r`  rf  r
   rl  ro  re   r4   r(   rJ  rJ  S  s        7 7 7
K K K. . .# # #	, 	, 	, ]__    _ *H H H H Hr4   rJ  c                      e Zd ZdZd Zd Zd Zd Z ej	        e
j        d           ej	         ej        dej                  d           e            d	                                     Z ej	        e
j        d           ej	         ej        dej                  d           e            d
                                     ZdS )TestExecutablePrependedZipz@Test our ability to open zip files with an executable prepended.c                 ^    t          dd          | _        t          dd          | _        d S )Nexe_with_zipziptestdata)r  exe_with_z64)r	   exe_zip	exe_zip64r  s    r(   rF   z TestExecutablePrependedZip.setUp  s.    }EEE!.GGGr4   c                 <   |                      t          j        |          d|            t          j        |          5 }|                                D ]-}|                    |          }|                     d|           .	 d d d            d S # 1 swxY w Y   d S )Nzis_zipfile failed on s   FAVORITE_NUMBER)rr   rR   r  rS   rv   rj   rp   )rD   r=  rV   r  r9   s        r(   _test_zip_worksz*TestExecutablePrependedZip._test_zip_works  s    *400666	8 	8 	8 _T"" 	8e^^%% 8 8zz!}}0$77778	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s    ABBBc                 :    |                      | j                   d S r    )ry  rv  r  s    r(    test_read_zip_with_exe_prependedz;TestExecutablePrependedZip.test_read_zip_with_exe_prepended  s    T\*****r4   c                 :    |                      | j                   d S r    )ry  rw  r  s    r(   "test_read_zip64_with_exe_prependedz=TestExecutablePrependedZip.test_read_zip64_with_exe_prepended  s    T^,,,,,r4   zsys.executable required.z	/bin/bashz#Test relies on #!/bin/bash working.c                 |    t          j        | j        t          j        g          }|                     d|           d S Ns   number in executable: 5)
subprocesscheck_outputrv  sys
executablerp   rD   outputs     r(   test_execute_zip2z,TestExecutablePrependedZip.test_execute_zip2  s8    
 ($,)GHH0&99999r4   c                 |    t          j        | j        t          j        g          }|                     d|           d S r  )r  r  rw  r  r  rp   r  s     r(   test_execute_zip64z-TestExecutablePrependedZip.test_execute_zip64  s8    
 ($.#.)IJJ0&99999r4   N)r  r  r  r  rF   ry  r{  r}  r  
skipUnlessr  r  rU  rA  X_OKr   r  r  re   r4   r(   rq  rq    sI       JJH H H8 8 8+ + +- - - X)CDDX;88>@ @: : @ @ ED: X)CDDX;88>@ @: : @ @ ED: : :r4   rq  c                   (    e Zd Z G d d          ZdS )jaracoc                   (    e Zd Z G d d          ZdS )jaraco.itertoolsc                        e Zd Zd Zd Zd ZdS )jaraco.itertools.Counterc                 <    d| _         t          |          | _        d S r  )r  iter
_orig_iter)rD   r2   s     r(   r  z!jaraco.itertools.Counter.__init__  s    
"&q''r4   c                     | S r    re   r  s    r(   __iter__z!jaraco.itertools.Counter.__iter__  s    r4   c                 N    t          | j                  }| xj        dz  c_        |S r  )nextr  r  )rD   results     r(   __next__z!jaraco.itertools.Counter.__next__  s%    do..

a

r4   N)r  r  r  r  r  r  re   r4   r(   Counterr    sA        * * *      r4   r  N)r  r  r  r  re   r4   r(   r  r    s<        	 	 	 	 	 	 	 	 	 	r4   r  N)r  r  r  r  re   r4   r(   r  r    s<                 r4   r  c                     t           j                            |                                           D ]}|                     |d           | S )z}
    Given a writable zip file zf, inject directory entries for
    any directories implied by the presence of children.
    r4   )rR   CompleteDirs_implied_dirsrv   rT   )r  r=  s     r(   add_dirsr    sH    
 $222;;==AA  
D#Ir4   c                  @   t          j                    } t          j        | d          }|                    dd           |                    dd           |                    dd           |                    dd	           |                    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
    rL   r   s   content of azb/c.txts   content of cz	b/d/e.txts   content of ezb/f.txts   content of fz	g/h/i.txts   content of izalpharep.zip)r$   r%   rR   rS   rT   rg   )r9   r  s     r(   build_alpharep_fixturer    s    2 :<<D	s	#	#BKK)))KK	?+++KK_---KK	?+++KK_--- BKIr4   c                 F     t          j                    fd            }|S )zZ
    Given a method, wrap it in a for loop that invokes method
    with each subtest.
    c                 P    |                                  D ]} | |           d S )N)alpharep)zipfile_alpharep)rD   r  meths     r(   r  zpass_alpharep.<locals>.wrapper  s@    --// 	* 	*HD)))))	* 	*r4   )	functoolswraps)r  r  s   ` r(   pass_alpharepr    s:     _T* * * * * Nr4   c                      e Zd Zd Zd Zd Zed             Zed             Zed             Z	ed             Z
ed             Zd	 Zd
 Zd Zd Zd Zed             Zd Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             ZdZd Zd Z d Z!ed             Z"ed              Z#ed!             Z$ed"             Z%ed#             Z&ed$             Z'ed%             Z(ed&             Z)ed'             Z*ed(             Z+ed)             Z,ed*             Z-d+S ),TestPathc                 t    t          j                    | _        |                     | j        j                   d S r    )r  r  fixturesr  rI  r  s    r(   rF   zTestPath.setUp  s/    ",..+,,,,,r4   c              #     K   |                                  5  t                      V  d d d            n# 1 swxY w Y   |                                  5  t          t                                V  d d d            d S # 1 swxY w Y   d S r    )r  r  r  r  s    r(   r  zTestPath.zipfile_alpharep!  s     \\^^ 	+ 	+(*****	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+\\^^ 	5 	513344444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   488A>>BBc                 h   t          j        | j                            t	                                          }|j        }|                                 ||j        z  }|                    d          5 }|	                    |
                                           d d d            n# 1 swxY w Y   |S r>   )r   r   r  r  r   rE   rI  rg   rA   rB   rm   )rD   r  tmpdirr  r   strms         r(   zipfile_ondiskzTestPath.zipfile_ondisk'  s    dm99(**EEFF))YYt__ 	*JJv(()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   3(B''B+.B+c                    t          j        |          }|                                \  }}}|                                \  }}}|                                \  }	|                                \  }
|
                                \  }d S r    )rR   r   iterdir)rD   r  rootr-  r  gr  r'   r   r  hr2   s               r(   test_iterdir_and_typeszTestPath.test_iterdir_and_types0  sj    |H%%,,..1a ))++1ayy{{yy{{yy{{r4   c                 .    t          j        |          }d S r    rR   r   rD   r  r  s      r(   test_is_file_missingzTestPath.test_is_file_missing@      |H%%r4   c                     t          j        |          }|                                \  }}}|                     t                    5  |                                 d d d            d S # 1 swxY w Y   d S r    )rR   r   r  r   rJ  rD   r  r  r-  r  r  s         r(   test_iterdir_on_filezTestPath.test_iterdir_on_fileE  s    |H%%,,..1az** 	 	IIKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A))A-0A-c                 .    t          j        |          }d S r    r  r  s      r(   test_subdir_is_dirzTestPath.test_subdir_is_dirL  r  r4   c                    t          j        |          }|                                \  }}}|                    d          5 }|                                }d d d            n# 1 swxY w Y   |                     |d           |                    dd          5 }|                                }d d d            n# 1 swxY w Y   |                     |d           d S )Nr;  r<  zcontent of arZ   )rR   r   r  rA   rj   ri   )rD   r  r  r-  r  r  r  r9   s           r(   r   zTestPath.test_openT  s<   |H%%,,..1aVVWV%% 	99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~...VVC!! 	T99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	~.....s$   A$$A(+A(B<<C C c                    t          j                    }t          j        |d          }|                    dd                    d                     d|_        t          j        |          }|                                \  }|	                    d          }|
                    dd          5 }|                                }d d d            n# 1 swxY w Y   |                     |d           |
                    d          5 }|                                }d d d            n# 1 swxY w Y   |                     |d           d S )	NrL   zpath/16.txtzThis was utf-16zutf-16ztest_open_utf16.zipz16.txtrZ   r<  )r$   r%   rR   rS   rT   r  rg   r   r  joinpathrA   rj   ri   )rD   in_memory_filer  r  r   u16r  r9   s           r(   test_open_encoding_utf16z!TestPath.test_open_encoding_utf16_  s   _^S11
M#4#;#;H#E#EFFF+|B,,..mmH%%XXc8$$ 	99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	0111XXxX(( 	D99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	011111s$   .CCCD''D+.D+c                    t          j                    }t          j        |d          }|                    dd           d|_        t          j        |          }|                                \  }|                    d          }|	                    dd          }| 
                    |d	           |                    d
dd          5 }| 
                    |                                d           d d d            n# 1 swxY w Y   |                     t          d          5  |	                    dd          }d d d            n# 1 swxY w Y   |                    d
dd          5 }|                     t                     5  |                                 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrL   zpath/bad-utf8.bins   invalid utf-8: .z"test_read_text_encoding_errors.zipzbad-utf8.binr;  ignore)errorszinvalid utf-8: .rZ   surrogateescapeu   invalid utf-8: .r=  r<  strict)r=  r  )r$   r%   rR   rS   rT   rg   r   r  r  	read_textri   rA   rj   r  rA  r   UnicodeDecodeError)rD   r  r  r  r   r  r9   r'   s           r(   test_open_encoding_errorsz"TestPath.test_open_encoding_errorsn  s   _^S11
')DEEE:|B,,..mmN++ }}WX}661222XXc7+<X== 	GQVVXX'EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G ##Iz:: 	< 	<==7=;;D	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< XXcGHX== 	""#566                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sZ   
)C??DD%E		EE,G F(G (F,	,G /F,	0G  GGc                 "   d}t          ddd|          }|j                                        }|                     t	          |          d|j                   |                     |d         d           |                     |d         d	           d
S )z8EncodingWarning must blame the read_text and open calls.a  import 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_encodingri  r   r   s   ^<string>:8: EncodingWarning:r`   s   ^<string>:9: EncodingWarning:N)r   rQ  rn   ri   ro   assertRegex)rD   codeprocwarningss       r(   test_encoding_warningszTestPath.test_encoding_warnings  s    
  &=tTJJ8&&((X48444!&GHHH!&GHHHHHr4   c                    t          j        t          j        t          j                    d                    }|                    d                              d          5 }|                    d           ddd           n# 1 swxY w Y   |                    d                              dd	          5 }|                    d
           ddd           dS # 1 swxY w Y   dS )zo
        If the zipfile is open for write, it should be possible to
        write bytes or text to it.
        rL   rP   zfile.binr?   s   binary contentsNrh  r;  r<  z	text file)rR   r   rS   r$   r%   r  rA   rB   )rD   r  r  s      r(   r  zTestPath.test_open_write  sE   
 \'/"*,,SAAABB[[$$))$// 	+4JJ)***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+[[$$))#)@@ 	$DJJ{###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s$   "BBB9CC #C c                    t          j        t          t                                          }|                     t
                    5  |                    d                                           ddd           dS # 1 swxY w Y   dS )zJ
        Attempting to open a directory raises IsADirectoryError.
        r  N)rR   r   r  r  r   IsADirectoryErrorr  rA   r  s     r(   test_open_extant_directoryz#TestPath.test_open_extant_directory       \(#9#;#;<<==011 	$ 	$KK!!###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$   (A==BBc                    t          j        |          }|                     t                    5  |                    d                              dd           d d d            n# 1 swxY w Y   |                     t                    5  |                    d                              dd           d d d            d S # 1 swxY w Y   d S )Nr   r1  r;  r<  )rR   r   r   rJ  r  rA   r  s      r(   test_open_binary_invalid_argsz&TestPath.test_open_binary_invalid_args  sJ   |H%%z** 	@ 	@MM'""''w'???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@z** 	7 	7MM'""''g666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s#   +A&&A*-A**CC	Cc                    t          j        t          t                                          }|                     t
                    5  |                    d                                           ddd           dS # 1 swxY w Y   dS )zR
        Attempting to open a missing directory raises FileNotFoundError.
        r  N)rR   r   r  r  r   FileNotFoundErrorr  rA   r  s     r(   test_open_missing_directoryz$TestPath.test_open_missing_directory  r  r  c                     t          j        |          }|                                \  }}}|                    d           d S )Nr;  )rR   r   r  r  r  s         r(   r  zTestPath.test_read  s<    |H%%,,..1a	Gr4   c                     t          j        |          }|                    d          }|                    d                              d                              d          }d S Nr   r  r   e.txtrR   r   r  rD   r  r  r-  r  s        r(   test_joinpathzTestPath.test_joinpath  sS    |H%%MM'""MM#'',,55g>>r4   c                 \    t          j        |          }|                    ddd          }d S )Nr  r   r  r  )rD   r  r  r  s       r(   test_joinpath_multiplezTestPath.test_joinpath_multiple  s*    |H%%MM#sG,,r4   c                 N    t          j        |          }|dz  }|dz  dz  dz  }d S r  r  r  s        r(   test_traverse_truedivzTestPath.test_traverse_truediv  s1    |H%%7N3Jw&r4   c                 J    t          dddd          }t          |           dS )zI
        Disable the __future__.division when testing traversal.
        zzipfile.Path(alpharep) / 'a'z(test)evalT)sourcerg   rQ   dont_inheritN)compiler  )rD   r  r  s      r(   test_traverse_simpledivz TestPath.test_traverse_simplediv  s5    
 1	
 
 
 	T




r4   c                     |                      |          }t          j        t          |                    }t	          j        |           dS )zN
        zipfile.Path should be constructable from a path-like object
        N)r  r   r   ru   rR   )rD   r  r  pathlikes       r(   test_pathlike_constructionz#TestPath.test_pathlike_construction  sD    
 ,,X66<N 3 344Xr4   c                 \    t          j        |          }|t          j        d          z   d S r  )rR   r   r   r  s      r(   test_traverse_pathlikezTestPath.test_traverse_pathlike  s,    |H%%w|C      r4   c                 .    t          j        |          }d S r    r  r  s      r(   test_parentzTestPath.test_parent  r  r4   c                 .    t          j        |          }d S r    r  r  s      r(   test_dir_parentzTestPath.test_dir_parent  r  r4   c                 .    t          j        |          }d S r    r  r  s      r(   test_missing_dir_parentz TestPath.test_missing_dir_parent  r  r4   c                     t          j        |          }|                                \  }}}|                    dd           |                    dd           |dz                                  \  }dS )zk
        If the underlying zipfile is changed, the Path object should
        reflect that change.
        r  r   zbar/baz.txtrb  r  N)rR   r   r  rT   )rD   r  r  r-  r  r  rb  s          r(   test_mutabilityzTestPath.test_mutability  so     |H%%,,..1a)U+++-/// ,''))r4   i    c                     t          j                    }t          j        |d          }t	          t
          t          | j                            D ]}|                    ||           d|_	        |S )zACreate a read-only zipfile with a huge number of entries entries.rL   rZ   )
r$   r%   rR   rS   mapru   r5   HUGE_ZIPFILE_NUM_ENTRIESrT   rQ   )rD   r  r  entrys       r(   huge_zipfilezTestPath.huge_zipfile  se    z||_T3''eD$ABBCC 	& 	&EKKu%%%%	r4   c                     t          j        |                                           }t          j                            |                                          }|D ]}|                    d           dS )zE
        Ensure joinpath on items in zipfile is linear time.
        suffixN)rR   r   r  r  r  r  r  r  )rD   r  entriesr  s       r(   test_joinpath_constant_timez$TestPath.test_joinpath_constant_time!  sk     |D--//00"**4<<>>:: 	% 	%ENN8$$$$	% 	%r4   c                 v    d t          d          D             }t          j                            |           d S )Nc                 l    g | ]1}d                      t          j        t          |          z             2S )rM  )r8   stringascii_lowercaseru   )r1   r  s     r(   r3   z:TestPath.test_implied_dirs_performance.<locals>.<listcomp>.  s2    PPPa/#a&&899PPPr4   r  )r5   rR   r  r  r  s     r(   test_implied_dirs_performancez&TestPath.test_implied_dirs_performance-  s8    PP5<<PPP**400000r4   c                    |                      |          }t          j        |          5 }t          d          D ]+}t          j        |d                              d           ,	 d d d            d S # 1 swxY w Y   d S )Nr   r   r;  r<  )r  rR   rS   r5   r   r  )rD   r  r[   reps       r(   test_read_does_not_closez!TestPath.test_read_does_not_close1  s    &&x00_X&& 	H$Qxx H HT7++55w5GGGGH	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   <A44A8;A8c                 L     G d dt           j                  } ||          }d S )Nc                       e Zd ZdS )(TestPath.test_subclass.<locals>.SubclassN)r  r  r  re   r4   r(   Subclassr  :  s        Dr4   r  r  )rD   r  r  r  s       r(   test_subclasszTestPath.test_subclass8  sC    	 	 	 	 	w| 	 	 	 x!!r4   c                 .    t          j        |          }d S r    r  r  s      r(   test_filenamezTestPath.test_filename@  r  r4   c                 .    t          j        |          }dS )zH
        The name of the root should be the name of the zipfile
        Nr  r  s      r(   test_root_namezTestPath.test_root_nameE  s    
 |H%%r4   c                 R    t          j        |          }|dz  }|dz  dz  }|dz  }dS )
        The suffix of the root should be the suffix of the zipfile.
        The suffix of each nested file is the final component's last suffix, if any.
        Includes the leading period, just like pathlib.Path.
        r   r  filename.tar.gzr   Nr  rD   r  r  r  r  r   s         r(   test_suffixzTestPath.test_suffixM  s>     |H%% 7N 3J** 3Jr4   c                 \    t          j        |          }|dz  }|dz  dz  }|dz  }|dz  }dS )r  r   r  r  r   z.hgrcNr  )rD   r  r  r  r  r   r  s          r(   test_suffixeszTestPath.test_suffixes`  sI     |H%% 7N 3J** 3J 7Nr4   c                 <    d |_         t          j        |          }d S r    )rg   rR   r   r  s      r(   test_suffix_no_filenamez TestPath.test_suffix_no_filenamev  s     |H%%r4   c                 R    t          j        |          }|dz  }|dz  dz  }|dz  }dS )z>
        The final path component, without its suffix
        r   r  r  r   Nr  r  s         r(   	test_stemzTestPath.test_stem}  s>    
 |H%% 7N 3J** 3Jr4   c                 F    t          j        |          }d|j        _        d S )Nzfoo/bar.zip)rR   r   r  rg   r  s      r(   test_root_parentzTestPath.test_root_parent  s!    |H%%*	r4   c                 *   d|_         t          j        |          }|                     t                    5  |j         ddd           n# 1 swxY w Y   |                     t                    5  |j         ddd           n# 1 swxY w Y   |dz  }dS )zd
        It is an error to attempt to get the name
        or parent of an unnamed zipfile.
        Nr  )rg   rR   r   r   rA  r=  parent)rD   r  r  subs       r(   test_root_unnamedzTestPath.test_root_unnamed  s
    !|H%%y)) 	 	II	 	 	 	 	 	 	 	 	 	 	 	 	 	 	y)) 	 	KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Sjs#   A

AA/BB
Bc                     t          dt          j        fi           }|                                 D ]%} ||                              d          j        }&d S )N	PathChildzsome dir)typerR   r   r  r  r(  )rD   r  r;   r[   s       r(   test_inheritancezTestPath.test_inheritance  s\    ;44--// 	) 	)H3x==))*55<DD	) 	)r4   c                     |                      |          }t          j        |          }t          j        |           |                    |j                   dS )zU
        A zip file wrapped in a Path should extract even with implied dirs.
        N)r  rR   rS   r   r  r(  )rD   r  source_pathr  s       r(   #test_extract_orig_with_implied_dirsz,TestPath.test_extract_orig_with_implied_dirs  sQ    
 ))(33_[))R
k()))))r4   N).r  r  r  rF   r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r"  r$  r&  r*  r.  r1  re   r4   r(   r  r    s       - - -5 5 5     ] : : ]:   ] & & ]& / / ]/2 2 2  2I I I&	$ 	$ 	$$ $ $ 7 7 ]7$ $ $ 1 1 ]1 ? ? ]? ? ? ]?
 ? ? ]? 
 
 ]
   ] ! ! ]! 4 4 ]4
 - - ]-
 7 7 ]7 8 8 ]8  '  	> 	> 	>1 1 1 H H ]H 0 0 ]0 = = ]= A A ]A   ]$     ] * 7 7 ]7 : : ]:$ 2 2 ]2   ]" ) ) ]) * * ]* * *r4   r  c                       e Zd Zg dZd                    d          d                    d          d                    d          gZd Zd	 Zd
 Zd Z	d Z
d Zd Zd Zd Zd ZdS )EncodedMetadataTests)u   一u   二u   三zThis is pure ASCII.
r.   u%   これは現代的日本語です。
r;  u"   これは古い日本語です。
	shift_jisc                    |                      t          t                     ddg| j        dd          z   }t	          j        t          d          5 }t          || j                  D ]&\  }}|                    ||t          j	                   '	 d d d            n# 1 swxY w Y   t          t          d          5 }|                                }d d d            n# 1 swxY w Y   t          | j        |d d                   D ]A\  }}|                    |                    d          |                    d                    }Bt          t          d	          5 }|                    |           d d d            d S # 1 swxY w Y   d S )
Nn1n2r   rL   rP   r1  r.   r4  r?   )r  r   r   
file_namesrR   rS   r   file_contentrT   r   rA   rj   r  r  rB   )rD   placeholdersrd  tempr  r9   r=  s          r(   rF   zEncodedMetadataTests.setUp  s$   ''' d|doabb&99_V#... 	?"!$\43D!E!E ? ?gD'7+=>>>>?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? &$ 	27799D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	do|BQB/?@@ 	: 	:JD$<<G 4 4 $K 8 8: :DD&$ 	2HHTNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   =BB!B:CC"CE==FFc                 \   |                                 }|                     t          |          t          |                     |                                }d |D             }|                     t          |          t          |                     t	          ||          D ]\  }}|                    |          }|                     |j        |           |                     |j        t          |                     |                     |	                    |          |           d S )Nc                     g | ]	}|j         
S re   rf   )r1   r  s     r(   r3   z3EncodedMetadataTests._test_read.<locals>.<listcomp>  s    ------r4   )
rv   ri   sortedrw   r   ry   rg   rx   ro   rj   )	rD   rV   expected_namesr  r   r   r=  r  r   s	            r(   
_test_readzEncodedMetadataTests._test_read  s     ~(>(>???   --u---~(>(>??? !1ABB 	8 	8MD'==&&DT]D111T^S\\:::UZZ--w7777		8 	8r4   c                     t          j        t          dd          5 }|                     || j        | j                   d d d            d S # 1 swxY w Y   d S )NrZ   r4  metadata_encoding)rR   rS   r   r@  r8  r9  r*  s     r(    test_read_with_metadata_encodingz5EncodedMetadataTests.test_read_with_metadata_encoding  s    _VSKHHH 	GEOOE4?D4EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   "AAAc                     d | j         d d         D             | j         dd          z   }t          j        t          d          5 }|                     ||| j                   d d d            d S # 1 swxY w Y   d S )Nc                 ^    g | ]*}|                     d                               d          +S r4  cp437r  r  r1   r=  s     r(   r3   zLEncodedMetadataTests.test_read_without_metadata_encoding.<locals>.<listcomp>  B     ; ; ;" ++k2299'BB ; ; ;r4   r   rZ   r8  rR   rS   r   r@  r9  rD   r?  rV   s      r(   #test_read_without_metadata_encodingz8EncodedMetadataTests.test_read_without_metadata_encoding  s    ; ;&*obqb&9; ; ;=A_QRR=PQ_VS)) 	FUOOE>43DEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   A..A25A2c                     d | j         d d         D             | j         dd          z   }t          j        t          dd          5 }|                     ||| j                   d d d            d S # 1 swxY w Y   d S )Nc                 ^    g | ]*}|                     d                               d          +S )r4  koi8-urI  rJ  s     r(   r3   zSEncodedMetadataTests.test_read_with_incorrect_metadata_encoding.<locals>.<listcomp>  sB     ; ; ;" ++k2299(CC ; ; ;r4   r   rZ   rQ  rB  rL  rM  s      r(   *test_read_with_incorrect_metadata_encodingz?EncodedMetadataTests.test_read_with_incorrect_metadata_encoding  s    ; ;&*obqb&9; ; ;=A_QRR=PQ_VSHEEE 	FOOE>43DEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   A00A47A4c                 @   |                      t                    5  t          j        t          dd           d d d            n# 1 swxY w Y   |                      t                    5  t          j        t          dd           d d d            d S # 1 swxY w Y   d S )NrZ   r.   rB  r;  )r   r  rR   rS   r   r  s    r(   +test_read_with_unsuitable_metadata_encodingz@EncodedMetadataTests.test_read_with_unsuitable_metadata_encoding  s:    122 	D 	DOFC7CCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D122 	D 	DOFC7CCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds#   AAA)BBBc                 (   d}d | j         d d         D             | j         dd          z   }|                    |           g | j        dR }t          j        t
          d          5 }|                    |d           |                     t          |	                                          t          |                     d d d            n# 1 swxY w Y   t          j        t
          d          5 }| 
                    |||           d d d            n# 1 swxY w Y   t          j        t
          dd	          5 }|                     t          |	                                          t          |                     t          t          ||                    D ]\  }\  }}|                    |          }|                     |j        |           |                     |j        t!          |                     |dk     rM|                     t          j                  5  |                    |           d d d            n# 1 swxY w Y   |                     |                    |          |           	 d d d            d S # 1 swxY w Y   d S )
Nu   四c                 ^    g | ]*}|                     d                               d          +S rG  rI  rJ  s     r(   r3   z?EncodedMetadataTests.test_read_after_append.<locals>.<listcomp>  rK  r4   r   s
   newcontentr-  
newcontentrZ   r4  rB  )r8  r   r9  rR   rS   r   rT   ri   r>  rv   r@  	enumerater   ry   rg   rx   ro   r   r  rj   )	rD   newnamer?  r  rV   r2   r=  r  r   s	            r(   test_read_after_appendz+EncodedMetadataTests.test_read_after_append  s   ; ;&*obqb&9; ; ;=A_QRR=PQg&&&>T.>>>_VS)) 	OUNN7L111VENN$4$455vn7M7MNNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O _VS)) 	EUOOE>3CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E _VSKHHH 
	@EVENN$4$455vn7M7MNNN&/NDT0U0U&V&V @ @"?D'}}T**  555  W>>>q55**7+=>> ) )

4((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) $$UZZ%5%5w????@
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@ 
	@s\   'ACCC1DDD<C%J!I7JIJ
I.JJJc                     t           j        }dD ]C}|                     t          d          5   |d|d           d d d            n# 1 swxY w Y   Dd S )N)rL   r  r-  z^metadata_encoding is onlyznonesuch.zipr4  rB  )rR   rS   r  rJ  )rD   ZFrQ   s      r(   !test_write_with_metadata_encodingz6EncodedMetadataTests.test_write_with_metadata_encoding   s    _# 	H 	HD''
(DF F H H>4;GGGGH H H H H H H H H H H H H H H	H 	Hs   AA	A	c                 .   d}g d}t                      5 }t                      5 }|                     t          t          j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |                                d           |                     ||                                           t                      5 }t	          j        ddt          g           d d d            n# 1 swxY w Y   |                                }t                      5 }t	          j        ddt          g           d d d            n# 1 swxY w Y   |                                }| j
        D ]}|                     ||           d S )Nz/Non-conforming encodings not supported with -c.)--metadata-encoding=shift_jisri  nonesuchr`  r8  r_  r\  rW  )r   r   r   
SystemExitrR   mainri   rm   rp   r   r8  )rD   errmsgrN  stdoutstderrlistingr=  s          r(   test_cli_with_metadata_encodingz4EncodedMetadataTests.test_cli_with_metadata_encoding'  s   BNNN 	B& "" Bf!!*glDAAAB B B B B B B B B B B B B B B	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	**B///ffoo//000 	J&L94HIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J//## 	J&L94HIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J//##O 	) 	)DMM$((((	) 	)sX   A.'AA.A	A.A	A..A25A2D  DD-EEEc                    t          j        t                     |                     t          t                     | j        D ]m}	 t          j        t           j                            t          |                     ;# t          $ r Y Gt          $ r |                     d|           Y jw xY wt          j        ddt          t          g           t          j        t                    }| j        D ]}|                     ||           d S )Nzcannot encode file name r_  rn  )rU  r  r!   r  r   r8  ra  r   r8   r  UnicodeEncodeErrorr`  rR   rb  r   r"  rp   )rD   r}   rf  r=  s       r(   'test_cli_with_metadata_encoding_extractz<EncodedMetadataTests.test_cli_with_metadata_encoding_extract:  s   
((( / 	A 	ABAWb112222   % A A A???@@@@@A 	5tVWMNNN*W%%O 	) 	)DMM$((((	) 	)s   7A<<
B,!B,+B,N)r  r  r  r8  r  r9  rF   r@  rD  rN  rR  rT  rZ  r]  rg  rj  re   r4   r(   r3  r3    s       ///J&&w//T[[\cddNUUVabbL  (8 8 8"G G G
F F FF F FD D D@ @ @4H H H) ) )&) ) ) ) )r4   r3  c                   *    e Zd ZdZd Zd Zd Zd ZdS )StripExtraTestsr`   c                 2   t          j        d          }|                    | j        d          }|                    dd          }|                    dd          }|                     dt          j        || j        f                     |                     |t          j        || j        f                     |                     |dz   t          j        |dz   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     d S )Nr  r   r   r  r4      zrc  Structr  ZIP64_EXTRAri   rR   _strip_extrarD   r  r-  r  r  s        r(   test_no_datazStripExtraTests.test_no_dataT  s}   M%  FF4#Q''FF1aLLFF1aLLg21t7G6IJJKKKG0T5E4GHHIIIdFG(4$2B1DEE	G 	G 	G 	1g21Q3q54;K:MNNOOO1g21Q3q54;K:MNNOOO1g21Q3q54;K:MNNOOOOOr4   c                 D   t          j        d          }|                    | j        d          dz   }|                    dd          dz   }|                    dd          dz   }|                     dt          j        || j        f                     |                     |t          j        || j        f                     |                     |d	z   t          j        |d	z   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     |                     ||z   t          j        ||z   |z   | j        f                     d S )
Nr  r`   rr  r      bbr  s   cccr4   rn  ro  rs  s        r(   test_with_datazStripExtraTests.test_with_datac  s   M%  FF4#Q''$.FF1aLL5 FF1aLL6!g21t7G6IJJKKKG0T5E4GHHIIIdFG(4$2B1DEE	G 	G 	G 	1g21Q3q54;K:MNNOOO1g21Q3q54;K:MNNOOO1g21Q3q54;K:MNNOOOOOr4   c                    t          j        d          }|                    | j        d          dz   }|                    dd          dz   }|                     dt          j        ||z   | j        f                     |                     dt          j        ||z   |z   | j        f                     |                     dt          j        ||z   dz   | j        f                     |                     |dz   t          j        ||z   |z   dz   | j        f                     |                     |t          j        ||z   |z   | j        f                     |                     |t          j        ||z   |z   | j        f                     |                     |t          j        ||z   |z   | j        f                     d S )Nr  r`   rr  r   rv  r4   rn  ro  )rD   r  r-  r  s       r(   test_multipleszStripExtraTests.test_multiplesr  s   M%  FF4#Q''$.FF1aLL5 g21Q39I8KLLMMMg21Q3q54;K:MNNOOO'&qs4x$2B1DEE	G 	G 	GdFG(1Qtd6F5HII	K 	K 	K 	G01Q9I8KLLMMMG01Q9I8KLLMMMG01Q9I8KLLMMMMMr4   c                 ~   |                      dt          j        d| j        f                     |                      dt          j        d| j        f                     |                      dt          j        d| j        f                     |                      dt          j        d| j        f                     d S )Nr4   rn  s   zzs   zzz)ri   rR   rr  rq  r  s    r(   test_too_shortzStripExtraTests.test_too_short  s    g239I8KLLMMMw3D4;K:MNNOOO7'0@/BCC	E 	E 	EG($2B1DEE	G 	G 	G 	G 	Gr4   N)r  r  r  rq  rt  rw  ry  r{  re   r4   r(   rl  rl  M  se        
 KP P PP P PN N N G G G G Gr4   rl  __main__)ar+  r  importlib.utilrU  r$   r  rU  r   r:  r  rc  r  r  test.support.script_helperr   rs   r  unittest.mockrs  rR   r  tempfiler   r   r   r   test.supportr   r	   r
   r   r   r   r   r   test.support.os_helperr   r   r   r   r   r   r!   rj  r6   DATAFILES_DIRr  r)   r+   TestCaser  ri  rr  rw  r|  r  r  r  r  r   r1  r4  r6  r8  r:  r  r  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r6  rJ  rq  tupleconsumer  r  r  r  r  r3  rl  r  rb  re   r4   r(   <module>r     s}            				     				            



 7 7 7 7 7 7              # " " " " " - - - - - - - - - - & & & & & &                                
 3,SL	#T T T
# # #Q Q Q Q Q Q Q QhJ J J J J ; ( 1J J JD H H H H H!<!)!2H H H $ $ $ $ $:'0$ $ $ # # # # #9&/# # #
O O O O O O O Od\0 \0 \0 \0 \0"?"*"3\0 \0 \0~ ' ' ' ' '#@#+#4' ' ' $ $ $ $ $!>!)!2$ $ $ # # # # # = ( 1# # #
 D  D  D  D  D  D  D  DD% % % % %+X-> % % % ' ' ' ' ',h.? ' ' ' $ $ $ $ $*H,= $ $ $ # # # # #)8+< # # #~ ~ ~ ~ ~X& ~ ~ ~B} } } } }8$ } } }@S S S S S" S S Sl       >
 
 
 
 
+X-> 
 
 
 
7 
7 
7 
7 
7,h.? 
7 
7 
7     *H,=    & & & & &)8+< & & &q q q q qh' q q qhX; X; X; X; X; X; X; X;v% % % % %'I'/'8% % % ' ' ' ' '(J(0(9' ' ' $ $ $ $ $&H&.&7$ $ $ # # # # #%G%-%6# # #               4@ 4@ 4@ 4@ 4@h' 4@ 4@ 4@n z z z z zX. z z zzs s s s s) s s sl *  *  *  *  *8$  *  *  *FMH MH MH MH MHh' MH MH MH`%: %: %: %: %:!2 %: %: %:R           ! ! !H  ]* ]* ]* ]* ]*x  ]* ]* ]*@N) N) N) N) N)8, N) N) N)b;G ;G ;G ;G ;Gh' ;G ;G ;G| zHMOOOOO r4   