B
    u9a‡„ ã               @   s~  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	Z	d dl
Z
d dlZ
d dlZd dlmZ d dlmZ yd dlZW n ek
r˜   dZY nX yd dlZW n ek
r¾   dZY nX yd dlZW n ek
rä   dZY nX dd„ Zej ej¡d	 Zed
 Ze d¡Zej ed¡Zej ed¡Zej ed¡Z ej ed¡Z!ej ed¡Z"dZ#dZ$G dd„ dƒZ%ej&G dd„ dƒƒZ'ej(G dd„ dƒƒZ)ej*G dd„ dƒƒZ+G dd„ de%ƒZ,G dd„ de,e
j-ƒZ.G dd „ d e'e.ƒZ/G d!d"„ d"e)e.ƒZ0G d#d$„ d$e+e.ƒZ1G d%d&„ d&e,e
j-ƒZ2G d'd(„ d(e'e2ƒZ3G d)d*„ d*e)e2ƒZ4G d+d,„ d,e+e2ƒZ5G d-d.„ d.e,ƒZ6G d/d0„ d0e6ƒZ7G d1d2„ d2e7e
j-ƒZ8G d3d4„ d4e'e7e
j-ƒZ9G d5d6„ d6e)e7e
j-ƒZ:G d7d8„ d8e+e7e
j-ƒZ;G d9d:„ d:e6e
j-ƒZ<G d;d<„ d<e'e<ƒZ=G d=d>„ d>e)e<ƒZ>G d?d@„ d@e+e<ƒZ?G dAdB„ dBe%e
j-ƒZ@G dCdD„ dDe'e@ƒZAG dEdF„ dFe)e@ƒZBG dGdH„ dHe+e@ƒZCG dIdJ„ dJe,e
j-ƒZDG dKdL„ dLƒZEG dMdN„ dNeEe,e
j-ƒZFG dOdP„ dPeEe,e
j-ƒZGG dQdR„ dRe%ƒZHG dSdT„ dTeHe
j-ƒZIG dUdV„ dVe'eIƒZJG dWdX„ dXe)eIƒZKG dYdZ„ dZe+eIƒZLG d[d\„ d\eHe
j-ƒZMG d]d^„ d^e'eMƒZNG d_d`„ d`e)eMƒZOG dadb„ dbe+eMƒZPG dcdd„ dde
j-ƒZQG dedf„ dfeHe
j-ƒZRG dgdh„ dhe'eRƒZSG didj„ dje)eRƒZTG dkdl„ dle+eRƒZUG dmdn„ dneRƒZVe
 WeXedoƒdp¡G dqdr„ dre
j-ƒƒZYG dsdt„ dteQƒZZG dudv„ dvƒZ[G dwdx„ dxe[e
j-ƒZ\G dydz„ dze[e
j-ƒZ]G d{d|„ d|e[e
j-ƒZ^G d}d~„ d~ƒZ_G dd€„ d€e_e
j-ƒZ`G dd‚„ d‚e'e_e
j-ƒZaG dƒd„„ d„e)e_e
j-ƒZbG d…d†„ d†e+e_e
j-ƒZcG d‡dˆ„ dˆe
j-ƒZdG d‰dŠ„ dŠe
j-ƒZeG d‹dŒ„ dŒe
j-ƒZfG ddŽ„ dŽe
j-ƒZge
 heXedoƒd¡G dd‘„ d‘e,e
j-ƒƒZiG d’d“„ d“e)e
j-ƒZjd”d•„ Zke
 WeXed–ƒd—¡e
 WeXed˜ƒd™¡G dšd›„ d›e
j-ƒƒƒZldœd„ ZmdždŸ„ Zneod krze
 p¡  dS )¡é    N)Úmd5)Úcontextmanager)ÚRandom)Úsupport)Úscript_helperc             C   s   t | ƒ ¡ S )N)r   Z	hexdigest)Údata© r   ú"/usr/lib/python3.7/test_tarfile.pyÚmd5sum   s    r
   z-tardirz-extract-testztesttar.tarztesttar.tar.gzztesttar.tar.bz2ztesttar.tar.xzztmp.tarZtesttarZ 65f477c818ad9e15f7feab0c6d37742fZ a54fbc4ca4f4399a90e1b27164012fc6c               @   s.   e Zd ZeZdZejZej	j
Z
edd„ ƒZdS )ÚTarTestÚ c             C   s   | j | j S )N)ÚprefixÚsuffix)Úselfr   r   r	   Úmode4   s    zTarTest.modeN)Ú__name__Ú
__module__Ú__qualname__Útarnamer   ÚioÚFileIOÚopenÚtarfileÚTarFileÚtaropenÚpropertyr   r   r   r   r	   r   .   s
   r   c               @   s*   e Zd ZeZdZerejndZe	j
jZdS )ÚGzipTestZgzN)r   r   r   Úgzipnamer   r   ÚgzipZGzipFiler   r   r   Zgzopenr   r   r   r   r	   r   8   s   r   c               @   s*   e Zd ZeZdZerejndZe	j
jZdS )ÚBz2TestÚbz2N)r   r   r   Úbz2namer   r   r    ÚBZ2Filer   r   r   Zbz2openr   r   r   r   r	   r   ?   s   r   c               @   s*   e Zd ZeZdZerejndZe	j
jZdS )ÚLzmaTestZxzN)r   r   r   Úxznamer   r   ÚlzmaZLZMAFiler   r   r   Zxzopenr   r   r   r   r	   r#   F   s   r#   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚReadTestzr:c             C   s   t j| j| jdd| _d S )Nz	iso8859-1)r   Úencoding)r   r   r   r   Útar)r   r   r   r	   ÚsetUpR   s    zReadTest.setUpc             C   s   | j  ¡  d S )N)r(   Úclose)r   r   r   r	   ÚtearDownV   s    zReadTest.tearDownN)r   r   r   r   r)   r+   r   r   r   r	   r&   N   s   r&   c               @   sd   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚUstarReadTestc          	   C   sV   | j  d¡}| j  |¡4}| ¡ }|  t|ƒ|jd¡ |  t|ƒtd¡ W d Q R X d S )Nzustar/regtypezregular file extraction failed)	r(   Ú	getmemberÚextractfileÚreadÚassertEqualÚlenÚsizer
   Úmd5_regtype)r   ÚtarinfoÚfobjr   r   r   r	   Útest_fileobj_regular_file\   s    z'UstarReadTest.test_fileobj_regular_filec          	   C   s¢   | j  dt¡ | j  d¡}ttj td¡dƒ}| ¡ }W d Q R X | j  	|¡J}t
 |¡}| ¡ }|  ||d¡ |  t|ƒdd¡ |  |d dd¡ W d Q R X d S )Nzustar/regtypeÚrzfileobj.readlines() failedér   éS   zOI will gladly admit that Python is not the fastest running scripting language.
)r(   ÚextractÚTEMPDIRr-   r   ÚosÚpathÚjoinÚ	readlinesr.   r   ÚTextIOWrapperr0   r1   )r   r4   Úfobj1Úlines1r5   Úfobj2Úlines2r   r   r	   Útest_fileobj_readlinese   s    

z$UstarReadTest.test_fileobj_readlinesc          	   C   sz   | j  dt¡ | j  d¡}ttj td¡dƒ}| ¡ }W d Q R X | j  	|¡"}t
t |¡ƒ}|  ||d¡ W d Q R X d S )Nzustar/regtyper7   zfileobj.__iter__() failed)r(   r:   r;   r-   r   r<   r=   r>   r?   r.   Úlistr   r@   r0   )r   r4   rA   rB   rC   rD   r   r   r	   Útest_fileobj_iterw   s    zUstarReadTest.test_fileobj_iterc       	   	   C   sú  | j  dt¡ ttj td¡dƒ}| ¡ }W d Q R X | j  d¡}| j  	|¡}| ¡ }| 
d¡ |  d| ¡ d¡ | 
dd¡ |  d| ¡ d¡ | 
dd¡ |  d	| ¡ d
¡ | 
d	d¡ |  d| ¡ d¡ | d¡}|  ||dd… d¡ | 
dd¡ |  |j| ¡ d¡ |  | ¡ dd¡ | 
|j d¡ |  d| ¡ d¡ | 
d¡ | ¡ }| 
d¡ | ¡ }|  ||d¡ | 
d¡ |  t| ¡ ƒ| ¡ d¡ | 
d¡ |  t| ¡ ƒd | ¡ d¡ | 
d¡ | ¡ }|  | ¡ |t|ƒd … d¡ | ¡  d S )Nzustar/regtypeÚrbr   zseek() to file's start failedi   z"seek() to absolute position failedi üÿÿé   i   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 failedó    z0read() at file's end did not return empty stringz$relative seek() to file's end failedi   zreadlines() after seek failedztell() after readline() failedz)tell() after seek() and readline() failedzread() after readline() failed)r(   r:   r;   r   r<   r=   r>   r/   r-   r.   Úseekr0   Útellr2   r?   r1   Úreadliner*   )	r   r5   r   r4   ÚtextÚsÚs1Ús2Úliner   r   r	   Útest_fileobj_seek   s\    






zUstarReadTest.test_fileobj_seekc          	   C   sr   | j  d¡\}t |¡}| ¡  d¡}|  t|ƒt¡ y| 	d¡ W n t
k
rb   |  d¡ Y nX W d Q R X d S )Nzustar/regtypez	iso8859-1éd   zseeking failed in text mode)r(   r.   r   r@   r/   Úencoder0   r
   r3   rM   ÚAttributeErrorÚfail)r   r5   r   r   r   r	   Útest_fileobj_text³   s    
zUstarReadTest.test_fileobj_textc          
   C   sD   | j  |¡.}| j  |¡}|  |j|j¡ W d Q R X W d Q R X d S )N)r(   r.   r0   Úname)r   ZlnktypeÚregtypeÚaÚbr   r   r	   Ú_test_fileobj_linkÂ   s    z UstarReadTest._test_fileobj_linkc             C   s   |   dd¡ d S )Nzustar/lnktypezustar/regtype)r_   )r   r   r   r	   Útest_fileobj_link1Ç   s    z UstarReadTest.test_fileobj_link1c             C   s   |   dd¡ d S )Nz./ustar/linktest2/lnktypezustar/linktest1/regtype)r_   )r   r   r   r	   Útest_fileobj_link2Ê   s    z UstarReadTest.test_fileobj_link2c             C   s   |   dd¡ d S )Nzustar/symtypezustar/regtype)r_   )r   r   r   r	   Útest_fileobj_symlink1Î   s    z#UstarReadTest.test_fileobj_symlink1c             C   s   |   dd¡ d S )Nz./ustar/linktest2/symtypezustar/linktest1/regtype)r_   )r   r   r   r	   Útest_fileobj_symlink2Ñ   s    z#UstarReadTest.test_fileobj_symlink2c             C   s   |   dd¡ d S )NZsymtype2zustar/regtype)r_   )r   r   r   r	   Útest_issue14160Õ   s    zUstarReadTest.test_issue14160N)r   r   r   r6   rE   rG   rU   rZ   r_   r`   ra   rb   rc   rd   r   r   r   r	   r,   Z   s   	
2r,   c               @   s   e Zd ZdS )ÚGzipUstarReadTestN)r   r   r   r   r   r   r	   re   Ø   s   re   c               @   s   e Zd ZdS )ÚBz2UstarReadTestN)r   r   r   r   r   r   r	   rf   Û   s   rf   c               @   s   e Zd ZdS )ÚLzmaUstarReadTestN)r   r   r   r   r   r   r	   rg   Þ   s   rg   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚListTestc             C   s   t j| j| jd| _d S )N)r   )r   r   r   r   r(   )r   r   r   r	   r)   å   s    zListTest.setUpc          	      s,  t jt  ¡ ddd}t td|¡ ˆ jjdd W d Q R X | ¡  	¡ }ˆ  
d|¡ ˆ  
d|¡ ˆ  
d	|¡ ˆ  
d
|¡ ˆ  
d|¡ ˆ  
d|¡ ˆ  
d|¡ ˆ  
d|¡ ‡ fdd„}ˆ  
|dƒ|¡ ˆ  
|dƒ|¡ ˆ  
|dƒ|¡ ˆ  
|dƒ|¡ ˆ  
|dƒ|¡ ˆ  |d¡ ˆ  d|¡ ˆ  d|¡ d S )NÚasciiÚ
)ÚnewlineÚstdoutF)Úverboses   ustar/conttypes   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                s   |   ˆ jjd¡}| dd¡S )NÚsurrogateescaperi   Úbackslashreplace)Údecoder(   r'   rW   )r^   rQ   )r   r   r	   Úconv÷   s    z ListTest.test_list.<locals>.convs   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   r@   ÚBytesIOr   Ú	swap_attrÚsysr(   rF   ÚdetachÚgetvalueÚassertInÚassertRegexÚassertNotIn)r   ÚtioÚoutrq   r   )r   r	   Ú	test_listè   s.    

zListTest.test_listc          	   C   s”   t jt  ¡ ddd}t td|¡ | jjdd W d Q R X | ¡  	¡ }|  
|d¡ |  d|¡ |  d	|¡ |  d
|¡ |  d|¡ |  d|¡ d S )Nri   rj   )rk   rl   T)rm   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   r@   rr   r   rs   rt   r(   rF   ru   rv   rx   rw   )r   rz   r{   r   r   r	   Útest_list_verbose  s    zListTest.test_list_verbosec          	   C   st   t jt  ¡ ddd}dd„ }t td|¡ | jjd|| jƒd W d Q R X | ¡  	¡ }|  
d	|¡ |  d
|¡ d S )Nri   rj   )rk   c             s   s&   x |   ¡ D ]}d|jkr
|V  q
W d S )NZreg)Ú
getmembersr[   )r(   r4   r   r   r	   Úmembers'  s    
z+ListTest.test_list_members.<locals>.membersrl   F)rm   r   s   ustar/regtypes   ustar/conttype)r   r@   rr   r   rs   rt   r(   rF   ru   rv   rw   ry   )r   rz   r   r{   r   r   r	   Útest_list_members%  s     zListTest.test_list_membersN)r   r   r   r)   r|   r}   r€   r   r   r   r	   rh   â   s   %rh   c               @   s   e Zd ZdS )ÚGzipListTestN)r   r   r   r   r   r   r	   r   2  s   r   c               @   s   e Zd ZdS )ÚBz2ListTestN)r   r   r   r   r   r   r	   r‚   6  s   r‚   c               @   s   e Zd ZdS )ÚLzmaListTestN)r   r   r   r   r   r   r	   rƒ   :  s   rƒ   c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚCommonReadTestc          	   C   s‚   t  t| j dd¡¡ W d Q R X zPyt  t| j¡}| ¡  W n  t jk
r^   |  d¡ Y nX |  | 	¡ g ¡ W d | 
¡  X d S )Nr7   Úwz&tarfile.open() failed on empty archive)r   r   Útmpnamer   ÚreplaceÚgetnamesÚ	ReadErrorrY   ÚassertListEqualr~   r*   )r   r(   r   r   r	   Útest_empty_tarfile@  s    
z!CommonReadTest.test_empty_tarfilec          	   C   s*   |   td¡ t d| j¡ W d Q R X d S )NZxxx)ÚassertRaisesRegexÚFileNotFoundErrorr   r   r   )r   r   r   r	   Útest_non_existent_tarfileQ  s    z(CommonReadTest.test_non_existent_tarfilec          	   C   sB   t tdƒ W d Q R X |  tjtj t| j¡ |  tjtj t¡ d S )NÚwb)r   r†   ÚassertRaisesr   r‰   r   )r   r   r   r	   Útest_null_tarfileW  s    
z CommonReadTest.test_null_tarfilec          
   C   s²   t dƒ d¡ dd¡}x–dD ]Ž}|  td¡@}| |d ¡ t d¡}t|ƒ|_	| | 
¡ ¡ | |¡ W d Q R X tjtd	d
d}z|  | ¡ dgd| ¡ W d | ¡  X qW d S )Nr   i   i   Zbig)ó    ó   ar…   i   Úfoor7   T)r   Zignore_zerosz3ignore_zeros=True should have skipped the %r-blocks)r   ZgetrandbitsÚto_bytesr   r†   Úwriter   ÚTarInfor1   r2   ÚtobufrŠ   rˆ   r*   )r   r   Úcharr5   r4   r(   r   r   r	   Útest_ignore_zeros`  s    


z CommonReadTest.test_ignore_zerosc             C   s  xdD ]}t  td¡(}t  d¡}d|_| |t d¡¡ W d Q R X ttdƒ}| |¡ W d Q R X t  t¡.}|  	t j
d¡ x|D ]}qŠW W d Q R X W d Q R X t  t¡\}| ¡ }|  	t j
d¡ | |t¡ W d Q R X |  	t j
d¡ | |¡ ¡  W d Q R X W d Q R X qW d S )N)i   iX  i   i°  zw:r”   i   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazr+bzunexpected end of data)r   r   r†   r—   r2   Úaddfiler   rr   ÚtruncaterŒ   r‰   Únextr:   r;   r.   r/   )r   r2   r(   Útr5   r   r   r	   Útest_premature_end_of_archivev  s"    

z,CommonReadTest.test_premature_end_of_archiveN)r   r   r   r‹   rŽ   r‘   rš   rŸ   r   r   r   r	   r„   >  s
   	r„   c               @   sÌ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze eedƒd¡ejdd „ ƒƒZd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-S ).ÚMiscReadTestBasec             C   s   d S )Nr   )r   r   r   r	   Úrequires_name_attribute  s    z(MiscReadTestBase.requires_name_attributec          
   C   st   |   ¡  t| jdƒV}|  |jt¡ tj|| jd,}|  |jt¡ |  |jt	j
 |j¡¡ W d Q R X W d Q R X d S )NrH   )Úfileobjr   )r¡   r   r   ÚassertIsInstancer[   Ústrr   r   r0   r<   r=   Úabspath)r   r5   r(   r   r   r	   Útest_no_name_argument’  s    z&MiscReadTestBase.test_no_name_argumentc          	   C   sZ   t | jdƒ}| ¡ }W d Q R X t |¡}|  tt|d¡ tj || j	d}|  
|j¡ d S )NrH   r[   )r¢   r   )r   r   r/   r   rr   r   rX   Úgetattrr   r   ÚassertIsNoner[   )r   r5   r   r(   r   r   r	   Útest_no_name_attributeš  s    
z'MiscReadTestBase.test_no_name_attributec          	   C   s\   t | jdƒ}| ¡ }W d Q R X t |¡}d|_tj || jd}|  |j¡ W d Q R X d S )NrH   r   )r¢   r   )	r   r   r/   r   rr   r[   r   r   r¨   )r   r5   r   r(   r   r   r	   Útest_empty_name_attribute¢  s    
z*MiscReadTestBase.test_empty_name_attributec          
   C   s`   t  | jt j¡}t|dƒ<}|  |jt¡ tj|| jd}|  	|j¡ W d Q R X W d Q R X d S )NrH   )r¢   r   )
r<   r   r   ÚO_RDONLYr£   r[   Úintr   r   r¨   )r   Úfdr5   r(   r   r   r	   Útest_int_name_attributeª  s
    z(MiscReadTestBase.test_int_name_attributec          
   C   s~   |   ¡  t | j¡}t|dƒV}|  |jt¡ tj|| j	d,}|  |jt¡ |  
|jtj |j¡¡ W d Q R X W d Q R X d S )NrH   )r¢   r   )r¡   r<   Úfsencoder   r   r£   r[   Úbytesr   r   r0   r=   r¥   )r   r   r5   r(   r   r   r	   Útest_bytes_name_attribute³  s    z*MiscReadTestBase.test_bytes_name_attributec          	   C   s.  t  | j¡}tj|| jd0}|  |jt¡ |  	|jt
j t
 |¡¡¡ W d Q R X |  |¡0}|  |jt¡ |  	|jt
j t
 |¡¡¡ W d Q R X tjj|| jd0}|  |jt¡ |  	|jt
j t
 |¡¡¡ W d Q R X | jdkr*tj|dd0}|  |jt¡ |  	|jt
j t
 |¡¡¡ W d Q R X d S )N)r   r   r7   )ÚpathlibÚPathr   r   r   r   r£   r[   r¤   r0   r<   r=   r¥   Úfspathr   r   r   )r   r   r(   r   r   r	   Útest_pathlike_name¼  s    &&&z#MiscReadTestBase.test_pathlike_namec          	   C   s†   t tdƒ W d Q R X |  td¡ |  td¡}W d Q R X |  td¡ |  td¡}W d Q R X |  td¡ |  td¡}W d Q R X d S )Nr   zmode must be ÚqÚrwr   )r   r†   rŒ   Ú
ValueErrorr   )r   r(   r   r   r	   Útest_illegal_mode_argÌ  s    
z&MiscReadTestBase.test_illegal_mode_argc          	   C   sÒ   t j| j| jd}z>| ¡  | ¡ }|j}|j}| |¡}| ¡ }W d Q R X W d | 	¡  X |  | j¡`}| 
|¡ |j| jd|d}| ¡ }|  |j|¡ | ¡  |  | |¡ ¡ |d¡ | 	¡  W d Q R X d S )N)r   zr:)r   r¢   zseek back did not work)r   r   r   r   r   r[   Úoffsetr.   r/   r*   rM   r0   r~   )r   r(   rž   r[   rº   Úfr   r5   r   r   r	   Útest_fileobj_with_offsetÖ  s$    

z)MiscReadTestBase.test_fileobj_with_offsetc          	   C   sH   |   tjtjt| j¡ ttdƒ}| j tjtj|| jd W d Q R X d S )NrH   )r¢   r   )r   r   r‰   r   r   r   )r   r5   r   r   r	   Útest_fail_compó  s    zMiscReadTestBase.test_fail_compc             C   s"   | j  d¡}|  |jtjd¡ d S )Nzmisc/dirtype-old-v7zv7 dirtype failed)r(   r-   r0   Útyper   ÚDIRTYPE)r   r4   r   r   r	   Útest_v7_dirtypeú  s    z MiscReadTestBase.test_v7_dirtypec             C   s4   y| j  d¡ W n tk
r.   |  d¡ Y nX d S )Nzmisc/regtype-xstarz3failed to find misc/regtype-xstar (mangled prefix?))r(   r-   ÚKeyErrorrY   )r   r   r   r	   Útest_xstar_type  s    z MiscReadTestBase.test_xstar_typec             C   sR   xL| j D ]B}|  t|jƒdd|j ¡ |j d¡s4q|  |jdd|j ¡ qW d S )Ni½>zwrong mtime for %szustar/r   zwrong uname for %s)r(   r0   r¬   Úmtimer[   Ú
startswithÚuname)r   r4   r   r   r	   Útest_check_members  s    
z#MiscReadTestBase.test_check_membersc             C   s   |   | j ¡ d jdd¡ d S )Néÿÿÿÿzmisc/eofzcould not find all members)r0   r(   r~   r[   )r   r   r   r	   Útest_find_members  s    z"MiscReadTestBase.test_find_membersÚlinkzMissing hardlink implementationc          
   C   sü   t jtdddâ}| dt¡ |  tjtj	 
td¡¡ | dt¡ |  tjtj	 
td¡¡ ttj	 
td¡dƒ}| ¡ }W d Q R X |  t|ƒt¡ | dt¡ |  tjtj	 
td¡¡ ttj	 
td¡dƒ}| ¡ }W d Q R X |  t|ƒt¡ W d Q R X d S )NrI   z	iso8859-1)Z
errorlevelr'   zustar/regtypezustar/lnktyperH   zustar/symtype)r   r   r   r:   r;   Ú
addCleanupr   Úunlinkr<   r=   r>   r/   r0   r
   r3   )r   r(   r»   r   r   r   r	   Útest_extract_hardlink  s    z&MiscReadTestBase.test_extract_hardlinkc       	   	   C   sà   t jtdd}tj td¡}t |¡ z dd„ |D ƒ}| ||¡ x€|D ]x}tj ||j	¡}t
jdkr„|  |jd@ t |¡jd@ ¡ dd	„ }tj |¡}d
 ||jƒ||ƒ|¡}|  |j||¡ qHW W d | ¡  t |¡ X d S )Nz	iso8859-1)r'   Ú
extractallc             S   s   g | ]}|  ¡ r|‘qS r   )Úisdir)Ú.0rž   r   r   r	   ú
<listcomp>4  s    z4MiscReadTestBase.test_extractall.<locals>.<listcomp>Úwin32iÿ  c             S   s(   t | tƒrd | |  ¡ ¡S d | ¡S d S )Nz{} ({})z
{!r} (int))Ú
isinstanceÚfloatÚformatÚhex)rÃ   r   r   r	   Úformat_mtime<  s    
z6MiscReadTestBase.test_extractall.<locals>.format_mtimez,tar mtime {0} != file time {1} of path {2!a})r   r   r   r<   r=   r>   r;   ÚmkdirrÍ   r[   rt   Úplatformr0   r   ÚstatÚst_modeÚgetmtimerÔ   rÃ   r*   r   Úrmtree)	r   r(   ÚDIRÚdirectoriesr4   r=   rÖ   Z
file_mtimeÚerrmsgr   r   r	   Útest_extractall-  s(    


z MiscReadTestBase.test_extractallc          	   C   sª   d}t j td¡}t  |¡ z|tjtddd}| |¡}|j	||d t j ||¡}|  
t j |¡|j¡ tjdkrŒ|  
t  |¡jd@ d¡ W d Q R X W d t |¡ X d S )	Nzustar/dirtypeZ
extractdirz	iso8859-1)r'   )r=   rÑ   iÿ  ií  )r<   r=   r>   r;   r×   r   r   r   r-   r:   r0   rÛ   rÃ   rt   rØ   rÙ   rÚ   r   rÜ   )r   ÚdirtyperÝ   r(   r4   Ú	extractedr   r   r	   Útest_extract_directoryK  s    


&z'MiscReadTestBase.test_extract_directoryc          
   C   sŠ   t  t¡d }t |¡h tjtddN}dd„ |D ƒ}| ||¡ x,|D ]$}||j	 }|  
tj |¡|j¡ qJW W d Q R X W d Q R X d S )NrÍ   z	iso8859-1)r'   c             S   s   g | ]}|  ¡ r|‘qS r   )rÎ   )rÏ   rž   r   r   r	   rÐ   ^  s    zBMiscReadTestBase.test_extractall_pathlike_name.<locals>.<listcomp>)r²   r³   r;   r   Útemp_dirr   r   r   rÍ   r[   r0   r<   r=   rÛ   rÃ   )r   rÝ   r(   rÞ   r4   r=   r   r   r	   Útest_extractall_pathlike_nameZ  s    

z.MiscReadTestBase.test_extractall_pathlike_namec          
   C   s|   d}t  t¡d }t |¡V tjtdd<}| |¡}|j	||d || }|  
tj |¡|j¡ W d Q R X W d Q R X d S )Nzustar/dirtyperÍ   z	iso8859-1)r'   )r=   )r²   r³   r;   r   rä   r   r   r   r-   r:   r0   r<   r=   rÛ   rÃ   )r   rá   rÝ   r(   r4   râ   r   r   r	   Útest_extract_pathlike_named  s    
z+MiscReadTestBase.test_extract_pathlike_namec          	   C   sŽ   t j td¡}t|dƒ}| d¡ W d Q R X zNt tj	¡}y| 
|¡ W n$ tjk
rn   |  |jj¡ Y nX |  d¡ W d t |¡ X d S )NÚemptyr   rL   zReadError not raised)r<   r=   r>   r;   r   r–   ÚobjectÚ__new__r   r   Ú__init__r‰   Ú
assertTruer¢   ÚclosedrY   r   rË   )r   rç   r5   r(   r   r   r	   Útest_init_close_fobjn  s    z%MiscReadTestBase.test_init_close_fobjc          	   C   sX   t  | j¡B}x:t||ƒD ],\}}|  |j|j¡ |  | ¡ | ¡ ¡ qW W d Q R X d S )N)r   r   r   Úzipr0   rº   Zget_info)r   r(   Zm1Zm2r   r   r	   Útest_parallel_iteration  s    z(MiscReadTestBase.test_parallel_iterationN)r   r   r   r¡   r¦   r©   rª   r®   r±   rµ   r¹   r¼   r½   rÀ   rÂ   rÆ   rÈ   ÚunittestÚ
skipUnlessÚhasattrr<   r   Úskip_unless_symlinkrÌ   rà   rã   rå   ræ   rí   rï   r   r   r   r	   r    Ž  s.   		
		

r    c               @   s   e Zd ZdZdS )ÚMiscReadTestN)r   r   r   r½   r   r   r   r	   rô   ‰  s   rô   c               @   s   e Zd ZdS )ÚGzipMiscReadTestN)r   r   r   r   r   r   r	   rõ   Œ  s   rõ   c               @   s   e Zd Zdd„ ZdS )ÚBz2MiscReadTestc             C   s   |   d¡ d S )NzBZ2File have no name attribute)ÚskipTest)r   r   r   r	   r¡     s    z'Bz2MiscReadTest.requires_name_attributeN)r   r   r   r¡   r   r   r   r	   rö     s   rö   c               @   s   e Zd Zdd„ ZdS )ÚLzmaMiscReadTestc             C   s   |   d¡ d S )NzLZMAFile have no name attribute)r÷   )r   r   r   r	   r¡   ”  s    z(LzmaMiscReadTest.requires_name_attributeN)r   r   r   r¡   r   r   r   r	   rø   “  s   rø   c               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚStreamReadTestzr|c          
   C   sr   xl| j D ]b}| ¡ sq| j  |¡B}x:y| d¡}W n  tjk
rT   |  d¡ Y nX |s&P q&W W d Q R X qW d S )Ni   z6simple read-through using TarFile.extractfile() failed)r(   Zisregr.   r/   r   ÚStreamErrorrY   )r   r4   r5   Úbufr   r   r	   Útest_read_throughœ  s    z StreamReadTest.test_read_throughc          	   C   sT   | j  ¡ }| j  |¡}| ¡ }W d Q R X |  t|ƒ|jd¡ |  t|ƒtd¡ d S )Nzregular file extraction failed)	r(   r   r.   r/   r0   r1   r2   r
   r3   )r   r4   r5   r   r   r   r	   r6   ¬  s    
z(StreamReadTest.test_fileobj_regular_filec          	   C   s:   | j  ¡ }| j  |d ¡}|  tj|j¡ W d Q R X d S )Nr   )r(   r~   r.   r   r   rú   r/   )r   Ztarinfosr»   r   r   r	   Útest_provoke_stream_errorµ  s    
z(StreamReadTest.test_provoke_stream_errorc          	   C   sÈ   t jtdd}zª| j}xž| ¡ }| ¡ }|d kr2P |  |d¡ | ¡ sN| ¡ rr|  t j	¡ | 
|¡ W d Q R X q| 
|¡}| 
|¡}|d krq|  |d¡ |  | ¡ | ¡ d¡ qW W d | ¡  X d S )Nz	iso8859-1)r'   zstream.next() failed.zstream.extractfile() failedzstream extraction failed)r   r   r   r(   r   ÚassertIsNotNoneZislnkZissymr   rú   r.   r0   r/   r*   )r   Ztar1Ztar2Zt1Zt2Úv1Úv2r   r   r	   Útest_compare_membersº  s*    

z#StreamReadTest.test_compare_membersN)r   r   r   r   rü   r6   rý   r  r   r   r   r	   rù   ˜  s
   	rù   c               @   s   e Zd ZdS )ÚGzipStreamReadTestN)r   r   r   r   r   r   r	   r  Õ  s   r  c               @   s   e Zd ZdS )ÚBz2StreamReadTestN)r   r   r   r   r   r   r	   r  Ø  s   r  c               @   s   e Zd ZdS )ÚLzmaStreamReadTestN)r   r   r   r   r   r   r	   r  Û  s   r  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚDetectReadTestc          
   C   sJ   yt  ||¡}W n, t jk
r< } z|  ¡  W d d }~X Y n
X | ¡  d S )N)r   r   r‰   rY   r*   )r   r[   r   r(   Úer   r   r	   Ú_testfunc_fileà  s
    zDetectReadTest._testfunc_filec          
   C   sd   y*t |dƒ}tj |||d}W d Q R X W n, tjk
rV } z|  ¡  W d d }~X Y n
X | ¡  d S )NrH   )r¢   )r   r   r‰   rY   r*   )r   r[   r   r»   r(   r  r   r   r	   Ú_testfunc_fileobjè  s    z DetectReadTest._testfunc_fileobjc          	   C   sú   | j r®|  tj¡ tjtd| j  d W d Q R X |  tj¡ tjtd| j  d W d Q R X |  tj¡ tj| jdd W d Q R X |  tj¡ tj| jdd W d Q R X || jdƒ || jd| j  ƒ || jdƒ || jd| j  ƒ || jdƒ d S )Nzr:)r   zr|r7   zr:*zr|*)r   r   r   r‰   r   r   )r   Ztestfuncr   r   r	   Ú_test_modesñ  s    zDetectReadTest._test_modesc             C   s   |   | j¡ d S )N)r	  r  )r   r   r   r	   Útest_detect_file  s    zDetectReadTest.test_detect_filec             C   s   |   | j¡ d S )N)r	  r  )r   r   r   r	   Útest_detect_fileobj  s    z"DetectReadTest.test_detect_fileobjN)r   r   r   r  r  r	  r
  r  r   r   r   r	   r  ß  s
   	r  c               @   s   e Zd ZdS )ÚGzipDetectReadTestN)r   r   r   r   r   r   r	   r    s   r  c               @   s   e Zd Zdd„ ZdS )ÚBz2DetectReadTestc          	   C   sT   t tdƒ}| ¡ }W d Q R X tjtddd}| |¡ W d Q R X |  td¡ d S )NrH   r   rI   )Zcompresslevelzr|*)r   r   r/   r    r"   r†   r–   r  )r   r5   r   r   r   r	   Útest_detect_stream_bz2  s
    z(Bz2DetectReadTest.test_detect_stream_bz2N)r   r   r   r  r   r   r   r	   r  
  s   r  c               @   s   e Zd ZdS )ÚLzmaDetectReadTestN)r   r   r   r   r   r   r	   r    s   r  c               @   s¦   e Zd Zd(dd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdS ))ÚMemberReadTestNc          	   K   s¦   |d k	r<| j  |¡"}|  t| ¡ ƒ|d|j ¡ W d Q R X d|d< d|d< d|d< d|jkrnd	|d
< d	|d< x2| ¡ D ]&\}}|  t||ƒ|d||jf ¡ qxW d S )Nzwrong md5sum for %si½>rÃ   iè  ÚuidrV   Úgidzold-v7r   rÅ   Úgnamezwrong value in %s field of %s)r(   r.   r0   r
   r/   r[   Úitemsr§   )r   r4   ÚchksumÚkwargsr»   ÚkÚvr   r   r	   Ú_test_member  s    
zMemberReadTest._test_memberc             C   s    | j  d¡}| j|dtd d S )Nzustar/regtypeic  )r2   r  )r(   r-   r  r3   )r   r4   r   r   r	   Útest_find_regtype0  s    z MemberReadTest.test_find_regtypec             C   s    | j  d¡}| j|dtd d S )Nzustar/conttypeic  )r2   r  )r(   r-   r  r3   )r   r4   r   r   r	   Útest_find_conttype4  s    z!MemberReadTest.test_find_conttypec             C   s   | j  d¡}| j|dd d S )Nzustar/dirtyper   )r2   )r(   r-   r  )r   r4   r   r   r	   Útest_find_dirtype8  s    z MemberReadTest.test_find_dirtypec             C   s   | j  d¡}| j|dd d S )Nzustar/dirtype-with-sizeéÿ   )r2   )r(   r-   r  )r   r4   r   r   r	   Útest_find_dirtype_with_size<  s    z*MemberReadTest.test_find_dirtype_with_sizec             C   s    | j  d¡}| j|ddd d S )Nzustar/lnktyper   zustar/regtype)r2   Úlinkname)r(   r-   r  )r   r4   r   r   r	   Útest_find_lnktype@  s    z MemberReadTest.test_find_lnktypec             C   s    | j  d¡}| j|ddd d S )Nzustar/symtyper   r\   )r2   r  )r(   r-   r  )r   r4   r   r   r	   Útest_find_symtypeD  s    z MemberReadTest.test_find_symtypec             C   s"   | j  d¡}| j|dddd d S )Nzustar/blktyper   é   )r2   ÚdevmajorÚdevminor)r(   r-   r  )r   r4   r   r   r	   Útest_find_blktypeH  s    z MemberReadTest.test_find_blktypec             C   s"   | j  d¡}| j|dddd d S )Nzustar/chrtyper   rI   r"  )r2   r#  r$  )r(   r-   r  )r   r4   r   r   r	   Útest_find_chrtypeL  s    z MemberReadTest.test_find_chrtypec             C   s   | j  d¡}| j|dd d S )Nzustar/fifotyper   )r2   )r(   r-   r  )r   r4   r   r   r	   Útest_find_fifotypeP  s    z!MemberReadTest.test_find_fifotypec             C   s    | j  d¡}| j|dtd d S )Nzustar/sparsei P )r2   r  )r(   r-   r  Ú
md5_sparse)r   r4   r   r   r	   Útest_find_sparseT  s    zMemberReadTest.test_find_sparsec             C   s    | j  d¡}| j|dtd d S )Nz
gnu/sparsei P )r2   r  )r(   r-   r  r(  )r   r4   r   r   r	   Útest_find_gnusparseX  s    z"MemberReadTest.test_find_gnusparsec             C   s    | j  d¡}| j|dtd d S )Nzgnu/sparse-0.0i P )r2   r  )r(   r-   r  r(  )r   r4   r   r   r	   Útest_find_gnusparse_00\  s    z%MemberReadTest.test_find_gnusparse_00c             C   s    | j  d¡}| j|dtd d S )Nzgnu/sparse-0.1i P )r2   r  )r(   r-   r  r(  )r   r4   r   r   r	   Útest_find_gnusparse_01`  s    z%MemberReadTest.test_find_gnusparse_01c             C   s    | j  d¡}| j|dtd d S )Nzgnu/sparse-1.0i P )r2   r  )r(   r-   r  r(  )r   r4   r   r   r	   Útest_find_gnusparse_10d  s    z%MemberReadTest.test_find_gnusparse_10c             C   s    | j  d¡}| j|dtd d S )Nu   ustar/umlauts-Ã„Ã–ÃœÃ¤Ã¶Ã¼ÃŸic  )r2   r  )r(   r-   r  r3   )r   r4   r   r   r	   Útest_find_umlautsh  s    z MemberReadTest.test_find_umlautsc             C   s   d}|   || j ¡ ¡ d S )Na   ustar/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/12345/1234567/longname)rw   r(   rˆ   )r   r[   r   r   r	   Útest_find_ustar_longnamem  s    z'MemberReadTest.test_find_ustar_longnamec             C   s    | j  d¡}| j|dtd d S )Nzmisc/regtype-old-v7ic  )r2   r  )r(   r-   r  r3   )r   r4   r   r   r	   Útest_find_regtype_oldv7q  s    z&MemberReadTest.test_find_regtype_oldv7c             C   s@   | j  ¡  tj| j| jdd| _ | j  d¡}| j|dtd d S )Nz	iso8859-1)r   r'   u   pax/umlauts-Ã„Ã–ÃœÃ¤Ã¶Ã¼ÃŸic  )r2   r  )	r(   r*   r   r   r   r   r-   r  r3   )r   r4   r   r   r	   Útest_find_pax_umlautsu  s
    

z$MemberReadTest.test_find_pax_umlauts)N)r   r   r   r  r  r  r  r  r   r!  r%  r&  r'  r)  r*  r+  r,  r-  r.  r/  r0  r1  r   r   r   r	   r    s&   
r  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLongnameTestc             C   sX   | j d d d }y| j |¡}W n tk
r@   |  d¡ Y nX |  |jtjd¡ d S )Nú/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/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/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)	Úsubdirr(   r-   rÁ   rY   ÚassertNotEqualr¾   r   r¿   )r   r4  r4   r   r   r	   Útest_read_longname€  s    zLongnameTest.test_read_longnamec             C   sh   | j d d d }| j d d d }y| j |¡}W n tk
rR   |  d¡ Y nX |  |j|d¡ d S )Nr3  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/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/r4  Úlonglinkzlonglink not foundzlinkname wrong)r5  r(   r-   rÁ   rY   r0   r  )r   r4  r8  r4   r   r   r	   Útest_read_longlinkŠ  s    zLongnameTest.test_read_longlinkc          	   C   sp   | j d d d }| j |¡}|j}| jj |¡ t | jj d¡¡}|  	t
j¡ t
jd|d W d Q R X d S )Nr3  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/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/r4  i   zfoo.tar)r[   r¢   )r5  r(   r-   rº   r¢   rM   r   rr   r/   r   r   r‰   r   )r   r4  r4   rº   r5   r   r   r	   Útest_truncated_longname“  s    z$LongnameTest.test_truncated_longnamec          	   C   sj   | j d d d }| j |¡j}ttdƒ6}| |¡ tj 	| 
d¡dd¡}|  |j| j¡ W d Q R X d S )Nr3  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/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/r4  rH   i   z	iso8859-1Ústrict)r5  r(   r-   rº   r   r   rM   r   r—   Zfrombufr/   r0   r¾   Úlongnametype)r   r4  rº   r5   r4   r   r   r	   Útest_header_offsetœ  s    
zLongnameTest.test_header_offsetN)r   r   r   r7  r9  r:  r=  r   r   r   r	   r2  ~  s   
		r2  c               @   sJ   e Zd ZdZejZdd„ Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zedd„ ƒZdS )ÚGNUReadTestZgnuc          	   C   sz   | j  |t¡ tj t|¡}t|dƒ}| ¡ }W d Q R X |  t	|ƒt
d| ¡ |  ¡ rvt |¡}|  |jd |j¡ d S )NrH   zwrong md5sum for %si   )r(   r:   r;   r<   r=   r>   r   r/   r0   r
   r(  Ú_fs_supports_holesrÙ   Z
assertLessÚ	st_blocksÚst_size)r   r[   Úfilenamer5   r   rQ   r   r   r	   Ú_test_sparse_file´  s    

zGNUReadTest._test_sparse_filec             C   s   |   d¡ d S )Nz
gnu/sparse)rC  )r   r   r   r	   Útest_sparse_file_oldÀ  s    z GNUReadTest.test_sparse_file_oldc             C   s   |   d¡ d S )Nzgnu/sparse-0.0)rC  )r   r   r   r	   Útest_sparse_file_00Ã  s    zGNUReadTest.test_sparse_file_00c             C   s   |   d¡ d S )Nzgnu/sparse-0.1)rC  )r   r   r   r	   Útest_sparse_file_01Æ  s    zGNUReadTest.test_sparse_file_01c             C   s   |   d¡ d S )Nzgnu/sparse-1.0)rC  )r   r   r   r	   Útest_sparse_file_10É  s    zGNUReadTest.test_sparse_file_10c           	   C   sx   t j d¡rptj td¡} t| dƒ"}| d¡ | 	d¡ | 
¡  W d Q R X t | ¡}t | ¡ |jd |jk S dS d S )NZlinuxzsparse-testr   i   s   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi   F)rt   rØ   rÄ   r<   r=   r>   r;   r   rM   r–   rœ   rÙ   r   rË   r@  rA  )r[   r5   rQ   r   r   r	   r?  Ì  s    



zGNUReadTest._fs_supports_holesN)r   r   r   r5  r   ÚGNUTYPE_LONGNAMEr<  rC  rD  rE  rF  rG  Ústaticmethodr?  r   r   r   r	   r>  ¨  s   	r>  c               @   s&   e Zd ZdZejZdd„ Zdd„ ZdS )ÚPaxReadTestZpaxc             C   sÐ   t jtdd}z²| d¡}|  |jd¡ |  |jd¡ |  |j d¡d¡ | d¡}|  |jd	¡ |  |jd¡ |  |j d¡d¡ | d
¡}|  |jd¡ |  |jd¡ |  |j d¡d¡ W d | 	¡  X d S )Nz	iso8859-1)r'   zpax/regtype1r”   ÚbarzVENDOR.umlautsu   Ã„Ã–ÃœÃ¤Ã¶Ã¼ÃŸzpax/regtype2r   zpax/regtype3r   )
r   r   r   r-   r0   rÅ   r  Úpax_headersÚgetr*   )r   r(   r4   r   r   r	   Útest_pax_global_headersè  s$    



z#PaxReadTest.test_pax_global_headersc             C   s¢   t jtdd}z„| d¡}|  |jd¡ |  |jd¡ |  |jd¡ |  |jd¡ |  t	|jƒt
¡ |  t
|jd ƒd¡ |  t
|jd ƒd¡ W d | ¡  X d S )	Nz	iso8859-1)r'   zpax/regtype4ic  é{   g  €Ç^ÏAZatimeZctime)r   r   r   r-   r0   r2   r  r  rÃ   r¾   rÓ   rL  r*   )r   r(   r4   r   r   r	   Útest_pax_number_fieldsÿ  s    
z"PaxReadTest.test_pax_number_fieldsN)	r   r   r   r5  r   ÚXHDTYPEr<  rN  rP  r   r   r   r	   rJ  ã  s   rJ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚWriteTestBasec             C   sp   t  ¡ }tj|| jd}| t d¡¡ | ¡  |  |j	d¡ | 
¡ }~t ¡  |  |j	¡ |  || 
¡ ¡ d S )N)r¢   r   r”   z#external fileobjs must never closed)r   rr   r   r   r   r›   r—   r*   ÚassertFalserì   rv   r   Z
gc_collectr0   )r   r5   r(   r   r   r   r	   Útest_fileobj_no_close  s    z#WriteTestBase.test_fileobj_no_closec          	   C   s€   t  t| j¡6}t  d¡}t jt j |_| |t	 
d|j ¡¡ W d Q R X |  td¡ }|  t| ¡ ƒt jd ¡ W d Q R X d S )Nr”   r“   rH   rK   )r   r   r†   r   r—   Ú
RECORDSIZEÚ	BLOCKSIZEr2   r›   r   rr   r0   r1   r/   )r   r(   rž   r5   r   r   r	   Útest_eof_marker   s    
"zWriteTestBase.test_eof_markerN)r   r   r   rT  rW  r   r   r   r	   rR    s   rR  c               @   s°   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	e
 eedƒd¡dd„ ƒZejdd„ ƒZdd„ Zdd„ Zd&dd„Zejdd„ ƒZdd„ Zd d!„ Zd"d#„ Zd$d%„ ZdS )'Ú	WriteTestzw:c             C   sj   d}t  t| j¡}zt  |¡}| |¡ W d | ¡  X t  t¡}z|  | ¡ d |d¡ W d | ¡  X d S )NÚd0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789r   z!failed to store 100 char filename)	r   r   r†   r   r—   r›   r*   r0   rˆ   )r   r[   r(   rž   r   r   r	   Útest_100_char_name2  s    



zWriteTest.test_100_char_namec          	   C   sp   t  t| j¡}z<tj td¡}t|dƒ}| d¡ W d Q R X | 	|¡ W d | 
¡  X |  tj t¡dd¡ d S )NÚfiler   s   aaar   ztarfile is empty)r   r   r†   r   r<   r=   r>   r;   r–   Úaddr*   ZassertGreaterÚgetsize)r   r(   r=   r5   r   r   r	   Útest_tar_sizeF  s    
zWriteTest.test_tar_sizec          	   C   s–   t  t| j¡}zxtj td¡}t|dƒ W d Q R X | |¡}|  	|j
d¡ t|dƒ}| d¡ W d Q R X | |¡}|  	|j
d¡ W d | ¡  X d S )Nr[  r   r   s   aaar"  )r   r   r†   r   r<   r=   r>   r;   Ú
gettarinfor0   r2   r–   r*   )r   r(   r=   r4   r5   r   r   r	   Útest_file_sizeT  s    


zWriteTest.test_file_sizec          	   C   sd   t j td¡}t  |¡ z:t t| j¡}z| 	|¡}|  
|jd¡ W d | ¡  X W d t |¡ X d S )NÚ	directoryr   )r<   r=   r>   r;   r×   r   r   r†   r   r_  r0   r2   r*   r   Úrmdir)r   r=   r(   r4   r   r   r	   Útest_directory_sized  s    

zWriteTest.test_directory_sizec             C   s  t j td¡}t  |¡ tt j |d¡dƒ ¡  tt j |d¡dƒ ¡  zŽt t| j	¡}zpt
j d¡}ddg|_| |¡ W d Q R X g }x(| ¡ D ]}| t j |j¡d ¡ q”W |  |dddg¡ W d | ¡  X W d t t j |d¡¡ t t j |d¡¡ t |¡ X d S )Nra  Ú1r]   Ú2z
os.listdirrÇ   )r<   r=   r>   r;   r×   r   r*   r   r†   r   rð   ÚmockÚpatchÚreturn_valuer\  r~   ÚappendÚsplitr[   r0   r   rË   rb  )r   r=   r(   Zmock_listdirÚpathsÚmr   r   r	   Útest_ordered_recursions  s$    

z WriteTest.test_ordered_recursionc          
   C   s’   t  t| j¡z}t t¡d }t|dƒ}| d¡ W d Q R X | |¡}| t	 
|¡¡}|  |jt¡ |  |j|j¡ |  |jd¡ W d Q R X d S )Nr[  r   s   aaar"  )r   r   r†   r   r²   r³   r;   r–   r_  r<   r´   r£   r[   r¤   r0   r2   )r   r(   r=   r5   r4   Ztarinfo2r   r   r	   Útest_gettarinfo_pathlike_name‰  s    
z'WriteTest.test_gettarinfo_pathlike_namerÉ   zMissing hardlink implementationc          
   C   sÞ   t j td¡}t j td¡}t|dƒ}| d¡ W d Q R X yt  ||¡ W n0 tk
r| } z|  d| ¡ W d d }~X Y nX zDt	 t
| j¡}z&| |¡ | |¡}|  |jd¡ W d | ¡  X W d t |¡ t |¡ X d S )NrÉ   Úlink_targetr   s   aaazos.link(): %sr   )r<   r=   r>   r;   r   r–   rÉ   ÚPermissionErrorr÷   r   r†   r   r_  r0   r2   r*   r   rË   )r   rÉ   Útargetr5   r  r(   r4   r   r   r	   Útest_link_size”  s"     


zWriteTest.test_link_sizec          	   C   sf   t j td¡}t  d|¡ z:t t| j¡}z| 	|¡}|  
|jd¡ W d | ¡  X W d t |¡ X d S )NÚsymlinkro  r   )r<   r=   r>   r;   rs  r   r   r†   r   r_  r0   r2   r*   r   rË   )r   r=   r(   r4   r   r   r	   Útest_symlink_size¬  s    
zWriteTest.test_symlink_sizec          	   C   sŒ   t j t¡}t t| j¡}zb|  |j|d¡ | 	|¡ |  | 
¡ g d¡ t t¡ | 	|¡ W d Q R X |  | 
¡ g d¡ W d | ¡  X d S )Nzarchive name must be absolutezadded the archive to itself)r<   r=   r¥   r†   r   r   r   r0   r[   r\  rˆ   r   Ú
change_cwdr;   r*   )r   Zdstnamer(   r   r   r	   Útest_add_selfº  s    


zWriteTest.test_add_selfc          	   C   s  t j td¡}t  |¡ zæx$dD ]}t j ||¡}t |¡ q W dd„ }tjt	| j
dd}z|j|d|d W d | ¡  X |  t¡ | |dd	d |¡ W d Q R X t t	d
¡}zBx(|D ] }|  |jd¡ |  |jd¡ q¶W |  t| ¡ ƒd¡ W d | ¡  X W d t |¡ X d S )NÚfilter)r”   rK  Zbazc             S   s&   t j | j¡dkrd S d| _d| _| S )NrK  rO  r”   )r<   r=   Úbasenamer[   r  rÅ   )r4   r   r   r	   rw  Ô  s
    z%WriteTest.test_filter.<locals>.filterz	iso8859-1)r'   Z	empty_dir)Úarcnamerw  Tr7   rO  r”   r"  )r<   r=   r>   r;   r×   r   Úcreate_empty_filer   r   r†   r   r\  r*   r   Ú	TypeErrorr0   r  rÅ   r1   r~   rÜ   )r   Útempdirr[   rw  r(   r4   r   r   r	   Útest_filterÌ  s*    



zWriteTest.test_filterNFc             C   s²   t j td¡}|st |¡ n
t  |¡ t t	| j
¡}z|j||d W d | ¡  X t t	d¡}z| ¡ }W d | ¡  X |sˆt |¡ n
t |¡ |  |j|pª| t jd¡¡ d S )Nr”   )ry  r7   r3  )r<   r=   r>   r;   r   rz  r×   r   r   r†   r   r\  r*   r   rË   rb  r0   r[   r‡   Úsep)r   r=   Zcmp_pathÚdirr”   r(   rž   r   r   r	   Ú_test_pathnameô  s     



zWriteTest._test_pathnamec          	   C   s  t j td¡}t j td¡}t  |¡ zÀt j |d¡}t j |d¡}t|dƒ}| d¡ W d Q R X t  ||¡ t |d¡}| 	|¡ | 	|¡ | 
¡  t |d¡}z4y|j|d W n tk
rÔ   |  d	¡ Y nX W d | 
¡  X W d t |¡ t |¡ X d S )
NZtestsymlinksztestsymlinks.tarÚsourcers  r…   z
something
r7   )r=   z&extractall failed with symlinked files)r<   r=   r>   r;   r×   r   r–   rs  r   r\  r*   rÍ   ÚOSErrorrY   r   rË   rÜ   )r   r|  ZtemparchiveZsource_fileZtarget_filer»   r(   r   r   r	   Útest_extractall_symlinks  s*    



z"WriteTest.test_extractall_symlinksc             C   s<  |   d¡ |   tj ddd¡¡ |   tj ddd¡¡ |   tj dd¡¡ |   tj ddd¡¡ |   tj dddd¡¡ |   tj dddd¡¡ |   tj dddd¡¡ |   tj dd¡¡ |   tj ddd¡¡ |   tj dddd¡¡ |   tj dddd¡¡ |   dtj tj d ¡ | j dtj tj ddd d S )Nr”   Ú.rK  z..T)r  )r€  r<   r=   r>   r~  )r   r   r   r	   Útest_pathnames.  s    
zWriteTest.test_pathnamesc             C   s4   t jdkr|  dd¡ n|  dd¡ |  dd¡ d S )NrÑ   zC:\foor”   z/fooz///foo)rt   rØ   r€  )r   r   r   r	   Útest_abs_pathnames?  s    
zWriteTest.test_abs_pathnamesc          	   C   sŒ   t  t¡x t t| j¡}z| d¡ W d | ¡  X t td¡}z2x,|D ]$}|j	dkrH|  
|j	 d¡|j	¡ qHW W d | ¡  X W d Q R X d S )Nr„  r7   z./)r   ru  r;   r   r   r†   r   r\  r*   r[   rë   rÄ   )r   r(   rž   r   r   r	   Útest_cwdF  s    


zWriteTest.test_cwdc          
      sr   xlt ttfD ]^‰ G ‡ fdd„dtjƒ}|ƒ }|  ˆ ¡" tjt| j	|tj
ddid}W d Q R X |  |j¡ qW d S )Nc                   s   e Zd ZdZ‡ fdd„ZdS )z8WriteTest.test_open_nonwritable_fileobj.<locals>.BadFileTc                s   | j rd| _ ˆ ‚d S )NF)Úfirst)r   r   )Úexctyper   r	   r–   [  s    z>WriteTest.test_open_nonwritable_fileobj.<locals>.BadFile.writeN)r   r   r   rˆ  r–   r   )r‰  r   r	   ÚBadFileY  s   rŠ  Znonrç   )r¢   rÔ   rL  )r‚  ÚEOFErrorÚRuntimeErrorr   rr   r   r   r   r†   r   Ú
PAX_FORMATrS  rì   )r   rŠ  r»   r(   r   )r‰  r	   Útest_open_nonwritable_fileobjW  s    z'WriteTest.test_open_nonwritable_fileobj)NF)r   r   r   r   rZ  r^  r`  rc  rm  rn  rð   rñ   rò   r<   rr  r   ró   rt  rv  r}  r€  rƒ  r…  r†  r‡  rŽ  r   r   r   r	   rX  .  s$   (
rX  c               @   s   e Zd ZdS )ÚGzipWriteTestN)r   r   r   r   r   r   r	   r  g  s   r  c               @   s   e Zd ZdS )ÚBz2WriteTestN)r   r   r   r   r   r   r	   r  j  s   r  c               @   s   e Zd ZdS )ÚLzmaWriteTestN)r   r   r   r   r   r   r	   r‘  m  s   r‘  c               @   s@   e Zd ZdZdZdd„ Ze ej	dko.e
edƒd¡dd	„ ƒZdS )
ÚStreamWriteTestzw|Nc          	   C   s”   t  t| j¡}| ¡  | jr\|  ¡ }ttdƒ}| ¡ }W d Q R X | |¡}|  |j	d¡ n|  t¡}| ¡ }W d Q R X |  
| d¡t jd¡ d S )NrH   zfound trailing datar’   zincorrect zero padding)r   r   r†   r   r*   Údecompressorr/   Z
decompressrS  Zunused_datar0   ÚcountrU  )r   r(   Zdecr5   r   r   r   r	   Útest_stream_paddingv  s    
z#StreamWriteTest.test_stream_paddingrÑ   ÚumaskzMissing umask implementationc          	   C   sj   t j t¡rt t¡ t  d¡}z8t t| j	¡}| 
¡  t  t¡jd@ }|  |dd¡ W d t  |¡ X d S )Né   iÿ  i¤  zwrong file permissions)r<   r=   Úexistsr†   r   rË   r–  r   r   r   r*   rÙ   rÚ   r0   )r   Zoriginal_umaskr(   r   r   r   r	   Útest_file_mode†  s    

zStreamWriteTest.test_file_mode)r   r   r   r   r“  r•  rð   rñ   rt   rØ   rò   r<   r™  r   r   r   r	   r’  q  s
   r’  c               @   s   e Zd ZdS )ÚGzipStreamWriteTestN)r   r   r   r   r   r   r	   rš  —  s   rš  c               @   s   e Zd ZerejndZdS )ÚBz2StreamWriteTestN)r   r   r   r    ZBZ2Decompressorr“  r   r   r   r	   r›  š  s   r›  c               @   s   e Zd ZerejndZdS )ÚLzmaStreamWriteTestN)r   r   r   r%   ZLZMADecompressorr“  r   r   r   r	   rœ    s   rœ  c               @   sp   e Zd Zdd„ Zddd„Zddd„Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚGNUWriteTestc             C   s   t |ƒd d }|d S )Ni   rI   )r1   )r   rQ   Zblocksr   r   r	   Ú_length¥  s    zGNUWriteTest._lengthNc             C   sX   d}t |ƒtjkr(|d7 }||  |¡7 }|d k	rTt |ƒtjkrT|d7 }||  |¡7 }|S )Ni   )r1   r   ÚLENGTH_NAMErž  ÚLENGTH_LINK)r   r[   rÉ   r”  r   r   r	   Ú
_calc_size©  s    zGNUWriteTest._calc_sizec             C   sÀ   t  |¡}|r||_t j|_t  td¡}z6t j|_| 	|¡ |  
||¡}|j}|  ||d¡ W d | ¡  X t  t¡}z<| ¡ }|  |d¡ |  |j|jd¡ |  |j|jd¡ W d | ¡  X d S )Nr…   z%GNU longname/longlink creation failedzunable to read longname member)r   r—   r  ÚLNKTYPEr¾   r   r†   Ú
GNU_FORMATrÔ   r›   r¡  rº   r0   r*   r   rþ   r[   )r   r[   rÉ   r4   r(   rÿ   r   Úmemberr   r   r	   Ú_test·  s,    




zGNUWriteTest._testc             C   s   |   d¡ d S )Naÿ  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam)r¥  )r   r   r   r	   Útest_longname_1023Ô  s    zGNUWriteTest.test_longname_1023c             C   s   |   d¡ d S )Na   longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longname)r¥  )r   r   r   r	   Útest_longname_1024×  s    zGNUWriteTest.test_longname_1024c             C   s   |   d¡ d S )Na  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longname_)r¥  )r   r   r   r	   Útest_longname_1025Ú  s    zGNUWriteTest.test_longname_1025c             C   s   |   dd¡ d S )Nr[   aÿ  longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk)r¥  )r   r   r   r	   Útest_longlink_1023Ý  s    zGNUWriteTest.test_longlink_1023c             C   s   |   dd¡ d S )Nr[   a   longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink)r¥  )r   r   r   r	   Útest_longlink_1024à  s    zGNUWriteTest.test_longlink_1024c             C   s   |   dd¡ d S )Nr[   a  longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink_)r¥  )r   r   r   r	   Útest_longlink_1025ã  s    zGNUWriteTest.test_longlink_1025c             C   s   |   dd¡ d S )Naÿ  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnamaÿ  longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk)r¥  )r   r   r   r	   Útest_longnamelink_1023æ  s    z#GNUWriteTest.test_longnamelink_1023c             C   s   |   dd¡ d S )Na   longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnamea   longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink)r¥  )r   r   r   r	   Útest_longnamelink_1024ê  s    z#GNUWriteTest.test_longnamelink_1024c             C   s   |   dd¡ d S )Na  longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/longnam/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_a  longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlnk/longlink_)r¥  )r   r   r   r	   Útest_longnamelink_1025î  s    z#GNUWriteTest.test_longnamelink_1025)N)N)r   r   r   rž  r¡  r¥  r¦  r§  r¨  r©  rª  r«  r¬  r­  r®  r   r   r   r	   r  ¡  s   

r  c               @   sn   e Zd ZdZej ed¡Zdd„ Z	e
dd„ ƒZe
dd„ ƒZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú
CreateTestzx:Ú
spameggs42c             C   s   t  t¡ d S )N)r   rË   r†   )r   r   r   r	   r)   ù  s    zCreateTest.setUpc          	   C   s&   t | jdƒ}| d¡ W d Q R X d S )Nr   s   aaa)r   Ú	file_pathr–   )Úclsr5   r   r   r	   Ú
setUpClassü  s    zCreateTest.setUpClassc             C   s   t  | j¡ d S )N)r   rË   r±  )r²  r   r   r	   ÚtearDownClass  s    zCreateTest.tearDownClassc          	   C   sh   t  t| j¡}| | j¡ W d Q R X |  t¡}| ¡ }W d Q R X |  t	|ƒd¡ |  
d|d ¡ d S )NrI   r°  r   )r   r   r†   r   r\  r±  r   rˆ   r0   r1   rw   )r   ÚtobjÚnamesr   r   r	   Útest_create  s    zCreateTest.test_createc          	   C   sŒ   t  t| j¡}| | j¡ W d Q R X |  t¡ t  t| j¡}W d Q R X |  t¡}| 	¡ }W d Q R X |  
t|ƒd¡ |  d|d ¡ d S )NrI   r°  r   )r   r   r†   r   r\  r±  r   ÚFileExistsErrorr   rˆ   r0   r1   rw   )r   rµ  r¶  r   r   r	   Útest_create_existing  s    zCreateTest.test_create_existingc          	   C   sf   |   td¡}| | j¡ W d Q R X |   t¡}| ¡ }W d Q R X |  t|ƒd¡ |  d|d ¡ d S )NÚxrI   r°  r   )r   r†   r\  r±  rˆ   r0   r1   rw   )r   rµ  r¶  r   r   r	   Útest_create_taropen  s    zCreateTest.test_create_taropenc          
   C   s”   |   td¡}| | j¡ W d Q R X |  t¡ |   td¡ W d Q R X W d Q R X |   t¡}| ¡ }W d Q R X |  t|ƒd¡ |  	d|d ¡ d S )Nrº  rI   r°  r   )
r   r†   r\  r±  r   r¸  rˆ   r0   r1   rw   )r   rµ  r¶  r   r   r	   Útest_create_existing_taropen#  s    z'CreateTest.test_create_existing_taropenc          	   C   sÀ   t  t t¡| j¡D}|  |jt¡ |  	|jt
j t¡¡ | t | j¡¡ | ¡ }W d Q R X |  	t|ƒd¡ |  d|d ¡ |  t¡}| ¡ }W d Q R X |  	t|ƒd¡ |  d|d ¡ d S )NrI   r°  r   )r   r   r²   r³   r†   r   r£   r[   r¤   r0   r<   r=   r¥   r\  r±  rˆ   r1   rw   r   )r   rµ  r¶  r   r   r	   Útest_create_pathlike_name0  s    z$CreateTest.test_create_pathlike_namec          	   C   s¾   |   t t¡d¡D}|  |jt¡ |  |jtj	 
t¡¡ | t | j¡¡ | ¡ }W d Q R X |  t|ƒd¡ |  d|d ¡ |   t¡}| ¡ }W d Q R X |  t|ƒd¡ |  d|d ¡ d S )Nrº  rI   r°  r   )r   r²   r³   r†   r£   r[   r¤   r0   r<   r=   r¥   r\  r±  rˆ   r1   rw   )r   rµ  r¶  r   r   r	   Ú!test_create_taropen_pathlike_name>  s    z,CreateTest.test_create_taropen_pathlike_nameN)r   r   r   r   r<   r=   r>   r;   r±  r)   Úclassmethodr³  r´  r·  r¹  r»  r¼  r½  r¾  r   r   r   r	   r¯  ó  s   		r¯  c               @   s   e Zd ZdS )ÚGzipCreateTestN)r   r   r   r   r   r   r	   rÀ  M  s   rÀ  c               @   s   e Zd ZdS )ÚBz2CreateTestN)r   r   r   r   r   r   r	   rÁ  Q  s   rÁ  c               @   s   e Zd ZdS )ÚLzmaCreateTestN)r   r   r   r   r   r   r	   rÂ  U  s   rÂ  c               @   s   e Zd ZdZdZdZdS )ÚCreateWithXModeTestrº  N)r   r   r   r   r»  r¼  r   r   r   r	   rÃ  Y  s   rÃ  rÉ   zMissing hardlink implementationc               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚHardlinkTestc          
   C   s¨   t j td¡| _t j td¡| _t| jdƒ}| d¡ W d Q R X yt  | j| j¡ W n0 t	k
r† } z|  
d| ¡ W d d }~X Y nX t td¡| _| j | j¡ d S )Nr”   rK  r   s   foozos.link(): %sr…   )r<   r=   r>   r;   r”   rK  r   r–   rÉ   rp  r÷   r   r†   r(   r\  )r   r5   r  r   r   r	   r)   e  s     zHardlinkTest.setUpc             C   s&   | j  ¡  t | j¡ t | j¡ d S )N)r(   r*   r   rË   r”   rK  )r   r   r   r	   r+   t  s    
zHardlinkTest.tearDownc             C   s$   | j  | j¡}|  |jtjd¡ d S )Nzadd file as regular failed)r(   r_  r”   r0   r¾   r   ÚREGTYPE)r   r4   r   r   r	   Útest_add_twicey  s    zHardlinkTest.test_add_twicec             C   s$   | j  | j¡}|  |jtjd¡ d S )Nzadd file as hardlink failed)r(   r_  rK  r0   r¾   r   r¢  )r   r4   r   r   r	   Útest_add_hardlink€  s    zHardlinkTest.test_add_hardlinkc             C   s,   d| j _| j  | j¡}|  |jtjd¡ d S )NTzdereferencing hardlink failed)r(   Zdereferencer_  rK  r0   r¾   r   rÅ  )r   r4   r   r   r	   Útest_dereference_hardlink…  s    z&HardlinkTest.test_dereference_hardlinkN)r   r   r   r)   r+   rÆ  rÇ  rÈ  r   r   r   r	   rÄ  a  s
   rÄ  c               @   s&   e Zd Zddd„Zdd„ Zdd„ ZdS )	ÚPaxWriteTestNc             C   s¤   t  |¡}|r||_t j|_t jtdt jd}z| |¡ W d | 	¡  X t  t¡}zB|rv| 
¡ d j}|  ||d¡ n| 
¡ d j}|  ||d¡ W d | 	¡  X d S )Nr…   )rÔ   r   zPAX longlink creation failedzPAX longname creation failed)r   r—   r  r¢  r¾   r   r†   r  r›   r*   r~   r0   r[   )r   r[   rÉ   r4   r(   ÚlÚnr   r   r	   r¥  Ž  s     


zPaxWriteTest._testc          
   C   s  ddddddœ}t jtdt j|d}z| t  d¡¡ W d | ¡  X t jtd	d
}z |  |j|¡ |  | 	¡ d j|¡ xv|j 
¡ D ]h\}}|  t|ƒt¡ |  t|ƒt¡ |t jkr„yt j| |ƒ W q„ ttfk
rê   |  d¡ Y q„X q„W W d | ¡  X d S )NrK  Ú0z1.23u   Ã¤Ã¶Ã¼Útest)r”   r  rÃ   rÍ  u   Ã¤Ã¶Ã¼r…   )rÔ   rL  z	iso8859-1)r'   r   z"unable to convert pax header field)r   r   r†   r  r›   r—   r*   r0   rL  r~   r  ZassertIsNotr¾   r°   ÚPAX_NUMBER_FIELDSr{  r¸   rY   )r   rL  r(   ÚkeyÚvalr   r   r	   Útest_pax_global_header¦  s.    

z#PaxWriteTest.test_pax_global_headerc             C   sª   dddœ}t jtdt jdd}z(t  ¡ }d|_d|_||_| |¡ W d | 	¡  X t jtdd	}z:| 
¡ d
 }|  |j|¡ |  |jd¡ |  |jd¡ W d | 	¡  X d S )Nr”   Z123)r=   r  r…   z	iso8859-1)rÔ   r'   u   Ã¤Ã¶Ã¼i   )r'   r   rO  )r   r   r†   r  r—   r[   r  rL  r›   r*   r~   r0   )r   rL  r(   rž   r   r   r	   Útest_pax_extended_headerÆ  s"    

z%PaxWriteTest.test_pax_extended_header)N)r   r   r   r¥  rÑ  rÒ  r   r   r   r	   rÉ  Œ  s   
 rÉ  c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚUnicodeTestc             C   s   |   d¡ d S )Nz	iso8859-1)Ú_test_unicode_filename)r   r   r   r	   Útest_iso8859_1_filenameâ  s    z#UnicodeTest.test_iso8859_1_filenamec             C   s   |   d¡ d S )NÚutf7)rÔ  )r   r   r   r	   Útest_utf7_filenameå  s    zUnicodeTest.test_utf7_filenamec             C   s   |   d¡ d S )Nzutf-8)rÔ  )r   r   r   r	   Útest_utf8_filenameè  s    zUnicodeTest.test_utf8_filenamec             C   sr   t jtd| j|dd}zd}| t  |¡¡ W d | ¡  X t jt|d}z|  | ¡ d j	|¡ W d | ¡  X d S )Nr…   r;  )rÔ   r'   Úerrorsu   Ã¤Ã¶Ã¼)r'   r   )
r   r   r†   rÔ   r›   r—   r*   r0   r~   r[   )r   r'   r(   r[   r   r   r	   rÔ  ë  s    

z"UnicodeTest._test_unicode_filenamec             C   sd   t jtd| jddd}z>t  ¡ }d|_|  t|j|¡ d|_d|_	|  t|j|¡ W d | 
¡  X d S )Nr…   ri   r;  )rÔ   r'   rÙ  u   Ã¤Ã¶Ã¼r”   )r   r   r†   rÔ   r—   r[   r   ÚUnicodeErrorr›   rÅ   r*   )r   r(   r4   r   r   r	   Útest_unicode_filename_errorú  s    
z'UnicodeTest.test_unicode_filename_errorc             C   s|   t jtdddd}zZxT|D ]L}|  t|jƒt¡ |  t|jƒt¡ |  t|jƒt¡ |  t|j	ƒt¡ qW W d | 
¡  X d S )Nr7   z	iso8859-1r;  )r'   rÙ  )r   r   r   ZassertIsr¾   r[   r¤   r  rÅ   r  r*   )r   r(   rž   r   r   r	   Útest_unicode_argument	  s    

z!UnicodeTest.test_unicode_argumentc             C   sÔ   t  d¡}d|_d|_t jtd| jdd}z| |¡ W d | ¡  X t jtdd}zr| 	d¡}|  
|jd¡ |  
|jd¡ | jt jkrÂ| ¡  t jtdd}| 	d¡}|  
|jd¡ |  
|jd¡ W d | ¡  X d S )	Nr”   u   Ã¤Ã¶Ã¼r…   z	iso8859-1)r   rÔ   r'   )r'   ri   u	   í³¤í³¶í³¼)r   r—   rÅ   r  r   r†   rÔ   r›   r*   r-   r0   r  )r   rž   r(   r   r   r	   Útest_uname_unicode  s(    



zUnicodeTest.test_uname_unicodeN)
r   r   r   rÕ  r×  rØ  rÔ  rÛ  rÜ  rÝ  r   r   r   r	   rÓ  à  s   rÓ  c               @   sf   e Zd ZejZdd„ Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zddd„Zdd„ Zdd„ Zddd„ZdS )ÚUstarUnicodeTestc             C   s0   |   d¡ |   dt¡ |   d¡ |   dt¡ d S )NrY  Úe01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890ud   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567Ã¿ue   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678Ã¿)Ú_test_ustar_namer¸   )r   r   r   r	   Útest_unicode_name18  s    

z#UstarUnicodeTest.test_unicode_name1c             C   s   |   d¡ |   dt¡ d S )Nud   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345Ã¿Ã¿ue   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456Ã¿Ã¿)rà  r¸   )r   r   r   r	   Útest_unicode_name2>  s    
z#UstarUnicodeTest.test_unicode_name2c             C   s0   |   d¡ |   dt¡ |   d¡ |   dt¡ d S )Na   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789a   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123/40123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012Ã¿/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123Ã¿/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789)rà  r¸   )r   r   r   r	   Útest_unicode_longname1D  s    

z'UstarUnicodeTest.test_unicode_longname1c             C   s   |   dt¡ |   dt¡ d S )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901Ã¿/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901Ã¿Ã¿/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789)rà  r¸   )r   r   r   r	   Útest_unicode_longname2J  s    z'UstarUnicodeTest.test_unicode_longname2c             C   s&   |   dt¡ |   d¡ |   dt¡ d S )Nu  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901Ã¿Ã¿/20123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789u   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567Ã¿u  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678Ã¿)rà  r¸   )r   r   r   r	   Útest_unicode_longname3N  s    
z'UstarUnicodeTest.test_unicode_longname3c             C   s   |   d¡ |   dt¡ d S )Nu   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345Ã¿Ã¿u  01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234/0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456Ã¿Ã¿)rà  r¸   )r   r   r   r	   Útest_unicode_longname4S  s    
z'UstarUnicodeTest.test_unicode_longname4Nc          	   C   s”   t jtd| jdd4}t  |¡}|d kr4| |¡ n|  ||j|¡ W d Q R X |d krt jtddd$}x|D ]}|  ||j¡ P qnW W d Q R X d S )Nr…   zutf-8)rÔ   r'   r7   )r'   )	r   r   r†   rÔ   r—   r›   r   r0   r[   )r   r[   Úexcr(   rž   r   r   r	   rà  W  s    

z!UstarUnicodeTest._test_ustar_namec             C   s0   |   d¡ |   dt¡ |   d¡ |   dt¡ d S )NrY  rß  ud   01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567Ã¿ue   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678Ã¿)Ú_test_ustar_linkr¸   )r   r   r   r	   Útest_unicode_link1f  s    

z#UstarUnicodeTest.test_unicode_link1c             C   s   |   d¡ |   dt¡ d S )Nud   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345Ã¿Ã¿ue   0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456Ã¿Ã¿)rè  r¸   )r   r   r   r	   Útest_unicode_link2l  s    
z#UstarUnicodeTest.test_unicode_link2c          	   C   sš   t jtd| jdd:}t  d¡}||_|d kr:| |¡ n|  ||j|¡ W d Q R X |d kr–t jtddd$}x|D ]}|  ||j¡ P qtW W d Q R X d S )Nr…   zutf-8)rÔ   r'   r”   r7   )r'   )	r   r   r†   rÔ   r—   r  r›   r   r0   )r   r[   rç  r(   rž   r   r   r	   rè  p  s    

z!UstarUnicodeTest._test_ustar_link)N)N)r   r   r   r   ÚUSTAR_FORMATrÔ   rá  râ  rã  rä  rå  ræ  rà  ré  rê  rè  r   r   r   r	   rÞ  1  s   
rÞ  c               @   s   e Zd ZejZdd„ ZdS )ÚGNUUnicodeTestc          
   C   s`   xZdD ]R\}}t jt|dd4}y| |¡}W n tk
rL   |  d¡ Y nX W d Q R X qW d S )N))zutf-8u   pax/bad-pax-í³¤í³¶í³¼)z	iso8859-1u   pax/bad-pax-Ã¤Ã¶Ã¼rn   )r'   rÙ  z%unable to read bad GNU tar pax header)r   r   r   r-   rÁ   rY   )r   r'   r[   r(   rž   r   r   r	   Útest_bad_pax_header„  s    
z"GNUUnicodeTest.test_bad_pax_headerN)r   r   r   r   r£  rÔ   rí  r   r   r   r	   rì  €  s   rì  c               @   s   e Zd ZejZdZdd„ ZdS )ÚPAXUnicodeTestNc          
   C   s`   xZdD ]R\}}t jt|dd4}y| |¡}W n tk
rL   |  d¡ Y nX W d Q R X qW d S )N))zutf-8u   pax/hdrcharset-í³¤í³¶í³¼)z	iso8859-1u   pax/hdrcharset-Ã¤Ã¶Ã¼rn   )r'   rÙ  z)unable to read POSIX.1-2008 binary header)r   r   r   r-   rÁ   rY   )r   r'   r[   r(   rž   r   r   r	   Útest_binary_header™  s    
z!PAXUnicodeTest.test_binary_header)r   r   r   r   r  rÔ   rÛ  rï  r   r   r   r	   rî  ’  s   rî  c               @   s&   e Zd Zdd„ Zd	dd„Zdd„ ZdS )
ÚAppendTestBasec             C   s$   t | _tj | j¡r t | j¡ d S )N)r†   r   r<   r=   r˜  r   rË   )r   r   r   r	   r)   ©  s    zAppendTestBase.setUpúw:c             C   sj   t jtddR}| d¡}d|_| |¡,}t  | j|¡}| ||¡ W d Q R X W d Q R X W d Q R X d S )Nz	iso8859-1)r'   zustar/regtyper”   )r   r   r   r-   r[   r.   r›   )r   r   Úsrcrž   r»   r(   r   r   r	   Ú_create_testtar®  s    
zAppendTestBase._create_testtarc             C   s(   |   d| j ¡ |  tjtjtd¡ d S )Nzw:r]   )ró  r   r   r   r‰   r   r†   )r   r   r   r	   Útest_append_compressed¶  s    z%AppendTestBase.test_append_compressedN)rñ  )r   r   r   r)   ró  rô  r   r   r   r	   rð  ¦  s   
rð  c               @   s‚   e Zd ZdZddd„Zdgdfdd„Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )Ú
AppendTestNc          	   C   s2   t j| jd|d}| t  d¡¡ W d Q R X d S )Nr]   )r¢   rK  )r   r   r   r›   r—   )r   r¢   r(   r   r   r	   Ú_add_testfile½  s    zAppendTest._add_testfilerK  c          	   C   s0   t j| j|d}|  | ¡ |¡ W d Q R X d S )N)r¢   )r   r   r   r0   rˆ   )r   r¶  r¢   r(   r   r   r	   r¥  Á  s    zAppendTest._testc             C   s   |   ¡  |  ¡  d S )N)rö  r¥  )r   r   r   r	   Útest_non_existingÅ  s    zAppendTest.test_non_existingc             C   s&   t  | jd¡ ¡  |  ¡  |  ¡  d S )Nzw:)r   r   r   r*   rö  r¥  )r   r   r   r	   Ú
test_emptyÉ  s    zAppendTest.test_emptyc             C   s.   t  d¡}|  |¡ | d¡ | j|d d S )Ns                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   r   )r¢   )r   rr   rö  rM   r¥  )r   r5   r   r   r	   Útest_empty_fileobjÎ  s    


zAppendTest.test_empty_fileobjc          	   C   s\   |   ¡  t| jdƒ}| ¡ }W d Q R X t |¡}|  |¡ | d¡ | jddg|d d S )NrH   r   r”   rK  )r¶  r¢   )	ró  r   r   r/   r   rr   rö  rM   r¥  )r   r5   r   r   r   r	   Útest_fileobjÔ  s    


zAppendTest.test_fileobjc             C   s$   |   ¡  |  ¡  | jddgd d S )Nr”   rK  )r¶  )ró  rö  r¥  )r   r   r   r	   Útest_existingÝ  s    zAppendTest.test_existingc          	   C   s6   t | jdƒ}| |¡ W d Q R X |  tj| j¡ d S )Nr   )r   r   r–   r   r   r‰   rö  )r   r   r5   r   r   r	   Ú_test_errorä  s    zAppendTest._test_errorc             C   s   |   d¡ d S )NrL   )rü  )r   r   r   r	   Ú	test_nullé  s    zAppendTest.test_nullc             C   s   |   d¡ d S )Ns                )rü  )r   r   r   r	   Útest_incompleteì  s    zAppendTest.test_incompletec             C   s   t  d¡ ¡ }|  |¡ d S )Nr”   )r   r—   r˜   rü  )r   r   r   r   r	   Útest_premature_eofï  s    zAppendTest.test_premature_eofc             C   s    t  d¡ ¡ }|  |d ¡ d S )Nr”   s                )r   r—   r˜   rü  )r   r   r   r   r	   Útest_trailing_garbageó  s    z AppendTest.test_trailing_garbagec             C   s   |   d¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rü  )r   r   r   r	   Útest_invalid÷  s    zAppendTest.test_invalid)N)r   r   r   rô  rö  r¥  r÷  rø  rù  rú  rû  rü  rý  rþ  rÿ  r   r  r   r   r   r	   rõ  º  s   
	rõ  c               @   s   e Zd ZdS )ÚGzipAppendTestN)r   r   r   r   r   r   r	   r  ú  s   r  c               @   s   e Zd ZdS )ÚBz2AppendTestN)r   r   r   r   r   r   r	   r  ý  s   r  c               @   s   e Zd ZdS )ÚLzmaAppendTestN)r   r   r   r   r   r   r	   r     s   r  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú
LimitsTestc             C   sÈ   t  d¡}| t j¡ t  d¡}|  t|jt j¡ t  d¡}| t j¡ t  d¡}|  t|jt j¡ t  d¡}|  t|jt j¡ t  d¡}d|_|  t|jt j¡ t  d¡}d|_|  t|jt j¡ d S )	NrY  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/longnamea   123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamer8  r[   i    )r   r—   r˜   rë  r   r¸   r  r  )r   r4   r   r   r	   Útest_ustar_limits  s     






zLimitsTest.test_ustar_limitsc             C   sX   t  d¡}| t j¡ t  d¡}d|_| t j¡ t  d¡}d|_|  t|jt j¡ d S )Na   123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamer8  r[   l          )r   r—   r˜   r£  r  r  r   r¸   )r   r4   r   r   r	   Útest_gnu_limits%  s    


zLimitsTest.test_gnu_limitsc             C   sR   t  d¡}| t j¡ t  d¡}d|_| t j¡ t  d¡}d|_| t j¡ d S )Na   123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/123/longnamer8  r[   l          )r   r—   r˜   r  r  r  )r   r4   r   r   r	   Útest_pax_limits2  s    


zLimitsTest.test_pax_limitsN)r   r   r   r  r  r  r   r   r   r	   r    s   r  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚMiscTestc             C   s`   |   t dddd¡d¡ |   t dddd¡d¡ |   t ddd¡d¡ |   t d	dd¡d¡ d S )
Nr”   é   ri   r;  s   foo     Zfoobarr"  s   foos   foo bar )r0   r   ÚstnÚnts)r   r   r   r	   Útest_char_fieldsA  s    zMiscTest.test_char_fieldsc             C   s¦   |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d	¡d
¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ d S )Ns   0000001 rI   s   7777777 iÿÿ s   €       i    s   €   ÿÿÿÿl   ÿÿ s   ÿÿÿÿÿÿÿÿrÇ   s   ÿÿÿÿÿÿÿœiœÿÿÿs   ÿ       lüÿÿÿ       r’   r   s           )r0   r   Únti)r   r   r   r	   Útest_read_number_fieldsK  s    z MiscTest.test_read_number_fieldsc             C   sÐ   |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d¡d¡ |   t d	¡d
¡ |   t d¡d¡ |   t d¡d¡ |   tjdtjdd¡ |   tjdtjdd¡ |   t tjdtjd¡d¡ d S )NrI   s   0000001 iÿÿ s   7777777 i    s   €       l   ÿÿ s   €   ÿÿÿÿrÇ   s   ÿÿÿÿÿÿÿÿiœÿÿÿs   ÿÿÿÿÿÿÿœlüÿÿÿ       s   ÿ       g      YÀ)rÔ   g      0Bs   €      gš™™™™™¹¿r   )r0   r   Úitnr£  r  )r   r   r   r	   Útest_write_number_fields_  s"    z!MiscTest.test_write_number_fieldsc          	   C   sœ   |   t¡ t ddtj¡ W d Q R X |   t¡ t ddtj¡ W d Q R X |   t¡ t ddtj¡ W d Q R X |   t¡ t ddtj¡ W d Q R X d S )NrÇ   r
  i    lýÿÿÿ    é   l        )r   r¸   r   r  rë  r£  )r   r   r   r	   Útest_number_field_limitsu  s    z!MiscTest.test_number_field_limitsc          /   C   sv   ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/h/}t j| t|d0 d S )1NÚversionÚgrpÚpwdZsymlink_exceptionZNULrV  rU  Z	GNU_MAGICZPOSIX_MAGICrŸ  r   ZLENGTH_PREFIXrÅ  ZAREGTYPEr¢  ZSYMTYPEZCHRTYPEZBLKTYPEr¿   ZFIFOTYPEZCONTTYPErH  ZGNUTYPE_LONGLINKZGNUTYPE_SPARSErQ  ZXGLTYPEZSOLARIS_XHDTYPEZSUPPORTED_TYPESZREGULAR_TYPESZ	GNU_TYPESZ
PAX_FIELDSZPAX_NAME_FIELDSrÎ  r  r  r  r  Zcalc_chksumsZcopyfileobjÚfilemodeZEmptyHeaderErrorZTruncatedHeaderErrorZEOFHeaderErrorZInvalidHeaderErrorZSubsequentHeaderErrorZExFileObjectÚmain)Ú	blacklist)r   Zcheck__all__r   )r   r  r   r   r	   Útest__all__  s     
zMiscTest.test__all__N)r   r   r   r  r  r  r  r  r   r   r   r	   r	  ?  s
   

r	  c               @   s¤   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'S )(ÚCommandLineTestc             O   s(   t jd|ž|Ž\}}}| tj ¡ d¡S )Nú-mr   ó   
)r  r   )r   Zassert_python_okr‡   r<   ÚlineseprW   )r   Úargsr  Úrcr{   Úerrr   r   r	   Ú
tarfilecmd”  s    
zCommandLineTest.tarfilecmdc             G   s   t jd|žŽ S )Nú-mr   )r#  r   )r   Zassert_python_failure)r   r  r   r   r	   Útarfilecmd_failure™  s    z"CommandLineTest.tarfilecmd_failurec          	   C   sb   t  d¡t  d¡g}|  t j|¡ t |d¡*}x"|D ]}|j|tj 	|¡d q6W W d Q R X d S )Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr…   )ry  )
r   ÚfindfilerÊ   rË   r   r   r\  r<   r=   rx  )r   Útar_nameÚfilesÚtfZtardatar   r   r	   Úmake_simple_tarfileœ  s    
z#CommandLineTest.make_simple_tarfilec             C   s|   |   ¡ \}}}|  |d¡ |  d| ¡ ¡ |  d| ¡ ¡ |  d| ¡ ¡ |   dd¡\}}}|  |d¡ |  | ¡ d¡ d S )NrL   s   usages   errors   requiredz-lr   )r$  r0   rw   Úlowerr6  Ústrip)r   r   r{   r!  r   r   r	   Útest_bad_use¥  s    zCommandLineTest.test_bad_usec             C   s8   x2t D ]*}x$dD ]}|  ||¡}|  |d¡ qW qW d S )N)z-tz--testrL   )Útesttarnamesr"  r0   )r   r&  Úoptr{   r   r   r	   Útest_test_command¯  s    

z!CommandLineTest.test_test_commandc             C   s:   x4t D ],}x&dD ]}|  |d|¡}|  d|¡ qW qW d S )N)z-vz	--verbosez-ts   is a tar archive.
)r-  r"  rw   )r   r&  r.  r{   r   r   r	   Útest_test_command_verboseµ  s    

z)CommandLineTest.test_test_command_verbosec             C   sì   t  d¡}|  d|¡\}}}|  d|¡ |  |d¡ |  |d¡ x¦tD ]ž}| j|dˆ t|dƒ}| ¡ }W d Q R X zVtt	dƒ}| 
|d d	… ¡ W d Q R X |  dt	¡\}}}|  |d¡ |  |d¡ W d t  t	¡ X W d Q R X qFW d S )
Nz
zipdir.zipz-ts    is not a tar archive.rL   rI   )r&  rH   r   iÿ  )r   r%  r$  rw   r0   r-  ZsubTestr   r/   r†   r–   rË   )r   Úzipnamer   r{   r!  r&  r»   r   r   r   r	   Útest_test_command_invalid_file»  s     

z.CommandLineTest.test_test_command_invalid_filec             C   s„   x~t D ]v}t ¡ *}t |d¡}|jdd W d Q R X W d Q R X | ¡  dd¡}x(dD ] }| j||dd}|  	||¡ qXW qW d S )Nr7   F)rm   ri   ro   )z-lz--list)ÚPYTHONIOENCODING)
r-  r   Úcaptured_stdoutr   r   rF   rv   rW   r"  r0   )r   r&  rž   r(  Úexpectedr.  r{   r   r   r	   Útest_list_commandÏ  s    

 
z!CommandLineTest.test_list_commandc             C   s†   x€t D ]x}t ¡ *}t |d¡}|jdd W d Q R X W d Q R X | ¡  dd¡}x*dD ]"}| j|d|dd}|  	||¡ qXW qW d S )	Nr7   T)rm   ri   ro   )z-vz	--verbosez-l)r3  )
r-  r   r4  r   r   rF   rv   rW   r"  r0   )r   r&  rž   r(  r5  r.  r{   r   r   r	   Útest_list_command_verboseÚ  s    

 

z)CommandLineTest.test_list_command_verbosec             C   sD   t  d¡}|  d|¡\}}}|  d|¡ |  |d¡ |  |d¡ d S )Nz
zipdir.zipz-ls    is not a tar archive.rL   rI   )r   r%  r$  rw   r0   )r   r1  r   r{   r!  r   r   r	   Útest_list_command_invalid_fileå  s
    
z.CommandLineTest.test_list_command_invalid_filec          
   C   st   t  d¡t  d¡g}xZdD ]R}z@| j|tf|žŽ }|  |d¡ t t¡}| ¡  W d Q R X W d t  t¡ X qW d S )Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt)z-cz--createrL   )	r   r%  r"  r†   r0   r   r   r~   rË   )r   r'  r.  r{   r(   r   r   r	   Útest_create_commandì  s    
z#CommandLineTest.test_create_commandc          
   C   sv   t  d¡t  d¡g}x\dD ]T}zB| j|dtf|žŽ }|  d|¡ t t¡}| ¡  W d Q R X W d t  t¡ X qW d S )Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt)z-vz	--verbosez-cs    file created.)	r   r%  r"  r†   rw   r   r   r~   rË   )r   r'  r.  r{   r(   r   r   r	   Útest_create_command_verboseù  s    
z+CommandLineTest.test_create_command_verbosec          	   C   s^   t  d¡g}z@| jdtf|žŽ }|  |d¡ t t¡}| ¡  W d Q R X W d t  t¡ X d S )Nztokenize_tests.txtz-crL   )	r   r%  r"  Údotlessnamer0   r   r   r~   rË   )r   r'  r{   r(   r   r   r	   Ú$test_create_command_dotless_filename	  s    z4CommandLineTest.test_create_command_dotless_filenamec          	   C   sl   t j td¡}t d¡g}z@| jd|f|žŽ }|  |d¡ t 	|¡}| 
¡  W d Q R X W d t |¡ X d S )Nz.testtarztokenize_tests.txtz-crL   )r<   r=   r>   r;   r   r%  r"  r0   r   r   r~   rË   )r   r&  r'  r{   r(   r   r   r	   Ú(test_create_command_dot_started_filename	  s    z8CommandLineTest.test_create_command_dot_started_filenamec          
   C   s„   t  d¡t  d¡g}xjtttfD ]\}|js,q zBtd |j }| jd|f|žŽ }| 	|¡}| 
¡  W d Q R X W d t  |¡ X q W d S )Nztokenize_tests.txtz9tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txtr„  z-c)r   r%  r   r   r#   r   r†   r   r"  r   r~   rË   )r   r'  Zfiletyper&  r{   r(   r   r   r	   Útest_create_command_compressed	  s    z.CommandLineTest.test_create_command_compressedc          
   C   s\   |   t¡ xLdD ]D}z2t t¡ |  |t¡}W d Q R X |  |d¡ W d t t¡ X qW d S )N)z-ez	--extractrL   )r)  r†   r   Útemp_cwdÚ	tarextdirr"  r0   rÜ   )r   r.  r{   r   r   r	   Útest_extract_command*	  s    

z$CommandLineTest.test_extract_commandc          
   C   s^   |   t¡ xNdD ]F}z4t t¡ |  |dt¡}W d Q R X |  d|¡ W d t t¡ X qW d S )N)z-vz	--verbosez-es    file is extracted.)r)  r†   r   r?  r@  r"  rw   rÜ   )r   r.  r{   r   r   r	   Útest_extract_command_verbose4	  s    

z,CommandLineTest.test_extract_command_verbosec          	   C   sP   |   t¡ z4t t¡ |  dtd¡}W d Q R X |  |d¡ W d t t¡ X d S )Nz-eZspamdirrL   )r)  r†   r   r?  r@  r"  r0   rÜ   )r   r{   r   r   r	   Ú(test_extract_command_different_directory>	  s    
z8CommandLineTest.test_extract_command_different_directoryc          	   C   sZ   t  d¡}t  t¡ |  d|¡\}}}W d Q R X |  d|¡ |  |d¡ |  |d¡ d S )Nz
zipdir.zipz-es    is not a tar archive.rL   rI   )r   r%  r?  r@  r$  rw   r0   )r   r1  r   r{   r!  r   r   r	   Ú!test_extract_command_invalid_fileG	  s    
z1CommandLineTest.test_extract_command_invalid_fileN)r   r   r   r"  r$  r)  r,  r/  r0  r2  r6  r7  r8  r9  r:  r<  r=  r>  rA  rB  rC  rD  r   r   r   r	   r  ’  s&   	



	r  c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚContextManagerTestc          	   C   s6   t  t¡}|  |jd¡ W d Q R X |  |jd¡ d S )Nzclosed inside runtime contextzcontext manager failed)r   r   r   rS  rì   rë   )r   r(   r   r   r	   Ú
test_basicR	  s    zContextManagerTest.test_basicc          
   C   s<   t  t¡}| ¡  |  t¡ | W d Q R X W d Q R X d S )N)r   r   r   r*   r   r‚  )r   r(   r   r   r	   Útest_closedW	  s
    
zContextManagerTest.test_closedc          
   C   sR   |   t¡ }t t¡
}t‚W d Q R X W d Q R X |  |jtd¡ |  |j	d¡ d S )Nz)wrong exception raised in context managerzcontext manager failed)
r   Ú	Exceptionr   r   r   r‚  r£   Z	exceptionrë   rì   )r   rç  r(   r   r   r	   Útest_exception`	  s    
z!ContextManagerTest.test_exceptionc          	   C   sV   y t  td¡
}t‚W d Q R X W n   Y nX |  tj t¡dd¡ |  |j	d¡ d S )Nr…   r   z-context manager wrote an end-of-archive blockzcontext manager failed)
r   r   r†   rH  r0   r<   r=   r]  rë   rì   )r   r(   r   r   r	   Útest_no_eofi	  s    zContextManagerTest.test_no_eofc          	   C   s2   t  td¡ W d Q R X |  tj t¡dd¡ d S )Nr…   r   z-context manager wrote no end-of-archive block)r   r   r†   r6  r<   r=   r]  )r   r   r   r	   Útest_eofu	  s    
zContextManagerTest.test_eofc          
   C   sf   t tdƒR}y"tj |dd
}t‚W d Q R X W n   Y nX |  |jd¡ |  |jd¡ W d Q R X d S )Nr   r…   )r¢   r   zexternal file object was closedzcontext manager failed)r   r†   r   rH  rS  rì   rë   )r   r5   r(   r   r   r	   rú  }	  s    zContextManagerTest.test_fileobjN)	r   r   r   rF  rG  rI  rJ  rK  rú  r   r   r   r	   rE  P	  s   		rE  zrequires os.link to be missingc               @   s€   e Zd Zdd„ Ze eejdƒd¡dd„ ƒZ	e eejdƒd¡dd„ ƒZ
e eed	ƒd
¡dd„ ƒZe eed	ƒd
¡dd„ ƒZdS )ÚLinkEmulationTestc          	   C   sJ   | j  |t¡ ttj t|¡dƒ}| ¡ }W d Q R X |  t	|ƒt
¡ d S )NrH   )r(   r:   r;   r   r<   r=   r>   r/   r0   r
   r3   )r   r[   r»   r   r   r   r	   Ú_test_link_extraction	  s    z'LinkEmulationTest._test_link_extractionÚislinkz3Skip emulation - has os.path.islink but not os.linkc             C   s   |   d¡ d S )Nzustar/lnktype)rM  )r   r   r   r	   Útest_hardlink_extraction1—	  s    z+LinkEmulationTest.test_hardlink_extraction1c             C   s   |   d¡ d S )Nz./ustar/linktest2/lnktype)rM  )r   r   r   r	   Útest_hardlink_extraction2œ	  s    z+LinkEmulationTest.test_hardlink_extraction2rs  z Skip emulation if symlink existsc             C   s   |   d¡ d S )Nzustar/symtype)rM  )r   r   r   r	   Útest_symlink_extraction1¡	  s    z*LinkEmulationTest.test_symlink_extraction1c             C   s   |   d¡ d S )Nz./ustar/linktest2/symtype)rM  )r   r   r   r	   Útest_symlink_extraction2¦	  s    z*LinkEmulationTest.test_symlink_extraction2N)r   r   r   rM  rð   ÚskipIfrò   r<   r=   rO  rP  rQ  rR  r   r   r   r	   rL  Š	  s   rL  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚBz2PartialReadTestc          	      s~   G ‡ fdd„dt jƒ‰ t t d¡ ¡ ¡}xNtt|ƒd ƒD ]:}ytj	ˆ |d |… ƒ|d W q< tj
k
rt   Y q<X q<W d S )Nc                   s0   e Zd ZdZ‡‡ fdd„Z‡‡ fdd„Z‡  ZS )z9Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIOFc                s4   | j rtdƒ‚|  ¡ t|  ¡ ƒk| _ tˆ | ƒ |¡S )Nz(infinite loop detected in tarfile.open())Úhit_eofÚAssertionErrorrN   r1   rv   Úsuperr/   )r   rË  )Ú	MyBytesIOÚ	__class__r   r	   r/   ³	  s    z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.readc                s   d| _ tˆ | ƒj|Ž S )NF)rU  rW  rM   )r   r  )rX  rY  r   r	   rM   ¹	  s    z>Bz2PartialReadTest._test_partial_input.<locals>.MyBytesIO.seek)r   r   r   rU  r/   rM   Ú__classcell__r   )rX  )rY  r	   rX  ±	  s   rX  r”   rI   )r¢   r   )r   rr   r    Úcompressr   r—   r˜   Úranger1   r   r‰   )r   r   r   rº  r   )rX  r	   Ú_test_partial_input°	  s    z&Bz2PartialReadTest._test_partial_inputc             C   s   |   d¡ d S )Nr7   )r]  )r   r   r   r	   Útest_partial_inputÄ	  s    z%Bz2PartialReadTest.test_partial_inputc             C   s   |   d¡ d S )Nzr:bz2)r]  )r   r   r   r	   Útest_partial_input_bz2Ç	  s    z)Bz2PartialReadTest.test_partial_input_bz2N)r   r   r   r]  r^  r_  r   r   r   r	   rT  ¬	  s   rT  c              C   sZ   ydd l } dd l}W n tk
r(   dS X |  d¡d dkr@dS | d¡d dkrVdS dS )Nr   FÚrootT)r  r  ÚImportErrorÚgetpwuidZgetgrgid)r  r  r   r   r	   Úroot_is_uid_gid_0Ë	  s    rc  Úchownzmissing os.chownÚgeteuidzmissing os.geteuidc               @   sÎ   e Zd Zedd„ ƒZeedd„ ƒƒZej 	d¡ej 	d¡ej 	d¡dd	„ ƒƒƒZ
ej 	d¡ej 	d¡ej 	d¡d
d„ ƒƒƒZe eƒ d¡ej 	d¡ej 	d¡ej 	d¡dd„ ƒƒƒƒZej 	d¡dd„ ƒZdS )ÚNumericOwnerTestc          	   C   s    t  d¡}| ddtj|f|ddtjd f|ddtj|fg}t td¡R}xJ|D ]B\}}}}	}
t |¡}||_||_	d	|_
d	|_|	|_| ||
¡ qLW W d Q R X tS )
Ns   contentéc   éb   éM   éL   éX   éW   r…   r`  )r   rr   r   rÅ  r¿   r   r†   r—   r  r  rÅ   r  r¾   r›   )Ú
filename_1Ú	dirname_1Ú
filename_2r5   r  Útarflr[   r  r  ÚtypÚcontentsrž   r   r   r	   Ú_make_test_archiveà	  s    

z#NumericOwnerTest._make_test_archivec          	   c   sZ   d| _ d}d}|}|}tj ||¡}t |||¡}t |¡}||||fV  W d Q R X d S )Nr   znumeric-owner-testfiler  )rh  r<   r=   r>   rf  rs  r   r   )Úmock_geteuidZfnameÚdirnamerm  rn  ro  Ztar_filenamerp  r   r   r	   Ú_setup_testø	  s    zNumericOwnerTest._setup_testzos.chownzos.chmodz
os.geteuidc       
   	   C   sˆ   |   |¡.\}}}}|j|tdd |j|tdd W d Q R X tj t|¡}tj t|¡}	|jtj 	|dd¡tj 	|	dd¡gdd d S )NT)Únumeric_ownerrg  rh  rk  rl  )Ú	any_order)
rv  r:   r;   r<   r=   r>   Úassert_has_callsrð   rf  Úcall)
r   rt  Ú
mock_chmodÚ
mock_chownrp  rm  Ú_ro  Úf_filename_1Úf_filename_2r   r   r	   Útest_extract_with_numeric_owner
  s    z0NumericOwnerTest.test_extract_with_numeric_ownerc          	   C   s’   |   |¡\}}}}|jtdd W d Q R X tj t|¡}tj t|¡}	tj t|¡}
|jtj 	|dd¡tj 	|	dd¡tj 	|
dd¡gdd	 d S )
NT)rw  rg  rh  ri  rj  rk  rl  )rx  )
rv  rÍ   r;   r<   r=   r>   ry  rð   rf  rz  )r   rt  r{  r|  rp  rm  rn  ro  r~  Zf_dirname_1r  r   r   r	   Ú"test_extractall_with_numeric_owner!
  s    z3NumericOwnerTest.test_extractall_with_numeric_ownerz uid=0,gid=0 must be named "root"c          	   C   sN   |   |¡\}}}}|j|tdd W d Q R X tj t|¡}| |dd¡ d S )NF)rw  r   )rv  r:   r;   r<   r=   r>   Zassert_called_with)r   rt  r{  r|  rp  rm  r}  r~  r   r   r	   Ú"test_extract_without_numeric_owner9
  s    z3NumericOwnerTest.test_extract_without_numeric_ownerc          	   C   s8   |   |¡$\}}}}|  t|j|tdd¡ W d Q R X d S )NFT)rv  r   r{  r:   r;   )r   rt  rp  rm  r}  r   r   r	   Útest_keyword_onlyH
  s    z"NumericOwnerTest.test_keyword_onlyN)r   r   r   rI  rs  r   rv  rð   rf  rg  r€  r  rñ   rc  r‚  rƒ  r   r   r   r	   rf  ×	  s   	





rf  c           
   C   s’   t  t¡ t t¡ tgattdƒ} |  ¡ }W d Q R X xTt	t
tfD ]F}|jrDt  |j¡ t |j¡ | |jd¡}| |¡ W d Q R X qDW d S )NrH   r   )r   rË   r;   r<   Úmakedirsr   r-  r   r/   r   r   r#   ri  r–   )r5   r   Úcr(   r   r   r	   ÚsetUpModuleO
  s    

r†  c               C   s   t j t¡rt t¡ d S )N)r<   r=   r˜  r;   r   rÜ   r   r   r   r	   ÚtearDownModule`
  s    r‡  Ú__main__)qrt   r<   r   Zhashlibr   Ú
contextlibr   Zrandomr   r²   rð   Zunittest.mockr   rÍ  r   Ztest.supportr   r   ra  r    r%   r
   r=   r¥   ZTESTFNr;   r@  r%  r   r>   r   r!   r$   r†   r;  r3   r(  r   Zrequires_gzipr   Zrequires_bz2r   Zrequires_lzmar#   r&   ZTestCaser,   re   rf   rg   rh   r   r‚   rƒ   r„   r    rô   rõ   rö   rø   rù   r  r  r  r  r  r  r  r  r2  r>  rJ  rR  rX  r  r  r‘  r’  rš  r›  rœ  r  r¯  rÀ  rÁ  rÂ  rÃ  rñ   rò   rÄ  rÉ  rÓ  rÞ  rì  rî  rð  rõ  r  r  r  r  r	  r  rE  rS  rL  rT  rc  rf  r†  r‡  r   r  r   r   r   r	   Ú<module>   sÞ   




~PP |=(a*;,  ;&RZ
*TQO@;S ?:!v
