
    daf                     
   d 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	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 ej(                  d	      Zd
ZdZej2                  j5                  ej6                        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jL                          yy)z!Test script for the gzip module.
    N)PIPEPopen)import_helper)	os_helper)_4G
bigmemtestrequires_subprocess)assert_python_okassert_python_failuregzipzlibsy     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y)UnseekableIOc                      y)NF selfs    )/root/Python-3.12.4/Lib/test/test_gzip.pyseekablezUnseekableIO.seekable%   s        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   $   s    &&r   r   c                   0    e Zd Zej                  Zd Zd Zy)BaseTestc                 B    t        j                  | j                         y r   r   unlinkfilenamer   s    r   setUpzBaseTest.setUp2       'r   c                 B    t        j                  | j                         y r   r'   r   s    r   tearDownzBaseTest.tearDown5   r+   r   N)r!   r"   r#   r   TESTFNr)   r*   r-   r   r   r   r%   r%   /   s    H((r   r%   c                   l   e Zd Zd:d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. Z0d/ Z1d0 Z2d1 Z3d2 Z4d3 Z5d4 Z6d5 Z7d6 Z8d7 Z9d8 Z:y9);TestGzipc                    t        |      }t        j                  | j                  d|z         5 }|j	                  |      }d d d        | j                  t        |             t        j                  | j                  d|z         5 }| j                  |j                         |       d d d        y # 1 sw Y   qxY w# 1 sw Y   y xY w)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_back:   s    t]]4==#d(3 	qA	CK(]]4==#d(3 	/qQVVXv.	/ 	/	 		/ 	/s   B1!B=1B:=Cc                    t         j                  | j                  d      5 }|j                  t        dz         |j                          |j                          t        t        d      r#t        j                  |j                                |j                          d d d        j                          y # 1 sw Y   xY w)Nwb2   fsync)r   r5   r)   r6   data1flushfilenohasattrosrC   closer   r=   s     r   
test_writezTestGzip.test_writeB   s    ]]4==$/ 	1GGEBJ GGIHHJr7#$GGI	 	
		 	s   A<B66B?c                    t        j                  | j                        }t        j	                  |d      5 }|j                  t        dz         d d d        | j                  j                  t               | j                  |j                  | j                         t        j	                  |d      5 }|j                  t               d d d        t        j	                  |      5 }|j                         }d d d        | j                  t        dz         | j                  |j                  t               | 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)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_fileP   s   %%dmm4]]8S) 	 QGGEBJ	 affc*/]]8S) 	QGGEN	]]8$ 	A	EBJ'affc*/	  	 	 		 	s#   E3E,&E8E),E58Fc                     | j                  t        t        dz               t        t        t	        d                  }|j                  dg d      }| j                  |       y )NrB      B)   rX      )shape)r?   
memoryviewrD   r4   rangecast)r   mr:   s      r   test_write_memoryviewzTestGzip.test_write_memoryviewa   sL      EBJ!78uU3Z()vvcv)  &r   c                 F    | j                  t        t        dz               y )NrB   )r?   	bytearrayrD   r   s    r   test_write_bytearrayzTestGzip.test_write_bytearrayg   s      52:!67r   c                 \    | j                  t        j                  dt        dz               y )NI(   )r?   arrayrD   r   s    r   test_write_arrayzTestGzip.test_write_arrayj   s      S%"*!=>r   c                 6   t         j                  | j                  d      5 }| j                  t              5  |j                  d       d d d        | j                  t              5  |j                  g        d d d        |j                  t               d d d        t         j                  | j                  d      5 }| j                  |j                         t               d d d        y # 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   y xY w)NrA    rb)	r   r5   r)   assertRaises	TypeErrorr6   rD   r7   r9   rJ   s     r   test_write_incompatible_typez%TestGzip.test_write_incompatible_typem   s     ]]4==$/ 	1""9- ""9- GGEN	 ]]4==$/ 	.1QVVXu-	. 	.  	 		. 	.sF   DC+	D&C78D=%D+C4	0D7D 	<DDDc                     | j                          t        j                  | j                  d      5 }|j	                         }d d d        | j                  t        dz         y # 1 sw Y   #xY w)Nr3   rB   )rK   r   r5   r)   r9   r7   rD   r   r=   rS   s      r   	test_readzTestGzip.test_readz   sT    ]]4==#. 	!A	E"H%	 	s   A$$A-c                    | j                          g }d}t        j                  | j                  d      5 }	 |j	                         }|sn@|j                  |       |t        |      z  }| j                  |j                         |       S	 d d d        | j                  dj                  |      t        dz         y # 1 sw Y   2xY w)Nr   r3   r   rB   )rK   r   r5   r)   read1appendr8   r7   r   joinrD   )r   blocksnreadr=   rS   s        r   
test_read1zTestGzip.test_read1   s    ]]4==#. 	2!GGIa Q  51  		2 	&)52:6	2 	2s   AB<<C   )sizememusec                     t         j                  t        d      }t         j                  t	        j
                  |      d      }| j                  |j                  |      t               y )Nrx   compresslevelrj   fileobjr;   )r   compressrD   r5   r   BytesIOr7   r9   )r   ry   
compressedr=   s       r   test_read_largezTestGzip.test_read_large   sI     ]]5]:
MM"**Z"8tMDu-r   c                 :   | j                          t        j                  | j                  d      }|j                  }| j                  |j                         |j                          | j                  |j                         | j                  t              5  |j                  d       d d d        | j                  t              5  |j                  d       d d d        | j                  t              5  |j                          d d d        t        j                  | j                  d      }|j                  }| j                  |j                         |j                          | j                  |j                         | j                  t              5  |j                  d       d d d        | j                  t              5  |j                          d d d        y # 1 sw Y   7x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)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* 	FF1I	z* 	FF1I	z* 	FFH	 MM$---))(		'z* 	GGCL	z* 	GGI	 		 		 		 		 		 	s<   GG,6G9HHG),G69HHHc                    | j                          t        j                  | j                  d      5 }|j	                  t
        dz         d d d        t        j                  | j                  d      5 }|j                         }d d d        | j                  t        dz  t
        dz  z          y # 1 sw Y   fxY w# 1 sw Y   9xY w)Nab   rj   rB   )	rK   r   r5   r)   r6   data2r9   r7   rD   ro   s      r   test_appendzTestGzip.test_append   s    ]]4==$/ 	 1GGEBJ	  ]]4==$/ 	1A	U2X%(34	  	 	 	s   B/2B;/B8;Cc                    t         j                  | j                  dd      5 }|j                  d       d d d        t	        dd      D ]=  }t         j                  | j                  dd      5 }|j                  d       d d d        ? t         j                  | j                  d      5 }d}	 |j                  d	      }||z  }|sn	 d d d        | j                  d
       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   4xY w)NrA   	      ar      r   rj   r   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 	aGGDM	q# 	At}}dA6 ! 	
 ]]4==$/ 	#6H{{4(D U  #	# 	8,	 	 	# 	#s#   C",C.(C:"C+.C7	:Dc                    t         j                  | j                  d      5 }|j                  t        dz         d d d        t         j                  | j                  d      5 }| j                  |j                         t        dz         d d d        | j                  t              5  t         j                  | j                  d       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)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QVVXurz2	3/ 	/MM$--.	/ 	/		  	 	3 	3	/ 	/s#   C"(C'!C)CC&)C2c                 \   | j                          t        j                  | j                  d      5 }t	        j
                  |      5 }|D cg c]  }| }}d d d        d d d        | j                  dt        j                  d      z         y c c}w # 1 sw Y   @xY w# 1 sw Y   DxY w)Nrj   rB   Tkeepends)	rK   r   r5   r)   r   BufferedReaderr7   rD   
splitlines)r   r=   r3   lineliness        r   test_buffered_readerzTestGzip.test_buffered_reader   s     	]]4==$/ 	-1""1% -*+,$,,-	- 	U%5%5t%5%D DE -- -	- 	-s5   B"B	BBB"BB	B""B+c                    | j                          t        j                  | j                  d      5 }d}	 |j	                  |      }|s|dk7  rn&| j                  t        |      |k         |dz   dz  }?	 d d d        y # 1 sw Y   y xY w)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JJ{+[A-uA+ 56*Q"4	 /4		5 	5 	5s   AA>>Bc                 L   | j                          t        j                  | j                  d      5 }|j	                         }d d d        t        j                  | j                  d      5 }	 |j	                  d      }|g k(  rn	 d d d        y # 1 sw Y   MxY w# 1 sw Y   y xY w)Nrj      )rK   r   r5   r)   	readlines)r   r=   r   s      r   test_readlineszTestGzip.test_readlines   s     ]]4==$/ 	1A	 ]]4==$/ 	"1KK$7E !	" 	"	 		" 	"s   B*BBB#c                    | j                          t        j                  | j                        5 }	 |j	                         }|j                         }|snu|j	                         }|j                  |       t        |      dkD  rd}nt        |      }|j                  |      }| j                  |d | |       |j                  |       	 d d d        y # 1 sw Y   y xY w)N
   )
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   s     ]]4==) 	Q

evu:b=F ZFv  w7v  $		 	 	s   BCCc                 (   | j                          t        j                  | j                        5 }|j	                  d       |j                  dd       |j	                  d      }d d d        | j                  t        dd        y # 1 sw Y   #xY w)Nr   rx   )whence      )rK   r   r5   r)   r9   r    r7   rD   )r   r=   ys      r   test_seek_whencezTestGzip.test_seek_whence  su     ]]4==) 	QFF2JFF2aF r
A	 	E"RL)		 	s   6BBc                     t         j                  | j                  d      5 }t        ddd      D ]$  }|j	                  |       |j                  d       & 	 d d d        y # 1 sw Y   y xY w)Nr2   r   rV      s   GZ
)r   r5   r)   r\   r    r6   )r   r=   poss      r   test_seek_writezTestGzip.test_seek_write  sZ    ]]4==#. 	!!QR( !s !	! 	! 	!s   5A  A)c                    | j                          t        j                  | j                  d      5 }| j	                  |j
                  j                  d       d d d        t        j                  | j                         t        j                  | j                  d      5 }| j	                  |j
                  j                  d       d d d        y # 1 sw Y   xxY w# 1 sw Y   y xY w)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	5']]4==#. 	5!Q[[--t4	5 	5	5 	5	5 	5s   'C'CCC$c                     dD ]l  }t         j                  | j                  |      5 }| j                  t	        |d             | j                  |j                  | j                         d d d        n y # 1 sw Y   yxY w)N)rA   rj   rQ   )r   r5   r)   r   rG   r7   rQ   )r   r;   r=   s      r   test_1647484zTestGzip.test_1647484(  sj      	8Dt}}d3 8q6 23  78 8	88 8s   AA33A<	c                 8   | j                          t        j                  | j                  d      5 }| j	                  t        |j                  d             | j                  |j                  j                  | j                         d d d        y # 1 sw Y   y xY w)Nrj   rQ   )	rK   r   r5   r)   r   rG   r   r7   rQ   rJ   s     r   test_paddedfile_getattrz TestGzip.test_paddedfile_getattr.  sh    ]]4==$/ 	<1OOGAIIv67QYY^^T]];	< 	< 	<s   ABBc                    d}t         j                  | j                  d|      5 }|j                  t               d d d        t         j                  | j                        5 }| j                  t        |d             | j                  |j                         |j                         }| j                  |t               | j                  |j                  |       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N[r2   mtimer   )r   r5   r)   r6   rD   r   rG   assertIsNoner   r9   r7   )r   r   fWritefReaddataReads        r   
test_mtimezTestGzip.test_mtime4  s    ]]4==#u]= 	 LL	 ]]4==) 	1UOOGE734ekk*zz|HXu-U[[%0	1 	1	  	 	1 	1s   C$"A9C0$C-0C9c           
         d}t         j                  | j                  d|      5 }|j                  t               d d d        t        | j                  d      5 }|j                  d      }| j                  |d       |j                  d      }| j                  |d       	 | j                  j                  d	      d
z   }d}|j                  d      }| j                  ||       |j                  d      }	| j                  |	t        j                  d|             |j                  d      }
| j                  |
d       |j                  d      }| j                  |d       |j                  t        |            }| j                  ||       |j                  t        j                  | j                        j                   dz
         |j                  d      }| j                  |d       |j                  d      }| j                  |t        j                  dt        t                           d d d        y # 1 sw Y   xY w# t        $ r d}d
}Y w xY w# 1 sw Y   y xY w)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mGWk2ZZ]FVW-(#}}33I>H '
 

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

3|#45IY5 JJrwwt}}-559:AJZ)9:AJZT3u:)FGW+	H +	H	  	  & (" '(+	H +	Hs=   H8AI! IE.I8IIIIII"c                 N    t         j                  | _        | j                          y r   )r   TESTFN_ASCIIr)   r   r   s    r   test_metadata_ascii_namez!TestGzip.test_metadata_ascii_namer  s    !..r   c                    g d}d}|D ]  \  }}}| j                  |      5  t        j                  | j                  d|      }|5  |j	                  t
               d d d        t        | j                  d      5 }|j                  |       |j                  d      }| j                  ||       d d d        d d d         y # 1 sw Y   gxY w# 1 sw Y    xY w# 1 sw Y   xY w)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_metadatav  s    

 	.3 	?*T5/d# ?t}}cO (LL'($--. ?%JJy)#jjmG$$Wo>?	? ?	?( (? ?	? ?s;   %CCC:5C/CCCCCC#	c                    t         j                  | j                  d      5 }|j                  d       d d d        t         j                  | j                  d      }|j	                          	 |5  	 d d d        | j                  d       	 t         j                  | j                  d      5 }ddz   d d d        | j                  d       y # 1 sw Y   xY w# 1 sw Y   gxY w# t        $ r Y dw xY w# 1 sw Y   BxY w# t        $ r Y y 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GGFO	MM$--.			N 
 IILM	7t}}d3 q!
 II56#	 	
  		
   		s_   C
,C" .C0C" 
 C= *C10C= 
CCC" "	C.-C.1C:6C= =	D	D	c                    t         j                  | j                  d      5 }|j                  t        dz         d d d        t        | j                  d      5 }|j                  d       d d d        t         j                  | j                  d      5 }|j                         }| j                  |t        dz  d       d d d        y # 1 sw Y   xY w# 1 sw Y   ixY w# 1 sw Y   y xY w)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	F 	F	  	 	" 	"	F 	Fs#   CC+CCCC'c                 ^    | j                  t        t        j                  t                     y r   )r   
issubclassr   BadGzipFileOSErrorr   s    r   test_gzip_BadGzipFile_exceptionz(TestGzip.test_gzip_BadGzipFile_exception  s    
4#3#3W=>r   c                 H   t        | j                  d      5 }|j                  t        dz         d d d        t        j                  | j                  d      5 }| j                  t        j                  |j                         d d d        y # 1 sw Y   ]xY w# 1 sw Y   y xY w)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   B+BBB!c                 r   t         dz  }t               }t        j                  |d      5 }|j	                  |       d d d        |j                         }t        |      }t        j                  |d      5 }| j                  |j                         |       d d d        y # 1 sw Y   exY w# 1 sw Y   y xY w)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n]]3T]2 	"aGGL!	"\\^
:&]]3T]2 	5aQVVX|4	5 	5		" 	"	5 	5s   B!7!B-!B*-B6c           	      T   t         dz  }t        j                  | j                  d      5 }|j	                  |       d d d        d }t        j                  | j                  d      5 }d|_        d} |       D ]R  }|j                  |      }|dk(  r n:| j                  |j                  t        |            |       |t        |      z  }T | j                  |j                  d      d       | j                  |t        |             d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	Nr   rA   c               3   :   K   	 t        ddd      D ]  } |   w)N   rB   r   )r\   )ns    r   sizesz!TestGzip.test_peek.<locals>.sizes  s+     q"b) AG s   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W  FF1I8  A3Q  QVVC[#.UC$56
	7 
	7	" 	"
	7 
	7s   D'B"DDD'c                 v   t         dz  j                  d      j                  d      }| j                          t        j                  | j                  d      5 }t        j                  |d      5 }| j                  |j                         |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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  s    ##G,777F]]4==#. 	7!!!!g6 7!  67	7 	77 7	7 	7s$   B/1!B#B/#B,	(B//B8c                    t        | j                  d      5 }t        j                  |d      5 }|j	                  d       | j                  |j                  |j                         | j                  |j                         |j                                | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  |j                  |j                         | j                  t         |j                         | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       d d d        t        | j                  d      5 }t        j                  |d      5 }|j	                  d	       | j                  |j                  |j                         | j                  |j                         |j                                | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  |j                  |j                         | j                  t         |j                         | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       d d d        t        | j                  d
      5 }t        j                  |d      5 }|j	                  d       | j                  |j                  |j                         | j                  |j                         |j                                | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  |j                  |j                         | j                  t         |j                         | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       d d d        t        | j                  d      5 }t        j                  |d      5 }| j                  |j#                         d       | j                  |j                  |j                         | j                  |j                         |j                                | j                  |j                  t        j$                         | j                  |j                         d       | j                  |j                         d       | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  |j                  |j                         | j                  t         |j                         | j                  |j                  t        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   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xxY w# 1 sw Y   xY w# 1 sw Y   MxY w# 1 sw Y   y xY w)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 /  2  SZZ\:  4ajjlE2ajjlD1ajjlD1ahh./ MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-!	.$ $--& 	.#s5 /  2  SZZ\:  4ajjlE2ajjlD1ajjlD1ahh./ MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-!	.$ $--& 	.#s5 /!  2  SZZ\:  4ajjlE2ajjlD1ajjlD1ahh./ MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-!	.$ $--& 	.#s5 /  ;7  2  SZZ\:  3ajjlD1ajjlE2ajjlD1ahh./ MM!((D)QVVSXX.nahh7QVVTYY/MM!**,-MM!**,.MM!**,-!	. 	.k/ /	. 	.&/ /	. 	.&/ /	. 	.&/ /	. 	.s   c6Dc);C4c6d%Dd1C4dd*Dd'C4d*9eDd7,C4e)c3	.c66d d	ddd'	"d**d47e	<eec                 
   t        j                  | j                  t         j                  t         j                  z  t         j
                  z        }t        j                  |d      5 }t        j                  |d      5 }|j                  d       | j                  |j                  d       | j                  |j                         |j                                d d d        | j                  j                  d       | j                  |j                  d       | j                  t         |j                         d d d        t        j                  | j                  t         j                  t         j                  z  t         j"                  z        }t        j                  |d      5 }t        j                  |d      5 }|j                  d	       | j                  |j                  d       | j                  |j                         |j                                d d d        | j                  j                  d       | j                  t         |j                         d d d        t        j                  | j                  t         j                  t         j                  z  t         j$                  z        }t        j                  |d
      5 }t        j                  |d      5 }|j                  d       | j                  |j                  d       | j                  |j                         |j                                d d d        | j                  j                  d       | j                  t         |j                         d d d        t        j                  | j                  t         j&                        }t        j                  |d      5 }t        j                  |d      5 }| j                  |j)                         d       | j                  |j                  d       | j                  |j                         |j                                d d d        | j                  j                  d       | j                  t         |j                         d d d        y # 1 sw Y   xY w# 1 sw Y   wxY w# 1 sw Y   xY w# 1 sw Y   kx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)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    WWT]]BKK"**$<ryy$HIYYr4  	8Cs5 ;  ,  SZZ\:; MM!((D)QVVR(nahh7	8 WWT]]BKK"**$<rzz$IJYYr4  	8Cs5 ;  ,  SZZ\:; QVVR(nahh7	8 WWT]]BKK"**$<r{{$JKYYr4  	8Cs5 ;!  ,  SZZ\:; QVVR(nahh7	8 WWT]]BKK0YYr4  	8Cs5 ;  ;7  ,  SZZ\:; QVVR(nahh7	8 	87; ;	8 	8; ;	8 	8; ;	8 	8; ;	8 	8s   'R0?AR#A R0)S
AR=AS
S$'ASAS$S=+A+S1AS=#R-	(R00R:=S	S

SS!	S$$S.1S:	6S==Tc                    t         j                  | j                  d      j                          t	        | j                  d      5 }t         j                  |d      5 }| j                  |j                  t         j                         d d d        t         j                  |d      5 }| j                  |j                  t         j                         d d d        t         j                  |d      5 }| j                  |j                  t         j                         d d d        t         j                  |d      5 }| j                  |j                  t         j                         d d d        | j                  t              5  t         j                  |d       d d d        d d d        d	D ]j  }t	        | j                  |      5 }t         j                  |
      5 }| j                  |j                  t         j                         d d d        d d d        l dD ]  }d|v rt        j                  | j                         t	        | j                  |      5 }| j                  t              5  t         j                  |
      }d d d        5  | j                  |j                  t         j                         d d d        d d d         y # 1 sw Y   Gx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   hxY w# 1 sw Y   mx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)NrA   r+br3   r~   r2   rM   r   z)rj   r7  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_modeM  s   dmmT*002$--' 
	31qs3 4q  34qs3 5q  45qs3 5q  45qs3 5q  45"":. 3ac23
	3   	8DdmmT* 8a]]1]- 8$$QVVTYY788 8	8 % 	9Dd{  /dmmT* 9a%%m4 1a0A1 9$$QVVTZZ899 9	94 45 55 55 53 3
	3 
	38 88 81 19 99 9s   L+KL'+KL1+K'L;+K4&LLLL(+LL(M.L5
M+M:MK	LK$	L'K1	,L4K>	9LL	LLL% L((L2	5L>:MM
MM	c                    | j                   }t        j                  |      }t        j	                  |d      5 }|j                  t        dz         d d d        | j                  j                  |       t        j	                  |d      5 }| j                  |j                         t        dz         d d d        | j                  |j                  |       t        j	                  |d      5 }| j                  |j                         t        dz         d d d        | j                  |j                  |       y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   >xY w)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_filenameg  s   }}\2]]>40 	 AGGEBJ	 0]]>40 	3AQVVXurz2	30]]<. 	3!QVVXurz2	3.	  	 	3 	3	3 	3s#   D:(E-(E:EEEc                    t        j                         }t        j                  |d      5 }|j	                  t
        dz         | j                  |j                  d       | j                  t         j                  |j                         | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j!                         d       | j                  |j"                  d       d d d        | j                  j"                  d       | j                  |j                  d       | j                  t$        |j                         | j                  |j                  t        j                         | j                  |j                         d       | j                  |j                         d       | j                  |j!                         d       |j'                  d       t        j                  |d      5 }| j                  |j)                         t
        dz         | j                  |j                  d       | j                  t         j                  |j                         | j                  |j                  t        j*                         | j                  |j                         d       | j                  |j                         d       | j                  |j!                         d       | j                  |j"                  d       d d d        | j                  |j"                  d       | j                  |j                  d       | j                  t$        |j                         | j                  |j                  t        j*                         | j                  |j                         d       | j                  |j                         d       | j                  |j!                         d       y # 1 sw Y   xY w# 1 sw Y   xY w)	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_nameu  s   jjl]]3T]2 	+aGGEBJQVVR(b55qxx@QVVTZZ0MM!**,.MM!**,-MM!**,-MM!((E*	+ 	ahh%$.!((3,ajjlE*ajjlD)ajjlD)]]3T]2 	+aQVVXurz2QVVR(b55qxx@QVVTYY/MM!**,-MM!**,.MM!**,-MM!((E*	+ 	ahh%$.!((3+ajjlD)ajjlE*ajjlD)C	+ 	+$	+ 	+s   DQDQQQc                 x   | j                   dz   }t        | j                   d      5 }t        j                  ||d      5 }|j	                  t
        dz         | j                  |j                  |       d d d        d d d        t        | j                   d      5 }t        j                  ||d      5 }| j                  |j                         t
        dz         | j                  |j                  |       d d d        d d d        t        j                  | j                   d      5 }| j                  |j                         t
        dz         | 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   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)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  sd   MME)	4==$' 	07mmGidmK	0OPGGEBJQVVY/	0 	0 4==$' 	07mmGidmK	0OPQVVXurz2QVVY/	0 	0
 ]]4==$/ 	41QVVXurz2QVVT]]3	4 	4	0 	0 	0 	0	0 	0 	0 	0
	4 	4sT   F5E>4FF$3AF7F$'AF0>F	FFF!	F$$F-0F9c                    t         j                  dt        d      z  d      }| j                  t	        |      t
        j                         t        j                  |      }t         j                  |      }| j                  |j                  d      d       dt
        j                  z   }| j                  |j                  j                  j                         |d       y)	z-Decompressed data buffering should be limitedr   g    >Ar   r|   r9  rx   z)Excessive amount of data was decompressedN)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X-Q}?D	2#9#9:zz$t,Q////
V^^//446
7	9r   c                 \   t         t        fD ]  }dD ]  }t        j                  |g| }| j	                  t        |      t               t        j                  t        j                  |      d      5 }| j	                  |j                         |       d d d          y # 1 sw Y   xY w)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 	5D. 5d2T2  ee4]]2::e+<4]H 5A$$QVVXt45 55	55 5s   4!B""B+c           	         d}t         t        fD ]  }dD ]  }| j                  ||      5  t        j                  |g|d|i}| j                  t        |      t               t        j                  t        j                  |      d      5 }|j                  d       | j                  |j                  |       d d d        d d d          y # 1 sw Y   xY w# 1 sw Y   xY w)Nr   rU  )r:   r   r   rj   r~   rx   )rD   r   r   r   r   r7   rV  r4   r5   r   r   r9   r   )r   r   r:   r   rW  r=   s         r   test_compress_mtimezTestGzip.test_compress_mtime  s    EN 	9D. 9\\t$\7 9 MM$CCUCE$$T%[%8rzz%/@tL 9PQq	((%899 99	9
9 99 9s$   A#C.C	;CCCC%c                 (   dD ]  }| j                  |      5  t        j                  t        d|      }t        j                  t        d|      }| j	                  t        |       | j                  t        |       d d d         y # 1 sw Y   xY w)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     	5EE* 5!]]5]O
"mmE%mPeZ0  4	5 5	55 5s   A%BB	c                    t         t        fD ]  }t        j                         }t        j                  |d      5 }|j                  |       d d d        | j                  t        j                  |j                               |       t        j                  |      }| j                  t        j                  |      |        y # 1 sw Y   yxY w)NrA   r~   )rD   r   r   r   r   r5   r6   r7   
decompressr  r   )r   r:   r
  r=   rW  s        r   test_decompresszTestGzip.test_decompress  s    EN 	;D**,Cs6 !T__S\\^<dCMM$'ET__U3T:	; s   CC	c                     t         j                  t              }| j                  t        t         j
                  |d d        y )Nr   r   rD   rk   EOFErrorrc  r   compressed_datas     r   !test_decompress_truncated_trailerz*TestGzip.test_decompress_truncated_trailer  -    --.(DOO_Sb5IJr   c                     t         j                  t              }| j                  t        t         j
                  |d d        y )Nrg  ri  s     r   test_decompress_missing_trailerz(TestGzip.test_decompress_missing_trailer  rl  r   c                    t         dz  }t        j                  |      d d }t        j                  t	        j
                  |            5 }| j                  t        |j                         d d d        t        j                  t	        j
                  |            5 }| j                  |j                  t        |            |       | j                  t        |j                  d       d d d        t        dd      D ]X  }t        j                  t	        j
                  |d |             5 }| j                  t        |j                  d       d d d        Z y # 1 sw Y   xY w# 1 sw Y   }xY w# 1 sw Y   }xY w)NrB   rn  r9  rx   r   r   )rD   r   r   r5   r   r   rk   rh  r9   r7   r8   r\   )r   r:   	truncatedr=   r   s        r   test_read_truncatedzTestGzip.test_read_truncated  s)   RxMM$',	]]2::i#8]9 	0Qh/	0]]2::i#8]9 	3QQVVCI.5h2	3 q" 	7Arzz)BQ-'@A 7Q!!(AFFA67 7	7	0 	0	3 	3
7 7s%   !EAE%,"E1E"%E.1E:	c                     d}t         j                  t        j                  |            5 }| j	                  |j                         d       d d d        y # 1 sw Y   y xY w)Ns   cQ ExtraI-. 2Mx   r9  s   Test)r   r5   r   r   r7   r9   )r   gzdatar=   s      r   test_read_with_extrazTestGzip.test_read_with_extra  sO    < ]]2::f#5]6 	0!QVVXw/	0 	0 	0s   !AAc                 ^   t         j                  | j                  d      5 }|j                  t               d d d        t         j                  | j                  d      5 }|j
                  j                  j                  j                          d d d        y # 1 sw Y   axY w# 1 sw Y   y xY w)NrA   rj   )	r   r   r)   r6   rD   rO  r*  _fpprependrJ   s     r   test_prepend_errorzTestGzip.test_prepend_error  s~    YYt}}d+ 	qGGEN	YYt}}d+ 	(qIIMM%%'	( 	(	 		( 	(s   B/B#B #B,c                 b   t        j                   dg d      }t        |      |j                  z  }t        j	                  t        j                         d      5 }| j                  |j                  |      |       | j                  |j                         |       d d d        y # 1 sw Y   y xY w)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    KK_-Q!**$]]2::<c]: 	/aQWWQZ0QVVXv.	/ 	/ 	/s   AB%%B.c                    t        j                         }d}t        j                  |d      5 }|j	                  |       |j                          |j                         }d d d        |j                         }| j                  t        j                  |      |       | j                  t              5  t        j                         d d d        t        j                  t        j                         }t        j                        }t        j                  |       |j                  |j                               }| j                  ||       y # 1 sw Y   xY w# 1 sw Y   xY w)N   important message here.r2   r~   )wbits)r   r   r   r5   r6   rE   r  r7   rc  rk   rh  r   decompressobj	MAX_WBITS_read_gzip_headerr9   )r   bmessager=   partial_data	full_datarS   read_messages           r   test_flush_flushes_compressorz&TestGzip.test_flush_flushes_compressor
  s	   JJL,]]13]/ 	(1GGGGGI::<L	( JJL	3W= x( 	*OOL)	*dnn_5JJ|$q!||AFFH-w/	( 	(	* 	*s   2E2EEE&c                 z    G d d      }t        j                         } |       }t        j                  |d      5 }||_        |j                          |j                  d       |j                  d       d d d        t        j                  dddg}| j                  |j                  |       y # 1 sw Y   :xY w)	Nc                        e Zd Zd Zd ZddZy)1TestGzip.test_flush_modes.<locals>.FakeCompressorc                     g | _         y r   )modesr   s    r   __init__z:TestGzip.test_flush_modes.<locals>.FakeCompressor.__init__#  s	    
r   c                      yNr   r   )r   r:   s     r   r   z:TestGzip.test_flush_modes.<locals>.FakeCompressor.compress%  s    r   c                 :    | j                   j                  |       yr  )r  rs   )r   r;   s     r   rE   z7TestGzip.test_flush_modes.<locals>.FakeCompressor.flush'  s    

!!$'r   N))r!   r"   r#   r  r   rE   r   r   r   FakeCompressorr  "  s     r   r  r2   r~   rB   r  )	zlib_moder  )
r   r   r   r5   r   rE   r   Z_SYNC_FLUSHr7   r  )r   r  r  fcr=   expected_modess         r   test_flush_modeszTestGzip.test_flush_modes  s    	 	 JJL]]13]/ 	#1AJGGIGGBKGGcG"		# 	
 	>2	# 	#s   ;B11B:c                 p   t        j                         }d}t        j                  |d      5 }|j	                  |       |j                  t        |             |j	                  |       d d d        |j                         }| j                  t        j                  |      |dz         y # 1 sw Y   BxY w)Nr  r2   r~   r   )
r   r   r   r5   r6   r    r8   r  r7   rc  )r   r  r  r=   r:   s        r   test_write_seek_writezTestGzip.test_write_seek_write:  s     JJL,]]13]/ 	1GGGFF3w< GGG	 zz|.!<	 	s   =B,,B5N)r  );r!   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+  r5  r=  rB  rE  rI  rS  rX  rZ  ra  rd  rk  ro  rr  ru  ry  r  r  r  r  r   r   r   r0   r0   9   s1   /0"'8?.&7 S#. $.85-&/	F
5
"&*!58<	11Hf?(7*
F?@57,7G.R&8P94/#*J4
95	95;KK70(/0*36
=r   r0   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestOpenc                    t         dz  }t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }t        j                  |j                               }| j                  ||       d d d        t        j                  | j                  d      5 }| j                  |j                         |       d d d        t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }t        j                  |j                               }| j                  ||dz         d d d        | j                  t              5  t        j                  | j                  d       d d d        t        j                  | j                         t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }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   xY w# 1 sw Y   tx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)NrB   rA   rj   r   r   r   rD   r   r   r)   r6   rc  r9   r7   rk   r   r   r(   r   r	  r=   	file_datas       r   test_binary_modeszTestOpen.test_binary_modesH  s   rzYYt}}d+ 	"qGGL!	"$--& 	6!1IY5	6 YYt}}d+ 	5qQVVX|4	5 YYt}}d+ 	"qGGL!	"$--& 	:!1IYq(89	: / 	+IIdmmT*	+'YYt}}d+ 	"qGGL!	"$--& 	6!1IY5	6 	6)	" 	"	6 	6	5 	5	" 	"	: 	:	+ 	+	" 	"	6 	6_   I6I+8!I8J19J!J/J+6J7I(+I58JJJJ(+J47K c                    t        j                  | j                        }t        j	                  |d      5 }|j                  t        dz         d d d        | j                  j                  | j                         t        j	                  |d      5 }|j                  t               d d d        | j                  |j                  | j                         t        j	                  |      5 }| j                  |j                         t        dz         d d d        | j                  |j                  | j                         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   HxY w)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_filec  s    %%dmm4YYx& 	 !GGEBJ	 /YYx& 	!GGEN	/YYx  	3AQVVXurz2	3/	  	 	 		3 	3s#   EE,(EEEE$c                    t         dz  }t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }t        j                  |j                               }| j                  ||       d d d        t        j                  | j                  d      5 }| j                  |j                         |       d d d        t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }t        j                  |j                               }| j                  ||dz         d d d        | j                  t              5  t        j                  | j                  d       d d d        t        j                  | j                         t        j                  | j                  d      5 }|j	                  |       d d d        t        | j                  d      5 }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   xY w# 1 sw Y   tx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)NrB   r2   rj   r3   rM   r   r   r  r  s       r   test_implicit_binary_modesz#TestOpen.test_implicit_binary_modeso  s   rzYYt}}c* 	"aGGL!	"$--& 	6!1IY5	6 YYt}}c* 	5aQVVX|4	5 YYt}}c* 	"aGGL!	"$--& 	:!1IYq(89	: / 	*IIdmmS)	*'YYt}}c* 	"aGGL!	"$--& 	6!1IY5	6 	6)	" 	"	6 	6	5 	5	" 	"	: 	:	* 	*	" 	"	6 	6r  c                    t         j                  d      dz  }|j                  dt        j                        }t
        j                  | j                  dd      5 }|j                  |       d d d        t        | j                  d      5 }t
        j                  |j                               j                  d      }| j                  ||       d d d        t
        j                  | j                  dd      5 }| j                  |j                         |       d d d        t
        j                  | j                  dd      5 }|j                  |       d d d        t        | j                  d      5 }t
        j                  |j                               j                  d      }| j                  ||d	z         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)
Nr  rB   
wtr  rj   rtatr   rD   r  replacerH   linesepr   r   r)   r6   rc  r9   r7   r   r	  uncompressed_rawr=   r  s        r   test_text_modeszTestOpen.test_text_modes  s   ||G,r1'//bjjAYYt}}dWY= 	"GGL!	"$--& 	:!188AIY(89	: YYt}}dWY= 	5QVVX|4	5YYt}}dWY= 	"GGL!	"$--& 	>!188AIY(81(<=	> 	>	" 	"	: 	:	5 	5	" 	"	> 	>s>   GAG:!G G,5AG8GG G),G58Hc                    t         dz  }|j                  d      }t        j                  |      }t        j	                  t        j                  |      d      5 }| j                  |j                         |       d d d        t        j	                  t        j                  |      d      5 }| j                  |j                         |       d d d        t        j	                  t        j                  |      dd      5 }| j                  |j                         |       d d d        y # 1 sw Y   xY w# 1 sw Y   jxY w# 1 sw Y   y xY w)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
YYrzz*-s3 	;qQVVX'9:	;YYrzz*-t4 	;QVVX'9:	;YYrzz*-tgYF 	9!QVVX'78	9 	9		; 	;	; 	;	9 	9s$   !D)+!D5?!E)D25D>E
c                 v   | j                  t              5  t        j                  d       d d d        | j                  t              5  t        j                  | j
                  d       d d d        | j                  t              5  t        j                  | j
                  d       d d d        | j                  t              5  t        j                  | j
                  dd       d d d        | j                  t              5  t        j                  | j
                  dd       d d d        | j                  t              5  t        j                  | j
                  dd	
       d d d        y # 1 sw Y   Gx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   y xY w)Ngw/^@wbtxbtrj   zutf-8r  ignore)errorsr  )newline)rk   rl   r   r   r   r)   r   s    r   test_bad_paramszTestOpen.test_bad_params  sK   y) 	IIg	z* 	,IIdmmU+	,z* 	,IIdmmU+	,z* 	=IIdmmTGI<	=z* 	<IIdmmT(I;	<z* 	9IIdmmT4I8	9 	9	 		, 	,	, 	,	= 	=	< 	<	9 	9sG   E1	!E>!F#F#F##F/1E;>FFF #F,/F8c                    t         j                  d      dz  }|j                  dt        j                        }t
        j                  | j                  dd      5 }|j                  |       d d d        t        | j                  d      5 }t
        j                  |j                               j                  d      }| j                  ||       d d d        t
        j                  | j                  dd      5 }| j                  |j                         |       d d d        y # 1 sw Y   xY w# 1 sw Y   axY w# 1 sw Y   y xY w)	Nr  rB   r  r  zutf-16r  rj   r  r  r  s        r   test_encodingzTestOpen.test_encoding  s   ||G,r1'//bjjAYYt}}dXY> 	"!GGL!	"$--& 	:!188BIY(89	: YYt}}dXY> 	5!QVVX|4	5 	5	" 	"	: 	:	5 	5s%   D$AD0:!D<$D-0D9<Ec                 @   t         j                  | j                  d      5 }|j                  d       d d d        t         j                  | j                  ddd      5 }| j	                  |j                         d       d d d        y # 1 sw Y   VxY w# 1 sw Y   y xY w)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 	1QVVXx0	1 	1	# 	#	1 	1s   B!BBBc                 x   t         j                  d      dz  }t        j                  | j                  ddd      5 }|j                  |       d d d        t        j                  | j                  ddd      5 }| j                  |j                         |g       d d d        y # 1 sw Y   WxY w# 1 sw Y   y xY w)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  s    ||G,r1YYt}}dWdYK 	"qGGL!	"YYt}}dWdYK 	<qQ[[]\N;	< 	<	" 	"	< 	<s   B$9"B0$B-0B9N)r!   r"   r#   r  r  r  r  r  r  r  r  r  r   r   r   r  r  G  s/    66
068> 	99
51<r   r  c                       fd}|S )Nc                 F     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  s>    KK	",00  +	  +s	   5 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y
)TestCommandLines   This is a simple test with gzipc                    t        j                         5 }t        j                  |d      5 }|j	                  | j
                         d d d        t        j                  dddf}t        |t        t        t              5 }|j                  |j                               \  }}d d d        d d d        | j                  d       | j                  | j
                         y # 1 sw Y   xY w# 1 sw Y   LxY w# 1 sw Y   PxY w)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    ZZ\ 	AXxd; +y		*+ >>45Dt4TB Ad++H,=,=,?@SA	A 	c"dii(+ +A A	A 	As:   C:C"	7C: #C.#C:"C+	'C:.C7	3C::Dc                    t         j                  j                  t        d      }| j	                  t         j                  j                  |             t        j                  |d      5 }|j                  | j                         d d d        t        ddd|      \  }}}t        t         j                  j                  t        d      d      5 }| j                  |j                         | j                         d d d        | j                  t         j                  j                  |             | j                  |d	       | j                  |d
       | j                  |d
       y # 1 sw Y   xY w# 1 sw Y   zxY w)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   77<<712YYxdY+ 	 rHHTYY	 'fdHEC"'',,w
3T: 	9hX]]_dii8	9 	x01Qc"c"	  	 	9 	9s   *E&+E2&E/2E;c                     t        dddd      \  }}}| j                  d|j                                | j                  |d       | j                  |d       y )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   sP    ,T64ARSCJCIIKXQc"r   c                    t         j                  ddf}t        |t        t        t              5 }|j	                  | j
                        \  }}d d d        | j                  d       | j                  d d d       y # 1 sw Y   1xY w)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  sy     ~~tV+4tD> 	3$''		2HC	3 	c"Ra+.		3 	3s   A>>Bc                    t         j                  j                  t        d      }|dz   }| j	                  t         j                  j                  |             t        |d      5 }|j                  | j                         d d d        t        dd|      \  }}}| j                  t         j                  j                  |             | j                  |d       | j                  |d       y # 1 sw Y   mxY w)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2.$' 	 2HHTYY	  (fnECx01c"c"	  	 s   $C,,C5c                    dD ]L  }| j                  |      5  t        j                  j                  t        d      }|dz   }| j                  t        j                  j                  |             t        |d      5 }|j                  | j                         d d d        t        dd||      \  }}}| j                  t        j                  j                  |             | j                  |d       | j                  |d       t        j                  |       | j                  t        j                  j                  |             d d d        O y # 1 sw Y   xY w# 1 sw Y   gxY w)	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)E1  !9:.$/ (2HHTYY'(  0fnn]Cx 89  c*  c*		(#  !9:; ;	;( (; ;s%   A$E =EB/E EE  E*	c                 p    t        dddd      \  }}}| j                  d|       | j                  |d       y )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_exclusive2  s8    ,T68XNCQSVWc"r   c                 p    t        dddd      \  }}}| j                  d|       | j                  |d       y )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_compression7  s8    ,T68T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__)'__doc__rf   r  r   rH   r   r  unittest
subprocessr   r   test.supportr   r   r   r   r	   test.support.script_helperr
   r   import_moduler   r   rD   r   r  abspathr.   r  r   r   TestCaser%   r0   r  r  r  r!   mainr   r   r   <module>r     s      	 	  
  " & " = = N"}""6*"}""6*		 ''//)**
+h
6&2:: &(x   (K=x K=\H<x H<V
[#h'' [#| zHMMO r   