a °:jÙzã @sPdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZz ddlZWney†dZYn0z ddlZWneyªdZYn0eefZzeef7ZWneyÔYn0gd¢ZdZd Zed Zd Zd Zd Zd ZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2e2Z3e!e"e#e$e'e(e)e%e&e*e+e,f Z4e!e"e)e,fZ5e*e+e,fZ6dZ7hd £Z8e9e9e9e:e:e:d!œZ;ej¡Z=d$d%„Z?d&d'„Z@d(d)„ZAd*e3fd+d,„ZBd-d.„ZCdedfd/d0„ZDd1d2„ZEGd3d4„d4eFƒZGGd5d6„d6eGƒZHGd7d8„d8eGƒZIGd9d:„d:eGƒZJGd;d<„d„d>eGƒZLGd?d@„d@eLƒZMGdAdB„dBeLƒZNGdCdD„dDeLƒZOGdEdF„dFeLƒZPGdGdH„dHeLƒZQGdIdJ„dJƒZRGdKdL„dLƒZSGdMdN„dNeTƒZUGdOdP„dPeTƒZVGdQdR„dRe jWƒZXe YdS¡ZZGdTdU„dUeTƒZ[GdVdW„dWeTƒZ\dXdY„Z]e\jZdZd[„Z^e_d\krLe^ƒdS)]z,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_FORMATró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,)ZatimeÚctimer(r)r*r'Úntúutf-8cCs(| ||¡}|d|…|t|ƒtS)z8Convert a string to a null-terminated bytes object. N)ÚencodeÚlenÚNUL)ÚsÚlengthÚencodingÚerrors©r7ú/usr/lib/python3.9/tarfile.pyÚstnžs r9cCs*| d¡}|dkr|d|…}| ||¡S)z8Convert a null-terminated bytes object to a string. réÿÿÿÿN)ÚfindÚdecode)r3r5r6Úpr7r7r8Ú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#ér@éÚasciiÚstrictÚ0úinvalid header)Úranger1r>ÚintÚstripÚ ValueErrorÚInvalidHeaderError)r3ÚnÚir7r7r8Únti¬s    rNrAcCsØ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. rrAr#z%0*orCrBr?r@zoverflow in number field)rHÚbytesr2rÚ bytearrayrGÚinsertrJ)rLÚdigitsÚformatr3rMr7r7r8ÚitnÀs  2    rTcCs0dtt 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. rBZ 148B8x356BZ 148b8x356b)ÚsumÚstructZ unpack_from)ÚbufZunsigned_chksumZ signed_chksumr7r7r8Ú calc_chksumsÝs rXc 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ÚdivmodrGÚreadr1Úwrite) ÚsrcZdstr4Ú exceptionÚbufsizeÚblocksÚ remainderÚbrWr7r7r8r[ês$       r[cCs8ttjddƒ}|dur(| |d¡ |¡}t|dddS)Nr5Úbackslashreplaceú )Úend)ÚgetattrÚsysÚstdoutr0r<Úprint)r3r5r7r7r8Ú _safe_printsrlc@seZdZdZdS)rzBase exception.N©Ú__name__Ú __module__Ú __qualname__Ú__doc__r7r7r7r8r src@seZdZdZdS)r z%General exception for extract errors.Nrmr7r7r7r8r sr c@seZdZdZdS)rz&Exception for unreadable tar archives.Nrmr7r7r7r8rsrc@seZdZdZdS)rz.Exception for unavailable compression methods.Nrmr7r7r7r8rsrc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.Nrmr7r7r7r8r sr c@seZdZdZdS)r z!Base exception for header errors.Nrmr7r7r7r8r sr c@seZdZdZdS)ÚEmptyHeaderErrorzException for empty headers.Nrmr7r7r7r8rrsrrc@seZdZdZdS)ÚTruncatedHeaderErrorz Exception for truncated headers.Nrmr7r7r7r8rssrsc@seZdZdZdS)ÚEOFHeaderErrorz"Exception for end of file headers.Nrmr7r7r7r8rt"srtc@seZdZdZdS)rKzException for invalid headers.Nrmr7r7r7r8rK%srKc@seZdZdZdS)ÚSubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nrmr7r7r7r8ru(sruc@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ÚhasattrrzrÚfd)ÚselfÚnameÚmoder7r7r8Ú__init__5sþý  z_LowLevelFile.__init__cCst |j¡dS©N)r{Úcloser©r‚r7r7r8r‡>sz_LowLevelFile.closecCst |j|¡Sr†)r{r]r©r‚r'r7r7r8r]Asz_LowLevelFile.readcCst |j|¡dSr†)r{r^r©r‚r3r7r7r8r^Dsz_LowLevelFile.writeN)rnrorprqr…r‡r]r^r7r7r7r8rv/s  rvc@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|ƒ}| ¡}|psz_StreamProxy.__init__cCs|jj|_|jSr†)ršr]rWr‰r7r7r8r]Bs z_StreamProxy.readcCsP|j d¡rdS|jdd…dkr8|jdd…dkr8d S|j d ¡rHd Sd SdS) Ns‹rrésBZhrºé s1AY&SYr)s]€sý7zXZr’r”)rWÚ startswithrˆr7r7r8r˜Fs $ z_StreamProxy.getcomptypecCs|j ¡dSr†)ršr‡rˆr7r7r8r‡Psz_StreamProxy.closeN)rnrorprqr…r]r˜r‡r7r7r7r8r—9s  r—c@sjeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z e j fdd„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|_|dur>d|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'ÚpositionrhrƒrœÚ map_indexÚmaprÃ)r‚ršrÍr'Z blockinfoZlastposZrealposr7r7r8r…]s(    z_FileInFile.__init__cCsdSr†r7rˆr7r7r8r¶vsz_FileInFile.flushcCsdS©NTr7rˆr7r7r8Úreadableysz_FileInFile.readablecCsdS)NFr7rˆr7r7r8Úwritable|sz_FileInFile.writablecCs |j ¡Sr†)ršÚseekablerˆr7r7r8rÔsz_FileInFile.seekablecCs|jS)z*Return the current file position. )rÎrˆr7r7r8r¿‚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_ENDrJ)r‚rÎÚwhencer7r7r8rÀ‡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#rY) r'rÎr×rÐrÏr1ršrÀr]rr2) r‚r'rWÚdataÚstartÚstoprÍr4rdr7r7r8r]—s,     z_FileInFile.readcCs&| t|ƒ¡}||dt|ƒ…<t|ƒSr†)r]r1)r‚rdrWr7r7r8Úreadinto¶sz_FileInFile.readintocCs d|_dSrÑ)rœrˆr7r7r8r‡»sz_FileInFile.close)N)N)rnrorprqr…r¶rÒrÓrÔr¿rÕrÖrÀr]rßr‡r7r7r7r8rÌWs  rÌcseZdZ‡fdd„Z‡ZS)Ú ExFileObjectcs&t|j|j|j|jƒ}tƒ |¡dSr†)rÌršÚ offset_datar'ÚsparseÚsuperr…)r‚ÚtarfileÚtarinforš©Ú __class__r7r8r…Ás ÿzExFileObject.__init__)rnrorpr…Ú __classcell__r7r7rær8rà¿sràs([0-9]{1,20}) c@sÞeZdZdZedddddddd d d d d dddddddddZdkdd„Zedd„ƒZej dd„ƒZedd„ƒZ e j dd„ƒZ dd„Z d d!„Z e ed"fd#d$„Zd%d&„Zd'd(„Zd)d*„Zed+d,„ƒZd-d.„Zed/d0„ƒZed1d2„ƒZed3d4„ƒZed5d6„ƒZed7d8„ƒZed9d:œd;d<„ƒZed=d>„ƒZed9d:œd?d@„ƒZdAdB„ZdCdD„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„Z/dcdd„Z0dedf„Z1dgdh„Z2didj„Z3dS)lraInformational 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ÚtypeÚlinknamer+r,ÚdevmajorÚdevminorrÍráÚ pax_headersrâräÚ_sparse_structsÚ _link_targetrcCsj||_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¤rrN)rƒr„r)r*r'r(réÚREGTYPErêrër+r,rìrírÍrárârî©r‚rƒr7r7r8r…ñs"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".©rƒrˆr7r7r8r% sz TarInfo.pathcCs ||_dSr†róròr7r7r8r%scCs|jS)z0In pax headers, "linkname" is called "linkpath".©rërˆr7r7r8r&szTarInfo.linkpathcCs ||_dSr†rô)r‚rër7r7r8r&scCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)rçrnrƒÚidrˆr7r7r8Ú__repr__szTarInfo.__repr__cCsl|j|jd@|j|j|j|j|j|j|j|j |j |j |j dœ }|dt krh|d d¡sh|dd7<|S)z9Return the TarInfo's attributes as a dictionary. éÿ) rƒr„r)r*r'r(rérêrër+r,rìrírêrƒú/)rƒr„r)r*r'r(rérêrër+r,rìríÚDIRTYPEr³)r‚Úinfor7r7r8Úget_infos"ózTarInfo.get_infoÚsurrogateescapecCsT| ¡}|tkr| |||¡S|tkr4| |||¡S|tkrH| ||¡Stdƒ‚dS)zq*z|| dd ¡Wn"tyt||||<Yq*Yn0t||ƒ|kr*||||<q*d D]`\}}||vr²d ||<q˜||}d |krÖd |d kränn t|t ƒr˜t |ƒ||<d ||<q˜|r|  |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. rrƒr%rër&)r+r+é )r,r,r rCrD))r)rA)r*rA)r'é )r(r rrAr#rŽr®)rrîÚcopyrrr0ÚUnicodeEncodeErrorr1Ú isinstanceÚfloatÚstrÚ_create_pax_generic_headerÚXHDTYPErr ) r‚rúr5rîrƒZhnamer4rRÚvalrWr7r7r8rÿ_s4 þ    *  zTarInfo.create_pax_headercCs| |td¡S)zAReturn the object as a pax global header block sequence. r/)rÚXGLTYPE)Úclsrîr7r7r8Úcreate_pax_global_headersz 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)ÚsplitrGr1rÄr0Ú LENGTH_PREFIXrrJ)r‚rƒr5r6Z componentsrMrr7r7r8r–s ÿzTarInfo._posix_split_namec Cs’| d¡ttfv}|r@t| dd¡d|ƒ}t| dd¡d|ƒ}ntdd||ƒ}tdd||ƒ}t| dd¡d||ƒt| d d¡d @d|ƒt| d d¡d|ƒt| d d¡d|ƒt| d d¡d|ƒt| dd¡d|ƒd| dt¡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ìrrArírrƒrr„r÷r)r*r'r r(s rërr+r r,rrz%dsrŽNi”þÿÿz%06orCi›þÿÿ) ÚgetÚCHRTYPEÚBLKTYPErTr9rñrrVr°rÈrÄrXrO) rúrSr5r6Zhas_device_fieldsrìríÚpartsrWrér7r7r8r¦s4  ñ&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)r\r1rÈr2)Zpayloadrbrcr7r7r8Ú_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'r)r0r2r1rrr r)rrƒrêr5r6rúr7r7r8r Ô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. Fr/rDTrŽs21 hdrcharset=BINARY rürÉrrCó ó=ó z././@PaxHeaderrƒrêr'rr®) Úitemsr0rr1rrOrrr r) rrîrêr5ZbinaryÚkeywordÚvalueZrecordsÚlrLr=rúr7r7r8rås<   ( ÿz"TarInfo._create_pax_generic_headercCs| |||¡S)zÂConstruct a TarInfo object from a 512 byte bytes object. To support the old v7 tar format AREGTYPE headers are transformed to DIRTYPE headers if their name ends in '/'. )Ú_frombuf)rrWr5r6r7r7r8ÚfrombufszTarInfo.frombufT©Údircheckc Cszt|ƒ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…||ƒ}|rŒ|jtkrŒ|j  d¡rŒt|_|jtkrrƒr„r)r*r'r(rérêrër+r,rìríÚAREGTYPEr³rùÚGNUTYPE_SPARSErGrJrÃÚboolrïÚisdirÚrstripÚ GNU_TYPES)rrWr5r6r*réÚobjrr›ÚstructsrMrÍÚnumbytesÚ isextendedÚorigsizer7r7r8r'!sZ          zTarInfo._frombufcCs | |¡S)zOReturn the next TarInfo object from TarFile object tarfile. )Ú _fromtarfile)rrär7r7r8Ú fromtarfileeszTarInfo.fromtarfilecCs<|j t¡}|j||j|j|d}|j ¡t|_| |¡S)z; See dircheck documentation in _frombuf(). r)) ršr]rÈr'r5r6r¿rÍÚ _proc_member)rrär*rWr:r7r7r8r?ls zTarInfo._fromtarfilecCsT|jttfvr| |¡S|jtkr,| |¡S|jtttfvrF|  |¡S|  |¡SdS)zYChoose the right processing method depending on the type and call it. N) rêr r Ú _proc_gnulongr5Ú _proc_sparserrÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r‚rär7r7r8rAs    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áÚisregrêÚSUPPORTED_TYPESÚ_blockr'rÍÚ_apply_pax_inforîr5r6)r‚rärÍr7r7r8rFŽs zTarInfo._proc_builtincCsˆ|j | |j¡¡}z|j|dd}Wnty@tdƒ‚Yn0|j|_|jt krht ||j |j ƒ|_ n|jtkr„t ||j |j ƒ|_|S)zSProcess the blocks that hold a GNU longname or longlink member. Fr)ú missing or bad subsequent header)ršr]rIr'r?r rurÍrêr r>r5r6rƒr rë)r‚rärWÚnextr7r7r8rBŸ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ér r2iø)rïršr]rÈrGrNrJrÃr6râr¿rárIr'rÍ) r‚rär;r=r>rWr›rMrÍr<r7r7r8rCµs(       zTarInfo._proc_sparsecCsÌ|j | |j¡¡}|jtkr&|j}n |j ¡}d}d}g}t|ƒ|krh||dkrht   ||¡}spt dƒ‚zt |  d¡ƒ}Wntyœt dƒ‚Yn0|dkr®t dƒ‚||t|ƒkrÆt dƒ‚| d¡|d} || d¡d| …} |  d¡\} } } | r| dks|| dkr$t dƒ‚| || | f¡| dkr^|dur^| d krZ|j}nd }||7}q<|durvd }|D]X\}} } | | d d |j¡}|tvr¶| | ||j|j¡}n| | d d |j¡}|||<qzz|j|d d }Wntytd ƒ‚Yn0d|vr| ||¡nFd|vr4| ||¡n.| d¡dkrb| d¡dkrb| |||¡|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. rNrFr#ér!rÊs hdrcharsetsBINARYr/Fr)rKúGNU.sparse.mapúGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrEr')%ršr]rIr'rêrrîrr1Ú_header_length_prefix_reÚmatchrKrHÚgrouprJrÝrgÚ partitionrÃr5Ú_decode_pax_fieldr6ÚPAX_NAME_FIELDSr?r ruÚ_proc_gnusparse_01Ú_proc_gnusparse_00rÚ_proc_gnusparse_10rrDrJrÍrárGrH)r‚rärWrîr›r5Ú raw_headersrSr4Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuer$r%rLrÍr7r7r8rEÑs|        ÿ  ÿ ÿ     zTarInfo._proc_paxc Cs¢g}g}|D]€\}}}|dkrRz| t| ¡ƒ¡WqŒtyNtdƒ‚YqŒ0q |dkr z| t| ¡ƒ¡Wq tyŠtdƒ‚Yq 0q tt||ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetrFsGNU.sparse.numbytesN)rÃrHr<rJrKÚlistÚziprâ)r‚rLr[Zoffsetsr<Ú_r$r%r7r7r8rYJs  zTarInfo._proc_gnusparse_00cCs@dd„|d d¡Dƒ}tt|ddd…|ddd…ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|ƒ‘qSr7)rH)Ú.0Úxr7r7r8Ú arŽz.TarInfo._proc_gnusparse_01..rOú,Nr$r#)rr\r]râ)r‚rLrîrâr7r7r8rX^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. Nr"r#r$) ršr]rÈrrHr1rÃr¿rár\r]râ)r‚rLrîräÚfieldsrârWZnumberr7r7r8rZds  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%rPr'zGNU.sparse.realsizerrøN) r#ÚsetattrrHÚ PAX_FIELDSÚPAX_NUMBER_FIELDSrJr8rrî)r‚rîr5r6r$r%r7r7r8rJts"   zTarInfo._apply_pax_infocCs2z| |d¡WSty,| ||¡YS0dS)z1Decode a single field from a pax record. rDN)r<ÚUnicodeDecodeError)r‚r%r5Zfallback_encodingZfallback_errorsr7r7r8rV‹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#)rKr\rÈ)r‚r3rbrcr7r7r8rI“s zTarInfo._blockcCs |jtvS©z4Return True if the Tarinfo object is a regular file.)rêÚ REGULAR_TYPESrˆr7r7r8rGŸsz TarInfo.isregcCs| ¡Srh)rGrˆr7r7r8Úisfile£szTarInfo.isfilecCs |jtkS)z!Return True if it is a directory.)rêrùrˆr7r7r8r7§sz TarInfo.isdircCs |jtkS)z%Return True if it is a symbolic link.)rêÚSYMTYPErˆr7r7r8Úissym«sz TarInfo.issymcCs |jtkS)z!Return True if it is a hard link.)rêÚLNKTYPErˆr7r7r8Úislnk¯sz TarInfo.islnkcCs |jtkS)z(Return True if it is a character device.)rêrrˆr7r7r8Úischr³sz TarInfo.ischrcCs |jtkS)z$Return True if it is a block device.)rêrrˆr7r7r8Úisblk·sz TarInfo.isblkcCs |jtkS)zReturn True if it is a FIFO.)rêÚFIFOTYPErˆr7r7r8Úisfifo»szTarInfo.isfifocCs |jduSr†)rârˆr7r7r8Úissparse¿szTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rêrrrqrˆr7r7r8ÚisdevÂsz TarInfo.isdev)r)4rnrorprqÚdictÚ __slots__r…Úpropertyr%Úsetterr&rörûrr rrýrþrÿÚ classmethodrrÚ staticmethodrrr rr(r'r@r?rArFrBrCrErYrXrZrJrVrIrGrjr7rlrnrorprrrsrtr7r7r7r8rÎsœè      1  #   2 C  y rc @s´eZdZdZdZdZdZdZeZ e Z dZ e ZeZd\dd „Zedddefd d „ƒZed]d d „ƒZed^dd„ƒZed_dd„ƒZed`dd„ƒZdddddœZdd„Zdd„Zdd„Zd d!„Zdad"d#„Zdbdd%œd&d'„Zdcdd(œd)d*„Z ddd+d,„Z!dedd.œd/d0„Z"dfdd.œd2d3„Z#d4d5„Z$dgd6d7„Z%d8d9„Z&d:d;„Z'dd?„Z)d@dA„Z*dBdC„Z+dDdE„Z,dFdG„Z-dHdI„Z.dJdK„Z/dhdLdM„Z0dNdO„Z1didPdQ„Z2dRdS„Z3dTdU„Z4dVdW„Z5dXdY„Z6dZd[„Z7dS)jrz=The TarFile Class provides an interface to tar archives. rFr#Nrxrüc Csªdddddœ}||vrtdƒ‚||_|||_|sh|jdkrTtj |¡sTd|_d|_t||jƒ}d |_n@|d urt|d ƒrt |j t t fƒr|j }t|d ƒr¢|j|_d |_|r¸tj  |¡nd |_ ||_|d urÒ||_|d urà||_|d urî||_|d urü||_|d ur ||_| |_| d ur0|jtkr0| |_ni|_| d urF| |_| d urV| |_| |_d |_g|_d |_|j ¡|_i|_zþ|jdkržd |_ | !¡|_ |jdkr2|j "|j¡z|j #|¡}|j $|¡WnXt%yü|j "|j¡Yq2Yn2t&y,}zt't |ƒƒ‚WYd }~n d }~00qª|jdvr|d |_|jr||j (|j )¡¡}|j *|¡|jt+|ƒ7_Wn&|js˜|j ,¡d |_‚Yn0d 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©rxÚaryr`ú!mode must be 'r', 'a', 'w' or 'x'r~ryFNrƒr„Trx©r~ryr`)-rJr„Ú_moder{r%ÚexistsÚ bltn_openr–r€rrƒrrOÚabspathršrSråÚ dereferenceÚ ignore_zerosr5r6rrîÚdebugÚ errorlevelÚ copybufsizerœÚmembersÚ_loadedr¿rÍÚinodesÚ firstmemberrLrÀr@rÃrtr rrrr^r1r‡)r‚rƒr„ršrSrår…r†r5r6rîr‡rˆr‰ZmodesÚerWr7r7r8r…ásŠ   ÿ          &   zTarFile.__init__c sÈ|s|stdƒ‚|dvr¬‡fdd„}tˆj|dD]l}tˆˆj|ƒ}|durV| ¡} z||d|fi|¤ŽWSttfyœ|dur”| | ¡Yq2Yq20q2tdƒ‚nd |vr| d d ¡\} }| pÌd} |pÔd }|ˆjvròtˆˆj|ƒ}n td |ƒ‚||| |fi|¤ŽSd |vrœ| d d ¡\} }| p4d} |p>d }| 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)rxúr:*csˆj|dkS)NÚtaropen)Ú OPEN_METH)r™©rr7r8Únot_compressedzsz$TarFile.open..not_compressed©ÚkeyNrxz%file could not be opened successfullyú:r#r”r•ú|rwzmode must be 'r' or 'w'Fr€zundiscernible mode) rJÚsortedr‘rhr¿rrrÀrr‹r‡r–r) rrƒr„ršraÚkwargsr“r™ÚfuncZ saved_posÚfilemodeÚstreamrÇr7r’r8rPsP%            z TarFile.opencKs$|dvrtdƒ‚||||fi|¤ŽS)zCOpen uncompressed tar archive name for reading or writing. r}r)rJ)rrƒr„ršr™r7r7r8r«szTarFile.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. ©rxryr`úmode must be 'r', 'w' or 'x'r)ÚGzipFilezgzip module is not availablerdNrxr·F) rJZgziprŸržrr¦rrr‡r–)rrƒr„ršÚ compresslevelr™rŸrÇr7r7r8Úgzopen³s0   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. rržr)ÚBZ2Filer‘)r rxznot a bzip2 fileF) rJrr¢ržrrr¦ÚEOFErrorr‡rr–)rrƒr„ršr r™r¢rÇr7r7r8Úbz2openÔs& 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. rržr)ÚLZMAFiler¨r“)Úpresetrxznot an lzma fileF) rJr§r¥r¨ržrrr£r‡rr–) rrƒr„ršr¦r™r¥r¨rÇr7r7r8Úxzopenðs& zTarFile.xzopenrr¡r¤r§)r”rrr’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šr^r2rÈrÍr\Ú RECORDSIZEr–r‡)r‚rbrcr7r7r8r‡s  ÿz TarFile.closecCs"| |¡}|durtd|ƒ‚|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år7r7r8Ú 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Šrˆr7r7r8Ú getmembers7szTarFile.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‘qSr7ró)r_rår7r7r8raErŽz$TarFile.getnames..)r®rˆr7r7r8ÚgetnamesAszTarFile.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ørr#rÚmajorÚminor):r¬rƒr{r%Ú splitdriver®ÚsepÚlstriprårär…ÚlstatÚstatÚfstatÚfilenoÚst_modeÚS_ISREGÚst_inoÚst_devÚst_nlinkrŒrmrñÚS_ISDIRrùÚS_ISFIFOrqÚS_ISLNKrkÚreadlinkÚS_ISCHRrÚS_ISBLKrr„Úst_uidr)Úst_gidr*Úst_sizer'Úst_mtimer(rêrëÚpwdÚgetpwuidr+rªÚgrpZgetgrgidr,r€r±Úst_rdevrìr²rí) r‚rƒÚarcnameršZdrvråZstatresrëZstmdÚinoderêr7r7r8Ú gettarinfoGs„      ÿ ÿ          zTarFile.gettarinfoT)rŠcCsú| ¡|dur|}|D]Ü}|r¤tt |j¡ƒtd|jp>|j|jpH|jfƒ|  ¡s`|  ¡rztdd|j |j fƒntd|j ƒtdt |j¡dd…ƒt|j| ¡r¶dnd ƒ|rî| ¡rØtd |jƒ| ¡rîtd |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%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dr¹rørz-> zlink to )r¬rlr·r›r„r+r)r,r*rorprìrír'r±Ú localtimer(rƒr7rlrërnrk)r‚ÚverboserŠrår7r7r8r\ªs0 ÿÿÿ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 %rztarfile: Excluded %rr{rÒ)r¬rƒr{r%r„Ú_dbgrÏrGrƒÚaddfiler7r˜ÚlistdirÚaddrÄ)r‚rƒrÍÚ recursiverÓråÚfr7r7r8r×Ês6    ,  ÿ 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)rarr#)r¬rrrSr5r6ršr^rÍr1r‰r[r'r\rÈr2rŠrÃ)r‚råršrWrarbrcr7r7r8rÕýs   zTarFile.addfileÚ.©Ú numeric_ownerc Csúg}|dur|}|D]>}| ¡r:| |¡t |¡}d|_|j||| ¡ |dq|jdd„d| ¡|D]„}tj  ||j ¡}z,|j |||d|  ||¡|  ||¡Wqptyò}z*|jdkr΂n| dd |¡WYd}~qpd}~00qpdS) 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. NéÀ©Ú set_attrsrÜcSs|jSr†ró)r~r7r7r8Ú.rŽz$TarFile.extractall..r”rÛr#ú tarfile: %s)r7rÃrr„ÚextractÚsortÚreverser{r%rÄrƒÚchownÚutimeÚchmodr rˆrÔ)r‚r%rŠrÜZ directoriesråÚdirpathrŽr7r7r8Ú extractalls.  ÿ  zTarFile.extractallrc Cs| d¡t|tƒr | |¡}n|}| ¡r>tj ||j¡|_ z"|j |tj ||j ¡||dWnªt yÈ}zP|j dkr~‚n6|jdurœ| dd|j¡n| dd|j|jf¡WYd}~nLd}~0ty }z*|j dkræ‚n| dd|¡WYd}~n d}~00dS)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. rxrÞrNr#ráztarfile: %s %r)r¬rrr«rnr{r%rÄrërðÚ_extract_memberrƒr¦rˆÚfilenamerÔÚstrerrorr )r‚Úmemberr%rßrÜrårŽr7r7r8râ>s*   þ   , zTarFile.extractcCs‚| 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. rxz'cannot extract (sym)link as file objectN)r¬rrr«rGrêrHÚ fileobjectrnrlršr‹r Ú extractfileÚ_find_link_target)r‚rírår7r7r8rïds      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)r8r®r{r´r%Údirnamer‚ÚmakedirsrnrlrÔrƒrërGÚmakefiler7ÚmakedirrrÚmakefifororpÚmakedevÚmakelinkrêrHÚ makeunknownrårçræ)r‚råÚ targetpathrßrÜZ upperdirsr7r7r8rê„s4       zTarFile._extract_membercCs(zt |d¡Wnty"Yn0dS)z,Make a directory called targetpath. rÝN)r{ÚmkdirÚFileExistsError©r‚rårùr7r7r8rôµ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âr[rr'Útruncate)r‚rårùÚsourceraÚtargetrÍr'r7r7r8ró¿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êrür7r7r8røÏs ÿzTarFile.makeunknowncCs"ttdƒrt |¡ntdƒ‚dS)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)r€r{rr rür7r7r8rõ×s  zTarFile.makefifocCs^ttdƒrttdƒstdƒ‚|j}| ¡r6|tjO}n |tjO}t ||t  |j |j ¡¡dS)zzShow listing of a tarfile)Úmetavarr"z-ez --extractú+)r#z zExtract tarfile into target dir)Únargsr$r"z-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrxrz{!r} is a tar archive.r#z{!r} is not a tar archive. r)rÑr$)r%rÚz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rr’r)r¬z.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:ryz{!r} file created.)ÚargparseÚArgumentParserÚ add_argumentZadd_mutually_exclusive_groupÚ parse_argsÚtestrrr®rkrirrÑrSÚexitr\rrâr1r{ÚcurdirZ format_helpréZcreateÚpopr%Úsplitextr×)r'rÚparserrTÚargsr_r”Ztfr-rZtar_namer^ZextZ compressionsZtar_modeZ tar_filesÚ file_namer7r7r8Úmainô s”  ÿ  ÿ þ þ ÿ   0  0    ,  ÿ   õ .r3Ú__main__)`rqÚversionÚ __author__Ú __credits__Úbuiltinsrrƒrir{rÕrZr·r±rVrÚrerÉržrËÚAttributeErrorÚNotImplementedErrorrr¦Ú NameErrorÚ__all__r2rÈr¨rrrrrrñr4rmrkrrrùrqZCONTTYPEr r r5rrrDr rrrrHrir9rerWrrHrfrƒr Úgetfilesystemencodingr9r>rNrTrXr[rlÚ Exceptionrr rrr r rrrsrtrKrurvr‹Úobjectr—rÌÚBufferedReaderràÚcompilerRrrrr3rnr7r7r7r8Úsö        üÿÿú  sh ~"W