
    7bh                        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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	 d dlZ	 d dlZ	 d dlZd
 Zej@                  jC                  ejD                        dz   Z#e#dz   Z$ ejJ                  d      Z&ej@                  jO                  e#d      Z(ej@                  jO                  e#d      Z)ej@                  jO                  e#d      Z*ej@                  jO                  e#d      Z+ej@                  jO                  e#d      Z,dZ-dZ.dZ/ G d d      Z0 ejb                          G d d             Z2 ejf                          G d d             Z4 ejj                          G d d             Z6 G d de0      Z7 G d  d!e7ejp                        Z9 G d" d#e2e9      Z: G d$ d%e4e9      Z; G d& d'e6e9      Z< G d( d)e7ejp                        Z= G d* d+e2e=      Z> G d, d-e4e=      Z? G d. d/e6e=      Z@ G d0 d1e7      ZA G d2 d3eA      ZB G d4 d5eBejp                        ZC G d6 d7e2eBejp                        ZD G d8 d9e4eBejp                        ZE G d: d;e6eBejp                        ZF G d< d=eAejp                        ZG G d> d?e2eG      ZH G d@ dAe4eG      ZI G dB dCe6eG      ZJ G dD dEe0ejp                        ZK G dF dGe2eK      ZL G dH dIe4eK      ZM G dJ dKe6eK      ZN G dL dMe2ejp                        ZO G dN dOe7ejp                        ZP G dP dQ      ZQ G dR dSeQe7ejp                        ZR G dT dUeQe7ejp                        ZS G dV dWe0      ZT G dX dYeTejp                        ZU G dZ d[e2eU      ZV G d\ d]e4eU      ZW G d^ d_e6eU      ZX G d` daeTejp                        ZY G db dce2eY      ZZ G dd dee4eY      Z[ G df dge6eY      Z\ G dh die0      Z] G dj dke4e]ejp                        Z^ G dl dme4e]ejp                        Z_ G dn doe2e]ejp                        Z` G dp dqe2e]ejp                        Za G dr dsejp                        Zb G dt duejp                        Zc G dv dweTejp                        Zd G dx dyeTejp                        Ze G dz d{e2ee      Zf G d| d}e4ee      Zg G d~ de6ee      Zh G d dee      Zi ej                   eked      d       G d dejp                               Zl G d dec      Zm G d d      Zn G d denejp                        Zo G d denejp                        Zp G d denejp                        Zq G d d      Zr G d derejp                        Zs G d de2erejp                        Zt G d de4erejp                        Zu G d de6erejp                        Zv G d dejp                        Zw G d dejp                        Zx G d dejp                        Zy G d dejp                        Zz ej                   eked      d       G d de7ejp                               Z| G d de4ejp                        Z}d Z~ ej                   eked      d       ej                   eked      d       G d dejp                                      Z G d de7ejp                        Z G d de7      Z G d deejp                        Z G d deejp                        Z G d deejp                        Z G d deejp                        Z G d dejp                        Zd Z G d d      Zej                  rd Znd Z G d dejp                        Z G dÄ dej                  ejp                        Z G dń dejp                        ZdǄ ZdȄ Zedk(  r ej"                          yy# e$ r dZY zw xY w# e$ r dZY w xY w# e$ r dZY w xY w# e$ r dZY w xY w)    N)sha256)contextmanager	ExitStack)Random)archiver_tests)support)	os_helper)script_helper)warnings_helperc                 4    t        |       j                         S N)r   	hexdigest)datas    ;/opt/python-3.12.12/usr/lib/python3.12/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                   h    e Zd ZeZdZej                  Zej                  j                  Z
ed        Zy)TarTest c                 4    | 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   ?   s6    GF99Doo%%G) )r   r   c                   `    e Zd ZeZdZerej                  ndZe	j                  j                  Zy)GzipTestgzN)r!   r"   r#   gzipnamer$   r   gzipGzipFiler'   r(   r)   gzopenr*   r,   r   r   r.   r.   I   s(    GF 4==dDoo$$Gr   r.   c                   `    e Zd ZeZdZerej                  ndZe	j                  j                  Zy)Bz2Testbz2N)r!   r"   r#   bz2namer$   r   r6   BZ2Filer'   r(   r)   bz2openr*   r,   r   r   r5   r5   P   s(    GF3;;4Doo%%Gr   r5   c                   `    e Zd ZeZdZerej                  ndZe	j                  j                  Zy)LzmaTestxzN)r!   r"   r#   xznamer$   r   lzmaLZMAFiler'   r(   r)   xzopenr*   r,   r   r   r;   r;   W   s(    GF 4==dDoo$$Gr   r;   c                       e Zd ZdZd Zd Zy)ReadTestr:c                 f    t        j                  | j                  | j                  d      | _        y )N	iso8859-1r    encodingr(   r'   r$   r    tarr   s    r   setUpzReadTest.setUpc   s!    <<499)46r   c                 8    | j                   j                          y r   )rI   closer   s    r   tearDownzReadTest.tearDowng   s    r   N)r!   r"   r#   r   rJ   rM   r,   r   r   rB   rB   _   s    F6r   rB   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      xr	  eed      d      d        Zy)UstarReadTestc                 F   | j                   j                  d      }| j                   j                  |      5 }|j                         }| j	                  t        |      |j                  d       | j	                  t        |      t        d       d d d        y # 1 sw Y   y xY w)Nustar/regtyperegular file extraction failed)	rI   	getmemberextractfilereadassertEquallensizer   sha256_regtyper   tarinfofobjr   s       r   test_fileobj_regular_filez'UstarReadTest.test_fileobj_regular_filem   sw    (($$_5XX!!'*d99;DSY46Yt_n46	 +**s   ABB c                 X   | j                   j                  dt        d       | j                   j                  d      }t	        t
        j                  j                  t        d      d      5 }|j                         }d d d        | j                   j                  |      5 }t        j                  |      }|j                         }| j                  |d       | j                  t        |      dd       | j                  |d   dd       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)	NrQ   r   filterrzfileobj.readlines() failedr   S   zOI will gladly admit that Python is not the fastest running scripting language.
)rI   extractTEMPDIRrS   r'   ospathjoin	readlinesrT   r%   TextIOWrapperrV   rW   )r   r[   fobj1lines1r\   fobj2lines2s          r   test_fileobj_readlinesz$UstarReadTest.test_fileobj_readlinesv   s    '&A(($$_5"'',,w8#>%__&F ? XX!!'*d$$T*E__&FVV02S[#02VBZ402 +* ?> +*s   ,D A+D D D)c                    | j                   j                  dt        d       | j                   j                  d      }t	        t
        j                  j                  t        d      d      5 }|j                         }d d d        | j                   j                  |      5 }t        t        j                  |            }| j                  |d       d d d        y # 1 sw Y   _xY w# 1 sw Y   y xY w)NrQ   r   r_   ra   zfileobj.__iter__() failed)rI   rd   re   rS   r'   rf   rg   rh   ri   rT   listr%   rj   rV   )r   r[   rk   rl   rm   rn   s         r   test_fileobj_iterzUstarReadTest.test_fileobj_iter   s    '&A(($$_5"'',,w8#>%__&F ?XX!!'*e"**512FVV/1 +* ?>**s   ,C 2C'C$'C0c                 2   | j                   j                  dt        d       t        t        j
                  j                  t        d      d      5 }|j                         }d d d        | j                   j                  d      }| j                   j                  |      5 }|j                         }|j                  d       | j                  d|j                         d       |j                  dd       | j                  d|j                         d       |j                  d	d
       | j                  d|j                         d       |j                  dd
       | j                  d|j                         d       |j                  d      }| j                  |dd d       |j                  dd       | j                  |j                  |j                         d       | j                  |j                         dd       |j                  |j                   d       | j                  d|j                         d       |j                  d       |j                         }|j                  d       |j                         }| j                  ||d       |j                  d       | j                  t        |j!                               |j                         d       |j                  d       | j                  t        |j!                               dz   |j                         d       |j                  d       |j!                         }| j                  |j                         |t        |      d  d       d d d        y # 1 sw Y    xY w# 1 sw Y   y xY w)NrQ   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)rI   rd   re   r'   rf   rg   rh   rU   rS   rT   seekrV   tellrX   ri   rW   readline)	r   r\   r   r[   textss1s2lines	            r   test_fileobj_seekzUstarReadTest.test_fileobj_seek   s   ' & 	 	("'',,w8$?499;D @ (($$_5XX!!'*d99;DIIaLQ		8:IIdAT499;=?IIeQT499;FHIIdAT499;FH		"AQT$35IIaOW\\499;68TYY[#KMIIw||mQ'Q		?AIIcN!BIIcN!BR8:IIaLS1499;9;IIcNS1C7DFIIaL==?DTYY[$s4yz*:9;O +*	 @? +*s   N  KN N
Nc                 n   | j                   j                  d      5 }t        j                  |      }|j	                         j                  d      }| j                  t        |      t               	 |j                  d       d d d        y # t        $ r | j                  d       Y %w xY w# 1 sw Y   y xY w)NrQ   rE   d   zseeking failed in text mode)rI   rT   r%   rj   rU   encoderV   r   rY   rz   AttributeErrorfailr   r\   r   s      r   test_fileobj_textzUstarReadTest.test_fileobj_text   s    XX!!/2d##D)D99;%%k2DYt_n=9		# 32 " 9 		789 32s*   AB+1BB(%B+'B((B++B4c                    | j                   j                  |      5 }| j                   j                  |      5 }| j                  |j                  |j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )rI   rT   rV   name)r   lnktyperegtypeabs        r   _test_fileobj_linkz UstarReadTest._test_fileobj_link   s_    XX!!'*aXX!!'*aQVVQVV, + +*** +*s"   A<'A0A<0A9	5A<<Bc                 (    | j                  dd       y )Nustar/lnktyperQ   r   r   s    r   test_fileobj_link1z UstarReadTest.test_fileobj_link1       Ar   c                 (    | j                  dd       y )N./ustar/linktest2/lnktypeustar/linktest1/regtyper   r   s    r   test_fileobj_link2z UstarReadTest.test_fileobj_link2        ; 9	;r   c                 (    | j                  dd       y )Nustar/symtyperQ   r   r   s    r   test_fileobj_symlink1z#UstarReadTest.test_fileobj_symlink1   r   r   c                 (    | j                  dd       y )N./ustar/linktest2/symtyper   r   r   s    r   test_fileobj_symlink2z#UstarReadTest.test_fileobj_symlink2   r   r   c                 (    | j                  dd       y )Nsymtype2rQ   r   r   s    r   test_issue14160zUstarReadTest.test_issue14160   s    
O<r   c                 H    | j                  d       | j                  d       y )Nbareaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)add_dir_and_getmemberr   s    r   test_add_dir_getmemberz$UstarReadTest.test_add_dir_getmember   s    ""5)""7+r   getuidgetgidz'Missing getuid or getgid implementationc           	      X   d }t        j                         5  t        j                  t        d      5 }t        j
                  |_        	 t        j                  |       |j                  ||       t        j                  |       	 d d d        t        j                  t              5 }| j                  |j                  |      |j                  |dz                d d d        d d d        y # t        j                  |       w xY w# 1 sw Y   xY w# 1 sw Y   8xY w# 1 sw Y   y xY w)Nc                 "    dx| _         | _        | S )Nr   )uidgidr[   s    r   r`   z3UstarReadTest.add_dir_and_getmember.<locals>.filter   s    (++GK'+Nr   wr_   /)r	   temp_cwdr(   r'   tmpnameUSTAR_FORMATformatrf   mkdiraddrmdirrV   rS   )r   r   r`   rI   s       r   r   z#UstarReadTest.add_dir_and_getmember   s    	 !gs+s$11
#HHTNGGDG0HHTN , g&#  MM$'MM$*- ' "! HHTN ,+ '& "!sR   D D
(C.2D!D )4DD .DDD	D D	D  D)N)r!   r"   r#   r]   ro   rr   r   r   r   r   r   r   r   r   r   unittest
skipUnlesshasattrrf   r   r,   r   r   rO   rO   k   s|    62$1/;b
9-
B;B;=,
 XX.H72x3HBDDr   rO   c                       e Zd Zy)GzipUstarReadTestNr!   r"   r#   r,   r   r   r   r         r   r   c                       e Zd Zy)Bz2UstarReadTestNr   r,   r   r   r   r     r   r   r   c                       e Zd Zy)LzmaUstarReadTestNr   r,   r   r   r   r     r   r   r   c                   $    e Zd Zd Zd Zd Zd Zy)ListTestc                 d    t        j                  | j                  | j                        | _        y )Nr    rH   r   s    r   rJ   zListTest.setUp  s    <<499=r   c                     t        j                  t        j                         dd      }t        j                  t
        d|      5   j                  j                  d       d d d        |j                         j                         } j                  d|        j                  d|        j                  d	|        j                  d
|        j                  d|        j                  d|        j                  d|        j                  d|        fd} j                   |d      |        j                   |d      |        j                   |d      |        j                   |d      |        j                   |d      |        j                  |d        j                  d|        j                  d|       y # 1 sw Y   lxY w)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                 t    | j                  j                  j                  d      }|j                  dd      S )Nsurrogateescaper   backslashreplace)decoderI   rG   r   )r   r~   r   s     r   convz ListTest.test_list.<locals>.conv!  s0    **,=>A88G%7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%   rj   BytesIOr   	swap_attrsysrI   rq   detachgetvalueassertInassertRegexassertNotIn)r   tiooutr   s   `   r   	test_listzListTest.test_list  s   rzz|WdCsHc2HHMM%M( 3jjl##%'-&,&,BCH2C82C8'-137	9 	dHI3Od ; <=@	Bd ; <=@	Bd67=d9:C@ 	 7 	8 	S)$C 32s   GGc                    t        j                  t        j                         dd      }t        j                  t
        d|      5  | j                  j                  d       d d d        |j                         j                         }| j                  |d       | j                  d|       | j                  d	|       | j                  d
|       | j                  d|       | j                  d|       y # 1 sw Y   xY w)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%   rj   r   r   r   r   rI   rq   r   r   r   r   )r   r   r   s      r   test_list_verbosezListTest.test_list_verbose7  s    rzz|WdCsHc2HHMM$M' 3jjl##% 	 = 	> 	137JCP 347	9 569	; 569	;' 32s   C66C?c                    t        j                  t        j                         dd      }d }t        j                  t
        d|      5  | j                  j                  d || j                               d d d        |j                         j                         }| j                  d|       | j                  d	|       y # 1 sw Y   LxY w)
Nr   r   r   c              3   \   K   | j                         D ]  }d|j                  v s|  y w)Nreg)
getmembersr   )rI   r[   s     r   membersz+ListTest.test_list_members.<locals>.membersQ  s(     >>+GLL(!M ,s   ",,r   F)r   r   r   r   )r%   rj   r   r   r   r   rI   rq   r   r   r   r   )r   r   r   r   s       r   test_list_memberszListTest.test_list_membersO  s    rzz|WdC	" sHc2HHMM%1BMC 3jjl##%&,*C0	 32s   	.CCN)r!   r"   r#   rJ   r   r   r   r,   r   r   r   r     s    >#%J;0
1r   r   c                       e Zd Zy)GzipListTestNr   r,   r   r   r   r   \  r   r   r   c                       e Zd Zy)Bz2ListTestNr   r,   r   r   r   r   `  r   r   r   c                       e Zd Zy)LzmaListTestNr   r,   r   r   r   r   d  r   r   r   c                   H    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)CommonReadTestc                    t        t        d      5  	 d d d        | j                  t        j                  t                     | j                  t        j                  t        j                  t                           t        t        d      5 }| j                  t        j                  |             d d d        | j                  t        j                  t        j                  d                   y # 1 sw Y   xY w# 1 sw Y   MxY w)Nwbrt   s   invalid)	r'   r   assertFalser(   
is_tarfiler	   FakePathr%   r   r   r\   s     r   test_is_tarfile_erroneousz(CommonReadTest.test_is_tarfile_erroneousj  s    '4  ! 	++G45 	++I,>,>w,GHI '4 DW//56 ! 	++BJJz,BCD !  ! s   C3%C?3C<?Dc           	      `   | j                  t        j                  | j                               | j                  t        j                  t	        j
                  | j                                     t        | j                  d      5 }| j                  t        j                  |             d d d        t        | j                  d      5 }| j                  t        j                  t        j                  |j                                            d d d        y # 1 sw Y   nxY w# 1 sw Y   y xY w)Nrt   )

assertTruer(   r   r$   r	   r   r'   r%   r   rU   r   s     r   test_is_tarfile_validz$CommonReadTest.test_is_tarfile_valid{  s    **4<<89 	**9+=+=dll+KLM $,,%OOG..t45 & $,,%OOG..rzz$))+/FGH &%	 &% &%s   %D	AD$D!$D-c                    t        | j                  d      5 }t        j                  |       | j	                  |j                         d       d d d        t        | j                  d      5 }t        j                  |j                               }t        j                  |       | j	                  |j                         d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nrt   r   )	r'   r$   r(   r   rV   r{   r%   r   rU   )r   r\   	file_likes      r   test_is_tarfile_keeps_positionz-CommonReadTest.test_is_tarfile_keeps_position  s     $,,%t$TYY[!, & $,,%

499;/Iy)Y^^-q1 &%	 &% &%s   6C+ACCC"c                    t        j                  t        | j                  j	                  dd            5  	 d d d        	 t        j                  t        | j                        }|j                          | j                  |j                         g        j                          y # 1 sw Y   oxY w# t         j                  $ r | j                  d       Y Cw xY w# j                          w xY w)Nra   r   z&tarfile.open() failed on empty archive)r(   r'   r   r    replacegetnamesassertListEqualr   	ReadErrorr   rL   r   rI   s     r   test_empty_tarfilez!CommonReadTest.test_empty_tarfile  s    
 \\'499#4#4S##>? @	,,w		2CLLN   !126IIK @?
    	@II>?	@
 IIKs5   B% 4B1 4 C %B.1$CC CC C-c                     | j                  t        d      5  t        j                  d| j                         d d d        y # 1 sw Y   y xY w)Nxxx)assertRaisesRegexFileNotFoundErrorr(   r'   r    r   s    r   test_non_existent_tarfilez(CommonReadTest.test_non_existent_tarfile  s3     ##$5u=LL		* >==s   !AA
c                 2   t        t        d      5  	 d d d        | j                  t        j                  t        j                   t        | j
                         | j                  t        j                  t        j                   t               y # 1 sw Y   {xY wNr   )r'   r   assertRaisesr(   r  r    r   s    r   test_null_tarfilez CommonReadTest.test_null_tarfile  s]     '4  !'++W\\7DIIN'++W\\7C ! s   BBc                 <   t        d      j                  d      }dD ]  }| j                  t        d      5 }|j	                  |dz         t        j                  d      }t        |      |_        |j	                  |j                                |j	                  |       d d d        t        j                  t        dd	      }	 | j                  |j                         dgd
|z         |j                           y # 1 sw Y   ^xY w# |j                          w xY w)Nr   ry   )       ar   rv   foora   T)r    ignore_zerosz3ignore_zeros=True should have skipped the %r-blocks)r   	randbytesr'   r   writer(   TarInforW   rX   tobufr  r  rL   )r   r   charr\   r[   rI   s         r   test_ignore_zerosz CommonReadTest.test_ignore_zeros  s     ay""3'!D 7C(D

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

7==?+

4  ) ,,wStDC$$S\\^eWI 		! " )( 		s   A*C=%D	=D		Dc                    dD ]  }t        j                  t        d      5 }t        j                  d      }d|_        |j                  |t        j                  d             d d d        t        t        d      5 }|j                  |       d d d        t        j                  t              5 }| j                  t         j                  d      5  |D ]  } 	 d d d        d d d        t        j                  t              5 }|j                         }| j                  t         j                  d      5  |j                  |t        d	       d d d        | j                  t         j                  d      5  |j                  |      j                          d d d        d d d         y # 1 sw Y   FxY w# 1 sw Y   )xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   SxY w# 1 sw Y   xY w)
N)ry   iX  rv   i  w:r  rv   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazr+bzunexpected end of datar   r_   )r(   r'   r   r  rX   addfiler%   r   truncater  r  nextrd   re   rT   rU   )r   rX   rI   tr\   s        r   test_premature_end_of_archivez,CommonReadTest.test_premature_end_of_archive  sq   *Dgt,OOE*Arzz+67 -
 gu%d# & g&#++G,=,=?WX  ! Y '
 g&#HHJ++G,=,=?WXKK76K: Y ++G,=,=?WXOOA&++- Y '& +,,
 &% YX '& YX YX '&sx   AF';F4.!GGG1G12G(G13 G%G1'F1	4F>	G
GG	G"G1%G.*G11G;	c                     | j                  t        j                  d      5  t        j                  t	        j
                  d            5 }	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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  sW     ##G$5$57^_g..?@C A `_@@ `_s#   )A)
AA)A&	"A))A2c                 .   | j                   j                  d      }| j                   j                  |      5 }| j                  |j                  d       | j                  t        |j                         | j                  |j                         d       | j                  |j                         d       | j                  r!| j                  t        |j                         n | j                  |j                         d       | j                  |j                  d       d d d        | j                  j                  d       | j                  |j                  d       | j                  t        |j                         | j                  |j                         d       | j                  |j                         d       | j                  r!| j                  t        |j                         y | j                  |j                         d       y # 1 sw Y   xY w)NrQ   TF)rI   rS   rT   rV   r   r  r   filenoassertIsreadablewritable	is_streamseekableclosed)r   filer\   s      r   test_extractfile_attrsz%CommonReadTest.test_extractfile_attrs  s\   xx!!/2XX!!$'4TYY8ndkk:MM$--/40MM$--/51~~!!.$--@dmmot4MM$++u- ( 	dkk4(O4.$++6dmmot,dmmou->>ndmm<MM$--/40% ('s   C&HHN)r!   r"   r#   r   r   r   r  r
  r  r  r   r$  r.  r,   r   r   r   r   h  s7    E"I
2"+D,.01r   r   c                   r   e Zd ZdZd Zd Zd Zd Zd Zd Z	d d	Z
d
 Zd Zd Zd Zd Zd Zd Zd Z ej(                   eed      d      ej0                  d               Zej4                  d        Zej4                  d        Zd Zd Zd Zd Z d Z!d Z" ejF                  e$du d      d        Z%d Z&y)!MiscReadTestBaseFc                      y r   r,   r   s    r   requires_name_attributez(MiscReadTestBase.requires_name_attribute  s    r   c                    | j                          t        | j                  d      5 }| j                  |j                  t
               t        j                  || j                        5 }| j                  |j                  t
               | j                  |j                  t        j                  j                  |j                               d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wNrt   fileobjr    )r2  r'   r$   assertIsInstancer   strr(   r    rV   rf   rg   abspathr   r\   rI   s      r   test_no_name_argumentz&MiscReadTestBase.test_no_name_argument  s    $$&$,,%!!$))S1d;s%%chh4  277??499+EF < &%;; &%s%   AC*)A$CC*C'	#C**C3c                 T   t        | j                  d      5 }|j                         }d d d        t        j                        }| j                  t        t        |d       t        j                   || j                        }| j                  |j                         y # 1 sw Y   wxY w)Nrt   r   r5  )r'   r$   rU   r%   r   r  r   getattrr(   r    assertIsNoner   r   r\   r   rI   s       r   test_no_name_attributez'MiscReadTestBase.test_no_name_attribute  ss    $,,%99;D &zz$.'4@ll4dii8#((# &%s   BB'c                 T   t        | j                  d      5 }|j                         }d d d        t        j                        }d|_        t        j                   || j                        5 }| j                  |j
                         d d d        y # 1 sw Y   kxY w# 1 sw Y   y xY w)Nrt   r   r5  )	r'   r$   rU   r%   r   r   r(   r    r>  r?  s       r   test_empty_name_attributez*MiscReadTestBase.test_empty_name_attribute  sw    $,,%99;D &zz$	\\$TYY73chh' 87	 &% 87s   B-BBB'c                    t        j                  | j                  t         j                        }t        |d      5 }| j	                  |j
                  t               t        j                  || j                        5 }| j                  |j
                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr4  )
rf   r'   r$   O_RDONLYr7  r   intr(   r    r>  )r   fdr\   rI   s       r   test_int_name_attributez(MiscReadTestBase.test_int_name_attribute   s|     WWT\\2;;/"d^t!!$))S1d;s!!#((+ < ^;; ^s$   AB6=B*B6*B3	/B66B?c                    | j                          t        j                  | j                        }t	        |d      5 }| j                  |j                  t               t        j                  || j                        5 }| j                  |j                  t               | j                  |j                  t        j                  j                  |j                               d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr4  )r2  rf   fsencoder$   r'   r7  r   bytesr(   r    rV   rg   r9  )r   r$   r\   rI   s       r   test_bytes_name_attributez*MiscReadTestBase.test_bytes_name_attribute)  s    $$&++dll+'4 D!!$))U3d;s%%chh6  277??499+EF < ! ;; ! s%   AC?>A$C3"C?3C<	8C??DNc                    || j                   }t        j                  j                  |      }t	        j
                  |      }t        j                  || j                        5 }| j                  |j                  |       d d d        | j                  |      5 }| j                  |j                  |       d d d        t        j                  j                  || j                        5 }| j                  |j                  |       d d d        | j                  dk(  r=t        j                  |d      5 }| j                  |j                  |       d d d        y y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   nxY w# 1 sw Y   y xY w)Nr   r   ra   )r$   rf   rg   r9  r	   r   r(   r'   r    rV   r   r*   r)   r   )r   r$   expectedrI   s       r   test_pathlike_namez#MiscReadTestBase.test_pathlike_name2  s   ?llG77??7+$$W-\\'		2cSXXx0 3\\'"cSXXx0 #__!!'		!:cSXXx0 ;;;"s3s  84 43  32"":: 43s0   $EE(*E45F E%(E14E= F	c                 `    | j                  t        j                  | j                               y r   )rN  rf   rI  r$   r   s    r   test_pathlike_bytes_namez)MiscReadTestBase.test_pathlike_bytes_nameA  s    DLL 9:r   c                    t        t        d      5  	 d d d        | j                  t        d      5  | j	                  t        d      }d d d        | j                  t        d      5  | j	                  t        d      }d d d        | j                  t        d      5  | j	                  t        d      }d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   WxY w# 1 sw Y   y xY w)Nr   zmode must be qrwr   )r'   r   r  
ValueErrorr*   r  s     r   test_illegal_mode_argz&MiscReadTestBase.test_illegal_mode_argD  s    '4  !##J@,,w,C A##J@,,w-C A##J@,,w+C A@ ! @@@@@@s.   B;C&CC;CCCC(c                 B   t        j                  | j                  | j                        }	 |j	                          |j	                         }|j
                  }|j                  }|j                  |      5 }|j                         }d d d        |j                          | j                  | j                        5 }|j                  |       |j                  | j                  d|      5 }|j	                         }| j                  |j
                  |       |j                          | j                  |j                  |      j                         d       d d d        d d d        y # 1 sw Y   xY w# |j                          w xY w# 1 sw Y   3xY w# 1 sw Y   y xY w)Nr   rC   r    r6  zseek back did not work)r(   r'   r$   r    r  r   offsetrT   rU   rL   rz   rV   r   )r   rI   r  r   rX  fr   r\   s           r   test_fileobj_with_offsetz)MiscReadTestBase.test_fileobj_with_offsetN  s2    ll4<<dii8	HHJ
A66DXXF#qvvx $ IIK YYt||$IIf $,,T4@CHHJ  .    !3!8!8!:D02 A	 %$ $# IIK A@	 %$sI   A	E4 6E(E4 :0F*A-F	F(E1-E4 4F	F	FFc                 @   | j                  t        j                  t        j                  t        | j
                         t        t        d      5 }| j                  t        j                  t        j                  || j
                         d d d        y # 1 sw Y   y xY wr4  )r  r(   r  r'   r$   r    r   s     r   test_fail_compzMiscReadTestBase.test_fail_compj  sf    '++W\\7DIIN'4 Dg//&*  < !  s   <BBc                     | j                   j                  d      }| j                  |j                  t        j
                  d       y )Nzmisc/dirtype-old-v7zv7 dirtype failed)rI   rS   rV   typer(   DIRTYPEr   r[   s     r   test_v7_dirtypez MiscReadTestBase.test_v7_dirtypeq  s6     (($$%:;w#	%r   c                 |    	 | j                   j                  d       y # t        $ r | j                  d       Y y w xY w)Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))rI   rS   KeyErrorr   r   s    r   test_xstar_typez MiscReadTestBase.test_xstar_typey  s9    	MHH34 	MIIKL	Ms    ;;c                    | j                   D ]{  }| j                  t        |j                        dd|j                  z         |j                  j                  d      sR| j                  |j                  dd|j                  z         } y )N鏽>zwrong mtime for %szustar/r(   zwrong uname for %s)rI   rV   rE  mtimer   
startswithunamer`  s     r   test_check_membersz#MiscReadTestBase.test_check_members  sn    xxGS/(7<<79<<**84W]]I(7<<79  r   c                 t    | j                  | j                  j                         d   j                  dd       y )Nzmisc/eofzcould not find all members)rV   rI   r   r   r   s    r   test_find_membersz"MiscReadTestBase.test_find_members  s/    ,,.r277,	.r   linkMissing hardlink implementationc                 J   t        j                  t        dd      5 }|j                  dt        d       | j                  t        j                  t        j                  j                  t        d             |j                  dt        d       | j                  t        j                  t        j                  j                  t        d             t        t        j                  j                  t        d      d      5 }|j                         }d d d        | j                  t              t               |j                  d	t        d       | j                  t        j                  t        j                  j                  t        d	             t        t        j                  j                  t        d	      d      5 }|j                         }d d d        | j                  t        |      t               d d d        y # 1 sw Y   xY w# 1 sw Y   =xY w# 1 sw Y   y xY w)
Nru   rE   )
errorlevelrG   rQ   r   r_   r   rt   r   )r(   r'   r$   rd   re   
addCleanupr	   unlinkrf   rg   rh   rU   rV   r   rY   )r   rI   rY  r   s       r   test_extract_hardlinkz&MiscReadTestBase.test_extract_hardlink  s\   
 \\'a+F#KKK@OOI,,bggll7O.TUKKK@OOI,,bggll7O.TUbggll7O<dCqvvx DYt_n=KKK@OOI,,bggll7O.TUbggll7O<dCqvvx DYt_n= GF DC DC GFs=   C#H HB/H H'HH
	HH	HH"c                    t        j                  t        d      }t        j                  j                  t        d      }t        j                  |       	 |D cg c]  }|j                         s| }}|j                  ||d       |D ]  }t        j                  j                  ||j                        }t        j                  dk7  rJ| j                  |j                  dz  t        j                  |      j                   dz  |j                         d }t        j                  j#                  |      }d	j%                   ||j&                         ||      |      }	| j                  |j&                  ||	        	 |j)                          t+        j,                  |       y c c}w # |j)                          t+        j,                  |       w xY w)
NrE   rG   
extractallfully_trustedr_   win32  c                     t        | t              r dj                  | | j                               S dj                  |       S )Nz{} ({})z
{!r} (int))
isinstancefloatr   hex)rg  s    r   format_mtimez6MiscReadTestBase.test_extractall.<locals>.format_mtime  s6    !%/(//uyy{CC+22599r   z,tar mtime {0} != file time {1} of path {2!a})r(   r'   r$   rf   rg   rh   re   r   isdirrw  r   r   platformrV   r    statst_modegetmtimer   rg  rL   r	   rmtree)
r   rI   DIRr  directoriesr[   rg   r  
file_mtimeerrmsgs
             r   test_extractallz MiscReadTestBase.test_extractall  s]    ll7[9ggll7L1
	"&)7cQWWY1cK7NN3OND&ww||C6<<7*$$W\\E%9%'WWT]%:%:U%B%,\\3:
  WW--d3
GNN / ,   
FC# '& IIKS!- 8* IIKS!s%   F, F'0F'4DF, 'F, ,'Gc                    d}t         j                  j                  t        d      }t        j                  |       	 t        j                  t        d      5 }|j                  |      }|j                  ||d       t         j                  j                  ||      }| j                  t         j                  j                  |      |j                         t        j                  dk7  r2| j                  t        j                  |      j                   dz  d	       d d d        t#        j$                  |       y # 1 sw Y   xY w# t#        j$                  |       w xY w)
Nustar/dirtype
extractdirrE   rv  rx  rg   r`   ry  rz  i  )rf   rg   rh   re   r   r(   r'   r$   rS   rd   rV   r  rg  r   r  r  r  r	   r  r   dirtyper  rI   r[   	extracteds         r   test_extract_directoryz'MiscReadTestBase.test_extract_directory  s    !ggll7L1
		"g<--0G#oFGGLLg6	  !1!1)!<gmmL<<7*$$RWWY%7%?%?%%GO = S! =< S!s$   E CD:E :E?E Ec                    t        j                  t              dz  }t        j                  |      5  t        j                  t        d      5 }|D cg c]  }|j                         s| }}| j                  t        d      5 }|j                  ||       d d d        | j                  j                  t               d d d        d d d        y c c}w # 1 sw Y   ?xY w# 1 sw Y   #xY w# 1 sw Y   y xY w)Nrw  rE   rv  Use the filter argument)pathlibPathre   r	   temp_dirr(   r'   r$   r  assertWarnsRegexDeprecationWarningrw  rV   filename__file__)r   r  rI   r  r  cms         r   2test_deprecation_if_no_filter_passed_to_extractallzCMiscReadTestBase.test_deprecation_if_no_filter_passed_to_extractall  s    ll7#l2s#LL;73&)7cQWWY1cK7&&'9;TUY[sK0 V R[[(3 8 $# 8UU 87 $#sS   C.C"C)C-C"C(C" C.C"CC""C+	'C..C7c                    d}t        j                  t              dz  }t        j                  |      5  t        j                  t        d      5 }|j                  |      }| j                  t        d      5 }|j                  ||       d d d        | j                  j                  t               d d d        d d d        y # 1 sw Y   :xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  rw  rE   rv  r  rg   )r  r  re   r	   r  r(   r'   r$   rS   r  r  rd   rV   r  r  )r   r  r  rI   r[   r  s         r   /test_deprecation_if_no_filter_passed_to_extractz@MiscReadTestBase.test_deprecation_if_no_filter_passed_to_extract  s    !ll7#l2s#LL;73mmG,G&&'9;TUY[G#. V R[[(3 8 $# VU 87 $#s;   C(C8C(C4CC
CC	CC&c                 n   t         j                  j                  t        d      }t	        j
                  |      5  t        j                  t        d      5 }|D cg c]  }|j                         s| }}|j                  t	        j                  |      |d       |D ]e  }t         j                  j                  ||j                        }| j                  t         j                  j                  |      |j                         g 	 d d d        d d d        y c c}w # 1 sw Y   xY w# 1 sw Y   y xY w)Nrw  rE   rv  rx  r_   )rf   rg   rh   re   r	   r  r(   r'   r$   r  rw  r   r   rV   r  rg  )r   r  rI   r  r  r[   rg   s          r   test_extractall_pathlike_dirz-MiscReadTestBase.test_extractall_pathlike_dir  s    ggll7L1$\\'K8C&)7cQWWY1cK7NN9--c2KNX&ww||C6  !1!1$!7G ' 9 %$7 98 %$s<   D+DD1D5BD	D+DD(	$D++D4c                 &   d}t         j                  j                  t        d      }t	        j
                  |      5  t        j                  t        d      5 }|j                  |      }|j                  |t	        j                  |      d       t         j                  j                  ||      }| j                  t         j                  j                  |      |j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr  rw  rE   rv  rx  r  )rf   rg   rh   re   r	   r  r(   r'   r$   rS   rd   r   rV   r  rg  r  s         r   test_extract_pathlike_dirz*MiscReadTestBase.test_extract_pathlike_dir  s    !ggll7L1$\\'K8CmmG,GKKi&8&8&=oKVS'2IRWW--i8'--H	 9 %$88 %$s$   DBC;*D;D	 DDc                    t         j                  j                  t        d      }t	        |d      5 }|j                  d       d d d        	 t        j                  t        j                        }	 |j                  |       | j                  d       t!        j"                  |       y # 1 sw Y   fxY w# t        j                  $ r( | j                  |j                  j                         Y \w xY w# t!        j"                  |       w xY w)Nemptyr   r   zReadError not raised)rf   rg   rh   re   r'   r  object__new__r(   r)   __init__r   r  r   r6  r,  r	   rs  )r   r  r\   rI   s       r   test_init_close_fobjz%MiscReadTestBase.test_init_close_fobj  s     Wg.%$JJsO 		$..1C2U# 		01U#  $$ 4 2 234
 U#s;   B(#C2 0B4 C2 (B148C/,C2 .C//C2 2D	c                 >   t        j                  | j                        5 }t        ||      D ]Y  \  }}| j	                  |j
                  |j
                         | j	                  |j                         |j                                [ 	 d d d        y # 1 sw Y   y xY wr   )r(   r'   r$   ziprV   rX  get_info)r   rI   m1m2s       r   test_parallel_iterationz(MiscReadTestBase.test_parallel_iteration  sj     \\$,,'3c3-B  BII6  > ( (''s   A)BBzrequires zlibc                 <   t         j                  j                  d      5 }t        j                  |_        | j                  t        j                        5  t        j                  | j                         d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)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  sh     ]]  !>?4#zzD""7#4#45T\\* 6 @?55 @?s#   5B B5BB	BBc                    t        j                         }t        j                  |d      }|j	                          |j                  d       t        j                  |d      5 }| j                  |j                         d        d d d        |j                  d       t        j                  |d      5 }| j                  |j                         d        d d d        y # 1 sw Y   [xY w# 1 sw Y   y xY w)Nr   r5  r   r|ra   )r%   r   r(   r'   rL   rz   rV   r  )r   rF  tfs      r   test_next_on_empty_tarfilez+MiscReadTestBase.test_next_on_empty_tarfile%  s    ZZ\\\"3/



\\"40BRWWY- 1 	
\\"3/2RWWY- 0/	 10 0/s   $!C5!C+C(+C4r   )'r!   r"   r#   r*  r2  r;  r@  rB  rG  rK  rN  rP  rU  rZ  r\  ra  rd  rj  rm  r   r   r   rf   r	   skip_unless_symlinkrt  skip_unless_working_chmodr  r  r  r  r  r  r  r  skipIfr  r  r  r,   r   r   r0  r0    s   IG$(,G5;,28<%M9. XV,:<""> #<>$ ((" )"> ((" )"
44HI$&? X__TT\?3+ 4+.r   r0  c                       e Zd ZdZy)MiscReadTestN)r!   r"   r#   r\  r,   r   r   r  r  2  s    Nr   r  c                       e Zd Zy)GzipMiscReadTestNr   r,   r   r   r  r  5  r   r   r  c                       e Zd Zd Zy)Bz2MiscReadTestc                 &    | j                  d       y )NzBZ2File have no name attributeskipTestr   s    r   r2  z'Bz2MiscReadTest.requires_name_attribute9  s    67r   Nr!   r"   r#   r2  r,   r   r   r  r  8  s    8r   r  c                       e Zd Zd Zy)LzmaMiscReadTestc                 &    | j                  d       y )NzLZMAFile have no name attributer  r   s    r   r2  z(LzmaMiscReadTest.requires_name_attribute=  s    78r   Nr  r,   r   r   r  r  <  s    9r   r  c                   ,    e Zd ZdZdZd Zd Zd Zd Zy)StreamReadTestr  Tc                 ,   | j                   D ]O  }|j                         s| j                   j                  |      5 }	 	 |j                  d      }sn	 d d d        Q y # t        j
                  $ r | j                  d       Y 6w xY w# 1 sw Y   xY w)Nry   z6simple read-through using TarFile.extractfile() failed)rI   isregrT   rU   r(   StreamErrorr   )r   r[   r\   bufs       r   test_read_throughz StreamReadTest.test_read_throughF  s     xxG==?%%g.$B"iin    /.   #.. B		 #A BB	 /.s.   B
A B
 $BB
BB

B	c                 D   | j                   j                         }| j                   j                  |      5 }|j                         }d d d        | j	                  t              |j                  d       | j	                  t        |      t        d       y # 1 sw Y   PxY w)NrR   )	rI   r  rT   rU   rV   rW   rX   r   rY   rZ   s       r   r]   z(StreamReadTest.test_fileobj_regular_fileV  st    ((--/XX!!'*d99;D +TGLL0	24.0	2	 +*s   BBc                     | j                   j                         }| j                   j                  |d         5 }| j                  t        j
                  |j                         d d d        y # 1 sw Y   y xY wNr   )rI   r   rT   r  r(   r  rU   )r   tarinfosrY  s      r   test_provoke_stream_errorz(StreamReadTest.test_provoke_stream_error_  sR    88&&(XX!!(1+.!g11166: /..s   +A--A6c                    t        j                  t        d      }	 | j                  }	 |j	                         }|j	                         }|n| j                  |d       |j                         s|j                         r:| j                  t         j                        5  |j                  |       d d d        |j                  |      }|j                  |      }|| j                  |d       | j                  |j                         |j                         d       	 |j                          y # 1 sw Y   xY w# |j                          w xY w)NrE   rv  zstream.next() failed.zstream.extractfile() failedzstream extraction failed)r(   r'   r$   rI   r  assertIsNotNoneislnkissymr  r  rT   rV   rU   rL   )r   tar1tar2t1t2v1v2s          r   test_compare_membersz#StreamReadTest.test_compare_membersd  s   ||Gk:	88DYY[YY[:$$R)@A88:**7+>+>?((, @%%b)%%b):$$R)FG  BGGI24#    JJL @? JJLs%   BD> D20A0D> 2D;7D> >EN)	r!   r"   r#   r   r*  r  r]   r  r  r,   r   r   r  r  A  s     FI 2;
r   r  c                       e Zd Zy)GzipStreamReadTestNr   r,   r   r   r  r    r   r   r  c                       e Zd Zy)Bz2StreamReadTestNr   r,   r   r   r  r    r   r   r  c                       e Zd Zy)LzmaStreamReadTestNr   r,   r   r   r  r    r   r   r  c                   *    e Zd Zd Zd Zd Zd Zd Zy)DetectReadTestc                     	 t        j                  ||      }|j                          y # t         j                  $ r}| j	                          Y d }~y d }~ww xY wr   )r(   r'   rL   r  r   )r   r   r    rI   es        r   _testfunc_filezDetectReadTest._testfunc_file  sE    	,,tT*C IIK    	IIKK	s   ) AAAc                     	 t        |d      5 }t        j                   |||      }d d d        j                          y # 1 sw Y   xY w# t        j                  $ r}| j	                          Y d }~y d }~ww xY w)Nrt   r6  )r'   r(   rL   r  r   )r   r   r    rY  rI   r  s         r   _testfunc_fileobjz DetectReadTest._testfunc_fileobj  s^    	dD!Qll4q9 "
 IIK "!   	IIKK	s-   A A A  A	A A9A44A9c                    | j                   r2| j                  t        j                        5  t        j                  t
        d| j                   z          d d d        | j                  t        j                        5  t        j                  t
        d| j                   z          d d d        | j                  t        j                        5  t        j                  | j
                  d       d d d        | j                  t        j                        5  t        j                  | j
                  d       d d d         || j
                  d        || j
                  d| j                   z           || j
                  d        || j
                  d| j                   z           || j
                  d       y # 1 sw Y   fxY w# 1 sw Y   #xY w# 1 sw Y   xY w# 1 sw Y   xY w)NrC   r   r  ra   zr:*r|*)r   r  r(   r  r'   r$   )r   testfuncs     r   _test_modeszDetectReadTest._test_modes  s5   ;;""7#4#45W4$+++=> 6""7#4#45W4$+++=> 6""7#4#45T\\5 6""7#4#45T\\5 6s#tdkk12u%tdkk12u% 65555555s/   )F:=)G"G"G :GGG G)c                 :    | j                  | j                         y r   )r  r  r   s    r   test_detect_filezDetectReadTest.test_detect_file  s    ,,-r   c                 :    | j                  | j                         y r   )r  r  r   s    r   test_detect_fileobjz"DetectReadTest.test_detect_fileobj  s    //0r   N)r!   r"   r#   r  r  r  r  r  r,   r   r   r  r    s    & .1r   r  c                       e Zd Zy)GzipDetectReadTestNr   r,   r   r   r  r    r   r   r  c                       e Zd Zd Zy)Bz2DetectReadTestc                    t        t        d      5 }|j                         }d d d        t        j                  t
        dd      5 }|j                         d d d        | j                  t
        d       y # 1 sw Y   VxY w# 1 sw Y   ,xY w)Nrt   r   ru   compresslevelr  )r'   r$   rU   r6   r8   r   r  r  r   s      r   test_detect_stream_bz2z(Bz2DetectReadTest.test_detect_stream_bz2  si    
 '4 D99;D ! [[$a8DJJt 9 	GU+ !  98s   A7B7B BN)r!   r"   r#   r   r,   r   r   r  r    s    ,r   r  c                       e Zd Zy)LzmaDetectReadTestNr   r,   r   r   r  r    r   r   r  c                       e Zd ZdZd Zy) GzipBrokenHeaderCorrectExceptionz>
    See: https://github.com/python/cpython/issues/107396
    c                     t        j                  d      }| j                  t        j                        5  t        j
                  |d       d d d        y # 1 sw Y   y xY w)Ns               zr|gzr5  )r%   r   r  r(   r  r'   )r   rY  s     r   runTestz(GzipBrokenHeaderCorrectException.runTest  sE    JJ
 w001LL0 211s   AAN)r!   r"   r#   __doc__r  r,   r   r   r  r    s    
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y)MemberReadTestNc           	         |[| j                   j                  |      5 }| j                  t        |j	                               |d|j
                  z         d d d        d|d<   d|d<   d|d<   d|j
                  vr
d	|d
<   d	|d<   |j                         D ]2  \  }}| j                  t        ||      |d|d|j
                         4 y # 1 sw Y   vxY w)Nwrong sha256sum for %srf  rg    r   r   r   zold-v7r(   ri  gnamezwrong value in z
 field of )rI   rT   rV   r   rU   r   itemsr=  )r   r[   chksumkwargsrY  kvs          r   _test_memberzMemberReadTest._test_member  s    %%g.!  1668!4f07<<?A / 'wuu7<<''F7O'F7OLLNDAqWWa0!78',,GI # /.s   8CCc                 j    | j                   j                  d      }| j                  |dt               y )NrQ   c  rX   r  rI   rS   r  rY   r`  s     r   test_find_regtypez MemberReadTest.test_find_regtype  s+    (($$_5'^Dr   c                 j    | j                   j                  d      }| j                  |dt               y )Nzustar/conttyper  r  r  r`  s     r   test_find_conttypez!MemberReadTest.test_find_conttype  s,    (($$%56'^Dr   c                 `    | j                   j                  d      }| j                  |d       y )Nr  r   rX   rI   rS   r  r`  s     r   test_find_dirtypez MemberReadTest.test_find_dirtype  s)    (($$_5'*r   c                 `    | j                   j                  d      }| j                  |d       y )Nzustar/dirtype-with-size   r  r  r`  s     r   test_find_dirtype_with_sizez*MemberReadTest.test_find_dirtype_with_size  s*    (($$%>?',r   c                 b    | j                   j                  d      }| j                  |dd       y )Nr   r   rQ   rX   linknamer  r`  s     r   test_find_lnktypez MemberReadTest.test_find_lnktype  s+    (($$_5'ODr   c                 b    | j                   j                  d      }| j                  |dd       y )Nr   r   r   r#  r  r`  s     r   test_find_symtypez MemberReadTest.test_find_symtype  s+    (($$_5'I>r   c                 d    | j                   j                  d      }| j                  |ddd       y )Nustar/blktyper      rX   devmajordevminorr  r`  s     r   test_find_blktypez MemberReadTest.test_find_blktype  -    (($$_5'ABr   c                 d    | j                   j                  d      }| j                  |ddd       y )Nustar/chrtyper   ru   r*  r+  r  r`  s     r   test_find_chrtypez MemberReadTest.test_find_chrtype  r/  r   c                 `    | j                   j                  d      }| j                  |d       y )Nustar/fifotyper   r  r  r`  s     r   test_find_fifotypez!MemberReadTest.test_find_fifotype  s*    (($$%56'*r   c                 j    | j                   j                  d      }| j                  |dt               y )Nzustar/sparse P r  rI   rS   r  sha256_sparser`  s     r   test_find_sparsezMemberReadTest.test_find_sparse  s+    (($$^4'mDr   c                 j    | j                   j                  d      }| j                  |dt               y )N
gnu/sparser7  r  r8  r`  s     r   test_find_gnusparsez"MemberReadTest.test_find_gnusparse  s+    (($$\2'mDr   c                 j    | j                   j                  d      }| j                  |dt               y )Ngnu/sparse-0.0r7  r  r8  r`  s     r   test_find_gnusparse_00z%MemberReadTest.test_find_gnusparse_00  ,    (($$%56'mDr   c                 j    | j                   j                  d      }| j                  |dt               y )Ngnu/sparse-0.1r7  r  r8  r`  s     r   test_find_gnusparse_01z%MemberReadTest.test_find_gnusparse_01  rA  r   c                 j    | j                   j                  d      }| j                  |dt               y )Ngnu/sparse-1.0r7  r  r8  r`  s     r   test_find_gnusparse_10z%MemberReadTest.test_find_gnusparse_10  rA  r   c                 j    | j                   j                  d      }| j                  |dt               y )Nu   ustar/umlauts-ÄÖÜäöüßr  r  r  r`  s     r   test_find_umlautsz MemberReadTest.test_find_umlauts#  s2    (($$ &D E'^Dr   c                 \    d}| j                  || j                  j                                y )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   rI   r  )r   r   s     r   test_find_ustar_longnamez'MemberReadTest.test_find_ustar_longname(  s"    <dDHH--/0r   c                 j    | j                   j                  d      }| j                  |dt               y )Nzmisc/regtype-old-v7r  r  r  r`  s     r   test_find_regtype_oldv7z&MemberReadTest.test_find_regtype_oldv7,  s,    (($$%:;'^Dr   c                     | j                   j                          t        j                  | j                  | j
                  d      | _         | j                   j                  d      }| j                  |dt               y )NrE   rF   u   pax/umlauts-ÄÖÜäöüßr  r  )	rI   rL   r(   r'   r$   r    rS   r  rY   r`  s     r   test_find_pax_umlautsz$MemberReadTest.test_find_pax_umlauts0  s_    <<499)46(($$ &D E'^Dr   r   )r!   r"   r#   r  r  r  r  r!  r%  r'  r.  r2  r5  r:  r=  r@  rD  rG  rI  rK  rM  rO  r,   r   r   r	  r	    so    I"EE+-E?CC+EEEEEE
1EEr   r	  c                   *    e Zd Zd Zd Zd Zd Zd Zy)LongnameTestc                     | j                   dz   dz   dz   }	 | j                  j                  |      }| j                  j                  t        j                  d       y # t        $ r | j	                  d       Y Hw xY w)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)	subdirrI   rS   rc  r   assertNotEqualr^  r(   r_  )r   rT  r[   s      r   test_read_longnamezLongnameTest.test_read_longname;  sp    ;;$|3j@	,hh((2G 	GLL'//*	,  	,II*+	,s   A A;:A;c                 
   | j                   dz   dz   dz   }| j                   dz   dz   dz   }	 | j                  j                  |      }| j                  j                  |d       y # t        $ r | j	                  d       Y :w xY w)Nr   rS  rT  longlinkzlonglink not foundzlinkname wrong)rU  rI   rS   rc  r   rV   r$  )r   rT  rY  r[   s       r   test_read_longlinkzLongnameTest.test_read_longlinkE  s    ;;$|3j@;;$|3j@	,hh((2G 	))85EF  	,II*+	,s   A% %BBc                    | j                   dz   dz   dz   }| j                  j                  |      }|j                  }| j                  j                  j                  |       t        j                  | j                  j                  j                  d            }| j                  t        j                        5  t        j                  d|       d d d        y # 1 sw Y   y xY w)Nr   rS  rT  i   zfoo.tar)r   r6  )rU  rI   rS   rX  r6  rz   r%   r   rU   r  r(   r  r'   )r   rT  r[   rX  r\   s        r   test_truncated_longnamez$LongnameTest.test_truncated_longnameN  s    ;;$|3j@(($$X.f%zz$((**//89w001LLi6 211s   9CC#c                    | j                   dz   dz   dz   }| j                  j                  |      j                  }t	        t
        d      5 }|j                  |       t        j                  j                  |j                  d      dd      }| j                  |j                  | j                         d d d        y # 1 sw Y   y xY w)Nr   rS  rT  rt   ry   rE   strict)rU  rI   rS   rX  r'   r$   rz   r(   r  frombufrU   rV   r^  longnametype)r   rT  rX  r\   r[   s        r   test_header_offsetzLongnameTest.test_header_offsetW  s     ;;$|3j@##H-44'4 DIIfoo--diin.98EGW\\4+<+<=	 !  s   A(B<<Cc           	         d}t        j                         5  t        j                  t        d      5 }| j
                  |_        	 t        j                  |       |j                  |       t        j                  |j                  d             	 d d d        t        j                  t              5 }| j                  |j                  |             | j                  |j                  |j                  d                   d d d        d d d        y # t        j                  |j                  d             w xY w# 1 sw Y   xY w# 1 sw Y   GxY w# 1 sw Y   y xY w)Nzfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/r   r   )r	   r   r(   r'   r   r   rf   r   r   r   rstripr  rS   removesuffix)r   longdirrI   s      r   test_longname_directoryz$LongnameTest.test_longname_directoryb  s    #!gs+s![[
2HHW%GGG$HHW^^C01 , g&#$$S]]7%;<$$S]]73G3G3L%MN ' "! HHW^^C01 ,+ '& "!sS   ED;&D+$D;!E1AEE&D88D;;E	 EE	EEN)r!   r"   r#   rW  rZ  r\  ra  rf  r,   r   r   rQ  rQ  9  s    ,G7	>Or   rQ  c                   n    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y)	GNUReadTestgnuc                    | j                   j                  |t        d       t        j                  j                  t        |      }t        |d      5 }|j                         }d d d        | j                  t              t        d|z         | j                         r?t        j                  |      }| j                  |j                  dz  |j                         y y # 1 sw Y   |xY w)Nr   r_   rt   r  ry   )rI   rd   re   rf   rg   rh   r'   rU   rV   r   r9  _fs_supports_holesr  
assertLess	st_blocksst_size)r   r   r  r\   r   r~   s         r   _test_sparse_filezGNUReadTest._test_sparse_file~  s    wv677<<.(D!T99;D "4-(4/	1 ""$!AOOAKK#-qyy9 % "!s   CC(c                 &    | j                  d       y )Nr<  ro  r   s    r   test_sparse_file_oldz GNUReadTest.test_sparse_file_old  s    |,r   c                 &    | j                  d       y )Nr?  rq  r   s    r   test_sparse_file_00zGNUReadTest.test_sparse_file_00      /0r   c                 &    | j                  d       y )NrC  rq  r   s    r   test_sparse_file_01zGNUReadTest.test_sparse_file_01  ru  r   c                 &    | j                  d       y )NrF  rq  r   s    r   test_sparse_file_10zGNUReadTest.test_sparse_file_10  ru  r   c                     t         j                  j                  d      rt        j                  j                  t        d      } t        | d      5 }|j                  d       |j                  d       |j                          d d d        t        j                  |       }t        j                  |        |j                  dz  |j                  k  S y# 1 sw Y   PxY w)Nlinuxzsparse-testr   i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxry   F)r   r  rh  rf   rg   rh   re   r'   rz   r  r  r  r	   rs  rm  rn  )r   r\   r~   s      r   rk  zGNUReadTest._fs_supports_holes  s     <<""7+77<<7DdD!T		$

;'	 "
 AT"KK#%		12 "!s   3CCN)r!   r"   r#   rU  r(   GNUTYPE_LONGNAMEr`  
GNU_FORMATr   ro  rr  rt  rw  ry  staticmethodrk  r,   r   r   rh  rh  q  sJ    F++LF
:-111  r   rh  c                   R    e Zd ZdZej
                  Zej                  Zd Z	d Z
d Zy)PaxReadTestpaxc                 >   t        j                  t        d      }	 |j                  d      }| j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  j                  d      d       |j                  d      }| j	                  |j
                  d	       | j	                  |j                  d       | j	                  |j                  j                  d      d       |j                  d
      }| j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  j                  d      d       |j                          y # |j                          w xY w)NrE   rv  pax/regtype1r  r   zVENDOR.umlautsu   ÄÖÜäöüßzpax/regtype2r   zpax/regtype3r(   )
r(   r'   r$   rS   rV   ri  r  pax_headersgetrL   r   rI   r[   s      r   test_pax_global_headersz#PaxReadTest.test_pax_global_headers  sA   ll7[9	mmN3GW]]E2W]]E2W00445EF;= mmN3GW]]B/W]]E2W00445EF;= mmN3GW]]I6W]]I6W00445EF;= IIKCIIKs   EF
 
Fc                 z   t        j                  t        d      }	 |j                  d      }| j	                  |j
                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  |j                  d       | j	                  t        |j                        t               | j	                  t        |j                  d         d       | j	                  t        |j                  d         d       |j                          y # |j                          w xY w)	NrE   rv  zpax/regtype4r  {   g  ^Aatimectime)r(   r'   r$   rS   rV   rX   r   r   rg  r^  r}  r  rL   r  s      r   test_pax_number_fieldsz"PaxReadTest.test_pax_number_fields  s    ll7[9
	mmN3GW\\40W[[#.W[[#.W]]L9T'--0%8U7#6#6w#?@,OU7#6#6w#?@,OIIKCIIKs   C:D( (D:c                 f   d}ddi}|D ]_  }| j                  |      5  t        j                  t        dt        j                  d      }	 t        j
                         }d|_        d	|_        ||_        |j                  |       |j                          t        t        d
      5 }|j                         }| j                  d|       |j                  d|      }d d d        t        t        d      5 }|j                          |j                         d d d        | j!                  t        j"                  d      5  t        j                  t        d       d d d        d d d        b y # |j                          w xY w# 1 sw Y   xY w# 1 sw Y   zxY w# 1 sw Y   BxY w# 1 sw Y   xY w)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   rE   r   rG   r  ru   rt   s   11 foo=bar
r   z)method tar: ReadError\('invalid header'\)rv  )subTestr(   r'   r   
PAX_FORMATr  r   r   r  r  rL   rU   r   r   r  r  r  r  )r   pax_header_replacementsr  replacementrI   r  rY  r   s           r   test_pax_header_bad_formatsz'PaxReadTest.test_pax_header_bad_formats  sJ   #
 en2K[1ll7C8J8J,79 )A"AFAE$/AMKKNIIK'4(A668DMM/48<<ED )
 '4(AJJLGGDM ) ++G,=,=?klLL;? m+ 21 3 IIK((
 )( ml+ 21sk   ,F&:E- F&&5FF&3"F(F&=FF&-E??F&FF&FF&F#F&&F0	N)r!   r"   r#   rU  r(   XHDTYPEr`  r  r   r  r  r  r,   r   r   r  r    s+    F??LF.(@r   r  c                       e Zd Zd Zd Zy)WriteTestBasec                    t        j                         }t        j                  || j                        5 }|j                  t        j                  d             d d d        | j                  |j                  d       |j                         }~t        j                          | j                  |j                         | j                  ||j                                y # 1 sw Y   xY w)Nr5  r  z#external fileobjs must never closed)r%   r   r(   r'   r    r  r  r   r,  r   r   
gc_collectrV   )r   r\   rI   r   s       r   test_fileobj_no_closez#WriteTestBase.test_fileobj_no_close  s    zz|\\$TYY73KK./ 8&KL}}%t}}/ 87s   %C  C)c                    t        j                  t        | j                        5 }t        j                  d      }t         j
                  t         j                  z
  |_        |j                  |t        j                  d|j                  z               d d d        | j                  t        d      5 }| j                  t        |j                               t         j
                  dz         d d d        y # 1 sw Y   cxY w# 1 sw Y   y xY w)Nr  r  rt   rx   )r(   r'   r   r    r  
RECORDSIZE	BLOCKSIZErX   r  r%   r   rV   rW   rU   )r   rI   r  r\   s       r   test_eof_markerzWriteTestBase.test_eof_marker  s    
 \\'499-&A'''*;*;;AFKK2::dQVVm45 .
 YYw%S-w/A/AA/EF &% .-
 &%s   A.C51;D5C>D
N)r!   r"   r#   r  r  r,   r   r   r  r    s    
0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y)	WriteTestr  c                    d}t        j                  t        | j                        }	 t        j                  |      }|j                  |       |j                          t        j                  t              }	 | j                  |j                         d   |d       |j                          y # |j                          w xY w# |j                          w xY w)Nd0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r   z!failed to store 100 char filename)	r(   r'   r   r    r  r  rL   rV   r  )r   r   rI   r  s       r   test_100_char_namezWriteTest.test_100_char_name&  s    
 !ll7DII.	%AKKNIIKll7#	S\\^A.79 IIK IIK IIKs   &B- 8$C -B?Cc                    t        j                  t        | j                        }	 t        j
                  j                  t        d      }t        |d      5 }|j                  d       d d d        |j                  |       |j                          | j                  t        j
                  j                  t              dd       y # 1 sw Y   _xY w# |j                          w xY w)Nr-  r      aaar   ztarfile is empty)r(   r'   r   r    rf   rg   rh   re   r  r   rL   assertGreatergetsize)r   rI   rg   r\   s       r   test_tar_sizezWriteTest.test_tar_size:  s    ll7DII.	77<<0DdD!T

6" "GGDMIIK277??73Q"	$ "! IIKs#   0C C(C CC C$c                 <   t        j                  t        | j                        }	 t        j
                  j                  t        d      }t        |d      5  	 d d d        |j                  |      }| j                  |j                  d       t        |d      5 }|j                  d       d d d        |j                  |      }| j                  |j                  d       |j                          y # 1 sw Y   xY w# 1 sw Y   SxY w# |j                          w xY w)Nr-  r   r   r  r*  )r(   r'   r   r    rf   rg   rh   re   
gettarinforV   rX   r  rL   )r   rI   rg   r[   r\   s        r   test_file_sizezWriteTest.test_file_sizeH  s    ll7DII.	77<<0DdD! "nnT*GW\\1-dD!T

6" "nnT*GW\\1-IIK "!
 "!
 IIKs<   0D	 C1AD	 C=+5D	 1C:6D	 =DD	 	Dc                    t         j                  j                  t        d      }t        j                  |       	 t        j                  t        | j                        }	 |j                  |      }| j                  |j                  d       |j                          	 t        j                  |       y # |j                          w xY w# t        j                  |       w xY w)N	directoryr   )rf   rg   rh   re   r   r(   r'   r   r    r  rV   rX   rL   r	   r   r   rg   rI   r[   s       r   test_directory_sizezWriteTest.test_directory_sizeX  s    ww||G[1
	",,w		2C...  q1		OOD! 		OOD!s#   $C	  -B4 C	 4CC	 	C c                 L   t         j                  j                  t        d      }t        j                  |       t        t         j                  j                  |d      d      j                          t        t         j                  j                  |d      d      j                          	 t        j
                  t        | j                        }	 t        j                  j                  d      5 }ddg|_        |j                  |       d d d        g }|j                         D ]=  }|j!                  t         j                  j#                  |j$                        d          ? | j'                  |g d       |j                          	 t)        j*                  t         j                  j                  |d             t)        j*                  t         j                  j                  |d             t)        j,                  |       y # 1 sw Y   xY w# |j                          w xY w# t)        j*                  t         j                  j                  |d             t)        j*                  t         j                  j                  |d             t)        j,                  |       w xY w)Nr  1r   2z
os.listdirrl  )r  r  r  )rf   rg   rh   re   r   r'   rL   r(   r   r    r   r  r  return_valuer   r   appendsplitr   rV   r	   rs  r   )r   rg   rI   mock_listdirpathsms         r   test_ordered_recursionz WriteTest.test_ordered_recursiong  s   ww||G[1
RWW\\$$c*002RWW\\$$c*002	",,w		2C	]]((6,14c
L-GGDM 7 )ALLqvv!6r!:; *  (?@		RWW\\$45RWW\\$45OOD! 76 		RWW\\$45RWW\\$45OOD!s>   +$H& H /H
A.H 8H& H
H H##H& &A=J#c                 P   t        j                  t        | j                        5 }t        j
                  j                  t        d      }t        |d      5 }|j                  d       d d d        |j                  t        j                  |            }|j                  |      }| j                  |j                  t               | j                  |j                  |j                         | j                  |j                   d       d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr-  r   r  r*  )r(   r'   r   r    rf   rg   rh   re   r  r  r	   r   r7  r   r8  rV   rX   )r   rI   rg   r\   r[   tarinfo2s         r   test_gettarinfo_pathlike_namez'WriteTest.test_gettarinfo_pathlike_name}  s    \\'499-77<<0DdD!T

6" "nnY%7%7%=>G~~d+H!!',,4W\\8==9W\\1- .-!! .-s$   1DD(BDD	DD%rn  ro  c                 @   t         j                  j                  t        d      }t         j                  j                  t        d      }t	        |d      5 }|j                  d       d d d        	 t        j                  ||       	 t        j                  t        | j                        }	 |j                  |       |j                  |      }| j                  |j                  d       |j                          	 t!        j"                  |       t!        j"                  |       y # 1 sw Y   xY w# t        $ r}| j                  d|z         Y d }~d }~ww xY w# |j                          w xY w# t!        j"                  |       t!        j"                  |       w xY w)Nrn  link_targetr   r  os.link(): %sr   )rf   rg   rh   re   r'   r  rn  PermissionErrorr  r(   r   r    r  rV   rX   rL   r	   rs  )r   rn  targetr\   r  rI   r[   s          r   test_link_sizezWriteTest.test_link_size  s$    ww||GV,g}5&$4JJv  	/GGFD!	#,,w		2Cv&...  q1		V$T"#    	/MM/A-..	/ 		V$T"sH   D&0D2 $E1 ,>E *E1 &D/2	E;EEE..E1 1,Fc                    t         j                  j                  t        d      }t        j                  d|       	 t        j                  t        | j                        }	 |j                  |      }| j                  |j                  d       |j                          	 t        j                  |       y # |j                          w xY w# t        j                  |       w xY w)Nsymlinkr  r   )rf   rg   rh   re   r  r(   r'   r   r    r  rV   rX   rL   r	   rs  r  s       r   test_symlink_sizezWriteTest.test_symlink_size  s    ww||GY/


=$'	#,,w		2C...  q1		T" 		T"s#   $C
 !-B5 C
 5CC
 
C!c                 <   t         j                  j                  t              }t	        j
                  t        | j                        }	 | j                  |j                  |d       |j                  |       | j                  |j                         g d       t        j                  t              5  |j                  |       d d d        | j                  |j                         g d       |j                          y # 1 sw Y   ;xY w# |j                          w xY w)Nzarchive name must be absolutezadded the archive to itself)rf   rg   r9  r   r(   r'   r    rV   r   r   r  r	   
change_cwdre   rL   )r   dstnamerI   s      r   test_add_selfzWriteTest.test_add_self  s    ''//'*ll7DII.	SXXw35GGGS\\^R13 %%g.  /S\\^R13 IIK /.
 IIKs%   	A(D	 1C=)D	 =DD	 	Dc                    t         j                  j                  t        d      }t        j                  |       	 dD ]7  }t         j                  j                  ||      }t        j                  |       9 d }t        j                  t        | j                  d      }	 |j                  |d|       |j                          | j                  t              5  |j                  |ddd |       d d d        t        j                  t        d	      }	 |D ]:  }| j                  |j                   d
       | j                  |j"                  d       < | j                  t%        |j'                               d       |j                          	 t        j(                  |       y # |j                          w xY w# 1 sw Y   xY w# |j                          w xY w# t        j(                  |       w xY w)Nr`   )r  r   bazc                 |    t         j                  j                  | j                        dk(  ry d| _        d| _        | S )Nr   r  r  )rf   rg   basenamer   r   ri  r   s    r   r`   z%WriteTest.test_filter.<locals>.filter  s3    77##GLL1U:! %r   rE   rv  	empty_dir)arcnamer`   Tra   r  r  r*  )rf   rg   rh   re   r   r	   create_empty_filer(   r'   r   r    r   rL   r  	TypeErrorrV   r   ri  rW   r   r  )r   tempdirr   r`   rI   r[   s         r   test_filterzWriteTest.test_filter  sh   '',,w1
	&-ww||GT2++D1 . ,,w		KHCVD		 ""9-dD&A . ,,w,C"G$$W[[#6$$W]]E:  #   S^^%5!6:		W% 		 .- 		W%sU   A%G !F" 5%G F70"G A(G ;G "F44G 7G <G GG G/Nc                    t         j                  j                  t        d      }|st	        j
                  |       nt        j                  |       t        j                  t        | j                        }	 |j                  ||       |j                          t        j                  t        d      }	 |j                         }|j                          |st	        j                  |       nt	        j                  |       | j!                  |j"                  |xs  |j%                  t         j&                  d             y # |j                          w xY w# |j                          w xY w)Nr  r  ra   r   )rf   rg   rh   re   r	   r  r   r(   r'   r   r    r   rL   r  rs  r   rV   r   r   sep)r   rg   cmp_pathdirr  rI   r  s          r   _test_pathnamezWriteTest._test_pathname  s     ggll7E*'',HHSMll7DII.	GGCG&IIKll7C(	
AIIKS!OOC !FT\\"&&#-FG IIK IIKs   7E 5E EE(c                    t         j                  j                  t        d      }t         j                  j                  t        d      }t        j                  |       	 t         j                  j                  |d      }t         j                  j                  |d      }t        |d      5 }|j                  d       d d d        t        j                  ||       t        j
                  |d      5 }|j                  |d       |j                  |d       d d d        t        j
                  |d	      5 }	 |j                  |d
       d d d        t        j                  |       t        j                  |       y # 1 sw Y   xY w# 1 sw Y   txY w# t        $ r | j                  d       Y gw xY w# 1 sw Y   lxY w# t        j                  |       t        j                  |       w xY w)Ntestsymlinksztestsymlinks.tarsourcer  r   z
something
r  rx   rq  rx  r  z&extractall failed with symlinked files)rf   rg   rh   re   r   r'   r  r  r(   r   rw  OSErrorr   r	   rs  r  )r   r  temparchivesource_filetarget_filerY  rI   s          r   test_extractall_symlinksz"WriteTest.test_extractall_symlinks  sp    '',,w7ggll7,>?
	&'',,wx8K'',,wy9Kk#&!& 'JJ{K0k3/3X6Y7 0 ka8CHNN*9 # ; 9 [)W%! '& 0/  HIIFGH 98 [)W%ss   AG +E?=4G 1'FG 7F79FG ?FG FG F41F73F44F77G <G ,G/c                 $   | j                  d       | j                  t        j                  j                  ddd             | j                  t        j                  j                  ddd             | j                  t        j                  j                  dd             | j                  t        j                  j                  ddd             | j                  t        j                  j                  dddd             | j                  t        j                  j                  dddd             | j                  t        j                  j                  dddd             | j                  t        j                  j                  dd             | j                  t        j                  j                  ddd             | j                  t        j                  j                  dddd             | j                  t        j                  j                  dddd             | j                  dt        j                  z   t        j                  z   dz          | j                  dt        j                  z   t        j                  z   dd       y )Nr  .r   ..T)r  )r  rf   rg   rh   r  r   s    r   test_pathnameszWriteTest.test_pathnames   s   E"BGGLLU;<BGGLLe<=BGGLLe45BGGLLeS9:BGGLLeS%@ABGGLLeT5ABBGGLLeT5ABBGGLLu56BGGLLud;<BGGLLuc5ABBGGLLudEBCEBFFNRVV3e;<EBFFNRVV3UEr   c                     t         j                  dk(  r| j                  dd       y | j                  dd       | j                  dd       y )Nry  zC:\foor  z/fooz///foo)r   r  r  r   s    r   test_abs_pathnameszWriteTest.test_abs_pathnames1  s>    <<7"	51.%0r   c                 2   t        j                  t              5  t        j                  t
        | j                        }	 |j                  d       |j                          t        j                  t
        d      }	 |D ]G  }|j                  dk7  s| j                  |j                  j                  d      |j                         I 	 |j                          	 d d d        y # |j                          w xY w# |j                          w xY w# 1 sw Y   y xY w)Nr  ra   ./)r	   r  re   r(   r'   r   r    r   rL   r   r   rh  r   rI   r  s      r   test_cwdzWriteTest.test_cwd8  s    !!'*,,w		2C		,,w,CAvv}(9(9$(?H  		 +*
 		 		 +*sA   %D C#*D<C87C8	D#C55D8D

DDc                    t         t        t        fD ]   G fddt        j                        } |       }t        j                  |       5  | j                        5  t        j                  t        | j                  |t        j                  ddi       d d d        d d d        | j                  |j                          y # 1 sw Y   /xY w# 1 sw Y   3xY w)Nc                       e Zd ZdZ fdZy)8WriteTest.test_open_nonwritable_fileobj.<locals>.BadFileTc                 0    | j                   r	d| _         y NF)first)r   r   exctypes     r   r  z>WriteTest.test_open_nonwritable_fileobj.<locals>.BadFile.writeM  s    zz%*
% "r   N)r!   r"   r#   r  r  )r  s   r   BadFiler  K  s    &r   r  nonr  )r6  r   r  )r  EOFErrorRuntimeErrorr%   r   r   check_no_resource_warningr  r(   r'   r   r    r  r   r,  )r   r  rY  r  s      @r   test_open_nonwritable_fileobjz'WriteTest.test_open_nonwritable_fileobjI  s    ,6G&"** & 	A99$?!!'*Wdii$+$6$6*/)9; + @ QXX&! 7 +* @?s$   C9CCCCC	r  )r!   r"   r#   r   r  r  r  r  r  r  r   r   r   rf   r  r	   r  r  r  r  r  r  r  r  r  r  r,   r   r   r  r  "  s    F($ "",	. XV,:<#<#, ""# ##$"&PH: ""& #&4F"1"'r   r  c                       e Zd Zy)GzipWriteTestNr   r,   r   r   r  r  ]  r   r   r  c                       e Zd Zy)Bz2WriteTestNr   r,   r   r   r  r  a  r   r   r  c                       e Zd Zy)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k7  xr	  e
ed      d       ej                  ej                  xs ej                  d      d               Zy)	StreamWriteTestw|Nc                 >   t        j                  t        | j                        }|j	                          | j
                  rg| j                         }t        t        d      5 }|j                         }d d d        |j                        }| j                  |j                  d       n.| j                  t              5 }|j                         }d d d        | j                  j                  d      t         j                  d       y # 1 sw Y   xY w# 1 sw Y   FxY w)Nrt   zfound trailing datar  zincorrect zero padding)r(   r'   r   r    rL   decompressorrU   
decompressr   unused_datarV   countr  )r   rI   decr\   r   s        r   test_stream_paddingz#StreamWriteTest.test_stream_paddingn  s    ll7DII.		##%Cgt$yy{ %>>$'DS__.CD7#tyy{ $E*G,>,>0	2 %$
 $#s   !D=DDDry  umaskzMissing umask implementationz$Emscripten's/WASI's umask is a stub.c                    t         j                  j                  t              rt	        j
                  t               t        j                  d      }	 t        j                  t        | j                        }|j                          t        j                  t              j                  dz  }| j                  |dd       t        j                  |       y # t        j                  |       w xY w)N   rz  i  zwrong file permissions)rf   rg   existsr   r	   rs  r
  r(   r'   r    rL   r  r  rV   )r   original_umaskrI   r    s       r   test_file_modezStreamWriteTest.test_file_mode~  s     77>>'"W%%	%,,w		2CIIK777#++e3DT5*BCHH^$BHH^$s   A-C C-)r!   r"   r#   r   r  r	  r   r   r   r  r   rf   r  r   is_emscriptenis_wasir  r,   r   r   r  r  i  st    FL2  X0IWR5I79X__0.%	9%r   r  c                       e Zd Zd Zy)GzipStreamWriteTestc                    t        j                  t        | j                        j	                          t        j                  t              j                  d      }t        j                  j                  t              |vsJ y)zf
        Ensure the source directory is not included in the tar header
        per bpo-41316.
        zlatin-1rv  N)r(   r'   r   r    rL   r  r  	read_textrf   rg   dirname)r   payloads     r    test_source_directory_not_leakedz4GzipStreamWriteTest.test_source_directory_not_leaked  sV    
 	Wdii(..0,,w'1191Ewww'w666r   N)r!   r"   r#   r  r,   r   r   r  r    s    7r   r  c                   .    e Zd Zerej                  ZydZy)Bz2StreamWriteTestN)r!   r"   r#   r6   BZ2Decompressorr  r,   r   r   r  r    s    *-3&&L4Lr   r  c                   .    e Zd Zerej                  ZydZy)LzmaStreamWriteTestN)r!   r"   r#   r>   LZMADecompressorr  r,   r   r   r  r    s    ,04((LdLr   r  c                   "    e Zd ZdZd Zd Zd Zy)_CompressedWriteTestsF   And we move to Bristol where they have a special, Very Silly candidatec                 ,   t        j                         }t        j                  t        | j
                  ||      5 }|j                  t        j                  d      t        j                  | j                               d d d        |S # 1 sw Y   |S xY w)Nr  r  )	r%   r   r(   r'   r   r    r  r  r  )r   r  r\   tarfls       r   _compressed_tarz$_CompressedWriteTest._compressed_tar  sf    zz|\\'499d(57:?MM'//%0"**T[[2IJ7 7 s   AB		Bc                 r    | j                  |      }| j                  |j                         dd d|z         y )Nr   rw   s   BZh%d1AY&SYr#  rV   r   r   r  r\   s      r   _test_bz2_headerz%_CompressedWriteTest._test_bz2_header  s7    ##M22.'-7	9r   c                 l    | j                  |      }| j                  |j                         d d d       y )Nr*  s   r%  r&  s      r   _test_gz_headerz$_CompressedWriteTest._test_gz_header  s/    ##M2!,o>r   N)r!   r"   r#   r  r#  r'  r)  r,   r   r   r   r     s    &F9
?r   r   c                       e Zd ZdZd Zy)Bz2CompressWriteTestr  c                 j    | j                  d       | j                  d       | j                  d       y Nru      	   r'  r   s    r   test_compression_levelsz,Bz2CompressWriteTest.test_compression_levels  ,    a a a r   Nr!   r"   r#   r   r1  r,   r   r   r+  r+    s    F!r   r+  c                       e Zd ZdZd Zy)Bz2CompressStreamWriteTestr  c                 j    | j                  d       | j                  d       | j                  d       y r-  r0  r   s    r   r1  z2Bz2CompressStreamWriteTest.test_compression_levels  r2  r   Nr3  r,   r   r   r5  r5    s    F!r   r5  c                       e Zd ZdZd Zy)GzCompressWriteTestr  c                 j    | j                  d       | j                  d       | j                  d       y r-  r)  r   s    r   r1  z+GzCompressWriteTest.test_compression_levels  ,    QQQr   Nr3  r,   r   r   r8  r8    s    F r   r8  c                       e Zd ZdZd Zy)GzCompressStreamWriteTestr  c                 j    | j                  d       | j                  d       | j                  d       y r-  r:  r   s    r   r1  z1GzCompressStreamWriteTest.test_compression_levels  r;  r   Nr3  r,   r   r   r=  r=    s    F r   r=  c                   @    e Zd Zd Z ej
                         d        Zy)CompressLevelRaisesc                     d}t        j                         }| j                  t              5  t	        j
                  t        d||       d d d        y # 1 sw Y   y xY w)Nr.  r  r  )r%   r   r  r  r(   r'   r   r&  s      r   test_compresslevel_wrong_modesz2CompressLevelRaises.test_compresslevel_wrong_modes  s>    zz|y)LL$MJ *))s   AAc                    t        j                         }| j                  t              5  t	        j
                  t        d|d       d d d        | j                  t              5  t	        j
                  t        d|d       d d d        | j                  t              5  t	        j
                  t        d|d       d d d        y # 1 sw Y   xY w# 1 sw Y   QxY w# 1 sw Y   y xY w)Nzw:bz2r   r  rw   zw|bz2)r%   r   r  rT  r(   r'   r   r   s     r   test_wrong_compresslevelsz-CompressLevelRaises.test_wrong_compresslevels  s     zz|z*LL'4qA +z*LL'4rB +z*LL'4rB +*	 +*****s#   C%C CCCC(N)r!   r"   r#   rB  r   requires_bz2rD  r,   r   r   r@  r@    s)    K WC Cr   r@  c                   X    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y)GNUWriteTestc                 .    t        |      dz  dz   }|dz  S )Nry   ru   )rW   )r   r~   blockss      r   _lengthzGNUWriteTest._length  s    Q3"|r   Nc                     d}t        |      t        j                  kD  r|dz  }|| j                  |      z  }|5t        |      t        j                  kD  r|dz  }|| j                  |      z  }|S )Nry   )rW   r(   LENGTH_NAMErJ  LENGTH_LINK)r   r   rn  r  s       r   
_calc_sizezGNUWriteTest._calc_size  sm    t9w***SLET\\$''ED	G,?,? ?SLET\\$''Er   c                    t        j                  |      }|r||_        t         j                  |_        t        j
                  t        d      }	 t         j                  |_        |j                  |       | j                  ||      }|j                  }| j                  ||d       |j                          t        j
                  t              }	 |j                         }| j                  |d       | j                  |j                   |j                   d       | j                  |j                  |j                  d       |j                          y # |j                          w xY w# |j                          w xY w)Nr   z%GNU longname/longlink creation failedzunable to read longname member)r(   r  r$  LNKTYPEr^  r'   r   r}  r   r  rN  rX  rV   rL   r  r  r   )r   r   rn  r[   rI   r  r  members           r   _testzGNUWriteTest._test  s   //$'#G"??GLll7C(	 ++CJKK t,BBR%LMIIKll7#		XXZF  46W\\6;;46W--v46 IIK IIK IIKs   AE A0E& E#&E8c                 &    | j                  d       y )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rR  r   s    r   test_longname_1023zGNUWriteTest.test_longname_1023  s    

12r   c                 &    | j                  d       y )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/longnamerU  r   s    r   test_longname_1024zGNUWriteTest.test_longname_1024!  s    

23r   c                 &    | j                  d       y )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_rU  r   s    r   test_longname_1025zGNUWriteTest.test_longname_1025$  s    

34r   c                 (    | j                  dd       y )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/longlnkrU  r   s    r   test_longlink_1023zGNUWriteTest.test_longlink_1023'  s    

69:r   c                 (    | j                  dd       y )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/longlinkrU  r   s    r   test_longlink_1024zGNUWriteTest.test_longlink_1024*  s    

6:;r   c                 (    | j                  dd       y )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_rU  r   s    r   test_longlink_1025zGNUWriteTest.test_longlink_1025-  s    

6;<r   c                 (    | j                  dd       y )NrT  r^  rU  r   s    r   test_longnamelink_1023z#GNUWriteTest.test_longnamelink_10230  s    

11	3r   c                 (    | j                  dd       y )NrX  ra  rU  r   s    r   test_longnamelink_1024z#GNUWriteTest.test_longnamelink_10244  s    

22	4r   c                 (    | j                  dd       y )Nr[  rd  rU  r   s    r   test_longnamelink_1025z#GNUWriteTest.test_longnamelink_10258  s    

33	5r   r   )r!   r"   r#   rJ  rN  rR  rV  rY  r\  r_  rb  re  rg  ri  rk  r,   r   r   rG  rG    s>    :345;<=345r   rG  c                       e Zd ZdZd Zy)DeviceHeaderTestr  c                 8   t         j                  j                  t        d      }t        j                  |       	 t        j                  t        | j                        }	 t        j                  d      }t        j                  d      }t
        j                  |_        t
        j                  |_        |j                  |       |j                  |       |j                          t        j                  t        d      }	 |j                  d      }|j                  d      }|j                          | j!                  |j"                  d       | j!                  |j$                  d       | j!                  |j"                  d       | j!                  |j$                  d       t        t        d      5 }|j'                         }d d d        |j(                  |j*                   }	||j(                  |j*                   }
t-        dd	      }| j!                  |	|   d
       | j!                  |
|   d       t/        j0                  |       y # |j                          w xY w# |j                          w xY w# 1 sw Y   xY w# t/        j0                  |       w xY w)Ndevice_header_testmy_block_devicer   my_regular_filera   r   rt   iI  iY  s   0000000 0000000 s                   )rf   rg   rh   re   r   r(   r'   r   r    r  BLKTYPEr^  REGTYPEr  rL   rS   rV   r,  r-  rU   rX  offset_dataslicer	   r  )r   r  rI   	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_filesA  s   '',,w(<=
#	&,,w		2C#OO1BC	#OO1BC	!(	!(	I&I&		 ,,w,C ]]+<=
 ]]+<=
		Z00!4Z00!4Z00!4Z00!4 gt$kkm %*++J,B,BCG*++J,B,BCG #31NW^46FGW^4jAW%3 		 		 %$ W%sV   $J  A8I *J "I! %BJ 5I6A0J IJ !I33J 6I?;J JN)r!   r"   r#   r   r  r,   r   r   rm  rm  =  s    F'&r   rm  c                       e Zd ZdZej
                  j                  ed      Zd Z	e
d        Ze
d        Zd Zd Zd Zd	 Zd
 Zd Zy)
CreateTestzx:
spameggs42c                 6    t        j                  t               y r   )r	   rs  r   r   s    r   rJ   zCreateTest.setUpq  s    !r   c                 |    t        | j                  d      5 }|j                  d       d d d        y # 1 sw Y   y xY w)Nr   r  )r'   	file_pathr  )clsr\   s     r   
setUpClasszCreateTest.setUpClasst  s*    #--&$JJv '&&   2;c                 B    t        j                  | j                         y r   )r	   rs  r  r  s    r   tearDownClasszCreateTest.tearDownClassy  s    'r   c                    t        j                  t        | j                        5 }|j	                  | j
                         d d d        | j                  t              5 }|j                         }d d d        | j                  t              d       | j                  d|d          y # 1 sw Y   hxY w# 1 sw Y   FxY wNru   r  r   )r(   r'   r   r    r   r  r*   r  rV   rW   r   r   tobjnamess      r   test_createzCreateTest.test_create}  s    \\'499-HHT^^$ . \\'"dMMOE #UQ'lE!H- .- #"s   B(B4(B14B=c                    t        j                  t        | j                        5 }|j	                  | j
                         d d d        | j                  t              5  t        j                  t        | j                        }d d d        | j                  t              5 }|j                         }d d d        | j                  t              d       | j                  d|d          y # 1 sw Y   xY w# 1 sw Y   txY w# 1 sw Y   RxY wr  )r(   r'   r   r    r   r  r  FileExistsErrorr*   r  rV   rW   r   r  s      r   test_create_existingzCreateTest.test_create_existing  s    \\'499-HHT^^$ . /<<3D 0 \\'"dMMOE #UQ'lE!H- .- 0/ #"s#   C*%C6 D*C36C?Dc                 d   | j                  t        d      5 }|j                  | j                         d d d        | j                  t              5 }|j	                         }d d d        | j                  t              d       | j                  d|d          y # 1 sw Y   hxY w# 1 sw Y   FxY wNxru   r  r   )r*   r   r   r  r  rV   rW   r   r  s      r   test_create_taropenzCreateTest.test_create_taropen  s    \\'3'4HHT^^$ ( \\'"dMMOE #UQ'lE!H- (' #"s   BB&B#&B/c                    | j                  t        d      5 }|j                  | j                         d d d        | j	                  t
              5  | j                  t        d      5  	 d d d        d d d        | j                  t              5 }|j                         }d d d        | j                  t              d       | j                  d|d          y # 1 sw Y   xY w# 1 sw Y   |xY w# 1 sw Y   xY w# 1 sw Y   ^xY wr  )
r*   r   r   r  r  r  r  rV   rW   r   r  s      r   test_create_existing_taropenz'CreateTest.test_create_existing_taropen  s    \\'3'4HHT^^$ ( /gs+ , 0 \\'"dMMOE #UQ'lE!H- (' ,+ 0/ #"s;   CC0'C$)C0C<C!$C-	)C00C9<Dc                    t        j                  t        j                  t              | j
                        5 }| j                  |j                  t               | j                  |j                  t        j                  j                  t                     |j                  t        j                  | j                               |j                         }d d d        | j                  t!              d       | j#                  d|d          | j%                  t              5 }|j                         }d d d        | j                  t!        |      d       | j#                  d|d          y # 1 sw Y   xY w# 1 sw Y   FxY wr  )r(   r'   r	   r   r   r    r7  r   r8  rV   rf   rg   r9  r   r  r  rW   r   r*   r  s      r   test_create_pathlike_namez$CreateTest.test_create_pathlike_name  s   \\),,W5tyyAT!!$))S1TYY(@AHHY''78MMOE	 B
 	UQ'lE!H-\\'"dMMOE #UQ'lE!H- BA #"s   BE+!E7+E47F c                    | j                  t        j                  t              d      5 }| j	                  |j
                  t               | j                  |j
                  t        j                  j                  t                     |j                  t        j                  | j                               |j                         }d d d        | j                  t              d       | j                  d|d          | j                  t              5 }|j                         }d d d        | j                  t        |      d       | j                  d|d          y # 1 sw Y   xY w# 1 sw Y   FxY wr  )r*   r	   r   r   r7  r   r8  rV   rf   rg   r9  r   r  r  rW   r   r  s      r   !test_create_taropen_pathlike_namez,CreateTest.test_create_taropen_pathlike_name  s    \\),,W5s;t!!$))S1TYY(@AHHY''78MMOE	 <
 	UQ'lE!H-\\'"dMMOE #UQ'lE!H- <; #"s   BEE)E&)E2N)r!   r"   r#   r   rf   rg   rh   re   r  rJ   classmethodr  r  r  r  r  r  r  r  r,   r   r   r  r  k  sf    FWl3I"   ( (.
.....r   r  c                       e Zd Zd Zy)GzipCreateTestc                    t        j                  t        | j                  d      5 }|j	                  | j
                         d d d        t        j                  t        dd      5 }	 d d d        y # 1 sw Y   0xY w# 1 sw Y   y xY w)Nru   r  zr:gzr(   r'   r   r    r   r  r   r  s     r   test_create_with_compresslevelz-GzipCreateTest.test_create_with_compresslevel  sZ    \\'499A>$HHT^^$ ?\\'6;t <; ?>;;   A2'A>2A;>BNr!   r"   r#   r  r,   r   r   r  r        r   r  c                       e Zd Zd Zy)Bz2CreateTestc                    t        j                  t        | j                  d      5 }|j	                  | j
                         d d d        t        j                  t        dd      5 }	 d d d        y # 1 sw Y   0xY w# 1 sw Y   y xY w)Nru   r  r:bz2r  r  s     r   r  z,Bz2CreateTest.test_create_with_compresslevel  sZ    \\'499A>$HHT^^$ ?\\'7!< =< ?><<r  Nr  r,   r   r   r  r    r  r   r  c                       e Zd Zd Zy)LzmaCreateTestc                     t        j                  t        | j                  d      5 }|j	                  | j
                         d d d        y # 1 sw Y   y xY w)Nru   )presetr  r  s     r   test_create_with_presetz&LzmaCreateTest.test_create_with_preset  s4    \\'499Q74HHT^^$ 877s   AAN)r!   r"   r#   r  r,   r   r   r  r    s    %r   r  c                       e Zd ZdZdZdZy)CreateWithXModeTestr  N)r!   r"   r#   r   r  r  r,   r   r   r  r    s    F#' r   r  rn  ro  c                   *    e Zd Zd Zd Zd Zd Zd Zy)HardlinkTestc                 R   t         j                  j                  t        d      | _        t         j                  j                  t        d      | _        t        | j                  d      5 }|j                  d       d d d        	 t        j                  | j                  | j
                         t        j                  t        d      | _        | j                  j                  | j                         y # 1 sw Y   yxY w# t        $ r}| j                  d|z         Y d }~sd }~ww xY w)Nr  r   r      foor  r   )rf   rg   rh   re   r  r   r'   r  rn  r  r  r(   r   rI   r   )r   r\   r  s      r   rJ   zHardlinkTest.setUp  s    77<</77<</$((D!TJJv "	/GGDHHdhh' <<-TXX "!
  	/MM/A-..	/s$   )C3*C? 3C<?	D&D!!D&c                     | j                   j                          t        j                  | j                         t        j                  | j
                         y r   )rI   rL   r	   rs  r  r   r   s    r   rM   zHardlinkTest.tearDown  s4    ""r   c                     | j                   j                  | j                        }| j                  |j                  t
        j                  d       y )Nzadd file as regular failed)rI   r  r  rV   r^  r(   rt  r`  s     r   test_add_twicezHardlinkTest.test_add_twice   s9     ((%%dhh/w,	.r   c                     | j                   j                  | j                        }| j                  |j                  t
        j                  d       y )Nzadd file as hardlink failed)rI   r  r   rV   r^  r(   rP  r`  s     r   test_add_hardlinkzHardlinkTest.test_add_hardlink  s7    ((%%dhh/w-	/r   c                     d| j                   _        | j                   j                  | j                        }| j	                  |j
                  t        j                  d       y )NTzdereferencing hardlink failed)rI   dereferencer  r   rV   r^  r(   rt  r`  s     r   test_dereference_hardlinkz&HardlinkTest.test_dereference_hardlink  sC    #((%%dhh/w/	1r   N)r!   r"   r#   rJ   rM   r  r  r  r,   r   r   r  r    s    #
./
1r   r  c                   &    e Zd ZddZd Zd Zd Zy)PaxWriteTestNc                 p   t        j                  |      }|r||_        t         j                  |_        t        j
                  t        dt         j                        }	 |j                  |       |j                          t        j
                  t              }	 |r1|j                         d   j                  }| j                  ||d       n0|j                         d   j                  }| j                  ||d       |j                          y # |j                          w xY w# |j                          w xY w)Nr   r   r   zPAX longlink creation failedzPAX longname creation failed)r(   r  r$  rP  r^  r'   r   r  r  rL   r   rV   r   )r   r   rn  r[   rI   lns          r   rR  zPaxWriteTest._test  s    //$'#G"??GLll7C0B0BC	KK IIKll7#	NN$Q'00  q*HINN$Q',,  q*HIIIK IIK IIKs   D A#D# D #D5c                 x   dddddd}t        j                  t        dt         j                  |      }	 |j	                  t        j
                  d             |j                          t        j                  t        d	
      }	 | j                  |j                  |       | j                  |j                         d   j                  |       |j                  j                         D ]o  \  }}| j                  t        |      t               | j                  t        |      t               |t         j                  v sW	 t        j                  |   |       q 	 |j                          y # |j                          w xY w# t        t         f$ r | j#                  d       Y w xY w# |j                          w xY w)Nr   0z1.23   äöütest)r  r   rg  r  r  r   )r   r  rE   rv  r   z"unable to convert pax header field)r(   r'   r   r  r  r  rL   rV   r  r   r  assertIsNotr^  rJ  PAX_NUMBER_FIELDSr  rT  r   )r   r  rI   keyvals        r   test_pax_global_headerz#PaxWriteTest.test_pax_global_header-  sY   & &( ll7C0B0B')	KK/0IIK ll7[9	S__k:S^^-a0<<kJOO113S  cE2  cE2'333H11#6s; 4 IIK# IIK &z2 H		"FGH IIKs<   $E, B9F'  FF' ,E> F$!F' #F$$F' 'F9c                 t   ddd}t        j                  t        dt         j                  d      }	 t        j                         }d|_        d|_        ||_        |j                  |       |j                          t        j                  t        d	      }	 |j                         d
   }| j                  |j                  |       | j                  |j
                  d       | j                  |j                  d       |j                          y # |j                          w xY w# |j                          w xY w)Nr  123)rg   r   r   rE   r  r     rv  r   r  )r(   r'   r   r  r  r   r   r  r  rL   r   rV   )r   r  rI   r  s       r   test_pax_extended_headerz%PaxWriteTest.test_pax_extended_headerM  s      %U3ll7C0B0B$/1	!A#AFAE'AMKKNIIKll7[9	 #AQ]]K8QVVU+QUUC(IIK IIK IIKs   :D A'D% D"%D7c                 .   t        j                         }d|_        d|_        d|_        d|_        d|_        |j                         }|j                  |d      }| j                  |d   d       | j                  |d	   t               | j                  |d	   d
       | j                  |d   d       | j                  |d   d       | j                  |d   d       | j                  |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|_        |j                         }|j                  |d      }| j                  |d   d       | j                  |d	   d       | j                  |d   d       | j                  |d   d       | j                  |d   d       | j                  |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          y )%Nr  g@@r   r  |   rE   rv  r   rg  r  rX   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   rg  rX   r   r   r  create_pax_headerrV   r7  rE  rJ  )r   r  infor  s       r   test_create_pax_headerz#PaxWriteTest.test_create_pax_headerf  s    OOzz|$$TK$@fu-d7mS1g-fs+ec*ec*b	)\]Cj)*+0:6 ## &+3Z0 399 <A9E ]	]
 Cj
 **
 -2#J7	8 OOzz|$$TK$@f{3g*fq)ea(ea(b	)\]Cj)*,1#J7 << 8	8
 ((
 */s4
 7>>
 AFb	J ]] Cj ** -2#J7	8r   r   )r!   r"   r#   rR  r  r  r  r,   r   r   r  r    s    0@258r   r  c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	UnicodeTestc                 &    | j                  d       y )NrE   _test_unicode_filenamer   s    r   test_iso8859_1_filenamez#UnicodeTest.test_iso8859_1_filename  s    ##K0r   c                 &    | j                  d       y )Nutf7r  r   s    r   test_utf7_filenamezUnicodeTest.test_utf7_filename  s    ##F+r   c                 &    | j                  d       y )Nutf-8r  r   s    r   test_utf8_filenamezUnicodeTest.test_utf8_filename  s    ##G,r   c                    t        j                  t        d| j                  |d      }	 d}|j	                  t        j
                  |             |j                          t        j                  t        |      }	 | j                  |j                         d   j                  |       |j                          y # |j                          w xY w# |j                          w xY w)Nr   r^  r   rG   errorsr  rv  r   )
r(   r'   r   r   r  r  rL   rV   r   r   )r   rG   rI   r   s       r   r  z"UnicodeTest._test_unicode_filename  s    ll7C$,X?	!DKK-.IIKll7X6	S^^-a055t<IIK IIK IIKs   &B: <-C :CC!c                 v   t        j                  t        d| j                  dd      }	 t        j                         }d|_        | j                  t        |j                  |       d|_        d|_	        | j                  t        |j                  |       |j                          y # |j                          w xY w)Nr   r   r^  r  r  r  )r(   r'   r   r   r  r   r  UnicodeErrorr  ri  rL   r  s      r   test_unicode_filename_errorz'UnicodeTest.test_unicode_filename_error  s    ll7C$+H>
	oo'G)GLlCKKA GL*GMlCKKAIIKCIIKs   A+B& &B8c                    t        j                  t        ddd      }	 |D ]  }| j                  t	        |j
                        t               | j                  t	        |j                        t               | j                  t	        |j                        t               | j                  t	        |j                        t                	 |j                          y # |j                          w xY w)Nra   rE   r^  rG   r  )r(   r'   r$   r'  r^  r   r8  r$  ri  r  rL   r  s      r   test_unicode_argumentz!UnicodeTest.test_unicode_argument  s    ll7C$/B	d166lC0d1::.4d177mS1d177mS1	  IIKCIIKs   B+C C.c                 <   t        j                  d      }d|_        d|_        t        j                  t
        d| j                  d      }	 |j                  |       |j                          t        j                  t
        d      }	 |j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  t         j                  k7  rt|j                          t        j                  t
        d      }|j                  d      }| j                  |j                  d       | j                  |j                  d       |j                          y # |j                          w xY w# |j                          w xY w)	Nr  r  r   rE   )r    r   rG   rv  r   u	   )r(   r  ri  r  r'   r   r   r  rL   rS   rV   r  )r   r  rI   s      r   test_uname_unicodezUnicodeTest.test_uname_unicode  s"   OOE"  ll7T[[$/1	KKNIIKll7[9	e$AQWWn5QWWn5{{g000		ll7W=MM%(  *>?  *>?IIK IIK IIKs   E4 	CF	 4F	FN)
r!   r"   r#   r  r  r  r  r  r  r  r,   r   r   r  r    s%    1,-
r   r  c                   d    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y)UstarUnicodeTestc                     | j                  d       | j                  dt               | j                  d       | j                  dt               y Nr  e01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890ud   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿue   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿ_test_ustar_namerT  r   s    r   test_unicode_name1z#UstarUnicodeTest.test_unicode_name1  B    /05zB?@@*Mr   c                 R    | j                  d       | j                  dt               y Nud   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿue   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr  r   s    r   test_unicode_name2z#UstarUnicodeTest.test_unicode_name2  "    ABBJOr   c                     | j                  d       | j                  dt               | j                  d       | j                  dt               y )Na   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123/40123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123ÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r  r   s    r   test_unicode_longname1z'UstarUnicodeTest.test_unicode_longname1	  sD    NONPZ[PQQS]^r   c                 \    | j                  dt               | j                  dt               y )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r  r   s    r   test_unicode_longname2z'UstarUnicodeTest.test_unicode_longname2	  s&    PR\]SU_`r   c                 ~    | j                  dt               | j                  d       | j                  dt               y )Nu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901ÿÿ/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567ÿu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678ÿr  r   s    r   test_unicode_longname3z'UstarUnicodeTest.test_unicode_longname3	  s5    TV`a^__aklr   c                 R    | j                  d       | j                  dt               y )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345ÿÿu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456ÿÿr  r   s    r   test_unicode_longname4z'UstarUnicodeTest.test_unicode_longname4	  s#    `aacmnr   Nc                    t        j                  t        d| j                  d      5 }t        j                  |      }||j                  |       n| j                  ||j
                  |       d d d        |Jt        j                  t        dd      5 }|D ]  }| j                  ||j                          n d d d        y y # 1 sw Y   VxY w# 1 sw Y   y xY w)Nr   r  r  ra   rv  )	r(   r'   r   r   r  r  r  rV   r   r   r   excrI   r  s        r   r  z!UstarUnicodeTest._test_ustar_name	  s    \\'3t{{WMQT%A{A!!#s{{A6 N ;gsW=A$$T1662  >=  NM >=s   AC%CCCc                     | j                  d       | j                  dt               | j                  d       | j                  dt               y r  _test_ustar_linkrT  r   s    r   test_unicode_link1z#UstarUnicodeTest.test_unicode_link1$	  r  r   c                 R    | j                  d       | j                  dt               y 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      }||_        ||j                  |       n| j                  ||j                  |       d d d        |Jt        j                  t        dd      5 }|D ]  }| j                  ||j
                          n d d d        y y # 1 sw Y   VxY w# 1 sw Y   y xY w)Nr   r  r  r  ra   rv  )	r(   r'   r   r   r  r$  r  r  rV   r	  s        r   r  z!UstarUnicodeTest._test_ustar_link.	  s    \\'3t{{WMQT&AAJ{A!!#s{{A6 N ;gsW=A$$T1::6  >=  NM >=s   AC%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    sG    !!F
NP_am
oNPr   r  c                   *    e Zd Zej                  Zd Zy)GNUUnicodeTestc                     dD ]<  \  }}t        j                  t        |d      5 }	 |j                  |      }d d d        > y # t        $ r | j                  d       Y 'w xY w# 1 sw Y   ixY w)N))r  u   pax/bad-pax-)rE   u   pax/bad-pax-äöür   r  z%unable to read bad GNU tar pax headerr(   r'   r$   rS   rc  r   r   rG   r   rI   r  s        r   test_bad_pax_headerz"GNUUnicodeTest.test_bad_pax_headerB	  ss    <NHd g%68;>Gd+A8 8<   GIIEFG	8 8(   A#AA A#A  A##A,	N)r!   r"   r#   r(   r}  r   r  r,   r   r   r  r  >	  s    FGr   r  c                   .    e Zd Zej                  ZdZd Zy)PAXUnicodeTestNc                     dD ]<  \  }}t        j                  t        |d      5 }	 |j                  |      }d d d        > y # t        $ r | j                  d       Y 'w xY w# 1 sw Y   ixY w)N))r  u   pax/hdrcharset-)rE   u   pax/hdrcharset-äöür   r  z)unable to read POSIX.1-2008 binary headerr  r  s        r   test_binary_headerz!PAXUnicodeTest.test_binary_headerW	  ss    ?NHd g%68;>Kd+A8 8?   KIIIJK	8 8r  )r!   r"   r#   r(   r  r   r  r  r,   r   r   r  r  P	  s    F #'
Kr   r  c                        e Zd Zd ZddZd Zy)AppendTestBasec                     t         | _        t        j                  j	                  | j                        r t        j                  | j                         y y r   )r   r$   rf   rg   r  r	   rs  r   s    r   rJ   zAppendTestBase.setUpg	  s4    77>>$,,'T\\* (r   c                 n   t        j                  t        d      5 }|j                  d      }d|_        |j                  |      5 }t        j                  | j                  |      5 }|j                  ||       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrE   rv  rQ   r  )r(   r'   r$   rS   r   rT   r  )r   r    srcr  rY  rI   s         r   _create_testtarzAppendTestBase._create_testtarl	  s    \\'K8Co.AAF#q\\$,,5KK1% 6 $ 98 65 $# 98s;   *B+!B'B:BB+BBB(	$B++B4c                     | j                  d| j                  z          | j                  t        j                  t        j
                  t        d       y )Nr  r   )r"  r   r  r(   r  r'   r   r   s    r   test_append_compressedz%AppendTestBase.test_append_compressedt	  s7    TDKK/0'++W\\7CHr   N)r  )r!   r"   r#   rJ   r"  r$  r,   r   r   r  r  d	  s    +
&Ir   r  c                   h    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y)
AppendTestNc                     t        j                  | j                  d|      5 }|j                  t        j                  d             d d d        y # 1 sw Y   y xY w)Nr   r  r   )r(   r'   r$   r  r  )r   r6  rI   s      r   _add_testfilezAppendTest._add_testfile{	  s9    \\$,,W=KK./ >==s   %AAr   c                     t        j                  | j                  |      5 }| j                  |j	                         |       d d d        y # 1 sw Y   y xY w)Nr  )r(   r'   r$   rV   r  )r   r  r6  rI   s       r   rR  zAppendTest._test	  s8    \\$,,8CS\\^U3 988s   !AAc                 D    | j                          | j                          y r   )r(  rR  r   s    r   test_non_existingzAppendTest.test_non_existing	  s    

r   c                     t        j                  | j                  d      j                          | j	                          | j                          y )Nr  )r(   r'   r$   rL   r(  rR  r   s    r   
test_emptyzAppendTest.test_empty	  s2    T\\4(..0

r   c                     t        j                  d      }| j                  |       |j                  d       | j	                  |       y )Ns                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   r   r  )r%   r   r(  rz   rR  r   s     r   test_empty_fileobjzAppendTest.test_empty_fileobj	  s7    zz,'4 		!

4
 r   c                 2   | j                          t        | j                  d      5 }|j                         }d d d        t	        j
                        }| j                  |       |j                  d       | j                  ddg|       y # 1 sw Y   VxY w)Nrt   r   r  r   )r  r6  )	r"  r'   r$   rU   r%   r   r(  rz   rR  r   s      r   test_fileobjzAppendTest.test_fileobj	  sr    $,,%99;D &zz$4 		!

%
6 &%s   BBc                 l    | j                          | j                          | j                  ddg       y )Nr  r   )r  )r"  r(  rR  r   s    r   test_existingzAppendTest.test_existing	  s,    

%
(r   c                     t        | j                  d      5 }|j                  |       d d d        | j                  t        j
                  | j                         y # 1 sw Y   4xY wr  )r'   r$   r  r  r(   r  r(  )r   r   r\   s      r   _test_errorzAppendTest._test_error	  sH    $,,%JJt &'++T-?-?@ &%s   AA%c                 &    | j                  d       y )Nr   r5  r   s    r   	test_nullzAppendTest.test_null	  s    r   c                 &    | j                  d       y )N                r7  r   s    r   test_incompletezAppendTest.test_incomplete	      $r   c                 l    t        j                  d      j                         }| j                  |       y )Nr  r(   r  r  r5  r   r   s     r   test_premature_eofzAppendTest.test_premature_eof	  s'    u%++-r   c                 r    t        j                  d      j                         }| j                  |dz          y )Nr  r:  r>  r?  s     r   test_trailing_garbagez AppendTest.test_trailing_garbage	  s,    u%++-
*+r   c                 &    | j                  d       y )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar7  r   s    r   test_invalidzAppendTest.test_invalid	  r<  r   r   )r!   r"   r#   r$  r(  rR  r+  r-  r/  r1  r3  r5  r8  r;  r@  rB  rD  r,   r   r   r&  r&  x	  sS    !0 !'4 4
!7)A
%,%r   r&  c                       e Zd Zy)GzipAppendTestNr   r,   r   r   rF  rF  	  r   r   rF  c                       e Zd Zy)Bz2AppendTestNr   r,   r   r   rH  rH  	  r   r   rH  c                       e Zd Zy)LzmaAppendTestNr   r,   r   r   rJ  rJ  	  r   r   rJ  c                       e Zd Zd Zd Zd Zy)
LimitsTestc                    t        j                  d      }|j                  t         j                         t        j                  d      }| j	                  t
        |j                  t         j                         t        j                  d      }|j                  t         j                         t        j                  d      }| j	                  t
        |j                  t         j                         t        j                  d      }| j	                  t
        |j                  t         j                         t        j                  d      }d|_        | j	                  t
        |j                  t         j                         t        j                  d      }d|_        | j	                  t
        |j                  t         j                         y )	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/longnamerY  r       )r(   r  r  r   r  rT  r$  r   r`  s     r   test_ustar_limitszLimitsTest.test_ustar_limits	  s4   //"34g**+ //"9:*gmmW5I5IJ //":;g**+ //">?*gmmW5I5IJ //";<*gmmW5I5IJ //*-4*gmmW5I5IJ //&) *gmmW5I5IJr   c                 x   t        j                  d      }|j                  t         j                         t        j                  d      }d|_        |j                  t         j                         t        j                  d      }d|_        | j                  t        |j                  t         j                         y NrN  rY  r   l          )r(   r  r  r}  r$  r   r  rT  r`  s     r   test_gnu_limitszLimitsTest.test_gnu_limits	  s~    //";<g(()//*-4g(() //&)+*gmmW5G5GHr   c                 X   t        j                  d      }|j                  t         j                         t        j                  d      }d|_        |j                  t         j                         t        j                  d      }d|_        |j                  t         j                         y rR  )r(   r  r  r  r$  r   r`  s     r   test_pax_limitszLimitsTest.test_pax_limits	  sr    //";<g(()//*-4g(()//&)+g(()r   N)r!   r"   r#   rP  rS  rU  r,   r   r   rL  rL  	  s    K>I
*r   rL  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                  j!                  d
      d                      Zy)MiscTestc                 @   | j                  t        j                  dddd      d       | j                  t        j                  dddd      d       | j                  t        j                  ddd      d       | j                  t        j                  d	dd      d       y )
Nr     r   r^  s   foo     foobarr*  r  s   foo bar )rV   r(   stnntsr   s    r   test_char_fieldszMiscTest.test_char_fields	  s    UAwA)	+Xq'8D	!%5wI	 ]GXF	 r   c                    | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d	      d
       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  d      d       y )N   0000001 ru      7777777            rO               rl                      r  r   s           )rV   r(   ntir   s    r   test_read_number_fieldsz MiscTest.test_read_number_fields	
  s     	^4a8^4i@%HI#	%%HI#	%%HI	%HI	%HI+	- 	U+Q/\2A6r   c                    | j                  t        j                  d      d       | j                  t        j                  d      d       | j                  t        j                  dt        j                        d       | j                  t        j                  dt        j                        d	       | j                  t        j                  d
t        j                        d       | j                  t        j                  dt        j                        d       | j                  t        j                  dt        j                        d       | j                  t        j                  dt        j                        d       | j                  t        j                  dt        j                        d       | j                  t        j                  t        j                  dt        j                              d       y )Nru   r_  ra  r`  rO  r  rb  rd  rc  rl  re  rg  rf  ri  rh  g      Yg      0Bs         gr   )rV   r(   itnr}  rj  r   s    r   test_write_number_fieldsz!MiscTest.test_write_number_fields
  sa   Q8Y/@Z8J8JK<	>Z8J8JK<	>R0B0BC<	>T'2D2DE<	>%7,3,>,>@<	> 	VG4F4FG<	>]7;M;MN<	>W[[g>P>P%QRTUVr   c                 |   | j                  t              5  t        j                  ddt        j                         d d d        | j                  t              5  t        j                  ddt        j                         d d d        | j                  t              5  t        j                  ddt        j
                         d d d        | j                  t              5  t        j                  ddt        j
                         d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   exY w# 1 sw Y   y xY w)Nrl  rY  rO  l       l        )r  rT  r(   rm  r   r}  r   s    r   test_number_field_limitsz!MiscTest.test_number_field_limits4
  s    z*KKAw334 +z*KK
Aw';';< +z*KK7+=+=> +z*KKq'*<*<= +* +*******s/   &D&D&D&&D2DD#&D/2D;c                 D    h d}t        j                  | t        |       y )N>0   NULgrprm  rj  r\  pwdr[  mainrs  CHRTYPEr_  rP  rt  SYMTYPEXGLTYPEr  versionAREGTYPECONTTYPEFIFOTYPEfilemoder  	GNU_MAGIC	GNU_TYPES
PAX_FIELDSr  rM  rL  POSIX_MAGICcopyfileobjExFileObjectcalc_chksumsLENGTH_PREFIXREGULAR_TYPESEOFHeaderErrorGNUTYPE_SPARSEPAX_NAME_FIELDSSOLARIS_XHDTYPESUPPORTED_TYPESEmptyHeaderErrorGNUTYPE_LONGLINKr|  LinkFallbackErrorr  symlink_exceptionInvalidHeaderErrorTruncatedHeaderErrorSubsequentHeaderError)not_exported)r   check__all__r(   )r   r  s     r   test__all__zMiscTest.test__all__>
  s    ! 	T7Fr   c                 ,   t         j                  j                  t         j                  j                  t              d      }| j                  t        j                        5 }t        j                  d      f}t        j                  j                  j                  t        j                  d|      5  t        j                  |       d d d        d d d        | j                  dt!        j"                               y # 1 sw Y   7xY w# 1 sw Y   ;xY w)Nr   zlzma module is not availabler@   )r  z?
- method xz: CompressionError('lzma module is not available')
)rf   rg   rh   r  r  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_missingN
  s    RWW__X68HIw001W,,-KLME$$++GOOXSX+YU# Z 2
 	O!!"	
 ZY 21s%   !AD
2C>D
>D	D

Dzrequires symlink supportchmodzmissing os.chmodos.chmodc                    t         j                  j                  t        d      fd}||_        t         j                  j                  t        d      }t               5 }|j                  dd       |j                  dt        j                  d       |j                  d|       d d d        t        j                  |       	 j                         j                  d	
       t        j                  |       t        j                         y # 1 sw Y   kxY w# t        j                  |       t        j                         w xY w)N
test127987c                     t         j                  j                  |       }t         j                  j                  |g      k7  rt	        d|      y )Nz8should not try to chmod anything outside the destination)rf   rg   realpath
commonpath	Exception)rg   r    r  target_pathr  s       r   mock_chmod_side_effectzRMiscTest.test_deferred_directory_attributes_update.<locals>.mock_chmod_side_effect`
  sH    ''**40Kww!!;"89WD Z\ghh Er   outside_tree_dirr  r  
symlink_to
?rwsrwsrwtr^  r    rI   r  )rf   rg   rh   re   r  ArchiveMakerr   r(   r_  makedirsr'   rw  r	   r  )r   
mock_chmodr  r  arcr  s        @r   )test_deferred_directory_attributes_updatez2MiscTest.test_deferred_directory_attributes_updateZ
  s    
 '',,w5	i "8
77<<1CD^sGGCCG(GGCgooLGAGGC$4G5 
 	$%	&HHJ!!wu!=-.W% ^ -.W%s    A	D!D D,EN)r!   r"   r#   r]  rk  rn  rq  r  r  r   r   r	   can_symlinkr   rf   r  r  r  r,   r   r   rW  rW  	  s     7(W.>G 

 X...02LMXW-/AB]]$& % C N&r   rW  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y)CommandLineTestc                     t        j                  ddg|i |\  }}}|j                  t        j                  j                         d      S )N-mr(      
)r
   assert_python_okr   rf   linesepr   )r   argsr  rcr   errs         r   
tarfilecmdzCommandLineTest.tarfilecmdv
  sL    $55dI @ @8>@C{{2::,,.66r   c                 0    t        j                  ddg| S )Nr  r(   )r
   assert_python_failure)r   r  s     r   tarfilecmd_failurez"CommandLineTest.tarfilecmd_failure{
  s    224JTJJr   c                 f   t        j                  dd      t        j                  dd      g}| j                  t        j                  |       t        j                  |d      5 }|D ]2  }|j                  |t        j                  j                  |             4 	 d d d        y # 1 sw Y   y xY w)Ntokenize_tests.txttokenizedatarU  9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr   r  )r   r#  rr  r	   rs  r(   r'   r   rf   rg   r  )r   tar_namefilesr  tardatas        r   make_simple_tarfilez#CommandLineTest.make_simple_tarfile~
  s    !!"6)79!! #>)79:
 		(((3\\(C(B w(8(8(AB ! )((s   %8B''B0c                    | j                  t        j                  |       t        j                  |d      5 }t        j
                  d      }|j                  |t        j                  d             t        j
                  d      }|j                  |t        j                  d             d d d        y # 1 sw Y   y xY w)Nr   benignr   r  ../evil)	rr  r	   rs  r(   r'   r  r  r%   r   )r   r  r  r  evils        r   make_evil_tarfilez!CommandLineTest.make_evil_tarfile
  s~    	(((3\\(C(B__X.FJJvrzz#J7??9-DJJtRZZ_J5	 )((s   A7B77C c                    | j                         \  }}}| j                  |d       | j                  d|j                                | j                  d|j                                | j                  d|j                                | j                  dd      \  }}}| j                  |d       | j	                  |j                         d       y )Nr   s   usages   errors   required-lr   )r  rV   r   lowerrV  strip)r   r  r   r  s       r   test_bad_usezCommandLineTest.test_bad_use
  s    ..0Cc"h		,h		,k399;/..tR8Cc"CIIK-r   c                 p    t         D ]-  }dD ]&  }| j                  ||      }| j                  |d       ( / y )N)-tz--testr   )testtarnamesr  rV   r   r  optr   s       r   test_test_commandz!CommandLineTest.test_test_command
  s6    $H%ooc84  c* & %r   c                 v    t         D ]0  }dD ])  }| j                  |d|d      }| j                  d|       + 2 y )N-vz	--verboser  r  PYTHONIOENCODINGs   is a tar archive.
)r  r  r   r  s       r   test_test_command_verbosez)CommandLineTest.test_test_command_verbose
  sB    $H(ooc47> & @4c: ) %r   c                    t        j                  d      }| j                  d|      \  }}}| j                  d|       | j	                  |d       | j	                  |d       t
        D ]  }| j                  |      5  t        |d      5 }|j                         }d d d        	 t        t        d      5 }|j                  d d	        d d d        | j                  dt              \  }}}| j	                  |d       | j	                  |d       t        j                  t               	 d d d         y # 1 sw Y   xY w# 1 sw Y   xxY w# t        j                  t               w xY w# 1 sw Y   xY w)
N
zipdir.zipr      is not a tar archive.r   ru   )r  rt   r   rz  )r   r#  r  r   rV   r  r  r'   rU   r   r  r	   rs  )r   zipnamer  r   r  r  rY  r   s           r   test_test_command_invalid_filez.CommandLineTest.test_test_command_invalid_file
  s-   ""<0..tW=C/5c"Q$Hx0(D)Q668D *.gt,Tc
+ -#'#:#:4#ILBS$$S#.$$R+$$W- 10 %)) -, $$W- 10sU   =E*
D4E*$E4E 	AEE*4D=9E* E	EE''E**E4	c                    t         D ]  }t        j                         5 }t        j                  |d      5 }|j                  d       d d d        d d d        j                         j                  dd      }dD ](  }| j                  ||d      }| j                  ||       *  y # 1 sw Y   axY w# 1 sw Y   exY w)Nra   Fr   r   r   )r  z--listr  
r  r   captured_stdoutr(   r'   rq   r   r   r  rV   r   r  r  r  rM  r  r   s          r   test_list_commandz!CommandLineTest.test_list_command
  s    $H((*a\\(C0BGGEG* 1 + zz|**74FGH%ooc87> & @  h/ & %00 +*s"   B4B(B4(B1-B44B=	c                    t         D ]  }t        j                         5 }t        j                  |d      5 }|j                  d       d d d        d d d        j                         j                  dd      }dD ])  }| j                  |d|d      }| j                  ||       +  y # 1 sw Y   bxY w# 1 sw Y   fxY w)	Nra   Tr   r   r   r  r  r  r  r  s          r   test_list_command_verbosez)CommandLineTest.test_list_command_verbose
  s    $H((*a\\(C0BGGDG) 1 + zz|**74FGH(ooc47> & @  h/ ) %00 +*s"   B5B)B5)B2.B55B>	c                     t        j                  d      }| j                  d|      \  }}}| j                  d|       | j	                  |d       | j	                  |d       y )Nr  r  r  r   ru   )r   r#  r  r   rV   r   r  r  r   r  s        r   test_list_command_invalid_filez.CommandLineTest.test_list_command_invalid_file
  sY    ""<0..tW=C/5c"Qr   c                    t        j                  dd      t        j                  dd      g}dD ]x  }	  | j                  |t        g| }| j	                  |d       t        j                  t              5 }|j                          d d d        t        j                  t               z y # 1 sw Y   %xY w# t        j                  t               w xY w)Nr  r  r  r  )-cz--creater   )
r   r#  r  r   rV   r(   r'   r   r	   rs  r   r  r  r   rI   s        r   test_create_commandz#CommandLineTest.test_create_command
  s    !!"6)79!! #>)79:
 $C*%dooc7;U;  c*\\'*cNN$ +   ) $ +*   )s$   AB98B-	B9-B6	2B99Cc                    t        j                  dd      t        j                  dd      g}dD ]|  }	  | j                  |dt        g|ddi}| j	                  d	|       t        j                  t              5 }|j                          d d d        t        j                  t               ~ y # 1 sw Y   %xY w# t        j                  t               w xY w)
Nr  r  r  r  r  r  r  r  s    file created.)
r   r#  r  r   r   r(   r'   r   r	   rs  r  s        r   test_create_command_verbosez+CommandLineTest.test_create_command_verbose
  s    !!"6)79!! #>)79:
 %C*%dooc4 @5 @7>@/5\\'*cNN$ +   ) %
 +*   )s$   AB=<B1B=1B:	6B==Cc                 t   t        j                  dd      g}	  | j                  dt        g| }| j	                  |d       t        j                  t              5 }|j                          d d d        t        j                  t               y # 1 sw Y   #xY w# t        j                  t               w xY w)Nr  r  r  r  r   )
r   r#  r  dotlessnamerV   r(   r'   r   r	   rs  )r   r  r   rI   s       r   $test_create_command_dotless_filenamez4CommandLineTest.test_create_command_dotless_filename
  s    !!"6~NO	*!$//$<e<CS#&k*c  + [) +* [)s$   AB B.B BB B7c                    t         j                  j                  t        d      }t	        j
                  dd      g}	  | j                  d|g| }| j                  |d       t        j                  |      5 }|j                          d d d        t        j                  |       y # 1 sw Y   xY w# t        j                  |       w xY w)Nz.testtarr  r  r  r  r   )rf   rg   rh   re   r   r#  r  rV   r(   r'   r   r	   rs  )r   r  r  r   rI   s        r   (test_create_command_dot_started_filenamez8CommandLineTest.test_create_command_dot_started_filename  s    77<<4!!"6~NO	'!$//$959CS#&h'3  ( X& (' X&s#   ;B4 9B(
B4 (B1-B4 4Cc                    t        j                  dd      t        j                  dd      g}t        t        t        fD ]y  }|j
                  s	 t        dz   |j                  z   } | j                  d|g| }|j                  |      5 }|j                          d d d        t        j                  |       { y # 1 sw Y   !xY w# t        j                         w xY w)Nr  r  r  r  r  r  )r   r#  r.   r5   r;   r'   r   r   r  r*   r   r	   rs  )r   r  filetyper  r   rI   s         r   test_create_command_compressedz.CommandLineTest.test_create_command_compressed  s    !!"6)79!! #>)79:
 "7H5H==+"S=8??:%doodH=u=%%h/3NN$ 0   * 6 0/   *s$   ;C	B=C	=C	C		C c                 X   | j                  t               dD ]f  }	 t        j                  t              5  | j                  |t              }d d d        | j                  d       t        j                  t               h y # 1 sw Y   7xY w# t        j                  t               w xY w)N)-ez	--extractr   r  r   r	   r   	tarextdirr  rV   r  r   r  r   s      r   test_extract_commandz$CommandLineTest.test_extract_command  sx      )$C,''	2//#w7C 3  c*  + %22   +s"   BBBB	BB)c                 ^   | j                  t               dD ]i  }	 t        j                  t              5  | j                  |dt        d      }d d d        | j                  d       t        j                  t               k y # 1 sw Y   7xY w# t        j                  t               w xY w)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//#tW;B * DC 3 4c:  + %22
   +s"   BBBB	
BB,c           	         | j                  t               t        j                  j	                  t
        d      }t        j                  t
               	 t        j                  |      5  | j                  dt        ddd       | j                  dt        dddd      }| j                  d	|       d d d        t        j                  t
               y # 1 sw Y   #xY w# t        j                  t
               w xY w)
Ndestr  r  z--filterr   rx  r  r  r  )r  r   rf   rg   rh   r  r   r	   r   r  r  r   r  )r   destdirr   s      r   test_extract_command_filterz+CommandLineTest.test_extract_command_filter3  s    w' '',,y&1
	(##G,''g(,(2F< oodG&*&0/7> & @ 4c: - Y' -, Y's%   C )AC0C CC C9c                 L   | j                  t               	 t        j                  t              5  | j                  dt        d      }d d d        | j                  d       t        j                  t               y # 1 sw Y   5xY w# t        j                  t               w xY w)Nr  spamdirr   r  )r   r   s     r   (test_extract_command_different_directoryz8CommandLineTest.test_extract_command_different_directoryF  sr      )	(##I.oodGY? /S#&Y'	 /. Y's"   B A<B <BB B#c                 "   t        j                  d      }t        j                  t              5  | j                  d|      \  }}}d d d        | j                  d       | j                  d       | j                  d       y # 1 sw Y   @xY w)Nr  r  r  r   ru   )r   r#  r	   r   r  r  r   rV   r  s        r   !test_extract_command_invalid_filez1CommandLineTest.test_extract_command_invalid_fileO  su    ""<0	*224ALBS +/5c"Q	 +*s   BB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  t
  sm    7
K	C6.+;.(	0	0 ** *	'+",	,(&( r   r  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ContextManagerTestc                     t        j                  t              5 }| j                  |j                  d       d d d        | j                  j                  d       y # 1 sw Y   &xY w)Nzclosed inside runtime contextcontext manager failed)r(   r'   r$   r   r,  r   r  s     r   
test_basiczContextManagerTest.test_basicZ  sF    \\'"cSZZ)HI #

$<= #"s   AA%c                     t        j                  t              }|j                          | j	                  t
              5  |5  	 d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr   )r(   r'   r$   rL   r  r  r  s     r   test_closedzContextManagerTest.test_closed_  sK     ll7#		w'  (' ('s#   A!AA!A	A!!A*c                 .   | j                  t              5 }t        j                  t              5 }t
        # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY w| j                  j                  t
        d       | j                  j                  d       y )Nz)wrong exception raised in context managerr  )
r  r  r(   r'   r$   r  r7  r  r   r,  )r   r
  rI   s      r   test_exceptionz!ContextManagerTest.test_exceptionh  sl    y)Sg&# '&& *)) 	cmmWI	K

$<=s   A7A 	AAc                    	 t        j                  t        d      5 }t        # 1 sw Y   nxY wn#  Y nxY w| j	                  t
        j                  j                  t              dd       | j                  j                  d       y )Nr   r   z-context manager wrote an end-of-archive blockr  )
r(   r'   r   r  rV   rf   rg   r  r   r,  r  s     r   test_no_eofzContextManagerTest.test_no_eofq  sh    	gs+s ,++	11?	A

$<=s   0 #,0 4c                     t        j                  t        d      5  	 d d d        | j                  t        j
                  j                  t              dd       y # 1 sw Y   >xY w)Nr   r   z-context manager wrote no end-of-archive block)r(   r'   r   rV  rf   rg   r  r   s    r   test_eofzContextManagerTest.test_eof}  sF     \\'3' (BGGOOG4a?	A ('s   AA#c                 $   t        t        d      5 }	 t        j                   |d      5 }t        # 1 sw Y   nxY wn#  Y nxY w| j	                  |j
                  d       | j                  j
                  d       d d d        y # 1 sw Y   y xY w)Nr   r   r5  zexternal file object was closedr  )r'   r   r(   r  r   r,  r   r:  s      r   r1  zContextManagerTest.test_fileobj  st     '4 D\\$S9S#O :99T[[*KLOOCJJ(@A !  s+   B>1:	>BA =BBN)	r!   r"   r#   r  r  r  r  r  r1  r,   r   r   r  r  X  s"    >
>
>A
Br   r  zrequires os.link to be missingc                   :   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y
)LinkEmulationTestc                 ,   | j                   j                  |t        d       t        t        j
                  j                  t        |      d      5 }|j                         }d d d        | j                  t              t               y # 1 sw Y   )xY w)Nrx  r_   rt   )rI   rd   re   r'   rf   rg   rh   rU   rV   r   rY   )r   r   rY  r   s       r   _test_link_extractionz'LinkEmulationTest._test_link_extraction  sc    w?"'',,w-t4668D 54.9 54s   B

Bislinkz3Skip emulation - has os.path.islink but not os.linkc                 &    | j                  d       y )Nr   r  r   s    r   test_hardlink_extraction1z+LinkEmulationTest.test_hardlink_extraction1       	""?3r   c                 &    | j                  d       y )Nr   r"  r   s    r   test_hardlink_extraction2z+LinkEmulationTest.test_hardlink_extraction2       	""#>?r   r  z Skip emulation if symlink existsc                 &    | j                  d       y )Nr   r"  r   s    r   test_symlink_extraction1z*LinkEmulationTest.test_symlink_extraction1  r$  r   c                 &    | j                  d       y )Nr   r"  r   s    r   test_symlink_extraction2z*LinkEmulationTest.test_symlink_extraction2  r'  r   N)r!   r"   r#   r  r   r  r   rf   rg   r#  r&  r)  r+  r,   r   r   r  r    s    : X__WRWWh/JL4L4 X__WRWWh/JL@L@ X__WR+79494 X__WR+79@9@r   r  c                       e Zd Zd Zd Zd Zy)Bz2PartialReadTestc                 T    G fddt         j                        t        j                  t	        j
                  d      j                               }t        t        |      dz         D ]#  }	 t	        j                   |d |       |       % y # t        j                  $ r Y <w xY w)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      | j                         t        | j	                               k(  | _         t
        |   |      S )Nz(infinite loop detected in tarfile.open())hit_eofAssertionErrorr{   rW   r   superrU   )r   r  	MyBytesIO	__class__s     r   rU   z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.read  sK    <<( *: ; ;#yy{c$--/.BBY2155r   c                 *    d| _         t        | 
  | S r  )r2  r4  rz   )r   r  r5  r6  s     r   rz   z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek  s    $Y2D99r   )r!   r"   r#   r2  rU   rz   __classcell__)r6  r5  s   @r   r5  r0    s    G6: :r   r5  r  ru   r5  )r%   r   r6   compressr(   r  r  rangerW   r'   r  )r   r    r   r  r5  s       @r   _test_partial_inputz&Bz2PartialReadTest._test_partial_input  s    
	:

 
	: ||GOOE288:;s4y1}%AYtBQx%8tD & $$ s   . BB'&B'c                 &    | j                  d       y Nra   r;  r   s    r   test_partial_inputz%Bz2PartialReadTest.test_partial_input  s      %r   c                 &    | j                  d       y )Nr  r>  r   s    r   test_partial_input_bz2z)Bz2PartialReadTest.test_partial_input_bz2  s      )r   N)r!   r"   r#   r;  r?  rA  r,   r   r   r-  r-    s    (&*r   r-  c                      	 dd l } dd l}| j                  d      d   dk7  ry|j	                  d      d   dk7  ryy# t        $ r Y yw xY w)Nr   FrootT)ru  rt  ImportErrorgetpwuidgetgrgid)ru  rt  s     r   root_is_uid_gid_0rG    sS     ||AqV#
||AqV#  s   ; 	AAchownzmissing os.chowngeteuidzmissing os.geteuidc                      e Zd Zed        Zeed               Zej                  j                  d      ej                  j                  d      ej                  j                  d      d                      Z
ej                  j                  d      ej                  j                  d      ej                  j                  d      d                      Z ej                   e       d      ej                  j                  d      ej                  j                  d      ej                  j                  d      d	                             Zej                  j                  d      d
        Zy)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 ]R  \  }}}}	}
t        j                  |      }||_        ||_	        d	|_
        d	|_        |	|_        |j                  ||
       T 	 d d d        t        S # 1 sw Y   t        S xY w)
Ns   contentc   b   M   L   X   W   r   rC  )r%   r   r(   rt  r_  r'   r   r  r   r   ri  r  r^  r  )
filename_1	dirname_1
filename_2r\   r  r"  r   r   r   typcontentsr  s               r   _make_test_archivez#NumericOwnerTest._make_test_archive  s     zz*% b"goot<b"goot<b"goot< \\'3'516-c3XOOD)  a* 27 (  ( s   .ACC#c              #      K   d| _         d}d}|}|}t        j                  j                  ||      }t        j                  |||      }t        j                  |      5 }||||f d d d        y # 1 sw Y   y xY ww)Nr   znumeric-owner-testfiler  )r  rf   rg   rh   rK  rX  r(   r'   )mock_geteuidr  r  rS  rT  rU  tar_filenamer"  s           r   _setup_testzNumericOwnerTest._setup_test   s      %&!( 
	WW\\'51
 (:::;D;EG \\,'5Y
:: (''s   AA<	A0'	A<0A95A<zos.chownr  z
os.geteuidc                    | j                  |      5 \  }}}}|j                  |t        dd       |j                  |t        dd       d d d        t        j                  j                  t              }t        j                  j                  t              }	|j                  t        j                  j                  |dd      t        j                  j                  |	dd      gd       y # 1 sw Y   xY w)	NTrx  numeric_ownerr`   rM  rN  rQ  rR  	any_order)
r\  rd   re   rf   rg   rh   assert_has_callsr   r  call)
r   rZ  r  
mock_chownr"  rS  _rU  f_filename_1f_filename_2s
             r   test_extract_with_numeric_ownerz0NumericOwnerTest.test_extract_with_numeric_owner  s    
 l+ 0<z10:MM*gT!0  2MM*wd!0  2	 , ww||GZ8ww||GZ8##X]]%7%7b"%M%-]]%7%7b"%M%' /3 	$ 	4 ,+s   8C..C7c           	      H   | j                  |      5 \  }}}}|j                  t        dd       d d d        t        j                  j                  t              }t        j                  j                  t              }	t        j                  j                  t              }
|j                  t        j                  j                  |dd      t        j                  j                  |	dd      t        j                  j                  |
dd	      gd
       y # 1 sw Y   xY w)NTrx  r^  rM  rN  rO  rP  rQ  rR  r`  )
r\  rw  re   rf   rg   rh   rb  r   r  rc  )r   rZ  r  rd  r"  rS  rT  rU  rf  f_dirname_1rg  s              r   "test_extractall_with_numeric_ownerz3NumericOwnerTest.test_extractall_with_numeric_owner+  s    
 l+ 0<z90:WD$3  5 , ww||GZ8ww||GY7ww||GZ8##X]]%7%7b"%M%-]]%7%7R%L%-]]%7%7b"%M%' /3	 	$ 	4 ,+s   DD!z uid=0,gid=0 must be named "root"c                     | j                  |      5 \  }}}}|j                  |t        dd       d d d        t        j                  j                  t              }|j                  |dd       y # 1 sw Y   AxY w)NFrx  r^  r   )r\  rd   re   rf   rg   rh   assert_called_with)r   rZ  r  rd  r"  rS  re  rf  s           r   "test_extract_without_numeric_ownerz3NumericOwnerTest.test_extract_without_numeric_ownerD  sm     l+/Hz1aMM*gU!0  2 ,
 ww||GZ8%%lAq9 ,+s   A11A:c           	          | j                  |      5 \  }}}}| j                  t        |j                  |t        dd       d d d        y # 1 sw Y   y xY w)NFT)r\  r  r  rd   re   )r   rZ  r"  rS  re  s        r   test_keyword_onlyz"NumericOwnerTest.test_keyword_onlyT  sG    l+/Hz1ai#mmZ%O ,++s   .A		AN)r!   r"   r#   r~  rX  r   r\  r   r  r  rh  rk  r   rG  rn  rp  r,   r   r   rK  rK    sh     . ;  ;( ]]$]]$]]&4 ' % %4$ ]]$]]$]]&4 ' % %4, X*,;=]]$]]$]]&	: ' % %=
	: ]]&O 'Or   rK  c                   *    e Zd Zd Zd Zd Zd Zd Zy)ReplaceTestsc                 8   | j                   j                  d      }|j                  d      }| j                  |j                  d       | j                  |j                  d       | j                  | j                   j                  d      j                  d       y )NrQ   z
misc/otherrq  )rI   rS   r   rV   r   r   rQ  replaceds      r   test_replace_namezReplaceTests.test_replace_name\  sv    ##O4>>|>45o6++O<AA(	*r   c                 &   | j                   j                  d      }|j                         }d|j                  d<   | j	                  |j                  d   d       | j	                  | j                   j                  d      j                  d   d       y )Nr  not-barr  r   rI   rS   r   r  rV   rt  s      r   test_replace_deepzReplaceTests.test_replace_deepd  s{    ##N3>>#(1W%++G4e<HH~.::7CU	Lr   c                 *   | j                   j                  d      }|j                  d      }d|j                  d<   | j	                  |j                  d   d       | j	                  | j                   j                  d      j                  d   d       y )Nr  F)deeprx  r  ry  rt  s      r   test_replace_shallowz!ReplaceTests.test_replace_shallowl  s    ##N3>>u>-(1W%++G4i@HH~.::7CY	Pr   c                 .   | j                   j                  d      }dD ]i  }| j                  |      5   |j                  di |d i}| j	                  t        ||      d        | j                  t        ||      d        d d d        k y # 1 sw Y   vxY w)NrQ   )r   rg  r    r$  r   r   ri  r  	attr_namer,   )rI   rS   r  r   rV   r=  rV  )r   rQ  r  ru  s       r   test_replace_allzReplaceTests.test_replace_allt  s    ##O4:I	2)6>>>Y,=>  9!=tD##GFI$>E 32:22s   ABB	c                     | j                   j                  d      }| j                  t              5  |j	                  d       d d d        y # 1 sw Y   y xY w)NrQ   i[)rX  )rI   rS   r  r  r   )r   rQ  s     r   test_replace_internalz"ReplaceTests.test_replace_internal}  s>    ##O4y)NN)N, *))s   AAN)r!   r"   r#   rv  rz  r}  r  r  r,   r   r   rr  rr  [  s    *LPF-r   rr  c                   p    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y)NoneInfoExtractTestsNc                 0    t        j                  t        dd      }t        j                  t
              dz   _        d|_        t               5 } j                  *|j                  t        j                  dt                     |j                   j                   j                         d d d        |j                          t!         fd	t        j                   j                        j#                  d
      D               _        y # 1 sw Y   _xY w)Nra   rE   rF   extractall_ctrlr   ignore)actioncategoryr_   c              3   T   K   | ]  }|j                  j                         ! y wr   )relative_tocontrol_dir).0pr  s     r   	<genexpr>z2NoneInfoExtractTests.setUpClass.<locals>.<genexpr>  s'       A? MM#//*?s   %(**/*)r(   r'   r$   r  r  re   r  rq  r   extraction_filterenter_contextwarningscatch_warningsr  rw  rL   setglobcontrol_paths)r  rI   r  s   `  r   r  zNoneInfoExtractTests.setUpClass  s    ll7{C!,,w/2CC[B$$,  !8!8#.@"B CNN3??33H3HNI	 
 			  A\\#//277? A A [s   ADDc                 B    t        j                  | j                         y r   )shutilr  r  r  s    r   r  z"NoneInfoExtractTests.tearDownClass  s    coo&r   c                    t        fdt        j                        j                  d      D              }| j                  dk(  r+dD ]&  }|j                  t        j                  |             ( | j                  | j                  |       y )Nc              3   @   K   | ]  }|j                          y wr   )r  )r  r  r  s     r   r  z;NoneInfoExtractTests.check_files_present.<locals>.<genexpr>  s"      ;9 MM)$9s   r  r   )r4  r)  r1  )r  r  r  r  r  discardrV   r  )r   r  	got_pathsrg   s    `  r   check_files_presentz(NoneInfoExtractTests.check_files_present  sv     ;\\),11&9; ;	 !!V+J!!',,t"45 K++Y7r   c              '     K   t        j                  t              dz  }d| j                  _        | j                  j                         D ]  }|D ]  }t        ||d          t        j                  |      5  | j                  j                  |d       | j                  |       | d d d        y # 1 sw Y   y xY ww)Nextractall_noner   rx  r_   )r  r  re   rI   rq  r   setattrr	   r  rw  r  )r   
attr_namesr  rQ  r  s        r   extract_with_nonez&NoneInfoExtractTests.extract_with_none  s     ll7#&77hh))+F'		40 ( , $HHO<$$S)I %$$s   A6C 83B4+	C 4B=9C c                    t        j                  t              j                         j                  }| j                  d      5 }t        j                  |      j                  d      D ]b  }| j                  |      5  	 |j                         j                  }| j                  |j                         j                  |       d d d        d 	 d d d        y # t        $ r |j                         s Y 0w xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nrg  r  r  )r  r  re   r  st_mtimer  r  r  assertGreaterEqualr  
is_symlink)r   nowr  rg   rg  s        r   test_extractall_none_mtimez/NoneInfoExtractTests.test_extractall_none_mtime  s     ll7#((*33##G,S)..v6\\t\,K $		 4 4 //		0D0DcJ -, 7 -,
 # "#0!  1" -, -,sH   :D=C7?C*C7
DC4	1C73C4	4C77D <DDc                    t        j                  t              j                         j                  }t        j                  t              dz  }|j                  d       |j                         j                  }| j                  d      5 }t        j                  |      j                  d      D ]  }| j                  |      5  |j                         r+| j                  |j                         j                  |       n:|j                         r*| j                  |j                         j                  |       d d d         	 d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nregular_filer   r    r  r  )r  r  re   r  r  
write_textr  r  r  is_dirrV   is_file)r   dir_moder  regular_file_moder  rg   s         r   test_extractall_none_modez.NoneInfoExtractTests.test_extractall_none_mode  s     <<(--/77||G,~=#(--/77##F+sS)..v6\\t\,{{}(()<)<hG(()<)<):<	 -, 7 ,+,, ,+s%   
:EA6E:
EEEE#c                 R    | j                  d      5  	 d d d        y # 1 sw Y   y xY w)Nr   r  r   s    r   test_extractall_none_uidz-NoneInfoExtractTests.test_extractall_none_uid      ##E* +**   &c                 R    | j                  d      5  	 d d d        y # 1 sw Y   y xY w)Nr   r  r   s    r   test_extractall_none_gidz-NoneInfoExtractTests.test_extractall_none_gid  r  r  c                 R    | j                  d      5  	 d d d        y # 1 sw Y   y xY w)Nri  r  r   s    r   test_extractall_none_unamez/NoneInfoExtractTests.test_extractall_none_uname      ##G, -,,r  c                 R    | j                  d      5  	 d d d        y # 1 sw Y   y xY w)Nr  r  r   s    r   test_extractall_none_gnamez/NoneInfoExtractTests.test_extractall_none_gname  r  r  c                 X    | j                  dddd      5  	 d d d        y # 1 sw Y   y xY w)Nr   r   ri  r  r  r   s    r   test_extractall_none_ownershipz3NoneInfoExtractTests.test_extractall_none_ownership  s&    ##E5'7C DCCs    ))r!   r"   r#   r  r  r  r  r  r   r  r  r  r  r  r  r  r  r,   r   r   r  r    so     A A ' '8 	 	K < r   r  c                       e Zd ZdZy)NoneInfoExtractTests_Datar   Nr!   r"   r#   r  r,   r   r   r  r    s    r   r  c                       e Zd ZdZy)!NoneInfoExtractTests_FullyTrustedrx  Nr  r,   r   r   r  r    s    'r   r  c                       e Zd ZdZy)NoneInfoExtractTests_TarrI   Nr  r,   r   r   r  r    s    r   r  c                       e Zd ZdZy)NoneInfoExtractTests_DefaultNr  r,   r   r   r  r    s    r   r  c                       e Zd Zd Zd Zy)NoneInfoTests_Miscc           
         t        j                         }t        j                  t        j                  t        j
                  fD ]  }| j                  |      5  t        j                  |d|      }|j                  t              }	 |j                  |       dD ]b  }| j                  |      5   |j                  di |d i}| j                  t        |       5  |j                  |       d d d        d d d        d 	 d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# t        $ r |t        j                  k(  rn Y Cw xY w# 1 sw Y   xY w)N)	tarformatr   )r6  r    r   )rg  r    r   r   ri  r  r  r,   )r%   r   r(   r   r}  r  r  r'   r  r$   r  r   r  rT  r  )r   bior  rI   r[   r  ru  s          r   test_addzNoneInfoTests_Misc.test_add  s&   jjl!..0B0B!,,.I	2ll3SK..16KK(&6	!\\I\>'6w'K)T9J'KH!%!7!7
;D+"H #H 5"H ?>&6 32.&"H "H ?> !  G$8$88  	 32s`   .ED$E0,D	D.D	6EDD	D!E$EEEEE	c           
      	   dhdhdhdhdhdhddhddhfD ]  }| j                  |      5  t        j                  t        d	      5 }t	        j
                  t	        j                         d
d      }t        j                  t        d|      5  |j                          d d d        |j                         D ]  }|D ]  }t        ||d          t	        j
                  t	        j                         d
d      }t        j                  t        d|      5  |j                          d d d        t        |j                         j                         j!                         |j                         j                         j!                               D ]  \  }}|dhk(  r)t#        j$                  d|      r| j'                  |d       6|dhk(  r)t#        j$                  d|      r| j'                  |d       e|dhk(  r)t#        j$                  d|      r| j'                  |d       |dhk(  r^|j)                  d      rM|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||
       | j+                  |d       |dhk(  r_|j-                  d      rN|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||	       | j+                  |d       ]|dhk(  r_|j)                  d      rN|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||
       | j'                  |d       |dhk(  r_|j-                  d      rN|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||	       | j'                  |d       '|ddhk(  r_|j)                  d      rN|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||
       | j'                  |d       |ddhk(  r_|j-                  d      rN|j!                  d      \  }	}
|j!                  d      \  }}| j'                  ||	       | j'                  |d       | j'                  ||        	 d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   /xY w# 1 sw Y   xY w)Nrg  r    r   r   ri  r  )r  rE   rv  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%   rj   r   r   r   r   rq   r   r  r  r   r   r  rematchrV   rh  r   endswith)r   r  rI   tio_prevrQ  r  tio_newrM  gotexp_user	exp_groupgot_user	got_groups                r   r   zNoneInfoTests_Misc.test_list  sB   
 $9vh%#9wi!7+eW-=?J ,,*,5,,w=++BJJL'4P&&sHh?HHJ @!nn.F%/		48 &0 / **2::<$O&&sHg>HHJ ?%():)C)C)E)K)K)M)0)9)B)B)D)J)J)L&NMHc!gY.288<Lh3W((m<#y0RXX>PRZ5[((k:#x/BHH2H5>((m<#y0X5H5H<6>.6nnT.B+).1iio+)((I>((9=#y0X5F5F=6?.6nnT.B+).1iio+)((8<((I>#w.83F3F%4(.6nnT.B+).1iio+)((I>((7;#w.83D3Dg3O.6nnT.B+).1iio+)((8<((G<#w'77H<O<OF=H.6nnT.B+).1iio+)((I>((7;#'77H<M<MF=H.6nnT.B+).1iio+)((8<((G< ((37]&N > 65? @? ?> >= 65sV   SASR*	A6SR7	%M0SS*R4/S7S<SS	SS	N)r!   r"   r#   r  r   r,   r   r   r  r    s    64A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  }t        j                  |      dd | dd k(  sJ |S )zInverse of `stat.filemode` (for permission bits)

    Using mode strings rather than numbers makes the later tests more readable.
    ru   Nr   )ra   -)r   r  )r  r  r~   Srx   r*     r.  rp     )r  r  r  TrY  )r  S_IRUSRS_IWUSRS_IXUSRS_ISUIDS_IRGRPS_IWGRPS_IXGRPS_ISGIDS_IROTHS_IWOTHS_IXOTHS_ISVTXr~  )r    str_moderesults      r   _filemode_to_intr  U  s   
 ABxH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++ $ == $QR000Mr   c                   >    e Zd ZdZd Zd Zd ZddddddddZd Zy)	r  zHelper to create a tar file with specific contents

    Usage:

        with ArchiveMaker() as t:
            t.add('filename', ...)

        with t.open() as tar:
            ... # `tar` is now a TarFile with 'filename' in it!
    c                 6    t        j                         | _        y r   )r%   r   r  r   s    r   r  zArchiveMaker.__init__|  s    ::<r   c                 R    t        j                  d| j                        | _        | S )Nr   rW  )r(   r)   r  tar_wr   s    r   	__enter__zArchiveMaker.__enter__  s    __#txx@
r   c                     | j                   j                          | j                  j                         | _        d | _        y r   )r  rL   r  r   rW  )r   r
  s     r   __exit__zArchiveMaker.__exit__  s-    

))+r   N)r^  r  hardlink_tor    rX   contentc                   t        |      } t        j                  |      j                  di |}	|+t	        |t               r|j                         }t        |      }|||	_        |t        |	j                        }|rt        |      |	_
        | t        j                  }t        |      |	_        | t        j                  }t        |      |	_        |j                  d      r|t        j                  }|||	_        |	j#                         rt%        j&                  |      }
nd}
| j(                  j+                  |	|
       y)a  Add a member to the test archive. Call within `with`.

        Provides many shortcuts:
        - default `type` is based on symlink_to, hardlink_to, and trailing `/`
          in name (which is stripped)
        - size & content defaults are based on each other
        - content can be str or bytes
        - mode should be textual ('-rwxrwxrwx')

        (add more! this is unstable internal test-only API)
        Nr   r,   )r8  r(   r  r   r|  r   rW   rX   rJ  r  r    rx  r$  rP  r  r_  r^  r  r%   r   r  r  )r   r   r^  r  r   r    rX   r  r  r[   r6  s              r   r   zArchiveMaker.add  s    4y/'//$'//9&9'3'!..*w<DGL-+D1GL!??D":G"??D";/G==$,??DGL==?jj)GG

7G,r   c                 n    t        j                  | j                        }t        j                  dd|i|S )z9Open the resulting archive as TarFile. Call after `with`.r6  r,   )r%   r   rW  r(   r'   )r   r  r  s      r   r'   zArchiveMaker.open  s+    jj'||2C2622r   )	r!   r"   r#   r  r  r  r  r   r'   r,   r   r   r  r  q  s1    	 
 !%4D$'-R3r   r  c                 8     t        j                  d      |       S )NzWASI: Skip symlink test for now)r   skiprY  s    r   symlink_testr    s    ?x}}>?BBr   c                     | S r   r,   r  s    r   r  r    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-y)*TestExtractionFiltersouterdirr  T)
check_flagc             #   d  K   t        j                  | j                        5  | j                  dz  }|j                  d       	 |j	                  | j
                  |       d| _        d| _        t        | j                  j                  d            | _
        | j                  j                  | j
                         | j                  j                  |       	 |  |j                          | j                  r| j                  | j                  | j                  t                      |r!| j                  |j                         d       n|dk(  sJ ddd       y# t        $ r'}|| _        d| _        t               | _
        Y d}~d}~ww xY w# |j                          w xY w# 1 sw Y   yxY ww)	a*  Extracts `tar` to `self.destdir` and allows checking the result

        If an error occurs, it must be checked using `expect_exception`

        Otherwise, all resulting files must be checked using `expect_file`,
        except the destination directory itself and parent directories of
        other files.
        When checking directories, do so before their contents.

        A file called 'flag' is made in outerdir (i.e. outside destdir)
        before extraction; it should not be altered nor should its contents
        be read/copied.
        flagz
capture mer_   NFr  Trx  )r	   r  r  r  rw  r  raised_exceptionreraise_exceptionr  r  expected_pathsr  r  rL   rV   r  )r   rI   r`   r  	flag_pathr
  s         r   check_contextz#TestExtractionFilters.check_context  s^     ..I  .7t||F; )-%).&&)$--*<*<V*D&E###++DLL9##++I6
		%%+++T00#%8  !4!4!6E0003 /.
  ,(+%)-&&)e##, 		% /.s`    F0!F$E!A7F$FA6F$	F0	F%FF$FF$F!!F$$F-)F0Nc                 *   | j                   r| j                   t        j                  t        j                  j                  | j                  |z              }| j                  || j                         | j                  j                  |       |yt        j                         ret        j                  dk7  rRt        j                  t        j                  |j                         j                               }| j#                  ||       |1t%        |t&              r!|j)                  d      rt*        j,                  }|Y| j                  |z  j/                         }t        j                  |      }		 |	|k7  r | j1                  |j3                  |	             n|t*        j8                  k(  s| | j1                  |j;                                n|t*        j,                  k(  r | j1                  |j=                                nq|t*        j>                  k(  r | j1                  |jA                                n>|t*        jB                  k(  r | j1                  |jE                                ntG        |      |*| j#                  |j                         jH                  |       | | j#                  |jK                         |       |jL                  D ]  }| j                  jO                  |        y# t4        $ r}
|
j7                  d|	d|        d}
~
ww xY w)z'Check a single file. See check_context.Nntr   z	expected=z, got=)(r  r  r  rf   rg   normpathr  r   r  remover	   	can_chmodr   r  r~  S_IMODEr  rV   r|  r8  r  r(   r_  readlinkr   samefiler  add_notert  r  r  r}  is_fiforx  r  NotImplementedErrorrn  r  parentsr  )r   r   r^  r  r    rX   r  rg   r  rM  r  parents               r   expect_filez!TestExtractionFilters.expect_file  s?      '''||BGG,,T\\D-@ABdD//0""4(	 3 3 5"''T/--TYY[-@-@ ABCS$'<JtS1dmmC6H??D!<<$&002C||J/Hs?OOCLL$:;
 W__$OODLLN+W__$OODKKM*W%%%OODLLN+W__$OODOO-.%d++TYY[00$7T^^-w7llF''/ #%  

ih[3&12s   2%K, ,	L5LLc                     | j                   |z  j                         }| j                  |t        j                         | j
                  D ch c]  }||j                  vr| c}| _        yc c}w )z-Check a directory; forget about its contents.r^  N)r  resolver!  r(   r_  r  r  )r   r   	tree_pathr  s       r   expect_any_treez%TestExtractionFilters.expect_any_tree#  sg    \\D(113	9**
*!		) *
 
s   A-c                     | j                  ||      5  | j                  | j                  	 d d d        d| _        | j                  S # 1 sw Y   xY wr  )r  r  r  )r   exc_type
message_res      r   expect_exceptionz&TestExtractionFilters.expect_exception,  sS    ##Hj9$$0+++ 1 : "'$$$	 :9s   AAc                     t               5 }|j                  d       d d d        dD ]<  }| j                  j                         |      5  | j	                  d       d d d        > y # 1 sw Y   KxY w# 1 sw Y   UxY w)Nz
benign.txt)rx  rI   r   r  r   r  r'   r!  r   r  r`   s      r   test_benign_filez&TestExtractionFilters.test_benign_file3  sa    ^sGGL! 4F##CHHJ7  . 87 5 ^ 87s   A'
A3'A03A<	c                 |   t               5 }|j                  | j                  dz         d d d        | j                  j	                         d      5  | j                  d       d d d        dD ]  }| j                  |j	                         |      5  t        | j                        j                  d      r9t        | j                        j                  d      }| j                  | d       n | j                  t        j                  d       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w)Nzescaped.evilrx  z../escaped.evilrI   r   r   z/escaped.evilz+['"].*escaped.evil['"] has an absolute path)r  r   r  r  r'   r!  r8  rh  lstripr*  r(   AbsolutePathError)r   r  r`   outerdir_strippeds       r   test_absolutez#TestExtractionFilters.test_absolute:  s     ^sGGDMMN23  
O<./ = $F##CHHJ7t}}%005 ),DMM(:(A(A#(F%$$(9':-%HI ))11IK 87 $ ^ =< 87s$   DD&A>D2D#&D/2D;	c                 
   t               5 }|j                  dd       |j                  dd       |j                  d       d d d        t        j                         r| j	                  j                         d      5  | j                  | j                  t               	 d d d        y | j                  dd       | j                  dd       | j                  d       	 d d d        | j	                  |j                         d	      5  | j                  t        j                  d
       d d d        | j	                  |j                         d      5  | j                  t        j                  d       d d d        y | j	                  j                         d      5  | j                  d       d d d        | j	                  |j                         d	      5  | j                  d       d d d        | j	                  |j                         d      5  | j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   YxY w# 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Ncurrentr  r  r   z
current/..parent/evilrx  r  rI   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*  r  r!  r(   OutsideDestinationErrorLinkOutsideDestinationErrorr   r  s     r   test_parent_symlinkz)TestExtractionFilters.test_parent_symlinkS  s    ^s
 GGI#G. GGHG6GGM"    "##CHHJ@((4 ))/:  A@ $$Y3$?$$X,$G$$Y/ A ##CHHJ6%%339: 7 ##CHHJ7%%779: 87 ##CHHJ@  / A##CHHJ6  / 7##CHHJ7  / 87Y ^ A@ 76 87 A@6677sY   8H. #H;,7H;!I!II!I-I9.H8;III!I*-I69Jc                    t               5 }d}t        j                  dk(  rd}ndt        j                  v rgt        j
                  | j                  j                  d      }d}t        t        | j                              |z   }||z
  t        |      |z   z  }d|z  }nt        d      d}d}	|D ]  }
|j                  t        j                  j                  ||      t        j                   d	
       |j                  t        j                  j                  ||
      |       t        j                  j                  ||      }t        j                  j                  |	|
      }	 t        j                  j                  g |d }dgt        |      z  }|j                  |t        j                  j                  |        |j                  dt        j                  j                  |d             |j                  dt        j                  j                  dd             |j                  dd       |j                  dd       d d d        | j#                  d      5  | j%                  j'                         dd      5  t        j                  dk(  r| j)                  t*        t,        f       n| j.                  r| j)                  t0               nk| j3                         | j5                  dd       | j5                  dd       | j5                  dt        j6                         | j5                  d|       d d d        d d d        dD ]  }| j#                  |      5  | j%                  j'                         |      5  | j)                  t8        t0        f      }t;        |t8              rZt        j                  dk(  r| j=                  |j>                  d       n*| jA                  |jB                  tB        jD                         d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   9xY w# 1 sw Y   
xY w)Nabcdefghijklmnopry  dddddddddddddddddddddddddPC_PATH_MAXru   dz1Need to guess component length for {sys.platform}r   
drwxrwxrwxr  r  llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllr  escapeflaglinkr  r   	overwrite)r  zescape/newfilenewrx  F)r`   r  z
../newfiler#  r   r0  r_   )r*  r.     )#r  r   r  rf   pathconf_namespathconfr  r   rW   r8  r  r  r   rg   rh   r(   r_  r  r  r'   r*  r	  r  r  rc  r&  r!  rx  r  r|  r   winerrorrV   errnoENAMETOOLONG)r   r  steps	componentmax_path_lenpath_sep_lendest_lencomponent_lenrg   	step_pathilinkpathparent_segmentsr`   r
  s                  r   test_realpath_limit_attackz0TestExtractionFilters.test_realpath_limit_attack  s`   
 ^s
 'E||w&$	""3"33!{{4==+?+?O s4<<01L@!-!8c%j<>W X-/	)*]^^DIT95GOO)  +T1-)Dww||D)4GGLLA6	  ww||4U4G4H#fs5z1OGGH)GGHGGHh)EGF GGJBGGLL6,JGKGGJG4GG$eG4O R ll?+  O,1 ! 3||w&%%'8/&JK&&%%h/ $$Y/  [ A  u =   @   ;3 ,  $Ff%t'9'9#((*V'9'T++Wh,?@c7+||w. cllK@((E4F4FG (U%% $s ^T3 3 ,+" (U'T%%sV   H>P#"#P<B=P0P<("Q
BQQ#P-0P9	5P<<QQQQ	c                    t        j                         r/t        j                  j	                  t
        d      }t        j                  |       t        j                  dt        j                  j	                  |d             t        t        j                  j	                  |ddd      d      5  	 d d d        t        j                  j                  t        j                  j	                  |d            rd}nLt        j                  j                  t        j                  j	                  |dd            rd}nt        d	      t               5 }|j                  dd
       |j                  dd
       |j                  d       d d d        | j                  j                         d      5  t        j                         r8| j                  dd
       | j                  dd
       | j                  d       n"| j                  d       | j                  d       d d d        | j                  |j                         d      5  t        j                         r!| j                  t         j"                  d       n"| j                  d       | j                  d       d d d        | j                  |j                         d      5  t        j                         rDr!| j                  t         j"                  d       nC| j                  t         j$                  d       n"| j                  d       | j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   HxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nresolution_testr  r6  r  r-  r   TFz#Could not determine link resolutionr  zcurrent/parentr7  rx  r   r  zcurrent/rI   r8  r   zS'current/parent' would link to ['"].*outerdir['"], which is outside the destination)r	   r  rf   rg   rh   re   r   r  r'   r  r3  r  r   r  r!  r*  r(   r9  r:  )r   testpathdotdot_resolves_earlyr  s       r   test_parent_symlink2z*TestExtractionFilters.test_parent_symlink2  s      "ww||G->?HHHX JJsBGGLL9=> bggll8YfEsK L ww~~bggll8V<= )-%XtV DE ).%$%JKK^s GGI#G. GG$G6GGM"  
O<$$&  s ;  d ;  +  ,  / = 
E2$$&%%77,-   ,  / 3 
F3$$&())#;;01 ))#??01   ,  /% 43_ LK ^ =< 32 43s?   /M
8M/A/M$AM1A;M=
MM!$M.1M:=Nc                 R   t               5 }|j                  d| j                         |j                  d       d d d        | j                  j	                         d      5  t        j                         r/| j                  d| j                         | j                  d       n| j                  d       d d d        | j                  |j	                         d      5  t        j                         r!| j                  t        j                  d       n| j                  d       d d d        | j                  |j	                         d      5  | j                  t        j                  d	       d d d        y # 1 sw Y   @xY w# 1 sw Y   xY w# 1 sw Y   lxY w# 1 sw Y   y xY w)
Nr   r  r7  rx  r  rI   r8  r   &'parent' is a link to an absolute path)r  r   r  r  r'   r	   r  r!  r*  r(   r9  AbsoluteLinkErrorr;  s     r   test_absolute_symlinkz+TestExtractionFilters.test_absolute_symlink'  s>    ^sGGHG7GGM"  
O<$$&  dmm D  +  / = 
E2$$&%%77,-   / 3 
F3!!))8: 43+ ^ =< 32 43s1   /E8"AFAF!F8FFFF&c                 X   t               5 }|j                  d| j                  dz         d d d        | j                  j	                         d      5  | j                  t        d       d d d        | j                  |j	                         d      5  | j                  t        d       d d d        | j                  |j	                         d      5  | j                  t        j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   kxY w# 1 sw Y   y xY w)	Nr   r  rF  rx  z.*foo. not foundrI   r   r`  )	r  r   r  r  r'   r*  rc  r(   ra  r;  s     r   test_absolute_hardlinkz,TestExtractionFilters.test_absolute_hardlinkE  s     ^sGGH$--%*?G@  
O<!!(,>? = 
E2!!(,>? 3 
F3!!))8: 43 ^ =< 32 43s/   !C<DD!D <DDD D)c                 ^   t               5 }|j                  dd       d d d        	 | j                  j                         d      5  t	        j
                         rDt        | j                  t              r| j                  t               n| j                  dd       n	 d d d        dD ]K  }| j                  j                         |      5  | j                  t        j                  d       d d d        M y # 1 sw Y   xY w# 1 sw Y   fxY w# t        $ r Y tw xY w# 1 sw Y   xY w)N../mooz..//tmp/moor  rx  r_   r0  zH'../moo' would be extracted to '.*moo', which is outside the destination)r  r   r  r'   r	   r  r|  r  r  r*  r!  r(   r9  r-  s      r   test_sly_relative0z(TestExtractionFilters.test_sly_relative0V  s     ^sGGHG7 	##CHHJ#G((*!$"7"7I --o>((m(L  H& $F##CHHJ7%%77,- 87 $1 ^
 HG   		 87sA   C<!D 	AD#D !D#<DDD 	D D #D,	c                 <   t               5 }|j                  d       |j                  dd       d d d        | j                  j                         d      5  | j	                  dt
        j                         t        j                         r| j	                  dd	       d d d        d
D ]K  }| j                  |j                         |      5  | j                  t
        j                  d       d d d        M y # 1 sw Y   xY w# 1 sw Y   fxY w# 1 sw Y   pxY w)Nztmp/ztmp/../../mooztmp/../..//tmp/moor  rx  tmpr#  rf  ztmp/../../tmp/moor0  zU'tmp/../../moo' would be extracted to ['"].*moo['"], which is outside the destination)r  r   r  r'   r!  r(   r_  r	   r  r*  r9  r-  s      r   test_sly_relative2z(TestExtractionFilters.test_sly_relative2y  s     ^sGGFOGGO0DGE  
O<U9$$&  6I J =
 $F##CHHJ7%%33$% 87 $ ^ =< 87s$   %C:A	D!D:DDD	c           	      j   t               5 }|j                  dd       |j                  dt        j                  j	                  dd             |j                  dt        j                  j	                  d	dd      
       d d d        dD ]  }| j                  j                         |      5  | j                  dd       | j                  dd       t        j                         r| j                  ddd       n| j                  dd       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Ntargetdir/targetr*  r  linkdir/hardlink	targetdirr  rF  linkdir/symlinkr  r  rI   r   rx  z../targetdir/targetrX   r  
r  r   rf   rg   rh   r  r'   r!  r	   r  r-  s      r   test_deep_symlinkz'TestExtractionFilters.test_deep_symlink  s   
 ^sGG&QG/GG&BGGLLX5'G ( GG%"'',,k83-G .  5F##CHHJ7  !3! <  !3! <((*$$%6Q0E % G $$%6Q$? 87 5 ^ 87s   A7D/A#D)D&)D2	c                 d   t               5 }|j                  dd       |j                  dt        j                  j	                  dd             |j                  dd	       |j                  d
t        j                  j	                  dd             |j                  dt        j                  j	                  dd             d d d        dD ]  }| j                  j                         |      5  | j                  dd	       | j                  d
d	       | j                  dd	       t        j                         r)| j                  ddd       | j                  ddd       n&| j                  dd	       | j                  dd	       d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nro  hardlinkr  symlink2linkdir	hardlink2rl  r*  r  rm  rn  r  rF  zlinkdir/hardlink2r  rp  rq  rr  r-  s      r   test_chainsz!TestExtractionFilters.test_chains  sx    ^sGG%*G=GGJ277<<;,(G )GG&QG/GG&BGGLLh4WGXGG'RWW\\)Y5WGX  5F##CHHJ7  !3! <  !3! <  !41 =((*$$%6Q0: % <$$Za0C % E $$%6Q$?$$Za$8 87 5 ^ 87s   B:F2BF&F#&F/	c           	         t               5 }|j                  d       |j                  d       |j                  dt        j                  j	                  dd             |j                  dt        j                  j	                  ddd	             |j                  dd
       |j                  dt        j                  j	                  dd             d d d        | j                  j                         d      5  t        j                         s | j                  t        j                         n}t        j                  dk(  r | j                  t        j                         nJ| j                  t        j                  d      }| j                  |j                   t        j                         d d d        dD ]  }| j#                  |      5  | j                  |j                         |      5  t        j                         s4| j%                  d       | j%                  d       | j%                  d       n[| j%                  d       | j%                  d       | j%                  dd       | j%                  dd       | j%                  dd
       d d d        d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   .xY w# 1 sw Y   xY w)Nz	a/t/dummyzb/cr   r  r  zc/escaper  	link_herer   boomrD  rF  r   ry  zJlink 'boom' would be extracted as a copy of 'c/escape', which was rejected)rI   rx  zc/z
a/t/escapez../../link_here)r  r   rf   rg   rh   r  r'   r	   r  r*  r(   r:  r   r  r  r7  	__cause__r  r!  )r   r  r  r`   s       r   test_sneaky_hardlink_fallbackz3TestExtractionFilters.test_sneaky_hardlink_fallback  s,   
 ^s GGK GGDMGGCBGGLLc$:G;GGJ277<<d8C,EG F GGCCG( GGFS((CGD " 
F3((* %%779(%%g&I&IJ))--78 %%akk&-&I&IK 4" -Ff%t'9'9#((*f'M ,,.$$[1$$T*$$T*$$[1$$T*$$\>O$P$$V8I$J$$SS$9 (N%% -E ^" 43$ (N'M%%s>   C
J%=B2J2!K.B$J?K%J/2J<?KKK	c                    t               5 }|j                  dt        j                  j	                  ddddd             |j                  dd       d d d        dD ]  }| j                  j                         |      5  t        j                         r@| j                  dd       |dk(  r| j                  dd       n| j                  dd	       n	 d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)
NrD  rn  r  z	link-herer  r  rp  r   zlink/link/../../link-here)
r  r   rf   rg   rh   r  r'   r	   r  r!  r-  s      r   test_exfiltration_via_symlinkz3TestExtractionFilters.test_exfiltration_via_symlink  s     ^sGGHffdDR])^G_GGFtG,  5F##CHHJ7((*$$V$='((k(J((4O ) Q  87 5	 ^
 87s   AC! AC-!C*-C6	c                    t               5 }|j                  dd       |j                  dd       |j                  dd       |j                  dd	       d d d        d
D ]  }| j                  j                         |      5 }t	        j
                         s| j                  d       nR|dk(  r'| j                  dd	       | j                  dd       n&| j                  dd	       | j                  dd       t        j                  dk7  r9|j                  j                         j                  }| j                  |dz  d       d d d         y # 1 sw Y   xY w# 1 sw Y   	xY w)Nza/pwnr  r  za/pwn/rB  r   zx/../za/xz../rp  r   ry  rz  )r  r   r  r'   r	   r  r!  r   r  r  r  r  rV  )r   r  r`   ccr  s        r   test_chmod_outside_dirz,TestExtractionFilters.test_chmod_outside_dir
  s7   
 ^sGGGG, GGH<G0GGGG0 GGEuG.  5F##CHHJ72 ,,.$$X.v%$$Uu$=$$W$=$$Uu$=$$W$A<<7* kk..088G''%? 87 5 ^ 87s   AECE!E!E+	c                    t               5 }|j                  d       |j                  d       |j                  dd       |j                  dd       d d d        dD ]o  }| j                  j                         |      5 }| j	                  d       | j	                  d       | j	                  d       | j	                  d       d d d        q y # 1 sw Y   ~xY w# 1 sw Y   xY w)	Ndir/zdir/../afilelink1rF  link2zdir/../dir/../afilerp  afiler,  )r   r  r`   r  s       r   test_link_fallback_normalizesz3TestExtractionFilters.test_link_fallback_normalizes*  s     ^sGGFOGGN#GGGG8GGG)>G?	  5F##CHHJ72  (  )  )  )	 87 5 ^ 87s   A	CACCC&	c                 	   t               5 }|j                  dd       |j                  dd       |j                  dd       |j                  dd	       |j                  d
d       |j                  dd       d d d        t        j                  j	                  t
        d      }t        |d      5  	 d d d        	 	 t        j                  |t        j                  |      j                  t        j                  z         t        j                  |      j                  t        j                  z  }t        j                  |       t        j                   |       t        j                  |t        j                  |      j                  t        j                  z         t        j                  |      j                  t        j                  z  }t        j"                  |       | j%                  j                         d      5  |r| j'                  dd       n| j'                  dd       | j'                  dd       | j'                  dd       | j'                  dd	       | j'                  d
d       |r| j'                  dd       n| j'                  dd       d d d        | j%                  |j                         d      5  | j'                  dd       | j'                  dd       | j'                  dd       | j'                  dd	       | j'                  d
d       | j'                  dd       d d d        | j%                  |j                         d      5  t        j(                  t        j*                  | j,                  j                         j                              }| j'                  dd       | j'                  dd       | j'                  dd       | j'                  dd       | j'                  d
d       | j'                  d|       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# t        $ r<}|j                  t        t        dd      k(  r| j                  d       n Y d }~d }~ww xY w# t        j                  |       w xY w# 1 sw Y   xY w# 1 sw Y   yxY w# 1 sw Y   y xY w)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 bitrx  z
?rwsrwsrwxz
?---rwsrwxrI   z
?rwxr-xr-xz
?rw-r-xr-xz
?---r-xr-xr   z
?rw-r--r--z
?rw-r-----z
?rw-------)r  r   rf   rg   rh   re   r'   r  r  r  r  r  rM  r=  r  rs  r   r   r  r!  r~  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GGKlG3GG&\G:GG%LG9GGILG1GGFG.  ww||GZ8,$ %	$
.66EG "$!6!>!>!MIIl#

rww|4<<t||KLGGL199DLLH

O<   , ?  , ?[|</lC.\BY\:  l ;  l ; = 
E2Zl;[|</lC.\BY\:V,7 3 
F3"mmDLL""$,,-. /OZl;[|</lC.\BY\:V/: 43q ^ %$  99x ;; MM #H I I	 IIl# =< 32 43sp   A3P16P>AQ 0R 	BR-A3R:+B=S1P;>Q	R1RR RR R*-R7:SSc                    t               5 }|j                  dt        j                         d d d        dD ]^  }| j	                  j                         |      5  t        t        d      r"| j                  dt        j                         n	 d d d        ` | j	                  j                         d      5  | j                  t        j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r#  )rx  rI   mkfifor   z'foo' is a special file)r  r   r(   r}  r  r'   r   rf   r!  r*  SpecialFileErrorr-  s      r   	test_pipezTestExtractionFilters.test_pipe  s    ^sGGE 0 0G1  -F##CHHJ72x($$U1A1A$B  87 - 
F3!!(()+ 43 ^ 87 43s#   "C"4C.8!C:"C+.C7	:Dc                    t         j                  t         j                  t         j                  fD ]  }t        j                  d      }||_        t        j                  |d      }| j                  ||       t        j                  |d      }| j                  |j
                  |       | j                  t         j                        5 }t        j                  |d       d d d        | j                  j                  j                  t         j                         | j                  |j                  j                  j                   d        y # 1 sw Y   qxY w)Nr  r   )r(   r}  rw  rs  r  r^  fully_trusted_filterr'  
tar_filterrV   r  r  data_filterr7  r  r[   r   )r   special_typer[   trustedrI   r  s         r   test_special_filesz(TestExtractionFilters.test_special_files  s     $,,goowNLooe,G'GL227B?GMM'7+$$Wb1CSXX|4""7#;#;<##GR0 =!!",,"6"6HR\\1166> O =<s   	EE	c                     t         j                  j                  t              5 }|j	                         D ]*  }t        j
                  |d      }| j                  ||       , 	 d d d        y # 1 sw Y   y xY w)Nr   )r(   r)   r'   r$   r   r  r'  r   rI   r[   filtereds       r   test_fully_trusted_filterz/TestExtractionFilters.test_fully_trusted_filter  sS    __!!'*c>>+"77Dh0 , +**s   >A,,A5c                 h   t         j                  j                  t        d      5 }|j	                         D ]d  }t        j
                  |d      }| j                  |j                  |j                         | j                  |j                  |j                         f 	 d d d        y # 1 sw Y   y xY wNrE   rv  r   )	r(   r)   r'   r$   r   r  r'  r   r^  r  s       r   test_tar_filterz%TestExtractionFilters.test_tar_filter  sy     __!!'K!@C>>+"--gr:hmmW\\:hmmW\\: , A@@s   A8B((B1c                    t         j                  j                  t        d      5 }|j	                         D ]e  }	 t        j
                  |d      }| j                  |j                  |j                         | j                  |j                  |j                         g 	 d d d        y # t         j                  $ r Y w xY w# 1 sw Y   y xY wr  )
r(   r)   r'   r$   r   r  FilterErrorr'  r   r^  r  s       r   test_data_filterz&TestExtractionFilters.test_data_filter  s     __!!'K!@C>>+&227B?H hmmW\\:hmmW\\: , A@ ** 	 A@s/   CB)AC)B?<C>B??CCc                 P   t               5 }|j                  d       ddd       t        j                  dt        f      5  | j                  j                         d      5  | j                  d       ddd       ddd       y# 1 sw Y   hxY w# 1 sw Y   xY w# 1 sw Y   yxY w)zEnsure the default filter warnsr  NzPython 3.14)r  r   r   check_warningsr  r  r'   r!  r;  s     r   test_default_filter_warnsz/TestExtractionFilters.test_default_filter_warns  s    ^sGGEN ++ 235##CHHJ5  ' 65 5 ^ 655 5s/   B !B!B3BBB	BB%c                     t        j                  t        d      }d }||_        | j	                  |d       5  | j                  d       d d d        y # 1 sw Y   y xY w)Nra   c                 &    | j                   dk(  r| S y NrQ   rq  r[   rg   s     r   strict_filterzSTestExtractionFilters.test_change_default_filter_on_instance.<locals>.strict_filter      ||.r   rQ   )r(   r)   r$   r  r  r!  )r   rI   r  s      r   &test_change_default_filter_on_instancez<TestExtractionFilters.test_change_default_filter_on_instance  sK    oogs+	
 !.T*_- +**s   AAc                 4   d }t        j                  t        d      }t        j                  t         j                  dt        |            5  | j                  |d       5  | j                  d       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                 &    | j                   dk(  r| S y r  rq  r  s     r   r  zPTestExtractionFilters.test_change_default_filter_on_class.<locals>.strict_filter  r  r   ra   r  rQ   )r(   r)   r$   r   r   r~  r  r!  )r   r  rI   s      r   #test_change_default_filter_on_classz9TestExtractionFilters.test_change_default_filter_on_class  sw    	
 oogs+w0C+M:<##C.  1 /< <..< <s$   BB1BB	BBc                      G d dt         j                        } |t        d      }| j                  |d       5  | j	                  d       d d d        y # 1 sw Y   y xY w)Nc                       e Zd Zd Zy)QTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclassc                 &    |j                   dk(  r|S y r  rq  r   r[   rg   s      r   r  zcTestExtractionFilters.test_change_default_filter_on_subclass.<locals>.TarSubclass.extraction_filter  s    <<?2"Nr   Nr  r,   r   r   TarSubclassr    s     r   r  ra   rQ   )r(   r)   r$   r  r!  )r   r  rI   s      r   &test_change_default_filter_on_subclassz<TestExtractionFilters.test_change_default_filter_on_subclass  sJ    	 '// 	  '3'T*_- +**s   AAc                     t        j                  t        d      }d|_        | j	                  |d       5  | j                  t               d d d        y # 1 sw Y   y xY w)Nra   r   )r(   r)   r$   r  r  r*  r  r  s     r   $test_change_default_filter_to_stringz:TestExtractionFilters.test_change_default_filter_to_string  sD    oogs+ &T*!!), +**s   AAc                 b     fd}t               5 }|j                  d       |j                  d       |j                  d       d d d         j                  j                         |      5   j	                  d        j	                  d       d d d        y # 1 sw Y   UxY w# 1 sw Y   y xY w)Nc                     j                  |j                         | j                  dk(  r| j                  d      S | j                  dk(  ry | S )N	move_thismovedrq  ignore_this)r'  r  r   r   )r[   rg   r   s     r   custom_filterz?TestExtractionFilters.test_custom_filter.<locals>.custom_filter  sF    MM$-||{*G44||},Nr   r  r  keepr  r,  )r   r  r  s   `  r   test_custom_filterz(TestExtractionFilters.test_custom_filter  s    	 ^sGGK GGM"GGFO  
M:W%V$ ;:	 ^ ;:s   4B-#B%B"%B.c                     t               5 }|j                  d       d d d        | j                  j                         d      5  | j	                  t
               d d d        y # 1 sw Y   HxY w# 1 sw Y   y xY w)Nr  zbad filter name)r  r   r  r'   r*  rT  r;  s     r   test_bad_filter_namez*TestExtractionFilters.test_bad_filter_name   sU    ^sGGEN 
,=>!!*- ?> ^>>s   A$A0$A-0A9c                     G d d      }t               5 }|j                  d       |j                  dd       |j                  d       d d d         |       5 }| j                  j                         |      5  | j	                  d       d d d        d d d        | j                  j                  d       | j                  |j                  d       y # 1 sw Y   xY w# 1 sw Y   VxY w# 1 sw Y   ZxY w)	Nc                       e Zd Zd Zd Zd Zy)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                  ||      }| xj                  dz  c_        |S # t         j                  $ r Y y w xY w)Nru   )r(   r  r  r  r  s      r   __call__zKTestExtractionFilters.test_stateful_filter.<locals>.StatefulFilter.__call__  sK     %11'4@G ((A-( **   s   / AAc                     d| _         y )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  
  s    !r   r  goodbadr   r  rx   T)r  r   r  r'   r!  rV   r  r  )r   r  r  r  s       r   test_stateful_filterz*TestExtractionFilters.test_stateful_filter  s    	! 	!  ^sGGFOGGEcG*GGFO  ##CHHJ>  ( ?  	::A>++T2 ^
 ?> s/   6C!C.;C"C.C"C+	'C..C7c                 	   d }d }d }d }d }t               5 }|j                  d       d d d        | j                  j                  d      |      5  	 d d d        | j                  |j                  d      |      5  	 d d d        | j                  |j                  d      |      5  	 d d d        | j                  |j                  d      |      5  | j	                  t
        j                         d d d        | j                  |j                  d      |      5  | j	                  t               d d d        | j                  |j                  d	      |      5  	 d d d        | j                  |j                  d	      |      5  | j	                  t
        j                         d d d        | j                  |j                  d	      |      5  | j	                  t               d d d        | j                  |j                  d	      |      5  | j	                  t
        j                         d d d        | j                  |j                  d	      |      5  | j	                  t               d d d        | j                  |j                  d
      |      5  | j	                  t
        j                         d d d        | j                  |j                  d
      |      5  | j	                  t
        j                         d d d        | j                  |j                  d
      |      5  | j	                  t               d d d        | j                  |j                  d
      |      5  | j	                  t
        j                         d d d        | j                  |j                  d
      |      5  | j	                  t               d d d        | j                  |j                  d      |      5  | j	                  t               d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ]xY w# 1 sw Y   *xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   +xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   ~xY w# 1 sw Y   AxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nc                 ,    t        j                  d      )Nzfailed with ExtractError)r(   ExtractErrorr  s     r   extracterror_filterzBTestExtractionFilters.test_errorlevel.<locals>.extracterror_filter%  s    &&'ABBr   c                 ,    t        j                  d      )Nzfailed with FilterError)r(   r  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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)rT  r  s     r   valueerror_filterz@TestExtractionFilters.test_errorlevel.<locals>.valueerror_filter-  s    566r   r-  r   r  ru   rx   zboo!)r  r   r  r'   r*  r(   r  rT  r  r  r  r  )r   r  r  r  r  r  r  s          r   test_errorlevelz%TestExtractionFilters.test_errorlevel$  s   	C	A	1	@	7 ^sGGFO 
 A 68KL M A 68JK L A 6G H A 6H!!'"2"23 I A 68IJ!!*- K
 A 68KL M A 68JK!!'"5"56 L A 6G!!'* H A 6H!!'"2"23 I A 68IJ!!*- K
 A 68KL!!'"6"67 M A 68JK!!'"5"56 L A 6G!!'* H A 6H!!'"2"23 I A 68IJ!!*- K
 F ;=OP!!), QPq ^
 ML LK HG IH KJ
 ML LK HG IH KJ
 ML LK HG IH KJ
 QPs   P!P.P;.Q Q$Q"$Q/ Q<R	 R$R#$ R0. R=8S
8 SS$S1!P+.P8;QQQ"Q,/Q9<R	RR #R-0R:=S
SS!$S.1S:)NNNNN)r  ).r!   r"   r#   r  r  re   r  r  r   r  r!  r&  r*  r.  r4  r  r<  r	   r  rY  r^  rb  rd  rg  rj  rs  ry  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   
 w||G$z1H G7; '1 '1R BF'+*0X
%/K2 00 00d ""FH # FHP T0 T0l : :::"  -  -D % %& @ @. 9 92 1: 1:f  , @ @>* C;J+$?1;
;(	.
2
.-%".3<E-r   r
  c                   `    e Zd Zej                  j                  ed      Zed        Z	d Z
d Zy)OverwriteTeststestoverwritec                 ,   t         j                  j                  t        d      x}| _        | j                  t        j                  |       t        j                  |d      5 }t        j                  d      }d|_        |j                  |t        j                  d             d d d        t         j                  j                  t        d      x}| _        | j                  t        j                  |       t        j                  |d      5 }|j                  |j!                  t         j"                  d             d d d        t         j                  j                  t        d      }|| _        | j                  t        j                  |       t        j                  |d      5 }t        j                  d      }d|_        |j                  |t        j                  d             d d d        y # 1 sw Y   OxY w# 1 sw Y   xY w# 1 sw Y   y xY w)	Nztar-with-file.tarr   r  rw   s
   newcontentztar-with-dir.tarztar-with-implicit-dir.tarz	test/file)rf   rg   rh   re   ar_with_fileaddClassCleanupr	   rs  r(   r'   r  rX   r  r%   r   ar_with_dirr  curdirar_with_implicit_dir)r  r  rI   r  s       r   r  zOverwriteTests.setUpClasso  sn   !ww||G5HIICI,,a0\\!S!S'AAFKK2::m45 "
 !ggll74FGGCOI,,a0\\!S!SKKryy&9: " GGLL"=>#$ I,,a0\\!S!S,AAFKK2::m45 "! "! "! "!s&   "AG10G>&AH
1G;>H
Hc                 .    t        j                  |d      S r=  )r(   r'   )r   rg   s     r   r'   zOverwriteTests.open  s    ||D#&&r   c                 >    |j                  | j                  d       y )Nrx  r_   )rw  testdir)r   ars     r   rw  zOverwriteTests.extractall  s    
dll?;r   N)r!   r"   r#   rf   rg   rh   re   r  r  r  r'   rw  r,   r   r   r  r  l  s2    ggll7O4G6 6*'<r   r  c                   r   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      j%                  ej&                        Zdej*                  z  Zd ZddZd Zd Zd Zd Zd Zy)OffsetValidationTestss   000755s   000001s      s   0011407    rp     s   0000755s   0000001s   0011327rY     s   0010070r   r     c                 |    t        | j                  d      5 }|j                  |       d d d        y # 1 sw Y   y xY wr  )r'   r$   r  )r   bufferrY  s      r   _write_bufferz#OffsetValidationTests._write_buffer  s)    $,,%GGFO &%%r  Nc                     t        | j                  d      5 }t        j                   d||      5 }|j                         cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        y # 1 sw Y   y xY w)Nrt   ra   )r    r6  r  )r'   r$   r(   r   )r   r  rY  rI   s       r   _get_membersz"OffsetValidationTests._get_members  s`    $,,%!,~~'  &%   &%%s"   A)A 	A)A	A))A2c                     | j                  t        j                  d      5  | j                          d d d        y # 1 sw Y   y xY w)Nr"  )r  r(   r  r   r   s    r   #_assert_raises_read_error_exceptionz9OffsetValidationTests._assert_raises_read_error_exception  s:    ##F
 
 
 
s	   ;Ac                     d| j                   fd| j                  fd| j                  ffD ]A  \  }}| j                  |      5  | j	                  |       | j                          d d d        C y # 1 sw Y   NxY w)Nposixri  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  sx    d//0D++,4))*+
&J
 Z0"">288: 10+

 10s   "A//A8	c                 D   | j                   | j                  z   | j                   z   }| j                  |       | j                         }| j	                  t        |      d       | j	                  |d   j                  d       | j	                  |d   j                  d       y )Nru   r   r  )valid_gnu_headerr  r  r   rV   rW   r   rX  r   r  r   s      r   (test_early_stop_at_invalid_offset_headerz>OffsetValidationTests.test_early_stop_at_invalid_offset_header  s    &&)@)@@4CXCXX6"##%Wq)*5**A.r   c                     | j                   | j                  z   dz  }| j                  |       | j                  d      }| j	                  t        |      d       y )Nr*  Tr  r   )r  
data_blockr  r   rV   rW   r  s      r   test_ignore_invalid_archivez1OffsetValidationTests.test_ignore_invalid_archive  sP    ))DOO;q@6"###6Wq)r   c                    | j                   | j                  | j                  z   df| j                  | j                  z   | j                   dffD ]  \  }}}| j                  ||z          | j	                  d      }| j                  t        |      d       | j                  |d   j                  d       | j                  |d   j                  |        y )Nr   rv   Tr  ru   r  )	r  r  r  r  r   rV   rW   r   rX  )r   first_blocksecond_blockexpected_offsetr   s        r   "test_ignore_invalid_offset_headersz8OffsetValidationTests.test_ignore_invalid_offset_headers  s     &&((4??: ((4??:&&;
6K {\9:''T':GS\1-WQZ__j9WQZ..@!;
r   r   )r!   r"   r#   r   r$   r(   rs  rL  SPACErt  rM  r  r  r  r  r  r  r  r  r}  r  r  r  r  r   r  r  r  r  r  r,   r   r   r  r    s6   G 	g)))
		%kk	* 		 		 &kk		* 	 	 &kk	* 	 	 ++

	 #
	# 	 {{	# //	  ++++
+!	,$ 

%	( ++
)	, ++
-	0 ++/1	0 "1	"0 %,KK1	04 ++/5	4 "5	"4 %,KK5	08 ++--
-9	.< ++
=	 H 	g)))
	{{	# 		 {{		# 	 {{	# 	 	 ++

	 #
	# 	 {{	# //	  ++++
+!	,$ 

%	( ++
)	, ++
-	0 ++/1	4 ++/5	8 ++
9	 D 	g)))
		%kk	* 		 		 &kk		* 	 	 &kk	* 	 	 ++

	 #
	# 	 {{	# //	  ++++
+!	,$ ++
%	 , 'wz2889K9KL7,,,J( ;/*Ar   r  c                  &   t        j                  t               t        j                  t               t
        gat        t
        d      5 } | j                         }d d d        t        t        t        fD ]  }|j                  st        j                  |j
                         t        j                  |j
                         |j                  |j
                  d      5 }|j                         d d d         y # 1 sw Y   xY w# 1 sw Y   xY w)Nrt   r   )r	   rs  re   rf   r  r$   r  r'   rU   r.   r5   r;   r  r  )r\   r   r{  rI   s       r   setUpModuler  '  s    WKK 9L	gt	yy{ 
 w(66QYY'		*		4(C		$ )(	 )	 
	 )(s   
C;D;DD	c                  ~    t         j                  j                  t              rt	        j
                  t               y y r   )rf   rg   r  re   r	   r  r,   r   r   tearDownModuler  8  s%    	ww~~g! r   __main__)rM  r   rf   r%   hashlibr   
contextlibr   r   randomr   r  r  r  r  r  r   unittest.mockr(   r  r   r   test.supportr	   r
   r   r1   rD  r  r6   r>   r   rg   r9  TESTFNre   r  r#  r$   rh   r0   r7   r=   r   r  r  rY   r9  r   requires_gzipr.   rE  r5   requires_lzmar;   rB   TestCaserO   r   r   r   r   r   r   r   r   r0  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  rQ  rh  r  r  r  r  r  r  r  r  r  r  r   r+  r5  r8  r=  r@  rG  rm  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r&  rF  rH  rJ  rL  rW  r  r  r  r  r-  rG  rK  rr  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r!   rv  r,   r   r   <module>r(     s    
 	 	  0    	        " & ($ ''//)**
+i
7o%	
'

=
)77<<!12
'',,w 1
2	g/	0
'',,w	
*ggll7I. G  G 
) ) % % % & & & % % %	w 	UHh// Un	- 		w 		- 	M1x** M1`	8X 		'8 		8X 	X1X X1vm.~ m.^	#X%6%6 	x!183D3D 	8g/1B1B 89x!183D3D 9
<^X%6%6 <|	> 		 		> 	&1Wh// &1P	> 	, ,	> 	1x1B1B 1"^EXx00 ^EB6O 6Op9,(*;*; 9xT@,(*;*; T@nGG G<x'x00 x'v		Hi 		7I 		Hi 	(%mX%6%6 (%V7(O 78/ 8;(O ;?7 ?,!7$8(:K:K !!*>! (%98;L;L   *> C(++ C$O58$$ O5d+&}h&7&7 +&\W. 1 1 W.tXz GZ %Xz %(* ( WR(*KL'18$$ '1 M'1TH8< H8VN NbL{H$5$5 L^G[("3"3 G$K[("3"3 K(I I(>%!2!2 >%@	X~x/@/@ 		G^X->-> 		X~x/@/@ 	8*"" 8*vt&x   t&na h'' a H7B** 7Bt V$&FG@("3"3 @ H@B*("3"3 *>	 WR)+=>WR+-ABwOx(( wO C ?wOt%-8X.. %-Pd8 dL 4h6G6G ((<(0(9(9(3X5F5F #7#+#4#4\8** \8|8C3 C3T ??Cf-H-- f-R<^22H4E4E <@XAH-- XAv "" zHMMO CQ  D  D  
C  DsH   $_ )_& ._4 3` _#"_#&_10_14_?>_?``