grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026î   f¥eã@sÝdZdZdZdZdZdZddlmZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZyddlZddlZWnek rÚdZZYnXeefZyeef7ZWnek r YnXd d d d gZd ZdZedZdZdZdZ dZ!dZ"dZ#d Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0d!Z1dZ2d"Z3d#Z4e3Z5e#e$e%e&e)e*e+e'e(e,e-e.f Z6e#e$e+e.fZ7e,e-e.fZ8d$d%d&d'd(d)d*d+fZ9d$d%d*d+hZ:ie;d,6e;d-6e;d'6e<d(6e<d)6e<d&6Z=e j>d.d/fkrŽd0Z?n e j@ƒZ?d1d2„ZAd3d4„ZBd5d6„ZCd7e5d8d9„ZDd:d;„ZEded<d=„ZFd>d?„ZGd@dA„ZHGdBd „d eIƒZJGdCdD„dDeJƒZKGdEdF„dFeJƒZLGdGdH„dHeJƒZMGdIdJ„dJeJƒZNGdKdL„dLeJƒZOGdMdN„dNeOƒZPGdOdP„dPeOƒZQGdQdR„dReOƒZRGdSdT„dTeOƒZSGdUdV„dVeOƒZTGdWdX„dXƒZUGdYdZ„dZƒZVGd[d\„d\eWƒZXGd]d^„d^eWƒZYGd_d`„d`e jZƒZ[Gdad „d eWƒZ\Gdbd „d eWƒZ]Gdcdd„ddƒZ^ded „Z_e]jZdfdg„Z`eadhkrÙe`ƒndS)iz,Read from and write to tar format archives. z0.9.0u"Lars Gustäbel (lars@gustaebel.de)z5$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $z?$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.é)ÚopenNÚTarFileÚTarInfoÚ is_tarfileÚTarErrorsiésustar sustar00édé›ó0ó1ó2ó3ó4ó5ó6ó7óLóKóSóxógóXééÚpathÚlinkpathÚsizeÚmtimeÚuidÚgidÚunameÚgnameZatimeZctimeÚntZcezutf-8cCs2|j||ƒ}|d|…|t|ƒtS)z8Convert a string to a null-terminated bytes object. N)ÚencodeÚlenÚNUL)ÚsÚlengthÚencodingÚerrors©r*ú,/opt/alt/python34/lib64/python3.4/tarfile.pyÚstn™sr,cCs>|jdƒ}|dkr.|d|…}n|j||ƒS)z8Convert a null-terminated bytes object to a string. srNéÿÿÿÿ)ÚfindÚdecode)r&r(r)Úpr*r*r+ÚntsŸs r1c CsØ|dd kr‚d}x:tt|ƒdƒD]"}|dK}|||d7}q-W|ddkrÔdt|ƒd| }qÔnRy1t|ddƒ}t|jƒp©d dƒ}Wntk rÓtd ƒ‚YnX|S) z/Convert a number field to a python number. ré€éÿrééÚasciiÚstrictÚ0zinvalid header)r2r3)Úranger$r1ÚintÚstripÚ ValueErrorÚInvalidHeaderError)r&ÚnÚir*r*r+Únti§s  r@r4cCsd|kod|dknrNtd|dt|ƒfdƒt}n¼|tkrþd|d |ko‚d|dknrþ|dkr¥tdgƒ}ntdgƒ}d||}xEt|dƒD]$}|jd|d@ƒ|dL}qÓWn td ƒ‚|S) z/Convert a python number to a number field. rr4rz%0*or6r5r2r3zoverflow in number field)Úbytesr:r%Ú GNU_FORMATÚ bytearrayr9Úinsertr<)r>ÚdigitsÚformatr&r?r*r*r+Úitn»s $*9  rGcCsBdttjd|ƒƒ}dttjd|ƒƒ}||fS)a¨Calculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces. According to the GNU tar sources, some tars (Sun and NeXT) calculate chksum with signed char, which will be different if there are chars in the buffer with the high bit set. So we calculate two checksums, unsigned and signed. r5Z 148B8x356BZ 148b8x356b)ÚsumÚstructZ unpack_from)ÚbufZunsigned_chksumZ signed_chksumr*r*r+Ú calc_chksums×s rKc Csï|dkrdS|dkr0tj||ƒdSd}t||ƒ\}}xQt|ƒD]C}|j|ƒ}t|ƒ|krŽ|dƒ‚n|j|ƒqXW|dkrë|j|ƒ}t|ƒ|krÛ|dƒ‚n|j|ƒndS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. rNéizunexpected end of datai@)ÚshutilÚ copyfileobjÚdivmodr9Úreadr$Úwrite) ÚsrcZdstr'Ú exceptionZBUFSIZEÚblocksÚ remainderÚbrJr*r*r+rNäs$   rNcCs,ddl}|jdtdƒtj|ƒS)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder)ÚwarningsÚwarnÚDeprecationWarningÚstatÚfilemode)ÚmoderWr*r*r+r[ýs   r[cCsSttjddƒ}|dk r?|j|dƒj|ƒ}nt|ddƒdS)Nr(ÚbackslashreplaceÚendú )ÚgetattrÚsysÚstdoutr#r/Úprint)r&r(r*r*r+Ú _safe_prints rdc@seZdZdZdS)rzBase exception.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r*r*r*r+r s c@seZdZdZdS)Ú ExtractErrorz%General exception for extract errors.N)rerfrgrhr*r*r*r+ris ric@seZdZdZdS)Ú ReadErrorz&Exception for unreadable tar archives.N)rerfrgrhr*r*r*r+rjs rjc@seZdZdZdS)ÚCompressionErrorz.Exception for unavailable compression methods.N)rerfrgrhr*r*r*r+rks rkc@seZdZdZdS)Ú StreamErrorz=Exception for unsupported operations on stream-like TarFiles.N)rerfrgrhr*r*r*r+rls rlc@seZdZdZdS)Ú HeaderErrorz!Base exception for header errors.N)rerfrgrhr*r*r*r+rms rmc@seZdZdZdS)ÚEmptyHeaderErrorzException for empty headers.N)rerfrgrhr*r*r*r+rns rnc@seZdZdZdS)ÚTruncatedHeaderErrorz Exception for truncated headers.N)rerfrgrhr*r*r*r+ro s roc@seZdZdZdS)ÚEOFHeaderErrorz"Exception for end of file headers.N)rerfrgrhr*r*r*r+rp#s rpc@seZdZdZdS)r=zException for invalid headers.N)rerfrgrhr*r*r*r+r=&s r=c@seZdZdZdS)ÚSubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rerfrgrhr*r*r*r+rq)s rqc@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) Ú _LowLevelFilez‰Low-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. cCsgitjd6tjtjBtjBd6|}ttdƒrK|tjO}ntj||dƒ|_dS)NÚrÚwÚO_BINARYi¶) ÚosÚO_RDONLYÚO_WRONLYÚO_CREATÚO_TRUNCÚhasattrrurÚfd)ÚselfÚnamer\r*r*r+Ú__init__6s z_LowLevelFile.__init__cCstj|jƒdS)N)rvÚcloser|)r}r*r*r+r€?sz_LowLevelFile.closecCstj|j|ƒS)N)rvrPr|)r}rr*r*r+rPBsz_LowLevelFile.readcCstj|j|ƒdS)N)rvrQr|)r}r&r*r*r+rQEsz_LowLevelFile.writeN)rerfrgrhrr€rPrQr*r*r*r+rr0s   rrc@s¬eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z ddd„Z ddd„Z dd„Zdd„ZdS)Ú_Streama˜Class that serves as an adapter between TarFile and a stream-like object. The stream-like object only needs to have a read() or write() method and is accessed blockwise. Use of gzip or bzip2 compression is possible. A stream-like object could be for example: sys.stdin, sys.stdout, a socket, a tape device etc. _Stream is intended to be used only internally. c Cs‡d|_|dkr0t||ƒ}d|_n|dkrWt|ƒ}|jƒ}n|p`d|_||_||_||_||_d|_ d|_ d|_ y®|dkr2yddl }Wnt k rätd ƒ‚YnX||_ |jdƒ|_|d kr%|jƒ|j|_qR|jƒn |d kr±yddl}Wnt k rntd ƒ‚YnX|d krŸd|_|jƒ|_t|_qR|jƒ|_n¡|d kr3yddl}Wnt k rítdƒ‚YnX|d kr!d|_|jƒ|_|j|_qR|jƒ|_n|dkrRtd|ƒ‚nWn-|jsr|jjƒnd|_ ‚YnXdS)z$Construct a _Stream object. TNFÚ*ÚórÚgzzzlib module is not availablersÚbz2zbz2 module is not availableÚxzzlzma module is not availableÚtarzunknown compression type %r) Ú _extfileobjrrÚ _StreamProxyÚ getcomptyper~r\ÚcomptypeÚfileobjÚbufsizerJÚposÚclosedÚzlibÚ ImportErrorrkÚcrc32ÚcrcÚ _init_read_gzÚerrorrSÚ_init_write_gzr†ÚdbufZBZ2DecompressorÚcmpÚOSErrorZ BZ2CompressorÚlzmaZLZMADecompressorÚ LZMAErrorZLZMACompressorr€) r}r~r\rŒr�rŽr‘r†r›r*r*r+rSsl                              z_Stream.__init__cCs*t|dƒr&|j r&|jƒndS)Nr�)r{r�r€)r}r*r*r+Ú__del__™sz_Stream.__del__cCs¶|jjd|jj|jj |jjdƒ|_tjdtt j ƒƒƒ}|j d|dƒ|j j dƒr’|j dd …|_ n|j |j j d d ƒtƒdS) z6Initialize for writing with gzip compression. é rz|t krPqqWn|d@rc|jdƒnd S)z:Initialize for reading a gzip compressed fileobj. r„rs‹znot a gzip filerszunsupported compression methodéér5r4rLN) r‘Z decompressobjr¢r™r˜Ú _Stream__readrjrkÚordrPr%)r}ZflagZxlenr&r*r*r+r•Ús.   ,     z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position. )r�)r}r*r*r+Útellùsz _Stream.tellrcCs|||jdkrit||j|jƒ\}}x$t|ƒD]}|j|jƒq?W|j|ƒn tdƒ‚|jS)zXSet the stream's file pointer to pos. Negative seeking is forbidden. rz seeking backwards is not allowed)r�rOrŽr9rPrl)r}r�rTrUr?r*r*r+Úseekþs z _Stream.seekNcCs||dkrTg}x-|j|jƒ}|s1Pn|j|ƒqWdj|ƒ}n|j|ƒ}|jt|ƒ7_|S)z–Return the next size number of bytes from the stream. If size is not defined, return all bytes of the stream up to EOF. Nrƒ)Ú_readrŽÚappendÚjoinr�r$)r}rÚtrJr*r*r+rP s z _Stream.readc Csà|jdkr|j|ƒSt|jƒ}x…||kr²|j|jƒ}|sVPny|jj|ƒ}Wn!|jk r�tdƒ‚YnX|j|7_|t|ƒ7}q.W|jd|…}|j|d…|_|S)z+Return size bytes from the stream. rˆzinvalid compressed dataN) rŒr«r$r˜rŽr™Z decompressrSrj)r}rÚcrJr*r*r+r¯s  z _Stream._readcCs�t|jƒ}xN||kr_|jj|jƒ}|s=Pn|j|7_|t|ƒ7}qW|jd|…}|j|d…|_|S)zsReturn size bytes from stream. If internal buffer is empty, read another block from the stream. N)r$rJr�rPrŽ)r}rr³rJr*r*r+Z__read2sz_Stream.__read)rerfrgrhrr�r—rQr¥r€r•r­r®rPr¯r«r*r*r*r+r�Hs  F       r�c@sFeZdZdZdd„Zdd„Zdd„Zdd „Zd S) rŠzsSmall proxy class that enables transparent compression detection for the Stream interface (mode 'r|*'). cCs"||_|jjtƒ|_dS)N)r�rPÚ BLOCKSIZErJ)r}r�r*r*r+rGs z_StreamProxy.__init__cCs|jj|_|jS)N)r�rPrJ)r}rr*r*r+rPKsz_StreamProxy.readcCsj|jjdƒrdS|jdd…dkrL|jdd…dkrLd S|jjdƒrbd Sd SdS)Ns‹r…rrŸsBZhrªé s1AY&SYr†ó]€óý7zXZr‡rˆ)r¶r·)rJÚ startswith)r}r*r*r+r‹Os2z_StreamProxy.getcomptypecCs|jjƒdS)N)r�r€)r}r*r*r+r€Ysz_StreamProxy.closeN)rerfrgrhrrPr‹r€r*r*r*r+rŠBs    rŠc@sšeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z e j dd„Z ddd„Z dd„Zdd„ZdS)Ú _FileInFilezA thin wrapper around an existing file object that provides a part of its data as an individual file object. NcCs,||_||_||_d|_t|ddƒ|_d|_|dkr`d|fg}nd|_g|_d}|j}xs|D]k\}}||kr¿|jj d||dfƒn|jj d||||fƒ||7}||}qˆW||jkr(|jj d||jdfƒndS)Nrr~FT) r�ÚoffsetrÚpositionr`r~r�Ú map_indexÚmapr°)r}r�rºrZ blockinfoZlastposZrealposr*r*r+rfs(            z_FileInFile.__init__cCsdS)Nr*)r}r*r*r+r¨sz_FileInFile.flushcCsdS)NTr*)r}r*r*r+Úreadable‚sz_FileInFile.readablecCsdS)NFr*)r}r*r*r+Úwritable…sz_FileInFile.writablecCs |jjƒS)N)r�Úseekable)r}r*r*r+rÀˆsz_FileInFile.seekablecCs|jS)z*Return the current file position. )r»)r}r*r*r+r­‹sz_FileInFile.tellcCsÐ|tjkr0tt|dƒ|jƒ|_n™|tjkr†|dkrgt|j|dƒ|_qÉt|j||jƒ|_nC|tjkr½tt|j||jƒdƒ|_n tdƒ‚|jS)z(Seek to a position in the file. rzInvalid argument) ÚioÚSEEK_SETÚminÚmaxrr»ÚSEEK_CURÚSEEK_ENDr<)r}r»Úwhencer*r*r+r®�s! ( z_FileInFile.seekc Csl|dkr|j|j}nt||j|jƒ}d}x'|dkrgxv|j|j\}}}}||jko†|knr�PqP|jd7_|jt|jƒkrPd|_qPqPWt|||jƒ}|r=|jj||j|ƒ|jj|ƒ}t|ƒ|kr0t dƒ‚n||7}n|t |7}||8}|j|7_qAW|S)z!Read data from the file. Nr„rrzunexpected end of data) rr»rÃr½r¼r$r�r®rPrjr%) r}rrJÚdataÚstartÚstoprºr'rVr*r*r+rP s.   z_FileInFile.readcCs5|jt|ƒƒ}||dt|ƒ…d?„Zd@dA„Z dBdC„Z!dDdE„Z"dFdG„Z#dHdI„Z$dJdK„Z%dLdM„Z&dNdO„Z'dPdQ„Z(dRdS„Z)dTdU„Z*dVdW„Z+dXdY„Z,dZd[„Z-d\d]„Z.d^d_„Z/d`da„Z0dbdc„Z1ddde„Z2dfdg„Z3dhS)jraInformational class which holds the details about an archive member given by a tar header block. TarInfo objects are returned by TarFile.getmember(), TarFile.getmembers() and TarFile.gettarinfo() and are usually created internally. r~r\rrrrÚchksumÚtypeÚlinknamer r!ÚdevmajorÚdevminorrºrÍÚ pax_headersrÎrÐÚ_sparse_structsÚ _link_targetrƒcCs�||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_i|_dS)zXConstruct a TarInfo object. name is the optional name of the member. i¤rrƒN)r~r\rrrrrÓÚREGTYPErÔrÕr r!rÖr×rºrÍrÎrØ)r}r~r*r*r+rás"                zTarInfo.__init__cCs|jS)N)r~)r}r*r*r+Ú_getpathûszTarInfo._getpathcCs ||_dS)N)r~)r}r~r*r*r+Ú_setpathýszTarInfo._setpathcCs|jS)N)rÕ)r}r*r*r+Ú _getlinkpathszTarInfo._getlinkpathcCs ||_dS)N)rÕ)r}rÕr*r*r+Ú _setlinkpathszTarInfo._setlinkpathcCs d|jj|jt|ƒfS)Nz<%s %r at %#x>)rÒrer~Úid)r}r*r*r+Ú__repr__szTarInfo.__repr__cCsÅi |jd6|jd@d6|jd6|jd6|jd6|jd6|jd6|jd 6|jd 6|j d 6|j d 6|j d 6|j d6}|d t krÁ|djdƒ rÁ|dd7ny||jd d ƒWn#tk rœ||||YnXt||ƒ|kr>||||q>Wx‹dD]ƒ\}}||kr÷d||r0rär*r*r+rÈs<      1   z"TarInfo._create_pax_generic_headerc Csft|ƒdkr!tdƒ‚nt|ƒtkrBtdƒ‚n|jtƒtkrftdƒ‚nt|dd…ƒ}|t|ƒkr�t dƒ‚n|ƒ}t |dd…||ƒ|_ t|dd …ƒ|_ t|d d …ƒ|_ t|d d …ƒ|_t|d d …ƒ|_t|d d…ƒ|_||_|dd …|_t |d d…||ƒ|_t |dd…||ƒ|_t |dd…||ƒ|_t|dd…ƒ|_t|dd…ƒ|_t |dd…||ƒ}|jtkr6|j jdƒr6t|_n|jtkrd}g}xƒtdƒD]u} y<t|||d…ƒ} t||d|d…ƒ} Wntk rµPYnX|j| | fƒ|d7}q^Wt|dƒ} t|dd…ƒ} || | f|_ n|j!ƒr6|j j"dƒ|_ n|rb|jt#krb|d|j |_ n|S)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headeré”éœz bad checksumrélété|éˆé�ii i)iIiQiYiôrâi‚rªrùéiâiãiï)$r$rnr´roÚcountr%rpr@rKr=r1r~r\rrrrrÓrÔrÕr r!rÖr×ÚAREGTYPEr¦rãÚGNUTYPE_SPARSEr9r<r°ÚboolrÙÚisdirÚrstripÚ GNU_TYPES)r rJr(r)rÓÚobjrîr�Ústructsr?rºÚnumbytesÚ isextendedÚorigsizer*r*r+ÚfrombufûsZ  ! "  zTarInfo.frombufcCsP|jjtƒ}|j||j|jƒ}|jjƒt|_|j|ƒS)zOReturn the next TarInfo object from TarFile object tarfile. ) r�rPr´r)r(r)r­rºÚ _proc_member)r rÐrJr$r*r*r+Ú fromtarfile:szTarInfo.fromtarfilecCst|jttfkr"|j|ƒS|jtkr>|j|ƒS|jtttfkrc|j |ƒS|j |ƒSdS)zYChoose the right processing method depending on the type and call it. N) rÔr÷röÚ _proc_gnulongrÚ _proc_sparserrÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r}rÐr*r*r+r*Os   zTarInfo._proc_membercCsx|jjƒ|_|j}|jƒs6|jtkrO||j|jƒ7}n||_|j |j |j |j ƒ|S)zfProcess a builtin type or an unknown type which will be treated as a regular file. ) r�r­rÍÚisregrÔÚSUPPORTED_TYPESÚ_blockrrºÚ_apply_pax_inforØr(r))r}rÐrºr*r*r+r0\s  zTarInfo._proc_builtinc Cs¼|jj|j|jƒƒ}y|j|ƒ}Wntk rQtdƒ‚YnX|j|_|jt kr‹t ||j |j ƒ|_ n-|jtkr¸t ||j |j ƒ|_n|S)zSProcess the blocks that hold a GNU longname or longlink member. z missing or bad subsequent header)r�rPr3rr+rmrqrºrÔr÷r1r(r)r~rörÕ)r}rÐrJÚnextr*r*r+r,ms  zTarInfo._proc_gnulongc Cs&|j\}}}|`xÇ|rá|jjtƒ}d}x’tdƒD]„}y<t|||d…ƒ}t||d|d…ƒ} Wntk r�PYnX|rÀ| rÀ|j|| fƒn|d7}qFWt|dƒ}qW||_ |jj ƒ|_ |j |j |j ƒ|_||_ |S)z8Process a GNU sparse header plus extra headers. rérùriø)rÙr�rPr´r9r@r<r°r rÎr­rÍr3rrº) r}rÐr%r'r(rJr�r?rºr&r*r*r+r-ƒs( "    zTarInfo._proc_sparsec Csø|jj|j|jƒƒ}|jtkr9|j}n|jjƒ}tj d|ƒ}|dk r…|j dƒj dƒ|ds z.TarInfo._proc_gnusparse_01..zGNU.sparse.mapú,Nrr)ÚsplitrErFrÎ)r}r5rØrÎr*r*r+rAs zTarInfo._proc_gnusparse_01cCs÷d}g}|jjtƒ}|jddƒ\}}t|ƒ}xjt|ƒ|dkr®d|kr€||jjtƒ7}n|jddƒ\}}|jt|ƒƒqEW|jjƒ|_t t |ddd…|ddd…ƒƒ|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Ns rr) r�rPr´rKr:r$r°r­rÍrErFrÎ)r}r5rØrÐZfieldsrÎrJZnumberr*r*r+rCs  zTarInfo._proc_gnusparse_10c Csxþ|jƒD]ð\}}|dkr8t|d|ƒq |dkr]t|dt|ƒƒq |dkr‚t|dt|ƒƒq |tkr |tkrÌyt||ƒ}WqÌtk rÈd}YqÌXn|dkrê|jdƒ}nt|||ƒq q W|jƒ|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namerzGNU.sparse.sizerzGNU.sparse.realsizerrâN) rÚsetattrr:Ú PAX_FIELDSÚPAX_NUMBER_FIELDSr<r"rrØ)r}rØr(r)rrr*r*r+r4&s"       zTarInfo._apply_pax_infoc Cs=y|j|dƒSWn"tk r8|j||ƒSYnXdS)z1Decode a single field from a pax record. r7N)r/ÚUnicodeDecodeError)r}rr(Zfallback_encodingZfallback_errorsr*r*r+r?=s zTarInfo._decode_pax_fieldcCs0t|tƒ\}}|r(|d7}n|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r)rOr´)r}rrTrUr*r*r+r3Es zTarInfo._blockcCs |jtkS)N)rÔÚ REGULAR_TYPES)r}r*r*r+r1Nsz TarInfo.isregcCs |jƒS)N)r1)r}r*r*r+ÚisfilePszTarInfo.isfilecCs |jtkS)N)rÔrã)r}r*r*r+r!Rsz TarInfo.isdircCs |jtkS)N)rÔÚSYMTYPE)r}r*r*r+ÚissymTsz TarInfo.issymcCs |jtkS)N)rÔÚLNKTYPE)r}r*r*r+ÚislnkVsz TarInfo.islnkcCs |jtkS)N)rÔÚCHRTYPE)r}r*r*r+ÚischrXsz TarInfo.ischrcCs |jtkS)N)rÔÚBLKTYPE)r}r*r*r+ÚisblkZsz TarInfo.isblkcCs |jtkS)N)rÔÚFIFOTYPE)r}r*r*r+Úisfifo\szTarInfo.isfifocCs |jdk S)N)rÎ)r}r*r*r+Úissparse^szTarInfo.issparsecCs|jtttfkS)N)rÔrVrXrZ)r}r*r*r+Úisdev`sz TarInfo.isdevN)znamezmodezuidzgidzsizezmtimezchksumztypezlinknamezunamezgnamezdevmajorzdevminorzoffsetz offset_dataz pax_headerszsparseztarfilez_sparse_structsz _link_target)4rerfrgrhÚ __slots__rrÜrÝÚpropertyrrÞrßrráråÚDEFAULT_FORMATÚENCODINGrìrèrérëÚ classmethodr ròÚ staticmethodrórrõrr)r+r*r0r,r-r/rBrArCr4r?r3r1rQr!rSrUrWrYr[r\r]r*r*r*r+rÓs`         1  3?    f             c@sÃeZdZdZdZdZdZdZeZ e Z dZ e ZeZdddddddddddddd „ Zeddded d „ƒZeddd d „ƒZeddddd„ƒZeddddd„ƒZeddddd„ƒZidd6dd6dd6dd6Zdd„Zdd „Zd!d"„Zd#d$„Zdddd%d&„Zd'd(d)„Zdd'dd*dd+d,„Z dd-d.„Z!d/dd0d1„Z"d2d'd3d4„Z#d5d6„Z$d'd7d8„Z%d9d:„Z&d;d<„Z'd=d>„Z(d?d@„Z)dAdB„Z*dCdD„Z+dEdF„Z,dGdH„Z-dIdJ„Z.dKdL„Z/dddMdN„Z0dOdP„Z1ddQdR„Z2dSdT„Z3dUdV„Z4dWdX„Z5dYdZ„Z6d[d\„Z7dS)]rz=The TarFile Class provides an interface to tar archives. rFrNrsræc CsÈidd6dd6dd6} || kr6tdƒ‚n||_| ||_|s§|jdkr‰tjj|ƒ r‰d|_d|_nt||jƒ}d|_nf|d kræt|d ƒræt |j t t fƒræ|j }nt|d ƒr|j|_nd |_|r%tjj |ƒnd |_ ||_|d k rO||_n|d k rg||_n|d k r||_n|d k r—||_n|d k r¯||_n| |_| d k rß|jtkrß| |_n i|_| d k r| |_n| d k r| |_nd|_g|_d|_|jjƒ|_i|_yF|jdkr{d |_|j ƒ|_n|jdkr,xŸ|jj!|jƒy&|jj"|ƒ}|jj#|ƒWq�t$k rî|jj!|jƒPYq�t%k r$}zt&t |ƒƒ‚WYd d }~Xq�Xq�Wn|jd kr“d |_|jr“|jj'|jj(ƒƒ}|jj)|ƒ|jt*|ƒ7_q“nWn-|js³|jj+ƒnd |_‚YnXd S)aÖOpen an (uncompressed) tar archive `name'. `mode' is either 'r' to read from an existing archive, 'a' to append data to an existing file or 'w' to create a new file overwriting an existing one. `mode' defaults to 'r'. If `fileobj' is given, it is used for reading or writing data. If it can be determined, `mode' is overridden by `fileobj's mode. `fileobj' is not closed, when TarFile is closed. Úrbrszr+bÚaÚwbrtzmode must be 'r', 'a' or 'w'FNr~r\TÚaw),r<r\Ú_modervrÚexistsÚ bltn_openr‰r{rr~rrAÚabspathr�rFrÑÚ dereferenceÚ ignore_zerosr(r)rêrØÚdebugÚ errorlevelr�ÚmembersÚ_loadedr­rºÚinodesÚ firstmemberr5r®r+r°rprmrjr rrQr$r€)r}r~r\r�rFrÑrlrmr(r)rØrnroZmodesÚerJr*r*r+r~sˆ    "     !                        ,    zTarFile.__init__c KsG| r| rtdƒ‚n|dkráx¦|jD]›}t||j|ƒ}|dk rj|jƒ}ny||d||�SWq3ttfk rÍ} z$|dk r¸|j|ƒnw3WYdd} ~ Xq3Xq3Wtdƒ‚nVd|krh|jddƒ\} }| pd} |pd}||jkrEt||j|ƒ}ntd |ƒ‚||| ||�Sd |kr|jd dƒ\} }| p•d} |p¡d}| dkr¿td ƒ‚nt|| |||ƒ} y||| | |�} Wn| j ƒ‚YnXd | _ | S|dkr7|j ||||�Stdƒ‚dS)a‚Open a tar archive for reading, writing or appending. Return an appropriate TarFile class. mode: 'r' or 'r:*' open for reading with transparent compression 'r:' open for reading exclusively uncompressed 'r:gz' open for reading with gzip compression 'r:bz2' open for reading with bzip2 compression 'r:xz' open for reading with lzma compression 'a' or 'a:' open for appending, creating the file if necessary 'w' or 'w:' open for writing without compression 'w:gz' open for writing with gzip compression 'w:bz2' open for writing with bzip2 compression 'w:xz' open for writing with lzma compression 'r|*' open a stream of tar blocks with transparent compression 'r|' open an uncompressed stream of tar blocks for reading 'r|gz' open a gzip compressed stream of tar blocks 'r|bz2' open a bzip2 compressed stream of tar blocks 'r|xz' open an lzma compressed stream of tar blocks 'w|' open an uncompressed stream for writing 'w|gz' open a gzip compressed stream for writing 'w|bz2' open a bzip2 compressed stream for writing 'w|xz' open an lzma compressed stream for writing znothing to openrsúr:*Nz%file could not be opened successfullyú:rrˆzunknown compression type %rú|rtzmode must be 'r' or 'w'Frezundiscernible mode)rsru)rsrt)rert) r<Ú OPEN_METHr`r­rjrkr®rKr�r€r‰Útaropen) r r~r\r�rŽÚkwargsrŒÚfuncZ saved_posrtr[Ústreamr²r*r*r+rësN             z TarFile.opencKs.|dkrtdƒ‚n|||||�S)zCOpen uncompressed tar archive name for reading or writing. rsrertzmode must be 'r', 'a' or 'w')rsrert)r<)r r~r\r�rzr*r*r+ry;s zTarFile.taropenržcKs2|d krtdƒ‚nyddl}|jWn$ttfk rXtdƒ‚YnXy |j||d||ƒ}Wn<tk r·|dk r°|dkr°tdƒ‚n‚YnXy|j||||�}WnNtk r|j ƒ|dkr tdƒ‚n‚Yn|j ƒ‚YnXd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rsrtzmode must be 'r' or 'w'rNzgzip module is not availablerVznot a gzip fileF)rsrt) r<ÚgzipZGzipFiler’ÚAttributeErrorrkršrjryr€r‰)r r~r\r�Ú compresslevelrzr}r²r*r*r+ÚgzopenCs2          zTarFile.gzopencKsê|d krtdƒ‚nyddl}Wntk rKtdƒ‚YnX|j|p[||d|ƒ}y|j||||�}WnTttfk rÈ|jƒ|dkrÁt dƒ‚n‚Yn|jƒ‚YnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rsrtzmode must be 'r' or 'w'.rNzbz2 module is not availablerznot a bzip2 fileF)rsrt) r<r†r’rkZBZ2FileryršÚEOFErrorr€rjr‰)r r~r\r�rrzr†r²r*r*r+Úbz2openes(       zTarFile.bz2opencKsí|d krtdƒ‚nyddl}Wntk rKtdƒ‚YnX|j|p[||d|ƒ}y|j||||�}WnW|jtfk rË|jƒ|dkrÄt dƒ‚n‚Yn|jƒ‚YnXd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rsrtzmode must be 'r' or 'w'rNzlzma module is not availableÚpresetznot an lzma fileF)rsrt) r<r›r’rkZLZMAFileryrœr�r€rjr‰)r r~r\r�rƒrzr›r²r*r*r+Úxzopen‚s&      zTarFile.xzopenryrˆr€r…r‚r†r„r‡c Cs·|jr dSd|_z€|jdkr•|jjttdƒ|jtd7_t|jtƒ\}}|dkr•|jjtt|ƒq•nWd|j s²|jj ƒnXdS)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrgrr) r�r\r�rQr%r´rºrOÚ RECORDSIZEr‰r€)r}rTrUr*r*r+r€©s   " z TarFile.closecCs2|j|ƒ}|dkr.td|ƒ‚n|S)aReturn a TarInfo object for member `name'. If `name' can not be found in the archive, KeyError is raised. If a member occurs more than once in the archive, its last occurrence is assumed to be the most up-to-date version. Nzfilename %r not found)Ú _getmemberÚKeyError)r}r~rÑr*r*r+Ú getmember¾s zTarFile.getmembercCs'|jƒ|js |jƒn|jS)zŽReturn the members of the archive as a list of TarInfo objects. The list has the same order as the members in the archive. )Ú_checkrqÚ_loadrp)r}r*r*r+Ú getmembersÉs   zTarFile.getmemberscCsdd„|jƒDƒS)z‹Return the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). cSsg|]}|j‘qSr*)r~)rGrÑr*r*r+rI×s z$TarFile.getnames..)r‹)r}r*r*r+ÚgetnamesÓszTarFile.getnamesc Cs^|jdƒ|dk r%|j}n|dkr:|}ntjj|ƒ\}}|jtjdƒ}|jdƒ}|jƒ}||_ |dkrÔt tdƒrÂ|j rÂtj |ƒ}qétj |ƒ}ntj|jƒƒ}d}|j}t j|ƒr�|j|jf} |j rj|jdkrj| |jkrj||j| krjt} |j| }qt} | dr||j| zlink to )r‰rdrZr[r\r rr!rrWrYrÖr×rr¤Z localtimerr~r!rSrÕrUrc)r}ÚverboserÑr*r*r+rE;s&  !#  z TarFile.listÚfilterc Csü|jdƒ|dkr"|}n|dk rtddl}|jdtdƒ||ƒrt|jdd|ƒdSn|jdk r¶tjj|ƒ|jkr¶|jdd|ƒdS|jd|ƒ|j ||ƒ}|dkrü|jdd |ƒdS|dk r;||ƒ}|dkr;|jdd|ƒdSn|j ƒrrt |d ƒ�}|j ||ƒWdQXn†|j ƒrë|j |ƒ|røxTtj|ƒD]@}|jtjj||ƒtjj||ƒ||d |ƒq¡Wqøn |j |ƒdS) a~Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.). If given, `arcname' specifies an alternative name for the file in the archive. Directories are added recursively by default. This can be avoided by setting `recursive' to False. `exclude' is a function that should return True for each filename to be excluded. `filter' is a function that expects a TarInfo object argument and returns the changed TarInfo object, if it returns None the TarInfo object will be excluded from the archive. rgNrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rrdr«)r‰rWrXrYÚ_dbgr~rvrrkr©r1rjÚaddfiler!ÚlistdirÚaddr±) r}r~r¨Z recursiveZexcluder«rWrÑÚfr*r*r+r¯XsB        *       *z TarFile.addcCsô|jdƒtj|ƒ}|j|j|j|jƒ}|jj|ƒ|jt |ƒ7_|dk ràt ||j|j ƒt |j t ƒ\}}|dkrÊ|jjtt |ƒ|d7}n|j|t 7_n|jj|ƒdS)a]Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size. rgNrr)r‰rrìrFr(r)r�rQrºr$rNrrOr´r%rpr°)r}rÑr�rJrTrUr*r*r+r­•s    zTarFile.addfileÚ.cCsOg}|dkr|}nx_|D]W}|jƒr\|j|ƒtj|ƒ}d|_n|j||d|jƒ ƒq"W|jddd„ƒ|jƒx«|D]£}tjj ||j ƒ}y4|j ||ƒ|j ||ƒ|j ||ƒWq¤tk rF}z.|jdkr ‚n|jdd|ƒWYdd}~Xq¤Xq¤WdS) aMExtract all members from the archive to the current working directory and set owner, modification time and permissions on directories afterwards. `path' specifies a different directory to extract to. `members' is optional and must be a subset of the list returned by getmembers(). NiÀÚ set_attrsÚkeycSs|jS)N)r~)rer*r*r+ÚÅsz$TarFile.extractall..rz tarfile: %s)r!r°rr\ÚextractÚsortÚreverservrr±r~ÚchownÚutimeÚchmodriror¬)r}rrpZ directoriesrÑÚdirpathrtr*r*r+Ú extractall¯s*      !  zTarFile.extractallrƒcCsa|jdƒt|tƒr.|j|ƒ}n|}|jƒr^tjj||jƒ|_ ny,|j |tjj||j ƒd|ƒWnÐt k r}zc|j dkr´‚nI|jdkrÝ|jdd|jƒn |jdd|j|jfƒWYdd}~XnNtk r\}z.|j dkr6‚n|jdd|ƒWYdd}~XnXdS)axExtract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately as possible. `member' may be a filename or a TarInfo object. You can specify a different directory using `path'. File attributes (owner, mtime, mode) are set unless `set_attrs' is False. rsr²rNrz tarfile: %sztarfile: %s %r)r‰rrrˆrUrvrr±rÕrÚÚ_extract_memberr~ršroÚfilenamer¬Ústrerrorri)r}Úmemberrr²rÑrtr*r*r+rµÕs&  ! 2zTarFile.extractcCs¹|jdƒt|tƒr.|j|ƒ}n|}|jƒsO|jtkr_|j||ƒS|jƒsw|j ƒr±t|j t ƒr˜t dƒ‚qµ|j |j|ƒƒSndSdS)züExtract a member from the archive as a file object. `member' may be a filename or a TarInfo object. If `member' is a regular file or a link, an io.BufferedReader object is returned. Otherwise, None is returned. rsz'cannot extract (sym)link as file objectN)r‰rrrˆr1rÔr2Ú fileobjectrUrSr�r�rlÚ extractfileÚ_find_link_target)r}rÀrÑr*r*r+rÂøs zTarFile.extractfilecCsÞ|jdƒ}|jdtjƒ}tjj|ƒ}|r_tjj|ƒ r_tj|ƒn|jƒsw|j ƒrš|j dd|j |j fƒn|j d|j ƒ|j ƒrÌ|j||ƒnÆ|jƒrë|j||ƒn§|jƒr |j||ƒnˆ|jƒs"|jƒr5|j||ƒn]|jƒsM|j ƒr`|j||ƒn2|jtkr‚|j||ƒn|j||ƒ|rÚ|j||ƒ|j ƒsÚ|j||ƒ|j||ƒqÚndS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rârz%s -> %sN)r"r rvr‘rÚdirnameriÚmakedirsrUrSr¬r~rÕr1Úmakefiler!Úmakedirr[ÚmakefiforWrYÚmakedevÚmakelinkrÔr2Ú makeunknownr¸rºr¹)r}rÑÚ targetpathr²Z upperdirsr*r*r+r½s4#    zTarFile._extract_memberc Cs-ytj|dƒWntk r(YnXdS)z,Make a directory called targetpath. iÀN)rvÚmkdirÚFileExistsError)r}rÑrÌr*r*r+rÇGs zTarFile.makedirc Cs±|j}|j|jƒt|dƒ�ƒ}|jdk rwxP|jD],\}}|j|ƒt|||tƒqDWnt|||jtƒ|j|jƒ|jƒWdQXdS)z'Make a file called targetpath. rfN) r�r®rÍrjrÎrNrjrÚtruncate)r}rÑrÌÚsourceÚtargetrºrr*r*r+rÆQs  zTarFile.makefilecCs+|j||ƒ|jdd|jƒdS)zYMake a file from a TarInfo object with an unknown type at targetpath. rz9tarfile: Unknown file type %r, extracted as regular file.N)rÆr¬rÔ)r}rÑrÌr*r*r+rË`s zTarFile.makeunknowncCs/ttdƒrtj|ƒn tdƒ‚dS)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)r{rvrÒri)r}rÑrÌr*r*r+rÈhszTarFile.makefifocCsŠttdƒ s ttdƒ r/tdƒ‚n|j}|jƒrT|tjO}n |tjO}tj||tj |j |j ƒƒdS)zzShow listing of a tarfilez-ez --extractÚnargsú+ú zExtract tarfile into target dirz-cz--createúúzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrsrçz{!r} is a tar archive.rz{!r} is not a tar archive. zr:*rªrrr±z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r…z.gzz.tgzr‡z.xzz.txzr†z.bz2z.tbzz.tbz2z.tb2zw:rtz{!r} file created.)rörù)rúrû)ÚargparseÚArgumentParserÚ add_argumentZadd_mutually_exclusive_groupÚ parse_argsZtestrrr‹rcrarèrªrFÚexitrErrµr$rvÚcurdirZ format_helpr¼ÚcreateÚpoprÚsplitextr¯)rürðÚparserr;ÚargsrRrˆZtfrrêZtar_nameÚ_ZextZ compressionsZtar_modeZ tar_filesÚ file_namer*r*r+Úmain† sŠ                        r Ú__main__)brhÚversionÚ __author__Z__date__Z __cvsid__Ú __credits__ÚbuiltinsrrjrarvrÁrMrZr¤rIrr9r¦r¤r’r~ÚNotImplementedErrorrØršÚ NameErrorÚ__all__r%r´r…rôrïrñrðr rÛrrTrRrVrXrãrZZCONTTYPEr÷rörrrr.rçrBrêr`r2rPr#rMr@rr:rNr~raÚgetfilesystemencodingr,r1r@rGrKrNr[rdÚ Exceptionrrirjrkrlrmrnrorpr=rqrrr�ÚobjectrŠr¹ÚBufferedReaderrÌrrrårr rer*r*r*r+ÚsÞ                             úh ÿÿ“ÿÿÿî)  Z