
    7bh                        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Zddl	m
Z
mZ ddl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j6                  j9                  ej:                        dz   Z G d dej>                        Z  G d dejB                        Z" G d de"      Z# G d de"      Z$d Z% G d dejB                        Z&e'dk(  r ejP                          yy)z!Test script for the gzip module.
    N)PIPEPopen)catch_unraisable_exception)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    8/opt/python-3.12.12/usr/lib/python3.12/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.setUp4       'r   c                 B    t        j                  | j                         y r   r(   r   s    r   tearDownzBaseTest.tearDown7   r,   r   N)r"   r#   r$   r   TESTFNr*   r+   r.   r   r   r   r&   r&   1   s    H((r   r&   c                   r   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:d9 Z;y:)<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(3qA 4CK(]]4==#d(3qQVVXv. 43 43 43s   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   r6   r*   r7   data1flushfilenohasattrosrD   closer   r>   s     r   
test_writezTestGzip.test_writeD   sx    ]]4==$/1GGEBJ GGIHHJr7#$GGI 0 	
	 0/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)Nr3   rC   a3   )r   FakePathr*   r   r6   r7   rE   assertIsInstancenamestrr8   r:   )r   r*   r>   ds       r   "test_write_read_with_pathlike_filez+TestGzip.test_write_read_with_pathlike_fileR   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 )NrC      B)   rY      )shape)r@   
memoryviewrE   r5   rangecast)r   mr;   s      r   test_write_memoryviewzTestGzip.test_write_memoryviewc   sL      EBJ!78uU3Z()vvcv)  &r   c                 F    | j                  t        t        dz               y )NrC   )r@   	bytearrayrE   r   s    r   test_write_bytearrayzTestGzip.test_write_bytearrayi   s      52:!67r   c                 \    | j                  t        j                  dt        dz               y )NI(   )r@   arrayrE   r   s    r   test_write_arrayzTestGzip.test_write_arrayl   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)NrB    rb)	r   r6   r*   assertRaises	TypeErrorr7   rE   r8   r:   rK   s     r   test_write_incompatible_typez%TestGzip.test_write_incompatible_typeo   s     ]]4==$/1""9- .""9- .GGEN 0 ]]4==$/1QVVXu- 0/ .--- 0/ 0/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)Nr4   rC   )rL   r   r6   r*   r:   r8   rE   r   r>   rT   s      r   	test_readzTestGzip.test_read|   sM    ]]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   r4   r   rC   )rL   r   r6   r*   read1appendr9   r8   r   joinrE   )r   blocksnreadr>   rT   s        r   
test_read1zTestGzip.test_read1   s    ]]4==#.!GGIa Q  51  	 / 	&)52:6 /.s   AB<<C   )sizememusec                     t         j                  t        d      }t         j                  t	        j
                  |      d      }| j                  |j                  |      t               y )Nry   compresslevelrk   fileobjr<   )r   compressrE   r6   r   BytesIOr8   r:   )r   rz   
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)Nr4   ry   r   r3   r   )rL   r   r6   r*   r   assertFalseclosedrJ   
assertTruerl   
ValueErrorr:   r!   r   r7   rF   )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   rk   rC   )	rL   r   r6   r*   r7   data2r:   r8   rE   rp   s      r   test_appendzTestGzip.test_append   s    ]]4==$/1GGEBJ 0 ]]4==$/1A 0U2X%(34 0/ 0/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)NrB   	      ar      r   rk   r   i    s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)r   r6   r*   r7   r]   r:   r8   )r   r>   izgfilecontentsztxts         r   test_many_appendzTestGzip.test_many_append   s     ]]4==$2aGGDM 3q#At}}dA6! 76 
 ]]4==$/6H{{4(D U  # 0 	8, 32 76 0/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xbrC   rk   )	r   r6   r*   r7   rE   r8   r:   rl   FileExistsErrorrK   s     r   test_exclusive_writezTestGzip.test_exclusive_write   s    ]]4==$/1GGEBJ 0]]4==$/1QVVXurz2 0/MM$--. 0/	 0/////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)Nrk   rC   Tkeepends)	rL   r   r6   r*   r   BufferedReaderr8   rE   
splitlines)r   r>   r4   lineliness        r   test_buffered_readerzTestGzip.test_buffered_reader   s     	]]4==$/1""1%*+,!$!, & 0 	U%5%5t%5%D DE - &% 0/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)Nrk   r   ry   rC   )rL   r   r6   r*   readliner   r9   )r   r>   line_lengthLs       r   test_readlinezTestGzip.test_readline   s{     ]]4==$/1KJJ{+[A-uA+ 56*Q"4	 /4	 0//s   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)Nrk      )rL   r   r6   r*   	readlines)r   r>   r   s      r   test_readlineszTestGzip.test_readlines   s     ]]4==$/1A 0 ]]4==$/1KK$7E ! 0/ 0/ 0/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
   )
rL   r   r6   r*   r   r   r!   r9   r:   r8   )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   ry   )whence      )rL   r   r6   r*   r:   r!   r8   rE   )r   r>   ys      r   test_seek_whencezTestGzip.test_seek_whence  sn     ]]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)Nr3   r   rW      s   GZ
)r   r6   r*   r]   r!   r7   )r   r>   poss      r   test_seek_writezTestGzip.test_seek_write  sL    ]]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)Nr4   rk   xr   )	rL   r   r6   r*   r8   	myfileobjr<   r   r)   rK   s     r   	test_modezTestGzip.test_mode"  s    ]]4==#.!Q[[--t4 /']]4==#.!Q[[--t4 /. /. /.s   '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)rB   rk   rR   )r   r6   r*   r   rH   r8   rR   )r   r<   r>   s      r   test_1647484zTestGzip.test_1647484*  sZ     Dt}}d3q6 23  7 43 !33s   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)Nrk   rR   )	rL   r   r6   r*   r   rH   r   r8   rR   rK   s     r   test_paddedfile_getattrz TestGzip.test_paddedfile_getattr0  s_    ]]4==$/1OOGAIIv67QYY^^T]]; 0//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[r3   mtimer   )r   r6   r*   r7   rE   r   rH   assertIsNoner   r:   r8   )r   r   fWritefReaddataReads        r   
test_mtimezTestGzip.test_mtime6  s    ]]4==#u]=LL >]]4==)UOOGE734ekk*zz|HXu-U[[%0 *) >=))s   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   r3   r   rk         ry      zLatin-1    r   rZ   z<i      rY   s   d)r   r6   r*   r7   rE   openr:   r8   encodeUnicodeEncodeErrorstructpackr9   r!   rI   statst_size)r   r   r   r   idBytescmByteexpectednameexpectedflags	flagsByte
mtimeBytesxflByteosByte	nameBytes
crc32Bytes
isizeBytess                  r   test_metadatazTestGzip.test_metadataA  s   ]]4==#u]=LL > $--&% 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 '& >= & (" '( '&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_namet  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))fastry      )bestr   r   )tradeoff   r   rY   r3   r}   rk   ry   )
subTestr   r6   r*   r7   rE   r   r!   r:   r8   )	r   cases	xflOffsetrR   levelexpectedXflByter   r   r   s	            r   test_compresslevel_metadataz$TestGzip.test_compresslevel_metadatax  s    

 	.3*T5/d#t}}cOLL' $--.%JJy)#jjmG$$Wo> /	 $# /4 V..	 $#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)NrB   s   xxxrk   z4__enter__ on a closed file didn't raise an exceptionry   r   z1/0 didn't raise an exception)r   r6   r*   r7   rJ   failr   ZeroDivisionErrorrK   s     r   test_with_openzTestGzip.test_with_open  s    ]]4==$/1GGFO 0MM$--.			N 
 IILM	7t}}d3q! 4
 II56# 0/
  		
 43  		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)NrB   rC   r   s2                                                     rk   zIncorrect data in file)r   r6   r*   r7   rE   r   r:   r8   rp   s      r   test_zero_padded_filezTestGzip.test_zero_padded_file  s    ]]4==$/1GGEBJ 0 $--&!GGL! ' ]]4==$/1AQ
,DE 0/ 0/ '& 0/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)NrB   rC   r4   )	r   r*   r7   rE   r   r6   rl   r  r   )r   files     r   test_bad_gzip_filezTestGzip.test_bad_gzip_file  sm    $--&$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)NrC   rB   r   rk   )rE   r   r   r6   r7   getvaluer8   r:   )r   uncompressedbufr>   r   s        r   test_non_seekable_filezTestGzip.test_non_seekable_file  s    rzn]]3T]2aGGL! 3\\^
:&]]3T]2aQVVX|4 32	 32 32s   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   rB   c               3   :   K   	 t        ddd      D ]  } |   w)N   rC   r   )r]   )ns    r   sizesz!TestGzip.test_peek.<locals>.sizes  s&     q"b)AG * s   rk   !   r   r   d   )
rE   r   r6   r*   r7   max_read_chunkpeekr8   r:   r9   )r   r
  r>   r  rw   r  ss          r   	test_peekzTestGzip.test_peek  s    s{]]4==$/1GGL! 0	
 ]]4==$/1!AEWFF1I8  A3Q  QVVC[#.UC$56 0/ 0/ 0/s   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)NrC   asciiTr   r4   encoding)rE   decoder   rL   r   r6   r*   r   TextIOWrapperr8   r   )r   r   r>   ts       r   test_textio_readlineszTestGzip.test_textio_readlines  s    ##G,777F]]4==#.!!!!g6!  6 7 /.66 /.s$   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      oneFTrB   r3      twor   rN      threerk   r4      twothree)r   r*   r   r6   r7   r8   rR   rG   r<   WRITEassertIsreadablewritabler   r   rl   AttributeErrorr:   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. 6 MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-! '$ $--&#s5  2  SZZ\:  4ajjlE2ajjlD1ajjlD1ahh. 6 MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-! '$ $--&#s5!  2  SZZ\:  4ajjlE2ajjlD1ajjlD1ahh. 6 MM!((D)QVVSXX.nahh7QVVTZZ0MM!**,.MM!**,-MM!**,-! '$ $--&#s5  ;7  2  SZZ\:  3ajjlD1ajjlE2ajjlD1ahh. 6 MM!((D)QVVSXX.nahh7QVVTYY/MM!**,-MM!**,.MM!**,-! '&k 65 '&& 65 '&& 65 '&& 65 '&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!  rj   TrB   r3   r"  r   rN   r#  rk   r4   r$  )rI   r   r*   O_WRONLYO_CREATO_EXCLfdopenr   r6   r7   r8   rR   rG   r&  r   rl   r)  O_TRUNCO_APPENDO_RDONLYr:   )r   fdr+  r>   s       r   test_fileobj_from_fdopenz!TestGzip.test_fileobj_from_fdopen'  sM    WWT]]BKK"**$<ryy$HIYYr4 Cs5  ,  SZZ\: 6 MM!((D)QVVR(nahh7 ! WWT]]BKK"**$<rzz$IJYYr4 Cs5  ,  SZZ\: 6 QVVR(nahh7 ! WWT]]BKK"**$<r{{$JKYYr4 Cs5!  ,  SZZ\: 6 QVVR(nahh7 ! WWT]]BKK0YYr4 Cs5  ;7  ,  SZZ\: 6 QVVR(nahh7 ! 7 65 !  65 !  65 !  65 ! s   '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)NrB   r+br4   r   r3   rN   r   z)rk   r8  r   )rB   r   r   )r   r6   r*   rJ   r   r8   r<   r*  r%  rl   r   r   r)   assertWarnsFutureWarning)r   r>   gr<   s       r   test_fileobj_modezTestGzip.test_fileobj_modeO  s:   dmmT*002$--'1qs3q  3 4qs3q  4 4qs3q  4 4qs3q  4 4"":.ac2 / (  DdmmT*a]]1]-$$QVVTYY7 . +*   %Dd{  /dmmT*a%%m4a0A 5$$QVVTZZ8  +* % 43333333.. (' .- +* 54Q +*s   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)NrB   rC   rk   )
r*   rI   fsencoder   r6   r7   rE   r8   rR   r:   )r   str_filenamebytes_filenamer>   s       r   test_bytes_filenamezTestGzip.test_bytes_filenamei  s    }}\2]]>40AGGEBJ 10]]>40AQVVXurz2 10]]<.!QVVXurz2 /. 10 10 /.s#   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)	NrB   r   rC   rj   FTr   rk   )r   r   r   r6   r7   rE   r8   rR   rl   r   rG   r<   r%  r&  r'  r(  r   r   r)  r!   r:   r*  )r   bior>   s      r   test_fileobj_without_namez"TestGzip.test_fileobj_without_namew  s   jjl]]3T]2aGGEBJQVVR(b55qxx@QVVTZZ0MM!**,.MM!**,-MM!**,-MM!((E* 3 	ahh%$.!((3,ajjlE*ajjlD)ajjlD)]]3T]2aQVVXurz2QVVR(b55qxx@QVVTYY/MM!**,-MM!**,.MM!**,-MM!((E* 3 	ahh%$.!((3+ajjlD)ajjlE*ajjlD)C 32$ 32s   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newrB   )r   r*   r<   rC   rk   )	r*   r   r   r6   r7   rE   r8   rR   r:   )r   	filename2r   r>   s       r   test_fileobj_and_filenamez"TestGzip.test_fileobj_and_filename  sA   MME)	4==$'7mmGidmKqGGEBJQVVY/ L ( 4==$'7mmGidmKqQVVXurz2QVVY/ L (
 ]]4==$/1QVVXurz2QVVT]]3 0/ LK ('
 LK ('
 0/sT   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}   r:  ry   z)Excessive amount of data was decompressedN)r   r   int
assertLessr9   r   DEFAULT_BUFFER_SIZEr   r6   r8   r:   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   )ry   )r   )r   rk   r   )rE   r   r   r   r8   typer5   r6   r   r   r:   )r   r;   r    datacr>   s        r   test_compresszTestGzip.test_compress  s    END.d2T2  ee4]]2::e+<4]HA$$QVVXt4 IH / # IHs   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   rV  )r;   r    r   rk   r   ry   )rE   r   r   r   r   r8   rW  r5   r6   r   r   r:   r   )r   r   r;   r    rX  r>   s         r   test_compress_mtimezTestGzip.test_compress_mtime  s    END.\\t$\7 MM$CCUCE$$T%[%8rzz%/@tLPQq	((%8 M 87 / #
 ML 87s$   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   ry   )r   r   r   rE   assertInassertNotIn)r   r   
nocompressyescompresss       r   test_compress_correct_levelz$TestGzip.test_compress_correct_level  so    EE*!]]5]O
"mmE%mPeZ0  4	 +* **s   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)NrB   r   )rE   r   r   r   r   r6   r7   r8   
decompressr	  r   )r   r;   r  r>   rX  s        r   test_decompresszTestGzip.test_decompress  s    END**,Cs6! 7T__S\\^<dCMM$'ET__U3T: #66s   CC	c                     t         j                  t              }| j                  t        t         j
                  |d d        y )Nr   r   rE   rl   EOFErrorrd  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 )Nrh  rj  s     r   test_decompress_missing_trailerz(TestGzip.test_decompress_missing_trailer  rm  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)NrC   ro  r:  ry   r   r   )rE   r   r   r6   r   r   rl   ri  r:   r8   r9   r]   )r   r;   	truncatedr>   r   s        r   test_read_truncatedzTestGzip.test_read_truncated  s   RxMM$',	]]2::i#8]9Qh/ :]]2::i#8]9QQVVCI.5h2 : q"Arzz)BQ-'@AQ!!(AFFA6 BA  :999
 BAs%   !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   r:  s   Test)r   r6   r   r   r8   r:   )r   gzdatar>   s      r   test_read_with_extrazTestGzip.test_read_with_extra  sF    < ]]2::f#5]6!QVVXw/ 766s   !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)NrB   rk   )	r   r   r*   r7   rE   rP  r+  _fpprependrK   s     r   test_prepend_errorzTestGzip.test_prepend_error  sl    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)ry   r      rZ   r  r3   r   )
rg   r9   itemsizer   r6   r   r   r8   r7   r   )r   qLENGTHr>   s       r   test_issue44439zTestGzip.test_issue44439  sv    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.r3   r   )wbits)r   r   r   r6   r7   rF   r	  r8   rd  rl   ri  r   decompressobj	MAX_WBITS_read_gzip_headerr:   )r   bmessager>   partial_data	full_datarT   read_messages           r   test_flush_flushes_compressorz&TestGzip.test_flush_flushes_compressor  s    JJL,]]13]/1GGGGGI::<L 0 JJL	3W= x(OOL) )dnn_5JJ|$q!||AFFH-w/ 0/ )(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  rt   )r   r<   s     r   rF   z7TestGzip.test_flush_modes.<locals>.FakeCompressor.flush)  s    

!!$'r   N))r"   r#   r$   r  r   rF   r   r   r   FakeCompressorr  $  s     r   r  r3   r   rC   r  )	zlib_moder  )
r   r   r   r6   r   rF   r   Z_SYNC_FLUSHr8   r  )r   r  r  fcr>   expected_modess         r   test_flush_modeszTestGzip.test_flush_modes!  s    	 	 JJL]]13]/1AJGGIGGBKGGcG"	 0 	
 	>2 0/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  r3   r   r   )
r   r   r   r6   r7   r!   r9   r	  r8   rd  )r   r  r  r>   r;   s        r   test_write_seek_writezTestGzip.test_write_seek_write<  s     JJL,]]13]/1GGGFF3w< GGG 0 zz|.!< 0/s   =B,,B5c                     t               5 }t        j                  t        j                         d       t        j                          | j                  |j                         d d d        y # 1 sw Y   y xY w)Nr3   r   )	r   r   r6   r   r   gccollectr   
unraisable)r   cms     r   test_refloop_unraisablez TestGzip.test_refloop_unraisableI  sI    
 ()RMM"**,SM9JJLbmm, *))s   AA--A6N)r  )<r"   r#   r$   r@   rL   rU   r`   rc   rh   rn   rq   rx   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r,  r6  r>  rC  rF  rJ  rT  rY  r[  rb  re  rl  rp  rs  rv  rz  r  r  r  r  r  r   r   r   r1   r1   ;   s6   /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   r1   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)NrC   rB   rk   r   r   r   rE   r   r   r*   r7   rd  r:   r8   rl   r   r   r)   r   r
  r>   	file_datas       r   test_binary_modeszTestOpen.test_binary_modesU  s   rzYYt}}d+qGGL! ,$--&!1IY5 ' YYt}}d+qQVVX|4 , YYt}}d+qGGL! ,$--&!1IYq(89 ' /IIdmmT* 0'YYt}}d+qGGL! ,$--&!1IY5 '&) ,+&& ,+ ,+&& 0/ ,+&&_   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)NrB   rC   r   rO   )
r   rP   r*   r   r   r7   rE   r8   rR   r:   )r   r*   r>   s      r   test_pathlike_filezTestOpen.test_pathlike_filep  s    %%dmm4YYx&!GGEBJ '/YYx&!GGEN '/YYx AQVVXurz2 !/ '& '& ! s#   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)NrC   r3   rk   r4   rN   r   r   r  r  s       r   test_implicit_binary_modesz#TestOpen.test_implicit_binary_modes|  s   rzYYt}}c*aGGL! +$--&!1IY5 ' YYt}}c*aQVVX|4 + YYt}}c*aGGL! +$--&!1IYq(89 ' /IIdmmS) 0'YYt}}c*aGGL! +$--&!1IY5 '&) +*&& +* +*&& 0/ +*&&r  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  rC   
wtr  rk   rtatr   rE   r  replacerI   linesepr   r   r*   r7   rd  r:   r8   r   r
  uncompressed_rawr>   r  s        r   test_text_modeszTestOpen.test_text_modes  sl   ||G,r1'//bjjAYYt}}dWY=GGL! >$--&!188AIY(89 ' YYt}}dWY=QVVX|4 >YYt}}dWY=GGL! >$--&!188AIY(81(<= '& >=&& >===&&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)NrC   r  r4   rk   r  r  )	rE   r  r   r   r   r   r   r8   r:   )r   uncompressed_bytesuncompressed_strr   r>   s        r   test_fileobjzTestOpen.test_fileobj  s    "RZ-44W=]]#56
YYrzz*-s3qQVVX'9: 4YYrzz*-t4QVVX'9: 5YYrzz*-tgYF!QVVX'78 GF	 4344FFs$   !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xbtrk   zutf-8r  ignore)errorsr  )newline)rl   rm   r   r   r   r*   r   s    r   test_bad_paramszTestOpen.test_bad_params  s   y)IIg *z*IIdmmU+ +z*IIdmmU+ +z*IIdmmTGI< +z*IIdmmT(I; +z*IIdmmT4I8 +* *)**********sG   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  rC   r  r  zutf-16r  rk   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>!QVVX|4 ?> ?>&& ?>s%   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)NrB   s   foobarr  r  r  )r  r  foobar)r   r   r*   r7   r8   r:   rK   s     r   test_encoding_error_handlerz$TestOpen.test_encoding_error_handler  sq    YYt}}d+qGGM" ,YYt}}dWXYNQVVXx0 ON ,+NNs   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  rC   r  r  )r  r  r  )rE   r  r   r   r*   r7   r8   r   )r   r
  r>   s      r   test_newlinezTestOpen.test_newline  s    ||G,r1YYt}}dWdYKqGGL! LYYt}}dWdYKqQ[[]\N; LK LKKKs   B$9"B0$B-0B9N)r"   r#   r$   r  r  r  r  r  r  r  r  r  r   r   r   r  r  T  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   )rI   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)NrB   r   -mr   -dstdinstdoutstderrr   )r   r   r   r6   r7   r;   sys
executabler   r   communicater	  r8   )r   bytes_io	gzip_filer    procouterrs          r   test_decompress_stdin_stdoutz,TestCommandLine.test_decompress_stdin_stdout  s    ZZ\Xxd;y		* < >>45Dt4TBd++H,=,=,?@S C  	c"dii( <; CB \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.gzrB   )r<   r  r   r  testgziprk   r   r   )rI   pathru   TEMPDIRr   existsr   r   r7   r;   r   r8   r:   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:hX]]_dii8 ; 	x01Qc"c" ,+ ;:s   *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'ry   r   )r   r8   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;   r8   )r   r    r  r  r  s        r   test_compress_stdin_outfilez+TestCommandLine.test_compress_stdin_outfile  sr     ~~tV+4tD>$''		2HC ? 	c"Ra+.	 ?>s   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  .gzrB   r  r   r   )rI   r  ru   r  r   r  r   r7   r;   r   r   r8   )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   rB   r  r   r   )r   rI   r  ru   r  r   r  r   r7   r;   r   r   r8   remove)r   r  r  r  r  r  r  r  s           r   test_compress_infile_outfilez,TestCommandLine.test_compress_infile_outfile,  s   2N^<!#gz!B)E1  !9:.$/2HHTYY' 0  0fnn]Cx 89  c*  c*		(#  !9: =< 3 0/ =<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^  r8   r  s       r   %test_compress_fast_best_are_exclusivez5TestCommandLine.test_compress_fast_best_are_exclusive?  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_compressionD  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__rg   r  r  r   rI   r   r  unittest
subprocessr   r   test.supportr   r   r   r   r	   r
   test.support.script_helperr   r   import_moduler   r   rE   r   r  abspathr/   r  r   r   TestCaser&   r1   r  r  r  r"   mainr   r   r   <module>r     s      	 	 	  
  " 3 & " = = N"}""6*"}""6*		 ''//)**
+h
6&2:: &(x   (V-x V-rH<x H<V
[#h'' [#| zHMMO r   