grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a XC?h±ã @sdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZz ddlZWneyŽdZYn0z ddlZWney²dZYn0eefZzeef7ZWneyÜYn0gd¢ZdZd Zed Zd Zd Zd Zd Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3e3Z4e"e#e$e%e(e)e*e&e'e+e,e-f Z5e"e#e*e-fZ6e+e,e-fZ7dZ8hd £Z9e:e:e:e;e;e;d!œZne ?¡Z>d$d%„Z@d&d'„ZAd(d)„ZBd*e4fd+d,„ZCd-d.„ZDdedfd/d0„ZEd1d2„ZFGd3d4„d4eGƒZHGd5d6„d6eHƒZIGd7d8„d8eHƒZJGd9d:„d:eHƒZKGd;d<„d„d>eHƒZMGd?d@„d@eMƒZNGdAdB„dBeMƒZOGdCdD„dDeMƒZPGdEdF„dFeMƒZQGdGdH„dHeMƒZRGdIdJ„dJƒZSGdKdL„dLƒZTGdMdN„dNeUƒZVGdOdP„dPeUƒZWGdQdR„dRe jXƒZYGdSdT„dTeHƒZZGdUdV„dVeZƒZ[GdWdX„dXeZƒZ\GdYdZ„dZeZƒZ]Gd[d\„d\eZƒZ^Gd]d^„d^eZƒZ_Gd_d`„d`eZƒZ`eZeeIfZadudbdc„Zbddde„Zcdfdg„Zddhdi„ZeecedeedjœZfeUƒZge hdk¡ZiGdldm„dmeUƒZjGdndo„doeUƒZkdpdq„ZlekjZdrds„Zmendtk�remƒdS)vz,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-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©r8ú,/opt/alt/python39/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)r4r6r7Úpr8r8r9Ú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#érAéÚasciiÚstrictÚ0úinvalid header)Úranger2r?ÚintÚstripr0ÚInvalidHeaderError)r4ÚnÚir8r8r9Únti°s    rNrBcCsØ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. rrBr#z%0*orDrCr@rAzoverflow in number field)rIÚbytesr3rÚ bytearrayrHÚinsertr0)rLÚdigitsÚformatr4rMr8r8r9Ú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. rCZ 148B8x356BZ 148b8x356b)ÚsumÚstructZ unpack_from)ÚbufZunsigned_chksumZ signed_chksumr8r8r9Ú 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ÚdivmodrHÚreadr2Úwrite) ÚsrcZdstr5Ú exceptionÚbufsizeÚblocksÚ remainderÚbrWr8r8r9r[îs$       r[cCs8ttjddƒ}|dur(| |d¡ |¡}t|dd�dS)Nr6Úbackslashreplaceú )Úend)ÚgetattrÚsysÚstdoutr1r=Úprint)r4r6r8r8r9Ú _safe_printsrlc@seZdZdZdS)rzBase exception.N©Ú__name__Ú __module__Ú __qualname__Ú__doc__r8r8r8r9rsrc@seZdZdZdS)r z%General exception for extract errors.Nrmr8r8r8r9r sr c@seZdZdZdS)rz&Exception for unreadable tar archives.Nrmr8r8r8r9rsrc@seZdZdZdS)rz.Exception for unavailable compression methods.Nrmr8r8r8r9rsrc@seZdZdZdS)r z=Exception for unsupported operations on stream-like TarFiles.Nrmr8r8r8r9r sr c@seZdZdZdS)r z!Base exception for header errors.Nrmr8r8r8r9r sr c@seZdZdZdS)ÚEmptyHeaderErrorzException for empty headers.Nrmr8r8r8r9rr srrc@seZdZdZdS)ÚTruncatedHeaderErrorz Exception for truncated headers.Nrmr8r8r8r9rs#srsc@seZdZdZdS)ÚEOFHeaderErrorz"Exception for end of file headers.Nrmr8r8r8r9rt&srtc@seZdZdZdS)rKzException for invalid headers.Nrmr8r8r8r9rK)srKc@seZdZdZdS)ÚSubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nrmr8r8r8r9ru,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Úmoder8r8r9Ú__init__9sþý  z_LowLevelFile.__init__cCst |j¡dS©N)r{Úcloser�©r‚r8r8r9r‡Bsz_LowLevelFile.closecCst |j|¡Sr†)r{r]r�©r‚r'r8r8r9r]Esz_LowLevelFile.readcCst |j|¡dSr†)r{r^r�©r‚r4r8r8r9r^Hsz_LowLevelFile.writeN)rnrorprqr…r‡r]r^r8r8r8r9rv3s  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|ƒ}| ¡}|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'ÚpositionrhrƒrœÚ map_indexÚmaprÃ)r‚ršrÍr'Z blockinfoZlastposZrealposr8r8r9r…as(    z_FileInFile.__init__cCsdSr†r8rˆr8r8r9r¶zsz_FileInFile.flushcCsdS©NTr8rˆr8r8r9Úreadable}sz_FileInFile.readablecCsdS)NFr8rˆr8r8r9Úwritable€sz_FileInFile.writablecCs |j ¡Sr†)ršÚseekablerˆr8r8r9rÔƒsz_FileInFile.seekablecCs|jS)z*Return the current file position. )rÎrˆr8r8r9r¿†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_ENDr0)r‚rÎÚwhencer8r8r9rÀ‹s   z_FileInFile.seekc Cs |dur|j|j}nt||j|jƒ}d}|dk�r|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Ïr2ršrÀr]rr3) r‚r'rWÚdataÚstartÚstoprÍr5rdr8r8r9r]›s,     z_FileInFile.readcCs&| t|ƒ¡}||dt|ƒ…<t|ƒSr†)r]r2)r‚rdrWr8r8r9Úreadintoºsz_FileInFile.readintocCs d|_dSrÑ)rœrˆr8r8r9r‡¿sz_FileInFile.close)N)N)rnrorprqr…r¶rÒrÓrÔr¿rÕrÖrÀr]rßr‡r8r8r8r9rÌ[s  rÌcseZdZ‡fdd„Z‡ZS)Ú ExFileObjectcs&t|j|j|j|jƒ}tƒ |¡dSr†)rÌršÚ offset_datar'ÚsparseÚsuperr…)r‚ÚtarfileÚtarinforš©Ú __class__r8r9r…Ås ÿzExFileObject.__init__©rnrorpr…Ú __classcell__r8r8rær9ràÃsràc@s eZdZdS)Ú FilterErrorN)rnrorpr8r8r8r9rêÐsrêcseZdZ‡fdd„Z‡ZS)ÚAbsolutePathErrorcs ||_tƒ d|j›d�¡dS)Nzmember z has an absolute path©rårãr…rƒ©r‚rårær8r9r…ÔszAbsolutePathError.__init__rèr8r8rær9rëÓsrëcseZdZ‡fdd„Z‡ZS)ÚOutsideDestinationErrorcs.||_||_tƒ |j›d|›d�d¡dS)Nz would be extracted to ú, ú which is outside the destination©råÚ_pathrãr…rƒ©r‚rår%rær8r9r…Ùs ÿz OutsideDestinationError.__init__rèr8r8rær9rîØsrîcseZdZ‡fdd„Z‡ZS)ÚSpecialFileErrorcs||_tƒ |j›d�¡dS)Nz is a special filerìrírær8r9r…àszSpecialFileError.__init__rèr8r8rær9rôßsrôcseZdZ‡fdd„Z‡ZS)ÚAbsoluteLinkErrorcs||_tƒ |j›d�¡dS)Nz is a link to an absolute pathrìrírær8r9r…åszAbsoluteLinkError.__init__rèr8r8rær9rõäsrõcseZdZ‡fdd„Z‡ZS)ÚLinkOutsideDestinationErrorcs.||_||_tƒ |j›d|›d�d¡dS)Nz would link to rïrðrñrórær8r9r…ês ÿz$LinkOutsideDestinationError.__init__rèr8r8rær9röésröcseZdZ‡fdd„Z‡ZS)ÚLinkFallbackErrorcs2||_||_tƒ d|j›d�d|›d�¡dS)Nzlink z would be extracted as a zcopy of z, which was rejectedrñrórær8r9r…ñs  ÿzLinkFallbackError.__init__rèr8r8rær9r÷ðsr÷TcCs"i}|j}tjj|tjjd�}| dtjf¡rH|j dtj¡}|d<tj |¡r\t |ƒ‚tjjtj  ||¡tjjd�}tj  ||g¡|kr˜t ||ƒ‚|j }|du�r|d@}|rü| ¡sÄ| ¡rÞ|d@sÔ|dM}|dO}n| ¡sî| ¡rôd}nt|ƒ‚||j k�r||d<|�r|jdu�r*d|d <|jdu�r>d|d <|jdu�rRd|d <|jdu�rfd|d <| ¡�sz| ¡�rtj |j¡�r’t|ƒ‚tj |j¡}||jk�r´||d <| ¡�rÚtj  |tj |¡|j¡}ntj  ||j¡}tjj|tjjd�}tj  ||g¡|k�rt||ƒ‚|S)N)rEú/rƒiíé@i¶ÿÿÿé€r„r)r*r+r,Úlinkname)rƒr{r%ÚrealpathÚ ALLOW_MISSINGrËÚsepÚlstripÚisabsrërÄÚ commonpathrîr„ÚisregÚislnkÚisdirÚissymrôr)r*r+r,rûrõÚnormpathÚdirnamerö)ÚmemberÚ dest_pathZfor_dataÚ new_attrsrƒZ target_pathr„Z normalizedr8r8r9Ú_get_filtered_attrsüsl ÿ           þÿÿ r cCs|Sr†r8)rr r8r8r9Úfully_trusted_filter@sr cCs,t||dƒ}|r(|jfi|¤ddi¤ŽS|S)NFÚdeep©r r®©rr r r8r8r9Ú tar_filterCs rcCs,t||dƒ}|r(|jfi|¤ddi¤ŽS|S)NTr Frrr8r8r9Ú data_filterIs r)Z fully_trustedr”rÜs([0-9]{1,20}) c@sÚeZdZdZedddddddd d d d d ddddddddd�Zdidd„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Ú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ƒr„r)r*r'r(rÚREGTYPErrûr+r,rrrÍrárâr©r‚rƒr8r8r9r…‚s"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".©rƒrˆr8r8r9r%šsz TarInfo.pathcCs ||_dSr†rrr8r8r9r%ŸscCs|jS)z0In pax headers, "linkname" is called "linkpath".©rûrˆr8r8r9r&£szTarInfo.linkpathcCs ||_dSr†r)r‚rûr8r8r9r&¨scCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)rçrnrƒÚidrˆr8r8r9Ú__repr__¬szTarInfo.__repr__T) rƒr(r„rûr)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. ) ÚcopyZdeepcopyrƒr(r„rûr)r*r+r,) r‚rƒr(r„rûr)r*r+r,r rÚresultr8r8r9r®¯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(rrrûr+r,rrrrƒrø)r„rƒr)r*r'r(rrrûr+r,rrÚDIRTYPEr³)r‚r„Úinfor8r8r9Ú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. r-rƒr%rûr&)r+r+é )r,r,r8rDrE))r)rB)r*rB)r'é )r(r9FrrBr#TrŽr®)r/rr r1r0r1ÚUnicodeEncodeErrorr2Ú isinstanceÚfloatÚroundÚstrÚ_create_pax_generic_headerÚXHDTYPEr3r ) r‚r$r6rrƒZhnamer5rRZ needs_paxÚvalZ val_is_floatZval_intrWr8r8r9r*s> þ      zTarInfo.create_pax_headercCs| |td¡S)zAReturn the object as a pax global header block sequence. r/)r?ÚXGLTYPE)Úclsrr8r8r9Úcreate_pax_global_headerMsz 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)ÚsplitrHr2rÄr1Ú LENGTH_PREFIXr1r0)r‚rƒr6r7Z componentsrMr.r8r8r9r2Ss ÿ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. rrrrBrr�NzTarInfo.type must not be Nonerƒrr„r"r)r*r'r9r(s rûr-r+r8r,r.rz%dsrŽi”þÿÿz%06orDi›þÿÿ)ÚgetÚCHRTYPEÚBLKTYPErTr:rr0r/rVr°rÈrÄrXrO) r$rSr6r7Zhas_device_fieldsrrZfiletypeÚpartsrWrr8r8r9r3cs:  ñ&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\r2rÈr3)Zpayloadrbrcr8r8r9Ú_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ƒrr'r-)r1r3r2r4r3r rK)rCrƒrr6r7r$r8r8r9r5—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/rETrŽs21 hdrcharset=BINARY r&rÉrrDó ó=ó z././@PaxHeaderrƒrr'r-r®) r'r1r:r2r>rOr/r3r rK) rCrrr6ZbinaryÚkeywordr+ZrecordsÚlrLr>r$r8r8r9r?¨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…||ƒ}|jtk�r†|j  d¡�r†t|_|jtk�r6d}g}tdƒD]j} z0t|||d…ƒ} t||d|d…ƒ} Wnt�yòY�qYn0| | | f¡|d7}�q¢t|dƒ} t|dd…ƒ} || | f|_ | !¡�rN|j  "d¡|_ |�rp|jt#v�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ºr9éiâiãiï)$r2rrrÈrsÚcountr3rtrNrXrKr?rƒr„r)r*r'r(rrrûr+r,rrÚAREGTYPEr³r#ÚGNUTYPE_SPARSErHr0rÃÚboolrrÚrstripÚ GNU_TYPES)rCrWr6r7rÚobjr.r›ÚstructsrMrÍÚnumbytesÚ isextendedÚorigsizer8r8r9ÚfrombufÛsZ         zTarInfo.frombufcCs8|j t¡}| ||j|j¡}|j ¡t|_| |¡S)zOReturn the next TarInfo object from TarFile object tarfile. ) ršr]rÈrdr6r7r¿rÍÚ _proc_member)rCrärWr_r8r8r9Ú fromtarfiles zTarInfo.fromtarfilecCsT|jttfvr| |¡S|jtkr,| |¡S|jtttfvrF|  |¡S|  |¡SdS)zYChoose the right processing method depending on the type and call it. N) rr7r6Ú _proc_gnulongr[Ú _proc_sparser@rBÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r‚rär8r8r9re/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_inforr6r7)r‚rärÍr8r8r9rk<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šr]rmr'rfr rurÍrr7r?r6r7rƒr6rû)r‚rärWÚnextr8r8r9rgMs   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ér9rXiø)rršr]rÈrHrNr0rÃr\râr¿rármr'rÍ) r‚rär`rbrcrWr›rMrÍrar8r8r9rhcs(       zTarInfo._proc_sparsecCsÈ|j | |j¡¡}|jtkr&|j}n |j ¡}d}d}g}t|ƒ|k�rh||dk�rht   ||¡}spt dƒ‚zt |  d¡ƒ}Wntyœt dƒ‚Yn0|dkr®t dƒ‚||t|ƒkrÆt dƒ‚| d¡|d} || d¡d| …} |  d¡\} } } | �r| dk�s|| dk�r$t dƒ‚| || | f¡| dk�r^|du�r^| d k�rZ|j}nd }||7}q<|du�rvd }|D]X\}} } | | d d |j¡}|tv�r¶| | ||j|j¡}n| | d d |j¡}|||<�qzz| |¡}Wnt�yþtd ƒ‚Yn0d |v�r| ||¡nFd |v�r0| ||¡n.| d¡dk�r^| d¡dk�r^| |||¡|jttfv�rÄ|  ||j|j¡|j!|_!d|v�rÄ|j"}| #¡�s®|jt$v�r¾|| |j¡7}||_!|S)zVProcess an extended or global header as described in POSIX.1-2008. rNrGr#érMrÊs hdrcharsetsBINARYr/roúGNU.sparse.mapúGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrFr')%ršr]rmr'rrBrr r2Ú_header_length_prefix_reÚmatchrKrIÚgroupr0rÝrgÚ partitionrÃr6Ú_decode_pax_fieldr7ÚPAX_NAME_FIELDSrfr ruÚ_proc_gnusparse_01Ú_proc_gnusparse_00rGÚ_proc_gnusparse_10r@rirnrÍrárrl)r‚rärWrr›r6Ú raw_headersrwr5Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuerOr+rprÍr8r8r9rjs|        ÿ  ÿ ÿ     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.offsetrGsGNU.sparse.numbytesN)rÃrIr=r0rKÚlistÚziprâ)r‚rprZoffsetsraÚ_rOr+r8r8r9r}øs  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|ƒ‘qSr8)rI)Ú.0Úxr8r8r9Ú rŽz.TarInfo._proc_gnusparse_01..rsú,Nr$r#)rEr€r�râ)r‚rprrâr8r8r9r| 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. NrNr#r$) ršr]rÈrErIr2rÃr¿rár€r�râ)r‚rprräÚfieldsrârWZnumberr8r8r9r~s  zTarInfo._proc_gnusparse_10c CsÀ| ¡D]¨\}}|dkr&t|d|ƒq|dkr@t|dt|ƒƒq|dkrZt|dt|ƒƒq|tvr|tvr’zt||ƒ}Wnty�d}Yn0|dkr¤| d¡}t|||ƒq| ¡|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namer%rtr'zGNU.sparse.realsizerrøN) r'ÚsetattrrIÚ PAX_FIELDSÚPAX_NUMBER_FIELDSr0r]r r)r‚rr6r7rOr+r8r8r9rn"s"   zTarInfo._apply_pax_infocCs2z| |d¡WSty,| ||¡YS0dS)z1Decode a single field from a pax record. rEN)r=ÚUnicodeDecodeError)r‚r+r6Zfallback_encodingZfallback_errorsr8r8r9rz9s 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#)r\rÈ)r‚rYrbrcr8r8r9rmAszTarInfo._blockcCs |jtvS©z4Return True if the Tarinfo object is a regular file.)rÚ REGULAR_TYPESrˆr8r8r9rJsz TarInfo.isregcCs| ¡SrŒ)rrˆr8r8r9ÚisfileNszTarInfo.isfilecCs |jtkS)z!Return True if it is a directory.)rr#rˆr8r8r9rRsz TarInfo.isdircCs |jtkS)z%Return True if it is a symbolic link.)rÚSYMTYPErˆr8r8r9rVsz TarInfo.issymcCs |jtkS)z!Return True if it is a hard link.)rÚLNKTYPErˆr8r8r9rZsz TarInfo.islnkcCs |jtkS)z(Return True if it is a character device.)rrHrˆr8r8r9Úischr^sz TarInfo.ischrcCs |jtkS)z$Return True if it is a block device.)rrIrˆr8r8r9Úisblkbsz TarInfo.isblkcCs |jtkS)zReturn True if it is a FIFO.)rÚFIFOTYPErˆr8r8r9ÚisfifofszTarInfo.isfifocCs |jduSr†)rârˆr8r8r9ÚissparsejszTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)rrHrIr“rˆr8r8r9Úisdevmsz TarInfo.isdev)r�)4rnrorprqÚdictÚ __slots__r…Úpropertyr%Úsetterr&rrr®r%rr r,r(r)r*Ú classmethodrDr2Ú staticmethodr3rKr5r?rdrfrerkrgrhrjr}r|r~rnrzrmrrŽrrrr‘r’r”r•r–r8r8r8r9r_sœè     ý  :  )   2 >  y rc @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#Nrxr&c Csªdddddœ}||vrtdƒ‚||_|||_|sh|jdkrTtj |¡sTd|_d|_t||jƒ}d |_n@|d ur�t|d ƒr�t |j t t fƒr�|j }t|d ƒr¢|j|_d |_|r¸tj  |¡nd |_ ||_|d urÒ||_|d urà||_|d urî||_|d urü||_|d u�r ||_| |_| d u�r0|jtk�r0| |_ni|_| d u�rF| |_| d u�rV| |_| |_d |_g|_d |_|j ¡|_i|_zþ|jdk�ržd |_ | !¡|_ |jdk�r2|j "|j¡z|j #|¡}|j $|¡WnXt%�yü|j "|j¡Y�q2Yn2t&�y,}zt't |ƒƒ‚WYd }~n d }~00�qª|jdv�r|d |_|j�r||j (|j )¡¡}|j *|¡|jt+|ƒ7_Wn&|j�s˜|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„)-r0r„Ú_moder{r%ÚexistsÚ bltn_openr–r€r;rƒr>rOÚabspathršrSråÚ dereferenceÚ ignore_zerosr6r7rrÚdebugÚ errorlevelÚ copybufsizerœÚmembersÚ_loadedr¿rÍÚinodesÚ firstmemberrprÀrfrÃrtr rrDr r^r2r‡)r‚rƒr„ršrSrår§r¨r6r7rr©rªr«ZmodesÚerWr8r8r9r…ŽsŠ   ÿ          &   zTarFile.__init__c sÈ|s|stdƒ‚|dvr¬‡fdd„}tˆj|d�D]l}tˆˆj|ƒ}|durV| ¡} z||d|fi|¤ŽWSttfyœ|dur”| | ¡Yq2Yq20q2tdƒ‚�nd |v�r| d d ¡\} }| pÌd} |pÔd }|ˆjvròtˆˆj|ƒ}n td |ƒ‚||| |fi|¤ŽSd |v�rœ| d d ¡\} }| �p4d} |�p>d }| dv�rRtdƒ‚t || |||ƒ} zˆ|| | fi|¤Ž} Wn|   ¡‚Yn0d| _ | S|dv�r¼ˆ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™©rCr8r9Únot_compressed'sz$TarFile.open..not_compressed)ÚkeyNrxz%file could not be opened successfullyú:r#r”r•ú|rwzmode must be 'r' or 'w'Fr¢zundiscernible mode) r0Úsortedr³rhr¿rrrÀrEr‹r‡r–r²) rCrƒr„ršraÚkwargsrµr™ÚfuncZ saved_posÚfilemodeÚstreamrÇr8r´r9rýsP%            z TarFile.opencKs$|dvrtdƒ‚||||fi|¤ŽS)zCOpen uncompressed tar archive name for reading or writing. rŸr¡)r0)rCrƒr„ršrºr8r8r9r²XszTarFile.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) r0ZgziprÀržrr¦rr²r‡r–)rCrƒr„ršÚ compresslevelrºrÀrÇr8r8r9Ú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. r¾r¿r)ÚBZ2Filer‘)rÁrxznot a bzip2 fileF) r0r�rÃržrr²r¦ÚEOFErrorr‡rr–)rCrƒr„ršrÁrºrÃrÇr8r8r9Ú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. r¾r¿r)ÚLZMAFiler¨r“)Úpresetrxznot an lzma fileF) r0r§rÆr¨ržrr²rÄr‡rr–) rCrƒr„ršrÇrºrÆr¨rÇr8r8r9Úxzopen�s& 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šr^r3rÈrÍr\Ú RECORDSIZEr–r‡)r‚rbrcr8r8r9r‡Ä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år8r8r9Ú 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ˆr8r8r9Ú 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‘qSr8r)rƒrår8r8r9r…òrŽz$TarFile.getnames..)rÏrˆr8r8r9Ú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%|_&| tk�r–|j'|_(nd|_(|j)|_*| |_+||_,t-�râzt- .|j$¡d|_/Wnt0�yàYn0t1�rzt1 2|j&¡d|_3Wnt0�yYn0| tt!fv�rVt4tdƒ�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®rþrÿrå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_ISCHRrHÚS_ISBLKrIr„Úst_uidr)Úst_gidr*Úst_sizer'Úst_mtimer(rrûÚpwdÚgetpwuidr+rËÚgrpZgetgrgidr,r€rÒÚst_rdevrrÓr) r‚rƒÚarcnameršZdrvråZstatresrûZstmdÚinoderr8r8r9Ú gettarinfoôs„      ÿ ÿ          zTarFile.gettarinfoT)r¬cCs*| ¡|dur|}|D�] }|rÎ|jdur6tdƒntt |j¡ƒtd|jpT|j|jp^|jfƒ|  ¡sv|  ¡r�tdd|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„rlrÖr¼r+r)r,r*r‘r’rrr'r(r±Ú localtimerƒrrrûrrk)r‚Úverboser¬rår8r8r9r€Ws8    ÿÿ  ÿ  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¦Ú_dbgrîrr¥Úaddfilerr¹ÚlistdirÚaddrÄ)r‚rƒrìÚ recursiveròråÚfr8r8r9r÷}s6    ,  ÿ z TarFile.addcCs¾| d¡t |¡}| |j|j|j¡}|j |¡|jt |ƒ7_|j }|dur®t ||j|j |d�t |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Ír r,rSr6r7ršr^rÍr2r«r[r'r\rÈr3r¬rÃ)r‚råršrWrarbrcr8r8r9rõ°s   zTarFile.addfilecCsp|dur0|j}|durtSt|tƒr,tdƒ‚|St|ƒr<|Sz t|WStyjtd|›d�ƒd‚Yn0dS)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z not found) Úextraction_filterr r;r>Ú TypeErrorÚcallableÚ_NAMED_FILTERSrËr0)r‚ròr8r8r9Ú_get_filter_functionÉs ÿ  zTarFile._get_filter_functionÚ.)Ú numeric_ownerròc Csºg}| |¡}|dur|}|D]L}| |||¡\}} |dur>q| ¡rP| | ¡|j||| ¡ ||d�q|jdd„dd�|D�]0} zúz|| |ƒ}WnBtyÚ} z*| | t| ƒ¡WYd} ~ Wq‚WYd} ~ n d} ~ 00|durô| | d¡Wq‚t j   ||j ¡} zt   | ¡} Wn&t�y8| |d¡YWq‚Yn0t | j¡�sX| |d ¡Wq‚|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_attrsrÚfilter_functioncSs|jSr†r)r r8r8r9ÚþrŽz$TarFile.extractall..T)r¶Úreversezexcluded by filterZmissingznot a directory)r)rþÚ_get_extract_tarinforrÃÚ _extract_oneÚsortÚ_FILTER_ERRORSÚ_log_no_directory_fixupÚreprr{r%rÄrƒrÕÚFileNotFoundErrorrÖrÞrÙÚchownÚutimeÚchmodr Ú_handle_nonfatal_error)r‚r%r¬rròZ directoriesrrråÚ unfilteredÚexcÚdirpathrÕr°r8r8r9Ú extractallÛsV ÿ þ $ÿ    zTarFile.extractallcCs| dd|j|f¡dS)Nr$z(tarfile: Not fixing up directory %r (%s))rôrƒ)r‚rÚreasonr8r8r9r  sÿzTarFile._log_no_directory_fixupr�c Cs8| |¡}| |||¡\}}|dur4| ||||¡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þrr) r‚rr%rrròrrårr8r8r9Úextract$ s  ÿzTarFile.extractc CsÖt|tƒr| |¡}n|}d}z|||ƒ}Wn^ttfy^}z| |¡WYd}~n6d}~0tyŠ}z| |¡WYd}~n d}~00|durª| dd|j ¡dS|  ¡rÎt   |¡}t j  ||j¡|_||fS)zŠGet (filtered, unfiltered) TarInfos from *member* *member* might be a string. Return (None, None) if not found. Nr$ró)NN)r;r>rÌr¦rêÚ_handle_fatal_errorr rrôrƒrr r{r%rÄrûr)r‚rrr%rÚfilteredr°r8r8r9r8 s"    zTarFile._get_extract_tarinfoc Cs�| d¡z&|j|tj ||j¡||||d�WnZty^}z| |¡WYd}~n6d}~0tyŠ}z|  |¡WYd}~n d}~00dS)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) rx)rrrÚextraction_rootN) rÍÚ_extract_memberr{r%rÄrƒr¦rr r)r‚rår%rrrr°r8r8r9rV s ü zTarFile._extract_onecCs"|jdkr‚n| dd|¡dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#ú tarfile: %sN)rªrô©r‚r°r8r8r9rj 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#rztarfile: %s %rztarfile: %s %s)rªr;r¦ÚfilenamerôÚstrerrorrrnrr8r8r9rq 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. rxz'cannot extract (sym)link as file objectN)rÍr;r>rÌrrrlÚ fileobjectrrršr‹r Ú extractfileÚ_find_link_target)r‚rrår8r8r9r} s      zTarFile.extractfile©rrcCsZ| d¡}| dtj¡}tj |¡}|r>tj |¡s>t |¡| ¡sN|  ¡rh|  dd|j |j f¡n|  d|j ¡|  ¡rŒ| ||¡n”| ¡r¢| ||¡n~| ¡r¸| ||¡nh| ¡sÈ| ¡rÖ| ||¡nJ| ¡sæ|  ¡rú|j||||d�n&|jtv�r| ||¡n | ||¡|�rV| |||¡|  ¡�sV| ||¡| ||¡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 -> %sr!N)r]r®r{rþr%rr¤ÚmakedirsrrrôrƒrûrÚmakefilerÚmakedirr”Úmakefifor‘r’ÚmakedevÚmakelink_with_filterrrlÚ makeunknownr rr )r‚råÚ targetpathrrrrZ upperdirsr8r8r9r� s<   ý    zTarFile._extract_membercCs>z&|jdurt |¡n t |d¡Wnty8Yn0dS)z,Make a directory called targetpath. NiÀ)r„r{ÚmkdirÚFileExistsError©r‚rår)r8r8r9r$Õ 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'r8r8r9r#ã 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ôrr,r8r8r9r(ó s ÿzTarFile.makeunknowncCs"ttdƒrt |¡ntdƒ‚dS)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)r€r{r0r r,r8r8r9r%û s  zTarFile.makefifocCsjttdƒrttdƒstdƒ‚|j}|dur.d}| ¡rB|tjO}n |tjO}t ||t  |j |j ¡¡dS)zrrrsruÚ Exceptionr�r;r¢ržr¬rÃr­)r‚Úmrår°r�r8r8r9rpƒ sZ   " "       z TarFile.nextc Cs´| ¡}d}|durFz| |¡}Wnty8d}Yn0|d|…}|rVtj |¡}t|ƒD]D}|rx|j|jkr^d}q^|rŒtj |j¡}n|j}||kr^|Sq^|r°t|ƒ‚dS)z}Find an archive member by name from bottom to top. If tarinfo is given, it is used as the starting point. FNT) rÏÚindexr0r{r%rÚreversedrÍrƒ) r‚rƒråÚ normalizer¬ZskippingrBrÚ member_namer8r8r9rÊ s,       zTarFile._getmembercCs| ¡}|durqqd|_dS)zWRead through the entire archive file and look for readable members. NT)rpr­rír8r8r9rÎê sz TarFile._loadcCs:|jrtd|jjƒ‚|dur6|j|vr6td|jƒ‚dS)znCheck if TarFile is still open, and if the operation's mode corresponds to TarFile's mode. z %s is closedNzbad operation for mode %r)rœr¦rçrnr„)r‚r„r8r8r9rÍô szTarFile._checkcCs`| ¡r.d tdtj |j¡|jfƒ¡}d}n |j}|}|j||dd�}|dur\t d|ƒ‚|S)zZFind the target member of a symlink or hardlink member in the archive. røNT)rårDzlinkname %r not found) rrÄròr{r%rrƒrûrÊrË)r‚rårûÚlimitrr8r8r9r ý s  zTarFile._find_link_targetccsŠ|jr|jEdHdSd}|jdur:| ¡}|d7}|V|t|jƒkrT|j|}n"|jsr| ¡}|svd|_dSndS|d7}|Vq:dS)z$Provide an iterator object. Nrr#T)r­r¬r¯rpr2)r‚rBrår8r8r9Ú__iter__ s$   zTarFile.__iter__cCs||jkrt|tjd�dS)z.Write debugging output to sys.stderr. ©ÚfileN)r©rkriÚstderr)r‚ÚlevelÚmsgr8r8r9rô/ s z TarFile._dbgcCs | ¡|Sr†)rÍrˆr8r8r9Ú __enter__5 szTarFile.__enter__cCs,|dur| ¡n|js"|j ¡d|_dSrÑ)r‡r–ršrœ)r‚rr+Ú tracebackr8r8r9Ú__exit__9 s   zTarFile.__exit__) NrxNNNNNNr&NNNN)rxN)rxNrª)rxNrª)rxNN)NNN)T)NT)N)rÿN)r�T)N)TF)NF)N)@rnrorprqr©r§r¨rªrrSr r6r7rråràrrúr…r›rÉrr²rÂrÅrÈr³r‡rÌrÏrÐrîr€r÷rõrþrr rrrrrrrr$r#r(r%r&r4r'r rr rprÊrÎrÍr rGrôrMrOr8r8r8r9rrsœý oZ    ü    c&3 ÿ Eÿ ÿ   ÿþ 82! ? ( 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. r])ršTFN)r€rr‡r)rƒrÇr8r8r9rG s   rc Cs`ddl}d}|j|d�}|jdddddd �|jd d td d �|jdd�}|jddddd�|jdddddd�|jdddddd�|jdd dd!d�| ¡}|jrº|jdurº| d"d#¡|j du�rJ|j }t |ƒ�r4t |d$ƒ�*}|  ¡t |  ¡tjd%�Wdƒn1�s0Y|j�rFt d& |¡ƒn| d"d' |¡¡�n|jdu�rº|j}t |ƒ�r¤t  |d(¡�}|j|jd)�Wdƒn1�s˜0Yn| d"d' |¡¡�n¢|jdu�r¤t|jƒd"k�rè|jd}tj}n,t|jƒd*k�r|j\}}n| d"| ¡¡t |ƒ�r�t  |d(¡� }|j||jd+�Wdƒn1�sR0Y|j�r¢|d,k�rzd- |¡} n d. ||¡} t | ƒn| d"d' |¡¡n¸|jdu�r\|j d¡} tj | ¡\} } d/d/d0d0d1d1d1d1d2œ} | | v�rød3| | nd4}|j}t  | |¡�&}|D]}| |¡�qWdƒn1�s<0Y|j�r\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ÚchoicesrTT)Zrequiredz-lz--listú zShow listing of a tarfile)rUrTz-ez --extractú+)rWz zExtract tarfile into target dir)ÚnargsrUrTz-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction rxrHz{!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:ryz{!r} file created.)ÚargparseÚArgumentParserÚ add_argumentrýZadd_mutually_exclusive_groupÚ parse_argsròrÚexitÚtestrrrÏrkrirJrðrSr€rr2r{ÚcurdirZ format_helprZcreateÚpopr%Úsplitextr÷)rZrPÚparserrxÚargsr_r”Ztfr`rLZtar_namer‚ZextZ compressionsZtar_modeZ tar_filesÚ file_namer8r8r9ÚmainZ s   ÿþ  ÿ þ þ ÿ    2  0    0  ÿ   õ .rfÚ__main__)T)orqÚversionÚ __author__Ú __credits__Úbuiltinsrr¥rir{rÕrZrÖr±rVr ÚreÚwarningsrèržrêÚAttributeErrorÚNotImplementedErrorr9r¦Ú NameErrorÚ__all__r3rÈrÉr4r/r1r0rFrrZr�r�rHrIr#r“ZCONTTYPEr7r6r[r@rBrir rrrrlr�r^r‰r{r<rIrŠrƒr Úgetfilesystemencodingr:r?rNrTrXr[rlr@rr rrr r rrrsrtrKrurvr‹Úobjectr—rÌÚBufferedReaderràrêrërîrôrõrör÷rr r rrrýrÚcompilervrrrrfrnr8r8r8r9Ús         üÿÿú  sh   Dý  ^_