
    5\h                        	 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m	Z	 d dl
mZ d dl
mZ d dl
mZmZmZ d dlmZmZ  ej        d          ZdZd	Zej                            ej                  d
z   Z G d dej                  Z G d dej                  Z G d de          Z G d de          Z d Z! G d dej                  Z"e#dk    r ej$                     dS dS )    N)PIPEPopen)import_helper)	os_helper)_4G
bigmemtestrequires_subprocess)assert_python_okassert_python_failuregzipsy     int length=DEFAULTALLOC, err = Z_OK;
  PyObject *RetVal;
  int flushmode = Z_FINISH;
  unsigned long start_total_out;

s   /* zlibmodule.c -- gzip-compatible data compression */
/* See http://www.gzip.org/zlib/
/* See http://www.winimage.com/zLibDll for Windows */
z-gzdirc                        e Zd Zd Zd Zd ZdS )UnseekableIOc                     dS )NF selfs    8/opt/python-3.11.14/usr/lib/python3.11/test/test_gzip.pyseekablezUnseekableIO.seekable$   s    u    c                     t           j        NioUnsupportedOperationr   s    r   tellzUnseekableIO.tell'       %%r   c                     t           j        r   r   )r   argss     r   seekzUnseekableIO.seek*   r   r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r   #   sA          & & && & & & &r   r   c                   (    e Zd Zej        Zd Zd ZdS )BaseTestc                 8    t          j        | j                   d S r   r   unlinkfilenamer   s    r   setUpzBaseTest.setUp1       '''''r   c                 8    t          j        | j                   d S r   r&   r   s    r   tearDownzBaseTest.tearDown4   r*   r   N)r    r!   r"   r   TESTFNr(   r)   r,   r   r   r   r$   r$   .   s:        H( ( (( ( ( ( (r   r$   c                   h   e Zd Zd8dZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Z ee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+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7S )9TestGzipbc                    t          |          }t                              | j        d|z             5 }|                    |          }d d d            n# 1 swxY w Y   |                     |t          |                     t                              | j        d|z             5 }|                     |                                |           d d d            d S # 1 swxY w Y   d S )Nwr)bytesr   GzipFiler(   writeassertEquallenread)r   datamodeb_datafls         r   write_and_read_backzTestGzip.write_and_read_back9   s=   t]]4=#d(33 	qA	 	 	 	 	 	 	 	 	 	 	 	 	 	 	CKK(((]]4=#d(33 	/qQVVXXv...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s#   AAA&)CC #C c                    t                               | j        d          5 }|                    t          dz             |                                 |                                 t          t          d          r&t          j	        |                                           |
                                 d d d            n# 1 swxY w Y   |
                                 d S )Nwb2   fsync)r   r5   r(   r6   data1flushfilenohasattrosrC   closer   r=   s     r   
test_writezTestGzip.test_writeA   s    ]]4=$// 	1GGEBJ GGIIIHHJJJr7## %$$$GGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
					s   BCC	Cc                 :   t          j        | j                  }t                              |d          5 }|                    t          dz             d d d            n# 1 swxY w Y   |                     |j        t                     | 
                    |j        | j                   t                              |d          5 }|                    t                     d d d            n# 1 swxY w Y   t                              |          5 }|                                }d d d            n# 1 swxY w Y   | 
                    |t          dz             |                     |j        t                     | 
                    |j        | j                   d S )Nr2   rB   a3   )r   FakePathr(   r   r5   r6   rD   assertIsInstancenamestrr7   r9   )r   r(   r=   ds       r   "test_write_read_with_pathlike_filez+TestGzip.test_write_read_with_pathlike_fileO   s   %dm44]]8S)) 	 QGGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 afc***///]]8S)) 	QGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	]]8$$ 	A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	EBJ'''afc***/////s5   AA#&A#C,,C03C0D22D69D6c                    |                      t          t          dz                       t          t          t	          d                              }|                    dg d          }|                      |           d S )NrB      B)   rX      )shape)r?   
memoryviewrD   r4   rangecast)r   mr:   s      r   test_write_memoryviewzTestGzip.test_write_memoryview`   sp      EBJ!7!7888uU3ZZ(())vvcv))  &&&&&r   c                 Z    |                      t          t          dz                       d S )NrB   )r?   	bytearrayrD   r   s    r   test_write_bytearrayzTestGzip.test_write_bytearrayf   s(      52:!6!677777r   c                 f    |                      t          j        dt          dz                       d S )NI(   )r?   arrayrD   r   s    r   test_write_arrayzTestGzip.test_write_arrayi   s,      S%"*!=!=>>>>>r   c                    t                               | j        d          5 }|                     t                    5  |                    d           d d d            n# 1 swxY w Y   |                     t                    5  |                    g            d d d            n# 1 swxY w Y   |                    t                     d d d            n# 1 swxY w Y   t                               | j        d          5 }|                     |                                t                     d d d            d S # 1 swxY w Y   d S )NrA    rb)	r   r5   r(   assertRaises	TypeErrorr6   rD   r7   r9   rJ   s     r   test_write_incompatible_typez%TestGzip.test_write_incompatible_typel   s    ]]4=$// 	1""9--                ""9--                GGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]4=$// 	.1QVVXXu---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.sj   CACA"	"C%A"	&CB%C%B)	)C,B)	-CCC.D<<E E c                    |                                   t                              | j        d          5 }|                                }d d d            n# 1 swxY w Y   |                     |t          dz             d S )Nr3   rB   )rK   r   r5   r(   r9   r7   rD   r   r=   rS   s      r   	test_readzTestGzip.test_ready   s    ]]4=#.. 	!A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	E"H%%%%%s   AAAc                    |                                   g }d}t                              | j        d          5 }	 |                                }|snP|                    |           |t          |          z  }|                     |                                |           g	 d d d            n# 1 swxY w Y   |                     d	                    |          t          dz             d S )Nr   r3   Tr   rB   )rK   r   r5   r(   read1appendr8   r7   r   joinrD   )r   blocksnreadr=   rS   s        r   
test_read1zTestGzip.test_read1   s   ]]4=#.. 	2!2GGII a   Q  51112 		2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	&))52:66666s   A)B//B36B3   )sizememusec                     t                               t          d          }t                               t	          j        |          d          }|                     |                    |          t                     d S )Nrx   compresslevelrj   fileobjr;   )r   compressrD   r5   r   BytesIOr7   r9   )r   ry   
compressedr=   s       r   test_read_largezTestGzip.test_read_large   s^     ]]5]::
MM"*Z"8"8tMDDu-----r   c                    |                                   t                              | j        d          }|j        }|                     |j                   |                                 |                     |j                   | 	                    t                    5  |                    d           d d d            n# 1 swxY w Y   | 	                    t                    5  |                    d           d d d            n# 1 swxY w Y   | 	                    t                    5  |                                 d d d            n# 1 swxY w Y   t                              | j        d          }|j        }|                     |j                   |                                 |                     |j                   | 	                    t                    5  |                    d           d d d            n# 1 swxY w Y   | 	                    t                    5  |                                 d d d            d S # 1 swxY w Y   d S )Nr3   rx   r   r2   r   )rK   r   r5   r(   r   assertFalseclosedrI   
assertTruerk   
ValueErrorr9   r   r   r6   rE   )r   r=   r   s      r   test_io_on_closed_objectz!TestGzip.test_io_on_closed_object   s   
 	MM$---)(((				'''z** 	 	FF1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	FF1III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	FFHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 MM$---)(((				'''z** 	 	GGCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	 	GGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sZ   C  CC%DDD,EEE!HH
H(I

IIc                    |                                   t                              | j        d          5 }|                    t
          dz             d d d            n# 1 swxY w Y   t                              | j        d          5 }|                                }d d d            n# 1 swxY w Y   |                     |t          dz  t
          dz  z              d S )Nab   rj   rB   )	rK   r   r5   r(   r6   data2r9   r7   rD   ro   s      r   test_appendzTestGzip.test_append   s0   ]]4=$// 	 1GGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  ]]4=$// 	1A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	U2X%(344444s#   AA#&A#
B++B/2B/c                 D   t                               | j        dd          5 }|                    d           d d d            n# 1 swxY w Y   t	          dd          D ]P}t                               | j        dd          5 }|                    d           d d d            n# 1 swxY w Y   Qt                               | j        d          5 }d}	 |                    d
          }||z  }|sn	 d d d            n# 1 swxY w Y   |                     |d           d S )NrA   	      ar      r   rj   r   rx   i    s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)r   r5   r(   r6   r\   r9   r7   )r   r=   izgfilecontentsztxts         r   test_many_appendzTestGzip.test_many_append   s    ]]4=$22 	aGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	q# 	 	At}dA66 !               ]]4=$// 	#6H#{{4((D "U# #	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	8,,,,,s5   AAAB$$B(	+B(	"C??DDc                 &   t                               | j        d          5 }|                    t          dz             d d d            n# 1 swxY w Y   t                               | j        d          5 }|                     |                                t          dz             d d d            n# 1 swxY w Y   |                     t                    5  t                               | j        d           d d d            d S # 1 swxY w Y   d S )NxbrB   rj   )	r   r5   r(   r6   rD   r7   r9   rk   FileExistsErrorrJ   s     r   test_exclusive_writezTestGzip.test_exclusive_write   s   ]]4=$// 	 1GGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]]4=$// 	31QVVXXurz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3// 	/ 	/MM$-...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s5   AAA61B33B7:B7!DD
D
c                 r   |                                   t                              | j        d          5 }t	          j        |          5 }d |D             }d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |dt                              d          z             d S )Nrj   c                     g | ]}|S r   r   ).0lines     r   
<listcomp>z1TestGzip.test_buffered_reader.<locals>.<listcomp>   s    ,,,$,,,r   rB   Tkeepends)	rK   r   r5   r(   r   BufferedReaderr7   rD   
splitlines)r   r=   r3   liness       r   test_buffered_readerzTestGzip.test_buffered_reader   s&    	]]4=$// 	-1"1%% -,,!,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	U%5%5t%5%D%D DEEEEEs5   A:
A#A:#A'	'A:*A'	+A::A>A>c                 B   |                                   t                              | j        d          5 }d}	 |                    |          }|s|dk    rn/|                     t          |          |k               |dz   dz  }M	 d d d            d S # 1 swxY w Y   d S )Nrj   r   rx   rB   )rK   r   r5   r(   readliner   r8   )r   r=   line_lengthLs       r   test_readlinezTestGzip.test_readline   s     ]]4=$// 	51K5JJ{++4[A--uA+ 5666*Q"4	5/4		5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   ABBBc                 v   |                                   t                              | j        d          5 }|                                }d d d            n# 1 swxY w Y   t                              | j        d          5 }	 |                    d          }|g k    rn	 d d d            d S # 1 swxY w Y   d S )Nrj   rx      )rK   r   r5   r(   	readlines)r   r=   r   s      r   test_readlineszTestGzip.test_readlines   s+    ]]4=$// 	1A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ]]4=$// 	"1"KK$$77E"!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s#   AAAB..B25B2c                 &   |                                   t                              | j                  5 }	 |                                }|                                }|sn|                                }|                    |           t          |          dk    rd}nt          |          }|                    |          }| 	                    |d |         |           |                    |           	 d d d            d S # 1 swxY w Y   d S )Nrx   
   )
rK   r   r5   r(   r   r   r   r8   r9   r7   )r   r=   oldposline1newposamountline2s          r   test_seek_readzTestGzip.test_seek_read   s3    ]]4=)) 	Q

#evu::b==FF ZZFv  ww777v $		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   CDD
D
c                 d   |                                   t                              | j                  5 }|                    d           |                    dd           |                    d          }d d d            n# 1 swxY w Y   |                     |t          dd                    d S )Nr   rx   )whence      )rK   r   r5   r(   r9   r   r7   rD   )r   r=   ys      r   test_seek_whencezTestGzip.test_seek_whence  s     ]]4=)) 	QFF2JJJFF2aF   r

A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	E"R%L)))))s   ABB	Bc                     t                               | j        d          5 }t          ddd          D ],}|                    |           |                    d           -	 d d d            d S # 1 swxY w Y   d S )Nr2   r   rV      s   GZ
)r   r5   r(   r\   r   r6   )r   r=   poss      r   test_seek_writezTestGzip.test_seek_write  s    ]]4=#.. 	!!QR(( ! !s    !	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   ?A..A25A2c                    |                                   t                              | j        d          5 }|                     |j        j        d           d d d            n# 1 swxY w Y   t          j        | j                   t                              | j        d          5 }|                     |j        j        d           d d d            d S # 1 swxY w Y   d S )Nr3   rj   xr   )	rK   r   r5   r(   r7   	myfileobjr;   r   r'   rJ   s     r   	test_modezTestGzip.test_mode  s:   ]]4=#.. 	5!Q[-t444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5''']]4=#.. 	5!Q[-t444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s#   !A""A&)A&&!CCCc                    dD ]}}t                               | j        |          5 }|                     t	          |d                     |                     |j        | j                   d d d            n# 1 swxY w Y   ~d S )N)rA   rj   rQ   )r   r5   r(   r   rG   r7   rQ   )r   r;   r=   s      r   test_1647484zTestGzip.test_1647484'  s      	8 	8Dt}d33 8q6 2 2333  7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8	8 	8s   AA55A9	<A9	c                 :   |                                   t                              | j        d          5 }|                     t          |j        d                     |                     |j        j        | j                   d d d            d S # 1 swxY w Y   d S )Nrj   rQ   )	rK   r   r5   r(   r   rG   r   r7   rQ   rJ   s     r   test_paddedfile_getattrz TestGzip.test_paddedfile_getattr-  s    ]]4=$// 	<1OOGAIv66777QY^T];;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   ABBBc                 0   d}t                               | j        d|          5 }|                    t                     d d d            n# 1 swxY w Y   t                               | j                  5 }|                     t          |d                     |                     |j                   |	                                }| 
                    |t                     | 
                    |j        |           d d d            d S # 1 swxY w Y   d S )N[r2   mtimer   )r   r5   r(   r6   rD   r   rG   assertIsNoner   r9   r7   )r   r   fWritefReaddataReads        r   
test_mtimezTestGzip.test_mtime3  sg   ]]4=#u]== 	 LL	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ]]4=)) 	1UOOGE733444ek***zz||HXu---U[%000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s$   AAA6BDDDc           
      p   d}t                               | j        d|          5 }|                    t                     d d d            n# 1 swxY w Y   t          | j        d          5 }|                    d          }|                     |d           |                    d          }|                     |d           	 | j                            d	          d
z   }d}n# t          $ r d}d
}Y nw xY w|                    d          }|                     ||           |                    d          }	|                     |	t          j        d|                     |                    d          }
|                     |
d           |                    d          }|                     |d           |                    t          |                    }|                     ||           |                    t          j        | j                  j        dz
             |                    d          }|                     |d           |                    d          }|                     |t          j        dt          t                                         d d d            d S # 1 swxY w Y   d S )Nr   r2   r   rj         rx      zLatin-1    r   rY   z<i      rX   s   d)r   r5   r(   r6   rD   openr9   r7   encodeUnicodeEncodeErrorstructpackr8   r   rH   statst_size)r   r   r   r   idBytescmByteexpectednameexpectedflags	flagsByte
mtimeBytesxflByteosByte	nameBytes
crc32Bytes
isizeBytess                  r   test_metadatazTestGzip.test_metadata>  s   ]]4=#u]== 	 LL	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  $-&& +	H% jjmmGWk222ZZ]]FVW---(#}33I>>H '% ( ( (" '( 

1IY666AJZT5)A)ABBBjjmmGWg...ZZ]]FVW--- 

3|#4#455IY555 JJrwt}--59:::AJZ)9:::AJZT3u::)F)FGGGW+	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	H +	HsI   AAA,AJ+C$#J+$C52J+4C55F)J++J/2J/c                 P    t           j        | _        |                                  d S r   )r   TESTFN_ASCIIr(   r   r   s    r   test_metadata_ascii_namez!TestGzip.test_metadata_ascii_nameq  s$    !.r   c                    g d}d}|D ]\  }}}|                      |          5  t                              | j        d|          }|5  |                    t
                     d d d            n# 1 swxY w Y   t          | j        d          5 }|                    |           |                    d          }| 	                    ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N))fastrx      )bestr   r   )tradeoff   r   rX   r2   r|   rj   rx   )
subTestr   r5   r(   r6   rD   r   r   r9   r7   )	r   cases	xflOffsetrQ   levelexpectedXflByter   r   r   s	            r   test_compresslevel_metadataz$TestGzip.test_compresslevel_metadatau  s   
 
 

 	.3 	? 	?*T5/d## ? ?t}cOO ( (LL'''( ( ( ( ( ( ( ( ( ( ( ( ( ( ($-.. ?%JJy)))#jjmmG$$Wo>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? ? ? ? ? ? ? ? ? ? ? ? ? ? ?	? 	?sZ   %C4	A0$C40A44C47A48C4ACC4C!!C4$C!%C44C8	;C8	c                 T   t                               | j        d          5 }|                    d           d d d            n# 1 swxY w Y   t                               | j        d          }|                                 	 |5  	 d d d            n# 1 swxY w Y   |                     d           n# t          $ r Y nw xY w	 t                               | j        d          5 }ddz   d d d            n# 1 swxY w Y   |                     d           d S # t          $ r Y d S w xY w)NrA   s   xxxrj   z4__enter__ on a closed file didn't raise an exceptionrx   r   z1/0 didn't raise an exception)r   r5   r(   r6   rI   failr   ZeroDivisionErrorrJ   s     r   test_with_openzTestGzip.test_with_open  s   ]]4=$// 	1GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	MM$-..					N                
 IILMMMM  	 	 	D		7t}d33 q!              
 II566666 ! 	 	 	DD	s}   AA
AB4 BB4 BB4 BB4 4
C C D %C7+D 7C;;D >C;?D 
D'&D'c                    t                               | j        d          5 }|                    t          dz             d d d            n# 1 swxY w Y   t          | j        d          5 }|                    d           d d d            n# 1 swxY w Y   t                               | j        d          5 }|                                }|                     |t          dz  d           d d d            d S # 1 swxY w Y   d S )NrA   rB   r   s2                                                     rj   zIncorrect data in file)r   r5   r(   r6   rD   r   r9   r7   ro   s      r   test_zero_padded_filezTestGzip.test_zero_padded_file  s   ]]4=$// 	 1GGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  $-&& 	"!GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" ]]4=$// 	F1AQ
,DEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs5   AAA+BBB84C99C= C=c                 j    |                      t          t          j        t                               d S r   )r   
issubclassr   BadGzipFileOSErrorr   s    r   test_gzip_BadGzipFile_exceptionz(TestGzip.test_gzip_BadGzipFile_exception  s'    
4#3W==>>>>>r   c                 V   t          | j        d          5 }|                    t          dz             d d d            n# 1 swxY w Y   t                              | j        d          5 }|                     t          j        |j                   d d d            d S # 1 swxY w Y   d S )NrA   rB   r3   )	r   r(   r6   rD   r   r5   rk   r  r   )r   files     r   test_bad_gzip_filezTestGzip.test_bad_gzip_file  s!   $-&& 	#$JJurz"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#]]4=#.. 	@$d.???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s#   A  AA+&BB"%B"c                    t           dz  }t                      }t                              |d          5 }|                    |           d d d            n# 1 swxY w Y   |                                }t          |          }t                              |d          5 }|                     |                                |           d d d            d S # 1 swxY w Y   d S )NrB   rA   r~   rj   )rD   r   r   r5   r6   getvaluer7   r9   )r   uncompressedbufr=   r   s        r   test_non_seekable_filezTestGzip.test_non_seekable_file  s=   rznn]]3T]22 	"aGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"\\^^
:&&]]3T]22 	5aQVVXX|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s#   AAA!)CCCc           	         t           dz  }t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   d }t                              | j        d          5 }d|_        d} |            D ]g}|                    |          }|dk    r nI|                     |                    t          |                    |           |t          |          z  }h|                     |                    d          d           |                     |t          |                     d d d            d S # 1 swxY w Y   d S )	Nr   rA   c               3   :   K   	 t          ddd          D ]} | V  )NT   rB   r   )r\   )ns    r   sizesz!TestGzip.test_peek.<locals>.sizes  s6      q"b))  AGGGGr   rj   !   r   r   d   )
rD   r   r5   r(   r6   max_read_chunkpeekr7   r9   r8   )r   r  r=   r  rv   r  ss          r   	test_peekzTestGzip.test_peek  s   s{]]4=$// 	"1GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"	 	 	
 ]]4=$// 
	71!AEUWW    FF1II88E  A333QQVVC[[#...UC$5$5666
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7 
	7s$   AAA;CEEEc                    t           dz                      d                              d          }|                                  t                              | j        d          5 }t          j        |d          5 }| 	                    |
                                |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrB   asciiTr   r3   encoding)rD   decoder   rK   r   r5   r(   r   TextIOWrapperr7   r   )r   r   r=   ts       r   test_textio_readlineszTestGzip.test_textio_readlines  s7   ##G,,777FF]]4=#.. 	7!!!g666 7!  6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s6   &C
=)B2&C
2B6	6C
9B6	:C

CCc                 .   t          | j        d          5 }t                              |d          5 }|                    d           |                     |j        |j                   |                     |                                |                                           |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           | 
                    |j        d           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     |j        |j                   |                     t           |j                   |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |d          5 }|                    d	           |                     |j        |j                   |                     |                                |                                           |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           | 
                    |j        d           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     |j        |j                   |                     t           |j                   |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           d d d            n# 1 swxY w Y   t          | j        d
          5 }t                              |d          5 }|                    d           |                     |j        |j                   |                     |                                |                                           |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           | 
                    |j        d           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     |j        |j                   |                     t           |j                   |                     |j        t          j	                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |d          5 }|                     |                                d           |                     |j        |j                   |                     |                                |                                           |                     |j        t          j                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           | 
                    |j        d           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     |j        |j                   |                     t           |j                   |                     |j        t          j                   | 
                    |                                d           | 
                    |                                d           | 
                    |                                d           d d d            d S # 1 swxY w Y   d S )Nr   r   r~      oneFTrA   r2      twor   rM      threerj   r3      twothree)r   r(   r   r5   r6   r7   rQ   rF   r;   WRITEassertIsreadablewritabler   r   rk   AttributeErrorr9   READ)r   rawr=   s      r   test_fileobj_with_namezTestGzip.test_fileobj_with_name  s	   $-&& 	.#s55 /  222  SZZ\\:::  444ajjllE222ajjllD111ajjllD111ah.../ / / / / / / / / / / / / / / MM!(D)))QVSX...nah777QVTZ000MM!**,,...MM!**,,---MM!**,,---!	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.$ $-&& 	.#s55 /  222  SZZ\\:::  444ajjllE222ajjllD111ajjllD111ah.../ / / / / / / / / / / / / / / MM!(D)))QVSX...nah777QVTZ000MM!**,,...MM!**,,---MM!**,,---!	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.$ $-&& 	.#s55 /!!!  222  SZZ\\:::  444ajjllE222ajjllD111ajjllD111ah.../ / / / / / / / / / / / / / / MM!(D)))QVSX...nah777QVTZ000MM!**,,...MM!**,,---MM!**,,---!	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.$ $-&& 	.#s55 /  ;777  222  SZZ\\:::  333ajjllD111ajjllE222ajjllD111ah.../ / / / / / / / / / / / / / / MM!(D)))QVSX...nah777QVTY///MM!**,,---MM!**,,...MM!**,,---!	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   I6D(E'I6'E+	+I6.E+	/C;I66I:=I:S63D(O'S6'O+	+S6.O+	/C;S66S:=S:]63D(Y']6'Y+	+]6.Y+	/C;]66]:=]:h
3D;c:.h
:c>	>h
c>	C;h

hhc                 P
   t          j        | j        t           j        t           j        z  t           j        z            }t          j        |d          5 }t                              |d          5 }|	                    d           | 
                    |j        d           | 
                    |                                |                                           d d d            n# 1 swxY w Y   |                     |j        d           | 
                    |j        d           |                     t           |j                   d d d            n# 1 swxY w Y   t          j        | j        t           j        t           j        z  t           j        z            }t          j        |d          5 }t                              |d          5 }|	                    d	           | 
                    |j        d           | 
                    |                                |                                           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     t           |j                   d d d            n# 1 swxY w Y   t          j        | j        t           j        t           j        z  t           j        z            }t          j        |d
          5 }t                              |d          5 }|	                    d           | 
                    |j        d           | 
                    |                                |                                           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     t           |j                   d d d            n# 1 swxY w Y   t          j        | j        t           j                  }t          j        |d          5 }t                              |d          5 }| 
                    |                                d           | 
                    |j        d           | 
                    |                                |                                           d d d            n# 1 swxY w Y   | 
                    |j        d           |                     t           |j                   d d d            d S # 1 swxY w Y   d S )Nr   r   r~   r#  ri   TrA   r2   r$  r   rM   r%  rj   r3   r&  )rH   r   r(   O_WRONLYO_CREATO_EXCLfdopenr   r5   r6   r7   rQ   rF   r(  r   rk   r+  O_TRUNCO_APPENDO_RDONLYr9   )r   fdr-  r=   s       r   test_fileobj_from_fdopenz!TestGzip.test_fileobj_from_fdopen$  s    WT]BK"*$<ry$HIIYr4   	8Cs55 ;  ,,,  SZZ\\:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; MM!(D)))QVR(((nah777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 WT]BK"*$<rz$IJJYr4   	8Cs55 ;  ,,,  SZZ\\:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; QVR(((nah777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 WT]BK"*$<r{$JKKYr4   	8Cs55 ;!!!  ,,,  SZZ\\:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; QVR(((nah777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 WT]BK00Yr4   	8Cs55 ;  ;777  ,,,  SZZ\\:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; QVR(((nah777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   E1A+C(E(C,	,E/C,	0AEEE3JA+I;JI	JI	>JJ J7OA+N?ON	ON	>OO!$O!!T>A>S<TS	TS	>TT"Tc                    t                               | j        d                                           t	          | j        d          5 }t                               |d          5 }|                     |j        t           j                   d d d            n# 1 swxY w Y   t                               |d          5 }|                     |j        t           j                   d d d            n# 1 swxY w Y   t                               |d          5 }|                     |j        t           j                   d d d            n# 1 swxY w Y   t                               |d          5 }|                     |j        t           j                   d d d            n# 1 swxY w Y   | 	                    t                    5  t                               |d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d	D ]}t	          | j        |          5 }t                               |
          5 }|                     |j        t           j                   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   dD ]}d|v rt          j        | j                   t	          | j        |          5 }|                     t                    5  t                               |
          }d d d            n# 1 swxY w Y   |5  |                     |j        t           j                   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )NrA   r+br3   r~   r2   rM   r   z)rj   r:  r   )rA   r   r   )r   r5   r(   rI   r   r7   r;   r,  r'  rk   r   r   r'   assertWarnsFutureWarning)r   r=   gr;   s       r   test_fileobj_modezTestGzip.test_fileobj_modeL  s   dmT**00222$-'' 
	31qs33 4q  3334 4 4 4 4 4 4 4 4 4 4 4 4 4 4qs33 5q  4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5qs33 5q  4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5qs33 5q  4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5"":.. 3 3ac2223 3 3 3 3 3 3 3 3 3 3 3 3 3 3
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3 
	3   	8 	8DdmT** 8a]]1]-- 8$$QVTY7778 8 8 8 8 8 8 8 8 8 8 8 8 8 88 8 8 8 8 8 8 8 8 8 8 8 8 8 8 % 	9 	9Dd{{ ///dmT** 9a%%m44 1 1a00A1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 9$$QVTZ8889 9 9 9 9 9 9 9 9 9 9 9 9 9 99 9 9 9 9 9 9 9 9 9 9 9 9 9 9	9 	9sV  H%&BHB	HB	H>&C0$H0C4	4H7C4	8H&E	=H	E	HE	H0&F"H"F&	&H)F&	*HG0$H0G4	4H7G4	8HHH+J&I9-J9I==J I=JJ	J	M+-L	M+LM+LM+"&MM+MM+MM++M/	2M/	c                 
   | j         }t          j        |          }t                              |d          5 }|                    t          dz             d d d            n# 1 swxY w Y   |                     |j        |           t                              |d          5 }|                     |	                                t          dz             d d d            n# 1 swxY w Y   |                     |j        |           t                              |d          5 }|                     |	                                t          dz             d d d            n# 1 swxY w Y   |                     |j        |           d S )NrA   rB   rj   )
r(   rH   fsencoder   r5   r6   rD   r7   rQ   r9   )r   str_filenamebytes_filenamer=   s       r   test_bytes_filenamezTestGzip.test_bytes_filenamef  s   }\22]]>400 	 AGGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 000]]>400 	3AQVVXXurz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3000]]<.. 	3!QVVXXurz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3.....s5   A!!A%(A%"1CC#&C# 1EE!$E!c                 l	   t          j                    }t                              |d          5 }|                    t
          dz             |                     |j        d           |                     t           j	        |j
                   |                     |j        t          j                   |                     |                                d           |                     |                                d           |                     |                                d           |                     |j        d           d d d            n# 1 swxY w Y   |                     |j        d           |                     |j        d           |                     t$          |j
                   |                     |j        t          j                   |                     |                                d           |                     |                                d           |                     |                                d           |                    d           t                              |d          5 }|                     |                                t
          dz             |                     |j        d           |                     t           j	        |j
                   |                     |j        t          j                   |                     |                                d           |                     |                                d           |                     |                                d           |                     |j        d           d d d            n# 1 swxY w Y   |                     |j        d           |                     |j        d           |                     t$          |j
                   |                     |j        t          j                   |                     |                                d           |                     |                                d           |                     |                                d           d S )	NrA   r~   rB   ri   FTr   rj   )r   r   r   r5   r6   rD   r7   rQ   rk   r   rF   r;   r'  r(  r)  r*  r   r   r+  r   r9   r,  )r   bior=   s      r   test_fileobj_without_namez"TestGzip.test_fileobj_without_namet  s   jll]]3T]22 	+aGGEBJQVR(((b5qx@@@QVTZ000MM!**,,...MM!**,,---MM!**,,---MM!(E***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	ah%%%$$$.!(333,,,ajjllE***ajjllD)))ajjllD)))]]3T]22 	+aQVVXXurz222QVR(((b5qx@@@QVTY///MM!**,,---MM!**,,...MM!**,,---MM!(E***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	ah%%%$$$.!(333+++ajjllD)))ajjllE***ajjllD)))))s%   DEEED)N66N:=N:c                    | j         dz   }t          | j         d          5 }t                              ||d          5 }|                    t
          dz             |                     |j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          | j         d          5 }t                              ||d          5 }|                     |                                t
          dz             |                     |j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t                              | j         d          5 }|                     |                                t
          dz             |                     |j        | j                    d d d            d S # 1 swxY w Y   d S )NnewrA   )r   r(   r;   rB   rj   )	r(   r   r   r5   r6   rD   r7   rQ   r9   )r   	filename2r   r=   s       r   test_fileobj_and_filenamez"TestGzip.test_fileobj_and_filename  s   ME)	4=$'' 	07mmGidmKK	0OPGGEBJQVY///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 4=$'' 	07mmGidmKK	0OPQVVXXurz222QVY///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0
 ]]4=$// 	41QVVXXurz222QVT]333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s~   B9B7BB	B
B	BB!B:EAD0$E0D4	4E7D4	8EEE2AGGGc                    	 t                               dt          d          z  d          }|                     t	          |          t
          j                   t          j        |          }t                               |          }| 	                    |
                    d          d           dt
          j        z   }|                     |j        j                                        |d           d S )Nr   g    >Ar   r|   r<  rx   z)Excessive amount of data was decompressed)r   r   int
assertLessr8   r   DEFAULT_BUFFER_SIZEr   r5   r7   r9   assertLessEqual_bufferr-  r   )r   bombdecomp
max_decomps       r   test_decompress_limitedz TestGzip.test_decompress_limited  s    ;}}USXX-Q}??D		2#9:::z$t,,Q/////
V^/4466
7	9 	9 	9 	9 	9r   c                    t           t          fD ]}dD ]}t          j        |g|R  }|                     t          |          t                     t                              t          j	        |          d          5 }|                     |
                                |           d d d            n# 1 swxY w Y   d S )Nr   )rx   )r   )r   rj   r~   )rD   r   r   r   r7   typer4   r5   r   r   r9   )r   r:   r   datacr=   s        r   test_compresszTestGzip.test_compress  s    EN 	5 	5D. 5 5d2T222  ee444]]2:e+<+<4]HH 5A$$QVVXXt4445 5 5 5 5 5 5 5 5 5 5 5 5 5 55	5 	5s   =)B22B69B6c           	         d}t           t          fD ]}dD ]}|                     ||          5  t          j        |g|R d|i}|                     t          |          t                     t                              t          j
        |          d          5 }|                    d           |                     |j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nr   rX  )r:   r   r   rj   r~   rx   )rD   r   r   r   r   r7   rY  r4   r5   r   r   r9   r   )r   r   r:   r   rZ  r=   s         r   test_compress_mtimezTestGzip.test_compress_mtime  sy   EN 	9 	9D. 9 9\\t$\77 9 9 M$CCCCUCCE$$T%[[%888rz%/@/@tLL 9PQq			((%8889 9 9 9 9 9 9 9 9 9 9 9 9 9 99 9 9 9 9 9 9 9 9 9 9 9 9 9 99	9 	9s6   A,C.1C	C.CC.CC..C25C2c                 `   dD ]}|                      |          5  t                              t          d|          }t                              t          d|          }|                     t          |           |                     t          |           d d d            n# 1 swxY w Y   d S )N)r   *   r   r   )r}   r   rx   )r   r   r   rD   assertInassertNotIn)r   r   
nocompressyescompresss       r   test_compress_correct_levelz$TestGzip.test_compress_correct_level  s     	5 	5EE** 5 5!]]5]OO
"mmE%mPPeZ000  444	5 5 5 5 5 5 5 5 5 5 5 5 5 5 5	5 	5s   A;B""B&	)B&	c                    t           t          fD ]}t          j                    }t                              |d          5 }|                    |           d d d            n# 1 swxY w Y   |                     t                              |	                                          |           t          
                    |          }|                     t                              |          |           d S )NrA   r~   )rD   r   r   r   r   r5   r6   r7   
decompressr  r   )r   r:   r  r=   rZ  s        r   test_decompresszTestGzip.test_decompress  s   EN 	; 	;D*,,Cs66 !              T__S\\^^<<dCCCMM$''ET__U33T::::	; 	;s    A""A&	)A&	c                     t                               t                    }|                     t          t           j        |d d                    d S )Nr   r   rD   rk   EOFErrorrf  r   compressed_datas     r   !test_decompress_truncated_trailerz*TestGzip.test_decompress_truncated_trailer  <    --..(DO_SbS5IJJJJJr   c                     t                               t                    }|                     t          t           j        |d d                    d S )Nrj  rl  s     r   test_decompress_missing_trailerz(TestGzip.test_decompress_missing_trailer  ro  r   c                 b   t           dz  }t                              |          d d         }t                              t	          j        |                    5 }|                     t          |j                   d d d            n# 1 swxY w Y   t                              t	          j        |                    5 }| 	                    |                    t          |                    |           |                     t          |j        d           d d d            n# 1 swxY w Y   t          dd          D ]p}t                              t	          j        |d |                             5 }|                     t          |j        d           d d d            n# 1 swxY w Y   qd S )NrB   rq  r<  rx   r   r   )rD   r   r   r5   r   r   rk   rk  r9   r7   r8   r\   )r   r:   	truncatedr=   r   s        r   test_read_truncatedzTestGzip.test_read_truncated  s   RxMM$'',	]]2:i#8#8]99 	0Qh///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0]]2:i#8#8]99 	3QQVVCII..555h222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 q" 	7 	7Arz)BQB-'@'@AA 7Q!!(AFA6667 7 7 7 7 7 7 7 7 7 7 7 7 7 7	7 	7s7   !BBB?AD##D'*D'5"F##F'	*F'	c                     d}t                               t          j        |                    5 }|                     |                                d           d d d            d S # 1 swxY w Y   d S )Ns   cQ ExtraI-. 2Mx   r<  s   Test)r   r5   r   r   r7   r9   )r   gzdatar=   s      r   test_read_with_extrazTestGzip.test_read_with_extra  s    < ]]2:f#5#5]66 	0!QVVXXw///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   )A&&A*-A*c                 b   t                               | j        d          5 }|                    t                     d d d            n# 1 swxY w Y   t                               | j        d          5 }|j        j        j                                         d d d            d S # 1 swxY w Y   d S )NrA   rj   )	r   r   r(   r6   rD   rR  r-  _fpprependrJ   s     r   test_prepend_errorzTestGzip.test_prepend_error  s	   YYt}d++ 	qGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	YYt}d++ 	(qIM%%'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s#   AAA3$B$$B(+B(c                    t          j         dg d          }t          |          |j        z  }t                              t          j                    d          5 }|                     |                    |          |           |                     |	                                |           d d d            d S # 1 swxY w Y   d S )NQ)rx   r      rY   r  r2   r~   )
rf   r8   itemsizer   r5   r   r   r7   r6   r   )r   qLENGTHr=   s       r   test_issue44439zTestGzip.test_issue44439  s    K___--Q!*$]]2:<<c]:: 	/aQWWQZZ000QVVXXv...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/s   AB;;B?B?N)r0   )8r    r!   r"   r?   rK   rT   r_   rb   rg   rm   rp   rw   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.  r8  r@  rE  rH  rL  rV  r[  r]  rd  rg  rn  rr  ru  rx  r|  r  r   r   r   r/   r/   8   sK       / / / /  0 0 0"' ' '8 8 8? ? ?. . .& & &7 7 7 ZS###. . $#.  85 5 5- - -&/ / /	F 	F 	F
5 
5 
5
" 
" 
"  &* * *! ! !5 5 58 8 8< < <	1 	1 	11H 1H 1Hf  ? ? ?(7 7 7*
F 
F 
F? ? ?@ @ @5 5 57 7 7,7 7 7G. G. G.R&8 &8 &8P9 9 94/ / /#* #* #*J4 4 4
9 
9 
95 5 5	9 	9 	95 5 5; ; ;K K KK K K7 7 70 0 0( ( (/ / / / /r   r/   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )TestOpenc                     t           dz  }t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||           d d d            n# 1 swxY w Y   t                              | j        d          5 }|                     |                                |           d d d            n# 1 swxY w Y   t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||dz             d d d            n# 1 swxY w Y   |                     t                    5  t                              | j        d           d d d            n# 1 swxY w Y   t          j        | j                   t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||           d d d            d S # 1 swxY w Y   d S )NrB   rA   rj   r   r   r   rD   r   r   r(   r6   rf  r9   r7   rk   r   r   r'   r   r  r=   	file_datas       r   test_binary_modeszTestOpen.test_binary_modes  sd   rzYYt}d++ 	"qGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	6!11IY555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 YYt}d++ 	5qQVVXX|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 YYt}d++ 	"qGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	:!11IYq(8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: // 	+ 	+IIdmT***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+'''YYt}d++ 	"qGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	6!11IY555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6   AAA-AB<<C C ')DD #D E))E-0E-	AGG"G !H--H14H11JJJ3ALL
Lc                    t          j        | j                  }t                              |d          5 }|                    t          dz             d d d            n# 1 swxY w Y   |                     |j        | j                   t                              |d          5 }|                    t                     d d d            n# 1 swxY w Y   |                     |j        | j                   t                              |          5 }|                     |	                                t          dz             d d d            n# 1 swxY w Y   |                     |j        | j                   d S )NrA   rB   r   rN   )
r   rO   r(   r   r   r6   rD   r7   rQ   r9   )r   r(   r=   s      r   test_pathlike_filezTestOpen.test_pathlike_file&  s   %dm44YYx&& 	 !GGEBJ	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 ///YYx&& 	!GGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	///YYx   	3AQVVXXurz222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3/////s5   AA#&A#%CCC1EEEc                     t           dz  }t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||           d d d            n# 1 swxY w Y   t                              | j        d          5 }|                     |                                |           d d d            n# 1 swxY w Y   t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||dz             d d d            n# 1 swxY w Y   |                     t                    5  t                              | j        d           d d d            n# 1 swxY w Y   t          j        | j                   t                              | j        d          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t                              |                                          }|                     ||           d d d            d S # 1 swxY w Y   d S )NrB   r2   rj   r3   rM   r   r   r  r  s       r   test_implicit_binary_modesz#TestOpen.test_implicit_binary_modes2  sd   rzYYt}c** 	"aGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	6!11IY555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 YYt}c** 	5aQVVXX|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 YYt}c** 	"aGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	:!11IYq(8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: // 	* 	*IIdmS)))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*'''YYt}c** 	"aGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	6!11IY555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6r  c                    t                               d          dz  }|                    dt          j                  }t
                              | j        dd          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t
          	                    |
                                                              d          }|                     ||           d d d            n# 1 swxY w Y   t
                              | j        dd          5 }|                     |
                                |           d d d            n# 1 swxY w Y   t
                              | j        dd          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t
          	                    |
                                                              d          }|                     ||d	z             d d d            d S # 1 swxY w Y   d S )
Nr  rB   
wtr  rj   rtatr   rD   r  replacerH   linesepr   r   r(   r6   rf  r9   r7   r   r  uncompressed_rawr=   r  s        r   test_text_modeszTestOpen.test_text_modesN  s   ||G,,r1'//bjAAYYt}dWY== 	"GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	:!1188AAIY(8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: YYt}dWY== 	5QVVXX|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5YYt}dWY== 	"GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	>!1188AAIY(81(<===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s\    BB	B"ADDD1)E&&E*-E*F55F9<F9AH;;H?H?c                    t           dz  }|                    d          }t                              |          }t                              t          j        |          d          5 }|                     |                                |           d d d            n# 1 swxY w Y   t                              t          j        |          d          5 }|                     |                                |           d d d            n# 1 swxY w Y   t                              t          j        |          dd          5 }|                     |                                |           d d d            d S # 1 swxY w Y   d S )NrB   r  r3   rj   r  r  )	rD   r  r   r   r   r   r   r7   r9   )r   uncompressed_bytesuncompressed_strr   r=   s        r   test_fileobjzTestOpen.test_fileobj^  s   "RZ-44W==]]#566
YYrz*--s33 	;qQVVXX'9:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;YYrz*--t44 	;QVVXX'9:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;YYrz*--tgYFF 	9!QVVXX'7888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s6   ')BB #B )D		DD)E99E= E=c                    |                      t                    5  t                              d           d d d            n# 1 swxY w Y   |                      t                    5  t                              | j        d           d d d            n# 1 swxY w Y   |                      t                    5  t                              | j        d           d d d            n# 1 swxY w Y   |                      t                    5  t                              | j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t                              | j        dd           d d d            n# 1 swxY w Y   |                      t                    5  t                              | j        dd	
           d d d            d S # 1 swxY w Y   d S )Ngw/^@wbtxbtrj   zutf-8r  ignore)errorsr  )newline)rk   rl   r   r   r   r(   r   s    r   test_bad_paramszTestOpen.test_bad_paramsi  s   y)) 	 	IIg	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z** 	, 	,IIdmU+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,z** 	, 	,IIdmU+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,z** 	= 	=IIdmTGI<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=z** 	< 	<IIdmT(I;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<z** 	9 	9IIdmT4I888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9sk   AA	A'!BBB9!C&&C*-C*#D::D>D>#FFF3#G##G'*G'c                    t                               d          dz  }|                    dt          j                  }t
                              | j        dd          5 }|                    |           d d d            n# 1 swxY w Y   t          | j        d          5 }t
          	                    |
                                                              d          }|                     ||           d d d            n# 1 swxY w Y   t
                              | j        dd          5 }|                     |
                                |           d d d            d S # 1 swxY w Y   d S )	Nr  rB   r  r  zutf-16r  rj   r  r  r  s        r   test_encodingzTestOpen.test_encodingx  s   ||G,,r1'//bjAAYYt}dXY>> 	"!GGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"$-&& 	:!1188BBIY(8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: YYt}dXY>> 	5!QVVXX|444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s7    BB	B"ADDD1)E''E+.E+c                 h   t                               | j        d          5 }|                    d           d d d            n# 1 swxY w Y   t                               | j        ddd          5 }|                     |                                d           d d d            d S # 1 swxY w Y   d S )NrA   s   foobarr  r  r  )r  r  foobar)r   r   r(   r6   r7   r9   rJ   s     r   test_encoding_error_handlerz$TestOpen.test_encoding_error_handler  s   YYt}d++ 	#qGGM"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#YYt}dWXYNN 	1QVVXXx000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s#   AA
A1)B''B+.B+c                    t                               d          dz  }t                              | j        ddd          5 }|                    |           d d d            n# 1 swxY w Y   t                              | j        ddd          5 }|                     |                                |g           d d d            d S # 1 swxY w Y   d S )Nr  rB   r  r  )r  r  r  )rD   r  r   r   r(   r6   r7   r   )r   r  r=   s      r   test_newlinezTestOpen.test_newline  s5   ||G,,r1YYt}dWdYKK 	"qGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"YYt}dWdYKK 	<qQ[[]]\N;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s$   A##A'*A'*CCCN)r    r!   r"   r  r  r  r  r  r  r  r  r  r   r   r   r  r  
  s        6 6 66
0 
0 
06 6 68> > > 	9 	9 	99 9 9
5 
5 
51 1 1< < < < <r   r  c                       fd}|S )Nc                 J     t          j                    fd            }|S )Nc                      t          j                   	  | i |t          j                   S # t          j                   w xY wr   )rH   makedirsr   rmtree)r   kwargs	directoryfunctions     r   wrapperz?create_and_remove_directory.<locals>.decorator.<locals>.wrapper  sU    K	""",x000 ++++	 ++++s	   3 A	)	functoolswraps)r  r  r  s   ` r   	decoratorz.create_and_remove_directory.<locals>.decorator  s>    		"	"	, 	, 	, 	, 	, 
#	"	, r   r   )r  r  s   ` r   create_and_remove_directoryr    s$         r   c                   
   e Zd ZdZ e            d             Z ee          d             Zd Z	 e             ee          d                         Z
 ee          d             Z ee          d             Zd Zd	 Zd
S )TestCommandLines   This is a simple test with gzipc                 B   t          j                    5 }t                              |d          5 }|                    | j                   d d d            n# 1 swxY w Y   t          j        dddf}t          |t          t          t                    5 }|
                    |                                          \  }}d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |d           |                     || j                   d S )NrA   r~   -mr   -dstdinstdoutstderrr   )r   r   r   r5   r6   r:   sys
executabler   r   communicater  r7   )r   bytes_io	gzip_filer   procouterrs          r   test_decompress_stdin_stdoutz,TestCommandLine.test_decompress_stdin_stdout  s   Z\\ 	AXxd;; +y	***+ + + + + + + + + + + + + + + >45Dt4TBBB Ad++H,=,=,?,?@@SA A A A A A A A A A A A A A A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	c"""di(((((sX   C#AC#A	C#A	 5C#+C C#C	C#C	C##C'*C'c                 T   t           j                            t          d          }|                     t           j                            |                     t                              |d          5 }|                    | j	                   d d d            n# 1 swxY w Y   t          ddd|          \  }}}t          t           j                            t          d          d          5 }|                     |                                | j	                   d d d            n# 1 swxY w Y   |                     t           j                            |                     |                     |d	           |                     |d
           |                     |d
           d S )Nztestgzip.gzrA   )r;   r  r   r  testgziprj   r   r   )rH   pathrt   TEMPDIRr   existsr   r   r6   r:   r
   r7   r9   r   )r   gzipnamefprcr  r  gunzipeds          r   test_decompress_infile_outfilez.TestCommandLine.test_decompress_infile_outfile  s   7<<7711222YYxdY++ 	 rHHTY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 'fdHEEC"',,w
33T:: 	9hX]]__di888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	x00111Qc"""c"""""s$   4BB"B/.D))D-0D-c                     t          dddd          \  }}}|                     d|                                           |                     |d           |                     |d           d S )Nr  r   r  zthisisatest.outs.   filename doesn't end in .gz: 'thisisatest.out'rx   r   )r   r7   stripr   r  r  r  s       r   $test_decompress_infile_outfile_errorz4TestCommandLine.test_decompress_infile_outfile_error  sm    ,T64ARSSCJCIIKKXXXQc"""""r   c                 :   t           j        ddf}t          |t          t          t                    5 }|                    | j                  \  }}d d d            n# 1 swxY w Y   |                     |d           |                     |d d         d           d S )Nr  r   r  r   r   r   )r  r  r   r   r  r:   r7   )r   r   r  r  r  s        r   test_compress_stdin_outfilez+TestCommandLine.test_compress_stdin_outfile  s     ~tV+4tD>>> 	3$''	22HC	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	c"""RaR+.....s   AA #A c                 (   t           j                            t          d          }|dz   }|                     t           j                            |                     t          |d          5 }|                    | j                   d d d            n# 1 swxY w Y   t          dd|          \  }}}| 
                    t           j                            |                     |                     |d           |                     |d           d S )Nr  .gzrA   r  r   r   )rH   r  rt   r  r   r  r   r6   r:   r
   r   r7   )r   local_testgzipr  r  r  r  r  s          r   $test_compress_infile_outfile_defaultz4TestCommandLine.test_compress_infile_outfile_default  s$   gz::!E)11222.$'' 	 2HHTY	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  (fnEECx00111c"""c"""""s   -BBBc                     dD ]}|                      |          5  t          j                            t          d          }|dz   }|                     t          j                            |                     t          |d          5 }|                    | j	                   d d d            n# 1 swxY w Y   t          dd||          \  }}}|                     t          j                            |                     |                     |d           |                     |d           t          j        |           |                     t          j                            |                     d d d            n# 1 swxY w Y   d S )	N)--fast--best)compress_levelr  r  rA   r  r   r   )r   rH   r  rt   r  r   r  r   r6   r:   r
   r   r7   remove)r   r  r  r  r  r  r  r  s           r   test_compress_infile_outfilez,TestCommandLine.test_compress_infile_outfile  s   2 	; 	;N^<< ; ;!#gz!B!B)E1  !9!9:::.$// (2HHTY'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (  0fnn]]Cx 8 8999  c***  c***	(###  !9!9:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	;s7   A-F	B0$F0B44F7B48B=FF	F	c                     t          dddd          \  }}}|                     d|           |                     |d           d S )Nr  r   r  r  s8   error: argument --best: not allowed with argument --fastr   r   r`  r7   r  s       r   %test_compress_fast_best_are_exclusivez5TestCommandLine.test_compress_fast_best_are_exclusive  sM    ,T68XNNCQSVWWWc"""""r   c                     t          dddd          \  }}}|                     d|           |                     |d           d S )Nr  r   r  r  sA   error: argument -d/--decompress: not allowed with argument --fastr   r  r  s       r   -test_decompress_cannot_have_flags_compressionz=TestCommandLine.test_decompress_cannot_have_flags_compression  sM    ,T68TJJCZ\_```c"""""r   N)r    r!   r"   r:   r	   r  r  r  r  r  r  r  r  r  r  r   r   r   r  r    s       -D
) 
) 
) ! ))# # *)# # # #   ))/ / *) / ! ))# # *)# ! )); ; *);$# # #
# # # # #r   r  __main__)%rf   r  r   rH   r   r  unittest
subprocessr   r   test.supportr   r   r   r   r	   test.support.script_helperr
   r   import_moduler   rD   r   r  abspathr-   r  r   r   TestCaser$   r/   r  r  r  r    mainr   r   r   <module>r     s'        				 				  



  " " " " " " " " & & & & & & " " " " " " = = = = = = = = = = N N N N N N N N"}"6**		 '//)*
+
+h
6& & & & &2: & & &( ( ( ( (x  ( ( (O/ O/ O/ O/ O/x O/ O/ O/dH< H< H< H< H<x H< H< H<V
 
 
[# [# [# [# [#h' [# [# [#| zHMOOOOO r   