
    6\h\                    L   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ 	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY w	 d dlZn# e$ r dZY nw xY wd
 Zej                             ej!                  dz   Z"e"dz   Z# ej$        d          Z%ej        &                    e"d          Z'ej        &                    e"d          Z(ej        &                    e"d          Z)ej        &                    e"d          Z*ej        &                    e"d          Z+dZ,dZ-dZ. G d d          Z/ ej0                     G d d                      Z1 ej2                     G d d                      Z3 ej4                     G d d                      Z5 G d de/          Z6 G d  d!e6ej7                  Z8 G d" d#e1e8          Z9 G d$ d%e3e8          Z: G d& d'e5e8          Z; G d( d)e6ej7                  Z< G d* d+e1e<          Z= G d, d-e3e<          Z> G d. d/e5e<          Z? G d0 d1e6          Z@ G d2 d3e@          ZA G d4 d5eAej7                  ZB G d6 d7e1eAej7                  ZC G d8 d9e3eAej7                  ZD G d: d;e5eAej7                  ZE G d< d=e@ej7                  ZF G d> d?e1eF          ZG G d@ dAe3eF          ZH G dB dCe5eF          ZI G dD dEe/ej7                  ZJ G dF dGe1eJ          ZK G dH dIe3eJ          ZL G dJ dKe5eJ          ZM G dL dMe1ej7                  ZN G dN dOe6ej7                  ZO G dP dQ          ZP G dR dSePe6ej7                  ZQ G dT dUePe6ej7                  ZR G dV dWe/          ZS G dX dYeSej7                  ZT G dZ d[e1eT          ZU G d\ d]e3eT          ZV G d^ d_e5eT          ZW G d` daeSej7                  ZX G db dce1eX          ZY G dd dee3eX          ZZ G df dge5eX          Z[ G dh diej7                  Z\ G dj dkeSej7                  Z] G dl dmeSej7                  Z^ G dn doe1e^          Z_ G dp dqe3e^          Z` G dr dse5e^          Za G dt due^          Zb ejc         ededv          dw           G dx dyej7                              Ze G dz d{e\          Zf G d| d}          Zg G d~ degej7                  Zh G d degej7                  Zi G d degej7                  Zj G d d          Zk G d dekej7                  Zl G d de1ekej7                  Zm G d de3ekej7                  Zn G d de5ekej7                  Zo G d dej7                  Zp G d dej7                  Zq G d dej7                  Zr G d dej7                  Zs ejt         ededv          d           G d de6ej7                              Zu G d de3ej7                  Zvd Zw ejc         eded          d           ejc         eded          d           G d dej7                                          Zx G d de6ej7                  Zy G d de6          Zz G d dezej7                  Z{ G d dezej7                  Z| G d dezej7                  Z} G d dezej7                  Z~ G d dej7                  Zd Z G d d          Zej        rd Znd Z G d dej7                  Z G d dej        ej7                  Z G d dej7                  Zd Zd Zedk    r ej                     dS dS )    N)sha256)contextmanager)Random)archiver_tests)support)	os_helper)script_helper)warnings_helperc                 D    t          |                                           S N)r   	hexdigest)datas    ;/opt/python-3.11.14/usr/lib/python3.11/test/test_tarfile.py	sha256sumr   *   s    $<<!!###    z-tardirz-extract-testztesttar.tarztesttar.tar.gzztesttar.tar.bz2testtar.tar.xzztmp.tartesttar    @e09e4bc8b3c9d9177e77256353b36c159f5f040531bbd4b024a8f9b9196c71ce@4f05a776071146756345ceee937b33fc5644f5a96b9780d1c7d6a32cdf164d7bc                   R    e Zd ZeZdZej        Zej	        j
        Z
ed             ZdS )TarTest c                      | j         | j        z   S r   )prefixsuffixselfs    r   modezTarTest.modeE   s    {T[((r   N)__name__
__module____qualname__tarnamer   ioFileIOopentarfileTarFiletaropenpropertyr    r   r   r   r   ?   sH        GF9Do%G) ) X) ) )r   r   c                   D    e Zd ZeZdZerej        ndZe	j
        j        ZdS )GzipTestgzN)r    r!   r"   gzipnamer#   r   gzipGzipFiler&   r'   r(   gzopenr)   r+   r   r   r-   r-   I   s2        GF *4==dDo$GGGr   r-   c                   D    e Zd ZeZdZerej        ndZe	j
        j        ZdS )Bz2Testbz2N)r    r!   r"   bz2namer#   r   r5   BZ2Filer&   r'   r(   bz2openr)   r+   r   r   r4   r4   P   s2        GF'3;;4Do%GGGr   r4   c                   D    e Zd ZeZdZerej        ndZe	j
        j        ZdS )LzmaTestxzN)r    r!   r"   xznamer#   r   lzmaLZMAFiler&   r'   r(   xzopenr)   r+   r   r   r:   r:   W   s2        GF *4==dDo$GGGr   r:   c                       e Zd ZdZd Zd ZdS )ReadTestr:c                 R    t          j        | j        | j        d          | _        d S )N	iso8859-1r   encodingr'   r&   r#   r   tarr   s    r   setUpzReadTest.setUpc   s)    <49)46 6 6r   c                 8    | j                                          d S r   )rH   closer   s    r   tearDownzReadTest.tearDowng   s    r   N)r    r!   r"   r   rI   rL   r+   r   r   rA   rA   _   s7        F6 6 6    r   rA   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Z ej         eed          o eed          d          d             ZdS )UstarReadTestc                 l   | j                             d          }| j                             |          5 }|                                }|                     t          |          |j        d           |                     t          |          t          d           d d d            d S # 1 swxY w Y   d S )Nustar/regtyperegular file extraction failed)	rH   	getmemberextractfilereadassertEquallensizer   sha256_regtyper   tarinfofobjr   s       r   test_fileobj_regular_filez'UstarReadTest.test_fileobj_regular_filem   s    ($$_55X!!'** 	6d99;;DSYY46 6 6Yt__n46 6 6		6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   A'B))B-0B-c                    | j                             dt          d           | j                             d          }t	          t
          j                            t          d          d          5 }|                                }d d d            n# 1 swxY w Y   | j         	                    |          5 }t          j        |          }|                                }|                     ||d           |                     t          |          dd           |                     |d         dd           d d d            d S # 1 swxY w Y   d S )	NrP   r   filterrzfileobj.readlines() failedr   S   zOI will gladly admit that Python is not the fastest running scripting language.
)rH   extractTEMPDIRrR   r&   ospathjoin	readlinesrS   r$   TextIOWrapperrU   rV   )r   rZ   fobj1lines1r[   fobj2lines2s          r   test_fileobj_readlinesz$UstarReadTest.test_fileobj_readlinesv   s   '&AAA($$_55"',,w88#>> 	'%__&&F	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' X!!'** 
	2d$T**E__&&FVV02 2 2S[[#02 2 2VBZ402 2 2
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2 
	2s%   0BBB6BEEEc                    | j                             dt          d           | j                             d          }t	          t
          j                            t          d          d          5 }|                                }d d d            n# 1 swxY w Y   | j         	                    |          5 }t          t          j        |                    }|                     ||d           d d d            d S # 1 swxY w Y   d S )NrP   r   r^   r`   zfileobj.__iter__() failed)rH   rc   rd   rR   r&   re   rf   rg   rh   rS   listr$   ri   rU   )r   rZ   rj   rk   rl   rm   s         r   test_fileobj_iterzUstarReadTest.test_fileobj_iter   sc   '&AAA($$_55"',,w88#>> 	'%__&&F	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'X!!'** 	1e"*51122FVV/1 1 1	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s$   0BBB69C<<D D c                    | j                             dt          d           t          t          j                            t          d          d          5 }|                                }d d d            n# 1 swxY w Y   | j                             d          }| j         	                    |          5 }|                                }|
                    d           |                     d|                                d           |
                    dd           |                     d|                                d           |
                    d	d
           |                     d|                                d           |
                    dd
           |                     d|                                d           |                    d          }|                     ||dd         d           |
                    dd           |                     |j        |                                d           |                     |                                dd           |
                    |j         d           |                     d|                                d           |
                    d           |                                }|
                    d           |                                }|                     ||d           |
                    d           |                     t          |                                          |                                d           |
                    d           |                     t          |                                          dz   |                                d           |
                    d           |                                }|                     |                                |t          |          d          d           d d d            d S # 1 swxY w Y   d S )NrP   r   r^   rbr   zseek() to file's start failedi   z"seek() to absolute position failedi       z+seek() to negative relative position failedz+seek() to positive relative position failed
   i
  zread() after seek failed   zseek() to file's end failedr   z0read() at file's end did not return empty stringz$relative seek() to file's end failed   zreadlines() after seek failedztell() after readline() failedz)tell() after seek() and readline() failedzread() after readline() failed)rH   rc   rd   r&   re   rf   rg   rT   rR   rS   seekrU   tellrW   rh   rV   readline)	r   r[   r   rZ   textss1s2lines	            r   test_fileobj_seekzUstarReadTest.test_fileobj_seek   sM   ' & 	 	( 	( 	("',,w88$?? 	499;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ($$_55X!!'** (	;d99;;DIIaLLLQ		8: : :IIdAT499;;=? ? ?IIeQT499;;FH H HIIdAT499;;FH H H		"AQT$Y35 5 5IIaOOOW\499;;68 8 8TYY[[#KM M MIIw|mQ'''Q		?A A AIIcNNN!!BIIcNNN!!BR8: : :IIaLLLS11499;;9; ; ;IIcNNNS11C7DF F FIIaLLL==??DTYY[[$s4yyzz*:9; ; ;O(	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	; (	;s%   A77A;>A;6NQQ
Q
c                    | j                             d          5 }t          j        |          }|                                                    d          }|                     t          |          t                     	 |	                    d           n%# t          $ r |                     d           Y nw xY wd d d            d S # 1 swxY w Y   d S )NrP   rD   d   zseeking failed in text mode)rH   rS   r$   ri   rT   encoderU   r   rX   ry   AttributeErrorfailr   r[   r   s      r   test_fileobj_textzUstarReadTest.test_fileobj_text   s   X!!/22 		9d#D))D99;;%%k22DYt__n===9		#! 9 9 9 		7888889		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9 		9s6   A$C BCB85C7B88CCCc                    | j                             |          5 }| j                             |          5 }|                     |j        |j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r   )rH   rS   rU   name)r   lnktyperegtypeabs        r   _test_fileobj_linkz UstarReadTest._test_fileobj_link   s    X!!'** 	-aX!!'**	-./QVQV,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s4   A;!A#A;#A'	'A;*A'	+A;;A?A?c                 2    |                      dd           d S )Nustar/lnktyperP   r   r   s    r   test_fileobj_link1z UstarReadTest.test_fileobj_link1       AAAAAr   c                 2    |                      dd           d S )N./ustar/linktest2/lnktypeustar/linktest1/regtyper   r   s    r   test_fileobj_link2z UstarReadTest.test_fileobj_link2   *     ; 9	; 	; 	; 	; 	;r   c                 2    |                      dd           d S )Nustar/symtyperP   r   r   s    r   test_fileobj_symlink1z#UstarReadTest.test_fileobj_symlink1   r   r   c                 2    |                      dd           d S )N./ustar/linktest2/symtyper   r   r   s    r   test_fileobj_symlink2z#UstarReadTest.test_fileobj_symlink2   r   r   c                 2    |                      dd           d S )Nsymtype2rP   r   r   s    r   test_issue14160zUstarReadTest.test_issue14160   s    
O<<<<<r   c                 Z    |                      d           |                      d           d S )Nbareaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)add_dir_and_getmemberr   s    r   test_add_dir_getmemberz$UstarReadTest.test_add_dir_getmember   s0    ""5)))""7+++++r   getuidgetgidz'Missing getuid or getgid implementationc           	         d }t          j                    5  t          j        t          d          5 }t          j        |_        	 t          j        |           |	                    ||           t          j
        |           n# t          j
        |           w xY w	 d d d            n# 1 swxY w Y   t          j        t                    5 }|                     |                    |          |                    |dz                        d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                 "    dx| _         | _        | S )Nr   )uidgidrZ   s    r   r_   z3UstarReadTest.add_dir_and_getmember.<locals>.filter   s    (++GK'+Nr   wr^   /)r   temp_cwdr'   r&   tmpnameUSTAR_FORMATformatre   mkdiraddrmdirrU   rR   )r   r   r_   rH   s       r   r   z#UstarReadTest.add_dir_and_getmember   s   	 	 	 !! 	 	gs++ #s$1
#HTNNNGGDG000HTNNNNBHTNNNNN# # # # # # # # # # # # # # # g&& #  MM$''MM$*--                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sq   D3B++B0B+BB+D3+B/	/D32B/	3D3A DD3D	D3"D	#D33D7:D7N)r    r!   r"   r\   rn   rq   r   r   r   r   r   r   r   r   r   unittest
skipUnlesshasattrre   r   r+   r   r   rN   rN   k   s"       6 6 62 2 2$1 1 1/; /; /;b
9 
9 
9- - -
B B B; ; ;B B B; ; ;= = =, , ,
 XX..H772x3H3HBD D D D  r   rN   c                       e Zd ZdS )GzipUstarReadTestNr    r!   r"   r+   r   r   r   r             Dr   r   c                       e Zd ZdS )Bz2UstarReadTestNr   r+   r   r   r   r     r   r   r   c                       e Zd ZdS )LzmaUstarReadTestNr   r+   r   r   r   r     r   r   r   c                   &    e Zd Zd Zd Zd Zd ZdS )ListTestc                 P    t          j        | j        | j                  | _        d S )Nr   rG   r   s    r   rI   zListTest.setUp  s     <49===r   c                 d    t          j        t          j                    dd          }t          j        t
          d|          5   j                            d           d d d            n# 1 swxY w Y   |                                	                                } 
                    d|            
                    d|            
                    d	|            
                    d
|            
                    d|            
                    d|            
                    d|            
                    d|            fd} 
                     |d          |            
                     |d          |            
                     |d          |            
                     |d          |            
                     |d          |                                |d                                d|                                d|           d S )Nascii
newlinestdoutFverbose   ustar/conttype   ustar/regtypes   ustar/lnktypes   ustar/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/1234567/longnames   ./ustar/linktest2/symtypes   ./ustar/linktest2/lnktypes   ustar/dirtype/s   ustar/dirtype-with-size/c                 p    |                      j        j        d          }|                    dd          S )Nsurrogateescaper   backslashreplace)decoderH   rF   r   )r   r}   r   s     r   convz ListTest.test_list.<locals>.conv!  s1    *,=>>A88G%7888r   s   ustar/umlauts-s'   misc/regtype-hpux-signed-chksum-s)   misc/regtype-old-v7-signed-chksum-s   pax/bad-pax-s   pax/hdrcharset-s)   ustar/conttype ?\r?\nustar/regtype ?\r?\ns   link tos   ->)r$   ri   BytesIOr   	swap_attrsysrH   rp   detachgetvalueassertInassertRegexassertNotIn)r   tiooutr   s   `   r   	test_listzListTest.test_list  s   rz||WdCCCsHc22 	) 	)HMM%M(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)jjll##%%'---&,,,&,,,BCHHH2C8882C888'---13777	9 	9 	9 	9 	9 	ddHII3OOOdd ; < <=@	B 	B 	Bdd ; < <=@	B 	B 	Bdd677===dd9::C@@@ 	 7 	8 	8 	8 	S)))$$$$$s   A--A14A1c                 F   t          j        t          j                    dd          }t          j        t
          d|          5  | j                            d           d d d            n# 1 swxY w Y   |                                	                                }| 
                    |d           |                     d|           |                     d	|           |                     d
|           |                     d|           |                     d|           d S )Nr   r   r   r   Tr   s   \?rw-r--r-- tarfile/tarfile\s+7011 \d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ustar/\w+type ?\r?\n\?rw-r--r-- tarfile/tarfile\s+7011 \d{4}-\d\d-\d\d\s+\d\d:\d\d:\d\d ustar/\w+type ?\r?\ns   ustar/symtype -> regtypes1   ./ustar/linktest2/symtype -> ../linktest1/regtypes;   ./ustar/linktest2/lnktype link to ./ustar/linktest1/regtypes	  gnu/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longlink link to gnu/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnames	  pax/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longlink link to pax/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longname)r$   ri   r   r   r   r   rH   rp   r   r   r   r   )r   r   r   s      r   test_list_verbosezListTest.test_list_verbose7  si   rz||WdCCCsHc22 	( 	(HMM$M'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(jjll##%% 	 = 	> 	> 	> 	13777JCPPP 347	9 	9 	9 569	; 	; 	; 569	; 	; 	; 	; 	;s   A,,A03A0c                    t          j        t          j                    dd          }d }t          j        t
          d|          5  | j                            d || j                             d d d            n# 1 swxY w Y   |                                	                                }| 
                    d|           |                     d	|           d S )
Nr   r   r   c              3   R   K   |                                  D ]}d|j        v r|V  d S )Nreg)
getmembersr   )rH   rZ   s     r   membersz+ListTest.test_list_members.<locals>.membersQ  s@      >>++ " "GL((!MMM" "r   r   F)r   r   r   r   )r$   ri   r   r   r   r   rH   rp   r   r   r   r   )r   r   r   r   s       r   test_list_memberszListTest.test_list_membersO  s   rz||WdCCC	" 	" 	" sHc22 	D 	DHMM%1B1BMCCC	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Djjll##%%&,,,*C00000s   +A>>BBN)r    r!   r"   rI   r   r   r   r+   r   r   r   r     sQ        > > >#% #% #%J; ; ;0
1 
1 
1 
1 
1r   r   c                       e Zd ZdS )GzipListTestNr   r+   r   r   r   r   \  r   r   r   c                       e Zd ZdS )Bz2ListTestNr   r+   r   r   r   r   `  r   r   r   c                       e Zd ZdS )LzmaListTestNr   r+   r   r   r   r   d  r   r   r   c                   J    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )CommonReadTestc                 P   t          t          d          5  	 d d d            n# 1 swxY w Y   |                     t          j        t                               |                     t          j        t          j        t                                         t          t          d          5 }|                     t          j        |                     d d d            n# 1 swxY w Y   |                     t          j        t          j        d                               d S )Nwbrs   s   invalid)	r&   r   assertFalser'   
is_tarfilepathlibPathr$   r   r   r[   s     r   test_is_tarfile_erroneousz(CommonReadTest.test_is_tarfile_erroneousj  sj   '4   	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	+G44555 	+GL,A,ABBCCC '4   	7DW/55666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	+BJz,B,BCCDDDDDs   $((.(C""C&)C&c           	      t   |                      t          j        | j                             |                      t          j        t	          j        | j                                       t          | j        d          5 }|                      t          j        |                     d d d            n# 1 swxY w Y   t          | j        d          5 }|                      t          j        t          j        |	                                                               d d d            d S # 1 swxY w Y   d S )Nrs   )

assertTruer'   r   r#   r   r   r&   r$   r   rT   r   s     r   test_is_tarfile_validz$CommonReadTest.test_is_tarfile_valid{  s   *4<88999 	*7<+E+EFFGGG $,%% 	6OOG.t44555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 $,%% 	IOOG.rz$))++/F/FGGHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Is%    (B44B8;B8AD--D14D1c                    t          | j        d          5 }t          j        |           |                     |                                d           d d d            n# 1 swxY w Y   t          | j        d          5 }t          j        |                                          }t          j        |           |                     |                                d           d d d            d S # 1 swxY w Y   d S )Nrs   r   )	r&   r#   r'   r   rU   rz   r$   r   rT   )r   r[   	file_likes      r   test_is_tarfile_keeps_positionz-CommonReadTest.test_is_tarfile_keeps_position  sT    $,%% 	-t$$$TYY[[!,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- $,%% 	2
499;;//Iy)))Y^^--q111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s$   =AA#&A#?A#C//C36C3c                    t          j        t          | j                            dd                    5  	 d d d            n# 1 swxY w Y   	 t          j        t          | j                  }|                                 |                     |                                g            n*# t           j        $ r | 	                    d           Y nw xY w|
                                 d S # |
                                 w xY w)Nr`   r   z&tarfile.open() failed on empty archive)r'   r&   r   r   replacegetnamesassertListEqualr   	ReadErrorr   rK   r   rH   s     r   test_empty_tarfilez!CommonReadTest.test_empty_tarfile  s,   
 \'49#4#4S##>#>?? 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		,w	22CLLNNN   !1!126666   	@ 	@ 	@II>?????	@
 IIKKKKKCIIKKKKs;   AA	A3B* )C* *$CC* CC* *D c                     |                      t          d          5  t          j        d| j                   d d d            d S # 1 swxY w Y   d S )Nxxx)assertRaisesRegexFileNotFoundErrorr'   r&   r   r   s    r   test_non_existent_tarfilez(CommonReadTest.test_non_existent_tarfile  s     ##$5u== 	+ 	+L	***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   AAAc                 .   t          t          d          5  	 d d d            n# 1 swxY w Y   |                     t          j        t          j         t          | j                   |                     t          j        t          j         t                     d S Nr   )r&   r   assertRaisesr'   r  r   r   s    r   test_null_tarfilez CommonReadTest.test_null_tarfile  s     '4   	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	'+W\7DINNN'+W\7CCCCCs   $((c                    t          d                              d          }dD ])}|                     t          d          5 }|                    |dz             t          j        d          }t          |          |_        |                    |	                                           |                    |           d d d            n# 1 swxY w Y   t          j        t          dd	          }	 | 
                    |                                dgd
|z             |                                 # |                                 w xY wd S )Nr   rx   )       ar   ru   foor`   T)r   ignore_zerosz3ignore_zeros=True should have skipped the %r-blocks)r   	randbytesr&   r   writer'   TarInforV   rW   tobufr  r  rK   )r   r   charr[   rZ   rH   s         r   test_ignore_zerosz CommonReadTest.test_ignore_zeros  sm    ayy""3''! 	 	D 7C(( !D

4$;'''!/%00"4yy

7==??+++

4   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ,wStDDDC$$S\\^^eWI   				!	 	s   A=CC	C	4-D77Ec                 R   dD ]"}t          j        t          d          5 }t          j        d          }d|_        |                    |t          j        d                     d d d            n# 1 swxY w Y   t          t          d          5 }|                    |           d d d            n# 1 swxY w Y   t          j        t                    5 }| 	                    t           j
        d          5  |D ]}	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        t                    5 }|                                }| 	                    t           j
        d          5  |                    |t          d	           d d d            n# 1 swxY w Y   | 	                    t           j
        d          5  |                    |                                           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   $d S )
N)rx   iX  ru   i  w:r  ru   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazr+bzunexpected end of datar   r^   )r'   r&   r   r  rW   addfiler$   r   truncater  r  nextrc   rd   rS   rT   )r   rW   rH   tr[   s        r   test_premature_end_of_archivez,CommonReadTest.test_premature_end_of_archive  s   * 	. 	.Dgt,, 8OE**Arz+667778 8 8 8 8 8 8 8 8 8 8 8 8 8 8
 gu%% $d###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ g&& #++G,=?WXX                                 
 g&& .#HHJJ++G,=?WXX ; ;KK76K:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ++G,=?WXX . .OOA&&++---. . . . . . . . . . . . . . .. . . . . . . . . . . . . . .	. 	.s   AA00A4	7A4	B22B6	9B6	!D!7D
>D!
DD!DD!!D%	(D%	5H:F$H$F((H+F(,#H(H7HHH
HHH	!H	c                     |                      t          j        d          5  t          j        t	          j        d                    5 }	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N%file could not be opened successfullyzrecursion.tar)r  r'   r  r&   r   findfiler  s     r   test_length_zero_headerz&CommonReadTest.test_length_zero_header  s     ##G$57^__ 	 	g.??@@ C              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s5   'A.A
A.A	A.A	A..A25A2c                    | j                             d          }| j                             |          5 }|                     t          |j                   |                     |                                d           |                     |                                d           | j	        r!|                     t          |j
                   n(|                     |
                                d           |                     |j        d           d d d            n# 1 swxY w Y   |                     |j        d           |                     t          |j                   |                     |                                d           |                     |                                d           | j	        r"|                     t          |j
                   d S |                     |
                                d           d S )NrP   TF)rH   rR   rS   r  r   filenoassertIsreadablewritable	is_streamseekableclosed)r   filer[   s      r   test_extractfile_attrsz%CommonReadTest.test_extractfile_attrs  s   x!!/22X!!$'' 	.4ndk:::MM$--//4000MM$--//5111~ 5!!.$-@@@@dmmoot444MM$+u---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	dk4(((.$+666dmmoot,,,dmmoou---> 	1ndm<<<<<MM$--//400000s   CDD!$D!N)r    r!   r"   r   r   r   r  r
  r  r  r   r$  r.  r+   r   r   r   r   h  s        E E E"I I I
2 
2 
2  "+ + +D D D  ,. . .0  1 1 1 1 1r   r   c                   ^   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Z ej         eed          d          ej        d                         Zej        d             Zej        d             Zd Zd Zd Zd Z ej         e!du d          d             Z"d Z#dS )MiscReadTestBaseFc                     d S r   r+   r   s    r   requires_name_attributez(MiscReadTestBase.requires_name_attribute  s    r   c                    |                                   t          | j        d          5 }|                     |j        t
                     t          j        || j                  5 }|                     |j        t
                     |                     |j        t          j
                            |j                             d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S Nrs   fileobjr   )r2  r&   r#   assertIsInstancer   strr'   r   rU   re   rf   abspathr   r[   rH   s      r   test_no_name_argumentz&MiscReadTestBase.test_no_name_argument  sk   $$&&&$,%% 	G!!$)S111d;;; Gs%%ch444  27??49+E+EFFFG G G G G G G G G G G G G G G	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs6   <C(&ACC(C	C(C	C((C,/C,c                 ^   t          | j        d          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }|                     t          t          |d           t          j         || j	                  }| 
                    |j                   d S )Nrs   r   r5  )r&   r#   rT   r$   r   r  r   getattrr'   r   assertIsNoner   r   r[   r   rH   s       r   test_no_name_attributez'MiscReadTestBase.test_no_name_attribute  s    $,%% 	99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z$.'4@@@l4di888#(#####s   7;;c                 Z   t          | j        d          5 }|                                }d d d            n# 1 swxY w Y   t          j        |          }d|_        t          j         || j                  5 }|                     |j                   d d d            d S # 1 swxY w Y   d S )Nrs   r   r5  )	r&   r#   rT   r$   r   r   r'   r   r>  r?  s       r   test_empty_name_attributez*MiscReadTestBase.test_empty_name_attribute  s   $,%% 	99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z$	\$TY777 	(3ch'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   7;;8B  B$'B$c                 z   t          j        | j        t           j                  }t          |d          5 }|                     |j        t                     t          j        || j                  5 }| 	                    |j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r4  )
re   r&   r#   O_RDONLYr7  r   intr'   r   r>  )r   fdr[   rH   s       r   test_int_name_attributez(MiscReadTestBase.test_int_name_attribute  s    WT\2;//"d^^ 	,t!!$)S111d;;; ,s!!#(+++, , , , , , , , , , , , , , ,	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s5   <B01BB0B	B0B	 B00B47B4c                    |                                   t          j        | j                  }t	          |d          5 }|                     |j        t                     t          j        || j	                  5 }|                     |j        t                     | 
                    |j        t          j                            |j                             d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r4  )r2  re   fsencoder#   r&   r7  r   bytesr'   r   rU   rf   r9  )r   r#   r[   rH   s       r   test_bytes_name_attributez*MiscReadTestBase.test_bytes_name_attribute'  sz   $$&&&+dl++'4   	GD!!$)U333d;;; Gs%%ch666  27??49+E+EFFFG G G G G G G G G G G G G G G	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs6   <C<:AC$C<$C(	(C<+C(	,C<<D D c           	      <   t          j        | j                  }t          j        || j                  5 }|                     |j        t                     | 	                    |j        t          j                            t          j        |                               d d d            n# 1 swxY w Y   |                     |          5 }|                     |j        t                     | 	                    |j        t          j                            t          j        |                               d d d            n# 1 swxY w Y   t          j                            || j                  5 }|                     |j        t                     | 	                    |j        t          j                            t          j        |                               d d d            n# 1 swxY w Y   | j        dk    rt          j        |d          5 }|                     |j        t                     | 	                    |j        t          j                            t          j        |                               d d d            d S # 1 swxY w Y   d S d S )Nr   r   r`   )r   r   r#   r'   r&   r   r7  r   r8  rU   re   rf   r9  fspathr)   r(   r   )r   r#   rH   s      r   test_pathlike_namez#MiscReadTestBase.test_pathlike_name0  sC   ,t|,,\'	222 	Lc!!#(C000SXrwry7I7I'J'JKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L \\'"" 	Lc!!#(C000SXrwry7I7I'J'JKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L _!!'	!:: 	Lc!!#(C000SXrwry7I7I'J'JKKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L ;"s333 Ps%%ch444  27??29W;M;M+N+NOOOP P P P P P P P P P P P P P P P P P sK   A+B,,B03B0A+EE
E4A+G++G/2G/A+JJJc                 8   t          t          d          5  	 d d d            n# 1 swxY w Y   |                     t          d          5  |                     t          d          }d d d            n# 1 swxY w Y   |                     t          d          5  |                     t          d          }d d d            n# 1 swxY w Y   |                     t          d          5  |                     t          d          }d d d            d S # 1 swxY w Y   d S )Nr   zmode must be qrwr   )r&   r   r  
ValueErrorr)   r  s     r   test_illegal_mode_argz&MiscReadTestBase.test_illegal_mode_arg@  s   '4   	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	##J@@ 	- 	-,,w,,C	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-##J@@ 	. 	.,,w--C	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.##J@@ 	, 	,,,w++C	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,sB   $((
A22A69A6C  CC&DDDc                    t          j        | j        | j                  }	 |                                 |                                }|j        }|j        }|                    |          5 }|                                }d d d            n# 1 swxY w Y   |	                                 n# |	                                 w xY w|                     | j                  5 }|
                    |           |                    | j        d|          5 }|                                }|                     |j        |           |                                 |                     |                    |                                          |d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr   rB   r   r6  zseek back did not work)r'   r&   r#   r   r  r   offsetrS   rT   rK   ry   rU   r   )r   rH   r  r   rV  fr   r[   s           r   test_fileobj_with_offsetz)MiscReadTestBase.test_fileobj_with_offsetJ  sB    l4<di888	HHJJJ

A6DXF##  qvvxx                              IIKKKKCIIKKKK YYt|$$ 	2IIf $,T4@@ 2CHHJJ  ...      !3!3!8!8!:!:D02 2 22 2 2 2 2 2 2 2 2 2 2 2 2 2 2		2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2sg   AB. -BB. BB. BB. .C!3F8B F F8 F$	$F8'F$	(F88F<?F<c                 2   |                      t          j        t          j        t          | j                   t          t          d          5 }|                      t          j        t          j        || j                   d d d            d S # 1 swxY w Y   d S r4  )r  r'   r  r&   r#   r   r   s     r   test_fail_compzMiscReadTestBase.test_fail_compf  s    '+W\7DINNN'4   	<Dg/&*  < < <	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s   3BBBc                     | j                             d          }|                     |j        t          j        d           d S )Nzmisc/dirtype-old-v7zv7 dirtype failed)rH   rR   rU   typer'   DIRTYPEr   rZ   s     r   test_v7_dirtypez MiscReadTestBase.test_v7_dirtypem  sG     ($$%:;;w#	% 	% 	% 	% 	%r   c                     	 | j                             d           d S # t          $ r |                     d           Y d S w xY w)Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))rH   rR   KeyErrorr   r   s    r   test_xstar_typez MiscReadTestBase.test_xstar_typeu  s`    	MH344444 	M 	M 	MIIKLLLLLL	Ms    A Ac                     | j         D ]r}|                     t          |j                  dd|j        z             |j                            d          sN|                     |j        dd|j        z             sd S )N鏽>zwrong mtime for %szustar/r'   zwrong uname for %s)rH   rU   rE  mtimer   
startswithunamer^  s     r   test_check_membersz#MiscReadTestBase.test_check_members~  s    x 	9 	9GS//(7<79 9 9<**844 W]I(7<79 9 9 9	9 	9r   c                 x    |                      | j                                        d         j        dd           d S )Nzmisc/eofzcould not find all members)rU   rH   r   r   r   s    r   test_find_membersz"MiscReadTestBase.test_find_members  sA    ,,..r27,	. 	. 	. 	. 	.r   linkMissing hardlink implementationc                    t          j        t          dd          5 }|                    dt          d           |                     t          j        t          j	        
                    t          d                     |                    dt          d           |                     t          j        t          j	        
                    t          d                     t          t          j	        
                    t          d          d          5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          t                     |                    d	t          d           |                     t          j        t          j	        
                    t          d	                     t          t          j	        
                    t          d	          d          5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          t                     d d d            d S # 1 swxY w Y   d S )
Nrt   rD   )
errorlevelrF   rP   r   r^   r   rs   r   )r'   r&   r#   rc   rd   
addCleanupr   unlinkre   rf   rg   rT   rU   r   rX   )r   rH   rW  r   s       r   test_extract_hardlinkz&MiscReadTestBase.test_extract_hardlink  so   
 \'a+FFF 	>#KKK@@@OOI,bgll7O.T.TUUUKKK@@@OOI,bgll7O.T.TUUUbgll7O<<dCC  qvvxx                             Yt__n===KKK@@@OOI,bgll7O.T.TUUUbgll7O<<dCC  qvvxx                             Yt__n===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s[   C4ID2&I2D6	6I9D6	:B>I8HIH	I H	!+II Ic                 l   t          j        t          d          }t          j                            t          d          }t          j        |           	 d |D             }|                    ||d           |D ]}t          j                            ||j	                  }t          j        dk    r>|                     |j        dz  t          j        |          j        dz  |j	                   d	 }t          j                            |          }d
                     ||j                   ||          |          }|                     |j        ||           	 |                                 t)          j        |           d S # |                                 t)          j        |           w xY w)NrD   rF   
extractallc                 :    g | ]}|                                 |S r+   isdir.0r  s     r   
<listcomp>z4MiscReadTestBase.test_extractall.<locals>.<listcomp>  %    777QWWYY71777r   fully_trustedr^   win32  c                     t          | t                    r(d                    | |                                           S d                    |           S )Nz{} ({})z
{!r} (int))
isinstancefloatr   hex)re  s    r   format_mtimez6MiscReadTestBase.test_extractall.<locals>.format_mtime  sF    !%// :(//uyy{{CCC+225999r   z,tar mtime {0} != file time {1} of path {2!a})r'   r&   r#   re   rf   rg   rd   r   ru  r   r   platformrU   r   statst_modegetmtimer   re  rK   r   rmtree)	r   rH   DIRdirectoriesrZ   rf   r  
file_mtimeerrmsgs	            r   test_extractallz MiscReadTestBase.test_extractall  s    l7[999gll7L11
	"77c777KNN3ONDDD& D Dw||C66<7**$$W\E%9%'WT]]%:U%B%,\3 3 3: : :
  W--d33
GNN L// L,,    
FCCCC#D& IIKKKS!!!!! IIKKKS!!!!s   DF	 	*F3c                    d}t           j                            t          d          }t          j        |           	 t          j        t          d          5 }|                    |          }|	                    ||d           t           j                            ||          }| 
                    t           j                            |          |j                   t          j        dk    r0| 
                    t          j        |          j        dz  d	           d d d            n# 1 swxY w Y   t#          j        |           d S # t#          j        |           w xY w)
Nustar/dirtype
extractdirrD   rt  r}  rf   r_   r~  r  i  )re   rf   rg   rd   r   r'   r&   r#   rR   rc   rU   r  re  r   r  r  r  r   r  r   dirtyper  rH   rZ   	extracteds         r   test_extract_directoryz'MiscReadTestBase.test_extract_directory  sp   !gll7L11
		"g<<< P--00G#oFFFGLLg66	  !1!1)!<!<gmLLL<7**$$RWY%7%7%?%%GOOOP P P P P P P P P P P P P P P S!!!!!IS!!!!s0   E CD*E *D..E 1D.2E E!c                    t          j        t                    dz  }t          j        |          5  t          j        t          d          5 }d |D             }|                    ||d           |D ]D}||j	        z  }| 
                    t          j                            |          |j                   E	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nru  rD   rt  c                 :    g | ]}|                                 |S r+   rw  ry  s     r   r{  zBMiscReadTestBase.test_extractall_pathlike_name.<locals>.<listcomp>  r|  r   r}  r^   )r   r   rd   r   temp_dirr'   r&   r#   ru  r   rU   re   rf   r  re  )r   r  rH   r  rZ   rf   s         r   test_extractall_pathlike_namez.MiscReadTestBase.test_extractall_pathlike_name  s   l7##l2$$ 	H 	H\'K888	H<?77c777KNN3ONDDD& H HW\)  !1!1$!7!7GGGGH		H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs6   CA,C:CC
	
CC
	CC"%C"c                    d}t          j        t                    dz  }t          j        |          5  t          j        t          d          5 }|                    |          }|	                    ||d           ||z  }| 
                    t          j                            |          |j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr  ru  rD   rt  r}  r  )r   r   rd   r   r  r'   r&   r#   rR   rc   rU   re   rf   r  re  r  s         r   test_extract_pathlike_namez+MiscReadTestBase.test_extract_pathlike_name  sv   !l7##l2$$ 	I 	I\'K888	I<?mmG,,GKKc/KBBBgIRW--i88'-HHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	Is6   CA+C:CC
	
CC
	CC"%C"c                 .   t           j                            t          d          }t	          |d          5 }|                    d           d d d            n# 1 swxY w Y   	 t                              t          j	                  }	 |
                    |           |                     d           n4# t          j        $ r" |                     |j        j                   Y nw xY wt!          j        |           d S # t!          j        |           w xY w)Nemptyr   r   zReadError not raised)re   rf   rg   rd   r&   r  object__new__r'   r(   __init__r   r  r   r6  r,  r   rq  )r   r  r[   rH   s       r   test_init_close_fobjz%MiscReadTestBase.test_init_close_fobj  s>    Wg..% 	$JJsOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 			$..11C2U### 		01111 $ 4 4 4 2333334
 U#####IU####sA   AAA$$C> 	B4 C> 4.C%"C> $C%%C> >Dc                 L   t          j        | j                  5 }t          ||          D ]_\  }}|                     |j        |j                   |                     |                                |                                           `	 d d d            d S # 1 swxY w Y   d S r   )r'   r&   r#   ziprU   rV  get_info)r   rH   m1m2s       r   test_parallel_iterationz(MiscReadTestBase.test_parallel_iteration  s     \$,'' 	?3c3-- ? ?B  BI666  >>>>?	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   A1BB BNzrequires zlibc                 8   t           j                            d          5 }t          j        |_        |                     t          j                  5  t          j	        | j
                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nztarfile.TarInfo.fromtarfile)r   mockpatchzliberrorside_effectr  r'   r  r&   r#   )r   r  s     r   test_zlib_error_does_not_leakz.MiscReadTestBase.test_zlib_error_does_not_leak  s    ]  !>?? 	+4#zD""7#455 + +T\***+ + + + + + + + + + + + + + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s5   1BA7+B7A;	;B>A;	?BBBc                 .   t          j                    }t          j        |d          }|                                 |                    d           t          j        |d          5 }|                     |                                d            d d d            n# 1 swxY w Y   |                    d           t          j        |d          5 }|                     |                                d            d d d            d S # 1 swxY w Y   d S )Nr   r5  r   r|r`   )r$   r   r'   r&   rK   ry   rU   r  )r   rF  tfs      r   test_next_on_empty_tarfilez+MiscReadTestBase.test_next_on_empty_tarfile  sg   Z\\\"3///







\"4000 	.BRWWYY---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	


\"3/// 	.2RWWYY---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s$   ))BB"%B")D

DD)$r    r!   r"   r*  r2  r;  r@  rB  rG  rK  rN  rS  rX  rZ  r_  rb  rh  rk  r   r   r   re   r   skip_unless_symlinkrr  skip_unless_working_chmodr  r  r  r  r  r  skipIfr  r  r  r+   r   r   r0  r0    s        I  G G G$ $ $( ( (, , ,G G GP P P , , ,2 2 28< < <% % %M M M9 9 9. . . XV,,:< <"> > #"< <>$ (" " )("> (" " )("H H HI I I$ $ $&? ? ? X_TT\?33+ + 43+. . . . .r   r0  c                       e Zd ZdZdS )MiscReadTestN)r    r!   r"   rZ  r+   r   r   r  r    s        NNNr   r  c                       e Zd ZdS )GzipMiscReadTestNr   r+   r   r   r  r    r   r   r  c                       e Zd Zd ZdS )Bz2MiscReadTestc                 0    |                      d           d S )NzBZ2File have no name attributeskipTestr   s    r   r2  z'Bz2MiscReadTest.requires_name_attribute  s    677777r   Nr    r!   r"   r2  r+   r   r   r  r    s#        8 8 8 8 8r   r  c                       e Zd Zd ZdS )LzmaMiscReadTestc                 0    |                      d           d S )NzLZMAFile have no name attributer  r   s    r   r2  z(LzmaMiscReadTest.requires_name_attribute   s    788888r   Nr  r+   r   r   r  r    s#        9 9 9 9 9r   r  c                   .    e Zd ZdZdZd Zd Zd Zd ZdS )StreamReadTestr  Tc                 6   | j         D ]}|                                s| j                             |          5 }	 	 |                    d          }n*# t          j        $ r |                     d           Y nw xY w|snE	 d d d            n# 1 swxY w Y   d S )NTrx   z6simple read-through using TarFile.extractfile() failed)rH   isregrS   rT   r'   StreamErrorr   )r   rZ   r[   bufs       r   test_read_throughz StreamReadTest.test_read_through)  s    x 	 	G==?? %%g.. $B"iinn". B B B		 #A B B B B BB                 	 	s4   BAB$A96B8A99BB	B	c                 h   | j                                         }| j                             |          5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          |j        d           |                     t          |          t          d           d S )NrQ   )	rH   r  rS   rT   rU   rV   rW   r   rX   rY   s       r   r\   z(StreamReadTest.test_fileobj_regular_file9  s    (--//X!!'** 	d99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	TGL0	2 	2 	24.0	2 	2 	2 	2 	2s   AAAc                     | j                                         }| j                             |d                   5 }|                     t          j        |j                   d d d            d S # 1 swxY w Y   d S Nr   )rH   r   rS   r  r'   r  rT   )r   tarinfosrW  s      r   test_provoke_stream_errorz(StreamReadTest.test_provoke_stream_errorB  s    8&&((X!!(1+.. 	;!g116:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   &A--A14A1c                    t          j        t          d          }	 | j        }	 |                                }|                                }|n|                     |d           |                                s|                                rM|                     t           j	                  5  |
                    |           d d d            n# 1 swxY w Y   |
                    |          }|
                    |          }||                     |d           |                     |                                |                                d           7	 |                                 d S # |                                 w xY w)NrD   rt  Tzstream.next() failed.zstream.extractfile() failedzstream extraction failed)r'   r&   r#   rH   r  assertIsNotNoneislnkissymr  r  rS   rU   rT   rK   )r   tar1tar2t1t2v1v2s          r   test_compare_membersz#StreamReadTest.test_compare_membersG  s   |Gk:::	8D4YY[[YY[[:$$R)@AAA88::  **7+>?? - -((,,,- - - - - - - - - - - - - - -%%b))%%b)):$$R)FGGG  BGGII24 4 4#4   JJLLLLLDJJLLLLs1   BE3 .CE3 CE3 CBE3 3F	N)	r    r!   r"   r   r*  r  r\   r  r  r+   r   r   r  r  $  sZ        FI   2 2 2; ; ;
    r   r  c                       e Zd ZdS )GzipStreamReadTestNr   r+   r   r   r  r  b  r   r   r  c                       e Zd ZdS )Bz2StreamReadTestNr   r+   r   r   r  r  e  r   r   r  c                       e Zd ZdS )LzmaStreamReadTestNr   r+   r   r   r  r  h  r   r   r  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )DetectReadTestc                     	 t          j        ||          }|                                 d S # t           j        $ r}|                                  Y d }~d S d }~ww xY wr   )r'   r&   rK   r  r   )r   r   r   rH   es        r   _testfunc_filezDetectReadTest._testfunc_filem  sh    	,tT**C IIKKKKK   	 	 	IIKKKKKKKKK	s   - AAAc                    	 t          |d          5 }t          j         |||          }d d d            n# 1 swxY w Y   |                                 d S # t          j        $ r}|                                  Y d }~d S d }~ww xY w)Nrs   r6  )r&   r'   rK   r  r   )r   r   r   rW  rH   r  s         r   _testfunc_fileobjz DetectReadTest._testfunc_fileobju  s    	dD!! :Ql4q999: : : : : : : : : : : : : : :
 IIKKKKK   	 	 	IIKKKKKKKKK	s2   A 6A :A :A B&B  Bc                    | j         rX|                     t          j                  5  t          j        t
          d| j         z              d d d            n# 1 swxY w Y   |                     t          j                  5  t          j        t
          d| j         z              d d d            n# 1 swxY w Y   |                     t          j                  5  t          j        | j        d           d d d            n# 1 swxY w Y   |                     t          j                  5  t          j        | j        d           d d d            n# 1 swxY w Y    || j        d            || j        d| j         z               || j        d            || j        d| j         z               || j        d           d S )NrB   r   r  r`   zr:*r|*)r   r  r'   r  r&   r#   )r   testfuncs     r   _test_modeszDetectReadTest._test_modes~  s   ; 	6""7#455 ? ?W4$++=>>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?""7#455 ? ?W4$++=>>>>? ? ? ? ? ? ? ? ? ? ? ? ? ? ?""7#455 6 6T\55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6""7#455 6 6T\55556 6 6 6 6 6 6 6 6 6 6 6 6 6 6s###tdk1222u%%%tdk1222u%%%%%sG   $AAA$B22B69B6DDD.EEEc                 :    |                      | j                   d S r   )r  r  r   s    r   test_detect_filezDetectReadTest.test_detect_file  s    ,-----r   c                 :    |                      | j                   d S r   )r  r  r   s    r   test_detect_fileobjz"DetectReadTest.test_detect_fileobj  s    /00000r   N)r    r!   r"   r  r  r  r  r  r+   r   r   r  r  l  s_            & & & . . .1 1 1 1 1r   r  c                       e Zd ZdS )GzipDetectReadTestNr   r+   r   r   r  r    r   r   r  c                       e Zd Zd ZdS )Bz2DetectReadTestc                 P   t          t          d          5 }|                                }d d d            n# 1 swxY w Y   t          j        t
          dd          5 }|                    |           d d d            n# 1 swxY w Y   |                     t
          d           d S )Nrs   r   rt   compresslevelr  )r&   r#   rT   r5   r7   r   r  r  r   s      r   test_detect_stream_bz2z(Bz2DetectReadTest.test_detect_stream_bz2  s   
 '4   	D99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 [$a888 	DJJt	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	GU+++++s   7;;B  BBN)r    r!   r"   r  r+   r   r   r  r    s#        , , , , ,r   r  c                       e Zd ZdS )LzmaDetectReadTestNr   r+   r   r   r  r    r   r   r  c                       e Zd Z	 d ZdS ) GzipBrokenHeaderCorrectExceptionc                     t          j        d          }|                     t          j                  5  t          j        |d           d d d            d S # 1 swxY w Y   d S )Ns               zr|gzr5  )r$   r   r  r'   r  r&   )r   rW  s     r   runTestz(GzipBrokenHeaderCorrectException.runTest  s    J
 
 w011 	1 	1L0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   AAAN)r    r!   r"   r  r+   r   r   r  r    s(        
1 
1 
1 
1 
1r   r  c                       e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )MemberReadTestNc           	         |p| j                             |          5 }|                     t          |                                          |d|j        z             d d d            n# 1 swxY w Y   d|d<   d|d<   d|d<   d|j        vr
d	|d
<   d	|d<   |                                D ]5\  }}|                     t          ||          |d|d|j                   6d S )Nwrong sha256sum for %srd  re    r   r   r   zold-v7r'   rg  gnamezwrong value in z
 field of )rH   rS   rU   r   rT   r   itemsr=  )r   rZ   chksumkwargsrW  kvs          r   _test_memberzMemberReadTest._test_member  s_   %%g.. A!  16688!4!4f07<?A A AA A A A A A A A A A A A A A A 'wuu7<'''F7O'F7OLLNN 	I 	IDAqWWa00!!78qq',,GI I I I	I 	Is   ?A((A,/A,c                 t    | j                             d          }|                     |dt                     d S )NrP   c  rW   r  rH   rR   r
  rX   r^  s     r   test_find_regtypez MemberReadTest.test_find_regtype  s8    ($$_55'^DDDDDr   c                 t    | j                             d          }|                     |dt                     d S )Nzustar/conttyper  r  r  r^  s     r   test_find_conttypez!MemberReadTest.test_find_conttype  s9    ($$%566'^DDDDDr   c                 h    | j                             d          }|                     |d           d S )Nr  r   rW   rH   rR   r
  r^  s     r   test_find_dirtypez MemberReadTest.test_find_dirtype  s6    ($$_55'*****r   c                 h    | j                             d          }|                     |d           d S )Nzustar/dirtype-with-size   r  r  r^  s     r   test_find_dirtype_with_sizez*MemberReadTest.test_find_dirtype_with_size  s7    ($$%>??',,,,,r   c                 j    | j                             d          }|                     |dd           d S )Nr   r   rP   rW   linknamer  r^  s     r   test_find_lnktypez MemberReadTest.test_find_lnktype  s8    ($$_55'ODDDDDr   c                 j    | j                             d          }|                     |dd           d S )Nr   r   r   r  r  r^  s     r   test_find_symtypez MemberReadTest.test_find_symtype  s8    ($$_55'I>>>>>r   c                 l    | j                             d          }|                     |ddd           d S )Nustar/blktyper      rW   devmajordevminorr  r^  s     r   test_find_blktypez MemberReadTest.test_find_blktype  :    ($$_55'ABBBBBr   c                 l    | j                             d          }|                     |ddd           d S )Nustar/chrtyper   rt   r!  r"  r  r^  s     r   test_find_chrtypez MemberReadTest.test_find_chrtype  r&  r   c                 h    | j                             d          }|                     |d           d S )Nustar/fifotyper   r  r  r^  s     r   test_find_fifotypez!MemberReadTest.test_find_fifotype  s7    ($$%566'*****r   c                 t    | j                             d          }|                     |dt                     d S )Nzustar/sparse P r  rH   rR   r
  sha256_sparser^  s     r   test_find_sparsezMemberReadTest.test_find_sparse  s8    ($$^44'mDDDDDr   c                 t    | j                             d          }|                     |dt                     d S )N
gnu/sparser.  r  r/  r^  s     r   test_find_gnusparsez"MemberReadTest.test_find_gnusparse  s8    ($$\22'mDDDDDr   c                 t    | j                             d          }|                     |dt                     d S )Ngnu/sparse-0.0r.  r  r/  r^  s     r   test_find_gnusparse_00z%MemberReadTest.test_find_gnusparse_00  9    ($$%566'mDDDDDr   c                 t    | j                             d          }|                     |dt                     d S )Ngnu/sparse-0.1r.  r  r/  r^  s     r   test_find_gnusparse_01z%MemberReadTest.test_find_gnusparse_01  r8  r   c                 t    | j                             d          }|                     |dt                     d S )Ngnu/sparse-1.0r.  r  r/  r^  s     r   test_find_gnusparse_10z%MemberReadTest.test_find_gnusparse_10  r8  r   c                 t    | j                             d          }|                     |dt                     d S )Nu   ustar/umlauts-ÄÖÜäöüßr  r  r  r^  s     r   test_find_umlautsz MemberReadTest.test_find_umlauts  sB    ($$ &D E E'^DDDDDr   c                 d    d}|                      || j                                                   d S )Na   ustar/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/1234567/longname)r   rH   r  )r   r   s     r   test_find_ustar_longnamez'MemberReadTest.test_find_ustar_longname  s/    <dDH--//00000r   c                 t    | j                             d          }|                     |dt                     d S )Nzmisc/regtype-old-v7r  r  r  r^  s     r   test_find_regtype_oldv7z&MemberReadTest.test_find_regtype_oldv7  s9    ($$%:;;'^DDDDDr   c                     | j                                          t          j        | j        | j        d          | _         | j                             d          }|                     |dt                     d S )NrD   rE   u   pax/umlauts-ÄÖÜäöüßr  r  )	rH   rK   r'   r&   r#   r   rR   r
  rX   r^  s     r   test_find_pax_umlautsz$MemberReadTest.test_find_pax_umlauts  sw    <49)46 6 6($$ &D E E'^DDDDDr   r   )r    r!   r"   r
  r  r  r  r  r  r  r%  r)  r,  r1  r4  r7  r;  r>  r@  rB  rD  rF  r+   r   r   r   r     sc       I I I I"E E EE E E+ + +- - -E E E? ? ?C C CC C C+ + +E E EE E EE E EE E EE E EE E E
1 1 1E E EE E E E Er   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )LongnameTestc                     | j         dz   dz   dz   }	 | j                            |          }n%# t          $ r |                     d           Y nw xY w|                     |j        t          j        d           d S )Nr     123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamezlongname not foundzread longname as dirtype)	subdirrH   rR   ra  r   assertNotEqualr\  r'   r]  )r   rK  rZ   s      r   test_read_longnamezLongnameTest.test_read_longname  s    ;$|3j@	,h((22GG 	, 	, 	,II*+++++	,GL'/*	, 	, 	, 	, 	,s   - AAc                     | j         dz   dz   dz   }| j         dz   dz   dz   }	 | j                            |          }n%# t          $ r |                     d           Y nw xY w|                     |j        |d           d S )Nr   rJ  rK  longlinkzlonglink not foundzlinkname wrong)rL  rH   rR   ra  r   rU   r  )r   rK  rP  rZ   s       r   test_read_longlinkzLongnameTest.test_read_longlink(  s    ;$|3j@;$|3j@	,h((22GG 	, 	, 	,II*+++++	,)85EFFFFFs   = AAc                    | j         dz   dz   dz   }| j                            |          }|j        }| j        j                            |           t          j        | j        j                            d                    }| 	                    t          j                  5  t          j        d|           d d d            d S # 1 swxY w Y   d S )Nr   rJ  rK  i   zfoo.tar)r   r6  )rL  rH   rR   rV  r6  ry   r$   r   rT   r  r'   r  r&   )r   rK  rZ   rV  r[   s        r   test_truncated_longnamez$LongnameTest.test_truncated_longname1  s    ;$|3j@($$X..f%%%z$(*//8899w011 	7 	7Li6666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   !CC	C	c                    | j         dz   dz   dz   }| j                            |          j        }t	          t
          d          5 }|                    |           t          j        	                    |
                    d          dd          }|                     |j        | j                   d d d            d S # 1 swxY w Y   d S )Nr   rJ  rK  rs   rx   rD   strict)rL  rH   rR   rV  r&   r#   ry   r'   r  frombufrT   rU   r\  longnametype)r   rK  rV  r[   rZ   s        r   test_header_offsetzLongnameTest.test_header_offset:  s     ;$|3j@##H--4'4   	>DIIfo--diinn.98E EGW\4+<===		> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>s   A*B<<C C c           	         d}t          j                    5  t          j        t          d          5 }| j        |_        	 t          j        |           |                    |           t          j	        |
                    d                     n,# t          j	        |
                    d                     w xY w	 d d d            n# 1 swxY w Y   t          j        t                    5 }|                     |                    |                     |                     |                    |                    d                               d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nzfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/r   r   )r   r   r'   r&   r   r   re   r   r   r   rstripr  rR   removesuffix)r   longdirrH   s      r   test_longname_directoryz$LongnameTest.test_longname_directoryE  s(   #!! 
	O 
	Ogs++ 2s![
2HW%%%GGG$$$HW^^C001111BHW^^C00111112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 g&& O#$$S]]7%;%;<<<$$S]]73G3G3L3L%M%MNNNO O O O O O O O O O O O O O O
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	O 
	Osp   E5C	)B((C	)B99C	=E5	C	E5C	E5-A$EE5E!	!E5$E!	%E55E9<E9N)r    r!   r"   rN  rQ  rS  rX  r]  r+   r   r   rH  rH    sg        , , ,G G G7 7 7	> 	> 	>O O O O Or   rH  c                   b    e Zd ZdZej        Zej        Zd Z	d Z
d Zd Zd Zed             ZdS )	GNUReadTestgnuc                    | j                             |t          d           t          j                            t          |          }t          |d          5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          t          d|z             |                                 r9t          j        |          }|                     |j        dz  |j                   d S d S )Nr   r^   rs   r  rx   )rH   rc   rd   re   rf   rg   r&   rT   rU   r   r0  _fs_supports_holesr  
assertLess	st_blocksst_size)r   r   filenamer[   r   r}   s         r   _test_sparse_filezGNUReadTest._test_sparse_filea  s   wv6667<<..(D!! 	T99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	4-(4/	1 	1 	1 ""$$ 	:!!AOOAK#-qy99999	: 	:s   A99A= A=c                 0    |                      d           d S )Nr3  rg  r   s    r   test_sparse_file_oldz GNUReadTest.test_sparse_file_oldm  s    |,,,,,r   c                 0    |                      d           d S )Nr6  ri  r   s    r   test_sparse_file_00zGNUReadTest.test_sparse_file_00p      /00000r   c                 0    |                      d           d S )Nr:  ri  r   s    r   test_sparse_file_01zGNUReadTest.test_sparse_file_01s  rm  r   c                 0    |                      d           d S )Nr=  ri  r   s    r   test_sparse_file_10zGNUReadTest.test_sparse_file_10v  rm  r   c                     t           j                            d          rt          j                            t          d          } t          | d          5 }|                    d           |	                    d           |
                                 d d d            n# 1 swxY w Y   t          j        |           }t          j        |            |j        dz  |j        k     S dS )Nlinuxzsparse-testr   i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrx   F)r   r  rf  re   rf   rg   rd   r&   ry   r  r  r  r   rq  rd  re  )r   r[   r}   s      r   rb  zGNUReadTest._fs_supports_holesy  s     <""7++ 	7<<77DdD!!  T		$

;'''	                             
 AT"""K#%	125s   ?B  B$'B$N)r    r!   r"   rL  r'   GNUTYPE_LONGNAMErW  
GNU_FORMATr   rg  rj  rl  ro  rq  staticmethodrb  r+   r   r   r_  r_  T  s        F+LF
: 
: 
:- - -1 1 11 1 11 1 1   \  r   r_  c                   @    e Zd ZdZej        Zej        Zd Z	d Z
d ZdS )PaxReadTestpaxc                 n   t          j        t          d          }	 |                    d          }|                     |j        d           |                     |j        d           |                     |j                            d          d           |                    d          }|                     |j        d	           |                     |j        d           |                     |j                            d          d           |                    d
          }|                     |j        d           |                     |j        d           |                     |j                            d          d           |	                                 d S # |	                                 w xY w)NrD   rt  pax/regtype1r  r   zVENDOR.umlautsu   ÄÖÜäöüßzpax/regtype2r   zpax/regtype3r'   )
r'   r&   r#   rR   rU   rg  r  pax_headersgetrK   r   rH   rZ   s      r   test_pax_global_headersz#PaxReadTest.test_pax_global_headers  s   l7[999	mmN33GW]E222W]E222W0445EFF;= = = mmN33GW]B///W]E222W0445EFF;= = = mmN33GW]I666W]I666W0445EFF;= = = IIKKKKKCIIKKKKs   E+F F4c                    t          j        t          d          }	 |                    d          }|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           |                     t          |j                  t                     |                     t          |j        d                   d           |                     t          |j        d                   d           |                                 d S # |                                 w xY w)	NrD   rt  zpax/regtype4r  {   g  ^Aatimectime)r'   r&   r#   rR   rU   rW   r   r   re  r\  r  r|  rK   r~  s      r   test_pax_number_fieldsz"PaxReadTest.test_pax_number_fields  s   l7[999
	mmN33GW\4000W[#...W[#...W]L999T'-00%888U7#6w#?@@,OOOU7#6w#?@@,OOOIIKKKKKCIIKKKKs   D
D= =Ec                    d}ddi}|D ]}|                      |          5  t          j        t          dt          j        d          }	 t          j                    }d|_        d	|_        ||_        |	                    |           |
                                 n# |
                                 w xY wt          t          d
          5 }|                                }|                     d|           |                    d|          }d d d            n# 1 swxY w Y   t          t          d          5 }|                                 |                    |           d d d            n# 1 swxY w Y   |                     t          j        d          5  t          j        t          d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )N)
s	    foo=bar
s   0 
s   1 
s   2 
s   3 =
s   4 =a
s   1000000 foo=bar
s
   0 foo=bar
s   -12 foo=bar
s$   000000000000000000000000036 foo=bar
r  r   )headerr   rD   r   rF   ry  rt   rs   s   11 foo=bar
r   z)method tar: ReadError\('invalid header'\)rt  )subTestr'   r&   r   
PAX_FORMATr  r   r   r|  r  rK   rT   r   r   r  r  r  r  )r   pax_header_replacementsr|  replacementrH   r  rW  r   s           r   test_pax_header_bad_formatsz'PaxReadTest.test_pax_header_bad_formats  s   #
 en2 	@ 	@K[11 @ @l7C8J,79 9 9 ))A"AFAE$/AMKKNNNIIKKKKCIIKKKK'4(( FA6688DMM/4888<<EEDF F F F F F F F F F F F F F F
 '4(( "AJJLLLGGDMMM" " " " " " " " " " " " " " " ++G,=?kll @ @L;????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @+@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@s   (G=BGB33GADGDGD G8*E."G.E22G5E26#GG5GGGG	GG	G	N)r    r!   r"   rL  r'   XHDTYPErW  r  r   r  r  r  r+   r   r   rx  rx    sZ        F?LF  .  (@ (@ (@ (@ (@r   rx  c                       e Zd Zd Zd ZdS )WriteTestBasec                    t          j                    }t          j        || j                  5 }|                    t          j        d                     d d d            n# 1 swxY w Y   |                     |j        d           |	                                }~t          j                     |                     |j                   |                     ||	                                           d S )Nr5  r  z#external fileobjs must never closed)r$   r   r'   r&   r   r  r  r   r,  r   r   
gc_collectrU   )r   r[   rH   r   s       r   test_fileobj_no_closez#WriteTestBase.test_fileobj_no_close  s   z||\$TY777 	03KK..///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0&KLLL}}%%%t}}/////s   (A##A'*A'c                 $   t          j        t          | j                  5 }t          j        d          }t           j        t           j        z
  |_        |                    |t          j
        d|j        z                       d d d            n# 1 swxY w Y   |                     t          d          5 }|                     t          |                                          t           j        dz             d d d            d S # 1 swxY w Y   d S )Nr  r  rs   rw   )r'   r&   r   r   r  
RECORDSIZE	BLOCKSIZErW   r  r$   r   rU   rV   rT   )r   rH   r  r[   s       r   test_eof_markerzWriteTestBase.test_eof_marker  sg   
 \'49-- 	6&&A''*;;AFKK2:dQVm44555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 YYw%% 	GS--w/AA/EFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs%   A#BBB5ADD	D	N)r    r!   r"   r  r  r+   r   r   r  r    s7        
0 
0 
0G G G G Gr   r  c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	 e
j         eed          d	          d
             Zej        d             Zd Zd ZddZej        d             Zd Zd Zd Zd ZdS )	WriteTestr  c                    d}t          j        t          | j                  }	 t          j        |          }|                    |           |                                 n# |                                 w xY wt          j        t                    }	 |                     |                                d         |d           |                                 d S # |                                 w xY w)Nd0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r   z!failed to store 100 char filename)	r'   r&   r   r   r  r  rK   rU   r  )r   r   rH   r  s       r   test_100_char_namezWriteTest.test_100_char_name	  s    
 !l7DI..	%%AKKNNNIIKKKKCIIKKKKl7##	S\\^^A.79 9 9 IIKKKKKCIIKKKKs   )A! !A7/C C/c                    t          j        t          | j                  }	 t          j                            t          d          }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   |	                    |           |
                                 n# |
                                 w xY w|                     t          j                            t                    dd           d S )Nr-  r      aaar   ztarfile is empty)r'   r&   r   r   re   rf   rg   rd   r  r   rK   assertGreatergetsize)r   rH   rf   r[   s       r   test_tar_sizezWriteTest.test_tar_size  s
   l7DI..	7<<00DdD!! #T

6"""# # # # # # # # # # # # # # #GGDMMMIIKKKKCIIKKKK27??733Q"	$ 	$ 	$ 	$ 	$s/   5B- A8,B- 8A<<B- ?A< B- -Cc                 v   t          j        t          | j                  }	 t          j                            t          d          }t          |d          5  	 d d d            n# 1 swxY w Y   |                    |          }| 	                    |j
        d           t          |d          5 }|                    d           d d d            n# 1 swxY w Y   |                    |          }| 	                    |j
        d           |                                 d S # |                                 w xY w)Nr-  r   r   r  r!  )r'   r&   r   r   re   rf   rg   rd   
gettarinforU   rW   r  rK   )r   rH   rf   rZ   r[   s        r   test_file_sizezWriteTest.test_file_size+  s   l7DI..	7<<00DdD!!                nnT**GW\1---dD!! #T

6"""# # # # # # # # # # # # # # #nnT**GW\1---IIKKKKKCIIKKKKsT   5D" A$D" $A((D" +A(,AD" /CD" CD" C3D" "D8c                    t           j                            t          d          }t          j        |           	 t          j        t          | j                  }	 |	                    |          }| 
                    |j        d           |                                 n# |                                 w xY w	 t          j        |           d S # t          j        |           w xY w)N	directoryr   )re   rf   rg   rd   r   r'   r&   r   r   r  rU   rW   rK   r   r   r   rf   rH   rZ   s       r   test_directory_sizezWriteTest.test_directory_size;  s    w||G[11
	",w	22C....  q111				OD!!!!!IOD!!!!s#   C 0B  C  B66C C&c                    t           j                            t          d          }t          j        |           t          t           j                            |d          d                                           t          t           j                            |d          d                                           	 t          j        t          | j	                  }	 t          j                            d          5 }ddg|_        |                    |           d d d            n# 1 swxY w Y   g }|                                D ]?}|                    t           j                            |j                  d                    @|                     |g d           |                                 n# |                                 w xY w	 t)          j        t           j                            |d                     t)          j        t           j                            |d                     t)          j        |           d S # t)          j        t           j                            |d                     t)          j        t           j                            |d                     t)          j        |           w xY w)Nr  1r   2z
os.listdirrj  )r  r  r  )re   rf   rg   rd   r   r&   rK   r'   r   r   r   r  r  return_valuer   r   appendsplitr   rU   r   rq  r   )r   rf   rH   mock_listdirpathsms         r   test_ordered_recursionz WriteTest.test_ordered_recursionJ  sY   w||G[11
RW\\$$$c**00222RW\\$$$c**00222	",w	22C	]((66 ",14c
L-GGDMMM" " " " " " " " " " " " " " " )) < <ALLqv!6!6r!:;;;;  (?(?(?@@@				RW\\$44555RW\\$44555OD!!!!! RW\\$44555RW\\$44555OD!!!!sJ   ;I F3 :D%F3 %D))F3 ,D)-A1F3 I 3G		I A:Kc                 V   t          j        t          | j                  5 }t	          j        t                    dz  }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   |                    |          }|                    t          j
        |                    }|                     |j        t                     |                     |j        |j                   |                     |j        d           d d d            d S # 1 swxY w Y   d S )Nr-  r   r  r!  )r'   r&   r   r   r   r   rd   r  r  re   rM  r7  r   r8  rU   rW   )r   rH   rf   r[   rZ   tarinfo2s         r   test_gettarinfo_pathlike_namez'WriteTest.test_gettarinfo_pathlike_name`  ss   \'49-- 	.<((61DdD!! #T

6"""# # # # # # # # # # # # # # #nnT**G~~bioo66H!!',444W\8=999W\1---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s6   -DA/#D/A3	3D6A3	7BDD"%D"rl  rm  c                 t   t           j                            t          d          }t           j                            t          d          }t	          |d          5 }|                    d           d d d            n# 1 swxY w Y   	 t          j        ||           n/# t          $ r"}|                     d|z             Y d }~nd }~ww xY w	 t          j        t          | j                  }	 |                    |           |                    |          }|                     |j        d           |                                 n# |                                 w xY w	 t!          j        |           t!          j        |           d S # t!          j        |           t!          j        |           w xY w)Nrl  link_targetr   r  os.link(): %sr   )re   rf   rg   rd   r&   r  rl  PermissionErrorr  r'   r   r   r  rU   rW   rK   r   rq  )r   rl  targetr[   r  rH   rZ   s          r   test_link_sizezWriteTest.test_link_sizek  s    w||GV,,g}55&$ 	4JJv	 	 	 	 	 	 	 	 	 	 	 	 	 	 		/GFD!!!! 	/ 	/ 	/MM/A-........	/	#,w	22Cv&&&....  q111				V$$$T""""" V$$$T""""sO   A==BB	B 
C)CCF /AE	 4F 	EF *F7c                    t           j                            t          d          }t          j        d|           	 t          j        t          | j                  }	 |	                    |          }| 
                    |j        d           |                                 n# |                                 w xY w	 t          j        |           d S # t          j        |           w xY w)Nsymlinkr  r   )re   rf   rg   rd   r  r'   r&   r   r   r  rU   rW   rK   r   rq  r  s       r   test_symlink_sizezWriteTest.test_symlink_size  s    w||GY//

=$'''	#,w	22C....  q111				T"""""IT""""s#   C 0B! C !B77C C'c                 z   t           j                            t                    }t	          j        t          | j                  }	 |                     |j        |d           |	                    |           |                     |
                                g d           t          j        t                    5  |	                    |           d d d            n# 1 swxY w Y   |                     |
                                g d           |                                 d S # |                                 w xY w)Nzarchive name must be absolutezadded the archive to itself)re   rf   r9  r   r'   r&   r   rU   r   r   r  r   
change_cwdrd   rK   )r   dstnamerH   s      r   test_add_selfzWriteTest.test_add_self  sM   '//'**l7DI..	SXw35 5 5GGGS\\^^R13 3 3 %g.. ! !   ! ! ! ! ! ! ! ! ! ! ! ! ! ! !S\\^^R13 3 3 IIKKKKKCIIKKKKs1   A3D$ 8CD$ CD$ !C",D$ $D:c                 &   t           j                            t          d          }t          j        |           	 dD ]6}t           j                            ||          }t          j        |           7d }t          j        t          | j
        d          }	 |                    |d|           |                                 n# |                                 w xY w|                     t                    5  |                    |ddd |           d d d            n# 1 swxY w Y   t          j        t          d	          }	 |D ]8}|                     |j        d
           |                     |j        d           9|                     t%          |                                          d           |                                 n# |                                 w xY w	 t          j        |           d S # t          j        |           w xY w)Nr_   )r  r   bazc                 v    t           j                            | j                  dk    rd S d| _        d| _        | S )Nr   r  r  )re   rf   basenamer   r   rg  r   s    r   r_   z%WriteTest.test_filter.<locals>.filter  s7    7##GL11U::F! %r   rD   rt  	empty_dir)arcnamer_   Tr`   r  r  r!  )re   rf   rg   rd   r   r   create_empty_filer'   r&   r   r   r   rK   r  	TypeErrorrU   r   rg  rV   r   r  )r   tempdirr   r_   rH   rZ   s         r   test_filterzWriteTest.test_filter  s4   ',,w11
	&- 2 2w||GT22+D1111   ,w	KHHHCVDDD				 ""9-- B BdD&AAAB B B B B B B B B B B B B B B ,w,,C" ; ;G$$W[#666$$W]E::::  S^^%5%5!6!6:::				W%%%%%IW%%%%sa   AG: C 1G: CG: 9DG: D##G: &D#'G: A0G
 5G: 
G  G: :HNFc                    t           j                            t          d          }|st	          j        |           nt          j        |           t          j        t          | j
                  }	 |                    ||           |                                 n# |                                 w xY wt          j        t          d          }	 |                                }|                                 n# |                                 w xY w|st	          j        |           nt	          j        |           |                     |j        |p|                    t           j        d                     d S )Nr  r  r`   r   )re   rf   rg   rd   r   r  r   r'   r&   r   r   r   rK   r  rq  r   rU   r   r   sep)r   rf   cmp_pathdirr  rH   r  s          r   _test_pathnamezWriteTest._test_pathname  s4    gll7E** 	',,,,HSMMMl7DI..	GGCG&&&IIKKKKCIIKKKKl7C((	

AIIKKKKCIIKKKK 	!S!!!!OC   !FT\\"&#-F-FGGGGGs   1B B3C: :Dc                     t           j                            t          d          }t           j                            t          d          }t          j        |           	 t           j                            |d          }t           j                            |d          }t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t          j        ||           t          j        |d          5 }|	                    |d           |	                    |d           d d d            n# 1 swxY w Y   t          j        |d	          5 }	 |
                    |d
           n%# t          $ r |                     d           Y nw xY wd d d            n# 1 swxY w Y   t          j        |           t          j        |           d S # t          j        |           t          j        |           w xY w)Ntestsymlinksztestsymlinks.tarsourcer  r   z
something
r  rw   ro  r}  r  z&extractall failed with symlinked files)re   rf   rg   rd   r   r&   r  r  r'   r   ru  OSErrorr   r   rq  r  )r   r  temparchivesource_filetarget_filerW  rH   s          r   test_extractall_symlinksz"WriteTest.test_extractall_symlinks  s    ',,w77gll7,>??
	&',,wx88K',,wy99Kk#&& '!&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 'J{K000k3// 83X666Y7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ka888 HCHNN*9 # ; ; ; ; H H HIIFGGGGGHH H H H H H H H H H H H H H H [)))W%%%%% [)))W%%%%s    AG# 0CG# CG# C-G# /E6G# EG# 	E
G# #F.%E=<F.=FF.FF."G# .F22G# 5F26G# #*Hc                 v   |                      d           |                      t          j                            ddd                     |                      t          j                            ddd                     |                      t          j                            dd                     |                      t          j                            ddd                     |                      t          j                            dddd                     |                      t          j                            dddd                     |                      t          j                            dddd                     |                      t          j                            dd                     |                      t          j                            ddd                     |                      t          j                            dddd                     |                      t          j                            dddd                     |                      dt          j        z   t          j        z   dz              |                      dt          j        z   t          j        z   dd           d S )Nr  .r   ..T)r  )r  re   rf   rg   r  r   s    r   test_pathnameszWriteTest.test_pathnames  s   E"""BGLLU;;<<<BGLLe<<===BGLLe44555BGLLeS99:::BGLLeS%@@AAABGLLeT5AABBBBGLLeT5AABBBBGLLu55666BGLLud;;<<<BGLLuc5AABBBBGLLudEBBCCCEBFNRV3e;<<<EBFNRV3UEEEEEr   c                     t           j        dk    r|                     dd           d S |                     dd           |                     dd           d S )Nr~  zC:\foor  z/fooz///foo)r   r  r  r   s    r   test_abs_pathnameszWriteTest.test_abs_pathnames  s]    <7""	511111...%00000r   c                 L   t          j        t                    5  t          j        t
          | j                  }	 |                    d           |                                 n# |                                 w xY wt          j        t
          d          }	 |D ]@}|j	        dk    r3| 
                    |j	                            d          |j	                   A	 |                                 n# |                                 w xY w	 d d d            d S # 1 swxY w Y   d S )Nr  r`   ./)r   r  rd   r'   r&   r   r   r   rK   r   r   rf  r   rH   r  s      r   test_cwdzWriteTest.test_cwd  sC   !'** 	 	,w	22C				,w,,C I IAv}}(9(9$(?(?HHHI 					 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sA    DA%D%A;;DAC2D2DDD Dc           
      j   t           t          t          fD ] G fddt          j                  } |            }|                               5  t          j        t          | j	        |t          j
        ddi          }d d d            n# 1 swxY w Y   |                     |j                   d S )Nc                       e Zd ZdZ fdZdS )8WriteTest.test_open_nonwritable_fileobj.<locals>.BadFileTc                 (    | j         r	d| _         d S NF)first)r   r   exctypes     r   r  z>WriteTest.test_open_nonwritable_fileobj.<locals>.BadFile.write0  s#    z &%*
%& &r   N)r    r!   r"   r  r  )r  s   r   BadFiler  .  s3        & & & & & & &r   r  nonr  )r6  r   r|  )r  EOFErrorRuntimeErrorr$   r   r  r'   r&   r   r   r  r   r,  )r   r  rW  rH   r  s       @r   test_open_nonwritable_fileobjz'WriteTest.test_open_nonwritable_fileobj,  s*   ,6 	' 	'G& & & & & & &"* & & & 		A""7++ A Al7DIq*1*<05w/?A A AA A A A A A A A A A A A A A A QX&&&&	' 	's   0BB	B	r  )r    r!   r"   r   r  r  r  r  r  r  r   r   r   re   r  r   r  r  r  r  r  r  r  r  r  r  r+   r   r   r  r    se       F  ($ $ $   " " "" " ",	. 	. 	. XV,,:< <# #< <#, "# # #"#  $"& "& "&PH H H H: "& & #"&4F F F"1 1 1  "' ' ' ' 'r   r  c                       e Zd ZdS )GzipWriteTestNr   r+   r   r   r  r  =  r   r   r  c                       e Zd ZdS )Bz2WriteTestNr   r+   r   r   r  r  A  r   r   r  c                       e Zd ZdS )LzmaWriteTestNr   r+   r   r   r  r  E  r   r   r  c                       e Zd ZdZdZd Z ej        ej	        dk    o e
ed          d           ej        ej        pej        d          d                         ZdS )	StreamWriteTestzw|Nc                 z   t          j        t          | j                  }|                                 | j        r|                                 }t          t          d          5 }|                                }d d d            n# 1 swxY w Y   |                    |          }|                     |j	        d           nF|                     t                    5 }|                                }d d d            n# 1 swxY w Y   | 
                    |                    d          t           j        d           d S )Nrs   zfound trailing datar  zincorrect zero padding)r'   r&   r   r   rK   decompressorrT   
decompressr   unused_datarU   countr  )r   rH   decr[   r   s        r   test_stream_paddingz#StreamWriteTest.test_stream_paddingN  s   l7DI..		 	###%%Cgt$$ #yy{{# # # # # # # # # # # # # # #>>$''DS_.CDDDD7## #tyy{{# # # # # # # # # # # # # # #E**G,>0	2 	2 	2 	2 	2s$   $BB	B	C<<D D r~  umaskzMissing umask implementationz$Emscripten's/WASI's umask is a stub.c                    t           j                            t                    rt	          j        t                     t          j        d          }	 t          j        t          | j	                  }|
                                 t          j        t                    j        dz  }|                     |dd           t          j        |           d S # t          j        |           w xY w)N   r  i  zwrong file permissions)re   rf   existsr   r   rq  r   r'   r&   r   rK   r  r  rU   )r   original_umaskrH   r   s       r   test_file_modezStreamWriteTest.test_file_mode^  s     7>>'"" 	&W%%%%	%,w	22CIIKKK77##+e3DT5*BCCCH^$$$$$BH^$$$$s   A+C C*)r    r!   r"   r   r  r  r   r   r   r  r   re   r  r   is_emscriptenis_wasir  r+   r   r   r  r  I  s        FL2 2 2  X0IWWR5I5I79 9X_0. % %	 9 9% % %r   r  c                       e Zd Zd ZdS )GzipStreamWriteTestc                     	 t          j        t          | j                                                   t          j        t                                        d          }d S )Nzlatin-1rt  )r'   r&   r   r   rK   r   r   	read_text)r   payloads     r    test_source_directory_not_leakedz4GzipStreamWriteTest.test_source_directory_not_leakedu  sM    	 	Wdi((..000,w''1191EEr   N)r    r!   r"   r  r+   r   r   r	  r	  t  s#        7 7 7 7 7r   r	  c                   $    e Zd Zerej        ndZdS )Bz2StreamWriteTestN)r    r!   r"   r5   BZ2Decompressorr  r+   r   r   r  r    s         *-73&&4LLLr   r  c                   $    e Zd Zerej        ndZdS )LzmaStreamWriteTestN)r    r!   r"   r=   LZMADecompressorr  r+   r   r   r  r    s         ,0:4((dLLLr   r  c                   Z    e Zd Zd ZddZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd ZdS )GNUWriteTestc                 6    t          |          dz  dz   }|dz  S )Nrx   rt   )rV   )r   r}   blockss      r   _lengthzGNUWriteTest._length  s     Q3"|r   Nc                     d}t          |          t          j        k    r|dz  }||                     |          z  }|:t          |          t          j        k    r|dz  }||                     |          z  }|S )Nrx   )rV   r'   LENGTH_NAMEr  LENGTH_LINK)r   r   rl  r  s       r   
_calc_sizezGNUWriteTest._calc_size  sw    t99w***SLET\\$'''ED		G,? ? ?SLET\\$'''Er   c                    t          j        |          }|r||_        t           j        |_        t          j        t          d          }	 t           j        |_        |	                    |           | 
                    ||          }|j        }|                     ||d           |                                 n# |                                 w xY wt          j        t                    }	 |                                }|                     |d           |                     |j        |j        d           |                     |j        |j        d           |                                 d S # |                                 w xY w)Nr   z%GNU longname/longlink creation failedzunable to read longname member)r'   r  r  LNKTYPEr\  r&   r   ru  r   r  r  rV  rU   rK   r  r  r   )r   r   rl  rZ   rH   r  r  members           r   _testzGNUWriteTest._test  sZ   /$'' 	+#G"?GLl7C((	 +CJKK   t,,BBR%LMMMIIKKKKCIIKKKKl7##		XXZZF  46 6 6W\6;46 6 6W-v46 6 6 IIKKKKKCIIKKKKs   
AB9 9C,A,E. .Fc                 0    |                      d           d S )N  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnamr   r   s    r   test_longname_1023zGNUWriteTest.test_longname_1023  s    

122222r   c                 0    |                      d           d S )N   longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnamer#  r   s    r   test_longname_1024zGNUWriteTest.test_longname_1024  s    

233333r   c                 0    |                      d           d S )N  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longname_r#  r   s    r   test_longname_1025zGNUWriteTest.test_longname_1025  s    

344444r   c                 2    |                      dd           d S )Nr     longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnkr#  r   s    r   test_longlink_1023zGNUWriteTest.test_longlink_1023  s    

69:::::r   c                 2    |                      dd           d S )Nr      longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlinkr#  r   s    r   test_longlink_1024zGNUWriteTest.test_longlink_1024  s    

6:;;;;;r   c                 2    |                      dd           d S )Nr     longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink_r#  r   s    r   test_longlink_1025zGNUWriteTest.test_longlink_1025  s    

6;<<<<<r   c                 2    |                      dd           d S )Nr"  r,  r#  r   s    r   test_longnamelink_1023z#GNUWriteTest.test_longnamelink_1023  s(    

11	3 	3 	3 	3 	3r   c                 2    |                      dd           d S )Nr&  r/  r#  r   s    r   test_longnamelink_1024z#GNUWriteTest.test_longnamelink_1024  s(    

22	4 	4 	4 	4 	4r   c                 2    |                      dd           d S )Nr)  r2  r#  r   s    r   test_longnamelink_1025z#GNUWriteTest.test_longnamelink_1025  s(    

33	5 	5 	5 	5 	5r   r   )r    r!   r"   r  r  r   r$  r'  r*  r-  r0  r3  r5  r7  r9  r+   r   r   r  r    s                :3 3 34 4 45 5 5; ; ;< < <= = =3 3 34 4 45 5 5 5 5r   r  c                       e Zd ZdZd ZdS )DeviceHeaderTestr  c                 |   t           j                            t          d          }t          j        |           	 t          j        t          | j                  }	 t          j	        d          }t          j	        d          }t
          j
        |_        t
          j        |_        |                    |           |                    |           |                                 n# |                                 w xY wt          j        t          d          }	 |                    d          }|                    d          }|                                 n# |                                 w xY w|                     |j        d           |                     |j        d           |                     |j        d           |                     |j        d           t          t          d          5 }|                                }d d d            n# 1 swxY w Y   ||j        |j                 }	||j        |j                 }
t-          dd	          }|                     |	|         d
           |                     |
|         d           t/          j        |           d S # t/          j        |           w xY w)Ndevice_header_testmy_block_devicer   my_regular_filer`   r   rs   iI  iY  s   0000000 0000000 s                   )re   rf   rg   rd   r   r'   r&   r   r   r  BLKTYPEr\  REGTYPEr  rK   rR   rU   r#  r$  rT   rV  offset_dataslicer   r  )r   r  rH   	input_blk	input_reg
output_blk
output_reginfiler  buf_blkbuf_regdevice_headerss               r   *test_headers_written_only_for_device_filesz;DeviceHeaderTest.test_headers_written_only_for_device_files  s   ',,w(<==
#	&,w	22C#O1BCCC	#O1BCCC	!(	!(	I&&&I&&&				 ,w,,C ]]+<==
 ]]+<==
				Z0!444Z0!444Z0!444Z0!444 gt$$ $kkmm$ $ $ $ $ $ $ $ $ $ $ $ $ $ $*+J,BBCG*+J,BBCG #311NW^46FGGGW^4jAAAW%%%%%IW%%%%sb   J% A6C& J% &C<<J% *E J% E//BJ% 3HJ% HJ% HA3J% %J;N)r    r!   r"   r   rM  r+   r   r   r;  r;    s(        F'& '& '& '& '&r   r;  c                       e Zd ZdZej                            ed          Zd Z	e
d             Ze
d             Zd Zd Zd Zd	 Zd
 Zd ZdS )
CreateTestzx:
spameggs42c                 8    t          j        t                     d S r   )r   rq  r   r   s    r   rI   zCreateTest.setUp  s    !!!!!r   c                     t          | j        d          5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nr   r  )r&   	file_pathr  )clsr[   s     r   
setUpClasszCreateTest.setUpClass  s    #-&& 	$JJv	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   9= =c                 8    t          j        | j                   d S r   )r   rq  rS  rT  s    r   tearDownClasszCreateTest.tearDownClass  s    '''''r   c                    t          j        t          | j                  5 }|                    | j                   d d d            n# 1 swxY w Y   |                     t                    5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          d           | 
                    d|d                    d S Nrt   rP  r   )r'   r&   r   r   r   rS  r)   r  rU   rV   r   r   tobjnamess      r   test_createzCreateTest.test_create  s)   \'49-- 	%HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% \\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----s#   AAA,BBBc                 T   t          j        t          | j                  5 }|                    | j                   d d d            n# 1 swxY w Y   |                     t                    5  t          j        t          | j                  }d d d            n# 1 swxY w Y   |                     t                    5 }|	                                }d d d            n# 1 swxY w Y   | 
                    t          |          d           |                     d|d                    d S r[  )r'   r&   r   r   r   rS  r  FileExistsErrorr)   r  rU   rV   r   r\  s      r   test_create_existingzCreateTest.test_create_existing!  s   \'49-- 	%HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% // 	4 	4<33D	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 \\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----s5   AAA, BBB=CC"%C"c                    |                      t          d          5 }|                    | j                   d d d            n# 1 swxY w Y   |                      t                    5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          d           |                     d|d                    d S Nxrt   rP  r   )r)   r   r   rS  r  rU   rV   r   r\  s      r   test_create_taropenzCreateTest.test_create_taropen-  s)   \\'3'' 	%4HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% \\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----s#   AA
A(B		BBc                 v   |                      t          d          5 }|                    | j                   d d d            n# 1 swxY w Y   |                     t
                    5  |                      t          d          5  	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                      t                    5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          d           | 	                    d|d                    d S rd  )
r)   r   r   rS  r  ra  r  rU   rV   r   r\  s      r   test_create_existing_taropenz'CreateTest.test_create_existing_taropen6  s    \\'3'' 	%4HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% // 	 	gs++                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 \\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----sY   AA
A(B)BB)B	B)B	B))B-0B-C//C36C3c                 Z   t          j        t          j        t                    | j                  5 }|                     |j        t                     | 	                    |j        t          j                            t                               |                    t          j        | j                             |                                }d d d            n# 1 swxY w Y   | 	                    t!          |          d           |                     d|d                    |                     t                    5 }|                                }d d d            n# 1 swxY w Y   | 	                    t!          |          d           |                     d|d                    d S r[  )r'   r&   r   r   r   r   r7  r   r8  rU   re   rf   r9  r   rS  r  rV   r   r)   r\  s      r   test_create_pathlike_namez$CreateTest.test_create_pathlike_nameC  s   \',w//;; 	$t!!$)S111TY(@(@AAAHHW\$.11222MMOOE		$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
 	UQ'''lE!H---\\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----s$   BCC #C  E!!E%(E%c                 R   |                      t          j        t                    d          5 }|                     |j        t                     |                     |j        t          j	        
                    t                               |                    t          j        | j                             |                                }d d d            n# 1 swxY w Y   |                     t          |          d           |                     d|d                    |                      t                    5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          d           |                     d|d                    d S rd  )r)   r   r   r   r7  r   r8  rU   re   rf   r9  r   rS  r  rV   r   r\  s      r   !test_create_taropen_pathlike_namez,CreateTest.test_create_taropen_pathlike_nameQ  s   \\',w//55 	$!!$)S111TY(@(@AAAHHW\$.11222MMOOE		$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
 	UQ'''lE!H---\\'"" 	$dMMOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$UQ'''lE!H-----s$   BCCC<EE!$E!N)r    r!   r"   r   re   rf   rg   rd   rS  rI   classmethodrU  rY  r_  rb  rf  rh  rj  rl  r+   r   r   rO  rO    s        FWl33I" " "   [ ( ( [(. . .
. 
. 
.. . .. . .. . .. . . . .r   rO  c                       e Zd Zd ZdS )GzipCreateTestc                    t          j        t          | j        d          5 }|                    | j                   d d d            n# 1 swxY w Y   t          j        t          dd          5 }	 d d d            d S # 1 swxY w Y   d S )Nrt   r  zr:gzr'   r&   r   r   r   rS  r   r]  s     r   test_create_with_compresslevelz-GzipCreateTest.test_create_with_compresslevelb  s    \'49A>>> 	%$HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%\'6;;; 	t	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#   A		AA0A??BBNr    r!   r"   rs  r+   r   r   ro  ro  `  #            r   ro  c                       e Zd Zd ZdS )Bz2CreateTestc                    t          j        t          | j        d          5 }|                    | j                   d d d            n# 1 swxY w Y   t          j        t          dd          5 }	 d d d            d S # 1 swxY w Y   d S )Nrt   r  r:bz2rq  rr  s     r   rs  z,Bz2CreateTest.test_create_with_compresslevelk  s    \'49A>>> 	%$HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%\'7!<<< 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rt  Nru  r+   r   r   rx  rx  i  rv  r   rx  c                       e Zd Zd ZdS )LzmaCreateTestc                     t          j        t          | j        d          5 }|                    | j                   d d d            d S # 1 swxY w Y   d S )Nrt   )presetrq  rr  s     r   test_create_with_presetz&LzmaCreateTest.test_create_with_presetv  s    \'49Q777 	%4HHT^$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   A

AAN)r    r!   r"   r  r+   r   r   r|  r|  r  s#        % % % % %r   r|  c                       e Zd ZdZdZdZdS )CreateWithXModeTestre  N)r    r!   r"   r   rf  rh  r+   r   r   r  r  {  s!        F#'   r   r  rl  rm  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )HardlinkTestc                 N   t           j                            t          d          | _        t           j                            t          d          | _        t          | j        d          5 }|                    d           d d d            n# 1 swxY w Y   	 t          j        | j        | j                   n/# t          $ r"}| 
                    d|z             Y d }~nd }~ww xY wt          j        t          d          | _        | j                            | j                   d S )Nr  r   r      foor  r   )re   rf   rg   rd   r  r   r&   r  rl  r  r  r'   r   rH   r   )r   r[   r  s      r   rI   zHardlinkTest.setUp  s:   7<<//7<<//$(D!! 	TJJv	 	 	 	 	 	 	 	 	 	 	 	 	 	 		/GDHdh'''' 	/ 	/ 	/MM/A-........	/ <--TXs*   *BBBB8 8
C$CC$c                     | j                                          t          j        | j                   t          j        | j                   d S r   )rH   rK   r   rq  r  r   r   s    r   rL   zHardlinkTest.tearDown  s@    """"""""r   c                     | j                             | j                  }|                     |j        t
          j        d           d S )Nzadd file as regular failed)rH   r  r  rU   r\  r'   rB  r^  s     r   test_add_twicezHardlinkTest.test_add_twice  sH     (%%dh//w,	. 	. 	. 	. 	.r   c                     | j                             | j                  }|                     |j        t
          j        d           d S )Nzadd file as hardlink failed)rH   r  r   rU   r\  r'   r  r^  s     r   test_add_hardlinkzHardlinkTest.test_add_hardlink  sF    (%%dh//w-	/ 	/ 	/ 	/ 	/r   c                     d| j         _        | j                             | j                  }|                     |j        t          j        d           d S )NTzdereferencing hardlink failed)rH   dereferencer  r   rU   r\  r'   rB  r^  s     r   test_dereference_hardlinkz&HardlinkTest.test_dereference_hardlink  sP    #(%%dh//w/	1 	1 	1 	1 	1r   N)r    r!   r"   rI   rL   r  r  r  r+   r   r   r  r    s_          # # #
. . ./ / /
1 1 1 1 1r   r  c                   (    e Zd ZddZd Zd Zd ZdS )PaxWriteTestNc                    t          j        |          }|r||_        t           j        |_        t          j        t          dt           j                  }	 |                    |           |	                                 n# |	                                 w xY wt          j        t                    }	 |r7|
                                d         j        }|                     ||d           n6|
                                d         j        }|                     ||d           |	                                 d S # |	                                 w xY w)Nr   r   r   zPAX longlink creation failedzPAX longname creation failed)r'   r  r  r  r\  r&   r   r  r  rK   r   rU   r   )r   r   rl  rZ   rH   lns          r   r   zPaxWriteTest._test  s   /$'' 	+#G"?GLl7C0BCCC	KK   IIKKKKCIIKKKKl7##	 JNN$$Q'0  q*HIIIINN$$Q',  q*HIIIIIKKKKKCIIKKKKs   B   B3A/D8 8Ec                    dddddd}t          j        t          dt           j        |          }	 |                    t          j        d                     |                                 n# |                                 w xY wt          j        t          d	
          }	 |                     |j        |           |                     |	                                d         j        |           |j        
                                D ]\  }}|                     t          |          t                     |                     t          |          t                     |t           j        v rH	 t          j        |         |           # t          t           f$ r |                     d           Y w xY w	 |                                 d S # |                                 w xY w)Nr   0z1.23   äöütest)r  r   re  r  r  r   )r   r|  rD   rt  r   z"unable to convert pax header field)r'   r&   r   r  r  r  rK   rU   r|  r   r  assertIsNotr\  rJ  PAX_NUMBER_FIELDSr  rR  r   )r   r|  rH   keyvals        r   test_pax_global_headerz#PaxWriteTest.test_pax_global_header  s   & &( ( l7C0B') ) )	KK//000IIKKKKCIIKKKK l7[999	S_k:::S^^--a0<kJJJO1133 H HS  cE222  cE222'333H1#6s;;;;%z2 H H H		"FGGGGGH 4H IIKKKKKCIIKKKKs<   'A- -B"C
G -FG &F1.G 0F11G G"c                    ddd}t          j        t          dt           j        d          }	 t          j                    }d|_        d|_        ||_        |                    |           |	                                 n# |	                                 w xY wt          j        t          d	          }	 |
                                d
         }|                     |j        |           |                     |j        d           |                     |j        d           |	                                 d S # |	                                 w xY w)Nr  123)rf   r   r   rD   r  r     rt  r   r  )r'   r&   r   r  r  r   r   r|  r  rK   r   rU   )r   r|  rH   r  s       r   test_pax_extended_headerz%PaxWriteTest.test_pax_extended_header  s"     %U33l7C0B$/1 1 1	!!A#AFAE'AMKKNNNIIKKKKCIIKKKKl7[999	  #AQ]K888QVU+++QUC(((IIKKKKKCIIKKKKs   =B   B5A+D6 6Ec                 h   t          j                    }d|_        d|_        d|_        d|_        d|_        |                                }|                    |d          }| 	                    |d         d           | 
                    |d	         t                     | 	                    |d	         d
           | 	                    |d         d           | 	                    |d         d           | 	                    |d         d           | 	                    |dt          d          z   dz   t          d          z   dz   t          d          z   dz   t          d          z   dz   t          d          z   dz   t          d          z   dz   t          d          z              t          j                    }d|_        d|_        d|_        d|_        d|_        |                                }|                    |d          }| 	                    |d         d           | 	                    |d	         d           | 	                    |d         d           | 	                    |d         d           | 	                    |d         d           | 	                    |dt          d          z   dz   t          d          z   dz   t          d          z   dz   dz   d z   t          d!          z   d"z   t          d#          z   d$z   t          d          z   dz   t          d          z              d S )%Nr  g@@r   r  |   rD   rt  r   re  r  rW   r   r   s   ././@PaxHeaderV   s9   0000000 0000000 0000000 00000000020 00000000000 010205  xs   ustar 00   s   16 mtime=1000.1
i  r  a   s9   0000644 0000173 0000174 00000000144 00000001750 006516  0u   foo㍴l    d(	 r  i  r   s9   0000000 0000000 0000000 00000000130 00000000000 010207  xs   15 path=foo㍴
16 uid=16777216
s$   16 gid=16777217
20 size=10000000000
s   21 mtime=10000000000
i  s   foo?`   s9   0000644 0000000 0000000 00000000000 00000000000 006540  0)r'   r  r   re  rW   r   r   r  create_pax_headerrU   r7  rE  rJ  )r   r  infor  s       r   test_create_pax_headerz#PaxWriteTest.test_create_pax_header  so    Ozz||$$TK$@@fu---d7mS111g---fs+++ec***ec***b		)\]Cjj)*+0::6 ## &+3ZZ0 399 <A99E ]	]
 Cjj
 **
 -2#JJ7	8 	8 	8 Ozz||$$TK$@@f{333g***fq)))ea(((ea(((b		)\]Cjj)*,1#JJ7 << 8	8
 ((
 */s4
 7>>
 AFb		J ]] Cjj ** -2#JJ7	8 	8 	8 	8 	8r   r   )r    r!   r"   r   r  r  r  r+   r   r   r  r    sV           0  @  258 58 58 58 58r   r  c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	UnicodeTestc                 0    |                      d           d S )NrD   _test_unicode_filenamer   s    r   test_iso8859_1_filenamez#UnicodeTest.test_iso8859_1_filename;  s    ##K00000r   c                 0    |                      d           d S )Nutf7r  r   s    r   test_utf7_filenamezUnicodeTest.test_utf7_filename>  s    ##F+++++r   c                 0    |                      d           d S )Nutf-8r  r   s    r   test_utf8_filenamezUnicodeTest.test_utf8_filenameA  s    ##G,,,,,r   c                    t          j        t          d| j        |d          }	 d}|                    t          j        |                     |                                 n# |                                 w xY wt          j        t          |          }	 |                     |                                d         j	        |           |                                 d S # |                                 w xY w)Nr   rU  r   rF   errorsr  rt  r   )
r'   r&   r   r   r  r  rK   rU   r   r   )r   rF   rH   r   s       r   r  z"UnicodeTest._test_unicode_filenameD  s    l7C$,X? ? ?	!DKK--...IIKKKKCIIKKKKl7X666	S^^--a05t<<<IIKKKKKCIIKKKKs   )A# #A93C! !C7c                 |   t          j        t          d| j        dd          }	 t          j                    }d|_        |                     t          |j        |           d|_        d|_	        |                     t          |j        |           |
                                 d S # |
                                 w xY w)Nr   r   rU  r  r  r  )r'   r&   r   r   r  r   r  UnicodeErrorr  rg  rK   r~  s      r   test_unicode_filename_errorz'UnicodeTest.test_unicode_filename_errorS  s    l7C$+H> > >
	o''G)GLlCKAAA GL*GMlCKAAAIIKKKKKCIIKKKKs   A*B% %B;c                    t          j        t          ddd          }	 |D ]}|                     t	          |j                  t                     |                     t	          |j                  t                     |                     t	          |j                  t                     |                     t	          |j	                  t                     	 |
                                 d S # |
                                 w xY w)Nr`   rD   rU  rF   r  )r'   r&   r#   r'  r\  r   r8  r  rg  r  rK   r  s      r   test_unicode_argumentz!UnicodeTest.test_unicode_argumentb  s    l7C$/B B B	 2 2d16llC000d1:..444d17mmS111d17mmS1111	2 IIKKKKKCIIKKKKs   B9C/ /Dc                 \   t          j        d          }d|_        d|_        t          j        t
          d| j        d          }	 |                    |           |                                 n# |                                 w xY wt          j        t
          d          }	 |	                    d          }| 
                    |j        d           | 
                    |j        d           | j        t           j        k    rz|                                 t          j        t
          d          }|	                    d          }| 
                    |j        d           | 
                    |j        d           |                                 d S # |                                 w xY w)	Nr  r  r   rD   )r   r   rF   rt  r   u	   )r'   r  rg  r  r&   r   r   r  rK   rR   rU   r  )r   r  rH   s      r   test_uname_unicodezUnicodeTest.test_uname_unicoden  sf   OE""  l7T[$/1 1 1	KKNNNIIKKKKCIIKKKKl7[999	e$$AQWn555QWn555{g000		l7W===MM%((  *>???  *>???IIKKKKKCIIKKKKs   A0 0B%CF F+N)
r    r!   r"   r  r  r  r  r  r  r  r+   r   r   r  r  9  s}        1 1 1, , ,- - -    
 
 
    r   r  c                   \    e Zd Zej        Zd Zd Zd Zd Z	d Z
d ZddZd	 Zd
 ZddZdS )UstarUnicodeTestc                     |                      d           |                      dt                     |                      d           |                      dt                     d S Nr  e01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890ud   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿue   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿ_test_ustar_namerR  r   s    r   test_unicode_name1z#UstarUnicodeTest.test_unicode_name1  `    /0005zBBB?@@@@*MMMMMr   c                 f    |                      d           |                      dt                     d S Nud   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿue   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr  r   s    r   test_unicode_name2z#UstarUnicodeTest.test_unicode_name2  4    ABBBBJOOOOOr   c                     |                      d           |                      dt                     |                      d           |                      dt                     d S )Na   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123/40123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r  r   s    r   test_unicode_longname1z'UstarUnicodeTest.test_unicode_longname1  sb    NOOONPZ[[[PQQQQS]^^^^^r   c                 r    |                      dt                     |                      dt                     d S )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r  r   s    r   test_unicode_longname2z'UstarUnicodeTest.test_unicode_longname2  s8    PR\]]]SU_`````r   c                     |                      dt                     |                      d           |                      dt                     d S )Nu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿr  r   s    r   test_unicode_longname3z'UstarUnicodeTest.test_unicode_longname3  sM    TV`aaa^____aklllllr   c                 f    |                      d           |                      dt                     d S )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr  r   s    r   test_unicode_longname4z'UstarUnicodeTest.test_unicode_longname4  s5    `aaaacmnnnnnr   Nc                    t          j        t          d| j        d          5 }t          j        |          }||                    |           n|                     ||j        |           d d d            n# 1 swxY w Y   |Wt          j        t          dd          5 }|D ]}|                     ||j                    d d d            d S # 1 swxY w Y   d S d S )Nr   r  r  r`   rt  )	r'   r&   r   r   r  r  r  rU   r   r   r   excrH   r  s        r   r  z!UstarUnicodeTest._test_ustar_name  s_   \'3t{WMMM 	7QT%%A{A!!#s{A666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 ;gsW===   A$$T16222                  ;s$   A	A88A<?A<!!CCCc                     |                      d           |                      dt                     |                      d           |                      dt                     d S r  _test_ustar_linkrR  r   s    r   test_unicode_link1z#UstarUnicodeTest.test_unicode_link1  r  r   c                 f    |                      d           |                      dt                     d S r  r  r   s    r   test_unicode_link2z#UstarUnicodeTest.test_unicode_link2  r  r   c                    t          j        t          d| j        d          5 }t          j        d          }||_        ||                    |           n|                     ||j        |           d d d            n# 1 swxY w Y   |Wt          j        t          dd          5 }|D ]}|                     ||j                    d d d            d S # 1 swxY w Y   d S d S )Nr   r  r  r  r`   rt  )	r'   r&   r   r   r  r  r  r  rU   r  s        r   r  z!UstarUnicodeTest._test_ustar_link  sf   \'3t{WMMM 	7QT&&AAJ{A!!#s{A666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 ;gsW===   A$$T1:666                  ;s$   AA??BB(!CCCr   )r    r!   r"   r'   r   r   r  r  r  r  r  r  r  r  r  r  r+   r   r   r  r    s        !F
N N NP P P_ _ _a a am m m
o o o   N N NP P P     r   r  c                   "    e Zd Zej        Zd ZdS )GNUUnicodeTestc                     dD ]u\  }}t          j        t          |d          5 }	 |                    |          }n%# t          $ r |                     d           Y nw xY wd d d            n# 1 swxY w Y   vd S )N))r  u   pax/bad-pax-)rD   u   pax/bad-pax-äöür   r  z%unable to read bad GNU tar pax headerr'   r&   r#   rR   ra  r   r   rF   r   rH   r  s        r   test_bad_pax_headerz"GNUUnicodeTest.test_bad_pax_header  s    < 	G 	GNHd g%68 8 8 G;>Gd++AA G G GIIEFFFFFG	G G G G G G G G G G G G G G G	G 	G1   A-<A-AA-AA--A1	4A1	N)r    r!   r"   r'   ru  r   r  r+   r   r   r  r    s0        FG G G G Gr   r  c                   &    e Zd Zej        ZdZd ZdS )PAXUnicodeTestNc                     dD ]u\  }}t          j        t          |d          5 }	 |                    |          }n%# t          $ r |                     d           Y nw xY wd d d            n# 1 swxY w Y   vd S )N))r  u   pax/hdrcharset-)rD   u   pax/hdrcharset-äöür   r  z)unable to read POSIX.1-2008 binary headerr  r  s        r   test_binary_headerz!PAXUnicodeTest.test_binary_header  s    ? 	K 	KNHd g%68 8 8 K;>Kd++AA K K KIIIJJJJJK	K K K K K K K K K K K K K K K	K 	Kr  )r    r!   r"   r'   r  r   r  r  r+   r   r   r  r    s8        F #'
K 
K 
K 
K 
Kr   r  c                   "    e Zd Zd ZddZd ZdS )AppendTestBasec                     t           | _        t          j                            | j                  rt          j        | j                   d S d S r   )r   r#   re   rf   r  r   rq  r   s    r   rI   zAppendTestBase.setUp	  sD    7>>$,'' 	+T\*****	+ 	+r   r  c                    t          j        t          d          5 }|                    d          }d|_        |                    |          5 }t          j        | j        |          5 }|                    ||           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )NrD   rt  rP   r  )r'   r&   r#   rR   r   rS   r  )r   r   srcr  rW  rH   s         r   _create_testtarzAppendTestBase._create_testtar	  sn   \'K888 	&Co..AAF## &q\$,55 &KK1%%%& & & & & & & & & & & & & & && & & & & & & & & & & & & & &	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&sY   2B;B#)B B#BB#BB#B;#B'	'B;*B'	+B;;B?B?c                     |                      d| j        z              |                     t          j        t          j        t          d           d S )Nr  r   )r  r   r  r'   r  r&   r   r   s    r   test_append_compressedz%AppendTestBase.test_append_compressed	  sB    TDK/000'+W\7CHHHHHr   N)r  )r    r!   r"   rI   r  r  r+   r   r   r  r    sK        + + +
& & & &I I I I Ir   r  c                   j    e Zd ZdZddZdgdfdZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZdS )
AppendTestNc                     t          j        | j        d|          5 }|                    t          j        d                     d d d            d S # 1 swxY w Y   d S )Nr   r  r   )r'   r&   r#   r  r  )r   r6  rH   s      r   _add_testfilezAppendTest._add_testfile	  s    \$,W=== 	0KK..///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   (AAAr   c                     t          j        | j        |          5 }|                     |                                |           d d d            d S # 1 swxY w Y   d S )Nr  )r'   r&   r#   rU   r  )r   r^  r6  rH   s       r   r   zAppendTest._test	  s    \$,888 	4CS\\^^U333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   )AAAc                 V    |                                   |                                  d S r   )r  r   r   s    r   test_non_existingzAppendTest.test_non_existing	  s%    

r   c                     t          j        | j        d                                           |                                  |                                  d S )Nr  )r'   r&   r#   rK   r  r   r   s    r   
test_emptyzAppendTest.test_empty"	  sE    T\4((..000

r   c                     t          j        d          }|                     |           |                    d           |                     |           d S )Ns                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   r   r  )r$   r   r  ry   r   r   s     r   test_empty_fileobjzAppendTest.test_empty_fileobj'	  sN    z,''4   		!

4
     r   c                 ^   |                                   t          | j        d          5 }|                                }d d d            n# 1 swxY w Y   t	          j        |          }|                     |           |                    d           |                     ddg|           d S )Nrs   r   r  r   )r^  r6  )	r  r&   r#   rT   r$   r   r  ry   r   r   s      r   test_fileobjzAppendTest.test_fileobj-	  s    $,%% 	99;;D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	z$4   		!

%
66666s   AAAc                     |                                   |                                  |                     ddg           d S )Nr  r   )r^  )r  r  r   r   s    r   test_existingzAppendTest.test_existing6	  sD    

%
(((((r   c                     t          | j        d          5 }|                    |           d d d            n# 1 swxY w Y   |                     t          j        | j                   d S r  )r&   r#   r  r  r'   r  r  )r   r   r[   s      r   _test_errorzAppendTest._test_error=	  s    $,%% 	JJt	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'+T-?@@@@@s   8<<c                 0    |                      d           d S )Nr   r  r   s    r   	test_nullzAppendTest.test_nullB	  s    r   c                 0    |                      d           d S )N                r  r   s    r   test_incompletezAppendTest.test_incompleteE	      $$$$$r   c                 |    t          j        d                                          }|                     |           d S Nr  r'   r  r  r  r   r   s     r   test_premature_eofzAppendTest.test_premature_eofH	  s7    u%%++--r   c                     t          j        d                                          }|                     |dz              d S )Nr  r  r  r  s     r   test_trailing_garbagez AppendTest.test_trailing_garbageL	  s<    u%%++--
*+++++r   c                 0    |                      d           d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar  r   s    r   test_invalidzAppendTest.test_invalidP	  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  	  s        !0 0 0 0 !'4 4 4 4 4    
! ! !7 7 7) ) )A A A
  % % %  , , ,% % % % %r   r  c                       e Zd ZdS )GzipAppendTestNr   r+   r   r   r  r  S	  r   r   r  c                       e Zd ZdS )Bz2AppendTestNr   r+   r   r   r  r  V	  r   r   r  c                       e Zd ZdS )LzmaAppendTestNr   r+   r   r   r  r  Y	  r   r   r  c                        e Zd Zd Zd Zd ZdS )
LimitsTestc                 d   t          j        d          }|                    t           j                   t          j        d          }|                     t
          |j        t           j                   t          j        d          }|                    t           j                   t          j        d          }|                     t
          |j        t           j                   t          j        d          }|                     t
          |j        t           j                   t          j        d          }d|_        |                     t
          |j        t           j                   t          j        d          }d|_        |                     t
          |j        t           j                   d S )	Nr  r  a   123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamea   1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/1234567/longname   123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamerP  r       )r'   r  r  r   r  rR  r  r   r^  s     r   test_ustar_limitszLimitsTest.test_ustar_limits_	  sL   /"344g*+++ /"9::*gmW5IJJJ /":;;g*+++ /">??*gmW5IJJJ /";<<*gmW5IJJJ /*--4*gmW5IJJJ /&)) *gmW5IJJJJJr   c                 l   t          j        d          }|                    t           j                   t          j        d          }d|_        |                    t           j                   t          j        d          }d|_        |                     t          |j        t           j                   d S Nr  rP  r   l          )r'   r  r  ru  r  r   r  rR  r^  s     r   test_gnu_limitszLimitsTest.test_gnu_limits~	  s    /";<<g()))/*--4g())) /&))+*gmW5GHHHHHr   c                 T   t          j        d          }|                    t           j                   t          j        d          }d|_        |                    t           j                   t          j        d          }d|_        |                    t           j                   d S r!  )r'   r  r  r  r  r   r^  s     r   test_pax_limitszLimitsTest.test_pax_limits	  s    /";<<g()))/*--4g()))/&))+g()))))r   N)r    r!   r"   r  r"  r$  r+   r   r   r  r  ]	  sG        K K K>I I I
* 
* 
* 
* 
*r   r  c                      e Zd Zd Zd Zd Zd Zd Zd Z e	j
         ej                    d           e	j
         eed          d	          e	j                            d
          d                                     ZdS )MiscTestc                 Z   |                      t          j        dddd          d           |                      t          j        dddd          d           |                      t          j        ddd          d           |                      t          j        d	dd          d           d S )
Nr     r   rU  s   foo     foobarr!  r  s   foo bar )rU   r'   stnntsr   s    r   test_char_fieldszMiscTest.test_char_fields	  s    UAwAA)	+ 	+ 	+Xq'8DD	! 	! 	!%5wII	  	  	 ]GXFF	  	  	  	  	 r   c                    |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d	          d
           |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           |                      t          j        d          d           d S )N   0000001 rt      7777777            r               rj                      r  r   s           )rU   r'   ntir   s    r   test_read_number_fieldsz MiscTest.test_read_number_fields	  sT    	^44a888^44i@@@%HII#	% 	% 	%%HII#	% 	% 	%%HII	 	 	%HII	 	 	%HII+	- 	- 	- 	U++Q///\22A66666r   c                 
   |                      t          j        d          d           |                      t          j        d          d           |                      t          j        dt          j                  d           |                      t          j        dt          j                  d	           |                      t          j        d
t          j                  d           |                      t          j        dt          j                  d           |                      t          j        dt          j                  d           |                      t          j        dt          j                  d           |                      t          j        dt          j                  d           |                      t          j        t          j        dt          j                            d           d S )Nrt   r.  r0  r/  r  r  r1  r3  r2  rj  r4  r6  r5  r8  r7  g      Yg      0Bs         gr   )rU   r'   itnru  r9  r   s    r   test_write_number_fieldsz!MiscTest.test_write_number_fields	  s   Q888Y//@@@Z8JKKK<	> 	> 	>Z8JKKK<	> 	> 	>R0BCCC<	> 	> 	>T'2DEEE<	> 	> 	>%7,3,>@ @ @<	> 	> 	> 	VG4FGGG<	> 	> 	>]7;MNNN<	> 	> 	>W[g>P%Q%Q%QRRTUVVVVVr   c                    |                      t                    5  t          j        ddt          j                   d d d            n# 1 swxY w Y   |                      t                    5  t          j        ddt          j                   d d d            n# 1 swxY w Y   |                      t                    5  t          j        ddt          j                   d d d            n# 1 swxY w Y   |                      t                    5  t          j        ddt          j                   d d d            d S # 1 swxY w Y   d S )Nrj  r(  r  l       l        )r  rR  r'   r<  r   ru  r   s    r   test_number_field_limitsz!MiscTest.test_number_field_limits	  s   z** 	5 	5KAw3444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5z** 	= 	=K
Aw';<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=z** 	? 	?K7+=>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?z** 	> 	>Kq'*<===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	>sG   !AAA-!BB!B?!C,,C03C0!D??EEc                 F    h d}t          j        | t          |           d S )N>9   NULgrpr<  r9  r+  pwdr*  mainrA  CHRTYPEr]  r  rB  SYMTYPEXGLTYPEr  versionAREGTYPECONTTYPEFIFOTYPEfilemoder  	GNU_MAGIC	GNU_TYPES
PAX_FIELDSr  
tar_filterFilterErrorr  r  POSIX_MAGICcopyfileobjdata_filterExFileObjectcalc_chksumsLENGTH_PREFIXREGULAR_TYPESEOFHeaderErrorGNUTYPE_SPARSEPAX_NAME_FIELDSSOLARIS_XHDTYPESUPPORTED_TYPESEmptyHeaderErrorGNUTYPE_LONGLINKrt  SpecialFileErrorAbsoluteLinkErrorAbsolutePathErrorLinkFallbackErrorr  symlink_exceptionInvalidHeaderErrorTruncatedHeaderErrorfully_trusted_filterSubsequentHeaderErrorOutsideDestinationErrorLinkOutsideDestinationError)not_exported)r   check__all__r'   )r   rl  s     r   test__all__zMiscTest.test__all__	  s3      " 	T7FFFFFFr   c                 ,   t           j                            t           j                            t                    d          }|                     t          j                  5 }t          j        d          f}t          j
        j                            t          j        d|          5  t          j        |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     dt!          |j                             d S )Nr   zlzma module is not availabler?   )r  z?
- method xz: CompressionError('lzma module is not available')
)re   rf   rg   dirname__file__r  r'   r  CompressionErrorr   r  r  r  r(   r&   r   r8  	exception)r   fnameexcinfor  s       r   .test_useful_error_message_when_modules_missingz7MiscTest.test_useful_error_message_when_modules_missing	  s^   RW__X668HIIw011 	$W,-KLLME$++GOXSX+YY $ $U###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$
 	O!""	
 	
 	
 	
 	
s7   "AC!)C
>C!
C	C!C	C!!C%(C%zrequires symlink supportchmodzmissing os.chmodos.chmodc                    t           j                            t          d          fd}||_        t           j                            t          d          }t                      5 }|                    dd           |                    dt          j        d           |                    d|           d d d            n# 1 swxY w Y   t          j	        |           	 |
                                                    d	
           t          j        |           t          j                   d S # t          j        |           t          j                   w xY w)N
test127987c                     t           j                            |           }t           j                            |g          k    rt	          d|          d S )Nz8should not try to chmod anything outside the destination)re   rf   realpath
commonpath	Exception)rf   r   r  target_pathr  s       r   mock_chmod_side_effectzRMiscTest.test_deferred_directory_attributes_update.<locals>.mock_chmod_side_effect	  sS    '**400Kw!!;"899WDD Z\ghhh EDr   outside_tree_dirre  r  
symlink_to
?rwsrwsrwtr\  r   rH   r  )re   rf   rg   rd   r  ArchiveMakerr   r'   r]  makedirsr&   ru  r   r  )r   
mock_chmodr  r  arcr  s        @r   )test_deferred_directory_attributes_updatez2MiscTest.test_deferred_directory_attributes_update	  s   
 ',,w55	i 	i 	i 	i 	i "8
7<<1CDD^^ 	6sGGCCG(((GGCgoLGAAAGGC$4G555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 	$%%%	&HHJJ!!wu!===-...W%%%%% -...W%%%%s   &ACC
C#)D6 6*E N)r    r!   r"   r,  r:  r=  r@  rn  rv  r   r   r   can_symlinkr   re   r  r  r  r+   r   r   r&  r&  	  s             7 7 7(W W W.> > >G G G(

 

 

 X..002LMMXW--/ABB]$$& & %$ CB NM& & &r   r&  c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )CommandLineTestc                     t          j        ddg|R i |\  }}}|                    t          j                                        d          S )N-mr'      
)r	   assert_python_okr   re   linesepr   )r   argsr  rcr   errs         r   
tarfilecmdzCommandLineTest.tarfilecmd
  s_    $5dI @ @ @ @8>@ @C{{2:,,..666r   c                 (    t          j        ddg|R  S )Nr  r'   )r	   assert_python_failure)r   r  s     r   tarfilecmd_failurez"CommandLineTest.tarfilecmd_failure
  s    24JTJJJJr   c                 n   t          j        dd          t          j        dd          g}|                     t          j        |           t          j        |d          5 }|D ]6}|                    |t          j	        
                    |                     7	 d d d            d S # 1 swxY w Y   d S )Ntokenize_tests.txttokenizedatarL  9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr   r  )r   r#  rp  r   rq  r'   r&   r   re   rf   r  )r   tar_namefilesr  tardatas        r   make_simple_tarfilez#CommandLineTest.make_simple_tarfile
  s    !"6)79 9 9! #>)79 9 9:
 		((333\(C(( 	CB  C Cw(8(8(A(ABBBBC	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   ":B**B.1B.c                    |                      t          j        |           t          j        |d          5 }t          j        d          }|                    |t          j        d                     t          j        d          }|                    |t          j        d                     d d d            d S # 1 swxY w Y   d S )Nr   benignr   r  ../evil)	rp  r   rq  r'   r&   r  r  r$   r   )r   r  r  r  evils        r   make_evil_tarfilez!CommandLineTest.make_evil_tarfile(
  s    	((333\(C(( 	6B_X..FJJvrz#J777?9--DJJtRZ__J555		6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   A;B>>CCc                    |                                  \  }}}|                     |d           |                     d|                                           |                     d|                                           |                     d|                                           |                      dd          \  }}}|                     |d           |                     |                                d           d S )Nr   s   usages   errors   required-lr   )r  rU   r   lowerrM  strip)r   r  r   r  s       r   test_bad_usezCommandLineTest.test_bad_use0
  s    ..00Cc"""h		,,,h		,,,k399;;///..tR88Cc"""CIIKK-----r   c                 |    t           D ]3}dD ].}|                     ||          }|                     |d           /4d S )N)-tz--testr   )testtarnamesr  rU   r   r  optr   s       r   test_test_commandz!CommandLineTest.test_test_command:
  s[    $ 	+ 	+H% + +ooc844  c****+	+ 	+r   c                     t           D ]6}dD ]1}|                     |d|d          }|                     d|           27d S )N-vz	--verboser  r  PYTHONIOENCODINGs   is a tar archive.
)r  r  r   r  s       r   test_test_command_verbosez)CommandLineTest.test_test_command_verbose@
  sj    $ 	; 	;H( ; ;ooc47> & @ @4c::::;	; 	;r   c                 p   t          j        d          }|                     d|          \  }}}|                     d|           |                     |d           |                     |d           t
          D ]<}|                     |          5  t          |d          5 }|                                }d d d            n# 1 swxY w Y   	 t          t          d          5 }|
                    |d d	                    d d d            n# 1 swxY w Y   |                     dt                    \  }}}|                     |d           |                     |d           t          j        t                     n# t          j        t                     w xY w	 d d d            n# 1 swxY w Y   >d S )
N
zipdir.zipr      is not a tar archive.r   rt   )r  rs   r   r  )r   r#  r  r   rU   r  r  r&   rT   r   r  r   rq  )r   zipnamer  r   r  r  rW  r   s           r   test_test_command_invalid_filez.CommandLineTest.test_test_command_invalid_fileG
  sV   "<00..tW==C/555c"""Q$ 	. 	.Hx00 
. 
.(D)) $Q6688D$ $ $ $ $ $ $ $ $ $ $ $ $ $ $.gt,, ,TcT
+++, , , , , , , , , , , , , , ,#'#:#:4#I#ILBS$$S#...$$R+++$W----I$W-----
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
. 
.	. 	.ss   F)"C7F)CF)
CF)E>$DE>DE>DAE>$F)>FF))F-	0F-	c                    t           D ]}t          j                    5 }t          j        |d          5 }|                    d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                                    dd          }dD ]0}|                     ||d          }| 	                    ||           1d S )Nr`   Fr   r   r   )r  z--listr  
r  r   captured_stdoutr'   r&   rp   r   r   r  rU   r   r  r  r  expectedr  r   s          r   test_list_commandz!CommandLineTest.test_list_command[
  sb   $ 	0 	0H(** +a\(C00 +BGGEG***+ + + + + + + + + + + + + + ++ + + + + + + + + + + + + + + zz||**74FGGH% 0 0ooc87> & @ @  h////0	0 	04   A-A
A-AA-AA--A1	4A1	c                    t           D ]}t          j                    5 }t          j        |d          5 }|                    d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                                                    dd          }dD ]1}|                     |d|d          }| 	                    ||           2d S )	Nr`   Tr   r   r   r  r  r  r  r  s          r   test_list_command_verbosez)CommandLineTest.test_list_command_verbosef
  sd   $ 	0 	0H(** *a\(C00 *BGGDG)))* * * * * * * * * * * * * * ** * * * * * * * * * * * * * * zz||**74FGGH( 0 0ooc47> & @ @  h////0	0 	0r  c                     t          j        d          }|                     d|          \  }}}|                     d|           |                     |d           |                     |d           d S )Nr  r  r  r   rt   )r   r#  r  r   rU   r   r  r  r   r  s        r   test_list_command_invalid_filez.CommandLineTest.test_list_command_invalid_fileq
  st    "<00..tW==C/555c"""Qr   c                    t          j        dd          t          j        dd          g}dD ]}	  | j        |t          g|R  }|                     |d           t          j        t                    5 }|                                 d d d            n# 1 swxY w Y   t          j	        t                     # t          j	        t                     w xY wd S )Nr  r  r  r  )-cz--creater   )
r   r#  r  r   rU   r'   r&   r   r   rq  r   r  r  r   rH   s        r   test_create_commandz#CommandLineTest.test_create_commandx
  s1   !"6)79 9 9! #>)79 9 9:
 $ 	* 	*C*%doc7;U;;;  c***\'** %cNN$$$% % % % % % % % % % % % % % %  ))))	 ))))	* 	*s0   AB;5B
B;B	B;B	B;;Cc                    t          j        dd          t          j        dd          g}dD ]}	  | j        |dt          g|R ddi}|                     d	|           t          j        t                    5 }|                                 d d d            n# 1 swxY w Y   t          j	        t                     # t          j	        t                     w xY wd S )
Nr  r  r  r  r  r  r  r  s    file created.)
r   r#  r  r   r   r'   r&   r   r   rq  r  s        r   test_create_command_verbosez+CommandLineTest.test_create_command_verbose
  sM   !"6)79 9 9! #>)79 9 9:
 % 	* 	*C*%doc4 @5 @ @ @7>@ @/555\'** %cNN$$$% % % % % % % % % % % % % % %  ))))	 ))))	* 	*s0   AB?9BB?B	B?!B	"B??Cc                    t          j        dd          g}	  | j        dt          g|R  }|                     |d           t          j        t                    5 }|                                 d d d            n# 1 swxY w Y   t          j	        t                     d S # t          j	        t                     w xY w)Nr  r  r  r  r   )
r   r#  r  dotlessnamerU   r'   r&   r   r   rq  )r   r  r   rH   s       r   $test_create_command_dotless_filenamez4CommandLineTest.test_create_command_dotless_filename
  s    !"6~NNNO	*!$/$<e<<<CS#&&&k** !c   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! [)))))I[))))s0   AB# A=1B# =BB# BB# #B>c                    t           j                            t          d          }t	          j        dd          g}	  | j        d|g|R  }|                     |d           t          j	        |          5 }|
                                 d d d            n# 1 swxY w Y   t          j        |           d S # t          j        |           w xY w)Nz.testtarr  r  r  r  r   )re   rf   rg   rd   r   r#  r  rU   r'   r&   r   r   rq  )r   r  r  r   rH   s        r   (test_create_command_dot_started_filenamez8CommandLineTest.test_create_command_dot_started_filename
  s   7<<44!"6~NNNO	'!$/$95999CS#&&&h'' !3   ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! X&&&&&IX&&&&s/   9B9 7BB9 BB9 B B9 9Cc                    t          j        dd          t          j        dd          g}t          t          t          fD ]}|j        s
	 t          dz   |j        z   } | j        d|g|R  }|	                    |          5 }|
                                 d d d            n# 1 swxY w Y   t          j        |           # t          j        |           w xY wd S )Nr  r  r  r  r  r  )r   r#  r-   r4   r:   r&   r   r   r  r)   r   r   rq  )r   r  filetyper  r   rH   s         r   test_create_command_compressedz.CommandLineTest.test_create_command_compressed
  sC   !"6)79 9 9! #>)79 9 9:
 "7H5 		+ 		+H= +"S=8?:%dodH=u===%%h// %3NN$$$% % % % % % % % % % % % % % %  ****	 ****		+ 		+s0   6CB#C#B'	'C*B'	+CCc                 x   |                      t                     dD ]}	 t          j        t                    5  |                     |t                    }d d d            n# 1 swxY w Y   |                     |d           t          j        t                     # t          j        t                     w xY wd S )N)-ez	--extractr   r  r   r   r   	tarextdirr  rU   r  r   r  r   s      r   test_extract_commandz$CommandLineTest.test_extract_command
  s      )))$ 	, 	,C,'	22 8 8//#w77C8 8 8 8 8 8 8 8 8 8 8 8 8 8 8  c*** ++++	 ++++	, 	,s.   BA!B!A%	%B(A%	)BB7c                 ~   |                      t                     dD ]}	 t          j        t                    5  |                     |dt          d          }d d d            n# 1 swxY w Y   |                     d|           t          j        t                     # t          j        t                     w xY wd S )Nr  r  r  r      file is extracted.)r  r   r   r   r  r  r   r  r  s      r   test_extract_command_verbosez,CommandLineTest.test_extract_command_verbose
  s     )))$ 	, 	,C,'	22 D D//#tW;B * D DCD D D D D D D D D D D D D D D 4c::: ++++	 ++++	, 	,s.   BA$B$A(	(B+A(	,BB:c           	      &   |                      t                     t          j                            t
          d          }t          j        t
                     	 t          j        |          5  | 	                    dt          ddd           | 
                    dt          dddd          }|                     d	|           d d d            n# 1 swxY w Y   t          j        t
                     d S # t          j        t
                     w xY w)
Ndestr  r  z--filterr   r}  r  r  r  )r  r   re   rf   rg   r  r   r   r   r  r  r   r  )r   destdirr   s      r   test_extract_command_filterz+CommandLineTest.test_extract_command_filter
  s>   w''' ',,y&11
	(#G,, ; ;''g(,(2F< < < oodG&*&0/7> & @ @ 4c:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; Y'''''IY''''s1   C5 .ACC5 CC5 CC5 5Dc                 p   |                      t                     	 t          j        t                    5  |                     dt          d          }d d d            n# 1 swxY w Y   |                     |d           t          j        t                     d S # t          j        t                     w xY w)Nr  spamdirr   r  )r   r   s     r   (test_extract_command_different_directoryz8CommandLineTest.test_extract_command_different_directory
  s      )))	(#I.. @ @oodGY??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @S#&&&Y'''''IY''''s.   B AB A""B %A"&B B5c                 H   t          j        d          }t          j        t                    5  |                     d|          \  }}}d d d            n# 1 swxY w Y   |                     d|           |                     |d           |                     |d           d S )Nr  r  r  r   rt   )r   r#  r   r   r  r  r   rU   r  s        r   !test_extract_command_invalid_filez1CommandLineTest.test_extract_command_invalid_file
  s    "<00	** 	B 	B224AALBS	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B/555c"""Qs   AAAN)r    r!   r"   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r+   r   r   r  r  
  sU       7 7 7
K K K	C 	C 	C6 6 6. . .+ + +; ; ;. . .(	0 	0 	0	0 	0 	0     * * ** * * * * *	' 	' 	'+ + +", , ,	, 	, 	,( ( (&( ( (         r   r  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )ContextManagerTestc                     t          j        t                    5 }|                     |j        d           d d d            n# 1 swxY w Y   |                     |j        d           d S )Nzclosed inside runtime contextcontext manager failed)r'   r&   r#   r   r,  r   r  s     r   
test_basiczContextManagerTest.test_basic
  s    \'"" 	JcSZ)HIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J
$<=====s   AA	Ac                     t          j        t                    }|                                 |                     t
                    5  |5  	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r   )r'   r&   r#   rK   r  r  r  s     r   test_closedzContextManagerTest.test_closed
  s     l7##		w'' 	 	                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s6   A1AA1A	A1 A	!A11A58A5c                 <   |                      t                    5 }t          j        t                    5 }t
          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   |                     |j        t
          d           |                     |j	        d           d S )Nz)wrong exception raised in context managerr  )
r  r~  r'   r&   r#   r  r7  rs  r   r,  )r   r  rH   s      r   test_exceptionz!ContextManagerTest.test_exception  s    y)) 	Sg&& #        	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	cmWI	K 	K 	K
$<=====s,   A=A	AA	AAAc                    	 t          j        t          d          5 }t          # 1 swxY w Y   n#  Y nxY w|                     t
          j                            t                    dd           |                     |j	        d           d S )Nr   r   z-context manager wrote an end-of-archive blockr  )
r'   r&   r   r~  rU   re   rf   r  r   r,  r  s     r   test_no_eofzContextManagerTest.test_no_eof  s    	gs++  s                 	D111?	A 	A 	A
$<=====s   0 $(0 (0 4c                     t          j        t          d          5  	 d d d            n# 1 swxY w Y   |                     t          j                            t                    dd           d S )Nr   r   z-context manager wrote no end-of-archive block)r'   r&   r   rM  re   rf   r  r   s    r   test_eofzContextManagerTest.test_eof  s     \'3'' 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	BGOOG44a?	A 	A 	A 	A 	As   )--c                 2   t          t          d          5 }	 t          j         |d          5 }t          # 1 swxY w Y   n#  Y nxY w|                     |j        d           |                     |j        d           d d d            d S # 1 swxY w Y   d S )Nr   r   r5  zexternal file object was closedr  )r&   r   r'   r~  r   r,  r   r:  s      r   r  zContextManagerTest.test_fileobj$  s    '4   	BD\$S999 $S#O$ $ $ $ $ $ $ $ $T[*KLLLOOCJ(@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	Bs>   BA6:	A:	ABA;BBBN)	r    r!   r"   r  r  r  r  r  r  r+   r   r   r  r  
  sv        > > >
  > > >
> 
> 
>A A A
B 
B 
B 
B 
Br   r  zrequires os.link to be missingc                   H   e Zd Zd Z ej         eej        d          d          d             Z	 ej         eej        d          d          d             Z
 ej         eed          d          d             Z ej         eed          d          d	             Zd
S )LinkEmulationTestc                 X   | j                             |t          d           t          t          j                            t          |          d          5 }|                                }d d d            n# 1 swxY w Y   |                     t          |          t                     d S )Nr}  r^   rs   )rH   rc   rd   r&   re   rf   rg   rT   rU   r   rX   )r   r   rW  r   s       r   _test_link_extractionz'LinkEmulationTest._test_link_extraction7  s    w???"',,w--t44 	6688D	 	 	 	 	 	 	 	 	 	 	 	 	 	 	4.99999s   A77A;>A;islinkz3Skip emulation - has os.path.islink but not os.linkc                 0    |                      d           d S )Nr   r  r   s    r   test_hardlink_extraction1z+LinkEmulationTest.test_hardlink_extraction1>       	""?33333r   c                 0    |                      d           d S )Nr   r  r   s    r   test_hardlink_extraction2z+LinkEmulationTest.test_hardlink_extraction2C       	""#>?????r   r  z Skip emulation if symlink existsc                 0    |                      d           d S )Nr   r  r   s    r   test_symlink_extraction1z*LinkEmulationTest.test_symlink_extraction1H  r   r   c                 0    |                      d           d S )Nr   r  r   s    r   test_symlink_extraction2z*LinkEmulationTest.test_symlink_extraction2M  r  r   N)r    r!   r"   r  r   r  r   re   rf   r  r  r  r  r+   r   r   r  r  1  s+       : : : X_WWRWh//JL L4 4L L4 X_WWRWh//JL L@ @L L@ X_WWR++79 94 49 94 X_WWR++79 9@ @9 9@ @ @r   r  c                        e Zd Zd Zd Zd ZdS )Bz2PartialReadTestc                 j    G fddt           j                  t          j        t	          j        d                                                    }t          t          |          dz             D ]?}	 t	          j	         |d |                   |           +# t          j
        $ r Y <w xY wd S )Nc                   2     e Zd ZdZ fdZ fdZ xZS )9Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIOFc                     | j         rt          d          |                                 t          |                                           k    | _         t          |                               |          S )Nz(infinite loop detected in tarfile.open())hit_eofAssertionErrorrz   rV   r   superrT   )r   r  	MyBytesIO	__class__s     r   rT   z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.readZ  sf    < ;( *: ; ; ;#yy{{c$--//.B.BBY--221555r   c                 B    d| _          t          |           j        | S r  )r  r  ry   )r   r  r  r  s     r   ry   z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek`  s$    $2uY--2D99r   )r    r!   r"   r  rT   ry   __classcell__)r  r  s   @r   r  r  X  sa        G6 6 6 6 6 6: : : : : : : : : :r   r  r  rt   r5  )r$   r   r5   compressr'   r  r  rangerV   r&   r  )r   r   r   re  r  s       @r   _test_partial_inputz&Bz2PartialReadTest._test_partial_inputW  s    
	: 
	: 
	: 
	: 
	: 
	: 
	:
 
	: 
	: 
	: |GOE2288::;;s4yy1}%% 	 	AYYtBQBx%8%8tDDDDD$   	 	s   6'BB0/B0c                 0    |                      d           d S Nr`   r  r   s    r   test_partial_inputz%Bz2PartialReadTest.test_partial_inputk  s      %%%%%r   c                 0    |                      d           d S )Nrz  r  r   s    r   test_partial_input_bz2z)Bz2PartialReadTest.test_partial_input_bz2n  s      )))))r   N)r    r!   r"   r  r  r  r+   r   r   r	  r	  S  sA          (& & &* * * * *r   r	  c                      	 dd l } dd l}n# t          $ r Y dS w xY w|                     d          d         dk    rdS |                    d          d         dk    rdS dS )Nr   FrootT)rD  rC  ImportErrorgetpwuidgetgrgid)rD  rC  s     r   root_is_uid_gid_0r#  r  s       uu
||AqV##u
||AqV##u4s    
chownzmissing os.chowngeteuidzmissing os.geteuidc                       e Zd Zed             Zeed                         Zej        	                    d          ej        	                    d          ej        	                    d          d                                     Z
ej        	                    d          ej        	                    d          ej        	                    d          d                                     Z ej         e            d          ej        	                    d          ej        	                    d          ej        	                    d          d	                                                 Zej        	                    d          d
             ZdS )NumericOwnerTestc                    t          j        d          }| ddt          j        |f|ddt          j        d f|ddt          j        |fg}t          j        t          d          5 }|D ]U\  }}}}	}
t          j        |          }||_        ||_	        d	|_
        d	|_        |	|_        |                    ||
           V	 d d d            n# 1 swxY w Y   t          S )
Ns   contentc   b   M   L   X   W   r   r  )r$   r   r'   rB  r]  r&   r   r  r   r   rg  r  r\  r  )
filename_1	dirname_1
filename_2r[   r  tarflr   r   r   typcontentsr  s               r   _make_test_archivez#NumericOwnerTest._make_test_archive  s!    z*%% b"got<b"got<b"got< \'3'' 	+516 + +-c3XOD))  a****+	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ s   !ACCCc              #   
  K   d| _         d}d}|}|}t          j                            ||          }t                              |||          }t          j        |          5 }||||fV  d d d            d S # 1 swxY w Y   d S )Nr   znumeric-owner-testfiler  )r  re   rf   rg   r'  r5  r'   r&   )mock_geteuidrt  rp  r/  r0  r1  tar_filenamer2  s           r   _setup_testzNumericOwnerTest._setup_test  s       %&!( 
	W\\'511
 (:::;D;EG G \,'' 	;5Y
::::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   "	A88A<?A<zos.chownrx  z
os.geteuidc                 $   |                      |          5 \  }}}}|                    |t          dd           |                    |t          dd           d d d            n# 1 swxY w Y   t          j                            t          |          }t          j                            t          |          }	|                    t          j        	                    |dd          t          j        	                    |	dd          gd           d S )	NTr}  numeric_ownerr_   r)  r*  r-  r.  	any_order)
r9  rc   rd   re   rf   rg   assert_has_callsr   r  call)
r   r7  r  
mock_chownr2  r/  _r1  f_filename_1f_filename_2s
             r   test_extract_with_numeric_ownerz0NumericOwnerTest.test_extract_with_numeric_owner  sH   
 l++ 	2 0<z10:MM*gT!0  2 2 2MM*wd!0  2 2 2		2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 w||GZ88w||GZ88##X]%7%7b"%M%M%-]%7%7b"%M%M%' /3 	$ 	4 	4 	4 	4 	4s   AA$$A(+A(c           	      p   |                      |          5 \  }}}}|                    t          dd           d d d            n# 1 swxY w Y   t          j                            t          |          }t          j                            t          |          }	t          j                            t          |          }
|                    t          j        	                    |dd          t          j        	                    |	dd          t          j        	                    |
dd	          gd
           d S )NTr}  r;  r)  r*  r+  r,  r-  r.  r=  )
r9  ru  rd   re   rf   rg   r?  r   r  r@  )r   r7  r  rA  r2  r/  r0  r1  rC  f_dirname_1rD  s              r   "test_extractall_with_numeric_ownerz3NumericOwnerTest.test_extractall_with_numeric_owner  sP   
 l++ 	5 0<z90:WD$3  5 5 5	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 w||GZ88w||GY77w||GZ88##X]%7%7b"%M%M%-]%7%7R%L%L%-]%7%7b"%M%M%' /3	 	$ 	4 	4 	4 	4 	4s   #AA	A	z uid=0,gid=0 must be named "root"c                    |                      |          5 \  }}}}|                    |t          dd           d d d            n# 1 swxY w Y   t          j                            t          |          }|                    |dd           d S )NFr}  r;  r   )r9  rc   rd   re   rf   rg   assert_called_with)r   r7  r  rA  r2  r/  rB  rC  s           r   "test_extract_without_numeric_ownerz3NumericOwnerTest.test_extract_without_numeric_owner  s     l++ 	2/Hz1aMM*gU!0  2 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2
 w||GZ88%%lAq99999s   $AA
A
c           	          |                      |          5 \  }}}}|                     t          |j        |t          dd           d d d            d S # 1 swxY w Y   d S )NFT)r9  r  r  rc   rd   )r   r7  r2  r/  rB  s        r   test_keyword_onlyz"NumericOwnerTest.test_keyword_only  s    l++ 	O/Hz1ai#mZ%O O O	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	Os   /AAAN)r    r!   r"   rv  r5  r   r9  r   r  r  rE  rH  r   r#  rK  rM  r+   r   r   r'  r'  ~  s          \. ; ; ^ \;( ]$$]$$]&&4 4 '& %$ %$4$ ]$$]$$]&&4 4 '& %$ %$4, X**,,;= =]$$]$$]&&	: 	: '& %$ %$= =
	: ]&&O O '&O O Or   r'  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )ReplaceTestsc                 8   | j                             d          }|                    d          }|                     |j        d           |                     |j        d           |                     | j                             d          j        d           d S )NrP   z
misc/otherr?  )rH   rR   r   rU   r   r   r  replaceds      r   test_replace_namezReplaceTests.test_replace_name  s    ##O44>>|>44555o666++O<<A(	* 	* 	* 	* 	*r   c                 *   | j                             d          }|                                }d|j        d<   |                     |j        d         d           |                     | j                             d          j        d         d           d S )Nr{  not-barr  r   rH   rR   r   r|  rU   rQ  s      r   test_replace_deepzReplaceTests.test_replace_deep  s    ##N33>>##(1W%+G4e<<<H~..:7CU	L 	L 	L 	L 	Lr   c                 .   | j                             d          }|                    d          }d|j        d<   |                     |j        d         d           |                     | j                             d          j        d         d           d S )Nr{  F)deeprU  r  rV  rQ  s      r   test_replace_shallowz!ReplaceTests.test_replace_shallow  s    ##N33>>u>--(1W%+G4i@@@H~..:7CY	P 	P 	P 	P 	Pr   c                 N   | j                             d          }dD ]}|                     |          5   |j        di |d i}|                     t          ||          d            |                     t          ||          d            d d d            n# 1 swxY w Y   d S )NrP   )r   re  r   r  r   r   rg  r  	attr_namer+   )rH   rR   r  r   rU   r=  rM  )r   r  r]  rR  s       r   test_replace_allzReplaceTests.test_replace_all  s   ##O44: 	F 	FI	22 F F)6>>>Y,=>>  9!=!=tDDD##GFI$>$>EEEF F F F F F F F F F F F F F F	F 	Fs   ABB	 B	c                     | j                             d          }|                     t                    5  |                    d           d d d            d S # 1 swxY w Y   d S )NrP   i[)rV  )rH   rR   r  r  r   )r   r  s     r   test_replace_internalz"ReplaceTests.test_replace_internal  s    ##O44y)) 	- 	-NN)N,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   AA AN)r    r!   r"   rS  rW  rZ  r^  r`  r+   r   r   rO  rO    sh        * * *L L LP P PF F F- - - - -r   rO  c                       e Zd ZdZed             Zed             Zd Zed             Z	d Z
d Zd Zd	 Zd
 Zd Zd ZdS )NoneInfoExtractTestsNc                     t          j        t          dd          }t          j        t
                    dz   _        d|_        |                     j         j	                   |
                                 t           fdt          j         j                                      d          D                        _        d S )	Nr`   rD   rE   extractall_ctrlr   r^   c              3   L   K   | ]}|                     j                  V  d S r   )relative_tocontrol_dir)rz  prT  s     r   	<genexpr>z2NoneInfoExtractTests.setUpClass.<locals>.<genexpr>2  sM        A  A MM#/** A  A  A  A  A  Ar   **/*)r'   r&   r#   r   r   rd   rg  ro  ru  extraction_filterrK   setglobcontrol_paths)rT  rH   s   ` r   rU  zNoneInfoExtractTests.setUpClass+  s    l7{CCC!,w//2CCss/DEEE		  A  A  A  A\#/2277?? A  A  A A Ar   c                 8    t          j        | j                   d S r   )shutilr  rg  rX  s    r   rY  z"NoneInfoExtractTests.tearDownClass6  s    co&&&&&r   c                 ,   t          fdt          j                                      d          D                       }| j        dk    r,dD ])}|                    t          j        |                     *|                     | j        |           d S )Nc              3   B   K   | ]}|                               V  d S r   )rf  )rz  rh  r  s     r   ri  z;NoneInfoExtractTests.check_files_present.<locals>.<genexpr>;  sC       ; ; MM)$$; ; ; ; ; ;r   rj  r   )r+  r   r(  )rl  r   r   rm  rk  discardrU   rn  )r   r  	got_pathsrf   s    `  r   check_files_presentz(NoneInfoExtractTests.check_files_present:  s     ; ; ; ;\),,11&99; ; ; ; ;	 !V++J 6 6!!',t"4"45555+Y77777r   c              '     K   t          j        t                    dz  }d| j        _        | j                                        D ]}|D ]}t          ||d            t          j        |          5  | j        	                    |d           | 
                    |           |V  d d d            d S # 1 swxY w Y   d S )Nextractall_noner   r}  r^   )r   r   rd   rH   ro  r   setattrr   r  ru  ru  )r   
attr_namesr  r  r]  s        r   extract_with_nonez&NoneInfoExtractTests.extract_with_noneD  s     l7##&77h))++ 	1 	1F' 1 1		400001$$ 	 	HO<<<$$S)))III	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   16B44B8;B8c                 N   t          j        t                                                    j        }|                     d          5 }t          j        |                              d          D ]}|                     |          5  	 |                                j        }|                     |                                j        |           n%# t          $ r |
                                s Y nw xY wd d d            n# 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nre  rj  rf   )r   r   rd   r  st_mtimerz  rm  r  assertGreaterEqualr  
is_symlink)r   nowr  rf   re  s        r   test_extractall_none_mtimez/NoneInfoExtractTests.test_extractall_none_mtimeP  s    l7##((**3##G,, 
	KS))..v66 	K 	K\\t\,, K KK $		 4 //		0DcJJJJ # " " "#00 "!" ""K K K K K K K K K K K K K K K	K
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	Ks[   A DD C!.D C1	.D 0C1	1D 4D DDDDD!Dc                    t          j        t                                                    j        }t          j        t                    dz  }|                    d           |                                j        }|                     d          5 }t          j        |                              d          D ]}|                     |          5  |	                                r.| 
                    |                                j        |           nA|                                r-| 
                    |                                j        |           d d d            n# 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nregular_filer   r   rj  r|  )r   r   rd   r  r  
write_textrz  rm  r  is_dirrU   is_file)r   dir_moder  regular_file_moder  rf   s         r   test_extractall_none_modez.NoneInfoExtractTests.test_extractall_none_mode`  s    <((--//7|G,,~=###(--//7##F++ 	<sS))..v66 < <\\t\,, < <{{}} <(()<hGGGG <(()<):< < <	< < < < < < < < < < < < < < <<	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<s8   A E:BE E: E$$E:'E$(E::E>E>c                 d    |                      d          5  	 d d d            d S # 1 swxY w Y   d S )Nr   rz  r   s    r   test_extractall_none_uidz-NoneInfoExtractTests.test_extractall_none_uidp  }    ##E** 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   %))c                 d    |                      d          5  	 d d d            d S # 1 swxY w Y   d S )Nr   r  r   s    r   test_extractall_none_gidz-NoneInfoExtractTests.test_extractall_none_gidt  r  r  c                 d    |                      d          5  	 d d d            d S # 1 swxY w Y   d S )Nrg  r  r   s    r   test_extractall_none_unamez/NoneInfoExtractTests.test_extractall_none_unamex  }    ##G,, 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  c                 d    |                      d          5  	 d d d            d S # 1 swxY w Y   d S )Nr  r  r   s    r   test_extractall_none_gnamez/NoneInfoExtractTests.test_extractall_none_gname|  r  r  c                 j    |                      dddd          5  	 d d d            d S # 1 swxY w Y   d S )Nr   r   rg  r  r  r   s    r   test_extractall_none_ownershipz3NoneInfoExtractTests.test_extractall_none_ownership  s    ##E5'7CC 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   (,,)r    r!   r"   rk  rm  rU  rY  ru  r   rz  r  r  r  r  r  r  r  r+   r   r   rb  rb  "  s         A A [A ' ' ['8 8 8 	 	 ^	K K K < < <             r   rb  c                       e Zd ZdZdS )NoneInfoExtractTests_Datar   Nr    r!   r"   rk  r+   r   r   r  r    s        r   r  c                       e Zd ZdZdS )!NoneInfoExtractTests_FullyTrustedr}  Nr  r+   r   r   r  r    s        'r   r  c                       e Zd ZdZdS )NoneInfoExtractTests_TarrH   Nr  r+   r   r   r  r    s        r   r  c                       e Zd ZdZdS )NoneInfoExtractTests_DefaultNr  r+   r   r   r  r    s        r   r  c                       e Zd Zd Zd ZdS )NoneInfoTests_Miscc           
         t          j                    }t          j        t          j        t          j        fD ]&}|                     |          5  t          j        |d|          }|                    t                    }	 |
                    |           dD ]}|                     |          5   |j        di |d i}|                     t          |           5  |
                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   n"# t          $ r |t          j        k    rn Y nw xY wd d d            n# 1 swxY w Y   (d S )N)	tarformatr   )r6  r   r   )re  r   r   r   rg  r  r\  r+   )r$   r   r'   r   ru  r  r  r&   r  r#   r  r   r  rR  r~  )r   bior  rH   rZ   r]  rR  s          r   test_addzNoneInfoTests_Misc.test_add  s=   jll!.0B!,. 	6 	6I	22 6 6l3SKKK..116KK(((&6 6 6	!\\I\>> 6 6'6w'K'K)T9J'K'KH!%!7!7
;D"H "H 6 6 #H 5 5 56 6 6 6 6 6 6 6 6 6 6 6 6 6 66 6 6 6 6 6 6 6 6 6 6 6 6 6 66 !    G$888  	6 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6s~   2ED$E2,D	D 4D	 DD	DD	EDEDE$E EEEE	E	c           
      4   dhdhdhdhdhdhddhddhfD ]}|                      |          5  t          j        t          d	          5 }t	          j        t	          j                    d
d          }t          j        t          d|          5  |
                                 d d d            n# 1 swxY w Y   |                                D ]}|D ]}t          ||d            t	          j        t	          j                    d
d          }t          j        t          d|          5  |
                                 d d d            n# 1 swxY w Y   t          |                                                                                                |                                                                                                          D ]\  }}|dhk    r,t#          j        d|          r|                     |d           9|dhk    r,t#          j        d|          r|                     |d           l|dhk    r,t#          j        d|          r|                     |d           |dhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||
           |                     |d           |dhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||	           |                     |d           |dhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||
           |                     |d           |dhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||	           |                     |d           |ddhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||
           |                     |d           |ddhk    rs|                    d          r^|                    d          \  }	}
|                    d          \  }}|                     ||	           |                     |d           }|                     ||           	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nre  r   r   r   rg  r  )ry  rD   rt  r   r   r   r   s   2003-01-\d\ds
   ????-??-??s   \d\d:\d\d:\d\ds   ??:??:??s   .([r-][w-][x-]){3}s
   ??????????)   tarfile/   lars/   foo/   /s   [0-9]+)   /tarfile   /users   /bar   1000/s   None   /100)r  r  r  r  )r  r  r  r  )r  r'   r&   r#   r$   ri   r   r   r   r   rp   r   rx  r  r   r   r  rematchrU   rf  r   endswith)r   ry  rH   tio_prevr  r]  tio_newr  gotexp_user	exp_groupgot_user	got_groups                r   r   zNoneInfoTests_Misc.test_list  s   
 $9vh%#9wi!7+eW-=? <	8 <	8J ,,*,55 98 98,w===98AD+BJLL'4PPP&sHh??  HHJJJ              !nn.. 9 9F%/ 9 9		488889*2:<<$OOO&sHg>>  HHJJJ              %():):)C)C)E)E)K)K)M)M)0)9)9)B)B)D)D)J)J)L)L&N &N .8 .8MHc!gY..28<Lh3W3W.((m<<<<#y00RX>PRZ5[5[0((k::::#x//BH2H5> 5>/((m<<<<#y00X5H5H<6> 6>0.6nnT.B.B+).1iioo+)((I>>>((9====#y00X5F5F=6? 6?0.6nnT.B.B+).1iioo+)((8<<<((I>>>>#w..83F3F%4( 4(..6nnT.B.B+).1iioo+)((I>>>((7;;;;#w..83D3Dg3O3O..6nnT.B.B+).1iioo+)((8<<<((G<<<<#w'777H<O<OF=H =H7.6nnT.B.B+).1iioo+)((I>>>((7;;;;#'777H<M<MF=H =H7.6nnT.B.B+).1iioo+)((8<<<((G<<<< ((37777].898 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98<	8 <	8s   V
AU4B/	#U4/B33U46B37A3U4*E	?U4EU4EPU4(V4U88V;U8<VV	V	N)r    r!   r"   r  r   r+   r   r   r  r    s7        6 6 64A8 A8 A8 A8 A8r   r  c                    	 | dd          }t           j        dd|d                  t           j        dd|d                  z  t           j        dt           j        t           j        z  t           j        d|d                  z  t           j        dd|d                  z  t           j        dd|d                  z  t           j        dt           j        t           j        z  t           j        d|d	                  z  t           j	        dd|d
                  z  t           j
        dd|d                  z  t           j        dt           j        t           j        z  t           j        d|d                  z  }|S )Nrt   r   )r`   -)r   r  )re  r  r}   Srw   r!        r?     )re  r  r  Tr(  )r  S_IRUSRS_IWUSRS_IXUSRS_ISUIDS_IRGRPS_IWGRPS_IXGRPS_ISGIDS_IROTHS_IWOTHS_IXOTHS_ISVTX)r   str_moderesults      r   _filemode_to_intr    sd    ABBxH1
%
%hqk
21
%
%hqk
231t|+ &qk++
 1
%
%hqk
23 1
%
%hqk
23 1t|+ &qk+	+ 1
%
%hqk
2
3 1
%
%hqk
23 1t|+ &qk++ ( Mr   c                   >    e Zd Z	 d Zd Zd ZddddddddZd ZdS )r  c                 6    t          j                    | _        d S r   )r$   r   r  r   s    r   r  zArchiveMaker.__init__  s    :<<r   c                 F    t          j        d| j                  | _        | S )Nr   rU  )r'   r(   r  tar_wr   s    r   	__enter__zArchiveMaker.__enter__  s    _#tx@@@
r   c                     | j                                          | j                                        | _        d | _        d S r   )r  rK   r  r   r4  )r   r  s     r   __exit__zArchiveMaker.__exit__  s6    
))++r   N)r\  r  hardlink_tor   rW   contentc                   	 t          |          } t          j        |          j        di |}	|8t	          |t                     r|                                }t          |          }|||	_        |t          |	j                  }|rt          |          |	_
        | t          j        }t          |          |	_        | t          j        }t          |          |	_        |                    d          r|t          j        }|||	_        |	                                rt%          j        |          }
nd }
| j                            |	|
           d S )Nr   r+   )r8  r'   r  r   r  r   rV   rW   rJ  r  r   rG  r  r  r  r]  r\  r  r$   r   r  r  )r   r   r\  r  r  r   rW   r  r  rZ   r6  s              r   r   zArchiveMaker.add#  sH   
	 4yy/'/$''/99&99'3'' +!..**w<<DGL-- 	2+D11GL!?D":G"?D";//G== 	#$,?DGL==?? 	j))GGG
7G,,,,,r   c                 \    	 t          j        | j                  }t          j        dd|i|S )Nr6  r+   )r$   r   r4  r'   r&   )r   r  r  s      r   r&   zArchiveMaker.openL  s1    Gj''|22C26222r   )r    r!   r"   r  r  r  r   r&   r+   r   r   r  r    s        	         
 !%4D$'- '- '- '- '-R3 3 3 3 3r   r  c                 <     t          j        d          |           S )NzWASI: Skip symlink test for now)r   skiprW  s    r   symlink_testr  W  s    ?x}>??BBBr   c                     | S r   r+   r  s    r   r  r  Z  s    r   c                      e Zd Z ej        e          dz  Zedz  Zeddd            Z		 	 d)dZ
d Zd*d
Zd Zd Zed             Zeej        d                         Zed             Zed             Zd Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zd Zd Zd Z d Z!d Z"d Z#d Z$d  Z%d! Z&d" Z'd# Z(d$ Z)d% Z*d& Z+d' Z,d( Z-dS )+TestExtractionFiltersouterdirr  T)
check_flagc             #   d  K   	 t          j        | j                  5  | j        dz  }|                    d           	 |                    | j        |           d | _        d| _        t          | j        	                    d                    | _
        | j
                            | j                   | j
                            |           n8# t          $ r+}|| _        d| _        t                      | _
        Y d }~nd }~ww xY w	 | V  |                                 n# |                                 w xY w| j        r| j        |                     | j
        t                                 |r(|                     |                                d           d d d            d S # 1 swxY w Y   d S )Nflagz
capture mer^   Frj  T)r   r  r  r  ru  r  raised_exceptionreraise_exceptionrl  rm  expected_pathsrs  r~  rK   rU   r  )r   rH   r_   r  	flag_pathr  s         r   check_contextz#TestExtractionFilters.check_contexth  s     	 .. 	1 	1.I  ...7t|F;;; )-%).&&)$-*<*<V*D*D&E&E##++DL999#++I6666  , , ,(+%)-&&)ee######,


				% ,++T0#%%888 1  !4!4!6!6EEE/	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1sT    F%CA4F%
D!C>9F%>DF%D F% D66A"F%%F),F)Nc                 ^   	 | j         r| j         t          j        t          j                            | j        |z                      }|                     || j                   | j        	                    |           |vt          j                    rct          j        dk    rSt          j        t          j        |                                j                            }|                     ||           |6t%          |t&                    r!|                    d          rt*          j        }|| j        |z                                  }t          j        |          }		 |	|k    r(|                     |                    |	                     n# t4          $ r!}
|
                    d|	d|            d }
~
ww xY w|t*          j        k    s|(|                     |                                           n|t*          j        k    r(|                     |                                           n|t*          j        k    r(|                     |                                            nG|t*          j!        k    r(|                     |"                                           ntG          |          |-|                     |                                j$        |           |(|                     |%                                |           |j&        D ]}| j        '                    |           d S )Nntr   z	expected=z, got=)(r  r   r   re   rf   normpathr  r   r  remover   	can_chmodr   r  rM  S_IMODEr  rU   r  r8  r  r'   r]  readlinkr   samefiler~  add_noterB  r  r  rL  is_fiforG  r  NotImplementedErrorre  r  parentsrs  )r   r   r\  r  r   rW   r  rf   r  r  r  parents               r   expect_filez!TestExtractionFilters.expect_file  s   5  	(''|BG,,T\D-@AABBdD/000""4(((	 3 5 5"'T//-TYY[[-@ A ABBCS$'''<JtS11<dmmC6H6H<?D!<$&0022C|J//Hs??OOCLL$:$:;;;   

1h11311222 W_$$OODLLNN++++W_$$OODKKMM****W%%%OODLLNN++++W_$$OODOO--....%d+++TYY[[0$777T^^--w777l 	0 	0F''////	0 	0s   !.F 
F<F77F<c                     	 | j         |z                                  |                     t          j                   fd| j        D             | _        d S )Nr\  c                 &    h | ]}|j         v|S r+   )r  )rz  rh  	tree_paths     r   	<setcomp>z8TestExtractionFilters.expect_any_tree.<locals>.<setcomp>  s0     
 
 
	)) )))r   )r  resolver  r'   r]  r  )r   r   r  s     @r   expect_any_treez%TestExtractionFilters.expect_any_tree  sm    ;\D(1133	999
 
 
 
*
 
 
r   r  c                     |                      ||          5  | j        | j        	 d d d            n# 1 swxY w Y   d| _        | j        S r  )r  r  r  )r   exc_type
message_res      r   expect_exceptionz&TestExtractionFilters.expect_exception  s    ##Hj99 	, 	,$0++ 1	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, "'$$s   377c                 0   t                      5 }|                    d           d d d            n# 1 swxY w Y   dD ]W}|                     |                                |          5  |                     d           d d d            n# 1 swxY w Y   Xd S )Nz
benign.txt)r}  rH   r   r  r   r  r&   r  r   r  r_   s      r   test_benign_filez&TestExtractionFilters.test_benign_file  s   ^^ 	"sGGL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"4 	/ 	/F##CHHJJ77 / /  .../ / / / / / / / / / / / / / /	/ 	/s   155(B

B	B	c                    t                      5 }|                    | j        dz             d d d            n# 1 swxY w Y   |                     |                                d          5  |                     d           d d d            n# 1 swxY w Y   dD ]}|                     |                                |          5  t          | j                                      d          r@t          | j                                      d          }|                     | d           n | 	                    t          j        d           d d d            n# 1 swxY w Y   d S )Nzescaped.evilr}  z../escaped.evilrH   r   r   z/escaped.evilz+['"].*escaped.evil['"] has an absolute path)r  r   r  r  r&   r  r8  rf  lstripr  r'   rc  )r   r  r_   outerdir_strippeds       r   test_absolutez#TestExtractionFilters.test_absolute  s/    ^^ 	4sGGDMN2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 

O<< 	0 	0.///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 $ 	K 	KF##CHHJJ77 K Kt}%%0055 K ),DM(:(:(A(A#(F(F%$$(9%H%H%HIIII ))1IK K KK K K K K K K K K K K K K K K	K 	Ks2   9= =,BBBBEE	 E	c                    t                      5 }|                    dd           |                    dd           |                    d           d d d            n# 1 swxY w Y   t          j                    rv|                     |                                d          5  | j        (|                     t                     	 d d d            d S | 	                    dd           | 	                    dd           | 	                    d           	 d d d            n# 1 swxY w Y   |                     |                                d	          5  |                     t          j        d
           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t          j        d           d d d            d S # 1 swxY w Y   d S |                     |                                d          5  | 	                    d           d d d            n# 1 swxY w Y   |                     |                                d	          5  | 	                    d           d d d            n# 1 swxY w Y   |                     |                                d          5  | 	                    d           d d d            d S # 1 swxY w Y   d S )Ncurrentr  r  r  z
current/..parent/evilr}  r  rH   T'parent/evil' would be extracted to ['"].*evil['"], which is outside the destinationr   zK'parent' would link to ['"].*outerdir['"], which is outside the destination)r  r   r   r  r  r&   r  r  ra  r  r'   rj  rk  r   r  s     r   test_parent_symlinkz)TestExtractionFilters.test_parent_symlink  s    ^^ 
	#s
 GGI#G... GGHG666GGM"""
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	#  "" !	0##CHHJJ@@ 0 0(4 ))/::: 0 0 0 0 0 0 0 0 $$Y3$???$$X,$GGG$$Y////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ##CHHJJ66 : :%%39: : :: : : : : : : : : : : : : : : ##CHHJJ77 : :%%79: : :: : : : : : : : : : : : : : : : : : ##CHHJJ@@ 0 0  ///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0##CHHJJ66 0 0  ///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0##CHHJJ77 0 0  ///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0s   AAA#&A#&#D&AD&&D*-D*!FF
F
9!G''G+.G+H>>II1JJJK))K-0K-c                 >	   t                      5 }d}t          j        dk    rd}ndt          j        v rct          j        | j        j        d          }d}t          t          | j
                            |z   }||z
  t          |          |z   z  }d|z  }nt          d          d}d}	|D ]}
|                    t          j                            ||          t          j        d	
           |                    t          j                            ||
          |           t          j                            ||          }t          j                            |	|
          }	t          j        j        g |dR  }dgt          |          z  }|                    |t          j        j        |            |                    dt          j                            |d                     |                    dt          j                            dd                     |                    dd           |                    dd           d d d            n# 1 swxY w Y   |                     d          5  |                     |                                dd          5  t          j        dk    r"|                     t*          t,          f           n| j        r|                     t0                     n{|                     |           |                     dd           |                     dd           |                     dt          j                   |                     d|           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   dD ]}|                     |          5  |                     |                                |          5  |                     t8          t0          f          }t;          |t8                    rQt          j        dk    r|                     |j        d           n%|                      |j!        tB          j"                   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nabcdefghijklmnopr~  dddddddddddddddddddddddddPC_PATH_MAXrt   dz1Need to guess component length for {sys.platform}r   
drwxrwxrwxr  r  llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllr  escapeflaglinkr  r  	overwrite)r  zescape/newfilenewr}  F)r_   r  z
../newfiler  r   r
  r^   )r!  r     )#r  r   r  re   pathconf_namespathconfr  r  rV   r8  r  r  r   rf   rg   r'   r]  r  r  r&   r  r	  ra  r  ra  r   r  rG  r  r  r   winerrorrU   errnoENAMETOOLONG)r   r  steps	componentmax_path_lenpath_sep_lendest_lencomponent_lenrf   	step_pathilinkpathparent_segmentsr_   r  s                  r   test_realpath_limit_attackz0TestExtractionFilters.test_realpath_limit_attack!  s   
 ^^ '	5s
 'E|w&&$		""333!{4=+?OO s4<0011L@!-!8c%jj<>W X-/		)*]^^^DI 7 7T955GO)  + + +T1--)DDDw||D)44GLLA66		
 w|4U4G444H#fs5zz1OGGH)GGHHHGGHh)E)EGFFF GGJBGLL6,J,JGKKKGGJG444GG$eG444O'	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5 '	5R ll?++ 	< 	<  O,1 ! 3 3	< 	< |w&&%%'8/&JKKKK& 	<%%h//// $$Y///  [ AAA  u ===   @@@   ;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<  $ 
	H 
	HFf%% 	H 	Ht'9'9#((**V'9'T'T 	H 	H++Wh,?@@c7++ H|w.. clK@@@@((E4FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H
	H 
	Hs   H?II!I:+N%CN5NN	NN		NNN<*R&BQ:.R:Q>>RQ>RR	R	c                    t          j                    rEt          j                            t
          d          }t          j        |           t          j        dt          j                            |d                     t          t          j                            |ddd          d          5  	 d d d            n# 1 swxY w Y   t          j        	                    t          j                            |d                    rd}nPt          j        	                    t          j                            |dd                    rd}nt          d	          t                      5 }|                    dd
           |                    dd
           |                    d           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    rD|                     dd
           |                     dd
           |                     d           n*|                     d           |                     d           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    r!|                     t           j        d           n*|                     d           |                     d           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    rD|r!|                     t           j        d           nK|                     t           j        d           n*|                     d           |                     d           d d d            d S # 1 swxY w Y   d S )Nresolution_testr  r  r  r-  r   TFz#Could not determine link resolutionr  zcurrent/parentr  r}  r  r  zcurrent/rH   r  r   zS'current/parent' would link to ['"].*outerdir['"], which is outside the destination)r   r  re   rf   rg   rd   r   r  r&   r  r  r  r   r  r  r  r'   rj  rk  )r   testpathdotdot_resolves_earlyr  s       r   test_parent_symlink2z*TestExtractionFilters.test_parent_symlink2k  s     "" 	Lw||G->??HHX JsBGLL9==>>> bgll8YfEEsKK                 w~~bgll8V<<== 	L )-%%XtV D DEE L ).%%$%JKKK^^ 
	#s GGI#G... GG$G666GGM"""
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 
	# 

O<< 	0 	0$&& 0  s ;;;  d ;;;  ++++  ,,,  ///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 

E22 
	0 
	0$&& 	0%%7,- - - -   ,,,  ///
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 
	0 

F33 	0 	0$&& 0( 1))#;01 1 1 1 ))#?01 1 1 1   ,,,  ///%	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s^   1B??CC(AF88F<?F<+BI99I= I=,ALLL
BOO Oc                    t                      5 }|                    d| j                   |                    d           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    r2|                     d| j                   |                     d           n|                     d           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    r!|                     t          j
        d           n|                     d           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t          j        d	           d d d            d S # 1 swxY w Y   d S )
Nr  r  r  r}  r  rH   r  r   &'parent' is a link to an absolute path)r  r   r  r  r&   r   r  r  r  r'   rj  rb  r  s     r   test_absolute_symlinkz+TestExtractionFilters.test_absolute_symlink  s    ^^ 	#sGGHG777GGM"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 

O<< 	0 	0$&& 0  dm DDD  ++++  ///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 

E22 	0 	0$&& 0%%7,- - - -   ///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 

F33 	: 	:!!)8: : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:sI   2AAA AC''C+.C+A
E00E47E4#!GGGc                    t                      5 }|                    d| j        dz             d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t          d           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t          d           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t          j        d           d d d            d S # 1 swxY w Y   d S )	Nr  r  r  r}  z.*foo. not foundrH   r   r7  )	r  r   r  r  r&   r  ra  r'   rb  r  s     r   test_absolute_hardlinkz,TestExtractionFilters.test_absolute_hardlink  sl    ^^ 	AsGGH$-%*?G@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 

O<< 	@ 	@!!(,>???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 

E22 	@ 	@!!(,>???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 

F33 	: 	:!!)8: : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:sC    ;??.BBB	C11C58C5$!EEEc                    t                      5 }|                    dd           d d d            n# 1 swxY w Y   	 |                     |                                d          5  t	          j                    rMt          | j        t                    r| 	                    t                     n| 
                    dd           n	 d d d            n# 1 swxY w Y   n# t          $ r Y nw xY wdD ]b}|                     |                                |          5  | 	                    t          j        d           d d d            n# 1 swxY w Y   cd S )N../mooz..//tmp/moor  r}  r^   r
  zH'../moo' would be extracted to '.*moo', which is outside the destination)r  r   r  r&   r   r  r  r  ra  r  r  r'   rj  r  s      r   test_sly_relative0z(TestExtractionFilters.test_sly_relative0  s'    ^^ 	8sGGHG777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8	##CHHJJ#GG  (** !$"7II 
M --o>>>>((m(LLLL                  	 	 	D	 $ 	- 	-F##CHHJJ77 - -%%7,- - -- - - - - - - - - - - - - - -	- 	-sT   377)C" (A"C
C" CC" CC" "
C/.C/!EE	E	c                    t                      5 }|                    d           |                    dd           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     dt
          j                   t          j                    r|                     dd	           d d d            n# 1 swxY w Y   d
D ]b}|                     |                                |          5  | 	                    t
          j
        d           d d d            n# 1 swxY w Y   cd S )Nztmp/ztmp/../../mooztmp/../..//tmp/moor  r}  tmpr  r<  ztmp/../../tmp/moor
  zU'tmp/../../moo' would be extracted to ['"].*moo['"], which is outside the destination)r  r   r  r&   r  r'   r]  r   r  r  rj  r  s      r   test_sly_relative2z(TestExtractionFilters.test_sly_relative2  s    ^^ 	FsGGFOOOGGO0DGEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 

O<< 	K 	KU999$&& K  6I JJJ	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K
 $ 	% 	%F##CHHJJ77 % %%%3$% % %% % % % % % % % % % % % % % %	% 	%s6   -AAA;ACCC
!D77D;	>D;	c           	         t                      5 }|                    dd           |                    dt          j                            dd                     |                    dt          j                            d	dd          
           d d d            n# 1 swxY w Y   dD ]}|                     |                                |          5  |                     dd           |                     dd           t          j	                    r|                     ddd           n|                     dd           d d d            n# 1 swxY w Y   d S )Ntargetdir/targetr!  r  linkdir/hardlink	targetdirr  r  linkdir/symlinkr  r  rH   r   r}  z../targetdir/targetrW   r  
r  r   re   rf   rg   r  r&   r  r   r  r  s      r   test_deep_symlinkz'TestExtractionFilters.test_deep_symlink(  s   
 ^^ 	.sGG&QG///GG&BGLLX5' 5'G ( ( ( GG%"',,k83- 3-G . . .	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 5 	@ 	@F##CHHJJ77 @ @  !3! <<<  !3! <<<(** @$$%6Q0E % G G G G $$%6Q$???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@s%   BBB"%B"A2EE	E	c                    t                      5 }|                    dd           |                    dt          j                            dd                     |                    dd	           |                    d
t          j                            dd                     |                    dt          j                            dd                     d d d            n# 1 swxY w Y   dD ]}|                     |                                |          5  |                     dd	           |                     d
d	           |                     dd	           t          j	                    r1|                     ddd           |                     ddd           n.|                     dd	           |                     dd	           d d d            n# 1 swxY w Y   d S )NrE  hardlinkr  symlink2linkdir	hardlink2rB  r!  r  rC  rD  r  r  zlinkdir/hardlink2r  rF  rG  rH  r  s      r   test_chainsz!TestExtractionFilters.test_chains@  s    ^^ 	YsGG%*G===GGJ27<<;,( ,(G ) ) )GG&QG///GG&BGLLh4W4WGXXXGG'RW\\)Y5W5WGXXX	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 	Y 5 	9 	9F##CHHJJ77 9 9  !3! <<<  !3! <<<  !41 ===(** 9$$%6Q0: % < < <$$Za0C % E E E E $$%6Q$???$$Za$8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9	9 	9s%   CC))C-0C- B8G$$G(	+G(	c           	      P   t                      5 }|                    d           |                    d           |                    dt          j                            dd                     |                    dt          j                            ddd	                     |                    dd
           |                    dt          j                            dd                     d d d            n# 1 swxY w Y   |                     |                                d          5  t          j                    s | 	                    t          j                   nut          j        dk    r | 	                    t          j                   nE| 	                    t          j        d          }|                     |j        t          j                   d d d            n# 1 swxY w Y   dD ]2}|                     |          5  |                     |                                |          5  t          j                    s@|                     d           |                     d           |                     d           no|                     d           |                     d           |                     dd           |                     dd           |                     dd
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   4d S )Nz	a/t/dummyzb/cr   r  r  zc/escaper  	link_herer   boomr  r  r   r~  zJlink 'boom' would be extracted as a copy of 'c/escape', which was rejected)rH   r}  zc/z
a/t/escapez../../link_here)r  r   re   rf   rg   r  r&   r   r  r  r'   rk  r   r  rd  r7  	__cause__r  r  )r   r  r  r_   s       r   test_sneaky_hardlink_fallbackz3TestExtractionFilters.test_sneaky_hardlink_fallbackZ  s   
 ^^ 	Es GGK   GGDMMMGGCBGLLc$:$:G;;;GGJ27<<d8C,E ,EG F F F GGCCG((( GGFS((C(CGDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E" 

F33 	K 	K(** K %%79 9 9 9((%%g&IJJJJ))-78 8 %%ak&-&IK K K	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K" - 	: 	:Ff%% 
: 
:t'9'9#((**f'M'M 
: 
: ,.. 	:$$[111$$T***$$T****$$[111$$T***$$\>O$PPP$$V8I$JJJ$$SS$999
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: 
:	: 	:s\   C"C==DD0B)G%%G),G)
)L3CL6LLL	L
LL	 L	c                 <   t                      5 }|                    dt          j                            ddddd                     |                    dd           d d d            n# 1 swxY w Y   dD ]}|                     |                                |          5  t          j                    rM| 	                    dd           |dk    r| 	                    dd           n| 	                    dd	           n	 d d d            n# 1 swxY w Y   d S )
Nr  rl  r  z	link-herer  r  rF  r   zlink/link/../../link-here)
r  r   re   rf   rg   r  r&   r   r  r  r  s      r   test_exfiltration_via_symlinkz3TestExtractionFilters.test_exfiltration_via_symlink  s    ^^ 	-sGGHffdDR])^)^G___GGFtG,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 5 	 	F##CHHJJ77 
 
(** 	$$V$===''((k(JJJJ((4O ) Q Q Q Q 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
	 	s%   AA++A/2A/"A"DD	D	c                 >   t                      5 }|                    dd           |                    dd           |                    dd           |                    dd	           d d d            n# 1 swxY w Y   d
D ]}|                     |                                |          5 }t	          j                    s|                     d           nc|dk    r/|                     dd	           |                     dd           n.|                     dd	           |                     dd           t          j        dk    r7|j	        
                                j        }|                     |dz  d           d d d            n# 1 swxY w Y   d S )Nza/pwnr  r  za/pwn/r  r   zx/../za/xz../rF  r   r~  r  )r  r   r  r&   r   r  r  r   r  r  r  r  rM  )r   r  r_   ccr  s        r   test_chmod_outside_dirz,TestExtractionFilters.test_chmod_outside_dir  s4   
 ^^ 
	/sGGGG,,, GGH<G000GGGG000 GGEuG...
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 
	/ 5 	@ 	@F##CHHJJ77 @2 ,.. B$$X....v%%$$Uu$===$$W$====$$Uu$===$$W$AAA<7** k..008G''%???@ @ @ @ @ @ @ @ @ @ @ @ @ @ @	@ 	@s%   AA88A<?A<0CFF	F	c                 4   t                      5 }|                    d           |                    d           |                    dd           |                    dd           d d d            n# 1 swxY w Y   dD ]}|                     |                                |          5 }|                     d           |                     d           |                     d           |                     d           d d d            n# 1 swxY w Y   d S )	Ndir/zdir/../afilelink1r  link2zdir/../dir/../afilerF  afiler  )r   r  r_   rY  s       r   test_link_fallback_normalizesz3TestExtractionFilters.test_link_fallback_normalizes  s    ^^ 	@sGGFOOOGGN###GGGG888GGG)>G???		@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 5 	* 	*F##CHHJJ77 *2  (((  )))  )))  )))	* * * * * * * * * * * * * * *	* 	*s%   AA44A8;A8+ADD	D	c                 t
   t                      5 }|                    dd           |                    dd           |                    dd           |                    dd	           |                    d
d           |                    dd           d d d            n# 1 swxY w Y   t          j                            t
          d          }t          |d          5  	 d d d            n# 1 swxY w Y   	 	 t          j        |t          j        |          j	        t          j
        z             nM# t          $ r@}|j        t          t          dd          k    r|                     d           n Y d }~nd }~ww xY wt          j        |          j	        t          j
        z  }t          j        |           n# t          j        |           w xY wt          j        |           t          j        |t          j        |          j	        t          j
        z             t          j        |          j	        t          j
        z  }t          j        |           |                     |                                d          5  |r|                     dd           n|                     dd           |                     dd           |                     dd           |                     dd	           |                     d
d           |r|                     dd           n|                     dd           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     dd           |                     dd           |                     dd           |                     dd	           |                     d
d           |                     dd           d d d            n# 1 swxY w Y   |                     |                                d          5  t          j        t          j        | j                                        j	                            }|                     dd           |                     dd           |                     dd           |                     dd           |                     d
d           |                     d|           d d d            d S # 1 swxY w Y   d S )Nall_bitsr  r   	perm_bitsz
?rwxrwxrwxexec_group_otherz
?rw-rwxrwxread_group_onlyz
?---r-----no_bitsz
?---------r\  z
?---rwsrwtztmp.filer   EFTYPEr   z?chmod() failed with EFTYPE: regular users cannot set sticky bitr}  z
?rwsrwsrwxz
?---rwsrwxrH   z
?rwxr-xr-xz
?rw-r-xr-xz
?---r-xr-xr   z
?rw-r--r--z
?rw-r-----z
?rw-------)r  r   re   rf   rg   rd   r&   rw  r  r  r  r  r$  r=  r  rq  r   r   r  r  rM  r  r  )r   r  tmp_filenamer  have_sticky_fileshave_sticky_dirsnormal_dir_modes          r   
test_modesz TestExtractionFilters.test_modes  s|    ^^ 	/sGGJ\G222GGKlG333GG&\G:::GG%LG999GGILG111GGFG...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ w||GZ88,$$ 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 		$
..6EG G G G   9x ; ;;; MM #H I I I I I I I I I	 "$!6!6!>!MIl####BIl####

rw|44<t|KLLLGL119DLH


O<< 	< 	<  @  , ????  , ???[|<<</lCCC.\BBBY\::: <  l ;;;;  l ;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 

E22 	8 	8Zl;;;[|<<</lCCC.\BBBY\:::V,777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 

F33 	; 	;"mDL""$$,-. -. / /OZl;;;[|<<</lCCC.\BBBY\:::V/:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   BB&&B*-B*&C44C8;C89D; :G ;
F6F ;G  F)G GB?MMM	BP  P$'P$CT--T14T1c                 P   t                      5 }|                    dt          j                   d d d            n# 1 swxY w Y   dD ]z}|                     |                                |          5  t          t          d          r"|                     dt          j                   n	 d d d            n# 1 swxY w Y   {|                     |                                d          5  | 	                    t          j
        d           d d d            d S # 1 swxY w Y   d S )Nr  r  )r}  rH   mkfifor   z'foo' is a special file)r  r   r'   rL  r  r&   r   re   r  r  ra  r  s      r   	test_pipezTestExtractionFilters.test_pipe  s   ^^ 	2sGGE 0G111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 - 	 	F##CHHJJ77  2x(( $$U1A$BBBB                

F33 	+ 	+!!()+ + +	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s3   "=AA49B99B=	 B=	-!DD"Dc                 x   t           j        t           j        t           j        fD ]}t          j        d          }||_        t          j        |d          }|                     ||           t          j        |d          }| 	                    |j        |           | 
                    t           j                  5 }t          j        |d           d d d            n# 1 swxY w Y   |                     |j        j        t           j                   | 	                    |j        j        j        d           d S )Nr  r   )r'   rL  rF  rA  r  r\  rh  r'  rQ  rU   r  ra  rU  r7  rs  rZ   r   )r   special_typerZ   trustedrH   cms         r   test_special_filesz(TestExtractionFilters.test_special_files,  sK    $,gowN 
	? 
	?Loe,,G'GL27B??GMM'7+++$Wb11CSX|444""7#;<< 1#GR0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1!!","6HHHR\16>>>>
	? 
	?s   <CC"	%C"	c                    t           j                            t                    5 }|                                D ]-}t          j        |d          }|                     ||           .	 d d d            d S # 1 swxY w Y   d S )Nr   )r'   r(   r&   r#   r   rh  r'  r   rH   rZ   filtereds       r   test_fully_trusted_filterz/TestExtractionFilters.test_fully_trusted_filter;  s    _!!'** 	1c>>++ 1 1"7DDh00001	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   AA66A:=A:c                 ^   t           j                            t          d          5 }|                                D ]W}t          j        |d          }|                     |j        |j                   |                     |j        |j                   X	 d d d            d S # 1 swxY w Y   d S NrD   rt  r   )	r'   r(   r&   r#   r   rQ  r'  r   r\  rv  s       r   test_tar_filterz%TestExtractionFilters.test_tar_filterB  s     _!!'K!@@ 	;C>>++ ; ;"-gr::hmW\:::hmW\::::;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   A-B""B&)B&c                    t           j                            t          d          5 }|                                D ]n}	 t          j        |d          }n# t           j        $ r Y *w xY w|                     |j        |j                   |                     |j	        |j	                   o	 d d d            d S # 1 swxY w Y   d S rz  )
r'   r(   r&   r#   r   rU  rR  r'  r   r\  rv  s       r   test_data_filterz&TestExtractionFilters.test_data_filterL  s    _!!'K!@@ 	;C>>++ ; ;&27B??HH*   HhmW\:::hmW\::::;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s5   B9AB9A'$B9&A''AB99B= B=c                    	 t                      5 }|                    d           d d d            n# 1 swxY w Y   t          j        |           5  |                     |                                d           5  |                     d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  )r  r   r
   check_no_warningsr  r&   r  r  s     r   test_default_filter_warns_notz3TestExtractionFilters.test_default_filter_warns_notX  sl   D^^ 	sGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.t44 	( 	(##CHHJJ55 ( (  '''( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(sB   266)B4:BB4B 	 B4#B 	$B44B8;B8c                     t          j        t          d          }d }||_        |                     |d           5  |                     d           d d d            d S # 1 swxY w Y   d S )Nr`   c                      | j         dk    r| S d S NrP   r?  rZ   rf   s     r   strict_filterzSTestExtractionFilters.test_change_default_filter_on_instance.<locals>.strict_filterb      |..tr   rP   )r'   r(   r#   rk  r  r  )r   rH   r  s      r   &test_change_default_filter_on_instancez<TestExtractionFilters.test_change_default_filter_on_instance`  s    ogs++	 	 	
 !.T** 	. 	._---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   AA"%A"c                 R   d }t          j        t          d          }t          j        t           j        dt          |                    5  |                     |d           5  |                     d           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                      | j         dk    r| S d S r  r?  r  s     r   r  zPTestExtractionFilters.test_change_default_filter_on_class.<locals>.strict_filterl  r  r   r`   rk  rP   )r'   r(   r#   r   r   rv  r  r  )r   r  rH   s      r   #test_change_default_filter_on_classz9TestExtractionFilters.test_change_default_filter_on_classk  s,   	 	 	
 ogs++w0C+M::< < 	2 	2##C.. 2 2  1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s6   B"B8BB	BB	BB #B c                      G d dt           j                  } |t          d          }|                     |d           5  |                     d           d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd ZdS )QTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclassc                      |j         dk    r|S d S r  r?  r   rZ   rf   s      r   rk  zcTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclass.extraction_filtery  s    <?22"N4r   Nr  r+   r   r   TarSubclassr  x  s#                 r   r  r`   rP   )r'   r(   r#   r  r  )r   r  rH   s      r   &test_change_default_filter_on_subclassz<TestExtractionFilters.test_change_default_filter_on_subclassw  s    	  	  	  	  	 '/ 	  	  	  k'3''T** 	. 	._---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s    A##A'*A'c                     t          j        t          d          }d|_        |                     |d           5  |                     t                     d d d            d S # 1 swxY w Y   d S )Nr`   r   )r'   r(   r#   rk  r  r  r  r  s     r   $test_change_default_filter_to_stringz:TestExtractionFilters.test_change_default_filter_to_string  s    ogs++ &T** 	- 	-!!),,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   A  A$'A$c                      fd}t                      5 }|                    d           |                    d           |                    d           d d d            n# 1 swxY w Y                        |                                |          5                       d                                d           d d d            d S # 1 swxY w Y   d S )Nc                                          |j                   | j        dk    r|                     d          S | j        dk    rd S | S )N	move_thismovedr?  ignore_this)r'  r  r   r   )rZ   rf   r   s     r   custom_filterz?TestExtractionFilters.test_custom_filter.<locals>.custom_filter  sQ    MM$---|{**G444|},,tNr   r  r  keepr  r  )r   r  r  s   `  r   test_custom_filterz(TestExtractionFilters.test_custom_filter  sY   	 	 	 	 	 ^^ 	sGGK   GGM"""GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 

M:: 	% 	%W%%%V$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s$   A A!!A%(A%+CCCc                 2   t                      5 }|                    d           d d d            n# 1 swxY w Y   |                     |                                d          5  |                     t
                     d d d            d S # 1 swxY w Y   d S )Nr  zbad filter name)r  r   r  r&   r  rR  r  s     r   test_bad_filter_namez*TestExtractionFilters.test_bad_filter_name  s   ^^ 	sGGENNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	

,=>> 	. 	.!!*---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   155$BBBc                 H    G d d          }t                      5 }|                    d           |                    dd           |                    d           d d d            n# 1 swxY w Y    |            5 }|                     |                                |          5  |                     d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j        d           |                     |j        d           d S )	Nc                        e Zd Zd Zd Zd ZdS )BTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilterc                     d| _         | S r  )num_files_processedr   s    r   r  zLTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__enter__  s    +,(r   c                     	 t          j        ||          }n# t           j        $ r Y d S w xY w| xj        dz  c_        |S )Nrt   )r'   rU  rR  r  r  s      r   __call__zKTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__call__  sY     %1'4@@GG*      44 ((A-((s    ++c                     d| _         d S )NT)done)r   exc_infos     r   r  zKTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__exit__  s     			r   N)r    r!   r"   r  r  r  r+   r   r   StatefulFilterr    sA            ! ! ! ! !r   r  goodbadr   r  rw   T)r  r   r  r&   r  rU   r  r  )r   r  r  r  s       r   test_stateful_filterz*TestExtractionFilters.test_stateful_filter  s   	! 	! 	! 	! 	! 	! 	! 	!  ^^ 	sGGFOOOGGEcG***GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ^ 	)##CHHJJ>> ) )  ((() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	:A>>>+T22222sH   AA**A.1A.?)C!(C
>C!
C	C!C	C!!C%(C%c                    d }d }d }d }d }t                      5 }|                    d           d d d            n# 1 swxY w Y   |                     |                    d          |          5  	 d d d            n# 1 swxY w Y   |                     |                    d          |          5  	 d d d            n# 1 swxY w Y   |                     |                    d          |          5  	 d d d            n# 1 swxY w Y   |                     |                    d          |          5  |                     t
          j                   d d d            n# 1 swxY w Y   |                     |                    d          |          5  |                     t                     d d d            n# 1 swxY w Y   |                     |                    d	          |          5  	 d d d            n# 1 swxY w Y   |                     |                    d	          |          5  |                     t
          j                   d d d            n# 1 swxY w Y   |                     |                    d	          |          5  |                     t                     d d d            n# 1 swxY w Y   |                     |                    d	          |          5  |                     t
          j                   d d d            n# 1 swxY w Y   |                     |                    d	          |          5  |                     t                     d d d            n# 1 swxY w Y   |                     |                    d
          |          5  |                     t
          j
                   d d d            n# 1 swxY w Y   |                     |                    d
          |          5  |                     t
          j                   d d d            n# 1 swxY w Y   |                     |                    d
          |          5  |                     t                     d d d            n# 1 swxY w Y   |                     |                    d
          |          5  |                     t
          j                   d d d            n# 1 swxY w Y   |                     |                    d
          |          5  |                     t                     d d d            n# 1 swxY w Y   |                     |                    d          |          5  |                     t                     d d d            d S # 1 swxY w Y   d S )Nc                 *    t          j        d          )Nzfailed with ExtractError)r'   ExtractErrorr  s     r   extracterror_filterzBTestExtractionFilters.test_errorlevel.<locals>.extracterror_filter  s    &'ABBBr   c                 *    t          j        d          )Nzfailed with FilterError)r'   rR  r  s     r   filtererror_filterzATestExtractionFilters.test_errorlevel.<locals>.filtererror_filter  s    %&?@@@r   c                      t          d          )Nzfailed with OSError)r  r  s     r   oserror_filterz=TestExtractionFilters.test_errorlevel.<locals>.oserror_filter  s    /000r   c                 *    t          j        d          )Nzfailed with base TarError)r'   TarErrorr  s     r   tarerror_filterz>TestExtractionFilters.test_errorlevel.<locals>.tarerror_filter  s    "#>???r   c                      t          d          )Nzfailed with ValueError)rR  r  s     r   valueerror_filterz@TestExtractionFilters.test_errorlevel.<locals>.valueerror_filter  s    5666r   r-  r   r  rt   rw   zboo!)r  r   r  r&   r  r'   r  rR  rR  r  r  r  )r   r  r  r  r  r  r  s          r   test_errorlevelz%TestExtractionFilters.test_errorlevel  s	   	C 	C 	C	A 	A 	A	1 	1 	1	@ 	@ 	@	7 	7 	7 ^^ 	sGGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 A 6 68KLL 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 A 6 68JKK 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 A 6 6GG 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 A 6 6HH 	4 	4!!'"2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 A 6 68IJJ 	. 	.!!*---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 A 6 68KLL 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 A 6 68JKK 	7 	7!!'"5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 A 6 6GG 	+ 	+!!'***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ A 6 6HH 	4 	4!!'"2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 A 6 68IJJ 	. 	.!!*---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 A 6 68KLL 	8 	8!!'"6777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 A 6 68JKK 	7 	7!!'"5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 A 6 6GG 	+ 	+!!'***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ A 6 6HH 	4 	4!!'"2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 A 6 68IJJ 	. 	.!!*---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 F ; ;=OPP 	- 	-!!),,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s1  A  AA5BB
B8CC
C
;D		DD> E**E.1E.GG
G
;H		HH> I**I.1I.KK
K
; L''L+.L+NN
N8 O$$O(+O( QQ	Q	:R!!R%(R% TT	T7UU"%U"V;;V?V?)NNNNN)r  ).r    r!   r"   r   r   rd   r  r  r   r  r  r   r  r  r  r  r  r   r  r0  r5  r8  r:  r=  r@  rI  rO  rU  rW  rZ  r`  rl  ro  rt  rx  r{  r}  r  r  r  r  r  r  r  r  r  r+   r   r   r  r  ^  s       
 w|G$$z1H G7; '1 '1 '1 '1 ^'1R BF'+*0 *0 *0 *0X
 
 
% % % %/ / /K K K2 00 00 \00d "FH FH #" \FHP T0 T0 \T0l : : \::: : :"  -  - \ -D % % \%& @ @ \@. 9 9 \92 1: 1: \1:f   \, @ @ \@>* * * C; C; C;J+ + +$? ? ?1 1 1; ; ;
; 
; 
;( ( (	. 	. 	.
2 
2 
2
. 
. 
.- - -% % %". . .3 3 3<E- E- E- E- E-r   r  c                   f    e Zd Zej                            ed          Zed             Z	d Z
d ZdS )OverwriteTeststestoverwritec                 P   t           j                            t          d          x}| _        |                     t          j        |           t          j	        |d          5 }t          j
        d          }d|_        |                    |t          j        d                     d d d            n# 1 swxY w Y   t           j                            t          d          x}| _        |                     t          j        |           t          j	        |d          5 }|                    |                    t           j        d                     d d d            n# 1 swxY w Y   t           j                            t          d          }|| _        |                     t          j        |           t          j	        |d          5 }t          j
        d          }d|_        |                    |t          j        d                     d d d            d S # 1 swxY w Y   d S )	Nztar-with-file.tarr   r  rv   s
   newcontentztar-with-dir.tarztar-with-implicit-dir.tarz	test/file)re   rf   rg   rd   ar_with_fileaddClassCleanupr   rq  r'   r&   r  rW   r  r$   r   ar_with_dirr  curdirar_with_implicit_dir)rT  rh  rH   r  s       r   rU  zOverwriteTests.setUpClass	  so   !w||G5HIIICI,a000\!S!! 	6S''AAFKK2:m44555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6
 !gll74FGGGCOI,a000\!S!! 	;SKKry&99:::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; GLL"=>>#$ I,a000\!S!! 	6S,,AAFKK2:m44555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s8   "AB22B69B64EE"%E"
AHH"Hc                 ,    t          j        |d          S r  )r'   r&   )r   rf   s     r   r&   zOverwriteTests.open  s    |D#&&&r   c                 >    |                     | j        d           d S )Nr}  r^   )ru  testdir)r   ars     r   ru  zOverwriteTests.extractall"  s     
dl?;;;;;r   N)r    r!   r"   re   rf   rg   rd   r  rm  rU  r&   ru  r+   r   r   r  r    s`        gll7O44G6 6 [6*' ' '< < < < <r   r  c                      e Zd ZeZej        ej        z  dz   ez   ej        z   dz   ez   ej        z   dz   ez   ej        z   dz   ez   ej        dz  z   ez   dz   ej        z   ej	        z   ej        ej
        z  z   ej        z   ej        dz  z   ej        dz  z   ej        dz  z   ez   ej        z   ej        dz  z   ez   ej        z   ej        ej        z  z   ej        dz  z   Zej        ej        z  d	z   ej        z   d
z   ej        z   d
z   ej        z   dz   ez   ej        dz  z   ez   dz   ej        z   ej	        z   ej        ej
        z  z   ej        z   ej        dz  z   ej        dz  z   ej        dz  z   ej        dz  z   ej        dz  z   Zej        ej        z  dz   ez   ej        z   dz   ez   ej        z   dz   ez   ej        z   dz   ez   ej        dz  z   ez   dz   ej        z   ej	        z   ej        ej
        z  z   ej        dz  z   Z ej        d                              ej                  Zdej        z  Zd ZddZd Zd Zd Zd Zd ZdS )OffsetValidationTestss   000755s   000001s      s   0011407    r?     s   0000755s   0000001s   0011327r(     s   0010070r  rf     c                     t          | j        d          5 }|                    |           d d d            d S # 1 swxY w Y   d S r  )r&   r#   r  )r   bufferrW  s      r   _write_bufferz#OffsetValidationTests._write_buffer  s    $,%% 	GGFOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rV  Nc                    t          | j        d          5 }t          j         d||          5 }|                                cd d d            cd d d            S # 1 swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nrs   r`   )r   r6  r  )r&   r#   r'   r   )r   r  rW  rH   s       r   _get_membersz"OffsetValidationTests._get_members  s    $,%% 	(!,   (~~''( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	(( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s4   A4AA4A	A4"A	#A44A8;A8c                     |                      t          j        d          5  |                                  d d d            d S # 1 swxY w Y   d S )Nr"  )r  r'   r  r  r   s    r   #_assert_raises_read_error_exceptionz9OffsetValidationTests._assert_raises_read_error_exception  s    ##F
 
 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   AA
Ac                     d| j         fd| j        fd| j        ffD ]\\  }}|                     |          5  |                     |           |                                  d d d            n# 1 swxY w Y   ]d S )Nposixr`  v7r  )invalid_posix_headerinvalid_gnu_headerinvalid_v7_headerr  r  r  )r   
tar_formatinvalid_headers      r   &test_invalid_offset_header_validationsz<OffsetValidationTests.test_invalid_offset_header_validations  s    d/0D+,4)*+
 	; 	;&J
 Z00 ; ;"">22288:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	;s   *A,,A0	3A0	c                 P   | j         | j        z   | j         z   }|                     |           |                                 }|                     t          |          d           |                     |d         j        d           |                     |d         j        d           d S )Nrt   r   rf  )valid_gnu_headerr  r  r  rU   rV   r   rV  r   r  r   s      r   (test_early_stop_at_invalid_offset_headerz>OffsetValidationTests.test_early_stop_at_invalid_offset_header  s    &)@@4CXX6"""##%%Wq)))*555*A.....r   c                     | j         | j        z   dz  }|                     |           |                     d          }|                     t          |          d           d S )Nr!  Tr  r   )r  
data_blockr  r  rU   rV   r  s      r   test_ignore_invalid_archivez1OffsetValidationTests.test_ignore_invalid_archive  sb    )DO;q@6"""###66Wq)))))r   c                    | j         | j        | j        z   df| j        | j        z   | j         dffD ]\  }}}|                     ||z              |                     d          }|                     t          |          d           |                     |d         j        d           |                     |d         j        |           d S )Nr   ru   Tr  rt   rf  )	r  r  r  r  r  rU   rV   r   rV  )r   first_blocksecond_blockexpected_offsetr   s        r   "test_ignore_invalid_offset_headersz8OffsetValidationTests.test_ignore_invalid_offset_headers  s     &(4?: (4?:&;
 	A 	A6K {\9:::''T'::GS\\1---WQZ_j999WQZ.@@@@!	A 	Ar   r   )r    r!   r"   r   r#   r'   rB  r  SPACErB  r  rS  rX  r  rN  r  r  r  r  ru  r  r  r  r  r  r  r  r  r  r  r+   r   r   r  r  &  s.       G 	g))
		%k	* 		 		 &k		* 	 	 &k	* 	 	 +

	 #
	# 	 {	# /	  ++
+!	,$ 
%	( +
)	, +
-	0 +/1	0 "1	"0 %,K1	04 +/5	4 "5	"4 %,K5	08 +-
-9	.< +
=	 H 	g))
	{	# 		 {		# 	 {	# 	 	 +

	 #
	# 	 {	# /	  ++
+!	,$ 
%	( +
)	, +
-	0 +/1	4 +/5	8 +
9	 D 	g))
		%k	* 		 		 &k		* 	 	 &k	* 	 	 +

	 #
	# 	 {	# /	  ++
+!	,$ +
%	 , 'wz22889KLL7,,J  ( ( ( (     ; ; ;/ / /* * *A A A A Ar   r  c                  8   t          j        t                     t          j        t                     t
          gat          t
          d          5 } |                                 }d d d            n# 1 swxY w Y   t          t          t          fD ]}|j        rt          j        |j                   t                              |j                   |                    |j        d          5 }|                    |           d d d            n# 1 swxY w Y   d S )Nrs   r   )r   rq  rd   re   r  r#   r  r&   rT   r-   r4   r:   r  r  )r[   r   rQ  rH   s       r   setUpModuler    sh   WK 9L	gt		 yy{{               w(    6 	 QY'''	***	4((  C		$                             	   s$   A11A58A5,DD	D	c                      t           j                            t                    rt	          j        t                     d S d S r   )re   rf   r  rd   r   r  r+   r   r   tearDownModuler    s9    	w~~g "!!!!!" "r   __main__)r$  r   re   r$   hashlibr   
contextlibr   randomr   r   rp  r  warningsr  r   unittest.mockr'   r  r   r   test.supportr   r	   r
   r0   r   r  r5   r=   r   rf   r9  TESTFNrd   r  r#  r#   rg   r/   r6   r<   r   r  r  rX   r0  r   requires_gzipr-   requires_bz2r4   requires_lzmar:   rA   TestCaserN   r   r   r   r   r   r   r   r   r0  r  r  r  r  r  r  r  r  r  r  r  r  r  r   rH  r_  rx  r  r  r  r  r  r  r	  r  r  r  r;  rO  ro  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'  rO  rb  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r    rE  r+   r   r   <module>r     s    



 				 				       % % % % % %         				                     " " " " " " & & & & & & ( ( ( ( ( (KKKK   DDDKKKK   DDDJJJJ   
CCCKKKK   DDD$ $ $ '//)*
+
+i
7o%	
'
=
)
)7<<!122
',,w 1
2
2	g/	0	0
',,w	
*
*gll7I.. G  G 
) ) ) ) ) ) ) ) % % % % % % % % & & & & & & & & % % % % % % % %	 	 	 	 	w 	 	 	U U U U UHh/ U U Un	 	 	 	 	- 	 	 		 	 	 	 	w 	 	 		 	 	 	 	- 	 	 	M1 M1 M1 M1 M1x* M1 M1 M1`	 	 	 	 	8X 	 	 		 	 	 	 	'8 	 	 		 	 	 	 	8X 	 	 	V1 V1 V1 V1 V1X V1 V1 V1rR. R. R. R. R.~ R. R. R.h    #X%6   	 	 	 	 	x!183D 	 	 	8 8 8 8 8g/1B 8 8 89 9 9 9 9x!183D 9 9 9
< < < < <^X%6 < < <|	 	 	 	 	> 	 	 		 	 	 	 	 	 	 		 	 	 	 	> 	 	 	&1 &1 &1 &1 &1Wh/ &1 &1 &1P	 	 	 	 	> 	 	 	, , , , , , , ,	 	 	 	 	> 	 	 	1 1 1 1 1x1B 1 1 1"^E ^E ^E ^E ^EXx0 ^E ^E ^EB6O 6O 6O 6O 6O 6O 6O 6Op9 9 9 9 9,(*; 9 9 9xT@ T@ T@ T@ T@,(*; T@ T@ T@nG G G G GG G G G<u' u' u' u' u'x0 u' u' u'p		 	 	 	 	Hi 	 	 		 	 	 	 	7I 	 	 		 	 	 	 	Hi 	 	 	(% (% (% (% (%mX%6 (% (% (%V7 7 7 7 7(O 7 7 78 8 8 8 8/ 8 8 8; ; ; ; ;(O ; ; ;O5 O5 O5 O5 O58$ O5 O5 O5d+& +& +& +& +&}h&7 +& +& +&\W. W. W. W. W. 1 W. W. W.t    Xz       GZ   % % % % %Xz % % %( ( ( ( (* ( ( ( WWR((*KLL'1 '1 '1 '1 '18$ '1 '1 ML'1TH8 H8 H8 H8 H8< H8 H8 H8VN N N N N N N NbL L L L L{H$5 L L L^G G G G G[("3 G G G$K K K K K[("3 K K K(I I I I I I I I(>% >% >% >% >%!2 >% >% >%@	 	 	 	 	X~x/@ 	 	 		 	 	 	 	G^X-> 	 	 		 	 	 	 	X~x/@ 	 	 	8* 8* 8* 8* 8*" 8* 8* 8*vx& x& x& x& x&x  x& x& x&va  a  a  a  a h' a  a  a H7B 7B 7B 7B 7B* 7B 7B 7Bt V$$&FGG@ @ @ @ @("3 @ @ HG@B* * * * *("3 * * *>	 	 	 WWR))+=>>WWR++-ABBwO wO wO wO wOx( wO wO CB ?>wOt%- %- %- %- %-8X. %- %- %-P` ` ` ` `8 ` ` `D     4h6G   ( ( ( ( ((<(0(9( ( (    3X5F       #7#+#4  \8 \8 \8 \8 \8* \8 \8 \8|  8C3 C3 C3 C3 C3 C3 C3 C3T ? C C C C  e- e- e- e- e-H- e- e- e-P< < < < <^2H4E < < <@XA XA XA XA XAH- XA XA XAv     "" " " zHMOOOOO sH   "A' 'A10A15A: :BBB BBB   B*)B*