grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 ct„j ´ã'@sBdZdZdZdZdZdZddlmZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZy ddlZWnek r˜dZYnXy ddlZWnek r¾dZYnXeefZyeef7ZWnek rêYnXd d d d d ddddddddddgZdZdZdZdZedZ dZ!dZ"dZ#dZ$d Z%d!Z&dZ'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4dZ5d/Z6d0Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1f Z9e&e'e.e1fZ:e/e0e1fZ;d…Ze>e>e?e?e?d9œZ@e jAd:k�rìd;ZBne jCƒZBdd?„ZEd@dA„ZFdBe8fdCdD„ZGdEdF„ZHdedfdGdH„ZIdIdJ„ZJdKdL„ZKGdMd „d eLƒZMGdNd„deMƒZNGdOd „d eMƒZOGdPd„deMƒZPGdQd„deMƒZQGdRd„deMƒZRGdSdT„dTeRƒZSGdUdV„dVeRƒZTGdWdX„dXeRƒZUGdYdZ„dZeRƒZVGd[d\„d\eRƒZWGd]d^„d^ƒZXGd_d`„d`ƒZYGdadb„dbeZƒZ[Gdcdd„ddeZƒZ\Gdedf„dfe j]ƒZ^Gdgdh„dheMƒZ_Gdidj„dje_ƒZ`Gdkdl„dle_ƒZaGdmdn„dne_ƒZbGdodp„dpe_ƒZcGdqdr„dre_ƒZdGdsdt„dte_ƒZee_eeNfZfd†dudv„Zgdwdx„Zhdydz„Zid{d|„Zjeheiejd}œZkeZƒZlejmd~ƒZnGdd „d eZƒZoGd€d „d eZƒZpd�d „ZqepjZd‚dƒ„Zresd„k�r>erƒdS)‡z,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ÚTarErrorÚ ReadErrorÚCompressionErrorÚ StreamErrorÚ ExtractErrorÚ HeaderErrorÚENCODINGÚ USTAR_FORMATÚ GNU_FORMATÚ PAX_FORMATÚDEFAULT_FORMATrTz/etc/python/tarfile.cfgóiésustar sustar00édé›ó0ó1ó2ó3ó4ó5ó6ó7óLóKóSóxógóXééÚpathÚlinkpathÚsizeÚmtimeÚuidÚgidÚunameÚgname)ZatimeZctimer(r)r*r'Úntzutf-8cCs8|dkrtdƒ‚|j||ƒ}|d|…|t|ƒtS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None)Ú ValueErrorÚencodeÚlenÚNUL)ÚsÚlengthÚencodingÚerrors©r6ú/usr/lib64/python3.6/tarfile.pyÚstn©s r8cCs*|jdƒ}|dkr|d|…}|j||ƒS)z8Convert a null-terminated bytes object to a string. rr#Néÿÿÿÿ)ÚfindÚdecode)r2r4r5Úpr6r6r7Únts±s  r=c Csª|dd krfd}x0tt|ƒdƒD]}|dK}|||d7}q"W|ddkr¦dt|ƒd| }n@y"t|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)r>r?)Úranger0r=ÚintÚstripr.ÚInvalidHeaderError)r2ÚnÚir6r6r7Únti¹s   rKr@cCsÜt|ƒ}d|ko"d|dknrDtd|d|fdƒt}n”|tkrÐd|d |kopd|dknrÐ|dkrŠtdgƒ}ntdgƒ}d||}x6t|dƒD]}|jd|d@ƒ|dL}q®Wntd ƒ‚|S) z/Convert a python number to a number field. rr@r#z%0*orBrAr>r?zoverflow in number field)rFÚbytesr1rÚ bytearrayrEÚinsertr.)rIÚdigitsÚformatr2rJr6r6r7ÚitnÍs  2   rQcCs0dttjd|ƒƒ}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. rAZ 148B8x356BZ 148b8x356b)ÚsumÚstructZ unpack_from)ÚbufZunsigned_chksumZ signed_chksumr6r6r7Ú calc_chksumsês rUc Csª|pd}|dkrdS|dkr.tj|||ƒdSt||ƒ\}}x8t|ƒD],}|j|ƒ}t|ƒ|krh|dƒ‚|j|ƒqFW|dkr¦|j|ƒ}t|ƒ|krœ|dƒ‚|j|ƒdS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. éirNzunexpected end of datai@)ÚshutilÚ copyfileobjÚdivmodrEÚreadr0Úwrite) ÚsrcÚdstr3Ú exceptionÚbufsizeÚblocksÚ remainderÚbrTr6r6r7rX÷s$     rXcCs ddl}|jdtdƒtj|ƒS)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)ÚwarningsÚwarnÚDeprecationWarningÚstatÚfilemode)Úmodercr6r6r7rgsrgcCs8ttjddƒ}|dk r(|j|dƒj|ƒ}t|dd�dS)Nr4Úbackslashreplaceú )Úend)ÚgetattrÚsysÚstdoutr/r;Úprint)r2r4r6r6r7Ú _safe_printsrpc@seZdZdZdS)rzBase exception.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r6r6r6r7rsc@seZdZdZdS)r z%General exception for extract errors.N)rqrrrsrtr6r6r6r7r !sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rqrrrsrtr6r6r6r7r$sc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rqrrrsrtr6r6r6r7r'sc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.N)rqrrrsrtr6r6r6r7r *sc@seZdZdZdS)r z!Base exception for header errors.N)rqrrrsrtr6r6r6r7r -sc@seZdZdZdS)ÚEmptyHeaderErrorzException for empty headers.N)rqrrrsrtr6r6r6r7ru0sruc@seZdZdZdS)ÚTruncatedHeaderErrorz Exception for truncated headers.N)rqrrrsrtr6r6r6r7rv3srvc@seZdZdZdS)ÚEOFHeaderErrorz"Exception for end of file headers.N)rqrrrsrtr6r6r6r7rw6srwc@seZdZdZdS)rHzException for invalid headers.N)rqrrrsrtr6r6r6r7rH9srHc@seZdZdZdS)ÚSubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rqrrrsrtr6r6r6r7rx<srxc@s0eZdZdZdd„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. cCsFtjtjtjBtjBdœ|}ttdƒr2|tjO}tj||dƒ|_dS)N)ÚrÚwÚO_BINARYi¶) ÚosÚO_RDONLYÚO_WRONLYÚO_CREATÚO_TRUNCÚhasattrr|rÚfd)ÚselfÚnamerhr6r6r7Ú__init__Is   z_LowLevelFile.__init__cCstj|jƒdS)N)r}Úcloserƒ)r„r6r6r7r‡Rsz_LowLevelFile.closecCstj|j|ƒS)N)r}rZrƒ)r„r'r6r6r7rZUsz_LowLevelFile.readcCstj|j|ƒdS)N)r}r[rƒ)r„r2r6r6r7r[Xsz_LowLevelFile.writeN)rqrrrsrtr†r‡rZr[r6r6r6r7ryCs  ryc@steZdZdZdd„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|_|dkrt||ƒ}d|_|dkr6t|ƒ}|jƒ}|pt|jƒ|jkrL|jj|jd|j…ƒ|j|jd…|_qWdS)z]Write string s to the stream if a whole new block is ready to be written. N)rTr0r_r”r[)r„r2r6r6r7Z__writeÈsz_Stream.__writec Cs²|jr dSd|_zŠ|jdkr:|jdkr:|j|jjƒ7_|jdkr˜|jr˜|jj|jƒd|_|jdkr˜|jjtj d|j ƒƒ|jjtj d|j d@ƒƒWd|j s¬|jj ƒXdS) z[Close the _Stream object. No operation should be done on it afterwards. NTr{r�r‹rŒzd|fg}d|_g|_d}|j}xT|D]L\}}||kr~|jj d||dfƒ|jj d||||fƒ||7}||}qZW||jkrÊ|jj d||jdfƒdS)Nrr…FT) r”Úoffsetr'Úpositionrlr…r–Ú map_indexÚmapr¸)r„r”rÂr'Z blockinfoZlastposZrealposr6r6r7r†us(   z_FileInFile.__init__cCsdS)Nr6)r„r6r6r7r®Žsz_FileInFile.flushcCsdS)NTr6)r„r6r6r7Úreadable‘sz_FileInFile.readablecCsdS)NFr6)r„r6r6r7Úwritable”sz_FileInFile.writablecCs |jjƒS)N)r”Úseekable)r„r6r6r7rÈ—sz_FileInFile.seekablecCs|jS)z*Return the current file position. )rÃ)r„r6r6r7rµšsz_FileInFile.tellcCs�|tjkr tt|dƒ|jƒ|_nj|tjkr\|dkrFt|j|dƒ|_qŠt|j||jƒ|_n.|tjkr‚tt|j||jƒdƒ|_ntdƒ‚|jS)z(Seek to a position in the file. rzInvalid argument) ÚioÚSEEK_SETÚminÚmaxr'rÃÚSEEK_CURÚSEEK_ENDr.)r„rÃÚwhencer6r6r7r¶Ÿs   z_FileInFile.seekc Cs|dkr|j|j}nt||j|jƒ}d}xà|dk�r xZ|j|j\}}}}||jkob|knrlPq:|jd7_|jt|jƒkr:d|_q:Wt|||jƒ}|rè|jj||j|ƒ|jj|ƒ}t|ƒ|krÞt dƒ‚||7}n |t |7}||8}|j|7_q.W|S)z!Read data from the file. Nr‹rr#zunexpected end of data) r'rÃrËrÅrÄr0r”r¶rZrr1) r„r'rTÚdataÚstartÚstoprÂr3rbr6r6r7rZ¯s.      z_FileInFile.readcCs&|jt|ƒƒ}||dt|ƒ…<t|ƒS)N)rZr0)r„rbrTr6r6r7ÚreadintoÎsz_FileInFile.readintocCs d|_dS)NT)r–)r„r6r6r7r‡Ósz_FileInFile.close)N)N)rqrrrsrtr†r®rÆrÇrÈrµrÉrÊr¶rZrÓr‡r6r6r6r7rÁos  rÁcseZdZ‡fdd„Z‡ZS)Ú ExFileObjectcs&t|j|j|j|jƒ}tƒj|ƒdS)N)rÁr”Ú offset_datar'ÚsparseÚsuperr†)r„ÚtarfileÚtarinfor”)Ú __class__r6r7r†Ùs  zExFileObject.__init__)rqrrrsr†Ú __classcell__r6r6)rÚr7rÔ×srÔc@s eZdZdS)Ú FilterErrorN)rqrrrsr6r6r6r7rÜäsrÜcseZdZ‡fdd„Z‡ZS)ÚAbsolutePathErrorcs ||_tƒjd|j›d�ƒdS)Nzmember z has an absolute path)rÙr×r†r…)r„rÙ)rÚr6r7r†èszAbsolutePathError.__init__)rqrrrsr†rÛr6r6)rÚr7rÝçsrÝcseZdZ‡fdd„Z‡ZS)ÚOutsideDestinationErrorcs.||_||_tƒj|j›d|›d�dƒdS)Nz would be extracted to z, z which is outside the destination)rÙÚ_pathr×r†r…)r„rÙr%)rÚr6r7r†ísz OutsideDestinationError.__init__)rqrrrsr†rÛr6r6)rÚr7rÞìsrÞcseZdZ‡fdd„Z‡ZS)ÚSpecialFileErrorcs||_tƒj|j›d�ƒdS)Nz is a special file)rÙr×r†r…)r„rÙ)rÚr6r7r†ôszSpecialFileError.__init__)rqrrrsr†rÛr6r6)rÚr7ràósràcseZdZ‡fdd„Z‡ZS)ÚAbsoluteLinkErrorcs||_tƒj|j›d�ƒdS)Nz! is a symlink to an absolute path)rÙr×r†r…)r„rÙ)rÚr6r7r†ùszAbsoluteLinkError.__init__)rqrrrsr†rÛr6r6)rÚr7ráøsrácseZdZ‡fdd„Z‡ZS)ÚLinkOutsideDestinationErrorcs.||_||_tƒj|j›d|›d�dƒdS)Nz would link to z, z which is outside the destination)rÙrßr×r†r…)r„rÙr%)rÚr6r7r†þsz$LinkOutsideDestinationError.__init__)rqrrrsr†rÛr6r6)rÚr7râýsrâcseZdZ‡fdd„Z‡ZS)ÚLinkFallbackErrorcs2||_||_tƒjd|j›d�d|›d�ƒdS)Nzlink z would be extracted as a zcopy of z, which was rejected)rÙrßr×r†r…)r„rÙr%)rÚr6r7r†szLinkFallbackError.__init__)rqrrrsr†rÛr6r6)rÚr7rãsrãcCs$i}|j}tjj|tjjd�}|jdtjfƒrH|jjdtjƒ}|d<tjj|ƒr\t |ƒ‚tjjtjj ||ƒtjjd�}tjj ||gƒ|kr˜t ||ƒ‚|j }|dk �r|d@}|�rþ|jƒsÆ|jƒrà|d@sÖ|dM}|dO}n|jƒsð|jƒröd}nt|ƒ‚||j k�r||d<|�r |jdk �r,d|d <|jdk �r@d|d <|jdk �rTd|d <|jdk �rhd|d <|jƒ�s||jƒ�r tjj|jƒ�r”t|ƒ‚tjj|jƒ}||jk�r¶||d <|jƒ�rÜtjj |tjj|ƒ|jƒ}ntjj ||jƒ}tjj|tjjd�}tjj ||gƒ|k�r t||ƒ‚|S)N)rCú/r…iíé@éIi€rhr)r*r+r,Úlinknamei¶ÿÿÿ)r…r}r%ÚrealpathÚ ALLOW_MISSINGrÀÚsepÚlstripÚisabsrÝr¹Ú commonpathrÞrhÚisregÚislnkÚisdirÚissymràr)r*r+r,rçráÚnormpathÚdirnamerâ)ÚmemberÚ dest_pathZfor_dataÚ new_attrsr…Z target_pathrhZ normalizedr6r6r7Ú_get_filtered_attrssd                r÷cCs|S)Nr6)rôrõr6r6r7Úfully_trusted_filterTsrøcCs(t||dƒ}|r$|jf|ddi—ŽS|S)NFÚdeep)r÷r¦)rôrõrör6r6r7Ú tar_filterWs rúcCs(t||dƒ}|r$|jf|ddi—ŽS|S)NTrùF)r÷r¦)rôrõrör6r6r7Ú data_filter]s rû)Z fully_trustedr�rÐs([0-9]{1,20}) c@s®eZdZdZdmZdndd„Zdd„Zdd„ZeeeƒZ dd„Z dd „Z ee e ƒZ d!d"„Z eeeeeeeed#ed$œ d%d&„Zd'd(„Zeed)fd*d+„Zd,d-„Zd.d/„Zd0d1„Zed2d3„ƒZd4d5„Zed6d7„ƒZed8d9„ƒZed:d;„ƒZedd?„ƒZed@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„Z3dhdi„Z4djdk„Z5dlS)oraInformational 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…rhr)r*r'r(ÚchksumÚtyperçr+r,ÚdevmajorÚdevminorrÂrÕÚ pax_headersrÖrØÚ_sparse_structsÚ _link_targetrŠcCsj||_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…rhr)r*r'r(rüÚREGTYPErýrçr+r,rþrÿrÂrÕrÖr)r„r…r6r6r7r†�s"zTarInfo.__init__cCs|jS)N)r…)r„r6r6r7Ú_getpath›szTarInfo._getpathcCs ||_dS)N)r…)r„r…r6r6r7Ú_setpath�szTarInfo._setpathcCs|jS)N)rç)r„r6r6r7Ú _getlinkpath¡szTarInfo._getlinkpathcCs ||_dS)N)rç)r„rçr6r6r7Ú _setlinkpath£szTarInfo._setlinkpathcCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)rÚrqr…Úid)r„r6r6r7Ú__repr__§szTarInfo.__repr__T) r…r(rhrçr)r*r+r,rùÚ_KEEPc CsŽ| rtj|ƒ} n tj|ƒ} || k r(|| _|| k r6|| _|| k rD|| _|| k rR|| _|| k r`|| _|| k rn|| _|| k r||| _|| k rŠ|| _ | S)zGReturn a deep copy of self with the given attributes replaced. ) ÚcopyÚdeepcopyr…r(rhrçr)r*r+r,) r„r…r(rhrçr)r*r+r,rùr Úresultr6r6r7r¦ªs(  zTarInfo.replacecCs‚|jdkrd}n |jd@}|j||j|j|j|j|j|j|j|j |j |j |j dœ }|dt kr~|djdƒ r~|dd7<|S)z9Return the TarInfo's attributes as a dictionary. Niÿ) r…rhr)r*r'r(rürýrçr+r,rþrÿrýr…rä)rhr…r)r*r'r(rürýrçr+r,rþrÿÚDIRTYPEr¬)r„rhÚinfor6r6r7Úget_infoÆs&   zTarInfo.get_infoÚsurrogateescapecCs~|jƒ}x(|jƒD]\}}|dkrtd|ƒ‚qW|tkrH|j|||ƒS|tkr^|j|||ƒS|tkrr|j||ƒStdƒ‚dS)ztdƒ‚t|dd…ƒ}|t|ƒkrbt 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…||ƒ}|jtk�r†|j jdƒ�r†t|_|jtk�r6d}g}xrtdƒD]f} y0t|||d…ƒ} t||d|d…ƒ} Wntk �rðPYnX|j| | fƒ|d7}�q¤Wt|dƒ} t|dd…ƒ} || | f|_ |j!ƒ�rN|j j"dƒ|_ |�rp|jt#k�rp|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ï)$r0rur¼rvÚcountr1rwrKrUrHr=r…rhr)r*r'r(rürýrçr+r,rþrÿÚAREGTYPEr¬rÚGNUTYPE_SPARSErEr.r¸ÚboolrrðÚrstripÚ GNU_TYPES)r1rTr4r5rüÚobjrr•ÚstructsrJrÂÚnumbytesÚ isextendedÚorigsizer6r6r7ÚfrombufÍsZ       zTarInfo.frombufcCs8|jjtƒ}|j||j|jƒ}|jjƒt|_|j|ƒS)zOReturn the next TarInfo object from TarFile object tarfile. ) r”rZr¼rRr4r5rµrÂÚ _proc_member)r1rØrTrMr6r6r7Ú fromtarfile s zTarInfo.fromtarfilecCsT|jttfkr|j|ƒS|jtkr,|j|ƒS|jtttfkrF|j |ƒS|j |ƒSdS)zYChoose the right processing method depending on the type and call it. N) rýr"r!Ú _proc_gnulongrIÚ _proc_sparser.r0ÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r„rØr6r6r7rS!s    zTarInfo._proc_membercCsR|jjƒ|_|j}|jƒs$|jtkr4||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ÕrîrýÚSUPPORTED_TYPESÚ_blockr'rÂÚ_apply_pax_inforr4r5)r„rØrÂr6r6r7rY.s zTarInfo._proc_builtinc Cs†|jj|j|jƒƒ}y|j|ƒ}Wntk r>tdƒ‚YnX|j|_|jt krft ||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”rZr[r'rTr rxrÂrýr"r=r4r5r…r!rç)r„rØrTÚnextr6r6r7rU?s  zTarInfo._proc_gnulongc CsÞ|j\}}}|`xœ|r¬|jjtƒ}d}xvtdƒD]j}y0t|||d…ƒ}t||d|d…ƒ} Wntk rzPYnX|r’| r’|j|| fƒ|d7}q0Wt|dƒ}qW||_ |jj ƒ|_ |j |j |j ƒ|_||_ |S)z8Process a GNU sparse header plus extra headers. rér$rFiø)rr”rZr¼rErKr.r¸rJrÖrµrÕr[r'rÂ) r„rØrNrPrQrTr•rJrÂrOr6r6r7rVUs(    zTarInfo._proc_sparsec CsÖ|jj|j|jƒƒ}|jtkr&|j}n |jjƒ}d}d}g}�x0t|ƒ|koV||dk�rnt j ||ƒ}|srt dƒ‚yt |j dƒƒ}Wntk r t dƒ‚YnX|dkr²t dƒ‚||t|ƒkrÊt dƒ‚|jdƒ|d} ||jdƒd| …} | jdƒ\} } } | �s"| dk�s"|| dk�r*t dƒ‚|j|| | fƒ| dk�rd|dk�rd| d k�r`|j}nd }||7}q@W|dk�r~d }x`|D]X\}} } |j| d d |jƒ}|tk�rÀ|j| ||j|jƒ}n|j| d d |jƒ}|||<�q„Wy|j|ƒ}Wntk �r td ƒ‚YnXd |k�r&|j||ƒnFd |k�r>|j||ƒn.|jdƒdk�rl|jdƒdk�rl|j|||ƒ|jttfk�rÒ|j ||j|jƒ|j!|_!d|k�rÒ|j"}|j#ƒ�s¼|jt$k�rÌ||j|jƒ7}||_!|S)zVProcess an extended or global header as described in POSIX.1-2008. rNzinvalid headerr#ér;r½s hdrcharsetsBINARYzutf-8z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrDr')%r”rZr[r'rýr0rr r0Ú_header_length_prefix_reÚmatchrHrFÚgroupr.rÑrkÚ partitionr¸r4Ú_decode_pax_fieldr5ÚPAX_NAME_FIELDSrTr rxÚ_proc_gnusparse_01Ú_proc_gnusparse_00r5Ú_proc_gnusparse_10r.rWr\rÂrÕrîrZ)r„rØrTrr•r4Ú raw_headersrbr3Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuer=rr]rÂr6r6r7rXqsx                 zTarInfo._proc_paxc Csªg}g}xŒ|D]„\}}}|dkrVy|jt|jƒƒƒWq’tk rRtdƒ‚Yq’Xq|dkry|jt|jƒƒƒWqtk r�tdƒ‚YqXqWtt||ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetzinvalid headersGNU.sparse.numbytesN)r¸rFr;r.rHÚlistÚziprÖ)r„r]rjZoffsetsrOÚ_r=rr6r6r7rhëszTarInfo._proc_gnusparse_00cCs@dd„|djdƒDƒ}tt|ddd…|ddd…ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|ƒ‘qSr6)rF)Ú.0Úxr6r6r7ú sz.TarInfo._proc_gnusparse_01..zGNU.sparse.mapú,Nr$r#)r3rkrlrÖ)r„r]rrÖr6r6r7rgÿszTarInfo._proc_gnusparse_01cCs¬d}g}|jjtƒ}|jddƒ\}}t|ƒ}xJt|ƒ|dkrvd|krV||jjtƒ7}|jddƒ\}}|jt|ƒƒq.W|jjƒ|_t t |ddd…|ddd…ƒƒ|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nr<r#r$) r”rZr¼r3rFr0r¸rµrÕrkrlrÖ)r„r]rrØZfieldsrÖrTZnumberr6r6r7ris  zTarInfo._proc_gnusparse_10c CsÆx¶|jƒD]ª\}}|dkr(t|d|ƒq |dkrBt|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.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerräN) rÚsetattrrFÚ PAX_FIELDSÚPAX_NUMBER_FIELDSr.rKr r)r„rr4r5r=rr6r6r7r\s"  zTarInfo._apply_pax_infoc Cs.y |j|dƒStk r(|j||ƒSXdS)z1Decode a single field from a pax record. rCN)r;ÚUnicodeDecodeError)r„rr4Zfallback_encodingZfallback_errorsr6r6r7re,s zTarInfo._decode_pax_fieldcCs2|dkrtdƒ‚t|tƒ\}}|r*|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. rzinvalid offsetr#)rHrYr¼)r„rGr`rar6r6r7r[4s zTarInfo._blockcCs |jtkS)N)rýÚ REGULAR_TYPES)r„r6r6r7rî@sz TarInfo.isregcCs|jƒS)N)rî)r„r6r6r7ÚisfileBszTarInfo.isfilecCs |jtkS)N)rýr)r„r6r6r7rðDsz TarInfo.isdircCs |jtkS)N)rýÚSYMTYPE)r„r6r6r7rñFsz TarInfo.issymcCs |jtkS)N)rýÚLNKTYPE)r„r6r6r7rïHsz TarInfo.islnkcCs |jtkS)N)rýr6)r„r6r6r7ÚischrJsz TarInfo.ischrcCs |jtkS)N)rýr7)r„r6r6r7ÚisblkLsz TarInfo.isblkcCs |jtkS)N)rýÚFIFOTYPE)r„r6r6r7ÚisfifoNszTarInfo.isfifocCs |jdk S)N)rÖ)r„r6r6r7ÚissparsePszTarInfo.issparsecCs|jtttfkS)N)rýr6r7r|)r„r6r6r7ÚisdevRsz TarInfo.isdevN)r…rhr)r*r'r(rürýrçr+r,rþrÿrÂrÕrrÖrØrr)rŠ)6rqrrrsrtÚ __slots__r†rrÚpropertyr%rrr&r r r¦rrr rrrrÚ classmethodr2rÚ staticmethodrr9r r-rRrTrSrYrUrVrXrhrgrir\rer[rîrwrðrñrïrzr{r}r~rr6r6r6r7rssf    1  *  3 ?  z c @sþeZdZdZdZdZdZdZeZ e Z dZ e ZeZdZdkdd „Zedddefd d „ƒZedld d „ƒZedmdd„ƒZedndd„ƒZedodd„ƒZdddddœZdd„Zdd„Zdd„Zd d!„Zdpd"d#„Zdqdd%œd&d'„Z drdd(œd)d*„Z!dsd+d,„Z"d-d.„Z#dtddd0œd1d2„Z$d3d4„Z%duddd0œd6d7„Z&d8d9„Z'dvd:d;„Z(dd?„Z*d@dA„Z+dwdddBœdCdD„Z,dEdF„Z-dGdH„Z.dIdJ„Z/dKdL„Z0dMdN„Z1dOdP„Z2dQdR„Z3dSdT„Z4dUdV„Z5dWdX„Z6dYdZ„Z7dxd[d\„Z8d]d^„Z9dyd_d`„Z:dadb„Z;dcdd„Zdidj„Z?dS)zrz=The TarFile Class provides an interface to tar archives. rFr#NrzrcCs°dddddœ}||krtdƒ‚||_|||_|sj|jdkrVtjj|ƒ rVd|_d|_t||jƒ}d |_n@|d kr’t|d ƒr’t |j t t fƒr’|j }t|d ƒr¤|j|_d |_|rºtjj |ƒnd |_ ||_|d k rÔ||_|d k râ||_|d k rð||_|d k �r||_|d k �r||_| |_| d k �r4|jtk�r4| |_ni|_| d k �rJ| |_| d k �rZ| |_| |_d |_g|_d |_|jjƒ|_i|_�yþ|jdk�r¤d |_ |j!ƒ|_ |jdk�r8x†|jj"|jƒy|jj#|ƒ}|jj$|ƒWnTt%k �r|jj"|jƒPYn0t&k �r0}zt't |ƒƒ‚WYd d }~XnX�q²W|jdk�r‚d |_|j�r‚|jj(|jj)ƒƒ}|jj*|ƒ|jt+|ƒ7_Wn&|j�sž|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. Úrbzr+bÚwbZxb)rzÚar{roz!mode must be 'r', 'a', 'w' or 'x'r†r{FNr…rhTrzro)r†r{ro)-r.rhÚ_moder}r%ÚexistsÚ bltn_openr�r‚r*r…r,rLÚabspathr”rPrÙÚ dereferenceÚ ignore_zerosr4r5rrÚdebugÚ errorlevelÚ copybufsizer–ÚmembersÚ_loadedrµrÂÚinodesÚ firstmemberr]r¶rTr¸rwr rr2r r[r0r‡)r„r…rhr”rPrÙr‹rŒr4r5rr�rŽr�ZmodesÚerTr6r6r7r†rsŠ             $   zTarFile.__init__c sº| r| rtdƒ‚|dkrª‡fdd„}xttˆj|d�D]b}tˆˆj|ƒ}|dk r\|jƒ} y||d|f|ŽSttfk r˜|dk r’|j| ƒw8Yq8Xq8Wtdƒ‚�nd |k�r |jd d ƒ\} }| pÊd} |pÒd }|ˆjkrðtˆˆj|ƒ}n td |ƒ‚||| |f|ŽSd |k�r’|jd d ƒ\} }| �p.d} |�p8d }| dk�rLtdƒ‚t || |||ƒ} yˆ|| | f|Ž} Wn| j ƒ‚YnXd| _ | S|dk�r®ˆj |||f|Ž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 openrzúr:*csˆj|dkS)NÚtaropen)Ú OPEN_METH)r“)r1r6r7Únot_compressed sz$TarFile.open..not_compressed)ÚkeyNz%file could not be opened successfullyú:r#r�zunknown compression type %rú|r{zmode must be 'r' or 'w'Fr†rozundiscernible mode)rzr•)rzr{)r†r{ro) r.Úsortedr—rlrµrrr¶r3rˆr‡r�r–) r1r…rhr”r_Úkwargsr˜r“ÚfuncZ saved_posrgÚstreamrºr6)r1r7rásP%             z TarFile.opencKs |dkrtdƒ‚||||f|ŽS)zCOpen uncompressed tar archive name for reading or writing. rzr†r{roz!mode must be 'r', 'a', 'w' or 'x')rzr†r{ro)r.)r1r…rhr”r�r6r6r7r–<szTarFile.taropenr¤cKsð|d krtdƒ‚yddl}|jWn ttfk rBtdƒ‚YnXy|j||d||ƒ}Wn.tk rŠ|dk r„|dkr„td ƒ‚‚YnXy|j|||f|Ž}WnBtk rÐ|j ƒ|dkrÊtd ƒ‚‚Yn|j ƒ‚YnXd |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzgzip module is not availablerbznot a gzip fileF)rzr{ro) r.ÚgzipZGzipFiler˜ÚAttributeErrorrr rr–r‡r�)r1r…rhr”Ú compresslevelr�r rºr6r6r7ÚgzopenDs2 zTarFile.gzopencKs¶|d krtdƒ‚y ddl}Wntk r8tdƒ‚YnX|j|pD|||d�}y|j|||f|Ž}WnFttfk r–|jƒ|dkr�t d ƒ‚‚Yn|jƒ‚YnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzbz2 module is not available)r¢znot a bzip2 fileF)rzr{ro) r.r�r˜rZBZ2Filer–r ÚEOFErrorr‡rr�)r1r…rhr”r¢r�r�rºr6r6r7Úbz2openfs(  zTarFile.bz2opencKs¸|d krtdƒ‚y ddl}Wntk r8tdƒ‚YnX|j|pD|||d�}y|j|||f|Ž}WnH|jtfk r˜|jƒ|dkr’t d ƒ‚‚Yn|jƒ‚YnXd |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rzr{rozmode must be 'r', 'w' or 'x'rNzlzma module is not available)Úpresetznot an lzma fileF)rzr{ro) r.r¡r˜rZLZMAFiler–r¢r¤r‡rr�)r1r…rhr”r¦r�r¡rºr6r6r7Úxzopenƒs& zTarFile.xzopenr–r£r¥r§)r�rŒr�rŽc Csˆ|jr dSd|_z`|jdkrn|jjttdƒ|jtd7_t|jtƒ\}}|dkrn|jjtt|ƒWd|j s‚|jj ƒXdS) zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTr†r{ror$r)r†r{ro) r–rhr”r[r1r¼rÂrYÚ RECORDSIZEr�r‡)r„r`rar6r6r7r‡ªs z TarFile.closecCs"|j|ƒ}|dkrtd|ƒ‚|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Ùr6r6r7Ú 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. )Ú_checkr‘Ú_loadr�)r„r6r6r7Ú getmembersÊszTarFile.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‘qSr6)r…)rnrÙr6r6r7rpØsz$TarFile.getnames..)r®)r„r6r6r7ÚgetnamesÔszTarFile.getnamesc Csp|jdƒ|dk r|j}|dkr$|}tjj|ƒ\}}|jtjdƒ}|jdƒ}|jƒ}||_ |dkrŒt tdƒr€|j r€tj |ƒ}qštj |ƒ}ntj|jƒƒ}d}|j}t j|ƒ�r|j|jf} |j rö|jdkrö| |jkrö||j| kröt} |j| }nt} | d�rx||j| <nht j|ƒ�r"t} nVt j|ƒ�r4t} nDt j|ƒ�rPt} tj|ƒ}n(t j|ƒ�rbt } nt j!|ƒ�rtt"} ndS||_||_#|j$|_%|j&|_'| tk�r¨|j(|_)nd|_)|j*|_+| |_,||_-t.�röyt.j/|j%ƒd|_0Wnt1k �rôYnXt2�r*yt2j3|j'ƒd|_4Wnt1k �r(YnX| t t"fk�rlt tdƒ�rlt td ƒ�rltj5|j6ƒ|_7tj8|j6ƒ|_9|S) aÒCreate a TarInfo object from the result of os.stat or equivalent on an existing file. The file is either named by `name', or specified as a file object `fileobj' with a file descriptor. If given, `arcname' specifies an alternative name for the file in the archive, otherwise, the name is taken from the 'name' attribute of 'fileobj', or the 'name' argument. The name should be a text string. ÚawxNräÚlstatrŠr#rÚmajorÚminor):r¬r…r}r%Ú splitdriver¦rêrërÙrØr‚r‹r±rfÚfstatÚfilenoÚst_modeÚS_ISREGÚst_inoÚst_devÚst_nlinkr’ryrÚS_ISDIRrÚS_ISFIFOr|ÚS_ISLNKrxÚreadlinkÚS_ISCHRr6ÚS_ISBLKr7rhÚst_uidr)Úst_gidr*Úst_sizer'Úst_mtimer(rýrçÚpwdÚgetpwuidr+rªÚgrpZgetgrgidr,r²Úst_rdevrþr³rÿ) r„r…Úarcnamer”ZdrvrÙZstatresrçZstmdÚinoderýr6r6r7Ú gettarinfoÚs~                 zTarFile.gettarinfoT)r�cCs0|jƒ|dkr|}�x|D�] }|rÒ|jdkr:tdƒnttj|jƒƒtd|jpX|j|jpb|jfƒ|j ƒsz|j ƒr”tdd|j |j fƒntd|j ƒ|jdkr¶tdƒntdtj|jƒdd …ƒt|j|jƒräd nd ƒ|�r"|jƒ�r td |jƒ|jƒ�r"td |jƒtƒqWdS)aPrint a table of contents to sys.stdout. If `verbose' is False, only the names of the members are printed. If it is True, an `ls -l'-like output is produced. `members' is optional and must be a subset of the list returned by getmembers(). Nz ??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02dr°rärŠz-> zlink to )r¬rhrprfrgr+r)r,r*rzr{rþrÿr'r(rªZ localtimer…rðrñrçrïro)r„Úverboser�rÙr6r6r7rk>s2      z TarFile.list)Úfilterc Csv|jdƒ|dkr|}|dk rPddl}|jdtdƒ||ƒrP|jdd|ƒdS|jdk r€tjj|ƒ|jkr€|jdd|ƒdS|jd|ƒ|j ||ƒ}|dkr´|jdd |ƒdS|dk rà||ƒ}|dkrà|jdd|ƒdS|j ƒ�rt |d ƒ�}|j ||ƒWdQRXnd|j ƒ�rh|j |ƒ|�rrxHtj|ƒD].}|jtjj||ƒtjj||ƒ|||d ��q4Wn |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 insteadr$ztarfile: Excluded %rztarfile: Skipped %rr#ztarfile: Unsupported type %rr„)rÎ)r¬rcrdreÚ_dbgr…r}r%rŠrÌrîr‰ÚaddfilerðÚlistdirÚaddr¹) r„r…rÊÚ recursiveZexcluderÎrcrÙÚfr6r6r7rÒdsB       z TarFile.addcCs¾|jdƒtj|ƒ}|j|j|j|jƒ}|jj|ƒ|jt |ƒ7_|j }|dk r®t ||j|j |d�t |j tƒ\}}|dkrœ|jjtt|ƒ|d7}|j|t7_|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°N)r_rr#)r¬r rrPr4r5r”r[rÂr0r�rXr'rYr¼r1r�r¸)r„rÙr”rTr_r`rar6r6r7rСs   zTarFile.addfilec"CsH|dk�r|j}|dk�rìtjjdƒ}|dkr�y ttƒ}Wntk rNYnBXddl}|jddd�}|�|j |ƒWdQRX|jdddd�}|rÒy t |}Wn&t k rÆt d|›d �ƒd‚YnX||_|St �rètjdtƒtStSt|tƒ�rtdƒ‚|St|ƒ�r|Syt |St k �rBt d|›d �ƒd‚YnXdS)NZ PYTHON_TARFILE_EXTRACTION_FILTERrú#)Z interpolationZcomment_prefixesrØrŠ)Zfallbackzfilter z not foundz4The default behavior of tarfile extraction has been z$changed to disallow common exploits z(including CVE-2007-4559). z1By default, absolute/parent paths are disallowed z and some mode bits are cleared. z/See https://access.redhat.com/articles/7004769 zfor more details.z#String names are not supported for z2TarFile.extraction_filter. Use a function such as ztarfile.data_filter directly.)rÕzXThe default behavior of tarfile extraction has been changed to disallow common exploits zsThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). z¤The default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed zÄThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. zóThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 aThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 for more details.zUString names are not supported for TarFile.extraction_filter. Use a function such as zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)Úextraction_filterr}Úenvironr5r‰Ú_CONFIG_FILENAMEÚFileNotFoundErrorÚ configparserZ ConfigParserZ read_fileÚ_NAMED_FILTERSrªr.Ú_RH_SAFER_DEFAULTrcrdÚRuntimeWarningrúrør*r,Ú TypeErrorÚcallable)r„rÎr…ÚfilerÚZconfr6r6r7Ú_get_filter_functionºsR       zTarFile._get_filter_functionÚ.)Ú numeric_ownerrÎc"Cs®g}|j|ƒ}|dkr|}xT|D]L}|j|||ƒ\}} |dkr@q |jƒrR|j| ƒ|j|||jƒ ||d�q W|jdd„dd��x$|D�]} yæy|| |ƒ}Wn4tk rÔ} z|j| t| ƒƒwŠWYdd} ~ XnX|dkrì|j| dƒwŠt j j ||j ƒ} yt j | ƒ} Wn$tk �r.|j|dƒwŠYnXtj| jƒ�sL|j|d ƒwŠ|j|| |d �|j|| ƒ|j|| ƒWqŠtk �r¤} z|j| ƒ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. The `filter` function will be called on each member just before extraction. It can return a changed TarInfo or None to skip the member. String names of common filters are accepted. N)Ú set_attrsrãÚfilter_functioncSs|jS)N)r…)r†r6r6r7Ú sz$TarFile.extractall..T)r™Úreversezexcluded by filterZmissingznot a directory)rã)ráÚ_get_extract_tarinforðr¸Ú _extract_oneÚsortÚ_FILTER_ERRORSÚ_log_no_directory_fixupÚreprr}r%r¹r…r±rÙrfr¼r·ÚchownÚutimeÚchmodr Ú_handle_nonfatal_error)r„r%r�rãrÎZ directoriesrårôrÙÚ unfilteredÚexcÚdirpathr±r”r6r6r7Ú extractallïsP       zTarFile.extractallcCs|jdd|j|fƒdS)Nr$z(tarfile: Not fixing up directory %r (%s))rÏr…)r„rôÚreasonr6r6r7rì4 szTarFile._log_no_directory_fixuprŠc Cs8|j|ƒ}|j|||ƒ\}}|dk r4|j||||ƒdS)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. The `filter` function will be called before extraction. It can return a changed TarInfo or None to skip the member. String names of common filters are accepted. N)rárèré) r„rôr%rärãrÎrårÙròr6r6r7Úextract8 s  zTarFile.extractcCsÒt|tƒr|j|ƒ}n|}d}y|||ƒ}WnZttfk r\}z|j|ƒWYdd}~Xn,tk r†}z|j|ƒWYdd}~XnX|dkr¦|jdd|j ƒdS|j ƒrÊt j |ƒ}t j j||jƒ|_||fS)zŠGet (filtered, unfiltered) TarInfos from *member* *member* might be a string. Return (None, None) if not found. Nr$ztarfile: Excluded %r)NN)r*r,r«r rÜÚ_handle_fatal_errorr rñrÏr…rïr r}r%r¹rçr)r„rôrår%ròÚfilteredr”r6r6r7rèL s"   zTarFile._get_extract_tarinfocCsŒ|jdƒy&|j|tjj||jƒ||||d�WnVtk r\}z|j|ƒWYdd}~Xn,tk r†}z|j |ƒWYdd}~XnXdS)z±Extract from filtered tarinfo to disk. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) rz)rärãråÚextraction_rootN) r¬Ú_extract_memberr}r%r¹r…r rør rñ)r„rÙr%rärãrår”r6r6r7réj s  zTarFile._extract_onecCs"|jdkr‚n|jdd|ƒdS)z=Handle non-fatal error (ExtractError) according to errorlevelr#z tarfile: %sN)rŽrÏ)r„r”r6r6r7rñ~ s zTarFile._handle_nonfatal_errorcCsn|jdkr‚n\t|tƒrP|jdkr6|jdd|jƒqj|jdd|j|jfƒn|jddt|ƒj|fƒdS)z1Handle "fatal" error according to self.errorlevelrNr#z tarfile: %sztarfile: %s %rztarfile: %s %s)rŽr*r ÚfilenamerÏÚstrerrorrýrq)r„r”r6r6r7rø… s   zTarFile._handle_fatal_errorcCs‚|jdƒt|tƒr |j|ƒ}n|}|jƒs6|jtkrB|j||ƒS|jƒsR|j ƒrzt|j t ƒrht 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. rzz'cannot extract (sym)link as file objectN)r¬r*r,r«rîrýrZÚ fileobjectrïrñr”rˆr Ú extractfileÚ_find_link_target)r„rôrÙr6r6r7rÿ‘ s      zTarFile.extractfile)rårúcCs\|jdƒ}|jdtjƒ}tjj|ƒ}|r@tjj|ƒ r@tj|ƒ|jƒsP|j ƒrj|j dd|j |j fƒn|j d|j ƒ|j ƒrŽ|j||ƒn”|jƒr¤|j||ƒn~|jƒrº|j||ƒnh|jƒsÊ|jƒrØ|j||ƒnJ|jƒsè|j ƒrü|j||||d�n&|jtk�r|j||ƒn |j||ƒ|�rX|j|||ƒ|j ƒ�sX|j||ƒ|j||ƒdS)zçExtract the filtered TarInfo object tarinfo to a physical file called targetpath. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a symlink) rär#z%s -> %s)rårúN)rKr¦r}rêr%rórˆÚmakedirsrïrñrÏr…rçrîÚmakefilerðÚmakedirr}Úmakefiforzr{ÚmakedevÚmakelink_with_filterrýrZÚ makeunknownrîrðrï)r„rÙÚ targetpathrärãrårúZ upperdirsr6r6r7rû° s:        zTarFile._extract_memberc Cs@y&|jdkrtj|ƒn tj|dƒWntk r:YnXdS)z,Make a directory called targetpath. NiÀ)rhr}ÚmkdirÚFileExistsError)r„rÙrr6r6r7rè s   zTarFile.makedircCs’|j}|j|jƒ|j}t|dƒ�f}|jdk rrx,|jD]"\}}|j|ƒt|||t|ƒq6W|j|jƒ|j ƒnt|||jt|ƒWdQRXdS)z'Make a file called targetpath. r…N) r”r¶rÕr�r‰rÖrXrr'Útruncate)r„rÙrÚsourcer_ÚtargetrÂr'r6r6r7rö s      zTarFile.makefilecCs"|j||ƒ|jdd|jƒdS)zYMake a file from a TarInfo object with an unknown type at targetpath. r#z9tarfile: Unknown file type %r, extracted as regular file.N)rrÏrý)r„rÙrr6r6r7r s zTarFile.makeunknowncCs"ttdƒrtj|ƒntdƒ‚dS)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)r‚r}rr )r„rÙrr6r6r7r s  zTarFile.makefifocCsnttdƒ sttdƒ r tdƒ‚|j}|dkr2d}|jƒrF|tjO}n |tjO}tj||tj |j |j ƒƒdS)zzFilter for extraction)ÚmetavarÚchoicesr/z-lz--listú zShow listing of a tarfile)r0r/z-ez --extractú+ú zExtract tarfile into target dir)Únargsr0r/z-cz--createúúzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction rz)ràz{!r} is a tar archive.z{!r} is not a tar archive. zr:*)rÍr$)r%rÎrâz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rŒrŽr�)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)r2r4)r6r7)ÚargparseÚArgumentParserÚ add_argumentrÛZadd_mutually_exclusive_groupÚ parse_argsrÎr÷ÚexitZtestrrr®rormr%rÍrPrkrr0r}ÚcurdirZ format_helprõZcreateÚpopr%ÚsplitextrÒ)r8r+ÚparserrcÚargsr\r�Ztfr=r'Ztar_namermZextZ compressionsZtar_modeZ tar_filesÚ file_namer6r6r7Úmainc s’                  rCÚ__main__)r%r&r'r(r)r*r+r,)T)trtÚversionÚ __author__Z__date__Z __cvsid__Ú __credits__Úbuiltinsrr‰rmr}rÉrWrfrªrSr ÚrercrÆr˜rÈr¡ÚNotImplementedErrorrr Ú NameErrorÚ__all__rÜrØr1r¼r¨rrrrr4rrHryrxr6r7rr|ZCONTTYPEr"r!rIr.r0rWr rrrrZrvrLrsrfr+rFrtr…r Úgetfilesystemencodingr8r=rKrQrUrXrgrpÚ Exceptionrr rrr r rurvrwrHrxryrˆÚobjectr‘rÁÚBufferedReaderrÔrÜrÝrÞràrárârãrër÷rørúrûrÛr ÚcompilerarrrrCrqr6r6r6r7Ús&         wh   D h  b