
    daf3                       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mZ d dlmZmZmZ d dl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&m'Z' e!dz   Z(e!d	z   Z)d
Z*dZ+g dZ,d Z- G d d      Z. G d de.ej^                        Z0 e        G d de.ej^                               Z1 e        G d de.ej^                               Z2 e        G d de.ej^                               Z3 G d d      Z4 G d de4ej^                        Z5 e        G d de4ej^                               Z6 e        G d de4ej^                               Z7 e        G d  d!e4ej^                               Z8 G d" d#      Z9 G d$ d%e9ej^                        Z: e        G d& d'e9ej^                               Z; e        G d( d)e9ej^                               Z< e        G d* d+e9ej^                               Z= G d, d-ej^                        Z> G d. d/ej^                        Z? G d0 d1ej                  ej^                        Z@ G d2 d3ej^                        ZA G d4 d5      ZB G d6 d7eBej^                        ZC e        G d8 d9eBej^                               ZD e        G d: d;eBej^                               ZE e        G d< d=eBej^                               ZF G d> d?ej^                        ZG G d@ dA      ZH G dB dCeHej^                        ZI e        G dD dEeHej^                               ZJ e        G dF dGeHej^                               ZK e        G dH dIeHej^                               ZL G dJ dK      ZM G dL dM      ZN G dN dOej^                        ZO e        G dP dQej^                               ZP G dR dSej^                        ZQ G dT dUej^                        ZR G dV dWej^                        ZS G dX dYej^                        ZT G dZ d[ej^                        ZU G d\ d]ej^                        ZVeWd^k(  r ej                          yy)_    N)TemporaryFile)randintrandom	randbytes)archiver_tests)script_helper)findfilerequires_zlibrequires_bz2requires_lzmacaptured_stdoutcaptured_stderrrequires_subprocess)TESTFNunlinkrmtreetemp_dirtemp_cwdfd_countFakePath2d  zipfile_datafiles))	_ziptest1
1q2w3e4r5t)zziptest2dir/_ziptest2
qawsedrftg)z!ziptest2dir/ziptest3dir/_ziptest3
azsxdcfvgb)z-ziptest2dir/ziptest3dir/ziptest4dir/_ziptest3
6y7u8i9o0pc              #   (  K   t          t               5 }| | j                  |j                         d d d        t	        j
                         5 }| | j                  |j                         d d d        y # 1 sw Y   FxY w# 1 sw Y   y xY wwN)TESTFN2r   assertFalseclosedioBytesIO)testfs     6/root/Python-3.12.4/Lib/test/test_zipfile/test_core.py	get_filesr*   )   s{     
M	 #A"# 
 #"# ## ## #s3   B A:B B1	B:B?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" Z$y)$AbstractTestsWithSourceFilec           	          t        t              D cg c]  }t        d|t               fz  d       c}| _        dj                  | j                        | _        y c c}w )Nz'Zipfile test line %d. random float: %f
ascii    )rangeFIXEDTEST_SIZEbytesr   line_genjoindata)clsis     r)   
setUpClassz&AbstractTestsWithSourceFile.setUpClass3   sW     "'~!68 H &(m,-46 8 88CLL)8s    Ac                     t        t        d      5 }|j                  | j                         d d d        y # 1 sw Y   y xY wNwbopenr   writer5   selffps     r)   setUpz!AbstractTestsWithSourceFile.setUp:   3    &$ 	 2HHTYY	  	  	    6?Nc                    ||d}t        j                  |dfi |5 }|j                  t        d       |j                  t        t               |j	                  d| j
                         |j                  dd      5 }| j                  D ]  }|j                  |        	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N)compressioncompresslevelwanother.namestrfilewritten-open-wmode)zipfileZipFiler>   r   writestrr5   r=   r3   )r@   r(   rF   rG   kwargszipfplines          r)   make_test_archivez-AbstractTestsWithSourceFile.make_test_archive?   s    !,}M__Q.v. 	"%KK/KK'NN9dii0,37 "1 MM "DGGDM""		" 	"" "		" 	"s$   A B>=#B2!B>2B;	7B>>Cc           	         | j                  |||       t        j                  |d|      5 }| j                  |j	                  t
              | j                         | j                  |j	                  d      | j                         | j                  |j	                  d      | j                         t        j                         }|j                  |       |j                         }|j                         }| j                  t        |      d       | j                  d|d          | j                  d|d          | j                  d	|d          |d
   j                         \  }}	}
}| j                  |d       | j                  t!        j"                  |	d             | j                  t!        j"                  |
d             | j                  |t%        t        | j                                     |j'                         }| j                  t        |      d       | j                  t
        |       | j                  d|       | j                  d|       | j                  d|       |j)                         }|D cg c]  }|j*                   }}| j                  t        |      d       | j                  t
        |       | j                  d|       | j                  d|       | j                  d|       |D ]1  }| j                  |j,                  t        | j                               3 t
        dddfD ]^  }|j/                  |      }| j                  |j*                  |       | j                  |j,                  t        | j                               ` | j1                  |j3                                d d d        y c c}w # 1 sw Y   y xY w)NrrI   rJ   )file   	File Namer   ModifiedSize   %Y-%m-%d%H:%M:%S   rK   )rT   rN   rO   assertEqualreadr   r5   r%   StringIOprintdirgetvalue
splitlineslenassertInsplit
assertTruetimestrptimestrnamelistinfolistfilename	file_sizegetinfoassertIsNonetestzip)r@   r(   rF   rG   rR   rA   	directorylinesfndatetime_sizenamesinfosr7   nminfos                    r)   zip_testz$AbstractTestsWithSourceFile.zip_testJ   s   q+}= __Q[1 1	/UUZZ/;UZZ7CUZZ	2DII> BNNN#I((*ESZ+MM+uQx0MM*eAh/MM&%(+$)!HNN$4!BeTR0OODMM$
;<OODMM%<=T3s499~#67 NN$ESZ+MM&%(MM.%0MM)U+MM*E2 NN$E)./AQZZ/E/SZ+MM&%(MM.%0MM)U+MM*E2 >  c$))n=> ~y:JK A}}R(  3  TYY@A emmo.c1	/ 1	/@ 0A1	/ 1	/s   IO>OD)OOOc                 \    t        |       D ]  }| j                  || j                           y r!   r*   r~   rF   r@   r(   s     r)   
test_basicz&AbstractTestsWithSourceFile.test_basic   )    4 	/AMM!T--.	/r/   c                 t   | j                  ||       t        j                  |d|      5 }g }|j                  t              5 }	 |j                  d      }|sn|j                  |       &	 d d d        g }|j                  d      5 }	 |j                  d      }|sn|j                  |       &	 d d d        | j                  dj                  |      | j                         | j                  dj                  |      | j                         d d d        y # 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   y xY wNrV      rI   r/   )
rT   rN   rO   r=   r   ra   appendr`   r4   r5   )	r@   r(   rF   rR   zipdata1zipopen1	read_datazipdata2zipopen2s	            r)   zip_open_testz)AbstractTestsWithSourceFile.zip_open_test   s(   q+. __Q[1 	<UHF# /x (c 2I$OOI.	  	/ HN+ /x (c 2I$OOI.	  	/ SXXh/;SXXh/;%	< 	</ // /	< 	<s<   D.(D+D.(D"/AD.D	D."D+	'D..D7c                 \    t        |       D ]  }| j                  || j                           y r!   r*   r   rF   r   s     r)   	test_openz%AbstractTestsWithSourceFile.test_open   +    4 	4Aq$"2"23	4r/   c                    t        t              }| j                  || j                         t	        j
                  |d| j                        5 }| j                  |j                  t               d d d        y # 1 sw Y   y xY wNrV   )	r   r"   r   rF   rN   rO   assertIsInstancero   rl   )r@   pathrR   s      r)   test_open_with_pathlikez3AbstractTestsWithSourceFile.test_open_with_pathlike   sc     4!1!12__T3(8(89 	7U!!%..#6	7 	7 	7s   !A77B c                    | j                  ||       t        j                  |d|      5 }g }|j                  t              5 }	 |j                  t        dd            }|sn|j                  |       0	 d d d        | j                  dj                  |      | j                         d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY wNrV   r\      r/   )rT   rN   rO   r=   r   ra   r   r   r`   r4   r5   )r@   r(   rF   rR   r   r   r   s          r)   zip_random_open_testz0AbstractTestsWithSourceFile.zip_random_open_test   s    q+. __Q[1 		<UHF# /x (ga.> ?I$OOI.	  	/ SXXh/;		< 		</ /		< 		<s#   B=2B153B=1B:	6B==Cc                 \    t        |       D ]  }| j                  || j                           y r!   r*   r   rF   r   s     r)   test_random_openz,AbstractTestsWithSourceFile.test_random_open   +    4 	;A%%a)9)9:	;r/   c                 |   | j                  ||       t        j                  |d      5 }|j                  t              5 }g }	 |j                  d      }|sn|j                  |       &	 d d d        d d d        | j                  dj                        | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)NrV   r/   )
rT   rN   rO   r=   r   read1r   r`   r4   r5   r@   r(   rF   rR   zipopenzipdatar   s          r)   zip_read1_testz*AbstractTestsWithSourceFile.zip_read1_test   s    q+. __Q$ 	*ZZ	*#*G#MM"-	 y)	  	* 	* 	'*DII6	* 	* 	* 	*s"   B2*B&*B2&B/	+B22B;c                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   
test_read1z&AbstractTestsWithSourceFile.test_read1   s+    4 	5A4#3#34	5r/   c                    | j                  ||       t        j                  |d      5 }|j                  t              5 }g }	 |j                  d      }| j                  t        |      d       |sn|j                  |       A	 d d d        d d d        | j                  dj                        | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)NrV   
   r/   )rT   rN   rO   r=   r   r   assertLessEqualrf   r   r`   r4   r5   r   s          r)   zip_read1_10_testz-AbstractTestsWithSourceFile.zip_read1_10_test   s    q+. __Q$ 	*ZZ	*#*G#MM"-	$$S^R8 y)  	* 	* 	'*DII6	* 	* 	* 	*s#   CACCC
	CCc                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   test_read1_10z)AbstractTestsWithSourceFile.test_read1_10   +    4 	8A""1d&6&67	8r/   c                 t   | j                  ||       t        j                  |d      5 }|j                  t              5 }d}	 |j                         }|sn||z  }|j                  d      }|sn||z  }2d d d        d d d        | j                  | j                         y # 1 sw Y   .xY w# 1 sw Y   2xY w)NrV   r/   d   )	rT   rN   rO   r=   r   readlinera   r`   r5   )r@   r(   rF   rR   r   r5   ra   s          r)   zip_readline_read_testz2AbstractTestsWithSourceFile.zip_readline_read_test   s    q+. __Q$ 	ZZ	#*D'')||C( 	 	 	tyy)	 	 	 	s"   B.6B"5B."B+	'B..B7c                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   test_readline_readz.AbstractTestsWithSourceFile.test_readline_read   s+    4 	=A''4+;+;<	=r/   c                 :   | j                  ||       t        j                  |d      5 }|j                  t              5 }| j
                  D ]$  }|j                         }| j                  ||       & 	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )rT   rN   rO   r=   r   r3   r   r`   )r@   r(   rF   rR   r   rS   linedatas          r)   zip_readline_testz-AbstractTestsWithSourceFile.zip_readline_test   s    q+. __Q$ 	5F# 5w MM 5D&//1H$$Xt455	5 	55 5	5 	5s"   B4B4BB	
BBc                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   test_readlinez)AbstractTestsWithSourceFile.test_readline  r   r/   c                 T   | j                  ||       t        j                  |d      5 }|j                  t              5 }|j                         }d d d        t        | j                        D ]  \  }}| j                  ||        	 d d d        y # 1 sw Y   CxY w# 1 sw Y   y xY wr   )	rT   rN   rO   r=   r   	readlineszipr3   r`   )r@   r(   rF   rR   r   ziplinesrS   ziplines           r)   zip_readlines_testz.AbstractTestsWithSourceFile.zip_readlines_test  s    q+. __Q$ 	0F# /w",,./!$T]]H!= 0g  $/0	0 	0/ /	0 	0s"   BB8BB	BB'c                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   test_readlinesz*AbstractTestsWithSourceFile.test_readlines  +    4 	9A##At'7'78	9r/   c                 4   | j                  ||       t        j                  |d      5 }|j                  t              5 }t        | j                  |      D ]  \  }}| j                  ||        	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )rT   rN   rO   r=   r   r   r3   r`   )r@   r(   rF   rR   r   rS   r   s          r)   zip_iterlines_testz.AbstractTestsWithSourceFile.zip_iterlines_test  s    q+. __Q$ 	4F# 4w%(%@ 4MD'$$Wd344	4 	44 4	4 	4s"   B1B1BB	BBc                 \    t        |       D ]  }| j                  || j                           y r!   )r*   r   rF   r   s     r)   test_iterlinesz*AbstractTestsWithSourceFile.test_iterlines  r   r/   c                    t        j                  t        d| j                        5 }|j	                  dd       ddd       t        j                  t        d| j                        5 }|j                  d      5 }| j                  |j                  d      d       | j                  |j                  d      d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   yxY w)	z>Check for cases where compressed data is larger than original.rH   rJ   12NrV   r\      1   2)rN   rO   r"   rF   rP   r=   r`   ra   )r@   rR   openobjs      r)   test_low_compressionz0AbstractTestsWithSourceFile.test_low_compression#  s     __Wc4+;+;< 	,NN9d+	, __Wc4+;+;< 	8I& 8'  a$7  a$78	8 	8		, 	,
8 8	8 	8s0   C&C$8AC;C$CC!	C$$C-c                     t        j                  t        d      }|j                  dd| j                         |j                  d      }| j                  |j                  | j                         y )NrH   b.txthello worldcompress_type)rN   rO   r"   rP   rF   rq   r`   r   )r@   rR   r}   s      r)   test_writestr_compressionz5AbstractTestsWithSourceFile.test_writestr_compression/  sT    -wT=M=MN}}W%++T-=-=>r/   c                    t        j                  t        dd      }|j                  dd| j                         |j                  dd| j                  d	       |j                  d      }| j                  |j                  | j                         | j                  |j                  d       |j                  d      }| j                  |j                  | j                         | j                  |j                  d       y )
NrH   r\   rG   a.txtr   r   r      )r   rG   )	rN   rO   r"   rP   rF   rq   r`   r   _compresslevel)r@   rR   a_infob_infos       r)   test_writestr_compresslevelz7AbstractTestsWithSourceFile.test_writestr_compresslevel5  s    A>wT=M=MNwT=M=M%& 	 	( w'--t/?/?@..2 w'--t/?/?@..2r/   c                    dD ]  }|dz   }t        |      }t        j                  t        j                         d| j
                        5 }|j                  d|       |j                  dd      5 }|j                  |      }| j                  t        |      |       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)N)r\   i  i   i  i @  r\   rH   foorV   )r   rN   rO   r%   r&   rF   rP   r=   ra   r`   rf   )r@   	test_sizerp   junkzipfrA   bufs          r)   test_read_return_sizez1AbstractTestsWithSourceFile.test_read_return_sizeE  s     6 	:I!AIY'DsD4D4DE :eT*YYuc* :b''),C$$SXy9:: :	:
: :: :s$   	%B:.-B.B:.B73B::C	c                    t        j                         }t        j                  |d      5 }|j	                  d| j
                  | j                         |j                         }d d d        |j                         }t        j                  |      }t        j                  |      5 }|j                  d      5 }|j                  dz
         | j                  t              5  |j                          d d d        d d d        d d d        t        j                  |      }t        j                  |      5 }|j                  d      5 }|j                  dz
         | j                  t              5  |j                  d      r	 |j                  d      rd d d        d d d        d d d        t        j                  |      }t        j                  |      5 }|j                  d      5 }|j                  dz
         | j                  t              5  |j                  d      r	 |j                  d      rd d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   sxY w# 1 sw Y   xxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   rxY w# 1 sw Y   vxY w# 1 sw Y   y xY w)NrH   rL   rJ   r      r   )r%   r&   rN   rO   rP   r5   rF   tellrd   r=   truncateassertRaisesEOFErrorra   r   )r@   rA   r   
end_offsetzipfiledatar   s         r)   test_truncated_zipfilez2AbstractTestsWithSourceFile.test_truncated_zipfileQ  sG   ZZ\__Rc* 	#dMM)TYYd>N>NMOJ	# kkmZZ$__R  	#D9% #JO,&&x0 #LLN##	# ZZ$__R  	D9% JO,&&x0 !,,s+ ",,s+	 ZZ$__R  	D9% JO,&&x0 !--, "--,	 	+	# 	## ## #	# 	#  	 	  	 	s   9I'I:9*I-#I 4I-<I:6J*J2$JJJK+*J7$J+:J7KI I*%I--I7	2I::JJJJ	JJ(+J40J77K 	<KKc                    d}t        |       D ]  }t        j                  |d| j                        5 }|j	                  t
        |       t        |      }| j                  d|       d d d        t        j                  |d      5 }t        |      }t        |t              r| j                  d|z  |       n| j                  d|z  |       | j                  d|       t        |j                  |            }| j                  d|z  |       | j                  d|       | j                  d	|       | j                  t        j                  k7  r$| j                  d
|       | j                  d|       |j                  |      5 }t        |      }| j                  d|z  |       | j                  d|       | j                  t        j                  k7  r| j                  d
|       d d d        | j                  dt                     d d d        | j                  dt                      y # 1 sw Y   xY w# 1 sw Y   XxY w# 1 sw Y   AxY w)Nz	file.namerH   zmode='w'rV   zfilename=%rzfile=%rzmode='r'z	filemode=z
file_size=zcompress_type=zcompress_size=zname=%rz[closed])r*   rN   rO   rF   r>   r   reprrg   
isinstancerl   rq   
ZIP_STOREDr=   )r@   fnamer(   rR   rV   r   s         r)   	test_reprz%AbstractTestsWithSourceFile.test_repro  s   4 	3AC)9)9: -eFE*Kj!,-
 C( 9EKa%MM-!"3Q7MM)a-3j!,u-.me3Q7k1-lA.##w'9'99MM"2A6MM"2A6ZZ& ;'WAMM)e"3Q7MM*a0''7+=+==&6:; j$w-8)9* MM*d5k27	3- -&; ;9 9s1   4H/C>IA"H<%#I/H9	<III	c                 `    t        |       D ]   }| j                  || j                  d       " y )N	   r   r   r   s     r)   test_compresslevel_basicz4AbstractTestsWithSourceFile.test_compresslevel_basic  s/    4 	@AMM!T--QM?	@r/   c                 v   t        j                  t        dd      5 }|j                  t        d       |j                  t        dd       |j                  d      }|j                  d      }| j                  |j                  d       | j                  |j                  d       ddd       y# 1 sw Y   yxY w)zTCheck that files within a Zip archive can have different
        compression levels.rH   r\   r   
compress_1
compress_9r   N)rN   rO   r"   r>   r   rq   r`   r   )r@   rR   one_info	nine_infos       r)   test_per_file_compresslevelz7AbstractTestsWithSourceFile.test_per_file_compresslevel  s     __Wc; 	:uKK-KKAK>}}\2Hl3IX44a8Y55q9	: 	: 	:s   B	B//B8c                     G fddt         j                        }d	  |       }d t        j                  |d| j                        5 }|j                  dd      5 }|j                  d       d d d        d	 |j                  dd      5 }|j                  d       d d d        	 d d d d        t        j                  t        j                  |j                                     5 }| j                  |j                         ddg       | j                  |j                  d      d       | j                  |j                  d      d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# t        $ r d	z  Y nw xY w	 d n# d w xY w	 d d d        n# 1 sw Y   nxY wt        j                  t        j                  |j                                     5 }| j                  |j                         dg       | j                  |j                  d      d       d d d        n# 1 sw Y   nxY w# 1 sw Y   y xY w)
Nc                   $     e Zd Z fdZ xZS )CAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFilec                 H    k(  rt         dz  t        | 	  |       y )Nr\   )OSErrorsuperr>   )r@   r5   	__class__countstops     r)   r>   zIAbstractTestsWithSourceFile.test_writing_errors.<locals>.BrokenFile.write  s*    $}%QJEd#r/   )__name__
__module____qualname__r>   __classcell__)r   r  r  s   @r)   
BrokenFiler     s    $ $r/   r  r   rH   file1s   data1file2s   data2r\   )r%   r&   rN   rO   rF   r=   r>   r   rd   r`   rm   ra   )r@   r  testfilerR   r(   r  r  s        @@r)   test_writing_errorsz/AbstractTestsWithSourceFile.test_writing_errors  s   	$ 	$ !|HE30@0@A !UZZ- &GGH%&!GS1 *Q)*
  E!" __RZZ(9(9(;<= 	<U^^-/ABUZZ0(;UZZ0(;	< 	<!& &* * AID !EDEE! ! ! H,=,=,?!@A @U  !1G9=  G!4h?@ @ @! (	< 	<s   FE1
F<E/E# E/)F)A%H4E 	F#E,	(E//F =F?F  FFFFF!AH&&H/4H=c                    d}t        j                  t        d      5 }|j                  |d       d d d        t        j                  t        d      5 }|j	                  |      5 }| j                  |j                  |       | j                  t        j                  |j                         | j                  |j                  d       | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                   d       d d d        | j                  j                   d       | j                  |j                  |       | j                  |j                  d       | j                  t        j                  |j                         | j                  t"        |j                         | j                  |j                         d       | j                  t"        |j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nsomefile.txtrH   rL   bogusrV   TF)rN   rO   r"   rP   r=   r`   namer   r%   UnsupportedOperationfilenorM   assertIsreadablewritableseekabler$   
ValueErrorr@   r   rR   fids       r)   test_zipextfile_attrsz1AbstractTestsWithSourceFile.test_zipextfile_attrs  s   __W3/ 	+5NN5'*	+ __W3/ 	85E" 1c  51!!""9"93::F  3/cllnd3cllne4cllnd3cjj%01 MM#**d+SXXu-SXXs+b55szzBj#,,7MM#,,.%0j#,,7	8 	8	+ 	+1 1	8 	8s1   H4I&CIC&I4H>I
	IIc                 @    t        t               t        t               y r!   r   r   r"   r@   s    r)   tearDownz$AbstractTestsWithSourceFile.tearDown      vwr/   r!   )%r  r  r  classmethodr8   rB   rT   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,   2   s    * * 
	"5/n/<047<;757 8*(=
580949
8?3 
:<3>@	:"<H8,r/   r,   c                   |    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y)StoredTestsWithSourceFileNc                 2   | j                  ||       t        j                  |d      5 }|j                  d      }| j	                  |j
                  d       |j                  d      }| j	                  |j
                  d       d d d        y # 1 sw Y   y xY w)NrV   rJ     rK   )rT   rN   rO   rq   r`   external_attr)r@   r(   rF   rR   zinfozinfo2s         r)   zip_test_writestr_permissionsz7StoredTestsWithSourceFile.zip_test_writestr_permissions  s    
 	q+.__Q$ 	@MM),EU00+>]]#34FV11;?	@ 	@ 	@s   ABBc                 d    t        |       D ]"  }| j                  |t        j                         $ y r!   )r*   r(  rN   r   r   s     r)   test_writestr_permissionsz3StoredTestsWithSourceFile.test_writestr_permissions  s-    4 	FA..q'2D2DE	Fr/   c                 j   t        j                  t        dt         j                        5 }|j	                  t
        d       d d d        t        j                  t        dt         j                        5 }| j                  |j                         dg       d d d        y # 1 sw Y   ]xY w# 1 sw Y   y xY w)NrH   	/absoluterV   absoluterN   rO   r"   r   r>   r   r`   rm   r@   rR   s     r)   test_absolute_arcnamesz0StoredTestsWithSourceFile.test_absolute_arcnames  s    __Wc7+=+=> 	-%KK,	- __Wc7+=+=> 	=%U^^-
|<	= 	=	- 	-	= 	=s   B2"B)B&)B2c                    t        j                  t        dt         j                        5 }|j	                  t
        t
               ddd       t        j                  t        dt         j                        5 }|j                  d| j                         | j                  |j                         t
        dg       ddd       y# 1 sw Y   ~xY w# 1 sw Y   yxY w)z&Test appending to an existing zipfile.rH   NarJ   )
rN   rO   r"   r   r>   r   rP   r5   r`   rm   r/  s     r)   test_append_to_zip_filez1StoredTestsWithSourceFile.test_append_to_zip_file  s    __Wc7+=+=> 	(%KK'	( __Wc7+=+=> 	D%NN9dii0U^^-	/BC	D 	D	( 	(	D 	Ds   C6ACCCc                    d}t        t        d      5 }|j                  |       ddd       t        j                  t        dt        j
                        5 }|j                  t        t               ddd       t        t        d      5 }|j                  t        |             t        j                  |d      5 }| j                  |j                         t        g       | j                  |j                  t              | j                         ddd       ddd       t        t        d      5 }| j                  |j                  t        |            |       |j                         }ddd       t        j                        5 }t        j                  |      5 }| j                  |j                         t        g       | j                  |j                  t              | j                         ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   RxY w# 1 sw Y   yxY w)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;   Nr2  rbrV   )r=   r"   r>   rN   rO   r   r   seekrf   r`   rm   ra   r5   r%   r&   )r@   r5   r(   rR   r   bios         r)   test_append_to_non_zip_filez5StoredTestsWithSourceFile.test_append_to_non_zip_file  s    )'4  	AGGDM	 __Wc7+=+=> 	(%KK'	( '4  	@AFF3t9C( @E  !1F8<  F!3TYY?@	@
 '4  	#AQVVCI.5&&(K	# ZZ$ 	<W__S-A 	<UU^^-x8UZZ/;	< 	< 	<	 		( 	(
@ @	@ 	@
	# 	#	< 	< 	< 	<sm   HH	1H*:AHH*/;H7IAI2IHHH'	"H**H47I I	IIc                    t        j                         5 }t        j                  |dt        j                        5 }|j                  t        t               d d d        |j                         }d d d        d}t        t        d      5 }|j                  |       |j                         d d d        t        j                  t              5 }| j                  |j                         t        g       | j                  |j                  t              | j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrH   r5  r;   )r%   r&   rN   rO   r   r>   r   rd   r=   r"   r`   rm   ra   r5   r@   r8  rR   r   r5   r(   s         r)   test_read_concatenated_zip_filez9StoredTestsWithSourceFile.test_read_concatenated_zip_file  s   ZZ\ 	)Sc7+=+=> ,%FF+,,,.K	) )'4  	!AGGDMGGK 	! __W% 	<U^^-x8UZZ/;	< 	<, ,	) 	)
	! 	!	< 	<s;   &D6D*D6#EAE*D3	/D66D?EEc                    t        j                         5 }t        j                  |dt        j                        5 }|j                  t        t               d d d        |j                         }d d d        ddz  }t        t        d      5 }|j                  |       |j                         d d d        t        j                  t        d      5 }| j                  |j                         t        g       |j                  d| j                         d d d        t        t        d      5 }| j                  |j                  t        |            |       |j                         }d d d        t        j                        5 }t        j                  |      5 }| j                  |j                         t        dg       | j                  |j                  t              | j                         | j                  |j                  d      | j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   AxY w# 1 sw Y   xY w# 1 sw Y   RxY w# 1 sw Y   y xY w)NrH   s   I am not a ZipFile!i@B r;   r2  rJ   r6  )r%   r&   rN   rO   r   r>   r   rd   r=   r"   r`   rm   rP   r5   ra   rf   r;  s         r)   $test_append_to_concatenated_zip_filez>StoredTestsWithSourceFile.test_append_to_concatenated_zip_file'  s   ZZ\ 	)Sc7+=+=> ,%FF+,,,.K	) &g-'4  	!AGGDMGGK 	! __Wc* 	1eU^^-x8NN9dii0	1 '4  	#AQVVCI.5&&(K	# ZZ$ 	?W__S-A 	?UU^^-	/BCUZZ/;UZZ	2DII>	? 	? 	?, ,	) 	)
	! 	!	1 	1	# 	#	? 	? 	? 	?sl   &H7H*H7#IAI*;II6BI*I6*H4	/H77IIII'*I3	/I66I?c                    t        j                  t        dt         j                        5 }|j	                  t
        t
               d d d        t        t        dd      5 }|j	                  d       d d d        t        j                  t        d      5 }| j                  |t         j                         d d d        y # 1 sw Y   yxY w# 1 sw Y   YxY w# 1 sw Y   y xY w)NrH   r2  utf-8encodingz
   rV   )rN   rO   r"   r   r>   r   r=   r   r@   rR   r(   s      r)   test_ignores_newline_at_endz5StoredTestsWithSourceFile.test_ignores_newline_at_end=  s    __Wc7+=+=> 	(%KK'	('31 	%QGGO$	%__Wc* 	:e!!%9	: 	:		( 	(	% 	%	: 	:s#   B=C	!C=C	CCc                    t        j                  t        dt         j                        5 }d|_        |j                  t        t               d d d        t        t        dd      5 }|j                  d       d d d        t        j                  t        d      5 }| j                  |t         j                         | j                  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   uxY w# 1 sw Y   y xY w)NrH      this is a commentr2  r@  rA  zabcdef
rV   )
rN   rO   r"   r   commentr>   r   r=   r   r`   rC  s      r)   )test_ignores_stuff_appended_past_commentszCStoredTestsWithSourceFile.test_ignores_stuff_appended_past_commentsE  s    __Wc7+=+=> 	(%0EMKK'	( '31 	"QGGL!	"__Wc* 	Be!!%9U]],@A	B 	B	( 	(	" 	"	B 	Bs#   "C &C,=C8 C),C58Dc                 <   t        j                  t        d      5 }|j                  t               t        t        d      5 }| j                  |j                  t              |j                                ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)z`Check that calling ZipFile.write without arcname specified
        produces the expected result.rH   r6  N)rN   rO   r"   r>   r   r=   r`   ra   rC  s      r)   test_write_default_namez1StoredTestsWithSourceFile.test_write_default_nameO  sz     __Wc* 	?eKKfd# ?q  F!3QVVX>?	? 	?? ?	? 	?s#   &B4B5BB	BBc                 h   d}t        j                  t        d| j                        5 }|j	                  |d       d d d        t        j                  t        d      5 }|j                  |      5 }|j                          | j                  |j                  d       | j                  t        |j                         | j                  t        |j                  d       | j                  t        |j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)	Nr  rH   rM   rF   r  rV   rL   Tr   )rN   rO   r"   rF   rP   r=   closer  r$   r   r  ra   r7  r   r  s       r)   test_io_on_closed_zipextfilez6StoredTestsWithSourceFile.test_io_on_closed_zipextfileW  s    __W3D<L<LM 	+QVNN5'*	+ __W3/ 	85E" 8c		cjj$/!!*chh7!!*chh:!!*chh78	8 	8	+ 	+8 8	8 	8s0   DD(1BD?D(DD%	!D((D1c                    t        j                  t        d      5 }|j                  dd       ddd       t        j                  t        d      5 }| j	                  t
        |j                  t               ddd       t        j                  t        d      5 }| j	                  t
              5  |j                  t        d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   oxY w# 1 sw Y   *xY w# 1 sw Y   yxY w)z[Check that trying to call write() on a readonly ZipFile object
        raises a ValueError.rH   rL   r  r  NrV   )	rN   rO   r"   rP   r   r  r>   r   r=   r/  s     r)   test_write_to_readonlyz0StoredTestsWithSourceFile.test_write_to_readonlyd  s     __W3/ 	45NN>73	4 __W3/ 	?5j%++v>	? __W3/ 	-5"":. -

6
,-	- 	-	4 	4	? 	?- -	- 	-s;   C&C&C>1C2	C>C#&C/2C;	7C>>Dc                    t        j                  t        d       t        j                  t
        d      5 }| j                  t        |j                  t               d d d        t        j                  t
        dd      5 }|j                  t               |j                  t              }| j                  |j                  d       d d d        y # 1 sw Y   uxY w# 1 sw Y   y xY w)N)r   r   rH   Fstrict_timestampsi  r\   r\   r   r   r   )osutimer   rN   rO   r"   r   r  r>   rq   r`   	date_time)r@   rR   r&  s      r)   test_add_file_before_1980z3StoredTestsWithSourceFile.test_add_file_before_1980q  s    
 __Wc* 	?ej%++v>	? __WcUC 	EuKKMM&)EU__.CD	E 	E	? 	?	E 	Es   &C?ACCC$c                    d}	 t        j                  |       	 t	        j
                  t        ||f       t	        j                  t              j                  }|dk7  r| j                  d|       t        j                  t        d      5 }| j                  t        j                  |j                  t               d d d        t        j                  t        dd	      5 }|j                  t               |j!                  t              }| j#                  |j$                  d
       d d d        y # t        $ r | j                  d| d       Y 8w xY w# t        $ r | j                  d       Y <w xY w# 1 sw Y   xY w# 1 sw Y   y xY w)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=rH   FrR  )i;           ;   r]  )rj   	localtimeOverflowErrorskipTestrU  rV  r   statst_mtime_nsrN   rO   r"   r   structerrorr>   rq   r`   rW  )r@   tsmtime_nsrR   r&  s        r)   test_add_file_after_2107z2StoredTestsWithSourceFile.test_add_file_after_2107|  sR   	HNN2	MHHVb"X& 776?..*+ MMI{KL__Wc* 	AefllEKK@	A __WcUC 	JuKKMM&)EU__.HI	J 	J-  	HMMOB4/EFG	H  	MMMKL	M	A 	A	J 	Js;   D0 E 0E6 AF0EEE32E36E?F)r  r  r  rN   r   rF   r   r(  r*  r0  r3  r9  r<  r>  rD  rH  rJ  rN  rP  rX  rg  r   r/   r)   r"  r"    s_    $$K@F=D<.<?,:B?8-	EJr/   r"  c                   *    e Zd Zej                  Zd Zy)DeflateTestsWithSourceFilec                    t        j                  t        d      5 }|j                  t        dt         j
                         |j                  t        dt         j                         |j                  d      }|j                  d      }| j                  |j                  t         j
                         | j                  |j                  t         j                         ddd       y# 1 sw Y   yxY w)zUCheck that files within a Zip archive can have different
        compression options.rH   storeme	deflatemeN)
rN   rO   r"   r>   r   r   ZIP_DEFLATEDrq   r`   r   )r@   rR   sinfodinfos       r)   test_per_file_compressionz4DeflateTestsWithSourceFile.test_per_file_compression  s     __Wc* 	HeKK	7+=+=>KKW-A-ABMM),EMM+.EU00'2D2DEU00'2F2FG	H 	H 	Hs   CC%%C.N)r  r  r  rN   rm  rF   rp  r   r/   r)   ri  ri    s     &&K	Hr/   ri  c                   $    e Zd Zej                  Zy)Bzip2TestsWithSourceFileNr  r  r  rN   	ZIP_BZIP2rF   r   r/   r)   rr  rr         ##Kr/   rr  c                   $    e Zd Zej                  Zy)LzmaTestsWithSourceFileNr  r  r  rN   ZIP_LZMArF   r   r/   r)   rw  rw         ""Kr/   rw  c                   @    e Zd Zed        Zd Zd Zd Zd Zd Z	d Z
y)	AbstractTestZip64InSmallFilesc                 ^    d t        dt              D        }dj                  |      | _        y )Nc              3   :   K   | ]  }t        d |z  d        yw)zTest of zipfile line %d.r.   N)r2   .0r7   s     r)   	<genexpr>z;AbstractTestZip64InSmallFiles.setUpClass.<locals>.<genexpr>  s%      7 4q8'B 7s   r      
)r0   r1   r4   r5   )r6   r3   s     r)   r8   z(AbstractTestZip64InSmallFiles.setUpClass  s(    7"1n57::h'r/   c                    t         j                  | _        t         j                  | _        dt         _        dt         _        t        t        d      5 }|j                  | j                         d d d        y # 1 sw Y   y xY w)Nr   r   r;   )	rN   ZIP64_LIMIT_limitZIP_FILECOUNT_LIMIT_filecount_limitr=   r   r>   r5   r?   s     r)   rB   z#AbstractTestZip64InSmallFiles.setUp  s`    )) ' ; ;"&'# &$ 	 2HHTYY	  	  	 s   A66A?c           	      ,   t        j                  |d|d      5 }|j                  t        d       |j                  t        t               |j	                  d| j
                         d d d        t        j                  |d|      5 }| j                  |j                  t              | j
                         | j                  |j                  d      | j
                         | j                  |j                  d      | j
                         t        j                         }|j                  |       |j                         }|j                         }| j                  t        |      d       | j                  d|d	          | j                  d
|d	          | j                  d|d	          |d   j                         \  }}}	}
| j                  |d       | j!                  t#        j$                  |d             | j!                  t#        j$                  |	d             | j                  |
t'        t        | j
                                     |j)                         }| j                  t        |      d       | j                  t        |       | j                  d|       | j                  d|       |j+                         }|D cg c]  }|j,                   }}| j                  t        |      d       | j                  t        |       | j                  d|       | j                  d|       |D ]1  }| j                  |j.                  t        | j
                               3 t        ddfD ]^  }|j1                  |      }| j                  |j,                  |       | j                  |j.                  t        | j
                               ` | j3                  |j5                                d d d        y # 1 sw Y   xY wc c}w # 1 sw Y   y xY w)NrH   T
allowZip64rI   rJ   rV   r_   rY   r   rZ   r[   r\   r]   r^      )rN   rO   r>   r   rP   r5   r`   ra   r%   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   )r@   r(   rF   rR   rA   rt   ru   rv   rw   rx   ry   rz   r{   r7   r|   r}   s                   r)   r~   z&AbstractTestZip64InSmallFiles.zip_test  s   __Q[TB 	1eKK/KK'NN9dii0	1 __Q[1 /	/UUZZ/;UZZ7CUZZ	2DII> BNN2I((*ESZ+MM+uQx0MM*eAh/MM&%(+$)!HNN$4!BeTR0OODMM$
;<OODMM%<=T3s499~#67 NN$ESZ+MM&%(MM.%0MM)U+ NN$E)./AQZZ/E/SZ+MM&%(MM.%0MM)U+ >  c$))n=> ~y9 A}}R(  3  TYY@A emmo._/	/ /	/	1 	1L 0A/	/ /	/s,   AO8I P
PDP
8PP

Pc                 \    t        |       D ]  }| j                  || j                           y r!   r   r   s     r)   r   z(AbstractTestZip64InSmallFiles.test_basic  r   r/   c                    t        j                  t        d| j                  d      }d|_        d}t        |      D ]   }|j                  d|z  d|dz  d	z  z         " | j                  t        |j                               |       |j                          t        j                  t        d
| j                        }| j                  t        |j                               |       t        |      D ]@  }|j                  d|z        j                  d      }| j                  |d|dz  d	z  z         B |j                          y )NrH   Tr  r      foo%08d%dr  9   rV   r.   )rN   rO   r   rF   debugr0   rP   r`   rf   rm   rM  ra   decode)r@   r   numfilesr7   zipf2contents         r)   test_too_many_filesz1AbstractTestZip64InSmallFiles.test_too_many_files	  s    vsD,<,<*.0
x 	=AMM)a-A);<	=T]]_-x8

T-=-=>U^^-.9x 	:AjjQ/66w?GWdadRi&89	: 	r/   c                    t        j                  t        d| j                  d      }d|_        d}t        |      D ]   }|j                  d|z  d|dz  d	z  z         " | j                  t        |j                               |       | j                  t         j                        5  |j                  d|z  d
       d d d        | j                  t        |j                               |       |j                          t        j                  t        d| j                  d      }d|_        | j                  t        |j                               |       | j                  t         j                        5  |j                  d|z  d
       d d d        | j                  t        |j                               |       |j                          t        j                  t        d| j                  d      }d|_        | j                  t        |j                               |       d}t        ||      D ]   }|j                  d|z  d|dz  d	z  z         " | j                  t        |j                               |       |j                          t        j                  t        d| j                        }| j                  t        |j                               |       t        |      D ]@  }|j                  d|z        j                  d      }| j                  |d|dz  d	z  z         B |j                          y # 1 sw Y   ~xY w# 1 sw Y   xY w)NrH   Fr  r   r   r  r  r  r  r/   r2  Tr  rV   r.   )rN   rO   r   rF   r  r0   rP   r`   rf   rm   r   LargeZipFilerM  ra   r  )r@   r   r  r7   	numfiles2r  r  s          r)   test_too_many_files_appendz8AbstractTestZip64InSmallFiles.test_too_many_files_append  s   vsD,<,<*/1
x 	=AMM)a-A);<	=T]]_-x8w334 	5MM)h.4	5T]]_-x8

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

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

T-=-=>U^^-.	:y! 	:AjjQ/66w?GWdadRi&89	: 	;	5 	5	5 	5s   'L94M9MMc                     | j                   t        _        | j                  t        _        t        t               t        t               y r!   )r  rN   r  r  r  r   r   r"   r  s    r)   r  z&AbstractTestZip64InSmallFiles.tearDownC  s*    "kk&*&;&;#vwr/   N)r  r  r  r  r8   rB   r~   r   r  r  r  r   r/   r)   r|  r|    s6     ( (
 7/r/&%Nr/   r|  c                   t    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y)StoredTestZip64InSmallFilesc                     t        j                  |d|d      5 }| j                  t         j                  |j                  t
        d       d d d        y # 1 sw Y   y xY wNrH   Fr  rI   )rN   rO   r   r  r>   r   r@   r(   rF   rR   s       r)   large_file_exception_testz5StoredTestZip64InSmallFiles.large_file_exception_testN  sQ    __Q[UC 	Cug22#kk6>C	C 	C 	Cs   1AAc                     t        j                  |d|d      5 }| j                  t         j                  |j                  d| j
                         d d d        y # 1 sw Y   y xY wr  )rN   rO   r   r  rP   r5   r  s       r)   large_file_exception_test2z6StoredTestZip64InSmallFiles.large_file_exception_test2S  sU    __Q[UC 	Iug22#nnndiiI	I 	I 	Is   7AA#c                     t        |       D ]B  }| j                  |t        j                         | j	                  |t        j                         D y r!   )r*   r  rN   r   r  r   s     r)   test_large_file_exceptionz5StoredTestZip64InSmallFiles.test_large_file_exceptionX  sC    4 	CA**1g.@.@A++Aw/A/AB	Cr/   c                 n   t        j                  t        dt         j                  d      5 }|j	                  t
        d       d d d        t        j                  t        dt         j                        5 }| j                  |j                         dg       d d d        y # 1 sw Y   ]xY w# 1 sw Y   y xY w)NrH   Tr  r,  rV   r-  r.  r/  s     r)   r0  z2StoredTestZip64InSmallFiles.test_absolute_arcnames]  s    __Wc7+=+=(,. 	-16KK,	- __Wc7+=+=> 	=%U^^-
|<	= 	=		- 	-	= 	=s   B4"B+B(+B4c                    t        j                  t        dd      5 }|j                  d| j                         d d d        t        j                  t        dd      5 }|j                  d      }|j                  }d d d        t        j                  t        dd      5 }|j                  d| j                         d d d        t        j                  t        dd      5 }|j                  d      }| j                  |j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   y xY w)NrH   Tr  rJ   rV   r2  strfile2)rN   rO   r"   rP   r5   rq   extrar`   )r@   rR   r&  r  s       r)   test_appendz'StoredTestZip64InSmallFiles.test_appende  s    __Wcd; 	1uNN9dii0	1__Wcd; 	 uMM),EKKE	  __Wcd; 	2uNN:tyy1	2__Wcd; 	1uMM),EU[[%0	1 	1	1 	1	  	 	2 	2	1 	1s/   DD$ D0!.D<D!$D-0D9<Ec                 H   d}d}g }	g }
|}|r&d}|r"|	j                  |       |
j                  |       t        j                  d|      }|}|r&d}|r"|	j                  |       |
j                  |       t        j                  d|      }|}|rd}|r|
j                  |       t        j                  d|      }t        j                  ddt        |	      z  z   ddt        |	      z  g|	 }t        j                  ddt        |
      z  z   ddt        |
      z  g|
 }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<Hr_   s   test.txt   test1234s   PK       ! %s   PK--       ! %s
           s   PK,       - -s                 s
            s   PK    l       s      s   PK      :   2 s       )r   rc  packrf   )r@   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_fieldsrp   compress_sizeheader_offsetlocal_extracentral_extracentral_dir_sizeoffset_to_central_dirlocal_extra_lengthcentral_extra_lengthro   r  filename_lengthzip64_contentss                           r)   make_zip64_filez+StoredTestZip64InSmallFiles.make_zip64_files  s     !	"I"))+6$++K8KKi0	#&M""))+6$++K8D-8,&M"$++,@AD-8kkC.///c$%%
  	
 C0111c&''
 "	
 ";;tR!c:N6O2O-OP &D"q3?Q;R7R2R S#[[q1s;M7N3N/NO%{{4Q=Q9R5R1RS ++dCM: L  !	!
    P	P 
   ## ::   !" #& ?'?( N)N* :+:, -. $/$2 M3M4 58 N9N: ";" 	B r/   c                    | j                  d      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  dt        j                        j                                | j                  ddd      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  dt        |j                        j                                | j                  d      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  dt        |j                        j                                | j                  ddddd      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  d	t        |j                        j                                | j                  d
ddd      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  d	t        |j                        j                                | j                  ddd
d      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  d	t        |j                        j                                | j                  d
d
d      }| j                  t        j                        5 }t        j                  t        j                  |             ddd       | j                  d	t        |j                        j                                y# 1 sw Y   xY w# 1 sw Y   @xY w# 1 sw Y   xY w# 1 sw Y   ,xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)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   rN   
BadZipFilerO   r%   r&   rg   rl   	exceptionlower)r@   missing_file_size_extraemissing_compress_size_extramissing_header_offset_extras        r)   test_bad_zip64_extraz0StoredTestZip64InSmallFiles.test_bad_zip64_extra  s   $ #'"6"6! #7 #
 w112 	AaOOBJJ'>?@	Ak3q{{#3#9#9#;< '+&:&:! !% '; '
#
 w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@ '+&:&:!% '; '
# w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@
 '+&:&:! !% $!% '; '
# w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@ '+&:&:"!% $!%	 '; '
# w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@ '+&:&:! !&!%	 '; '
# w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@ '+&:&:"!&!% '; '
#
 w112 	EaOOBJJ'BCD	Eos1;;'7'='='?@O	A 	A	E 	E	E 	E	E 	E	E 	E	E 	E	E 	EsS   )P#	)P0)P=7)Q
)Q')Q$>)Q1#P-0P:=Q
QQ!$Q.1Q: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 ]  }	|j	                  |	        t        j                  t        j                   | j                  d	i |            5 }
|
j                         d   }| j                  |j                  |       | j                  |j                  |       | j                  |j                  |       | j                  |
j                  |      |       d d d          y # 1 sw Y   xY w)
Nr  r   r  T)r  r  )r  r  )r  r  r\   r   )r0   rf   	itertoolscombinationsupdaterN   rO   r%   r&   r  rn   r`   rp   r  r  ra   )r@   expected_file_sizeexpected_compress_sizeexpected_header_offsetexpected_contentparamsrV   comborQ   czfr&  s               r)    test_generated_valid_zip64_extraz<StoredTestZip64InSmallFiles.test_generated_valid_zip64_extra4  sO   !"!"&
 "&$?%)$G%)$G
 q#f+/* 
	GA"//: 	G %AMM!$%__RZZ0D0D0D0Nv0N%OP GTVKKM!,E$$U__6HI$$U%8%8:PQ$$U%8%8:PQ$$RWWU^5EFG G		G
	G
G Gs   B	D55D>c                    t        j                         }t        j                  |dd      5 }|j	                  ddd      5 }|j                  d       ddd       ddd       |j                         }t        j                  d|dd	       \  }}}}}	}
}}}}}}}}}| j                  |d
       | j                  |t        j                         | j                  |d       | j                  |d       | j                  |	d       | j                  |
d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       t        j                  t        j                  |            }|j                         }| j                  t        |      d       | j                  |d   j                  t        j                         y# 1 sw Y   xY w# 1 sw Y   xY w)zGTest that forcing zip64 extensions correctly notes this in the zip filerH   TrM   r  text.txtrM   force_zip64   _Nz<4sBBHH8xIIHH8shhQQx4s?      PKr   r  r  r   r\         PK)r%   r&   rN   rO   r=   r>   rd   rc  unpackr`   assertGreaterEqualZIP64_VERSIONrn   rf   extract_version)r@   r5   r  zir   headerversrU  flagscompcsizeusizefn_lenex_total_lenro   ex_idex_lenex_usizeex_csizecd_sigzzinfoss                         r)   test_force_zip64z,StoredTestZip64InSmallFiles.test_force_zip64O  s   * zz|__T= 	#4@ B	 --/ MM2GCRLA	
D"eT5%(E68Xv 	/g&;&;<Q"q!
+
+#r*"$1%1%/OOBJJw/0Va(q	 9 97;P;PQ; 	 	s#   H5H(H5(H2	-H55H?c                     d }| j                  t        |t        j                                | j                  t        |t	        t        j                                      y)zjTest that creating a zip with/without seeking will raise a RuntimeError if zip64 was required but not usedc                     t        j                  | dd      5 }|j                  ddd      5 }|j                  dt         j                  dz   z         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	NrH   Tr  r  Fr  r  r\   )rN   rO   r=   r>   r  )rA   r  r  s      r)   make_zipzRStoredTestZip64InSmallFiles.test_unseekable_zip_unknown_filesize.<locals>.make_zip  ss    #$? ?2WWZcuWE ?HHTW%8%81%<=>?? ?? ?? ?s"   A1&A%A1%A.	*A11A:N)r   RuntimeErrorr%   r&   
Unseekabler@   r  s     r)   $test_unseekable_zip_unknown_filesizez@StoredTestZip64InSmallFiles.test_unseekable_zip_unknown_filesize  s>    	?
 	,"**,?,*RZZ\2JKr/   c                     d }| j                  t        j                  |t        j                                | j                  t        j                  |t        t        j                                      y)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   |_        |j                  |d       d d d        y # 1 sw Y   y xY w)NrH   Fr  r  r\   rL   )rN   rO   ZipInfor  rp   r=   )rA   r  r}   s      r)   r  zRStoredTestZip64InSmallFiles.test_zip64_required_not_allowed_fail.<locals>.make_zip  sY    #%@ (Bz2!(!4!4q!83'	( ( (s   AA##A,N)r   rN   r  r%   r&   r  r  s     r)   $test_zip64_required_not_allowed_failz@StoredTestZip64InSmallFiles.test_zip64_required_not_allowed_fail  sJ    	( 	'.."**,G'..*RZZ\:RSr/   c                    t         j                  dz   fd} |t        j                               j	                         }t        j                  dj                        |ddz          \  }}}}}}}	}
}}}}}}}| j                  |d       | j                  |t         j                         | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |	d       | j                  |
d	       | j                  |d
       | j                  |d       | j                  |d       | j                  |       | j                  |       | j                  |d        |t        t        j                                     j                  j	                         }t        j                  dj                        |ddz          \  }}}}}}}	}
}}}}}}}}}}| j                  |d       | j                  |t         j                         | j                  |d       | j                  dj                  |      d       | j                  |d       | j                  |d       | j                  |	d       | j                  |
d	       | j                  |d
       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |d       | j                  |       | j                  |       | j                  |d       y)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      }|_        |j	                  |dd      5 }|j                  dz         d d d        d d d        | S # 1 sw Y   xY w# 1 sw Y   | S xY w)NrH   Tr  r  Fr  r  )rN   rO   r	  rp   r=   r>   )rA   r  r}   r  rp   s       r)   r  zPStoredTestZip64InSmallFiles.test_unseekable_zip_known_filesize.<locals>.make_zip  s    #$? /2z2!*WWTW? /2HHTI-./	/ I/ /	/ Is#   1A>A2 A>2A;	7A>>Bz<4sBBHH8xIIHH8shhQQ{}x4sN>   r  r   r  r  r   r  r  z<4sBBHH8xIIHH8shhQQ{}x4s4xQQ4sV   z{:b}1000s   PK)rN   r  r%   r&   rd   rc  r  formatr`   r  r  r  rA   )r@   r  seekable_datar  r  rU  r  r  r  r  r  r  ro   r  r  r  r  r  unseekable_data	dd_headerdd_usizedd_csizerp   s                         @r)   "test_unseekable_zip_known_filesizez>StoredTestZip64InSmallFiles.test_unseekable_zip_known_filesize  s     ''!+		 !.779
 MM4;;IFVeWY\eWeHfg		
D"eT5%(E68X 	/g&;&;<Q"q!
+
+#r*"$9-9-/ #:bjjl#;<??HHJ
 MM:AA)Lo^m_adm_mNno		
D"eT5%(E68Xx6 	/g&;&;<Qu-v6q!
+
+#r*"$1%1%L19-9-/r/   N)FFFFFF)r  r  r  rN   r   rF   r  r  r  r0  r  r  r  r  r  r  r
  r  r   r/   r)   r  r  J  sb    $$KC
I
C
=1 7<8=8=aF\A|G64Rl	L
TJ0r/   r  c                   $    e Zd Zej                  Zy)DeflateTestZip64InSmallFilesNr  r  r  rN   rm  rF   r   r/   r)   r  r         &&Kr/   r  c                   $    e Zd Zej                  Zy)Bzip2TestZip64InSmallFilesNrs  r   r/   r)   r  r    ru  r/   r  c                   $    e Zd Zej                  Zy)LzmaTestZip64InSmallFilesNrx  r   r/   r)   r  r    rz  r/   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)AbstractWriterTestsc                 "    t        t               y r!   r   r"   r  s    r)   r  zAbstractWriterTests.tearDown  	    wr/   c                    d}t        j                  t        d| j                        5 }|j	                  dd      }|j                  |       |j                          | j                  |j                         |j                          | j                  |j                         | j                  |j                  d      |       d d d        y # 1 sw Y   y xY w)N   contentrH   r'   )rN   rO   r"   rF   r=   r>   rM  ri   r$   r`   ra   r@   r5   r   rH   s       r)   test_close_after_closez*AbstractWriterTests.test_close_after_close  s    __Wc4+;+;< 	6		&#&AGGDMGGIOOAHH%GGIOOAHH%TYYv.5	6 	6 	6s   BCCc                    d}t        j                  t        d| j                        5 }|j	                  dd      }|j                  |       |j                          | j                  |j                         | j                  t        |j
                  d       | j                  |j                  d      |       d d d        y # 1 sw Y   y xY w)Nr%  rH   r'   r/   )rN   rO   r"   rF   r=   r>   rM  ri   r$   r   r  r`   ra   r&  s       r)   test_write_after_closez*AbstractWriterTests.test_write_after_close	  s    __Wc4+;+;< 	6		&#&AGGDMGGIOOAHH%j!''37TYYv.5	6 	6 	6s   BCCc                    t        j                   dg d      }t        |      |j                  z  }t        j                  t        j                         d| j                        5 }|j                  dd      5 }| j                  |j                  |      |       d d d        | j                  |j                  d      j                  |       d d d        y # 1 sw Y   =xY w# 1 sw Y   y xY w)Nr  )r\   r   r  r_   rX   rH   r5   )arrayrf   itemsizerN   rO   r%   r&   rF   r=   r`   r>   rq   rp   )r@   qLENGTHr   r5   s        r)   test_issue44439z#AbstractWriterTests.test_issue44439  s    KK_-Q!**$__RZZ\30@0@A 	DS&#& 8$  A78S[[0::FC	D 	D8 8	D 	Ds$   $C!7"C3C!C	C!!C*c                 d   d}t        j                  t        d| j                        5 }|j	                  |d      5 }| j                  t        j                  |j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  t        j                  |j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr  rH   rL  FT)rN   rO   r"   rF   r=   r   r%   r  r  r  r  r  r  r$   r  s       r)   test_zipwritefile_attrsz+AbstractWriterTests.test_zipwritefile_attrs  s1   __W3D<L<LM 	1QVE3' 13!!""9"93::Fcllne4cllnd3cllne4cjj%01 MM#**d+b55szzBMM#,,.%0MM#,,.$/MM#,,.%0	1 	11 1	1 	1s$   F&B'F#B.F&F#	F&&F/N)r  r  r  r  r'  r)  r/  r1  r   r/   r)   r   r     s    	66D1r/   r   c                   $    e Zd Zej                  Zy)StoredWriterTestsNr  r  r  rN   r   rF   r   r/   r)   r3  r3  *  s    $$Kr/   r3  c                   $    e Zd Zej                  Zy)DeflateWriterTestsNr  r   r/   r)   r6  r6  -  s    &&Kr/   r6  c                   $    e Zd Zej                  Zy)Bzip2WriterTestsNrs  r   r/   r)   r8  r8  1  s    ##Kr/   r8  c                   $    e Zd Zej                  Zy)LzmaWriterTestsNrx  r   r/   r)   r:  r:  5  s    ""Kr/   r:  c                   N    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y)PyZipFileTestsc                 >    |dz   |vr| j                  |dz   |       y y )Nor  )rg   )r@   r  rm   s      r)   assertCompiledInzPyZipFileTests.assertCompiledIn;  s%    #:X%MM$*h/ &r/   c                    t        j                  |t         j                  t         j                  t         j                  v       s| j	                  d       t         j
                  j                  |d      }	 t        j                  |t         j                  t         j                  z        }t        j                  |       t        |       y # t        $ r | j	                  d       Y (w xY w)N)effective_idsz/requires write access to the installed locationztest_zipfile.try)rU  accessW_OKsupports_effective_idsr`  r   r4   r=   O_WRONLYO_CREATrM  	Exceptionr   )r@   r   ro   fds       r)   requiresWriteAccessz"PyZipFileTests.requiresWriteAccess?  s    yyrww')yyB4M4M'MOMMKL77<<&89	M2;;#;<BHHRL 	x  	MMMKL	Ms   7A
C C*)C*c                    | j                  t        j                  j                  t                     t               5 }t        j                  |d      5 }t        }|j                  d      r|j                  t        j                        }t        j                  .|j                  |j                  t        j                               d|v r t        j                  j                  |      }n|d d }|j!                  |       t        j                  j#                  |      }| j%                  ||j'                                | j)                  ||j'                                d d d        d d d        t               5 }t        j                  |d      5 }t        }|j                  d      r|d d }|j!                  |d       ddt        j                  j#                  |      }| j%                  ||j'                                | j)                  ||j'                                d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)NrH   .pyc__pycache__r   testpackage/)rI  rU  r   dirname__file__r   rN   	PyZipFileendswithrh   sepaltsepextend	importlibutilsource_from_cachewritepybasenameassertNotInrm   r?  )r@   trR   rv   
path_splitbns         r)   test_write_pyfilez PyZipFileTests.test_write_pyfileL  s     !:;_ 	87#4#4Q#< 	8B{{6"XXbff-
99(%%bhhryy&9: J."99"=BCRBMM"!!"%BR!12!!"enn&67	8 	8" _ 		87#4#4Q#< 		8B{{6"WMM"m,)277+;+;B+?@BR!12!!"enn&67		8 		8 		8#	8 	8 	8 	8"		8 		8 		8 		8sI   IDH7"I<IBI&I7I 	<III	II$c                    dd l }t        j                  j                  |j                        }| j                  |       t               5 }t        j                  |d      5 }|j                  |       |j                         }| j                  d|       | j                  d|       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   rH   zemail/__init__.pyzemail/mime/text.py)emailrU  r   rO  rP  rI  r   rN   rQ  rY  rm   r?  )r@   ra  
packagedirr\  rR   rz   s         r)   test_write_python_packagez(PyZipFileTests.test_write_python_packagej  s    WW__U^^4
  ,_ 	?7#4#4Q#< 	?MM*% NN$E!!"5u=!!"6>	? 	? 	? 	? 	? 	?s%   	C AB7&C7C 	<CCc           	         dd l }t        j                  j                  |j                        }| j                  |       t               5 }t        j                  |d      5 }t               5 }|j                  |       d d d        j                         }| j                  d|v        t               5 }|j                  |d        d d d        |j                         }| j                  d|v       d }t               5 }| j                  t              5  |j                  ||       d d d        d d d        |j                         }|rt        |       | j                  d|v       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   nxY w# 1 sw Y   BxY w# 1 sw Y   y xY w)Nr   rH   SyntaxErrorc                      y)NFr   )whatevers    r)   <lambda>zCPyZipFileTests.test_write_filtered_python_package.<locals>.<lambda>  s    r/   
filterfuncc                 `    t         j                  j                  |       j                  d       S )Nbad)rU  r   rZ  
startswith)r   s    r)   filterzAPyZipFileTests.test_write_filtered_python_package.<locals>.filter  s%    77++D1<<UCCCr/   )r'   rU  r   rO  rP  rI  r   rN   rQ  r   rY  rd   ri   assertWarnsUserWarningprint)r@   r'   rb  r\  rR   	reportSIO	reportStrrn  s           r)   "test_write_filtered_python_packagez1PyZipFileTests.test_write_filtered_python_packagex  s   WW__T]]3
  ,_ 	<7#4#4Q#< 	< !" *ij)*!**,IOOMY67 !" Mij5KLM!**,IOOM:;D " =i1A1A+1N =jV<= =!**,Ii OOM:;/	< 	< 	<* *M M= = = =%	< 	< 	< 	<s   	F6 F*+E:=5F*2F8F*?FF	)F18F*)F6:F?F*FF*FFF'#F**F3	/F66F?c                    dd l }t        j                  j                  |j                        }| j                  |       d}d}t               5 }t        j                  |d|      5 }|j                  |       |j                         }| j                  d|z   |       | j                  d|z   |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r\   rK  rH   )optimizezemail/__init__zemail/mime/text)ra  rU  r   rO  rP  rI  r   rN   rQ  rY  rm   rg   )r@   ra  rb  optlevelextr\  rR   rz   s           r)   test_write_with_optimizationz+PyZipFileTests.test_write_with_optimization  s    WW__U^^4
  ,_ 	:q#9	:=BMM*%NN$EMM*S0%8MM+c159	: 	: 	: 	: 	: 	:s%   C&AC2CC	CCc                    t        j                  t               	 t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t        t         j                  j                  t        d      dd      5 }|j                  d	       d d d        t               5 }t        j                  |d      5 }|j                  t               |j                         }| j                  d|       | j                  d|       | j                  d|       d d d        d d d        t        t               y # 1 sw Y   ;xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   FxY w# 1 sw Y   JxY w# t        t               w xY w)
Nmod1.pyrH   r@  rA  
print(42)
mod2.pyprint(42 * 42)
zmod2.txtzbla bla bla
rU  mkdirr"   r=   r   r4   r>   r   rN   rQ  rY  rm   r?  r[  r   r@   rA   r\  rR   rz   s        r)   test_write_python_directoryz*PyZipFileTests.test_write_python_directory  st   
	bggll7I6gN (RT'( bggll7I6gN -RT+,- bggll7J7wO *SU)*  4Aw'8'8C'@ 4Eg&(%%i7%%i7  U34 4 7O%( (- -* *4 4 4 4 7Os   0G F8G F#'8G F/1G GAF;6G>G F G #F,(G /F84G ;G	 GGG G$c                    t        j                  t               	 t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t               5 }t        j                  |d      5 }|j                  t        d 	       |j                         }| j                  d|       | j                  d|       d d d        d d d        t        t               y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   9xY w# 1 sw Y   =xY w# t        t               w xY w)
Nr{  rH   r@  rA  r|  r}  r~  c                 &    | j                  d       S )Nr}  )rR  )rv   s    r)   rh  zEPyZipFileTests.test_write_python_directory_filtered.<locals>.<lambda>  s    68kk)6L2L r/   ri  r  r  s        r)   $test_write_python_directory_filteredz3PyZipFileTests.test_write_python_directory_filtered  s0   
	bggll7I6gN (RT'( bggll7I6gN -RT+,-  3Aw'8'8C'@ 3Eg 3M N (%%i7  E23 3 7O( (- -3 3 3 3 7Osl   0E- D=8E- E	'E- 9E!AEE!%E- =EE- 	EE- E	E!!E*&E- -E>c                 p   t               5 }t        j                  |d      5 }t        t        dd      5 }|j                  d       d d d        | j                  t        |j                  t               t        t               d d d        d d d        y # 1 sw Y   NxY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrH   r@  rA  z!most definitely not a python file)
r   rN   rQ  r=   r   r>   r   r  rY  r   )r@   r\  rR   r(   s       r)   test_write_non_pyfilez$PyZipFileTests.test_write_non_pyfile  s    _ 	7#4#4Q#< 	fcG4 =;<=lEMM6B6N		 	 	= =	 	 	 	s9   B,B B<B B,BB  B)	%B,,B5c           	      
   t        j                  t               	 t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t               5 }t        j                  |d      5 }t               5 }|j                  t         j                  j                  t        d             d d d        | j                  dj                                |j                         }| j                  d|       | j                  d|       d d d        d d d        t!        t               y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   9xY w# 1 sw Y   =xY w# t!        t               w xY w)Nr{  rH   r@  rA  zBad syntax in python file
re  zmod1.pyc)rU  r  r"   r=   r   r4   r>   r   rN   rQ  r   rY  rg   rd   rm   r[  r   )r@   rA   r\  rR   srz   s         r)   test_write_pyfile_bad_syntaxz+PyZipFileTests.test_write_pyfile_bad_syntax  s(   
	bggll7I6gN 8RT678  4Aw'8'8C'@ 4E$& D!MM"'',,w	"BCD mQZZ\: (i/  U34 4 7O#8 8
D D4 4 4 4 7Osl   0E1 EE1 /E%E4EAE!E%)E1 E
E1 EEE"	E%%E.*E1 1Fc           
      z   t        j                  t               	 t        t         j                  j                  t        d      dd      5 }|j                  d       d d d        t               5 }t        j                  |d      5 }|j                  t        t         j                  j                  t        d                   |j                         }| j                  d|       d d d        d d d        t        t               y # 1 sw Y   xY w# 1 sw Y   -xY w# 1 sw Y   1xY w# t        t               w xY w)Nr{  rH   r@  rA  r|  )rU  r  r"   r=   r   r4   r>   r   rN   rQ  rY  r   rm   r?  r   r  s        r)   test_write_pathlikez"PyZipFileTests.test_write_pathlike  s    
		bggll7I6gN (RT'(  8Aw'8'8C'@ 8Ehrww||GY'GHI(%%i78 8
 7O( (8 8 8 8
 7OsT   0D) DD) /DAD%D-D) D
D) D	DD&"D) )D:N)r  r  r  r?  rI  r_  rc  rt  ry  r  r  r  r  r  r   r/   r)   r<  r<  :  s9    08<?<<:.(,r/   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k7  d      d        Z ej                   ej$                  j&                  dk7  d      d        Zd Zy)ExtractTestsc                     t        j                  t        dt         j                        5 }t        D ]  \  }}|j                  ||        	 d d d        y # 1 sw Y   y xY w)NrH   )rN   rO   r"   r   SMALL_TEST_DATArP   r@   rR   fpathfdatas       r)   make_test_filezExtractTests.make_test_file  sP    __Wc7+=+=> 	-% / -uue,-	- 	- 	-s   !AAc           	      z   t               5  | j                          t        j                  t        d      5 }t
        D ]  \  }}|j                  |      }t        j                  j                  t        j                         |      }t        j                  j                  |      }| j                  ||       t        |d      5 }| j                  |j                         |j                                d d d        t!        |        	 d d d        d d d        y # 1 sw Y   (xY w# 1 sw Y   xY w# 1 sw Y   y xY wNrV   r6  )r   r  rN   rO   r"   r  extractrU  r   r4   getcwdnormpathr`   r=   encodera   r   )r@   rR   r  r  writtenfilecorrectfiler(   s          r)   test_extractzExtractTests.test_extract  s    Z 	(!#. (%$3 (LE5"'--"6K #%'',,ryy{E"BK"$''"2"2;"?K$$[+> k40 CA((BC ;'((	( 	(C C( (	( 	(s;   +D1BD%/D	2D%D1D"D%%D.	*D11D:c                 x   | j                          t        j                  t        d      5 }t        D ]  \  }}|j                  ||      }t        j                  j                  ||      }t        j                  j                  |      }| j                  t        j                  j                  ||      ||f       t        |d      5 }| j                  |j                         |j                                d d d        t!        |        	 d d d        t!        t               y # 1 sw Y   /xY w# 1 sw Y   %xY wr  )r  rN   rO   r"   r  r  rU  r   r4   r  ri   samefiler=   r`   r  ra   r   )r@   targetrR   r  r  r  r  r(   s           r)   _test_extract_with_targetz&ExtractTests._test_extract_with_target  s    __Wc* 	$e / $u#mmE6: !ggll659 gg..{; 0 0k J[Z`Lab +t, ?$$U\\^QVVX>? {#$	$ 	w? ?	$ 	$s$   BD0/D$6D0$D-)D00D9c                 d    t               5 }| j                  |       d d d        y # 1 sw Y   y xY wr!   )r   r  r@   extdirs     r)   test_extract_with_targetz%ExtractTests.test_extract_with_target(  s,    Z 	36**62	3 	3 	3   &/c                 v    t               5 }| j                  t        |             d d d        y # 1 sw Y   y xY wr!   )r   r  r   r  s     r)   !test_extract_with_target_pathlikez.ExtractTests.test_extract_with_target_pathlike,  s1    Z 	=6**8F+;<	= 	= 	=   /8c           	         t               5  | j                          t        j                  t        d      5 }|j                          t        D ]  \  }}t        j                  j                  t        j                         |      }t        |d      5 }| j                  |j                         |j                                d d d        t        |        	 d d d        d d d        y # 1 sw Y   (xY w# 1 sw Y   xY w# 1 sw Y   y xY wr  )r   r  rN   rO   r"   
extractallr  rU  r   r4   r  r=   r`   r  ra   r   )r@   rR   r  r  outfiler(   s         r)   test_extract_allzExtractTests.test_extract_all0  s    Z 
	$!#. $%  "$3 $LE5 ggll299;>Ggt, C((BC 7O$$
	$ 
	$C C$ $
	$ 
	$s;   +C?AC3/C'	 C3C?'C0,C33C<	8C??Dc                    | j                          t        j                  t        d      5 }|j	                  |       t
        D ]s  \  }}t        j                  j                  ||      }t        |d      5 }| j                  |j                         |j                                d d d        t        |       u 	 d d d        t        t               y # 1 sw Y   /xY w# 1 sw Y   %xY wr  )r  rN   rO   r"   r  r  rU  r   r4   r=   r`   r  ra   r   )r@   r  rR   r  r  r  r(   s          r)   _test_extract_all_with_targetz*ExtractTests._test_extract_all_with_target=  s    __Wc* 	 eV$ /  u'',,vu5'4( ?A$$U\\^QVVX>? w 	  	w? ?	  	 s$   A
C5/C$CCCC'c                 d    t               5 }| j                  |       d d d        y # 1 sw Y   y xY wr!   )r   r  r  s     r)   test_extract_all_with_targetz)ExtractTests.test_extract_all_with_targetK  s,    Z 	76..v6	7 	7 	7r  c                 v    t               5 }| j                  t        |             d d d        y # 1 sw Y   y xY wr!   )r   r  r   r  s     r)   %test_extract_all_with_target_pathlikez2ExtractTests.test_extract_all_with_target_pathlikeO  s5    Z 	A6..x/?@	A 	A 	Ar  c                     | j                  t        j                  j                  |             t	        |d      5 }| j                  |j                         |       d d d        y # 1 sw Y   y xY w)Nr6  )ri   rU  r   isfiler=   r`   ra   )r@   ro   r  r(   s       r)   
check_filezExtractTests.check_fileS  sR    x01(D! 	0QQVVXw/	0 	0 	0s   !A%%A.c                 2   t         j                  j                  }| j                   |dd      d       | j                   |dd      d       | j                   |dd      d       | j                   |d	d      d
       | j                   |dd      d       y )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..rrN  	foo/ba..rz  /  /foo  /  /ba  rz	foo/ba  rz . /. /foo ./ . /. ./ba .rz	foo/ba .r)rN   rO   _sanitize_windows_namer`   )r@   sans     r)   test_sanitize_windows_namez'ExtractTests.test_sanitize_windows_nameX  s    oo440#68IJ1379MN3S9<H3S9<H93?Nr/   c                 .    g d}| j                  |       y )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)r@   common_hacknamess     r)   *test_extract_hackers_arcnames_common_casesz7ExtractTests.test_extract_hackers_arcnames_common_casesa  s    	
 	++,<=r/   \zRequires \ as path separator.c                 .    g d}| j                  |       y)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  )r@   windows_hacknamess     r)   *test_extract_hackers_arcnames_windows_onlyz7ExtractTests.test_extract_hackers_arcnames_windows_onlyn  s    
* 	++,=>r/   rN  zRequires / as path separator.c                 .    g d}| j                  |       y )N))z	//foo/barr  )r  zfoo../ba..r)
foo/..\barr  r  )r@   posix_hacknamess     r)   (test_extract_hackers_arcnames_posix_onlyz5ExtractTests.test_extract_hackers_arcnames_posix_only  s    

 	++O<r/   c                 D   |D ]  \  }}d|j                         z   }t        j                  t        dt        j                        5 }t        j
                         }||_        d|_        |j                  ||       d d d        |j                  t        j                  d      }t        j                  j                  ddd      }t        j                  j                  |g|j                  d       }t        j                  t        d      5 }|j                  ||      }	| j!                  |	|d	|d
|	d|       d d d        | j#                  ||       t%        d       t        j                  t        d      5 }|j'                  |       d d d        | j#                  ||       t%        d       t        j                  j                  t        j(                         g|j                  d       }t        j                  t        d      5 }|j                  |      }	| j!                  |	|d|z         d d d        | j#                  ||       t%        |j                  d      d          t        j                  t        d      5 }|j'                          d d d        | j#                  ||       t%        |j                  d      d          t+        t                y # 1 sw Y   jxY w# 1 sw Y   xY w# 1 sw Y   qxY w# 1 sw Y   xY w# 1 sw Y   ~xY w)N   foobarrH   r$  rN  r  subdirsubsubrV   zextract z: z != )msgz
extract %rr   )r  rN   rO   r"   r   r	  ro   r%  rP   replacerU  rS  r   r4   rh   r  r`   r  r   r  r  r   )
r@   	hacknamesarcname	fixednamer  rR   r&  
targetpathr  r  s
             r)   r  z+ExtractTests._test_extract_hackers_arcnames  s   "+ (	GY'.."22G#w/A/AB /e)!(&1#ug./ oobffc2Gh(CJ'',,zIIOOC4HIK#. F%#mmGZ@  k");&E ! FF
 OOK18#. -%  ,-OOK18'',,ryy{JY__S5IJK#. =%#mmG4  k%1G%; ! == OOK19??3'*+#. #%  "#OOK19??3'*+7OQ(	/ /F F- -= =# #s<   5K#0K0<K=)L
L#K-	0K:	=L	
L	L	N)r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  unittestskipIfrU  r   rS  r  r  r  r   r/   r)   r  r    s    -
(&&3=$7A0
O> X__RWW[[D(*JK? L?2 X__RWW[[C')IJ= K=)r/   r  c                   ,    e Zd ZeZed        Zd Zd Zy)OverwriteTestsc                 T   t         dz   x}| _        | j                  t        |       t	        j
                  |d      5 }|j                  dd       d d d        t         dz   x}| _        | j                  t        |       t	        j
                  |d      5 }|j                  d       d d d        t         dz   x}| _	        | j                  t        |       t	        j
                  |d      5 }|j                  dd       d d d        y # 1 sw Y   xY w# 1 sw Y   mxY w# 1 sw Y   y xY w)Nz-with-file.ziprH   r'   
   newcontentz-with-dir.zipz-with-implicit-dir.zipz	test/file)
r   ar_with_fileaddClassCleanupr   rN   rO   rP   ar_with_dirr  ar_with_implicit_dir)r6   prR   s      r)   r8   zOverwriteTests.setUpClass  s	   %(888CFA&__Q$ 	2NN6=1	2 %66COFA&__Q$ 	 KK	  (.0H'HHC$FA&__Q$ 	7NN;6	7 	7	2 	2
	  	 
	7 	7s#   DD*DDDD'c                 .    t        j                  |d      S r   )rN   rO   )r@   r   s     r)   r=   zOverwriteTests.open  s    tS))r/   c                 :    |j                  | j                         y r!   )r  testdir)r@   ars     r)   r  zOverwriteTests.extractall  s    
dll#r/   N)	r  r  r  r   r  r  r8   r=   r  r   r/   r)   r  r    s#    G7 7 *$r/   r  c                      e Zd Zd Zd Zd Zd Zd Z e       d        Z	d Z
d Z e       d	        Z e       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,        Z0 e       d-        Z1 e       d.        Z2d/ Z3y0)1
OtherTestsc                    t        j                  t        dt         j                        5 }|j	                  dd       | j                  t              5  |j	                  dd       d d d        | j                  |j                         dgdz         d d d        t        j                  t        d      5 }|j                         }d}|D ]/  }|j                  |      5 }||j                         z  }d d d        1 | j                  |dd	h       d}|D ]  }||j                  |      z  } | j                  |dd	h       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)
NrH   r  r   barr   rV   r/   r  s   barfoo)rN   rO   r"   r   rP   ro  rp  r`   rm   rn   r=   ra   rg   )r@   rR   r{   r5   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% +GLLN*D+ ++ MM$I 67D )

4(()MM$I 67
	8 
	8	. .	= 	=+ +	
	8 
	8sH   (EE%,E3)E,E 0AE,E	EE E)%E,,E5c                    t        j                  t        d      5 }dD ]L  }t        j                  |      }|xj                  t         j
                  z  c_        |j                  ||       N 	 d d d        y # 1 sw Y   y xY w)NrH   abcdefghijklmnop)rN   rO   r"   r	  	flag_bits_MASK_USE_DATA_DESCRIPTORrP   )r@   orig_zipr5   r&  s       r)   -test_writestr_extended_local_header_issue1202z8OtherTests.test_writestr_extended_local_header_issue1202  sh    __Wc* 	/h* /-7#D#DD!!%./	/ 	/ 	/s   AA77B c                    t        j                  t        d      5 }t        D ]3  \  }}|j	                  ||       | j                  |j                  d       5 	 ddd       | j                  j                  d       t        j                  t        d      5 }| j                  |j                  d       ddd       | j                  |j                  d       y# 1 sw Y   xY w# 1 sw Y   2xY w)z8Check that the zipfile is closed after the 'with' block.rH   zzipfp is not openNzipfp is not closedrV   )rN   rO   r"   r  rP   assertIsNotNonerA   rr   r  s       r)   
test_closezOtherTests.test_close  s    __Wc* 	De / Duue,$$UXX/BCD	D 	%(($9:__Wc* 	@e  +>?	@%(($9:	D 	D	@ 	@s   =CC%C"%C.c                    t        j                  t        d      5 }t        D ]  \  }}|j	                  ||        	 ddd       	 t        j                  t        d      5 }t        j
                         # 1 sw Y   9xY w# 1 sw Y   yxY w# t         j
                  $ r | j                  j                  d       Y yw xY w)zWCheck that the zipfile is closed if an exception is raised in the
        'with' block.rH   NrV   r  )rN   rO   r"   r  rP   r  rr   rA   )r@   rR   r  r  zipfp2s        r)   test_close_on_exceptionz"OtherTests.test_close_on_exception   s     __Wc* 	-e / -uue,-	-	@#. +&((**	- 	-
+ +!! 	@fii)>?	@s5   !A5B  B5A>B
B 
B /B?>B?c                 z    d}| j                  t        t        j                  t	        j
                  |      d       y )Nsd   PKx     !p@               xPKxx     !p@                           xPK      /        rV   )r   NotImplementedErrorrN   rO   r%   r&   r@   r5   s     r)   test_unsupported_versionz#OtherTests.test_unsupported_version  s1    Y 	-w**T*C	1r/   c                     t        d      }t        j                  |      5 }|j                         D ]!  }|j	                  |      j                          # 	 d d d        y # 1 sw Y   y xY w)Nzzip_cp437_header.zip)r	   rN   rO   rm   r=   rM  )r@   r   rR   r  s       r)   test_read_unicode_filenamesz&OtherTests.test_read_unicode_filenames  s]     /0__U# 	)u( )

4 &&()	) 	) 	)s   5A  A)c                    t        j                  t        d      5 }|j                  dd       |j                  dd       | j	                  |j                         d   j                  t               d d d        t        j                  t        d      5 }| j                  |j                  d   j                  d       | j                  |j                  d   j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrH   foo.txtzTest for unicode filenameu   ö.txtr   rV   r\   )
rN   rO   r   rP   r   rn   ro   rl   r`   filelistr@   r  s     r)   test_write_unicode_filenamesz'OtherTests.test_write_unicode_filenames   s    __VS) 	BRKK	#>?KK
$?@!!"++-"2";";SA	B
 __VS) 	BRR[[^44i@R[[^44jA	B 	B	B 	B
	B 	Bs   AC/AC;/C8;Dc                    t        j                  t        d      5 }|j                  d      }t        j                  |      }d}d}dd l}t        j                  d|j                  |            }	||	z   |z   }
t        |
      j                  dd	      }||z   |
z   |_        |j                  |d
       d d d        y # 1 sw Y   y xY w)NrH   rL   r@  s   up   r   r  r   littles   Hello World!)rN   rO   r   r  r	  zlibrc  r  crc32rf   to_bytesr  rP   )r@   ro   extra_data_namer  filename_encodedzip_infotag_for_unicode_pathversion_of_unicode_pathr  filename_crc
extra_datatsizes               r)   create_zipfile_with_extra_dataz)OtherTests.create_zipfile_with_extra_data*  s    __V#. 	3"'w7x0H#. &-#!;;tTZZ8H-IJL0<?/QJ
O,,Q9E1E9JFHN KK/2#	3 	3 	3s   BB;;Cc                     | j                  ddj                  d             t        j                  t        d      5 }| j                  |j                  d   j                  d       d d d        y # 1 sw Y   y xY w)N
   이름.txtr@  rV   r   )r  r  rN   rO   r   r`   r   ro   r  s     r)   5test_read_zipfile_containing_unicode_path_extra_fieldz@OtherTests.test_read_zipfile_containing_unicode_path_extra_field>  sd    ++L,:M:Mg:VW__VS) 	DRR[[^44lC	D 	D 	Ds   *A//A8c                     | j                  dd       | j                  t              5  t        j                  t
        d      j                          d d d        y # 1 sw Y   y xY w)Nr  r/   rV   )r  ro  rp  rN   rO   r   rM  r  s    r)   test_read_zipfile_warningz$OtherTests.test_read_zipfile_warningD  sL    ++L#>k* 	1OOFC(..0	1 	1 	1s   )AA#c                     | j                  dd       | j                  t        j                        5  t        j                  t
        d      j                          d d d        y # 1 sw Y   y xY w)Nr     rV   )r  r   rN   
BadZipfilerO   r   rM  r  s    r)   test_read_zipfile_errorz"OtherTests.test_read_zipfile_errorJ  sR    ++L'Bw112 	1OOFC(..0	1 	1 	1s   )A$$A-c                     t        j                  t        d      5 }|j                  dd       | j	                  |j                  d      d       d d d        y # 1 sw Y   y xY w)NrH   u   прикладs   sample)rN   rO   r"   rP   r`   ra   r/  s     r)   'test_read_after_write_unicode_filenamesz2OtherTests.test_read_after_write_unicode_filenamesP  sT    __Wc* 	FeNN+Y7UZZ(899E	F 	F 	Fs   4AA!c                 R   t        t               d}d}t        j                  t        dt        j                        5 }|j                  ||       ddd       | j                  t              5  t        j                  t        dt        j                         ddd       t        j                  t        d      5 }| j                  |j                         |g       | j                  |j                  |      |       ddd       y# 1 sw Y   xY w# 1 sw Y   {xY w# 1 sw Y   yxY w)z&Test exclusive creating a new zipfile.testfile.txt#   hello, world. this is some content.xNrV   )r   r"   rN   rO   r   rP   r   FileExistsErrorr`   rm   ra   )r@   ro   r  rR   s       r)   test_exclusive_create_zip_filez)OtherTests.test_exclusive_create_zip_fileU  s    w!8__Wc7+=+=> 	.%NN8W-	./ 	>OOGS'*<*<=	>__Wc* 	<eU^^-z:UZZ17;	< 	<		. 	.	> 	>	< 	<s$   D-*D9ADDDD&c                 L   t         j                  j                  t              rt        j                  t               d}d}	 t        j                  t        d      5 }|j                  ||       d d d        | j                  t         j                  j                  t                     t        j                  t        d      5 }| j                  |j                  |      |       d d d        y # 1 sw Y   xY w# t        $ r | j                  d       Y w xY w# 1 sw Y   y xY w)Nr  r  r2  z1Could not append data to a non-existent zip file.rV   )rU  r   existsr   r   rN   rO   rP   r   failri   r`   ra   )r@   ro   r  r  s       r)   (test_create_non_existent_file_for_appendz3OtherTests.test_create_non_existent_file_for_appendb  s    77>>&!IIf!8	K- /Hg./
 	v./__VS) 	9RRWWX.8	9 	9/ / 	KIIIJ	K
	9 	9s6   C: C./C: "D.C73C: :DDD#c                     t        t        dd      5 }|j                  d       d d d        	 t        j                  t              }y # 1 sw Y   $xY w# t        j
                  $ r Y y w xY w)NrH   r@  rA  this is not a legal zip file
)r=   r   r>   rN   rO   r  )r@   rA   r  s      r)   test_close_erroneous_filez$OtherTests.test_close_erroneous_filet  s`     &#0 	7BHH56	7	(B	7 	7 !! 		s   AA AA*)A*c                    t        t        dd      5 }|j                  d       ddd       | j                  t	        j
                  t                     | j                  t	        j
                  t        t                           t        t        d      5 }| j                  t	        j
                  |             ddd       t        j                         }|j                  d       | j                  t	        j
                  |             |j                  dd       | j                  t	        j
                  |             y# 1 sw Y    xY w# 1 sw Y   xY w)	z;Check that is_zipfile() correctly identifies non-zip files.rH   r@  rA  r(  Nr6  s   this is not a legal zip file
r   )
r=   r   r>   r#   rN   
is_zipfiler   r%   r&   r7  r?   s     r)   test_is_zip_erroneous_filez%OtherTests.test_is_zip_erroneous_file  s     &#0 	7BHH56	7++F34++HV,<=>&$ 	52W//34	5 ZZ\
23++B/0
1++B/0	7 	7	5 	5s   E%EEEc                    t        j                         }t        j                  |d      5 }|j	                  dd       ddd       |j                         }t        t        |            D ]I  }t        j                  |d|       }| j                  t        j                  t        j                  |       K y# 1 sw Y   zxY w)zCCheck that zipfiles with missing bytes at the end raise BadZipFile.rH   rL   r     O, for a Muse of Fire!N)
r%   r&   rN   rO   rP   rd   r0   rf   r   r  )r@   rA   r   r   Ns        r)   test_damaged_zipfilezOtherTests.test_damaged_zipfile  s     ZZ\__Rc* 	@dMM)%>?	@kkm s;'( 	GAKO,Bg00'//2F	G	@ 	@s   B88Cc                    t        j                  t        d      5 }|j                  dd       ddd       | j	                  t        j
                  t                     t        t        d      5 }| j	                  t        j
                  |             |j                  dd       |j                         }ddd       t        j                         }|j                         | j	                  t        j
                  |             |j                  dd       | j	                  t        j
                  |             y# 1 sw Y   xY w# 1 sw Y   xY w)z7Check that is_zipfile() correctly identifies zip files.rH   rL   r  r.  Nr6  r   )rN   rO   r   rP   ri   r+  r=   r7  ra   r%   r&   r>   )r@   r   rA   zip_contentss       r)   test_is_zip_valid_filez!OtherTests.test_is_zip_valid_file  s     __V#. 	@$MM)%>?	@ 	**623&$ 	%2OOG..r23GGAqM779L	%
 ZZ\
**2./
1**2./	@ 	@
	% 	%s   D>/AE>EEc                 V    | j                  t        t        j                  t               y r!   )r   r   rN   rO   r   r  s    r)   %test_non_existent_file_raises_OSErrorz0OtherTests.test_non_existent_file_raises_OSError  s     	'7??F;r/   c                    t        t        dd      }|j                          | j                  t        j
                  t        j                  t               t        t        dd      5 }|j                  d       d d d        | j                  t        j
                  t        j                  t               y # 1 sw Y   =xY w)NrH   r@  rA  z
short file)r=   r   rM  r   rN   r  rO   r>   )r@   r(   rA   s      r)   !test_empty_file_raises_BadZipFilez,OtherTests.test_empty_file_raises_BadZipFile  s    w/		',,goovF&#0 	#BHH\"	#',,goovF	# 	#s   (B66B?c                     t        d      }dD ]_  }t        j                  d|      |dd t        j                  |      }| j                  t        j                  t        j                  |       a y )N   PK                  )r\   r  r  rZ  r  )		bytearrayrc  r  r%   r&   r   rN   r  rO   )r@   bufferdirsizer(   s       r)   8test_negative_central_directory_offset_raises_BadZipFilezCOtherTests.test_negative_central_directory_offset_raises_BadZipFile  s`    34 " 	FG"KKg6F2bM

6"Ag00'//1E	Fr/   c                 j   t        j                         }t        j                  |d      5 }|j	                  dd       ddd       | j                  t        j                  d       | j                  t        |j                  d       | j                  t        |j                         | j                  t        |j                  dd       t        t        dd	      5 }|j                  d
       ddd       | j                  t        |j                  t               y# 1 sw Y   xY w# 1 sw Y   ;xY w)z?Verify that testzip() doesn't swallow inappropriate exceptions.rH   rL   r  O, for a Muse of Fire!Nz	bogus.txtr  r@  rA  zzipfile test data)r%   r&   rN   rO   rP   r   r  ra   r=   rs   r   r>   )r@   r5   r   r(   s       r)   !test_closed_zip_raises_ValueErrorz,OtherTests.test_closed_zip_raises_ValueError  s    zz|__T, 	?MM)%=>	? 	*dii;*dii;*dll3*dmm['J&#0 	)AGG'(	)*djj&9	? 	?	) 	)s   DD)D&)D2c                 X    | j                  t        t        j                  t        d       y)z>Check that bad modes passed to ZipFile constructor are caught.r-  N)r   r  rN   rO   r   r  s    r)   test_bad_constructor_modez$OtherTests.test_bad_constructor_mode  s    *goovsCr/   c                    t        j                  t        d      5 }|j                  dd       ddd       t        j                  t        d      5 }|j	                  d       | j                  t        |j                  dd       | j                  t        |j                  dd       | j                  t        |j                  dd	       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)
z7Check that bad modes passed to ZipFile.open are caught.rH   rL   r  r?  NrV   r-  UrU)rN   rO   r   rP   ra   r   r  r=   r@   r   s     r)   test_bad_open_modezOtherTests.test_bad_open_mode  s    __V#. 	?$MM)%=>	? __V#. 	F$IIi j$))YDj$))YDj$))YE	F 	F	? 	?	F 	Fs   CA8CCC(c                 ~   t        j                  t        d      5 }|j                  dd       |j	                  d      5 }t        t              D ]#  }| j                  |j                  d      d       % | j                  |j                         d       ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY w)	zsCheck that calling read(0) on a ZipExtFile object returns an empty
        string and doesn't advance file pointer.rH   rL   r  r?  r   r/   r.  N)	rN   rO   r   rP   r=   r0   r1   r`   ra   )r@   r   r(   r7   s       r)   
test_read0zOtherTests.test_read0  s     __V#. 	F$MM)%=>9% F~. 5A$$QVVAY45   +DE	F	F 	FF F	F 	Fs$   $B3 AB'B3'B0	,B33B<c                     t        j                  t        d      5 }| j                  t        |j
                  dd       ddd       y# 1 sw Y   yxY w)zqCheck that attempting to call open() for an item that doesn't
        exist in the archive raises a RuntimeError.rH   rL   r  rV   N)rN   rO   r   r   KeyErrorr=   rF  s     r)   test_open_non_existent_itemz&OtherTests.test_open_non_existent_item  sE     __V#. 	C$h		9cB	C 	C 	Cs   #AAc                 Z    | j                  t        t        j                  t        dd       y)zMCheck that bad compression methods passed to ZipFile.open are
        caught.rH   r   N)r   r  rN   rO   r   r  s    r)   test_bad_compression_modez$OtherTests.test_bad_compression_mode  s     	-wRPr/   c                     d}t        j                  t        j                  |      d      5 }| j	                  t
        |j                  d       d d d        y # 1 sw Y   y xY w)Nsf   PK.    C@              x PK..    C@                          xPK      /   !     rV   r   )rN   rO   r%   r&   r   r  r=   )r@   r5   r   s      r)   test_unsupported_compressionz'OtherTests.test_unsupported_compression  sT    6 __RZZ-s3 	Ct1499cB	C 	C 	Cs   "AA c                     t        j                  t        d      5 }|j                  dd       | j	                  |j                         dg       ddd       y# 1 sw Y   yxY w)zLCheck that a filename containing a null byte is properly
        terminated.rH   rL   zfoo.txt qqqr.  r  N)rN   rO   r   rP   r`   rm   rF  s     r)   test_null_byte_in_filenamez%OtherTests.test_null_byte_in_filename  sQ     __V#. 	;$MM*,EFT]]_yk:	; 	; 	;s   4AA"c                    | j                  t        j                  d       | j                  t        j                  d       | j                  t        j                  d       | j                  t        j
                  d       y)zACheck that ZIP internal structure sizes are calculated correctly.   .   8   r   N)r`   rN   sizeEndCentDirsizeCentralDirsizeEndCentDir64sizeEndCentDir64Locatorr  s    r)   test_struct_sizeszOtherTests.test_struct_sizes$  sZ    //4//4112688"=r/   c                 	   t        j                  t        d      5 }| j                  |j                  d       |j                  dd       ddd       t        j                  t        d      5 }| j                  |j                  d       ddd       d}t        j                  t        d      5 }||_        |j                  dd       ddd       t        j                  t        d      5 }| j                  j                  |       ddd       d	j                  t        d
      D cg c]  }d|dz  dz  z   c}      }|j                  d      }t        j                  t        d      5 }||_        |j                  dd       ddd       t        j                  t        d      5 }| j                  |j                  |       ddd       t        j                  t        d      5 }| j                  t              5  |dz   |_        ddd       |j                  dd       ddd       t        j                  t        d      5 }| j                  |j                  |       ddd       t        j                  t        d      5 }d|_        |j                  dd       ddd       t        j                  t        d      5 }d|_        ddd       t        j                  t        d      5 }| j                  |j                  d       ddd       t        j                  t        d      5 }d|_        |j                  dd       ddd       t        j                  j                  t              }t        j                  t        d      5 }d|_        ddd       | j                  |t        j                  j                  t              kD         t        j                  t        d      5 }| j                  |j                  d       ddd       y# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   7xY wc c}w # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   `xY w# 1 sw Y   SxY w# 1 sw Y    xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   oxY w# 1 sw Y   .xY w# 1 sw Y   yxY w)z8Check that comments on the archive are handled properly.rH   rL   r/   r  r?  NrV   s9   Bravely taking to his feet, he beat a very brave retreat.   r  r  r   r.   s   oopss   original commentr2  s   an updated comments   original comment that's longers   shorter comment)rN   rO   r   r`   rG  rP   r4   r0   r  ro  rp  rU  r   getsizeri   )r@   r   zipfrrG  r7   comment2original_zip_sizes          r)   test_commentszOtherTests.test_comments+  s    __V#. 	?$T\\3/MM)%=>	? __V#. 	1%U]]C0	1 O__V#. 	?$"DLMM)%=>	? __V#. 	4%T\\73	4 77k8JK1DAqD2I.KL??7+__V#. 	?$#DLMM)%=>	? __V#. 	6%U]]H5	6 __V#. 	?$!!+. 2''12MM)%=>	? __V#. 	6%U]]H5	6 __V- 	?.DLMM)%=>	? __V- 	10DL	1__V- 	BT\\+@A	B
 __V- 	?<DLMM)%=>	? GGOOF3__V- 	.-DL	.)BGGOOF,CCD__V- 	?T\\+=>	? 	?g	? 	?	1 	1
	? 	?	4 	4 L	? 	?	6 	6
2 2	? 	?	6 	6	? 	?	1 	1	B 	B
	? 	?	. 	.	? 	?s   /P.P%0P2-P?*Q/Q,Q,Q8Q+Q8
R
RR2R,2R9S2SP"%P/2P<?Q	QQ(+Q5	0Q88RRRR),R69SSSc                    t        j                  t        dt         j                        5 }|j	                  dd       | j                  t              5  d|_        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)NrH   r  r?  zthis is an error)rN   rO   r   r   rP   r   	TypeErrorrG  rF  s     r)   test_unicode_commentzOtherTests.test_unicode_commente  sm    __VS'*<*<= 	2MM)%=>""9- 212	2 	22 2	2 	2s#   (A7A+A7+A4	0A77B c                 Z   t        j                  t        dt         j                        5 }| j	                  |j
                         d|_        d d d        t        j                  t        d      5 }| j                  |j                  d       d d d        y # 1 sw Y   IxY w# 1 sw Y   y xY w)Nr2  rF  rV   )rN   rO   r   r   r#   r   rG  r`   rF  s     r)   $test_change_comment_in_empty_archivez/OtherTests.test_change_comment_in_empty_archivek  s    __VS'*<*<= 	0T]]+/DL	0 __VS) 	ATT\\+?@	A 	A	0 	0	A 	As   #B/B!B!B*c                    t        j                  t        dt         j                        5 }|j	                  dd       d d d        t        j                  t        dt         j                        5 }| j                  |j                         d|_        d d d        t        j                  t        d      5 }| j                  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   UxY w# 1 sw Y   y xY w)NrH   r  r?  r2  rF  rV   )	rN   rO   r   r   rP   ri   r   rG  r`   rF  s     r)   'test_change_comment_in_nonempty_archivez2OtherTests.test_change_comment_in_nonempty_archiver  s    __VS'*<*<= 	?MM)%=>	?__VS'*<*<= 	0OODMM*/DL	0 __VS) 	ATT\\+?@	A 	A	? 	?	0 	0	A 	As#   C.#C%3C1C"%C.1C:c                    t        j                  t        d      }|j                          	 t        j                  t        d      }t        j                  t        d      }|j                          	 t        j                  t        d      }y # t         j                  $ r | j                  d       Y nw xY w#  | j                  d       Y y xY w)NrH   rL   rV   z+Unable to create empty ZIP file in 'w' moder2  z+Unable to create empty ZIP file in 'a' mode)rN   rO   r   rM  r  r%  rF  s     r)   test_empty_zipfilezOtherTests.test_empty_zipfile{  s     vC0

	E??64D vC0

	E??64D !! 	EIICD	E	EIICDs   B 4B: $B76B7:Cc                     t        t        dd      }|j                          | j                  t        j
                  t        j                  t        d       y )NrH   r@  rA  rV   )r=   r   rM  r   rN   r  rO   r   s     r)   test_open_empty_filezOtherTests.test_open_empty_file  s9     w/		',,goovsKr/   c                 P    | j                  t        t        j                  dd       y )N	seventies)i  r\   r\   r   r   r   )r   r  rN   r	  r  s    r)   test_create_zipinfo_before_1980z*OtherTests.test_create_zipinfo_before_1980  s    *!//;8M	Or/   c                 f    t        j                  d      }| j                  t        |      d       y)z=Before bpo-26185, repr() on empty ZipInfo object was failing.empty)ro   z&<ZipInfo filename='empty' file_size=0>N)rN   r	  r`   r   r@   r  s     r)   test_create_empty_zipinfo_reprz)OtherTests.test_create_empty_zipinfo_repr  s%    __g.b#KLr/   c                     t        j                         }| j                  |j                  d       | j                  |j                  d       | j                  |j
                  d       | j                  |j                  t         j                         | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  t         j                         | j                  |j                  t         j                         | j                  |j                  d       | j                  |j                   d       | j                  |j"                  d       | j                  |j$                  d       | j                  |j&                  d       | j                  |j(                  d       | j                  |j*                  d       y)z'Ensure all required attributes are set.NoNamerT  r/   )r   r  r   N)rN   r	  r`   orig_filenamero   rW  r   r   rG  r  rg   create_systemcreate_versionDEFAULT_VERSIONr  reservedr  volumeinternal_attrr%  rp   r  rt  s     r)   ,test_create_empty_zipinfo_default_attributesz7OtherTests.test_create_empty_zipinfo_default_attributes  sq   __))84h/'<=))7+=+=>S)3'b&&/**G,C,CD++W-D-DEa(q)A&))1-))1- 	q)))1-r/   c                     d}t        j                  t        j                  |      d      5 }| j	                  |j                                ddd       y# 1 sw Y   yxY w)z>If an extra field in the header is less than 4 bytes, skip it.sn   PK     @        abc   APK     @                    abc  PK      3   %     rV   N)rN   rO   r%   r&   rr   rs   r@   r   r   s      r)   #test_zipfile_with_short_extra_fieldz.OtherTests.test_zipfile_with_short_extra_field  sQ    B 	 __RZZ0#6 	.$dlln-	. 	. 	.s    AAc                    d}d}d}t        j                  t        dt         j                        5 }|j	                  dd      5 }|j                  |       d d d        |j	                  dd      5 }| j                  t              5  |j	                  dd       d d d        | j                  t              5  |j	                  dd	       d d d        | j                  t              5  |j                  d
d       d d d        | j                  t              5  |j                  t        d       d d d        | j                  t              5  |j                          d d d        |j                  |       d d d        |j	                  dd      5 }|j                  |       d d d        d d d        t        j                  t        d	      5 }| j                  |j                  d      |       | j                  |j                  d      |       | j                  |j                  d      |       | j                  |j                         g d       d d d        y # 1 sw Y   	xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   cxY w# 1 sw Y   BxY w# 1 sw Y   6xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Ns"   It's fun to charter an accountant!s    And sail the wide accountant seas#   To find, explore the funds offshorerH   r   rL   r  handlerV   rl   abcderW   baz)r   r  r  )rN   rO   r"   r   r=   r>   r   r  rP   rP  rM  r`   ra   rm   )r@   msg1msg2msg3r   w2w1s          r)   test_open_conflicting_handlesz(OtherTests.test_open_conflicting_handles  s]   425__Wc7+=+=> 	$5s+ r5s+ r&&z2 2IIhSI12&&z2 /IIe#I./&&z2 2MM%12&&z2 1JJx01&&z2 !JJL! 5s+ r	$ __Wc* 	EdTYYu-t4TYYu-t4TYYu-t4T]]_.CD		E 	E# 2 2/ /2 21 1! !  	 	$	E 	Es   KIK1J+I*J+8I7J+)J<J+J0J+JJ+7KJ8$KBKI'	"K*I4/J+7J<J+J	J+JJ+J(#J++J5	0K8K	=KKKc           	         d}|j                  d      }t        j                  t        d      5 }|j	                  d|       d d d        t        j                  t        d      5 }|j                  dd      5 }|j                  |t        j                         | j                  |j                         |       |j                  | t        j                         | j                  |j                         d       |j                  |t        j                         | j                  |j                         |       | j                  |j                  d      |||dz           | j                  |j                         |dz          |j                  dt        j                         | j                  |j                         t        |             |j                  dt        j                         | j                  |j                         d       d d d        d d d        t        j                          }t        j                  |d      5 }|j	                  d|       d d d        t        j                  |d      5 }|j                  dd      5 }|j                  |t        j                         | j                  |j                         |       |j                  | t        j                         | j                  |j                         d       |j                  |t        j                         | j                  |j                         |       | j                  |j                  d      |||dz           | j                  |j                         |dz          |j                  dt        j                         | j                  |j                         t        |             |j                  dt        j                         | j                  |j                         d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   5xY w# 1 sw Y   :xY w# 1 sw Y   xY w# 1 sw Y   FxY w# 1 sw Y   y xY w)	Ns   Where's Bruce?s   BrucerH   r  rV   r   rX   rL   )findrN   rO   r   rP   r=   r7  rU  SEEK_SETr`   r   SEEK_CURra   SEEK_ENDrf   r%   r&   )r@   txtblocr   rA   r5   s         r)   test_seek_tellzOtherTests.test_seek_tell  s7   xx!__VS) 	*TMM)S)	*__VS) 	/T9c* /bbkk*  D1r{{+  A.bkk*  D1  Sd1f-=>  D1H52;;'  CH52;;'  A./	/ zz|__T, 	*MM)S)	*__T, 	/9c* /bbkk*  D1r{{+  A.bkk*  D1  Sd1f-=>  D1H52;;'  CH52;;'  A./	/ 	/)	* 	*/ /	/ 	/ 	* 	*/ /	/ 	/sa   P1#Q6FP>QQ8Q1FQ% Q11P;>Q	QQQ"%Q.	*Q11Q:c                 0   d}|j                  d      }t        j                  t        d      5 }|j	                  d|       d d d        t        j                  t        d      5 }|j                  dd      5 }|j                  |t        j                         | j                  |j                  d      d       d d d        d d d        t        j                  t        d      5 }|j                  dd      5 }|j                  d	       |j                  d
t        j                         | j                  |j                  d      d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   7xY w# 1 sw Y   y xY w)Ns   Charge men!s   menrH   r  rV   rL   r   s   men!   r\   )r  rN   rO   r   rP   r=   r7  rU  r  r`   ra   )r@   r  r  r   rA   s        r)   test_read_after_seekzOtherTests.test_read_after_seek	  sB   xx__VS) 	*TMM)S)	*__V#. 	7$9c* 7bbkk*  g67	7 __V#. 	7$9c* 7b
2;;'  g67	7 	7	* 	*7 7	7 	7
7 7	7 	7sU   E$E47AE(9E4$F7AF 
FE%(E1	-E44E= F		FFc                    d}t        j                  |      }t        j                  |dt        j                        5 }|j                  dd       d d d        t        j                  dd       5  t        j                  |      5 }| j                  t        |j                  d       d d d        d d d        y # 1 sw Y   hxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr9  rH   )rF   r      azzipfile.bz2)r%   r&   rN   rO   rt  rP   mockpatchr   r  r  )r@   r5   zip_filer  s       r)   )test_decompress_without_3rd_party_libraryz4OtherTests.test_decompress_without_3rd_party_library	  s    d::d#__Xs8I8IJ 	'bKK&	'ZZt, 	E* Eb!!,

GDE	E 	E	' 	'E E	E 	Es/   B8/C"C'C8CC		CCc                 <   d}t        j                  t        j                  |      d      5 }| j	                  |j                         ddg       |j                  d      }| j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       |j                  d      }| j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  t        |j                  d            d       | j                  t         j                  d      5  |j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	Ns   PK    lH8   	     a   0K\d`PK     lH8   	                   aPK     lH8   	                   bPK      ^   /     rV   r2  br   r  	  zFile name.*differ)rN   rO   r%   r&   r`   rm   rq   r  r  rp   rf   ra   assertRaisesRegexr  r@   r5   r   r  s       r)   test_full_overlapzOtherTests.test_full_overlap!	  sK   
 	 __RZZ-s3 	tT]]_sCj9c"BR--q1R--r2R\\40c"BR--q1R--r2R\\40S30$7''(:(:<OP 		#	 	 	 	s$   D7F#F5FF	FFc                 <   d}t        j                  t        j                  |      d      5 }| j	                  |j                         ddg       |j                  d      }| j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       |j                  d      }| j	                  |j                  d       | j	                  |j                  d	       | j	                  |j                  d
       | j                  t         j                  d      5  |j                  d       d d d        | j	                  t        |j                  d            d
       d d d        y # 1 sw Y   <xY w# 1 sw Y   y xY w)Ns   PK    lHY84   (     a  PK    lH8   	     b   0K\d`PK     lHY84   (                   aPK     lH8   	               $   bPK      ^   S     rV   r2  r  r   4   i(  $   r  r  zOverlapped entries)rN   rO   r%   r&   r`   rm   rq   r  r  rp   r  r  ra   rf   r  s       r)   test_quoted_overlapzOtherTests.test_quoted_overlap>	  sK   ) 	 __RZZ-s3 	8tT]]_sCj9c"BR--q1R--r2R\\40c"BR--r2R--r2R\\40''(:(:<PQ 		#S30$7	8 	8 	8 	8s$   DF9F2FF	FFc                 @    t        t               t        t               y r!   r  r  s    r)   r  zOtherTests.tearDown]	  r  r/   N)4r  r  r  r  r  r  r  r  r
   r  r  r  r  r  r  r  r"  r&  r)  r,  r0  r3  r5  r7  r=  r@  rB  rG  rI  rL  rN  rP  rR  r[  rc  rf  rh  rj  rl  rn  rq  ru  r  r  r  r  r  r   r  r  r  r  r   r/   r)   r  r    s}   8(/
;@	1 _) )B3( _D D
 _1 1
 _1 1
F
<9$1$G0&<G	F:$DF
FCQ
	C;>8?t2AAE"LOM
.,.E:&/P7  ^E E _ 8 _8 8<r/   r  c                       e Zd Zd Zd Zy)AbstractBadCrcTestsc                     | j                   }t        j                  t        j                  |      d      5 }| j                  d|j                                ddd       y# 1 sw Y   yxY w)z>Tests that files with bad CRCs return their name from testzip.rV   rL   afileN)zip_with_bad_crcrN   rO   r%   r&   r`   rs   r  s      r)   test_testzip_with_bad_crcz-AbstractBadCrcTests.test_testzip_with_bad_crcc	  sQ    ''__RZZ0s; 	6tWdlln5	6 	6 	6s   !A!!A*c                    | j                   }t        j                  t        j                  |      d      5 }| j                  t        j                  |j                  d       ddd       t        j                  t        j                  |      d      5 }|j                  dd      5 }| j                  t        j                  |j                         ddd       ddd       t        j                  t        j                  |      d      5 }|j                  dd      5 }d|_	        | j                  t        j                        5  |j                  d      r	 |j                  d      rddd       ddd       ddd       y# 1 sw Y   $xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ?xY w# 1 sw Y   CxY w# 1 sw Y   yxY w)zFTests that files with bad CRCs raise a BadZipFile exception when read.rV   rL   r  Nr   )
r  rN   rO   r%   r&   r   r  ra   r=   MIN_READ_SIZE)r@   r   r   corrupt_files       r)   test_read_with_bad_crcz*AbstractBadCrcTests.test_read_with_bad_crck	  s   '' __RZZ0s; 	Ftg00$))WE	F __RZZ0s; 	It7C( IL!!'"4"4l6G6GHI	I
 __RZZ0s; 	t7C( L-.*&&w'9'9: &++A. '++A.	 		F 	F
I I	I 	I  	 	sk   ,FF(+FFG 'F6$F*,F64GFF	FF'*F3/F66F?	;GGN)r  r  r  r  r  r   r/   r)   r  r  b	  s    6r/   r  c                   (    e Zd Zej                  ZdZy)StoredBadCrcTestssx   PK      ;:r         afilehello,AworldPK      ;:r                     afilePK      3   /     N)r  r  r  rN   r   rF   r  r   r/   r)   r  r  	  s    $$K	 r/   r  c                   (    e Zd Zej                  ZdZy)DeflateBadCrcTestss|   PK    n}=FAKE   n      afileHW(/Iɠ= PK    n}=FAKE   n                  afilePK      3   3     N)r  r  r  rN   rm  rF   r  r   r/   r)   r  r  	  s    &&K	6 r/   r  c                   (    e Zd Zej                  ZdZy)Bzip2BadCrcTestss   PK   nu=FAKE8   n      afileBZh91AY&SYԨ  @ D   P!u5:"(HjTe?PK   nu=FAKE8   n                 afilePK      3   [     N)r  r  r  rN   rt  rF   r  r   r/   r)   r  r  	  s    ##K
	 r/   r  c                   (    e Zd Zej                  ZdZy)LzmaBadCrcTestss   PK   nu=FAKE   n      afile	 ]    4I:3`	q!.8 PK   nu=FAKE   n                 afilePK      3   >     N)r  r  r  rN   ry  rF   r  r   r/   r)   r  r  	  s    ""K	% r/   r  c                   ^    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y)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                  | j                         d d d        t	        j
                  t        d      | _        t        t        d      5 }|j                  | j                         d d d        t	        j
                  t        d      | _	        y # 1 sw Y   |xY w# 1 sw Y   5xY w)Nr;   rV   )
r=   r   r>   r5   rN   rO   r   r"   data2zip2r?   s     r)   rB   zDecryptionTests.setUp	  s    &$ 	 2HHTYY	 ??63/'4  	!BHHTZZ 	!OOGS1		  	 	! 	!s   B($B4(B14B=c                     | j                   j                          t        j                  t               | j
                  j                          t        j                  t               y r!   )r   rM  rU  r   r   r  r"   r  s    r)   r  zDecryptionTests.tearDown	  s6    
		&		
		'r/   c                     | j                  t        | j                  j                  d       | j                  t        | j                  j                  d       y )Ntest.txtzero)r   r  r   ra   r  r  s    r)   test_no_passwordz DecryptionTests.test_no_password	  s8     	,zB,		?r/   c                    | j                   j                  d       | j                  t        | j                   j                  d       | j
                  j                  d       | j                  t        | j
                  j                  d       y )Ns   perlr  r  )r   setpasswordr   r  ra   r  r  s    r)   test_bad_passwordz!DecryptionTests.test_bad_password	  sZ    W%,zB		g&,		?r/   c                 D   | j                   j                  d       | j                  | j                   j                  d      | j                         | j
                  j                  d       | j                  | j
                  j                  d      | j                         y )N   pythonr  s   12345r  )r   r  r`   ra   plainr  plain2r  s    r)   test_good_passwordz"DecryptionTests.test_good_password	  sh    Y'z2DJJ?		h'/=r/   c                    d}| j                  t        |      5  | j                  j                  d       d d d        | j                  t        |      5  | j                  j	                  dd       d d d        | j                  t        |      5  | j                  j                  dd       d d d        | j                  t        |      5  | j                  j                  dd       d d d        | j                  t        |      5  d| j                  _        | j                  j                  d       d d d        y # 1 sw Y   	xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   zxY w# 1 sw Y   y xY w)Nzpwd: expected bytes, got strunicoder  python)pwd)r  re  r   r  ra   r=   r  r  )r@   expected_msgs     r)   test_unicode_passwordz%DecryptionTests.test_unicode_password	  s7   5##I|< 	,HH  +	, ##I|< 	0HHMM*h/	0 ##I|< 	4HHMM*(M3	4 ##I|< 	7HHZX6	7 ##I|< 	&#DHHLHHMM*%	& 	&	, 	,	0 	0	4 	4	7 	7	& 	&s;   D<E	E
E!-E-<E	EE!E*-E6c                 P   | j                   j                  d       | j                  }d}|j                  |      }t	        |      }| j                   j                  dd      5 }|j                  |t        j                         | j                  |j                         |       |j                  | t        j                         | j                  |j                         d       |j                  |t        j                         | j                  |j                         |       | j                  |j                  |      ||||z           |j                  }d|_        d|_        d|_        |j                  dt        j                         | j                  |j                         d       |j                  |t        j                         | j                  |j                  |      ||||z           ||_        |j                  dt        j                          | j                  |j                         t	        |             |j                  dt        j                         | j                  |j                         d       |j                          d d d        y # 1 sw Y   y xY w)Nr  s
   encryptionr  rV   r   r\   r/   )r   r  r  r  rf   r=   r7  rU  r  r`   r   r  ra   r  _readbuffer_offsetr  )r@   r  	test_wordr  bloc_lenrA   old_read_sizes          r)   r  zDecryptionTests.test_seek_tell
  s   Y'jj!	xx	"y>XX]]:s+ 	rGGD"++&RWWY-GGTE2;;'RWWY*GGD"++&RWWY-RWWX.Dh0GH
 ,,M B BNBJGGAr{{#RWWY*GGD"++&RWWX.Dh0GH,BGGAr{{#RWWYC1GGAr{{#RWWY* GGI;	 	 	s   "H1JJ%N)r  r  r  __doc__r5   r  r  r  rB   r  r  r  r
   r  r  r  r   r/   r)   r  r  	  s]    
	) 		: 
 *EF2@@ _> >&&#r/   r  c                   R    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y)"AbstractTestsWithRandomBinaryFilesc                     t        dd      dz  t        dd      z   }dj                  d t        |      D              | _        y )Nr  @   r   r\   r/   c           	   3   r   K   | ]/  }t        j                  d t               t        dd      z         1 yw)z<fir   N)rc  r  r   r   r  s     r)   r  z@AbstractTestsWithRandomBinaryFiles.setUpClass.<locals>.<genexpr>1
  s1      7 ! #KKfhwud7K.KL 7s   57)r   r4   r0   r5   )r6   	datacounts     r)   r8   z-AbstractTestsWithRandomBinaryFiles.setUpClass.
  s@    BOD(71d+;;	88 7%*9%57 7r/   c                     t        t        d      5 }|j                  | j                         d d d        y # 1 sw Y   y xY wr:   r<   r?   s     r)   rB   z(AbstractTestsWithRandomBinaryFiles.setUp4
  rC   rD   c                 @    t        t               t        t               y r!   r  r  s    r)   r  z+AbstractTestsWithRandomBinaryFiles.tearDown9
  r  r/   c                     t        j                  |d|      5 }|j                  t        d       |j                  t        t               d d d        y # 1 sw Y   y xY w)NrH   rI   )rN   rO   r>   r   r  s       r)   rT   z4AbstractTestsWithRandomBinaryFiles.make_test_archive=
  sE    __Q[1 	(UKK/KK'	( 	( 	(s   1AAc                    | j                  ||       t        j                  |d|      5 }|j                  t              }| j                  t        |      t        | j                               | j                  || j                         | j                  |j                  d      | j                         d d d        y # 1 sw Y   y xY w)NrV   rI   )rT   rN   rO   ra   r   r`   rf   r5   )r@   r(   rF   rR   testdatas        r)   r~   z+AbstractTestsWithRandomBinaryFiles.zip_testC
  s    q+. __Q[1 	DUzz&)HS]C		N;Xtyy1UZZ7C		D 	D 	Ds   BB>>Cc                 \    t        |       D ]  }| j                  || j                           y r!   r   r   s     r)   	test_readz,AbstractTestsWithRandomBinaryFiles.test_readM
  r   r/   c                 6   | j                  ||       t        j                  |d|      5 }g }|j                  t              5 }	 |j                  d      }|sn|j                  |       &	 d d d        g }|j                  d      5 }	 |j                  d      }|sn|j                  |       &	 d d d        dj                  |      }	| j                  t        |	      t        | j                               | j                  |	| j                         dj                  |      }
| j                  t        |
      t        | j                               | j                  |
| j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY wr   )rT   rN   rO   r=   r   ra   r   r4   r`   rf   r5   )r@   r(   rF   rR   r   r   r   r   r   	testdata1	testdata2s              r)   r   z0AbstractTestsWithRandomBinaryFiles.zip_open_testQ
  sj   q+. __Q[1 	3UHF# /x (c 2I$OOI.	  	/ HN+ /x (c 2I$OOI.	  	/ *IS^S^<Y		2*IS^S^<Y		2/	3 	3/ // /	3 	3s<   F(E6+F(F/B>F6F 	;FF	FFc                 \    t        |       D ]  }| j                  || j                           y r!   r   r   s     r)   r   z,AbstractTestsWithRandomBinaryFiles.test_openn
  r   r/   c                    | j                  ||       t        j                  |d|      5 }g }|j                  t              5 }	 |j                  t        dd            }|sn|j                  |       0	 d d d        dj                  |      }| j                  t        |      t        | j                               | j                  || j                         d d d        y # 1 sw Y   mxY w# 1 sw Y   y xY wr   )rT   rN   rO   r=   r   ra   r   r   r4   r`   rf   r5   )r@   r(   rF   rR   r   r   r   r  s           r)   r   z7AbstractTestsWithRandomBinaryFiles.zip_random_open_testr
  s    q+. __Q[1 	2UHF# /x (ga.> ?I$OOI.	  	/ xx)HS]C		N;Xtyy1	2 	2/ /	2 	2s$   C-2C!5A#C-!C*	&C--C6c                 \    t        |       D ]  }| j                  || j                           y r!   r   r   s     r)   r   z3AbstractTestsWithRandomBinaryFiles.test_random_open
  r   r/   N)r  r  r  r  r8   rB   r  rT   r~   r  r   r   r   r   r   r/   r)   r  r  -
  sB    7 7
 
(D/3:42";r/   r  c                   $    e Zd Zej                  Zy) StoredTestsWithRandomBinaryFilesNr4  r   r/   r)   r  r  
  s    $$Kr/   r  c                   $    e Zd Zej                  Zy)!DeflateTestsWithRandomBinaryFilesNr  r   r/   r)   r  r  
  r  r/   r  c                   $    e Zd Zej                  Zy)Bzip2TestsWithRandomBinaryFilesNrs  r   r/   r)   r  r  
  ru  r/   r  c                   $    e Zd Zej                  Zy)LzmaTestsWithRandomBinaryFilesNrx  r   r/   r)   r  r  
  rz  r/   r  c                   $    e Zd Zd Zd Zd Zd Zy)Tellablec                      || _         d| _        y )Nr   )rA   offsetr?   s     r)   __init__zTellable.__init__
  s    r/   c                 f    | j                   j                  |      }| xj                  |z  c_        |S r!   )rA   r>   r  )r@   r5   ns      r)   r>   zTellable.write
  s'    GGMM$qr/   c                     | j                   S r!   )r  r  s    r)   r   zTellable.tell
  s    {{r/   c                 8    | j                   j                          y r!   rA   flushr  s    r)   r  zTellable.flush
      r/   N)r  r  r  r  r>   r   r  r   r/   r)   r  r  
  s    
r/   r  c                       e Zd Zd Zd Zd Zy)r  c                     || _         y r!   )rA   r?   s     r)   r  zUnseekable.__init__
  s	    r/   c                 8    | j                   j                  |      S r!   )rA   r>   r  s     r)   r>   zUnseekable.write
  s    ww}}T""r/   c                 8    | j                   j                          y r!   r  r  s    r)   r  zUnseekable.flush
  r   r/   N)r  r  r  r  r>   r  r   r/   r)   r  r  
  s    #r/   r  c                       e Zd Zd Zd Zd Zy)UnseekableTestsc           	      p   d t         t        fD ]g  }| j                  |      5  t        j                         }|j                  d       t        j                  |      }t        j                   ||      dt        j                        5 }|j                  dd       |j                  dd       d d d        | j                  |j                         d d	 d
       t        j                  |d      5 }|j                  d      5 }| j                  |j                         d       d d d        |j                  d      5 }| j                  |j                         d       d d d        d d d        d d d        j y # 1 sw Y   xY w# 1 sw Y   cxY w# 1 sw Y   5xY w# 1 sw Y   9xY w# 1 sw Y   xY w)Nc                     | S r!   r   r(   s    r)   rh  z/UnseekableTests.test_writestr.<locals>.<lambda>
      ! r/   wrapper   abcrH   ones   111twos   222rX      abcPKrV   rL   )r  r  subTestr%   r&   r>   BufferedWriterrN   rO   r   rP   r`   rd   r=   ra   )r@   r  r(   bfrR   r   zopens          r)   test_writestrzUnseekableTests.test_writestr
  si   #h
: 	?Gg. ?JJL&&q)__WR[#w7I7IJ 3eNN662NN6623   bq!18<__QS1 ?T6* ?e((v>?6* ?e((v>??? ?	?
3 3
? ?? ?? ?? ?sm   A&F+%E;0AF+2F!F	%F>!F	F'F+;F F+FFFFF($F++F5	c           	         d t         t        fD ]  }| j                  |      5  t        j                         }|j                  d       t        j                  |      }t        j                   ||      dt        j                        5 }| j                  t        t               t        t        d      5 }|j                  d       d d d        |j                  t        d       t        t        d      5 }|j                  d       d d d        |j                  t        d	       d d d        | j                  |j                         d d
 d       t        j                  |d      5 }|j                  d      5 }| j                  |j!                         d       d d d        |j                  d	      5 }| j                  |j!                         d       d d d        d d d        d d d         y # 1 sw Y   +xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   |xY w# 1 sw Y   NxY w# 1 sw Y   RxY w# 1 sw Y   5xY w)Nc                     | S r!   r   r	  s    r)   rh  z,UnseekableTests.test_write.<locals>.<lambda>
  r
  r/   r  r  rH   r;   r  r  r  r  rX   r  rV   rL   )r  r  r  r%   r&   r>   r  rN   rO   r   
addCleanupr   r   r=   r`   rd   ra   )r@   r  r(   r  rR   f2r   r  s           r)   
test_writezUnseekableTests.test_write
  s   #h
: 	?Gg. ?JJL&&q)__WR[#w7I7IJ 0eOOFF3fd+ )r()KK/fd+ )r()KK/0   bq!18<__QS1 ?T6* ?e((v>?6* ?e((v>??? ?	?) )) )0 0? ?? ?? ?? ?s   A&H:+H
6G1	.H
6G>	H
&AH:(H.:!H	H.4!H"	H.H:1G;6H
>HH

HH:HH."H+'H..H73H::I	c           	      p   d t         t        fD ]g  }| j                  |      5  t        j                         }|j                  d       t        j                  |      }t        j                   ||      dt        j                        5 }|j                  dd      5 }|j                  d       d d d        |j                  dd      5 }|j                  d       d d d        d d d        | j                  |j                         d d	 d
       t        j                  |      5 }| j                  |j                  d      d       | j                  |j                  d      d       d d d        d d d        j y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   9xY w# 1 sw Y   xY w)Nc                     | S r!   r   r	  s    r)   rh  z1UnseekableTests.test_open_write.<locals>.<lambda>
  r
  r/   r  r  rH   r  r  r  r  rX   r  )r  r  r  r%   r&   r>   r  rN   rO   r   r=   r`   rd   ra   )r@   r  r(   r  r   r  s         r)   test_open_writezUnseekableTests.test_open_write
  sx   #h
: 	@Gg. @JJL&&q)__WR[#w7I7IJ ,d63/ ,5F+,63/ ,5F+,,
   bq!18<__Q' @4$$TYYv%6?$$TYYv%6?@@ @	@, ,, ,, ,@ @@ @sn   A&F+FE;	0F
F	F$A F+$AF'F+;F FFFFF+F($F++F5	N)r  r  r  r  r  r  r   r/   r)   r  r  
  s    ? ?*@r/   r  c                   X    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y)TestsWithMultipleOpensc                 P    dt        d      z   | _        dt        d      z   | _        y )Nr  i'  r  )r   data1r  )r6   s    r)   r8   z!TestsWithMultipleOpens.setUpClass
  s$    Yu--	Yu--	r/   c                     t        j                  |dt         j                        5 }|j                  d| j                         |j                  d| j
                         d d d        y # 1 sw Y   y xY w)NrH   r  r  )rN   rO   rm  rP   r#  r  )r@   r(   rR   s      r)   rT   z(TestsWithMultipleOpens.make_test_archive
  sS    __QW%9%9: 	/eNN64::.NN64::.	/ 	/ 	/s   9A((A1c           	      $   t        |       D ]  }| j                  |       t        j                  |d      5 }|j	                  d      5 }|j	                  d      5 }|j                  d      }|j                  d      }||j                         z  }||j                         z  }d d d        d d d        | j                         | j                  || j                         d d d         y # 1 sw Y   JxY w# 1 sw Y   NxY w# 1 sw Y   xY w)NrV   rL   r    )r*   rT   rN   rO   r=   ra   r`   r#  r@   r(   r   zopen1zopen2r#  r  s          r)   test_same_filez%TestsWithMultipleOpens.test_same_file
  s     4 		4A""1%- 4YYv& +&$))F2C +v"KK,E"KK,EV[[]*EV[[]*E	+ +
   .  

34 4		4+ + + +4 4s<   D	C9A	C-	$C9,6D-C62C99D>DD	c           	      8   t        |       D ]  }| j                  |       t        j                  |d      5 }|j	                  d      5 }|j	                  d      5 }|j                  d      }|j                  d      }||j                         z  }||j                         z  }d d d        d d d        | j                  | j                         | j                  | j                         d d d         y # 1 sw Y   TxY w# 1 sw Y   XxY w# 1 sw Y   xY w)NrV   rL   r  r  r&  	r*   rT   rN   rO   r=   ra   r`   r#  r  r'  s          r)   test_different_filez*TestsWithMultipleOpens.test_different_file	  s     4 		4A""1%- 4YYv& +&$))F2C +v"KK,E"KK,EV[[]*EV[[]*E	+ +
   

3  

34 4		4+ + + +4 4s=   D	DA	C7	$D,A D7D <DDDD	c           	      8   t        |       D ]  }| j                  |       t        j                  |d      5 }|j	                  d      5 }|j                  d      }|j	                  d      5 }|j                  d      }||j                         z  }||j                         z  }d d d        d d d        | j                  | j                         | j                  | j                         d d d         y # 1 sw Y   TxY w# 1 sw Y   XxY w# 1 sw Y   xY w)NrV   rL   r  r&  r  r,  )r@   r(   r   r(  r#  r)  r  s          r)   test_interleavedz'TestsWithMultipleOpens.test_interleaved  s     4 
	4A""1%- 4YYv& /&"KK,E6* /f &C 0..//   

3  

34 4
	4
/ // /4 4s<   D	#D,8C7	$D,A D7D <DDDD	c                 r   t        |       D ]  }| j                  |       t        j                         5 }t	        j
                  |d      5 }|j                  |j                  d            }|j                  |j                  d            }d d d        j                  d      }j                  d      }||j                         z  }||j                         z  }d d d        | j                  | j                         | j                  | j                          y # 1 sw Y   xY w# 1 sw Y   QxY w)NrV   r  r  r&  )r*   rT   
contextlib	ExitStackrN   rO   enter_contextr=   ra   r`   r#  r  )r@   r(   stackr   r(  r)  r#  r  s           r)   test_read_after_closez,TestsWithMultipleOpens.test_read_after_close&  s	   4 	0A""1%%%' '5__Q, D"0061BCF"0061BCFD C(C(&&' UDJJ/UDJJ/	0D D' 's%   D-AD!AD-!D*&D--D6	c                    t        |       D ],  }t        j                  |dt        j                        5 }|j	                  d| j
                         |j	                  d| j                         |j                  d      5 }|j                  d      }d d d        d d d        | j                  | j
                  d d        t        j                  |d      5 }|j                  d      }|j                  d      }d d d        | j                  || j
                         | j                  | j                         / y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ]xY w)NrH   r  r  r&  rV   )
r*   rN   rO   rm  rP   r#  r  r=   ra   r`   r@   r(   r   r(  r#  r  s         r)   test_read_after_writez,TestsWithMultipleOpens.test_read_after_write4  s   4 	0AC)=)=> -$fdjj1fdjj1YYv& -&"KK,E--
 UDJJt$45C( *D		&)		&)* UDJJ/UDJJ/	0- -- -* *s0   A
E	?D=E	#E=EE		E	E	c                    t        |       D ]  }t        j                  |dt        j                        5 }|j	                  d| j
                         |j                  d      5 }|j                  d       |j	                  d| j                         d d d        d d d        t        j                  |d      5 }|j                  d      }|j                  d      }d d d        | j                  | j
                         | j                  | j                          y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ]xY w)NrH   r  r&  r  rV   )
r*   rN   rO   rm  rP   r#  r=   ra   r  r`   r7  s         r)   test_write_after_readz,TestsWithMultipleOpens.test_write_after_readB  s   4 
	0AC)=)=> 6$fdjj1YYv& 6&KK$MM&$**566
 C( *D		&)		&)* UDJJ/UDJJ/
	06 66 6
* *s/   .D*#.DD*7#D6D'#D**D3	6D?	c                 h   t               }| j                  t               t        j                  t        d      5 }t        d      D ].  }|j                  d       |j                  d      5 }	 d d d        0 	 d d d        | j                  |t                      y # 1 sw Y   ^xY w# 1 sw Y   0xY w)NrV   rL   r   r  )	r   rT   r"   rN   rO   r0   ra   r=   r`   )r@   
startcountr   r   r(  s        r)   test_many_opensz&TestsWithMultipleOpens.test_many_opensO  s     Z
w'__W3/ 	43Z 		&!YYv& & 	
 	XZ0 	 	s#   1B(,B.
B(B%!B((B1c                 :   t        j                  t        dt         j                        5 }|j	                  d| j
                         d d d        t        j                  t        dt         j                        5 }|j                  dd      5 }|j                  d      }|j                  dd      5 }|j                  | j                         d d d        ||j                         z  }d d d        d d d        | j                  | j
                         t        j                  t              5 }| j                  |j                  d      | j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrH   r  r2  rV   r&  r  )rN   rO   r"   rm  rP   r#  r=   ra   r>   r  r`   )r@   r   r1r#  r  s        r)   test_write_while_readingz/TestsWithMultipleOpens.test_write_while_reading[  s@   __Wc7+?+?@ 	.DMM&$**-	.__Wc7+?+?@ 	#D63' #2YYvs+ )rHHTZZ()"	#	# 	

+__W% 	<TYYv.

;	< 	<	. 	.
) )# #	# 	#	< 	<sS   E 8F$E9/E-E9&F+,F E*-E62E99F	>FFFc                 "    t        t               y r!   r"  r  s    r)   r  zTestsWithMultipleOpens.tearDownh  r#  r/   N)r  r  r  r  r8   rT   r*  r-  r/  r5  r8  r:  r=  r@  r  r   r/   r)   r!  r!  
  sF    . ./444000
1<r/   r!  c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestWithDirectoryc                 6    t        j                  t               y r!   )rU  r  r"   r  s    r)   rB   zTestWithDirectory.setUpm  s    
r/   c           
      z   t        j                  t        d            5 }|j                  t               d d d        | j                  t        j                  j                  t        j                  j                  t        d                   | j                  t        j                  j                  t        j                  j                  t        dd                   | j                  t        j                  j                  t        j                  j                  t        ddd                   y # 1 sw Y   xY w)N
zipdir.zipr2  r  r  )rN   rO   r	   r  r"   ri   rU  r   isdirr4   r$  rF  s     r)   test_extract_dirz"TestWithDirectory.test_extract_dirp  s    __Xl34 	%OOG$	%bggll7C&@ABbggll7C&EFGrww||GS#s'KLM		% 	%s   D11D:c                     t        j                  t         j                  j                  t        d             | j                          y )Nr2  )rU  r  r   r4   r"   rH  r  s    r)   test_bug_6050zTestWithDirectory.test_bug_6050w  s)    
gs+,r/   c           
      l   t        d      }t        j                  |      5 }|j                  t               d d d        t
        j                  dk(  r| j                  t
        j                  j                  t
        j                  j                  t        d                   | j                  t
        j                  j                  t
        j                  j                  t        dd                   | j                  t
        j                  j                  t
        j                  j                  t        ddd                   | j                  t
        j                  j                  t
        j                  j                  t        d                   | j                  t
        j                  j                  t
        j                  j                  t        dd                   y | j                  t
        j                  j                  t
        j                  j                  t        d                   | j                  t
        j                  j                  t
        j                  j                  t        d	                   | j                  t
        j                  j                  t
        j                  j                  t        d                   | j                  t
        j                  j                  t
        j                  j                  t        d                   y # 1 sw Y   xY w)
Nzzipdir_backslash.zipntr2  r  r  r   r  za\b\czd\e\)r	   rN   rO   r  r"   rU  r  ri   r   rG  r4   r  r#   r$  )r@   zfnamer   s      r)   test_extract_dir_backslashz,TestWithDirectory.test_extract_dir_backslash|  s   01__V$ 	%OOG$	%77d?OOBGGMM"'',,w*DEFOOBGGMM"'',,wS*IJKOOBGGNN277<<c3+OPQOOBGGMM"'',,w*DEFOOBGGMM"'',,wS*IJKOOBGGNN277<<+KLMOOBGGNN277<<+JKLRWW^^BGGLL#,FGHRWW^^BGGLL#,FGH	% 	%s   L))L3c           	         t         j                  j                  t        d      }t        j                  |       t        j
                  |      j                  dz  }t        j                  t        d      5 }|j                  |       |j                  d   }| j                  |j                  j                  d             | j                  |j                   |dz  dz         |j                  |d       |j                  d   }| j                  |j                  d	       | j                  |j                   |dz  dz         d d d        t        j                  t        d
      5 }|j                  d   }| j                  |j                  j                  d             | j                  |j                   |dz  dz         |j                  d   }| j                  |j                  d	       | j                  |j                   |dz  dz         t         j                  j                  t        d      }t        j                  |       |j#                  |       | j                  t         j                  j%                  t         j                  j                  |d                   | j                  t'        t        j(                  |            d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r^  rH   r   z/x/r  yr\   zy/rV   r  r   )rU  r   r4   r"   r  ra  st_moderN   rO   r   r>   r   ri   ro   rR  r`   r%  r  rG  rf   listdir)r@   dirpathrM   r   r&  r  s         r)   test_write_dirz TestWithDirectory.test_write_dir  s*   '',,w,
www''&0__VS) 	GTJJwMM!$EOOENN33E:;U0042:2EFJJw$MM!$EOOENND1U0042:2EF	G __VS) 	9TMM!$EOOENN33E:;U0042:2EFMM!$EOOENND1U0042:2EFWW\\'84FHHVOOF#OOBGGMM"'',,vs*CDESF!34a8	9 	9	G 	G	9 	9s   6CK$E-K'K$'K0c           	         t        j                  t         j                  j                  t        d             t        j                  t        d      5 }|j                  dd       |j                  d   }| j                  |j                  d       | j                  |j                  d       d d d        t        j                  t        d      5 }|j                  d   }| j                  |j                  j                  d             | j                  |j                  d       t         j                  j                  t        d      }t        j                  |       |j                  |       | j                  t         j                  j!                  t         j                  j                  |d                   | j                  t        j"                  |      dg       d d d        y # 1 sw Y   ?xY w# 1 sw Y   y xY w)	Nr   rH   zx/r/   r   i ArV   r  )rU  r  r   r4   r"   rN   rO   r   rP   r   r`   ro   r%  ri   rR  r  rG  rR  )r@   r   r&  r  s       r)   test_writestr_dirz#TestWithDirectory.test_writestr_dir  sh   
gs+,__VS) 	JTMM$$MM!$EU^^T2U002HI		J
 __VS) 	8TMM!$EOOENN33D9:U002HIWW\\'84FHHVOOF#OOBGGMM"'',,vs*CDERZZ/#7	8 	8	J 	J
	8 	8s   AG)DG6)G36G?c                    t        j                  t        d      5 }|j                  d       |j                  d   }| j                  |j                  d       | j                  |j                  d       |j                  d       |j                  d   }| j                  |j                  d       | j                  |j                  d       |j                  dd	
       |j                  d   }| j                  |j                  d       | j                  |j                  d       t        j                  d      }d|_        d|_	        d|_
        d|_        |j                  |       |j                  d   }| j                  |j                  d       | j                  |j                  |j                         t        j                  j                  t        d      }t        j                  |       |j!                  |       | j                  t#        t        j$                  |            h d       d d d        y # 1 sw Y   y xY w)NrH   rt   r   
directory/i Adirectory2/r\   
directory3i  rL   r   zdirectory3/zdirectory4/r  r  >   rt   
directory2rZ  
directory4)rN   rO   r   r  r   r`   ro   r%  r	  CRCrp   r  rU  r   r4   r"   r  setrR  )r@   r  r&  	old_zinfo	new_zinfor  s         r)   
test_mkdirzTestWithDirectory.test_mkdir  s   __VS) 	oRHH[!KKNEU^^\:U002HIHH]#KKNEU^^];U002HIHH\H.KKNEU^^];U002HI6I&<I#IM"#I&'I#HHYAIY//?Y44i6M6MNWW\\'84FHHVMM&!SF!346mn;	o 	o 	os   HH<<Ic                 l   t        j                  t        d      5 }|j                  t        j                  d      d       |j
                  d   }| j                  |j                  d       t        j                  j                  t        d      }t        j                  |       t        j                  |      j                  dz  }|j                  |d       |j
                  d	   }| j                  |j                  d       | j                  |j                   |d
z  d
z         t        j                  j                  t        d      }t        j                  |       |j#                  |       | j                  t%        t        j&                  |            ddh       d d d        y # 1 sw Y   y xY w)NrH   rX  r]  r   r[  r^  rY  )r  r\   r  r  rt   )rN   rO   r   rP   r	  r   r`   ro   rU  r   r4   r"   r  ra  rQ  r>   r%  r  r^  rR  )r@   r  r&  rt   rM   r  s         r)    test_create_directory_with_writez2TestWithDirectory.test_create_directory_with_write  s;   __VS) 	SRKK5r:KKNEU^^\:Wl;IHHY779%--6DHHYH6KKNEU^^];U0042:2EFWW\\'84FHHVMM&!SF!34{L6QR%	S 	S 	Ss   FF**F3c                     t        j                         }t        j                  |d      }|j	                  d       |j                  dd       |j                  t               y)z
        gh-112795: Some tools or self constructed codes will add '/' folder to
        the zip file, this is a strange behavior, but we should support it.
        rH   rN  z./a.txtaaaN)r%   r&   rN   rO   r  rP   r  r"   )r@   in_memory_filer  s      r)   test_root_folder_in_zipfilez-TestWithDirectory.test_root_folder_in_zipfile  sD    
 __^S1

Iu%
gr/   c                     t        t               t        j                  j	                  t
              rt        t
               y y r!   )r   r"   rU  r   r$  r   r   r  s    r)   r  zTestWithDirectory.tearDown  s%    w77>>&!6N "r/   N)r  r  r  rB   rH  rJ  rN  rT  rV  ra  rc  rg  r  r   r/   r)   rC  rC  l  s9    N 
I 948"o@S*	r/   rC  c                   *    e Zd Zd Zd Zd Zd Zd Zy)ZipInfoTestsc                 `   t         j                  j                  t              }| j	                  t        j                  |j                        d       | j                  |j                                | j	                  |j                  t        j                  j                  t                     y Nztest_core.py)rN   r	  	from_filerP  r`   	posixpathrZ  ro   r#   is_dirrp   rU  r   r_  rt  s     r)   test_from_filezZipInfoTests.test_from_file  sj    __&&x0++BKK8.I%rwwx'@Ar/   c                 r   t         j                  j                  t        t                    }| j                  t        j                  |j                        d       | j                  |j                                | j                  |j                  t        j                  j                  t                     y rl  )rN   r	  rm  r   rP  r`   rn  rZ  ro   r#   ro  rp   rU  r   r_  rt  s     r)   test_from_file_pathlikez$ZipInfoTests.test_from_file_pathlike  so    __&&x'9:++BKK8.I%rwwx'@Ar/   c                    t         j                  j                  t        j                  t
              d      }| j                  t        j                  |j                        d       | j                  |j                                | j                  |j                  t        j                  j                  t
                     y )Nr'   )rN   r	  rm  rU  fsencoderP  r`   rn  rZ  ro   r#   ro  rp   r   r_  rt  s     r)   test_from_file_bytesz!ZipInfoTests.test_from_file_bytes
  su    __&&r{{8'<fE++BKK8&A%rwwx'@Ar/   c                    t        t        d      5 }t        j                  j	                  |j                         d      }| j                  t        j                  |j                        d       | j                  |j                                | j                  |j                  t        j                  j                  t                     d d d        y # 1 sw Y   y xY w)Nr6  r'   )r=   rP  rN   r	  rm  r  r`   rn  rZ  ro   r#   ro  rp   rU  r   r_  )r@   r(   r  s      r)   test_from_file_filenoz"ZipInfoTests.test_from_file_fileno  s    (D! 	FQ**188:v>BY//<fERYY[)R\\277??8+DE		F 	F 	Fs   B:CCc                    t         j                  j                  t         j                  j                  t                    }t
        j                  j                  |d      }| j                  |j                  d       | j                  |j                                | j                  |j                  t
        j                         | j                  |j                  d       y )Nstdlib_testszstdlib_tests/r   )rU  r   rO  abspathrP  rN   r	  rm  r`   ro   ri   ro  r   r   rp   )r@   rS  r  s      r)   test_from_dirzZipInfoTests.test_from_dir  s    ''//"''//(";<__&&w?o6		$))7+=+=>q)r/   N)r  r  r  rp  rr  ru  rw  r{  r   r/   r)   rj  rj    s    BBBF*r/   rj  c                   J    e Zd Zd Zd Zd Zd Zd Z e       d        Z	d Z
y)	CommandLineTestc                     t        j                  ddg|i |\  }}}|j                  t        j                  j                         d      S )N-mrN   r  )r   assert_python_okr  rU  linesepr  )r@   argsrQ   rcouterrs         r)   
zipfilecmdzCommandLineTest.zipfilecmd"  sL    $55dI @ @8>@C{{2::,,.66r/   c                 0    t        j                  ddg| S )Nr  rN   )r   assert_python_failure)r@   r  s     r)   zipfilecmd_failurez"CommandLineTest.zipfilecmd_failure'  s    224JTJJr/   c                    | j                         \  }}}| j                  |d       | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  dd      \  }}}| j                  |d       | j	                  |j                         d       y )Nr/   s   usages   errors   required-lr]  )r  r`   rg   r  assertNotEqualstrip)r@   r  r  r  s       r)   test_bad_usezCommandLineTest.test_bad_use*  s    ..0Cc"h		,h		,k399;/..tR8Cc"CIIK-r/   c                     t        d      }dD ]4  }| j                  ||      }| j                  |j                         d       6 t        d      }| j	                  d|      \  }}}| j                  |d       y )NrF  )-tz--tests   Done testingztesttar.tarr  r/   )r	   r  r`   rstripr  )r@   zip_nameoptr  r  r  s         r)   test_test_commandz!CommandLineTest.test_test_command4  su    L)! 	<C//#x0CSZZ\?;	< M*..tX>Cc"r/   c                 T   t        d      }t        j                         }t        j                  |d      5 }|j                  |       d d d        |j                         j                  dd      }dD ](  }| j                  ||d      }| j                  ||       * y # 1 sw Y   WxY w)NrF  rV   r.   backslashreplace)r  z--listzascii:backslashreplace)PYTHONIOENCODING)
r	   r%   rb   rN   rO   rc   rd   r  r  r`   )r@   r  r\  tfexpectedr  r  s          r)   test_list_commandz!CommandLineTest.test_list_command=  s    L)KKM__Xs+ 	rKKN	::<&&w0BC! 	,C//#x3K " MCS(+	,	 	s   BB'c                    | j                  t        t               t        t        dd      5 }|j	                  d       d d d        t        j                  t               | j                  t        t               t        t
        j                  j                  t        d      dd      5 }|j	                  d       d d d        t        t        g}t        t        dz   t        dz   g}d	D ]  }	  | j                  |t        g| }| j                  |d
       t        j                  t              5 }| j                  |j!                         |       | j                  |j#                  |d         d       | j                  |j#                  |d         d       d d d        t        t                y # 1 sw Y   vxY w# 1 sw Y   xY w# 1 sw Y   5xY w# t        t               w xY w)NrH   r@  rA  ztest 1zfile.txtztest 2rN  z	/file.txt)-cz--creater/   r   s   test 1r   s   test 2)r  r   r   r=   r>   rU  r  	TESTFNDIRr   r   r4   r  r"   r`   rN   rO   rm   ra   )r@   r(   filesrm   r  r  r  s          r)   test_create_commandz#CommandLineTest.test_create_commandH  s|   '&#0 	AGGH	
	*"'',,y*5sWM 	QRGGH	#IOY-DE# 		 C %dooc7;U;  c*__W- F$$R[[]H=$$RWWXa[%99E$$RWWXa[%99EF
 w		 	 		 	F F
 ws=   F3*G -AG0A)GG3F= G
G	GG*c                 B   t        d      }dD ]h  }t               5 }| j                  |||      }| j                  |d       t	        j
                  |      5 }|j                         D ]  }t        j                  j                  ||j                  j                  dt        j                              }|j                         r/| j                  t        j                  j                  |             | j                  t        j                  j!                  |             t#        |d      5 }| j                  |j%                         |j%                  |             d d d         	 d d d        d d d        k y # 1 sw Y   xY w# 1 sw Y   "xY w# 1 sw Y   xY w)NrF  )-ez	--extractr/   rN  r6  )r	   r   r  r`   rN   rO   rn   rU  r   r4   ro   r  rS  ro  ri   rG  r  r=   ra   )	r@   r  r  r  r  r  r  r   r(   s	            r)   test_extract_commandz$CommandLineTest.test_extract_command^  sT   L)$ 	HC Hvooc8V<  c*__X. 	H" kkm H!ww||F$&KK$7$7RVV$D F99; OOBGGMM$,?@ OOBGGNN4,@A!%dD!1 HQ $ 0 02772; GH HH	HH H	HH H	H 	HH Hs<   ;FCF,0E;
F'F;F FFFF	N)r  r  r  r  r  r  r  r  r
   r  r  r   r/   r)   r}  r}     s8    7
K.#	, _   *Hr/   r}  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y)TestExecutablePrependedZipz@Test our ability to open zip files with an executable prepended.c                 L    t        dd      | _        t        dd      | _        y )Nexe_with_zipziptestdata)r  exe_with_z64)r	   exe_zip	exe_zip64r  s    r)   rB   z TestExecutablePrependedZip.setUps  s    }E!.Gr/   c                    | j                  t        j                  |      d|        t        j                  |      5 }|j	                         D ]%  }|j                  |      }| j                  d|       ' 	 d d d        y # 1 sw Y   y xY w)Nzis_zipfile failed on s   FAVORITE_NUMBER)ri   rN   r+  rO   rm   ra   rg   )r@   r  rR   r  r5   s        r)   _test_zip_worksz*TestExecutablePrependedZip._test_zip_worksw  s|    **40/v6	8 __T" 	8e^^% 8zz!}0$78	8 	8 	8s   9BB
c                 :    | j                  | j                         y r!   )r  r  r  s    r)    test_read_zip_with_exe_prependedz;TestExecutablePrependedZip.test_read_zip_with_exe_prepended  s    T\\*r/   c                 :    | j                  | j                         y r!   )r  r  r  s    r)   "test_read_zip64_with_exe_prependedz=TestExecutablePrependedZip.test_read_zip64_with_exe_prepended  s    T^^,r/   zsys.executable required.z	/bin/bashz#Test relies on #!/bin/bash working.c                     t        j                  | j                  t        j                  g      }| j                  d|       y Ns   number in executable: 5)
subprocesscheck_outputr  sys
executablerg   r@   outputs     r)   test_execute_zip2z,TestExecutablePrependedZip.test_execute_zip2  s0    
 (($,,)GH0&9r/   c                     t        j                  | j                  t        j                  g      }| j                  d|       y r  )r  r  r  r  r  rg   r  s     r)   test_execute_zip64z-TestExecutablePrependedZip.test_execute_zip64  s0    
 (($..#..)IJ0&9r/   N)r  r  r  r  rB   r  r  r  r  
skipUnlessr  r  rU  rB  X_OKr   r  r  r   r/   r)   r  r  p  s    JH8+- X)CDX;8>@: @ E: X)CDX;8>@: @ E:r/   r  c                       e Zd Zg dZdj	                  d      dj	                  d      dj	                  d      gZd Zd	 Zd
 Zd Z	d Z
d Zd Zd Zd Zd Zy)EncodedMetadataTests)u   一u   二u   三zThis is pure ASCII.
r.   u%   これは現代的日本語です。
r@  u"   これは古い日本語です。
	shift_jisc                    | j                  t        t               ddg| j                  dd  z   }t	        j
                  t        d      5 }t        || j                        D ]&  \  }}|j                  ||t        j                         ( 	 d d d        t        t        d      5 }|j                         }d d d        t        | j                  |d d       D ]5  \  }}j                  |j                  d      |j                  d            }7 t        t        d	      5 }|j                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)
Nn1n2r   rH   rL   r6  r.   r  r;   )r  r   r   
file_namesrN   rO   r   file_contentrP   r   r=   ra   r  r  r>   )r@   placeholdersr  tempr  r5   r  s          r)   rB   zEncodedMetadataTests.setUp  s1   ' d|dooab&99__V#. 	?"!$\43D3D!E ?gD'7+=+=>?	? &$ 	2779D	doo|BQ/?@ 	:JD$<<G 4 $K 8:D	: &$ 	2HHTN	 		? 	?	 	
	 	s%   
A D8#EE8EEEc                    |j                         }| j                  t        |      t        |             |j                         }|D cg c]  }|j                   }}| j                  t        |      t        |             t        ||      D ]x  \  }}|j                  |      }	| j                  |	j                  |       | j                  |	j                  t        |             | j                  |j                  |      |       z y c c}w r!   )
rm   r`   sortedrn   ro   r   rq   rp   rf   ra   )
r@   rR   expected_namesr  rz   r{   r  r  r  r}   s
             r)   
_test_readzEncodedMetadataTests._test_read  s     ~(>?  ',---~(>? !1AB 	8MD'==&DT]]D1T^^S\:UZZ-w7		8	 .s   	D
c                     t        j                  t        dd      5 }| j                  || j                  | j
                         d d d        y # 1 sw Y   y xY w)NrV   r  metadata_encoding)rN   rO   r   r  r  r  r/  s     r)    test_read_with_metadata_encodingz5EncodedMetadataTests.test_read_with_metadata_encoding  sG    __VSKH 	GEOOE4??D4E4EF	G 	G 	Gs   (AAc                 <   | j                   d d D cg c]"  }|j                  d      j                  d      $ c}| j                   dd  z   }t        j                  t
        d      5 }| j                  ||| j                         d d d        y c c}w # 1 sw Y   y xY w)Nr   r  cp437rV   r  r  r  rN   rO   r   r  r  r@   r  r  rR   s       r)   #test_read_without_metadata_encodingz8EncodedMetadataTests.test_read_without_metadata_encoding  s     '+oobq&9;" ++k299'B ;=A__QR=PQ__VS) 	FUOOE>43D3DE	F 	F;	F 	Fs   'B&BBc                 @   | j                   d d D cg c]"  }|j                  d      j                  d      $ c}| j                   dd  z   }t        j                  t
        dd      5 }| j                  ||| j                         d d d        y c c}w # 1 sw Y   y xY w)Nr   r  zkoi8-urV   r  r  r  s       r)   *test_read_with_incorrect_metadata_encodingz?EncodedMetadataTests.test_read_with_incorrect_metadata_encoding  s     '+oobq&9;" ++k299(C ;=A__QR=PQ__VSHE 	FOOE>43D3DE	F 	F;	F 	Fs   'B(BBc                    | j                  t              5  t        j                  t        dd       d d d        | j                  t              5  t        j                  t        dd       d d d        y # 1 sw Y   DxY w# 1 sw Y   y xY w)NrV   r.   r  r@  )r   UnicodeDecodeErrorrN   rO   r   r  s    r)   +test_read_with_unsuitable_metadata_encodingz@EncodedMetadataTests.test_read_with_unsuitable_metadata_encoding  sz     12 	DOOFC7C	D12 	DOOFC7C	D 	D	D 	D	D 	Ds   A6B6A?Bc                    d}| j                   d d D cg c]"  }|j                  d      j                  d      $ c}| j                   dd  z   }|j                  |       g | j                  d}t        j                  t        d      5 }|j                  |d       | j                  t        |j                               t        |             d d d        t        j                  t        d      5 }| j                  |||       d d d        t        j                  t        dd	      5 }| j                  t        |j                               t        |             t        t        ||            D ]  \  }\  }}|j                  |      }| j                  |j                   |       | j                  |j"                  t%        |             |dk  r:| j'                  t
        j(                        5  |j+                  |       d d d        | j                  |j+                  |      |        	 d d d        y c c}w # 1 sw Y   pxY w# 1 sw Y   GxY w# 1 sw Y   xY w# 1 sw Y   y xY w)
Nu   四r   r  r  r  r2  
newcontentrV   r  )r  r  r  r   r  rN   rO   r   rP   r`   r  rm   r  	enumerater   rq   ro   rp   rf   r   r  ra   )	r@   newnamer  r  r  rR   r7   r  r}   s	            r)   test_read_after_appendz+EncodedMetadataTests.test_read_after_append  s    &*oobq&9;" ++k299'B ;=A__QR=PQg&>T..>>__VS) 	OUNN7L1VENN$45vn7MN	O __VS) 	EUOOE>3CD	E __VSKH 
	@EVENN$45vn7MN&/NDT0U&V @"?D'}}T*  5  W>q5**7+=+=> )

4() ) $$UZZ%5w?@
	@ 
	@;
	O 	O	E 	E) )
	@ 
	@sC   'H8
AH=1I
)CI#0I,I#=I
II I##I,c                     t         j                  }dD ],  }| j                  t        d      5   |d|d       d d d        . y # 1 sw Y   9xY w)N)rH   r   r2  z^metadata_encoding is onlyznonesuch.zipr  r  )rN   rO   r  r  )r@   ZFrM   s      r)   !test_write_with_metadata_encodingz6EncodedMetadataTests.test_write_with_metadata_encoding  s[    __# 	HD''
(DF H>4;GH H	HH Hs   AA	c                    d}g d}t               5 }t               5 }| j                  t        t        j
                  |       d d d        d d d        | j                  j                         d       | j                  |j                                t               5 }t	        j
                  ddt        g       d d d        |j                         }t               5 }t	        j
                  ddt        g       d d d        |j                         }| j                  D ]  }| j                  ||        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   axY w)Nz/Non-conforming encodings not supported with -c.)--metadata-encoding=shift_jisr  nonesuchr  r]  r  r  r  )r   r   r   
SystemExitrN   mainr`   rd   rg   r   r  )r@   errmsgr  stdoutstderrlistingr  s          r)   test_cli_with_metadata_encodingz4EncodedMetadataTests.test_cli_with_metadata_encoding  s5   BN 	B& " Bf!!*gllDAB	B 	*B/ffoo/0 	J&LL94HI	J//# 	J&LL94HI	J//#OO 	)DMM$(	)B B	B 	B	J 	J	J 	Js:   E &D4E EE4D=	9E  E	EE!c                    t        j                  t               | j                  t        t               | j
                  D ]:  }	 t        j                  t         j                  j                  t        |             < t        j                  ddt        t        g       t        j                  t              }| j
                  D ]  }| j!                  ||        y # t        $ r Y t        $ r | j                  d|       Y w xY w)Nzcannot encode file name r  r  )rU  r  r"   r  r   r  ra  r   r4   r   UnicodeEncodeErrorr`  rN   r  r   rR  rg   )r@   rv   r  r  s       r)   'test_cli_with_metadata_encoding_extractz<EncodedMetadataTests.test_cli_with_metadata_encoding_extract  s    
( // 	ABAWb12	A 	5tVWMN**W%OO 	)DMM$(	)  % A 8?@As   7C	D&DDN)r  r  r  r  r  r  rB   r  r  r  r  r  r  r  r  r  r   r/   r)   r  r    sr    /J&&w/T[[\cdNUUVabL(8"G
FFD@4H)&)r/   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)StripExtraTestsr\   c                 <   t        j                  d      }|j                  | j                  d      }|j                  dd      }|j                  dd      }| j	                  dt        j                  || j                  f             | j	                  |t        j                  || j                  f             | j	                  |dz   t        j                  |dz   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             y )Nr  r   r   r  r/      zrc  Structr  ZIP64_EXTRAr`   rN   _strip_extrar@   r  r2  r  r  s        r)   test_no_datazStripExtraTests.test_no_data0  sZ   MM% FF4##Q'FF1aLFF1aLg221t7G7G6IJKG00T5E5E4GHIdFG((4$2B2B1DE	G 	1g221Q3q54;K;K:MNO1g221Q3q54;K;K:MNO1g221Q3q54;K;K:MNOr/   c                 N   t        j                  d      }|j                  | j                  d      dz   }|j                  dd      dz   }|j                  dd      dz   }| j	                  dt        j                  || j                  f             | j	                  |t        j                  || j                  f             | j	                  |d	z   t        j                  |d	z   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             | j	                  ||z   t        j                  ||z   |z   | j                  f             y )
Nr  r\   r  r      bbr  s   cccr/   r  r  r  s        r)   test_with_datazStripExtraTests.test_with_data?  si   MM% FF4##Q'$.FF1aL5 FF1aL6!g221t7G7G6IJKG00T5E5E4GHIdFG((4$2B2B1DE	G 	1g221Q3q54;K;K:MNO1g221Q3q54;K;K:MNO1g221Q3q54;K;K:MNOr/   c                    t        j                  d      }|j                  | j                  d      dz   }|j                  dd      dz   }| j	                  dt        j                  ||z   | j                  f             | j	                  dt        j                  ||z   |z   | j                  f             | j	                  dt        j                  ||z   dz   | j                  f             | j	                  |dz   t        j                  ||z   |z   dz   | j                  f             | j	                  |t        j                  ||z   |z   | j                  f             | j	                  |t        j                  ||z   |z   | j                  f             | j	                  |t        j                  ||z   |z   | j                  f             y )Nr  r\   r  r   r  r/   r  r  )r@   r  r2  r  s       r)   test_multipleszStripExtraTests.test_multiplesN  s   MM% FF4##Q'$.FF1aL5 g221Q39I9I8KLMg221Q3q54;K;K:MNO'&&qs4x$2B2B1DE	GdFG((1Qtd6F6F5HI	K 	G001Q9I9I8KLMG001Q9I9I8KLMG001Q9I9I8KLMr/   c                    | j                  dt        j                  d| j                  f             | j                  dt        j                  d| j                  f             | j                  dt        j                  d| j                  f             | j                  dt        j                  d| j                  f             y )Nr/   r  s   zzs   zzz)r`   rN   r  r  r  s    r)   test_too_shortzStripExtraTests.test_too_short^  s    g2239I9I8KLMw33D4;K;K:MNO7''0@0@/BC	EG(($2B2B1DE	Gr/   N)r  r  r  r  r  r  r  r  r   r/   r)   r  r  )  s!    
 KPPN Gr/   r  __main__)Yr+  r1  importlib.utilrV  r%   r  rU  rn  rc  r  r  rj   r  unittest.mockr  rN   tempfiler   r   r   r   r'   r   test.supportr   r	   r
   r   r   r   r   r   test.support.os_helperr   r   r   r   r   r   r   r"   r  r1   DATAFILES_DIRr  r*   r,   TestCaser"  ri  rr  rw  r|  r  r  r  r  r   r3  r6  r8  r:  r<  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  rC  rj  r}  r  r  r  r  r  r   r/   r)   <module>r     s      	  	    
     # - -  &    
 3,SL	#T
#g gT~J ; ( 1 1~JB H!<!)!2!2H H $:'00$ $ #9&//# #
O Od\0"?"*"3"3\0~ '#@#+#4#4' ' $!>!)!2!2$ $ # = ( 1 1# #
/1 /1b%+X->-> % ',h.?.? ' ' $*H,=,= $ $ #)8+<+< # #~X&& ~B8$$ D$^22H4E4E $6G
"" G
T >
+X->-> 
 
7,h.?.? 
7 
7 *H,=,=   &)8+<+< & &qh'' qhX; X;v%'I'/'8'8% '(J(0(9(9' ' $&H&.&7&7$ $ #%G%-%6%6# #   4@h'' 4@n zX.. z zzN)) Nb *8$$  *FMHh'' MH`%:!2!2 %:PN)8,, N)b;Gh'' ;G| zHMMO r/   