grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ”qcŽkã@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:d,e;d-e;d'e;d(e<d)e<d&e<iZ=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`ƒdS)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/python35/lib64/python3.5/tarfile.pyÚstn™sr,cCs;|jdƒ}|dkr+|d|…}|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 krd}x:tt|ƒdƒD]"}|dK}|||d7}q-W|ddkrÑdt|ƒd| }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||ƒ\}}xNt|ƒD]@}|j|ƒ}t|ƒ|kr‹|dƒ‚|j|ƒqXW|dkrâ|j|ƒ}t|ƒ|krÕ|dƒ‚|j|ƒdS)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[cCsPttjddƒ}|dk r<|j|dƒj|ƒ}t|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. cCsbdtjdtjtjBtjBi|}ttdƒrF|tjO}tj||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|_|dkr-t||ƒ}d|_|dkrQt|ƒ}|jƒ}|pZd|_||_||_||_||_d|_ d|_ d|_ y«|dkr,yddl }Wnt k rÞtd ƒ‚YnX||_ |jdƒ|_|d kr|jƒ|j|_qI|jƒn|d kr«yddl}Wnt k rhtd ƒ‚YnX|d kr™d|_|jƒ|_t|_qI|jƒ|_nž|d kr-yddl}Wnt k rçtdƒ‚YnX|d krd|_|jƒ|_|j|_qI|jƒ|_n|dkrItd|ƒ‚Wn*|jsf|jjƒd|_ ‚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ƒdS)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 …|_ |j |j j d d ƒtƒdS) z6Initialize for writing with gzip compression. é rzd?„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+Ú _getlinkpathûszTarInfo._getlinkpathcCs ||_dS)N)rÕ)r}rÕr*r*r+Ú _setlinkpathýszTarInfo._setlinkpathcCs d|jj|jt|ƒfS)Nz<%s %r at %#x>)rÒrer~Úid)r}r*r*r+Ú__repr__szTarInfo.__repr__cCsµd|jd|jd@d|jd|jd|jd|jd|jd |jd |jd |j d |j d |j d|j i }|d t kr±|djdƒ r±|dd7<|S)z9Return the TarInfo's attributes as a dictionary. r~r\iÿrrrrrÓrÔrÕr r!rÖr×ú/)r~r\rrrrrÓrÔrÕr r!rÖr×ÚDIRTYPEr¦)r}Úinfor*r*r+Úget_infos             $zTarInfo.get_infoÚsurrogateescapecCsv|jƒ}|tkr+|j|||ƒS|tkrJ|j|||ƒS|tkrf|j||ƒStdƒ‚dS)zy||jd d ƒWn#tk r™||||YnXt||ƒ|kr>||||Wx…dD]}\}}||krîd||r0rär*r*r+rÃs<      1   z"TarInfo._create_pax_generic_headerc CsNt|ƒdkrtdƒ‚t|ƒtkr<tdƒ‚|jtƒtkr]tdƒ‚t|dd…ƒ}|t|ƒkr‘t dƒ‚|ƒ}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…||ƒ}|jtkr'|j jdƒr't|_|jtkrd}g}xƒtdƒD]u} y<t|||d…ƒ} t||d|d…ƒ} Wntk r¦PYnX|j| | fƒ|d7}qOWt|dƒ} t|dd…ƒ} || | f|_ |j!ƒr!|j j"dƒ|_ |rJ|jt#krJ|d|j |_ |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)rrJr(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)rrÐrJr#r*r*r+Ú fromtarfile5szTarInfo.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)Js   zTarInfo._proc_membercCsu|jjƒ|_|j}|jƒs6|jtkrL||j|jƒ7}||_|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+r/Ws  zTarInfo._proc_builtinc Cs¹|jj|j|jƒƒ}y|j|ƒ}Wntk rQtdƒ‚YnX|j|_|jt kr‹t ||j |j ƒ|_ n*|jtkrµt ||j |j ƒ|_|S)zSProcess the blocks that hold a GNU longname or longlink member. z missing or bad subsequent header)r�rPr2rr*rmrqrºrÔr÷r1r(r)r~rörÕ)r}rÐrJÚnextr*r*r+r+hs  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ƒ|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°rrÎr­rÍr2rrº) 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ƒ|d<|j dƒ}|dkr©|j }nd}tjdƒ}d}xà|j||ƒ}|sàP|jƒ\} } t| ƒ} ||jd ƒd|jdƒ| d…} |j| dd|jƒ} | tkrt|j| ||j |jƒ} n|j| dd|jƒ} | || <|| 7}qÇWy|j|ƒ} Wntk rÚtd ƒ‚YnXd |krú|j| |ƒn_d |kr|j| ||ƒn=|j d ƒdkrY|j dƒdkrY|j| ||ƒ|jttfkrâ| j||j |jƒ|j | _ d|krâ| j!} | j"ƒsÃ| jt#krÙ| | j| jƒ7} | |_ | S)zVProcess an extended or global header as described in POSIX.1-2008. s\d+ hdrcharset=([^\n]+)\nNrzutf-8Ú hdrcharsetZBINARYs(\d+) ([^=]+)=rrz missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorr8r)$r�rPr2rrÔrrØrþÚreÚsearchÚgroupr/r r(ÚcompileÚmatchÚgroupsr:r^rÉÚ_decode_pax_fieldr)ÚPAX_NAME_FIELDSr*rmrqÚ_proc_gnusparse_01Ú_proc_gnusparse_00Ú_proc_gnusparse_10rr-r3rºrÍr0r1)r}rÐrJrØr<r6r(Zregexr�r'rrr4rºr*r*r+r.šs`     .        *    zTarInfo._proc_paxcCsšg}x6tjd|ƒD]"}|jt|jdƒƒƒqWg}x6tjd|ƒD]"}|jt|jdƒƒƒqXWtt||ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.0. s\d+ GNU.sparse.offset=(\d+)\nrs\d+ GNU.sparse.numbytes=(\d+)\nN)r8Úfinditerr°r:r:ÚlistÚziprÎ)r}r4rØrJZoffsetsr<r%r*r*r+rAs  zTarInfo._proc_gnusparse_00cCsVdd„|djdƒDƒ}tt|ddd…|ddd…ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|]}t|ƒ‘qSr*)r:)Ú.0Úxr*r*r+ú s z.TarInfo._proc_gnusparse_01..zGNU.sparse.mapú,Nrr)r rDrErÎ)r}r4rØrÎr*r*r+r@ s zTarInfo._proc_gnusparse_01cCsôd}g}|jjtƒ}|jddƒ\}}t|ƒ}xgt|ƒ|dkr«d|kr}||jjtƒ7}|jddƒ\}}|jt|ƒƒqEW|jjƒ|_t t |ddd…|ddd…ƒƒ|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Ns rr) r�rPr´r r:r$r°r­rÍrDrErÎ)r}r4rØrÐZfieldsrÎrJZnumberr*r*r+rBs  zTarInfo._proc_gnusparse_10c Cs xõ|jƒD]ç\}}|dkr8t|d|ƒq |dkr]t|dt|ƒƒq |dkr‚t|dt|ƒƒq |tkr |tkrÉyt||ƒ}Wntk rÈd}YnX|dkrä|jdƒ}t|||ƒ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!rþrØ)r}rØr(r)rrr*r*r+r3!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>8s zTarInfo._decode_pax_fieldcCs-t|tƒ\}}|r%|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r)rOr´)r}rrTrUr*r*r+r2@s zTarInfo._blockcCs |jtkS)N)rÔÚ REGULAR_TYPES)r}r*r*r+r0Isz TarInfo.isregcCs |jƒS)N)r0)r}r*r*r+ÚisfileKszTarInfo.isfilecCs |jtkS)N)rÔrã)r}r*r*r+r Msz TarInfo.isdircCs |jtkS)N)rÔÚSYMTYPE)r}r*r*r+ÚissymOsz TarInfo.issymcCs |jtkS)N)rÔÚLNKTYPE)r}r*r*r+ÚislnkQsz TarInfo.islnkcCs |jtkS)N)rÔÚCHRTYPE)r}r*r*r+ÚischrSsz TarInfo.ischrcCs |jtkS)N)rÔÚBLKTYPE)r}r*r*r+ÚisblkUsz TarInfo.isblkcCs |jtkS)N)rÔÚFIFOTYPE)r}r*r*r+ÚisfifoWszTarInfo.isfifocCs |jdk S)N)rÎ)r}r*r*r+ÚissparseYszTarInfo.issparsecCs|jtttfkS)N)rÔrTrVrX)r}r*r*r+Úisdev[sz TarInfo.isdevN)r~r\rrrrrÓrÔrÕr r!rÖr×rºrÍrØrÎrÐrÙrÚ)4rerfrgrhÚ __slots__rrÜrÝÚpropertyrrÞrßrráråÚDEFAULT_FORMATÚENCODINGrìrèrérëÚ classmethodrròÚ staticmethodrór rõrr(r*r)r/r+r,r.rAr@rBr3r>r2r0rOr rQrSrUrWrYrZr[r*r*r*r+rÍs`         1  3?    f             c@sÔeZdZdZdZdZdZdZeZ e Z dZ e ZeZdddddddddddddd „ Zeddded d „ƒZeddd d „ƒZeddddd„ƒZeddddd„ƒZeddddd„ƒZddddddddiZdd„Zdd „Zd!d"„Zd#d$„Zdddd%d&„Zd'd(dd)d*„Zdd'dd+dd,d-„Z dd.d/„Z!d0dd1dd2d3„Z"d4d'd1dd5d6„Z#d7d8„Z$d'dd9d:„Z%d;d<„Z&d=d>„Z'd?d@„Z(dAdB„Z)dCdD„Z*dEdF„Z+dGdH„Z,dIdJ„Z-dKdL„Z.dMdN„Z/dddOdP„Z0dQdR„Z1ddSdT„Z2dUdV„Z3dWdX„Z4dYdZ„Z5d[d\„Z6d]d^„Z7dS)_rz=The TarFile Class provides an interface to tar archives. rFrNrsræc Cs›ddddddddi} || kr6td ƒ‚||_| ||_|s¤|jdkr†tjj|ƒ r†d|_d|_t||jƒ}d |_n`|d kràt|d ƒràt |j t t fƒrà|j }t|d ƒrû|j|_d|_|rtjj |ƒnd |_ ||_|d k rC||_|d k rX||_|d k rm||_|d k r‚||_|d k r—||_| |_| d k rÇ|jtkrÇ| |_n i|_| d k rå| |_| d k rú| |_d |_g|_d |_|jjƒ|_i|_y:|jdkrZd |_|j ƒ|_|jdkrxœ|jj!|jƒy&|jj"|ƒ}|jj#|ƒWqlt$k rÍ|jj!|jƒPYqlt%k r}zt&t |ƒƒ‚WYd d }~XqlXqlW|jdkrid|_|jri|jj'|jj(ƒƒ}|jj)|ƒ|jt*|ƒ7_Wn*|js†|jj+ƒd|_‚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. rsÚrbÚazr+brtÚwbrGZxbz!mode must be 'r', 'a', 'w' or 'x'FNr~r\T)rcrtrG),r<r\Ú_modervrÚexistsÚ bltn_openr‰r{rr~rrAÚabspathr�rFrÑÚ dereferenceÚ ignore_zerosr(r)rêrØÚdebugÚ errorlevelr�ÚmembersÚ_loadedr­rºÚinodesÚ firstmemberr4r®r*r°rprmrjrrþrQr$r€)r}r~r\r�rFrÑrirjr(r)rØrkrlZmodesÚerJr*r*r+rysˆ     "      !                        )     zTarFile.__init__c sY| r| rtdƒ‚|dkrö‡fdd†}x¬tˆjd|ƒD]•}tˆˆj|ƒ}|dk r‚|jƒ} y||d||�SWqNttfk râ} z!|dk rÍ|j| ƒwNWYdd} ~ XqNXqNWtdƒ‚nSd |kr}|jd d ƒ\} }| p#d} |p/d }|ˆjkrZtˆˆj|ƒ}ntd |ƒ‚||| ||�Sd |kr'|jd d ƒ\} }| pªd} |p¶d }| dkrÑtdƒ‚t || |||ƒ} yˆ|| | |�} Wn| j ƒ‚YnXd| _ | S|dkrIˆ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 'x' or 'x:' create a tarfile exclusively without compression, raise an exception if the file is already created 'x:gz' create a gzip compressed tarfile, raise an exception if the file is already created 'x:bz2' create a bzip2 compressed tarfile, raise an exception if the file is already created 'x:xz' create an lzma compressed tarfile, raise an exception if the file is already created '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:*csˆj|dkS)NÚtaropen)Ú OPEN_METH)rŒ)rr*r+Únot_compressedsz$TarFile.open..not_compressedÚkeyNz%file could not be opened successfullyú:rrˆzunknown compression type %rú|rtzmode must be 'r' or 'w'FrcrGzundiscernible mode)rsrr)rsrt)rcrtrG) r<Úsortedrtr`r­rjrkr®r r�r€r‰rs)rr~r\r�rŽÚkwargsrurŒÚfuncZ saved_posrqr[Ústreamr²r*)rr+ræsP%                 z TarFile.opencKs+|dkrtdƒ‚|||||�S)zCOpen uncompressed tar archive name for reading or writing. rsrcrtrGz!mode must be 'r', 'a', 'w' or 'x')rsrcrtrG)r<)rr~r\r�rzr*r*r+rsAs  zTarFile.taropenržcKs)|d krtdƒ‚yddl}|jWn$ttfk rUtdƒ‚YnXy |j||d||ƒ}Wn9tk r±|dk rª|dkrªtd ƒ‚‚YnXy|j||||�}WnKtk r|j ƒ|dkrtd ƒ‚‚Yn|j ƒ‚YnXd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rsrtrGzmode must be 'r', 'w' or 'x'rNzgzip module is not availablerVznot a gzip fileF)rsrtrG) r<ÚgzipZGzipFiler’ÚAttributeErrorrkršrjrsr€r‰)rr~r\r�Ú compresslevelrzr}r²r*r*r+ÚgzopenIs2             zTarFile.gzopencKsä|d krtdƒ‚yddl}Wntk rHtdƒ‚YnX|j|pX||d|ƒ}y|j||||�}WnQttfk rÂ|jƒ|dkr»t d ƒ‚‚Yn|jƒ‚YnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rsrtrGzmode must be 'r', 'w' or 'x'rNzbz2 module is not availablerznot a bzip2 fileF)rsrtrG) r<r†r’rkZBZ2FilersršÚEOFErrorr€rjr‰)rr~r\r�rrzr†r²r*r*r+Úbz2openks(         zTarFile.bz2opencKsç|d krtdƒ‚yddl}Wntk rHtdƒ‚YnX|j|pX||d|ƒ}y|j||||�}WnT|jtfk rÅ|jƒ|dkr¾t d ƒ‚‚Yn|jƒ‚YnXd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rsrtrGzmode must be 'r', 'w' or 'x'rNzlzma module is not availableÚpresetznot an lzma fileF)rsrtrG) r<r›r’rkZLZMAFilersrœr�r€rjr‰)rr~r\r�rƒrzr›r²r*r*r+Úxzopenˆs&        zTarFile.xzopenrˆrsr…r€r†r‚r‡r„c Cs®|jr dSd|_zz|jdkr�|jjttdƒ|jtd7_t|jtƒ\}}|dkr�|jjtt|ƒWd|j s©|jj ƒXdS) zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrcrtrGrr)rcrtrG) r�r\r�rQr%r´rºrOÚ RECORDSIZEr‰r€)r}rTrUr*r*r+r€¯s    z TarFile.closecCs/|j|ƒ}|dkr+td|ƒ‚|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ƒ|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. )Ú_checkrnÚ_loadrm)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~)rFrÑr*r*r+rHÝs z$TarFile.getnames..)r‹)r}r*r*r+ÚgetnamesÙszTarFile.getnamesc CsI|jdƒ|dk r"|j}|dkr4|}tjj|ƒ\}}|jtjdƒ}|jdƒ}|jƒ}||_ |dkrÎt tdƒr¼|j r¼tj |ƒ}qãtj |ƒ}ntj|jƒƒ}d}|j}t j|ƒr„|j|jf} |j rd|jdkrd| |jkrd||j| krdt} |j| }qt} | dr||j| zlink to )r‰rdrZr[r\r rr!rrUrWrÖr×rr¤Z localtimerr~r rQrÕrSrc)r}ÚverbosermrÑr*r*r+rDCs*   #  z TarFile.listÚfilterc Csñ|jdƒ|dkr|}|dk rnddl}|jdtdƒ||ƒrn|jdd|ƒdS|jdk r°tjj|ƒ|jkr°|jdd|ƒdS|jd|ƒ|j ||ƒ}|dkrö|jdd |ƒdS|dk r2||ƒ}|dkr2|jdd|ƒdS|j ƒrjt |d ƒ�}|j ||ƒWdQRXnƒ|j ƒrà|j |ƒ|ríxatj|ƒD]@}|jtjj||ƒtjj||ƒ||d |ƒq™Wn |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. r�Nrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rrbr­)r‰rWrXrYÚ_dbgr~rvrrhr«r0rgÚaddfiler ÚlistdirÚaddr±) r}r~r©Z recursiveZexcluder­rWrÑÚfr*r*r+r±csB       *       *z TarFile.addcCsî|jdƒtj|ƒ}|j|j|j|jƒ}|jj|ƒ|jt |ƒ7_|dk rÚt ||j|j ƒt |j t ƒ\}}|dkrÇ|jjtt |ƒ|d7}|j|t 7_|jj|ƒdS)aAdd the TarInfo object `tarinfo' to the archive. If `fileobj' is given, it should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by using gettarinfo(). r�Nrr)r‰rþrìrFr(r)r�rQrºr$rNrrOr´r%rmr°)r}rÑr�rJrTrUr*r*r+r¯ s    zTarFile.addfileÚ.Ú numeric_ownercCsUg}|dkr|}xb|D]Z}|jƒrV|j|ƒtj|ƒ}d|_|j||d|jƒ d|ƒqW|jddd„ƒ|jƒx±|D]©}tjj ||j ƒ}y:|j ||d|ƒ|j ||ƒ|j ||ƒWq¤tk rL}z.|jdkr&‚n|jdd |ƒWYdd}~Xq¤Xq¤WdS) a¶Extract 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(). If `numeric_owner` is True, only the numbers for user/group names are used and not the names. NiÀÚ set_attrsr´rvcSs|jS)N)r~)rcr*r*r+ÚÑsz$TarFile.extractall..rz tarfile: %s)r r°rþr\ÚextractÚsortÚreverservrr±r~ÚchownÚutimeÚchmodrirlr®)r}rrmr´Z directoriesrÑÚdirpathrqr*r*r+Ú extractall¹s,        zTarFile.extractallrƒcCsd|jdƒt|tƒr.|j|ƒ}n|}|jƒr[tjj||jƒ|_ y2|j |tjj||j ƒd|d|ƒWnÐt k r}zc|j dkr·‚nI|jdkrà|jdd|jƒn |jdd|j|jfƒWYdd}~XnNtk r_}z.|j dkr9‚n|jdd|ƒWYdd}~XnXdS) aìExtract 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. If `numeric_owner` is True, only the numbers for user/group names are used and not the names. rsrµr´rNrz tarfile: %sztarfile: %s %r)r‰rrrˆrSrvrr±rÕrÚÚ_extract_memberr~ršrlÚfilenamer®Ústrerrorri)r}Úmemberrrµr´rÑrqr*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ˆr0rÔr1Ú fileobjectrSrQr�r�rlÚ extractfileÚ_find_link_target)r}rÂrÑr*r*r+rÄs zTarFile.extractfilecCsØ|jdƒ}|jdtjƒ}tjj|ƒ}|r\tjj|ƒ r\tj|ƒ|jƒst|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ƒr2|j||ƒn]|jƒsJ|j ƒr]|j||ƒn2|jtkr|j||ƒn|j||ƒ|rÔ|j|||ƒ|j ƒsÔ|j||ƒ|j||ƒdS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rârz%s -> %sN)r!r rvr’rÚdirnamerfÚmakedirsrSrQr®r~rÕr0Úmakefiler ÚmakedirrYÚmakefiforUrWÚmakedevÚmakelinkrÔr1Ú makeunknownrºr¼r»)r}rÑÚ targetpathrµr´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ÉWs zTarFile.makedirc Cs²|j}|j|jƒt|dƒ�ƒ}|jdk r‘x7|jD],\}}|j|ƒt|||tƒqDW|j|jƒ|jƒnt|||jtƒWdQRXdS)z'Make a file called targetpath. rdN) r�r®rÍrgrÎrNrjrÚtruncate)r}rÑrÎÚsourceÚtargetrºrr*r*r+rÈas   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Íps 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ÊxszTarFile.makefifocCs‡ttdƒ s ttdƒ r,tdƒ‚|j}|jƒrQ|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.z.gzr…z.tgzz.xzr‡z.txzz.bz2r†z.tbzz.tbz2z.tb2zw:rtz{!r} file created.)rørû)rürý)ÚargparseÚArgumentParserÚ add_argumentZadd_mutually_exclusive_groupÚ parse_argsZtestrrr‹rcrarêr¬rFÚexitrDrr·r$rvÚcurdirZ format_helpr¾ZcreateÚ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__ÚbuiltinsrrgrarvrÁrMrZr¤rIrþr8r§r¥r’r~ÚNotImplementedErrorrÚršÚ NameErrorÚ__all__r%r´r…rôrïrñrðr rÛrrRrPrTrVrãrXZCONTTYPEr÷rörrrr-rçrBrêr^r1rNr"rKr?rr:rLr~r_Úgetfilesystemencodingr,r1r@rGrKrNr[rdÚ Exceptionrrirjrkrlrmrnrorpr=rqrrr�ÚobjectrŠr¹ÚBufferedReaderrÌrrrçrr rer*r*r*r+ÚsÞ                             ôh ÿÿ”ÿÿÿÿ )  Z