a y4 fD£ã @sêdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZz ddlZWneyŽdZYn0z ddlZWney²dZYn0eefZzeef7ZWneyÜYn0gd¢ZdZd Zd Zd Zed Zd ZdZ dZ!dZ"dZ#dZ$d Z%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5e5Z6e$e%e&e'e*e+e,e(e)e-e.e/f Z7e$e%e,e/fZ8e-e.e/fZ9d!Z:hd"£Z;eej?d$krÀd%Z@ne A¡Z@d&d'„ZBd(d)„ZCd*d+„ZDd,e6fd-d.„ZEd/d0„ZFdedfd1d2„ZGd3d4„ZHGd5d6„d6eIƒZJGd7d8„d8eJƒZKGd9d:„d:eJƒZLGd;d<„d„d>eJƒZNGd?d@„d@eJƒZOGdAdB„dBeOƒZPGdCdD„dDeOƒZQGdEdF„dFeOƒZRGdGdH„dHeOƒZSGdIdJ„dJeOƒZTGdKdL„dLƒZUGdMdN„dNƒZVGdOdP„dPeWƒZXGdQdR„dReWƒZYGdSdT„dTe jZƒZ[GdUdV„dVeJƒZ\GdWdX„dXe\ƒZ]GdYdZ„dZe\ƒZ^Gd[d\„d\e\ƒZ_Gd]d^„d^e\ƒZ`Gd_d`„d`e\ƒZadsdadb„Zbdcdd„Zcdedf„Zddgdh„ZeecedeediœZfeWƒZgGdjdk„dkeWƒZhGdldm„dmeWƒZidndo„ZjeijZdpdq„ZkeldrkræekƒdS)tz,Read from and write to tar format archives. z0.9.0u"Lars Gustäbel (lars@gustaebel.de)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>r+r&r,r%)ÚatimeÚctimer(r)r*r'Úntúutf-8cCs8|durtdƒ‚| ||¡}|d|…|t|ƒtS)z8Convert a string to a null-terminated bytes object. Nzmetadata cannot contain None)Ú ValueErrorÚencodeÚlenÚNUL)ÚsÚlengthÚencodingÚerrors©r9ú/usr/lib64/python3.9/tarfile.pyÚstn§s r;cCs*| d¡}|dkr|d|…}| ||¡S)z8Convert a null-terminated bytes object to a string. réÿÿÿÿN)ÚfindÚdecode)r5r7r8Úpr9r9r:Únts¯s  r@cCs¤|ddvrbd}tt|ƒdƒD]}|dK}|||d7}q |ddkr dt|ƒd| }n>z"t|ddƒ}t| ¡p|d dƒ}Wntyžtd ƒ‚Yn0|S) z/Convert a number field to a python number. r)é€éÿr#érBéÚasciiÚstrictÚ0úinvalid header)Úranger3r@ÚintÚstripr1ÚInvalidHeaderError)r5ÚnÚir9r9r:Únti·s    rOrCcCsØt|ƒ}d|kr$d|dkrDnntd|d|fdƒt}n|tkrÌd|d |krrd|dkrÌnnV|dkrŠtdgƒ}ntdgƒ}d||}t|dƒD]}| d|d@¡|dL}q¬ntd ƒ‚|S) z/Convert a python number to a number field. rrCr#z%0*orErDrArBzoverflow in number field)rJÚbytesr4rÚ bytearrayrIÚinsertr1)rMÚdigitsÚformatr5rNr9r9r:ÚitnËs  2    rUcCs0dtt d|¡ƒ}dtt d|¡ƒ}||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. rDÚ 148B8x356BÚ 148b8x356b)ÚsumÚstructÚ unpack_from)ÚbufÚunsigned_chksumÚ signed_chksumr9r9r:Ú calc_chksumsès r^c Cs¦|pd}|dkrdS|dur.t |||¡dSt||ƒ\}}t|ƒD],}| |¡}t|ƒ|krf|dƒ‚| |¡qD|dkr¢| |¡}t|ƒ|kr˜|dƒ‚| |¡dS)zjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. i@rNúunexpected end of data)ÚshutilÚ copyfileobjÚdivmodrIÚreadr3Úwrite) ÚsrcÚdstr6Ú exceptionÚbufsizeÚblocksÚ remainderÚbr[r9r9r:raõs$       racCs8ttjddƒ}|dur(| |d¡ |¡}t|dddS)Nr7Úbackslashreplaceú )Úend)ÚgetattrÚsysÚstdoutr2r>Úprint)r5r7r9r9r:Ú _safe_printsrsc@seZdZdZdS)rzBase exception.N©Ú__name__Ú __module__Ú __qualname__Ú__doc__r9r9r9r:rsrc@seZdZdZdS)r z%General exception for extract errors.Nrtr9r9r9r:r sr c@seZdZdZdS)rz&Exception for unreadable tar archives.Nrtr9r9r9r:rsrc@seZdZdZdS)rz.Exception for unavailable compression methods.Nrtr9r9r9r:rsrc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.Nrtr9r9r9r:r !sr c@seZdZdZdS)r z!Base exception for header errors.Nrtr9r9r9r:r $sr c@seZdZdZdS)ÚEmptyHeaderErrorzException for empty headers.Nrtr9r9r9r:ry'sryc@seZdZdZdS)ÚTruncatedHeaderErrorz Exception for truncated headers.Nrtr9r9r9r:rz*srzc@seZdZdZdS)ÚEOFHeaderErrorz"Exception for end of file headers.Nrtr9r9r9r:r{-sr{c@seZdZdZdS)rLzException for invalid headers.Nrtr9r9r9r:rL0srLc@seZdZdZdS)ÚSubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nrtr9r9r9r:r|3sr|c@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}t ||d¡|_dS)N©ÚrÚwÚO_BINARYi¶) ÚosÚO_RDONLYÚO_WRONLYÚO_CREATÚO_TRUNCÚhasattrrrÚfd)ÚselfÚnameÚmoder9r9r:Ú__init__@sþý  z_LowLevelFile.__init__cCst |j¡dS©N)r‚Úcloserˆ©r‰r9r9r:rŽIsz_LowLevelFile.closecCst |j|¡Sr)r‚rcrˆ©r‰r'r9r9r:rcLsz_LowLevelFile.readcCst |j|¡dSr)r‚rdrˆ©r‰r5r9r9r:rdOsz_LowLevelFile.writeN)rurvrwrxrŒrŽrcrdr9r9r9r:r}:s  r}c@sreZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z ddd„Z dd„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|_|durt||ƒ}d|_|dkr6t|ƒ}| ¡}|pd|fg}d|_g|_d}|j}|D]L\}}||kr||j  d||df¡|j  d||||f¡||7}||}qX||jkrÆ|j  d||jdf¡dS)NrrŠFT) r¡Úoffsetr'ÚpositionrorŠr£Ú map_indexÚmaprÕ)r‰r¡ràr'Ú blockinfoÚlastposÚrealposr9r9r:rŒhs(    z_FileInFile.__init__cCsdSrr9rr9r9r:rÆsz_FileInFile.flushcCsdS©NTr9rr9r9r:Úreadable„sz_FileInFile.readablecCsdS)NFr9rr9r9r:Úwritable‡sz_FileInFile.writablecCs |j ¡Sr)r¡Úseekablerr9r9r:rêŠsz_FileInFile.seekablecCs|jS)z*Return the current file position. )rárr9r9r:rÑ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_ENDr1)r‰ráÚwhencer9r9r:rÒ’s   z_FileInFile.seekc Cs |dur|j|j}nt||j|jƒ}d}|dkr|j|j\}}}}||jkr`|krhqŽnqŽq6|jd7_|jt|jƒkr6d|_q6t|||jƒ}|râ|j ||j|¡|j |¡}t|ƒ|krØt dƒ‚||7}n |t |7}||8}|j|7_q,|S)z!Read data from the file. Nr•rr#r_) r'rárírãrâr3r¡rÒrcrr4) r‰r'r[ÚdataÚstartÚstopràr6rkr9r9r:rc¢s,     z_FileInFile.readcCs&| t|ƒ¡}||dt|ƒ…<t|ƒSr)rcr3)r‰rkr[r9r9r:ÚreadintoÁsz_FileInFile.readintocCs d|_dSrç)r£rr9r9r:rŽÆsz_FileInFile.close)N)N)rurvrwrxrŒrÆrèrérêrÑrërìrÒrcrõrŽr9r9r9r:rßbs  rßcseZdZ‡fdd„Z‡ZS)Ú ExFileObjectcs&t|j|j|j|jƒ}tƒ |¡dSr)rßr¡Ú offset_datar'ÚsparseÚsuperrŒ)r‰ÚtarfileÚtarinfor¡©Ú __class__r9r:rŒÌs ÿzExFileObject.__init__©rurvrwrŒÚ __classcell__r9r9rür:röÊsröc@s eZdZdS)Ú FilterErrorN)rurvrwr9r9r9r:r×srcseZdZ‡fdd„Z‡ZS)ÚAbsolutePathErrorcs ||_tƒ d|j›d¡dS)Nzmember z has an absolute path©rûrùrŒrŠ©r‰rûrür9r:rŒÛszAbsolutePathError.__init__rþr9r9rür:rÚsrcseZdZ‡fdd„Z‡ZS)ÚOutsideDestinationErrorcs.||_||_tƒ |j›d|›dd¡dS)Nz would be extracted to ú, ú which is outside the destination©rûÚ_pathrùrŒrŠ©r‰rûr%rür9r:rŒàs ÿz OutsideDestinationError.__init__rþr9r9rür:rßsrcseZdZ‡fdd„Z‡ZS)ÚSpecialFileErrorcs||_tƒ |j›d¡dS)Nz is a special filerrrür9r:rŒçszSpecialFileError.__init__rþr9r9rür:r æsr cseZdZ‡fdd„Z‡ZS)ÚAbsoluteLinkErrorcs||_tƒ |j›d¡dS)Nz is a link to an absolute pathrrrür9r:rŒìszAbsoluteLinkError.__init__rþr9r9rür:r ësr cseZdZ‡fdd„Z‡ZS)ÚLinkOutsideDestinationErrorcs.||_||_tƒ |j›d|›dd¡dS)Nz would link to rrrr rür9r:rŒñs ÿz$LinkOutsideDestinationError.__init__rþr9r9rür:r ðsr cCsäi}|j}tj |¡}| dtjf¡r@|j dtj¡}|d<tj |¡rTt|ƒ‚tj tj  ||¡¡}tj  ||g¡|krˆt ||ƒ‚|j }|durü|d@}|rê|  ¡s²| ¡rÌ|d@sÂ|dM}|dO}n| ¡sÜ| ¡râd}nt|ƒ‚||j krü||d<|rà|jdurd|d<|jdur*d|d <|jdur>d|d <|jdurRd|d <| ¡sf| ¡ràtj |j¡r~t|ƒ‚| ¡r¤tj  |tj |¡|j¡}ntj  ||j¡}tj |¡}tj  ||g¡|kràt||ƒ‚|S) Nú/rŠiíé@i¶ÿÿÿé€r‹r)r*r+r,)rŠr‚r%ÚrealpathrÞÚsepÚlstripÚisabsrrÖÚ commonpathrr‹ÚisregÚislnkÚisdirÚissymr r)r*r+r,Úlinknamer Údirnamer )ÚmemberÚ dest_pathÚfor_dataÚ new_attrsrŠÚ target_pathr‹r9r9r:Ú_get_filtered_attrs÷s^           þÿ  r cCs|Srr9)rrr9r9r:Úfully_trusted_filter6sr!cCs,t||dƒ}|r(|jfi|¤ddi¤ŽS|S)NFÚdeep©r r¹©rrrr9r9r:Ú tar_filter9s r%cCs,t||dƒ}|r(|jfi|¤ddi¤ŽS|S)NTr"Fr#r$r9r9r:Ú data_filter?s r&)Ú fully_trustedr›ròc@sÚeZdZdZedddddddd d d d d dddddddddZdidd„Zedd„ƒZej dd„ƒZedd„ƒZ e j dd„ƒZ dd„Z e e e e e e e e d e d!œ d"d#„Z d$d%„Zeed&fd'd(„Zd)d*„Zd+d,„Zd-d.„Zed/d0„ƒZd1d2„Zed3d4„ƒZed5d6„ƒZed7d8„ƒZed9d:„ƒZed;d<„ƒZed=d>„ƒZd?d@„ZdAdB„Z dCdD„Z!dEdF„Z"dGdH„Z#dIdJ„Z$dKdL„Z%dMdN„Z&dOdP„Z'dQdR„Z(dSdT„Z)dUdV„Z*dWdX„Z+dYdZ„Z,d[d\„Z-d]d^„Z.d_d`„Z/dadb„Z0dcdd„Z1dedf„Z2dgdh„Z3dS)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. zName of the archive member.zPermission bits.z6User ID of the user who originally stored this member.z7Group ID of the user who originally stored this member.zSize in bytes.zTime of last modification.zHeader checksum.z–File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.z User name.z Group name.zDevice major number.zDevice minor number.zThe tar header starts here.zThe file's data starts here.zMA dictionary containing key-value pairs of an associated pax extended header.zSparse member information.N)rŠr‹r)r*r'r(ÚchksumÚtyperr+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Šr‹r)r*r'r(r(ÚREGTYPEr)rr+r,r*r+ràr÷rør,©r‰rŠr9r9r:rŒus"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".©rŠrr9r9r:r%sz TarInfo.pathcCs ||_dSrr1r0r9r9r:r%’scCs|jS)z0In pax headers, "linkname" is called "linkpath".©rrr9r9r:r&–szTarInfo.linkpathcCs ||_dSrr2)r‰rr9r9r:r&›scCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)rýrurŠÚidrr9r9r:Ú__repr__ŸszTarInfo.__repr__T) rŠr(r‹rr)r*r+r,r"Ú_KEEPc CsŽ| rt |¡} n t |¡} || ur(|| _|| ur6|| _|| urD|| _|| urR|| _|| ur`|| _|| urn|| _|| ur||| _|| urŠ|| _ | S)zGReturn a deep copy of self with the given attributes replaced. ) ÚcopyÚdeepcopyrŠr(r‹rr)r*r+r,) r‰rŠr(r‹rr)r*r+r,r"r5Úresultr9r9r:r¹¢s(  zTarInfo.replacecCs€|jdurd}n |jd@}|j||j|j|j|j|j|j|j|j |j |j |j dœ }|dt kr||d d¡s||dd7<|S)z9Return the TarInfo's attributes as a dictionary. Néÿ) rŠr‹r)r*r'r(r(r)rr+r,r*r+r)rŠr )r‹rŠr)r*r'r(r(r)rr+r,r*r+ÚDIRTYPErÁ)r‰r‹Úinfor9r9r:Úget_info¾s(  ózTarInfo.get_infoÚsurrogateescapecCsz| ¡}| ¡D]\}}|durtd|ƒ‚q|tkrD| |||¡S|tkrZ| |||¡S|tkrn| ||¡Stdƒ‚dS)zq*z|| dd ¡Wn"tyt||||<Yq*Yn0t||ƒ|kr*||||<q*d D]„\}}d }||} t| t ƒ} | rÂt | ƒn| } d | krâd |dksònd ||<d}n| r| ||<d}|r˜||vr˜t | ƒ||<q˜|r4|  |t |¡} nd} | | |tdd¡S)z³Return the object as a ustar header block. If it cannot be represented this way, prepend a pax extended header sequence with supplement information. rDrŠr%rr&)r+r+é )r,r,rOrErF))r)rC)r*rC)r'é )r(rPFrrCr#Tr•r¹)rFr,r6rHrGr2ÚUnicodeEncodeErrorr3Ú isinstanceÚfloatÚroundÚstrÚ_create_pax_generic_headerÚXHDTYPErJr ) r‰r;r7r,rŠÚhnamer6rSÚ needs_paxÚvalÚ val_is_floatÚval_intr[r9r9r:rAs> þ      zTarInfo.create_pax_headercCs| |td¡S)zAReturn the object as a pax global header block sequence. r0)rVÚXGLTYPE)Úclsr,r9r9r:Úcreate_pax_global_header@sz TarInfo.create_pax_global_headercCs~| d¡}tdt|ƒƒD]T}d |d|…¡}d ||d…¡}t| ||¡ƒtkrt| ||¡ƒtkrqvqtdƒ‚||fS)zUSplit a name longer than 100 chars into a prefix and a name part. r r#Nzname is too long)ÚsplitrIr3rÖr2Ú LENGTH_PREFIXrHr1)r‰rŠr7r8Ú componentsrNrEr9r9r:rIFs ÿzTarInfo._posix_split_namec Cs¦| d¡ttfv}|r@t| dd¡d|ƒ}t| dd¡d|ƒ}ntdd||ƒ}tdd||ƒ}| dt¡}|durxtdƒ‚t| d d¡d ||ƒt| d d¡d @d|ƒt| d d¡d|ƒt| dd¡d|ƒt| dd¡d|ƒt| dd¡d|ƒd|t| dd¡d ||ƒ| dt¡t| dd¡d||ƒt| dd¡d||ƒ||t| dd¡d||ƒg}t  dt d  |¡¡} t | t d…ƒd} | dd…t d| dƒ| dd…} | S) z„Return a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. r)r*rrCr+r”NzTarInfo.type must not be NonerŠrr‹r9r)r*r'rPr(s rrDr+rOr,rErz%dsr•i”þÿÿz%06orEi›þÿÿ)ÚgetÚCHRTYPEÚBLKTYPErUr;r/r1rFrYr¾rÛrÖr^rP) r;rTr7r8Úhas_device_fieldsr*r+ÚfiletypeÚpartsr[r(r9r9r:rJVs:  ñ&zTarInfo._create_headercCs.tt|ƒtƒ\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes up to the next 512 byte border. r)rbr3rÛr4)Úpayloadrirjr9r9r:Ú_create_payload€szTarInfo._create_payloadcCsR| ||¡t}i}d|d<||d<t|ƒ|d<t|d<| |t||¡| |¡S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence for name. z ././@LongLinkrŠr)r'rD)r2r4r3rKrJr rj)r^rŠr)r7r8r;r9r9r:rLŠs ÿzTarInfo._create_gnu_long_headerc Cs0d}| ¡D]6\}}z| dd¡Wq ty@d}YqDYq 0q d}|rT|d7}| ¡D]\}}| d¡}|r€| |d¡}n | d¡}t|ƒt|ƒd}d } } |tt| ƒƒ} | | krÀqÆ| } q¦|tt| ƒd ƒd |d |d 7}q\i} d| d<|| d<t|ƒ| d<t| d<| | td d¡|  |¡S)z¡Return a POSIX.1-2008 extended or global header sequence that contains a list of keyword, value pairs. The values must be strings. Fr0rFTr•s21 hdrcharset=BINARY r=rÜrrEó ó=ó z././@PaxHeaderrŠr)r'rDr¹) r>r2rQr3rUrPrFrJr rj) r^r,r)r7ÚbinaryÚkeywordrBÚrecordsÚlrMr?r;r9r9r:rV›s<   ( ÿz"TarInfo._create_pax_generic_headerc Cstt|ƒdkrtdƒ‚t|ƒtkr(tdƒ‚| t¡tkr>tdƒ‚t|dd…ƒ}|t|ƒvrbt 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  d¡r†t|_|jtkr6d}g}tdƒD]j} z0t|||d…ƒ} t||d|d…ƒ} WntyòYqYn0| | | f¡|d7}q¢t|dƒ} t|dd…ƒ} || | f|_ | !¡rN|j  "d¡|_ |rp|jt#vrp|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ÊrPéiâiãiï)$r3ryrÛrzÚcountr4r{rOr^rLr@rŠr‹r)r*r'r(r(r)rr+r,r*r+ÚAREGTYPErÁr:ÚGNUTYPE_SPARSErIr1rÕÚboolr-rÚrstripÚ GNU_TYPES)r^r[r7r8r(ÚobjrEr¢ÚstructsrNràÚnumbytesÚ isextendedÚorigsizer9r9r:ÚfrombufÎsZ         zTarInfo.frombufcCs8|j t¡}| ||j|j¡}|j ¡t|_| |¡S)zOReturn the next TarInfo object from TarFile object tarfile. ) r¡rcrÛr…r7r8rÑràÚ _proc_member)r^rúr[r€r9r9r:Ú fromtarfile s zTarInfo.fromtarfilecCsT|jttfvr| |¡S|jtkr,| |¡S|jtttfvrF|  |¡S|  |¡SdS)zYChoose the right processing method depending on the type and call it. N) r)rNrMÚ _proc_gnulongr|Ú _proc_sparserWr]ÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r‰rúr9r9r:r†"s    zTarInfo._proc_membercCsR|j ¡|_|j}| ¡s$|jtvr4|| |j¡7}||_|  |j |j |j ¡|S)zfProcess a builtin type or an unknown type which will be treated as a regular file. ) r¡rÑr÷rr)ÚSUPPORTED_TYPESÚ_blockr'ràÚ_apply_pax_infor,r7r8)r‰rúràr9r9r:rŒ/s zTarInfo._proc_builtincCs„|j | |j¡¡}z| |¡}Wnty<tdƒ‚Yn0|j|_|jt krdt ||j |j ƒ|_ n|jtkr€t ||j |j ƒ|_|S)zSProcess the blocks that hold a GNU longname or longlink member. ú missing or bad subsequent header)r¡rcrŽr'r‡r r|ràr)rNr@r7r8rŠrMr)r‰rúr[Únextr9r9r:rˆ@s   zTarInfo._proc_gnulongc CsØ|j\}}}|`|r¨|j t¡}d}tdƒD]l}z0t|||d…ƒ}t||d|d…ƒ} WntyxYqšYn0|r| r| || f¡|d7}q,t|dƒ}q||_ |j  ¡|_ |j |  |j ¡|_||_ |S)z8Process a GNU sparse header plus extra headers. rérPryiø)r-r¡rcrÛrIrOr1rÕr}rørÑr÷rŽr'rà) r‰rúrrƒr„r[r¢rNràr‚r9r9r:r‰Vs(       zTarInfo._proc_sparsecCs,|j | |j¡¡}|jtkr&|j}n |j ¡}t  d|¡}|durX|  d¡  d¡|d<|  d¡}|dkrr|j }nd}t d¡}d}| ||¡}|s˜q6| ¡\} } t| ƒ} | dkr¼td ƒ‚|| d ¡d| d¡| d…} | | dd|j¡} | tvr| | ||j |j¡} n| | dd|j¡} | || <|| 7}q„z| |¡} Wnty`td ƒ‚Yn0d |vrz| | |¡nHd |vr”| | ||¡n.|  d¡dkrÂ|  d¡dkrÂ| | ||¡|jttfvr(|   ||j |j¡|j!| _!d|vr(| j"} |  #¡s| jt$vr"| |  | j¡7} | |_!| S)zVProcess an extended or global header as described in POSIX.1-2008. s\d+ hdrcharset=([^\n]+)\nNr#r0Ú hdrcharsetÚBINARYs(\d+) ([^=]+)=rrHr$rúGNU.sparse.mapúGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrGr')%r¡rcrŽr'r)r]r,r6ÚreÚsearchÚgroupr>rcr7ÚcompileÚmatchÚgroupsrJrLrnróÚ_decode_pax_fieldr8ÚPAX_NAME_FIELDSr‡r r|Ú_proc_gnusparse_01Ú_proc_gnusparse_00Ú_proc_gnusparse_10rWrŠrràr÷rr)r‰rúr[r,rœr“r7Úregexr¢r6rorBr‘ràr9r9r:r‹rsh       $ ÿ  ÿ ÿ     zTarInfo._proc_paxcCshg}t d|¡D]}| t| d¡ƒ¡qg}t d|¡D]}| t| d¡ƒ¡q:tt||ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.0. s\d+ GNU.sparse.offset=(\d+)\nr#s\d+ GNU.sparse.numbytes=(\d+)\nN)r˜ÚfinditerrÕrJršÚlistÚziprø)r‰r‘r,r[Úoffsetsrœr‚r9r9r:r¡ÚszTarInfo._proc_gnusparse_00cCs@dd„|d d¡Dƒ}tt|ddd…|ddd…ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|ƒ‘qSr9)rJ)Ú.0Úxr9r9r:Ú èr•z.TarInfo._proc_gnusparse_01..r•ú,Nr$r#)r`r¥r¦rø)r‰r‘r,rør9r9r:r åszTarInfo._proc_gnusparse_01cCs¨d}g}|j t¡}| dd¡\}}t|ƒ}t|ƒ|dkrtd|vrT||j t¡7}| dd¡\}}| t|ƒ¡q,|j ¡|_t t |ddd…|ddd…ƒƒ|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nrmr#r$) r¡rcrÛr`rJr3rÕrÑr÷r¥r¦rø)r‰r‘r,rúÚfieldsrør[Únumberr9r9r:r¢ës  zTarInfo._proc_gnusparse_10c CsÀ| ¡D]¨\}}|dkr&t|d|ƒq|dkr@t|dt|ƒƒq|dkrZt|dt|ƒƒq|tvr|tvr’zt||ƒ}Wntyd}Yn0|dkr¤| d¡}t|||ƒq| ¡|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer%r–r'zGNU.sparse.realsizerr N) r>ÚsetattrrJÚ PAX_FIELDSÚPAX_NUMBER_FIELDSr1r~r6r,)r‰r,r7r8rorBr9r9r:rûs"   zTarInfo._apply_pax_infocCs2z| |d¡WSty,| ||¡YS0dS)z1Decode a single field from a pax record. rFN)r>ÚUnicodeDecodeError)r‰rBr7Úfallback_encodingÚfallback_errorsr9r9r:ržs 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#)rbrÛ)r‰rzrirjr9r9r:rŽszTarInfo._blockcCs |jtvS©z4Return True if the Tarinfo object is a regular file.)r)Ú REGULAR_TYPESrr9r9r:r#sz TarInfo.isregcCs| ¡Sr´)rrr9r9r:Úisfile'szTarInfo.isfilecCs |jtkS)z!Return True if it is a directory.)r)r:rr9r9r:r+sz TarInfo.isdircCs |jtkS)z%Return True if it is a symbolic link.)r)ÚSYMTYPErr9r9r:r/sz TarInfo.issymcCs |jtkS)z!Return True if it is a hard link.)r)ÚLNKTYPErr9r9r:r3sz TarInfo.islnkcCs |jtkS)z(Return True if it is a character device.)r)rdrr9r9r:Úischr7sz TarInfo.ischrcCs |jtkS)z$Return True if it is a block device.)r)rerr9r9r:Úisblk;sz TarInfo.isblkcCs |jtkS)zReturn True if it is a FIFO.)r)ÚFIFOTYPErr9r9r:Úisfifo?szTarInfo.isfifocCs |jduSr)rørr9r9r:ÚissparseCszTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)r)rdrer»rr9r9r:ÚisdevFsz TarInfo.isdev)r”)4rurvrwrxÚdictÚ __slots__rŒÚpropertyr%Úsetterr&r4r5r¹r<rr rCr?r@rAÚ classmethodr_rIÚ staticmethodrJrjrLrVr…r‡r†rŒrˆr‰r‹r¡r r¢rržrŽrr¶rrrr¹rºr¼r½r¾r9r9r9r:rRsœè     ý  :  )   2 >  h  rc @säeZdZdZdZdZdZdZeZ e Z dZ e ZeZdZdfdd „Zedddefd d „ƒZedgd d „ƒZedhdd„ƒZedidd„ƒZedjdd„ƒZdddddœZdd„Zdd„Zdd„Zd d!„Zdkd"d#„Zdldd%œd&d'„Z dmdd(œd)d*„Z!dnd+d,„Z"d-d.„Z#doddd0œd1d2„Z$dpddd0œd4d5„Z%d6d7„Z&d8d9„Z'd:d;„Z(dd?„Z*dqd@dA„Z+dBdC„Z,dDdE„Z-dFdG„Z.dHdI„Z/dJdK„Z0dLdM„Z1dNdO„Z2dPdQ„Z3dRdS„Z4dTdU„Z5drdVdW„Z6dXdY„Z7dsdZd[„Z8d\d]„Z9d^d_„Z:d`da„Z;dbdc„Zd }| dvrRtdƒ‚t || |||ƒ} zˆ|| | fi|¤Ž} Wn|   ¡‚Yn0d| _ | S|dvr¼ˆj |||fi|¤Ž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 open)rúr:*csˆj|dkS)NÚtaropen)Ú OPEN_METH)r ©r^r9r:Únot_compressedsz$TarFile.open..not_compressed)ÚkeyNrz%file could not be opened successfullyú:r#r›rœú|r~zmode must be 'r' or 'w'FrËzundiscernible mode) r1ÚsortedrÝrorÑrrrÒr`r’rŽrrÜ) r^rŠr‹r¡rhÚkwargsrßr ÚfuncÚ saved_posÚfilemodeÚstreamrÙr9rÞr:rÖsP%            z TarFile.opencKs$|dvrtdƒ‚||||fi|¤ŽS)zCOpen uncompressed tar archive name for reading or writing. rÈrÊ)r1)r^rŠr‹r¡rär9r9r:rÜ1szTarFile.taropenrµcKsæ|dvrtdƒ‚zddlm}Wnty:tdƒ‚Yn0z|||d||ƒ}Wn,ty~|durx|dkrxtd ƒ‚‚Yn0z|j|||fi|¤Ž}Wn@tyÆ| ¡|dkrÀtd ƒ‚‚Yn| ¡‚Yn0d |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. ©rr€r©úmode must be 'r', 'w' or 'x'r)ÚGzipFilezgzip module is not availablerkNrrÇF) r1Úgziprër¥rr®rrÜrŽr)r^rŠr‹r¡Ú compresslevelrärërÙr9r9r:Úgzopen9s0   zTarFile.gzopenc Ks¸|dvrtdƒ‚zddlm}Wnty:tdƒ‚Yn0||pD|||d}z|j|||fi|¤Ž}WnDttfy˜| ¡|dkr’t dƒ‚‚Yn| ¡‚Yn0d |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rérêr)ÚBZ2Filer˜)rírznot a bzip2 fileF) r1r—rïr¥rrÜr®ÚEOFErrorrŽrr)r^rŠr‹r¡rírärïrÙr9r9r:Úbz2openZs& zTarFile.bz2openc Ks¼|dvrtdƒ‚zddlm}m}Wnty>tdƒ‚Yn0||pH|||d}z|j|||fi|¤Ž}WnD|tfyœ| ¡|dkr–t dƒ‚‚Yn| ¡‚Yn0d |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rérêr)ÚLZMAFiler²rš)Úpresetrznot an lzma fileF) r1r°ròr²r¥rrÜrðrŽrr) r^rŠr‹r¡róräròr²rÙr9r9r:Úxzopenvs& zTarFile.xzopenrÜrîrñrô)r›r–r—r™cCs˜|jr dSd|_zp|jdvrn|j ttd¡|jtd7_t|jtƒ\}}|dkrn|j tt|¡W|j s”|j  ¡n|j s’|j  ¡0dS)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NTrËr$r) r£r‹r¡rdr4rÛràrbÚ RECORDSIZErrŽ)r‰rirjr9r9r:rŽs  ÿz TarFile.closecCs(| | d¡¡}|dur$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. r Nzfilename %r not found)Ú _getmemberr~ÚKeyError)r‰rŠrûr9r9r:Ú getmember²s zTarFile.getmembercCs| ¡|js| ¡|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Õrr9r9r:Ú getmembers½szTarFile.getmemberscCsdd„| ¡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‘qSr9r1)r¨rûr9r9r:rªËr•z$TarFile.getnames..)rûrr9r9r:ÚgetnamesÇszTarFile.getnamesc CsZ| d¡|dur|j}|dur$|}tj |¡\}}| tjd¡}| d¡}| ¡}||_ |dur€|j stt  |¡}qŽt  |¡}nt  | ¡¡}d}|j}t  |¡rþ|j|jf} |j sæ|jdkræ| |jvræ||j| kræt} |j| }nt} | drü||j| <nht  |¡rt} nVt  |¡r"t} nDt  |¡r>t} t |¡}n(t  |¡rPt} nt   |¡rbt!} ndS||_||_"|j#|_$|j%|_&| tkr–|j'|_(nd|_(|j)|_*| |_+||_,t-râzt- .|j$¡d|_/Wnt0yàYn0t1rzt1 2|j&¡d|_3Wnt0yYn0| tt!fvrVt4tdƒrVt4tdƒrVt 5|j6¡|_7t 8|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 r”r#rÚmajorÚminor):rùrŠr‚r%Ú splitdriver¹rrrûrúrÐÚlstatÚstatÚfstatÚfilenoÚst_modeÚS_ISREGÚst_inoÚst_devÚst_nlinkr×r¸r/ÚS_ISDIRr:ÚS_ISFIFOr»ÚS_ISLNKr·ÚreadlinkÚS_ISCHRrdÚS_ISBLKrer‹Úst_uidr)Úst_gidr*Úst_sizer'Úst_mtimer(r)rÚpwdÚgetpwuidr+r÷ÚgrpÚgetgrgidr,r‡rþÚst_rdevr*rÿr+) r‰rŠÚarcnamer¡ÚdrvrûÚstatresrÚstmdÚinoder)r9r9r:Ú gettarinfoÍs„      ÿ ÿ          zTarFile.gettarinfoT)rÕcCs*| ¡|dur|}|D] }|rÎ|jdur6tdƒntt |j¡ƒtd|jpT|j|jp^|jfƒ|  ¡sv|  ¡rtdd|j |j fƒntd|j ƒ|jdur²tdƒntdt |j¡dd …ƒt|j| ¡ràd nd ƒ|r| ¡rtd |jƒ| ¡rtd |jƒtƒqdS)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ùr‹rsrrçr+r)r,r*r¹rºr*r+r'r(r¿Ú localtimerŠrrrrrr)r‰ÚverboserÕrûr9r9r:r¥0s8    ÿÿ  ÿ  z TarFile.list©ÚfiltercCsL| d¡|dur|}|jdurFtj |¡|jkrF| dd|¡dS| d|¡| ||¡}|durz| dd|¡dS|dur¦||ƒ}|dur¦| dd|¡dS| ¡ræt|dƒ}|  ||¡Wdƒn1sÚ0Ynb|  ¡r>|  |¡|rHt t  |¡ƒD],}|j tj ||¡tj ||¡||d qn |  |¡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. `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ýNr$ztarfile: Skipped %rr#ztarfile: Unsupported type %rútarfile: Excluded %rrÅr!)rùrŠr‚r%rÏÚ_dbgrrrÎÚaddfilerrãÚlistdirÚaddrÖ)r‰rŠrÚ recursiver"rûÚfr9r9r:r'Vs6    ,  ÿ z TarFile.addcCs¾| d¡t |¡}| |j|j|j¡}|j |¡|jt |ƒ7_|j }|dur®t ||j|j |dt |j tƒ\}}|dkrœ|j tt|¡|d7}|j|t7_|j |¡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)rhrr#)rùr6rCrTr7r8r¡rdràr3rÔrar'rbrÛr4rÕrÕ)r‰rûr¡r[rhrirjr9r9r:r%‰s   zTarFile.addfilecCsT|dur|j}|durøtj d¡}|dur z ttƒ}WntyJYnV0ddl}|jddd}||  |¡Wdƒn1s†0Y|jdddd}|ràz t |}Wn$t yÔt d|›d ƒd‚Yn0||_|St rôt d t¡tStSt|tƒr td ƒ‚|St|ƒr|Sz t |WSt yNt d|›d ƒd‚Yn0dS) NÚ PYTHON_TARFILE_EXTRACTION_FILTERr)ú#)Ú interpolationÚcomment_prefixesrúr”)Úfallbackzfilter z not foundaThe 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.zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)Úextraction_filterr‚ÚenvironrcrÎÚ_CONFIG_FILENAMEÚFileNotFoundErrorÚ configparserÚ ConfigParserÚ read_fileÚ_NAMED_FILTERSr÷r1Ú_RH_SAFER_DEFAULTÚwarningsÚwarnÚRuntimeWarningr%r!rRrUÚ TypeErrorÚcallable)r‰r"rŠÚfiler3Úconfr9r9r:Ú_get_filter_function¢sZ    þ(þ  ø  ÿ  zTarFile._get_filter_functionÚ.)Ú numeric_ownerr"c Csòg}| |¡}|dur|}|D]F}| |||¡}|dur:q| ¡rL| |¡|j||| ¡ |dq|jdd„dd|D]p}tj ||j ¡} z,|j || |d|  || ¡|  || ¡Wq|t yê} z| | ¡WYd} ~ q|d} ~ 00q|dS)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_attrsrAcSs|jSrr1)rÉr9r9r:Úør•z$TarFile.extractall..T)ràÚreverse)rA)r?Ú_get_extract_tarinforrÕÚ _extract_oneÚsortr‚r%rÖrŠÚchownÚutimeÚchmodr Ú_handle_nonfatal_error) r‰r%rÕrAr"Ú directoriesÚfilter_functionrrûÚdirpathrÚr9r9r:Ú extractall×s,  ÿ zTarFile.extractallr”cCs4| |¡}| |||¡}|dur0| ||||¡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?rFrG)r‰rr%rCrAr"rNrûr9r9r:Úextract s zTarFile.extractc CsÒt|tƒr| |¡}n|}|}z|||ƒ}Wn^ttfy^}z| |¡WYd}~n6d}~0tyŠ}z| |¡WYd}~n d}~00|durª| dd|j ¡dS|  ¡rÎt   |¡}t j  ||j¡|_|S)z@Get filtered TarInfo (or None) from member, which might be a strNr$r#)rRrUrør®rÚ_handle_fatal_errorr rLr$rŠrr6r‚r%rÖrr.)r‰rrNr%rûÚ unfilteredrÚr9r9r:rF s"    zTarFile._get_extract_tarinfoc CsŒ| d¡z"|j|tj ||j¡||dWnZtyZ}z| |¡WYd}~n6d}~0ty†}z|  |¡WYd}~n d}~00dS)z%Extract from filtered tarinfo to diskrrBN) rùÚ_extract_memberr‚r%rÖrŠr®rRr rL)r‰rûr%rCrArÚr9r9r:rG. s þ zTarFile._extract_onecCs"|jdkr‚n| dd|¡dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#ú tarfile: %sN)rÓr$©r‰rÚr9r9r:rL; s zTarFile._handle_nonfatal_errorcCsn|jdkr‚n\t|tƒrP|jdur6| dd|j¡qj| dd|j|jf¡n| ddt|ƒj|f¡dS)z1Handle "fatal" error according to self.errorlevelrNr#rUztarfile: %s %rztarfile: %s %s)rÓrRr®Úfilenamer$Ústrerrorr)rurVr9r9r:rRB s   zTarFile._handle_fatal_errorcCs‚| d¡t|tƒr | |¡}n|}| ¡s6|jtvrB| ||¡S| ¡sR|  ¡rzt|j t ƒrht dƒ‚q~|  | |¡¡SndSdS)a\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. For all other existing members, None is returned. If `member' does not appear in the archive, KeyError is raised. rz'cannot extract (sym)link as file objectN)rùrRrUrørr)rÚ fileobjectrrr¡r’r Ú extractfileÚ_find_link_target)r‰rrûr9r9r:rZN s      zTarFile.extractfilecCsT| d¡}| dtj¡}tj |¡}|r>tj |¡s>t |¡| ¡sN|  ¡rh|  dd|j |j f¡n|  d|j ¡|  ¡rŒ| ||¡nŽ| ¡r¢| ||¡nx| ¡r¸| ||¡nb| ¡sÈ| ¡rÖ| ||¡nD| ¡sæ|  ¡rô| ||¡n&|jtvr| ||¡n | ||¡|rP| |||¡|  ¡sP| ||¡| ||¡dS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. r r#z%s -> %sN)r~r¹r‚rr%rrÍÚmakedirsrrr$rŠrrÚmakefilerÚmakedirr¼Úmakefifor¹rºÚmakedevÚmakelinkr)rÚ makeunknownrIrKrJ)r‰rûÚ targetpathrCrAÚ upperdirsr9r9r:rTn s4       zTarFile._extract_membercCs>z&|jdurt |¡n t |d¡Wnty8Yn0dS)z,Make a directory called targetpath. NiÀ)r‹r‚ÚmkdirÚFileExistsError©r‰rûrcr9r9r:r^Ÿ s    zTarFile.makedircCs¢|j}| |j¡|j}t|dƒl}|jdurn|jD]"\}}| |¡t|||t|ƒq4| |j¡|  ¡nt|||jt|ƒWdƒn1s”0YdS)z'Make a file called targetpath. rÆN) r¡rÒr÷rÔrÎrørarr'Útruncate)r‰rûrcÚsourcerhÚtargetràr'r9r9r:r]­ s      zTarFile.makefilecCs"| ||¡| dd|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)r]r$r)rgr9r9r:rb½ s ÿzTarFile.makeunknowncCs"ttdƒrt |¡ntdƒ‚dS)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)r‡r‚rkr rgr9r9r:r_Å s  zTarFile.makefifocCsjttdƒrttdƒstdƒ‚|j}|dur.d}| ¡rB|tjO}n |tjO}t ||t  |j |j ¡¡dS)zrurvrwrxrÒrÐrÑrÓrrTr r7r8rrûrörYr/rŒrÃrõrrÜrîrñrôrÝrŽrørûrürr¥r'r%r?rPrQrFrGrLrRrZrTr^r]rbr_r`rarIrKrJr‘rörúrùr[r„r$r‰r‹r9r9r9r:rKsý oZ    ü    c&3 5ÿ -ÿ    ÿ 1! ? ( rcCsFz,t|dƒrt|d}nt|ƒ}| ¡WdSty@YdS0dS)z¤Return True if name points to a tar archive that we are able to handle, else return False. 'name' should be a string, file, or file-like object. rc)r¡TFN)r‡rrŽr)rŠrÙr9r9r:rõ s   rc Cs`ddl}d}|j|d}|jdddddd |jd d td d |jdd}|jddddd|jdddddd|jdddddd|jdd dd!d| ¡}|jrº|jdurº| d"d#¡|j durJ|j }t |ƒr4t |d$ƒ*}|  ¡t |  ¡tjd%Wdƒn1s0Y|jrFt d& |¡ƒn| d"d' |¡¡n|jdurº|j}t |ƒr¤t  |d(¡}|j|jd)Wdƒn1s˜0Yn| d"d' |¡¡n¢|jdur¤t|jƒd"krè|jd}tj}n,t|jƒd*kr|j\}}n| d"| ¡¡t |ƒrt  |d(¡ }|j||jd+Wdƒn1sR0Y|jr¢|d,krzd- |¡} n d. ||¡} t | ƒn| d"d' |¡¡n¸|jdur\|j d¡} tj | ¡\} } d/d/d0d0d1d1d1d1d2œ} | | vrød3| | nd4}|j}t  | |¡&}|D]}| |¡qWdƒn1s<0Y|jr\t d5 | ¡ƒdS)6Nrz3A simple command-line interface for tarfile module.)Ú descriptionz-vz --verboseÚ store_trueFzVerbose output)ÚactionÚdefaultÚhelpz--filterz zFilter for extraction)ÚmetavarÚchoicesrT)Úrequiredz-lz--listú zShow listing of a tarfile)r‘rz-ez --extractú+)r”z zExtract tarfile into target dir)Únargsr‘rz-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction rr…z{!r} is a tar archive.z{!r} is not a tar archive. rÛ)r r$)r%r"r@z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r–r™r—)r·z.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r€z{!r} file created.)ÚargparseÚArgumentParserÚ add_argumentr6Úadd_mutually_exclusive_groupÚ parse_argsr"rQÚexitÚtestrrrûrrrpr†r rTr¥rr3r‚ÚcurdirÚ format_helprPÚcreateÚpopr%Úsplitextr')r—rŒÚparserršÚargsrer›ÚtfržrˆÚtar_nameÚ_ÚextÚ compressionsÚtar_modeÚ tar_filesÚ file_namer9r9r:Úmain s   ÿþ  ÿ þ þ ÿ    2  0    0  ÿ   õ .r­Ú__main__)T)mrxÚversionÚ __author__Ú __credits__ÚbuiltinsrrÎrpr‚rër`rr¿rYr6r˜r8rr¥rÚAttributeErrorÚNotImplementedErrorrsr®Ú NameErrorÚ__all__r7r1r4rÛrõrKrFrHrGrar/r{r¸r·rdrer:r»ÚCONTTYPErNrMr|rWr]rŠr rrrrrµrr¯rŸrSrJr°rŠr Úgetfilesystemencodingr;r@rOrUr^rarsr{rr rrr r ryrzr{rLr|r}r’ÚobjectržrßÚBufferedReaderrörrrr r r r r!r%r&r6r5rrrr­rur9r9r9r:Ús        üÿÿú  sh  ?ý ~3_