grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j‰ºã @sdZdZdZdZddlmZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZzddlZWn eyGdZYnwzddlZWn eyYdZYnweefZzeef7ZWn eynYnwgd¢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ƒdSdS)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/python310/lib64/python3.10/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 |ddvr2d}tt|ƒdƒD]}|dK}|||d7}q|ddkr0dt|ƒd| }|Szt|ddƒ}t| ¡p?d dƒ}W|StyOtd ƒ‚w) 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|krd|dkr%nntd|d|fdƒt}|S|tkrmd|d |kr|j  d||df¡|j  d||||f¡||7}||}q,||jkre|j  d||jdf¡dSdS)Nrr†FT) rŸÚoffsetr'Úpositionrhr†r¡Ú map_indexÚmaprË)r…rŸrÕr'Z blockinfoZlastposZrealposr8r8r9rˆds*    ÿz_FileInFile.__init__cCsdSr‰r8r‹r8r8r9r»}óz_FileInFile.flushcCódS©NTr8r‹r8r8r9Úreadable€rÙz_FileInFile.readablecCrÚ©NFr8r‹r8r8r9ÚwritableƒrÙz_FileInFile.writablecCs |j ¡Sr‰)rŸÚseekabler‹r8r8r9r߆ó z_FileInFile.seekablecCrÄ)z*Return the current file position. )rÖr‹r8r8r9rʼnrÆz_FileInFile.tellcCsš|tjkrtt|dƒ|jƒ|_|jS|tjkr4|dkr't|j|dƒ|_|jSt|j||jƒ|_|jS|tjkrItt|j||jƒdƒ|_|jStdƒ‚)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}n t||j|jƒ}d}|dkr… |j|j\}}}}||jkr0|kr3nnn|jd7_|jt|jƒkrEd|_qt|||jƒ}|rp|j ||j|¡|j |¡}t|ƒ|krkt dƒ‚||7}n|t |7}||8}|j|7_|dks|S)z!Read data from the file. Nr“rTr#rY) r'rÖrãrØr×r2rŸrÈr]rr3) r…r'rWrÇÚstartÚstoprÕr5rdr8r8r9r]žs2ù    íz_FileInFile.readcCs&| t|ƒ¡}||dt|ƒ…<t|ƒSr‰)r]r2)r…rdrWr8r8r9Úreadinto½sz_FileInFile.readintocCs d|_dSrÛ)r¡r‹r8r8r9rŠÂràz_FileInFile.closer‰)rorprqrrrˆr»rÜrÞrßrÅrárârÈr]rêrŠr8r8r8r9rÔ^s   rÔcóeZdZ‡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__©rorprqrˆÚ __classcell__r8r8ròr9rìÆsrìc@s eZdZdS)Ú FilterErrorN)rorprqr8r8r8r9röÓsröcrë)Ú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÷Öór÷crë)ÚOutsideDestinationErrorcó.||_||_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ˆÜó  ÿz OutsideDestinationError.__init__rôr8r8ròr9rûÛrúrûcrë)ÚSpecialFileErrorcó||_tƒ |j›d�¡dS)Nz is a special filerørùròr8r9rˆãózSpecialFileError.__init__rôr8r8ròr9rârúrcrë)ÚAbsoluteLinkErrorcr)Nz is a link to an absolute pathrørùròr8r9rˆèrzAbsoluteLinkError.__init__rôr8r8ròr9rçrúrcrë)ÚLinkOutsideDestinationErrorcrü)Nz would link to rýrþrÿrròr8r9rˆírz$LinkOutsideDestinationError.__init__rôr8r8ròr9rìrúrcrë)ÚLinkFallbackErrorcs2||_||_tƒ d|j›d�d|›d�¡dS)Nzlink z would be extracted as a zcopy of z, which was rejectedrÿrròr8r9rˆôs   ÿzLinkFallbackError.__init__rôr8r8ròr9rórúrTc Cs,i}|j}tjj|tjjd�}| dtjf¡r$|j dtj¡}|d<tj |¡r.t |ƒ‚tjjtj  ||¡tjjd�}tj  ||g¡|krLt ||ƒ‚|j }|dur†|d@}|r}| ¡sa| ¡rn|d@si|dM}|dO}n| ¡sv| ¡ryd}nt|ƒ‚||j kr†||d<|�r|jdur’d|d <|jdur›d|d <|jdur¤d|d <|jdur­d|d <| ¡s¶| ¡�rtj |j¡rÁt|ƒ‚||krÊt ||ƒ‚tj |j¡}||jkrÚ||d <| ¡rótj | dtj¡¡}tj  |||¡}ntj  ||¡}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Úissymrr)r*r+r,r rÚnormpathÚdirnameÚrstripr) ÚmemberÚ dest_pathZfor_dataÚ new_attrsr†Z target_pathr‡Z normalizedZlink_dirr8r8r9Ú_get_filtered_attrsÿsh ÿ         ÿ rcCs|Sr‰r8)rrr8r8r9Úfully_trusted_filterIrÙrcCs,t||dƒ}|r|jdi|¤ddi¤ŽS|S)NFÚdeepr8©rr³©rrrr8r8r9Ú tar_filterLó r"cCs,t||dƒ}|r|jdi|¤ddi¤ŽS|S)NTrFr8r r!r8r8r9Ú data_filterRr#r$)Z fully_trustedr™rÇs([0-9]{1,20}) c @sPeZdZdZed�idd“dd“dd“dd “d d “d d “dd“dd“dd“dd“dd“dd“dd“dd“dd“d d!“d"d#“d$d%“d&d%“d'd%“ŽZd‚d)d*„Zed+d,„ƒZej d-d,„ƒZed.d/„ƒZ e j d0d/„ƒZ d1d2„Z e e e e e e e e d3e d4œ d5d6„Z d7d8„Zeed9fd:d;„Zdd?„Zd@dA„ZedBdC„ƒZdDdE„ZedFdG„ƒZedHdI„ƒZedJdK„ƒZedLdM„ƒZedNdO„ƒZed3dPœdQdR„ƒZedSdT„ƒZed3dPœdUdV„ƒZ dWdX„Z!dYdZ„Z"d[d\„Z#d]d^„Z$d_d`„Z%dadb„Z&dcdd„Z'dedf„Z(dgdh„Z)didj„Z*dkdl„Z+dmdn„Z,dodp„Z-dqdr„Z.dsdt„Z/dudv„Z0dwdx„Z1dydz„Z2d{d|„Z3d}d~„Z4dd€„Z5d%S)ƒraInformational class which holds the details about an archive member given by a tar header block. TarInfo objects are returned by TarFile.getmember(), TarFile.getmembers() and TarFile.gettarinfo() and are usually created internally. r†zName of the archive member.r‡zPermission bits.r)z6User ID of the user who originally stored this member.r*z7Group ID of the user who originally stored this member.r'zSize in bytes.r(zTime of last modification.ÚchksumzHeader checksum.Útypez–File type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.r zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.r+z User name.r,z Group name.ÚdevmajorzDevice major number.ÚdevminorzDevice minor number.rÕzThe tar header starts here.rízThe file's data starts here.Ú pax_headerszMA dictionary containing key-value pairs of an associated pax extended header.rîzSparse member information.rðNÚ_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&r r+r,r'r(rÕrírîr)©r…r†r8r8r9rˆ‹s" zTarInfo.__init__cCrÄ)z(In pax headers, "name" is called "path".©r†r‹r8r8r9r%£rÆz TarInfo.pathcCó ||_dSr‰r.r-r8r8r9r%¨ó cCrÄ)z0In pax headers, "linkname" is called "linkpath".©r r‹r8r8r9r&¬rÆzTarInfo.linkpathcCr/r‰r1)r…r r8r8r9r&±r0cCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)róror†Úidr‹r8r8r9Ú__repr__µszTarInfo.__repr__T) r†r(r‡r r)r*r+r,rÚ_KEEPc CsŽ| rt |¡} nt |¡} || ur|| _|| ur|| _|| ur"|| _|| ur)|| _|| ur0|| _|| ur7|| _|| ur>|| _|| urE|| _ | 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,rr4Ú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(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…r‡Úinfor8r8r9Úget_infoÔs(  ózTarInfo.get_infoÚsurrogateescapecCsv| ¡}| ¡D]\}}|durtd|ƒ‚q|tkr"| |||¡S|tkr-| |||¡S|tkr7| ||¡Stdƒ‚)zszTarInfo.create_gnu_headerc CsDt|d<|j ¡}ddtfddtfddfD]2\}}}||vrqz || dd ¡Wnty8||||<Yqwt||ƒ|krG||||<qd D]A\}}d }||} t| t ƒ} | r_t | ƒn| } d | krod |dkswnd ||<d}n| r| ||<d}|r‹||vr‹t | ƒ||<qJ|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. rBr†r%r r&)r+r+é )r,r,rMrDrE))r)rB)r*rB)r'é )r(rNFrrBr#Tr“r³)rDr)r5rFrEr1ÚUnicodeEncodeErrorr2Ú isinstanceÚfloatÚroundÚstrÚ_create_pax_generic_headerÚXHDTYPErHr ) r…r9r6r)r†Zhnamer5rRZ needs_paxÚvalZ val_is_floatZval_intrWr8r8r9r?sD þ  þ €    €zTarInfo.create_pax_headercCs| |td¡S)zAReturn the object as a pax global header block sequence. r/)rTÚXGLTYPE)Úclsr)r8r8r9Úcreate_pax_global_headerVsz TarInfo.create_pax_global_headercCs|| d¡}tdt|ƒƒD]-}d |d|…¡}d ||d…¡}t| ||¡ƒtkr9t| ||¡ƒtkr9||fSq tdƒ‚)zUSplit a name longer than 100 chars into a prefix and a name part. r r#Nzname is too long)ÚsplitrHr2rÌr1Ú LENGTH_PREFIXrFr0)r…r†r6r7Z componentsrMrCr8r8r9rG\s €þzTarInfo._posix_split_namec Cs¦| d¡ttfv}|r t| dd¡d|ƒ}t| dd¡d|ƒ}ntdd||ƒ}tdd||ƒ}| dt¡}|durr9r8r8r9rT±sB þ  ü( ÿ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)rXrWr6r7r8r8r9ÚfrombufäszTarInfo.frombuf©Údircheckc Csjt|ƒdkr tdƒ‚t|ƒtkrtdƒ‚| t¡tkrtdƒ‚t|dd…ƒ}|t|ƒvr1t 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|_|jtk�rd}g} tdƒD]0} zt|||d…ƒ} t||d|d…ƒ} Wn tyõYn w|  | | f¡|d7}qÑt|dƒ} t|dd…ƒ}| | |f|_ | !¡�r"|j  "d¡|_ |�r3|jt#v�r3|d|j |_ |S)a\Construct a TarInfo object from a 512 byte bytes object. If ``dircheck`` is set to ``True`` then ``AREGTYPE`` headers will be normalized to ``DIRTYPE`` if the name ends in a trailing slash. ``dircheck`` must be set to ``False`` if this function is called on a follow-up header such as ``GNUTYPE_LONGNAME``. rz empty headerztruncated headerzend of file headeré”éœz bad checksumrélété|éˆé�ii i)iIiQiYiôr i‚r¿rNéiâiãiï)$r2rtrÐruÚcountr3rvrNrXrKr?r†r‡r)r*r'r(r%r&r r+r,r'r(ÚAREGTYPEr¸r8ÚGNUTYPE_SPARSErHr0rËÚboolr*rrÚ GNU_TYPES)rXrWr6r7rir%ÚobjrCr ÚstructsrMrÕÚnumbytesÚ isextendedÚorigsizer8r8r9rfís\      ÿ    zTarInfo._frombufcCs | |¡S)zOReturn the next TarInfo object from TarFile object tarfile. )Ú _fromtarfile)rXrðr8r8r9Ú fromtarfile1s zTarInfo.fromtarfilecCs<|j t¡}|j||j|j|d�}|j ¡t|_| |¡S)z; See dircheck documentation in _frombuf(). rh) rŸr]rÐrfr6r7rÅrÕÚ _proc_member)rXrðrirWrwr8r8r9r|8s  zTarInfo._fromtarfilecCsP|jttfvr | |¡S|jtkr| |¡S|jtttfvr#|  |¡S|  |¡S)zYChoose the right processing method depending on the type and call it. ) r&rLrKÚ _proc_gnulongrtÚ _proc_sparserUrWÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)r…rðr8r8r9r~Ms     zTarInfo._proc_membercCsh|j ¡|_|j}| ¡s|jtvr|| |j¡7}||_|  |j |j |j ¡|  ¡r2|j d¡|_|S)zfProcess a builtin type or an unknown type which will be treated as a regular file. r )rŸrÅrírr&ÚSUPPORTED_TYPESÚ_blockr'rÕÚ_apply_pax_infor)r6r7rr†r)r…rðrÕr8r8r9rƒZs zTarInfo._proc_builtinc Csª|j | |j¡¡}z |j|dd�}Wnty&}ztt|ƒƒd‚d}~ww|j|_|j t kr:t ||j |j ƒ|_n|j tkrHt ||j |j ƒ|_| ¡rS|j d¡|_|S)zSProcess the blocks that hold a GNU longname or longlink member. FrhNr )rŸr]r…r'r|r rwrSrÕr&rLr?r6r7r†rKr rÚ removesuffix)r…rðrWÚnextrÏr8r8r9rps€ÿ  zTarInfo._proc_gnulongc CsÖ|j\}}}|`|rS|j t¡}d}tdƒD]4}zt|||d…ƒ}t||d|d…ƒ} Wn ty:Ynw|rF| rF| || f¡|d7}qt|dƒ}|s ||_ |j  ¡|_ |j |  |j ¡|_||_ |S)z8Process a GNU sparse header plus extra headers. rérNrqiø)r*rŸr]rÐrHrNr0rËrurîrÅrír…r'rÕ) r…rðrxrzr{rWr rMrÕryr8r8r9r€‹s,    ÿ  ô zTarInfo._proc_sparsec CsÔ|j | |j¡¡}|jtkr|j}n|j ¡}d}d}g}t|ƒ|krµ||dkrµt   ||¡}s6t dƒ‚z t |  d¡ƒ}Wn tyJt dƒ‚w|dkrSt dƒ‚||t|ƒkr_t dƒ‚| d¡|d} || d¡d| …} |  d¡\} } } | r‡| dks‡|| dkr‹t dƒ‚| || | f¡| dkr¥|dur¥| d kr£|j}nd }||7}t|ƒ|krµ||dks*|dur»d }|D]*\}} } | | d d |j¡}|tvrÚ| | ||j|j¡}n | | d d |j¡}|||<q½z |j|d d �}Wnt�y}ztt|ƒƒd‚d}~wwd |v�r| ||¡n#d|v�r| ||¡n| d¡dk�r5| d¡dk�r5| |||¡|jtt fv�rh| !||j|j¡|j"|_"d|v�rh|j#}| $¡�s]|jt%v�re|| |j¡7}||_"|S)zVProcess an extended or global header as described in POSIX.1-2008. rNrGr#érbrÒs hdrcharsetsBINARYr/FrhúGNU.sparse.mapúGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrFr')&rŸr]r…r'r&rWr)r5r2Ú_header_length_prefix_reÚmatchrKrIÚgroupr0rèrgÚ partitionrËr6Ú_decode_pax_fieldr7ÚPAX_NAME_FIELDSr|r rwrSÚ_proc_gnusparse_01Ú_proc_gnusparse_00r\Ú_proc_gnusparse_10rUr�r†rÕrírr„)r…rðrWr)r r6Ú raw_headersr�r5Zheader_value_end_offsetZkeyword_and_valueZ raw_keywordZequalsZ raw_valuerdr@rˆrÏrÕr8r8r9r‚§s„   ÿ Ú) ÿ ÿ ÿ €ÿ    zTarInfo._proc_paxc Cs˜g}g}|D];\}}}|dkr&z | t| ¡ƒ¡Wqty%tdƒ‚w|dkrAz | t| ¡ƒ¡Wqty@tdƒ‚wqtt||ƒƒ|_dS)z?Process a GNU tar extended sparse header, version 0.0. sGNU.sparse.offsetrGsGNU.sparse.numbytesN)rËrIr=r0rKÚlistÚziprî)r…rˆr—ZoffsetsryÚ_rdr@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Ú 7sz.TarInfo._proc_gnusparse_01..r‹ú,Nr$r#)rZr˜r™rî)r…rˆr)rîr8r8r9r”4s(zTarInfo._proc_gnusparse_01cCs¶d}g}|j t¡}| dd¡\}}t|ƒ}t|ƒ|dkrAd|vr*||j t¡7}| dd¡\}}| t|ƒ¡t|ƒ|dks|j ¡|_t t |ddd…|ddd…ƒƒ|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nrcr#r$) rŸr]rÐrZrIr2rËrÅrír˜r™rî)r…rˆr)rðZfieldsrîrWZnumberr8r8r9r–:s ü (zTarInfo._proc_gnusparse_10c CsÀ| ¡D]T\}}|dkrt|d|ƒq|dkr t|dt|ƒƒq|dkr-t|dt|ƒƒq|tvrX|tvrIzt||ƒ}Wn tyHd}Ynw|dkrR| 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<ÚsetattrrIÚ PAX_FIELDSÚPAX_NUMBER_FIELDSr0rr5r))r…r)r6r7rdr@r8r8r9r†Js& ÿ  €zTarInfo._apply_pax_infocCs.z| |d¡WSty| ||¡YSw)z1Decode a single field from a pax record. rE)r=ÚUnicodeDecodeError)r…r@r6Zfallback_encodingZfallback_errorsr8r8r9r’as  ÿ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…rrrbrcr8r8r9r…is zTarInfo._blockcCs |jtvS©z4Return True if the Tarinfo object is a regular file.)r&Ú REGULAR_TYPESr‹r8r8r9rur0z TarInfo.isregcCs| ¡Sr£)rr‹r8r8r9ÚisfileyszTarInfo.isfilecCó |jtkS)z!Return True if it is a directory.)r&r8r‹r8r8r9r}r0z TarInfo.isdircCr¦)z%Return True if it is a symbolic link.)r&ÚSYMTYPEr‹r8r8r9r�r0z TarInfo.issymcCr¦)z!Return True if it is a hard link.)r&ÚLNKTYPEr‹r8r8r9r…r0z TarInfo.islnkcCr¦)z(Return True if it is a character device.)r&r]r‹r8r8r9Úischr‰r0z TarInfo.ischrcCr¦)z$Return True if it is a block device.)r&r^r‹r8r8r9Úisblk�r0z TarInfo.isblkcCr¦)zReturn True if it is a FIFO.)r&ÚFIFOTYPEr‹r8r8r9Úisfifo‘r0zTarInfo.isfifocCs |jduSr‰)rîr‹r8r8r9Úissparse•ràzTarInfo.issparsecCs|jtttfvS)zCReturn True if it is one of character device, block device or FIFO.)r&r]r^r«r‹r8r8r9Úisdev˜sz TarInfo.isdevr8)r’)6rorprqrrÚdictÚ __slots__rˆÚpropertyr%Úsetterr&r3r4r³r:rr rAr=r>r?Ú classmethodrYrGÚ staticmethodrHr`rJrTrgrfr}r|r~rƒrr€r‚r•r”r–r†r’r…rr¥rrrr©rªr¬r­r®r8r8r8r9rhsÌÿþýüûúùø õ óòñðïîíëêéè      ý :  )   2 C  y  rc@s eZdZdZdZdZdZdZeZ e Z dZ e ZeZdZ    dkdd „Zedddefd d „ƒZedld d „ƒZedmdd„ƒZedmdd„ƒZedndd„ƒZdddddœZdd„Zdd„Zdd„Zd d!„Zdod"d#„Zdpdd%œd&d'„Z dqdd(œd)d*„Z!drd+d,„Z"d-d.„Z#dsddd0œd1d2„Z$d3d4„Z%dtddd0œd6d7„Z&d8d9„Z' drd:d;„Z(dd?„Z*d@dA„Z+ $ dudddBœdCdD„Z,dEdF„Z-dGdH„Z.dIdJ„Z/dKdL„Z0dMdN„Z1dOdP„Z2dQdR„Z3dSdT„Z4dUdV„Z5dWdX„Z6dYdZ„Z7dvd[d\„Z8d]d^„Z9drd_d`„Z:dadb„Z;dcdd„Zdidj„Z?dS)wrz=The TarFile Class provides an interface to tar archives. rFr#Nr{r;c Cs�dddddœ}||vrtdƒ‚||_|||_|s4|jdkr*tj |¡s*d|_d|_t||jƒ}d |_n |d urHt|d ƒrHt |j t t fƒrH|j }t|d ƒrQ|j|_d |_|r\tj  |¡nd |_ ||_|d uri||_|d urp||_|d urw||_|d ur~||_|d ur…||_| |_| d ur•|jtkr•| |_ni|_| d urŸ| |_| d ur¦| |_| |_d |_g|_d |_|j ¡|_i|_z||jdkrÉd |_ | !¡|_ |jdk�r |j "|j¡z|j #|¡}|j $|¡Wn#t%yõ|j "|j¡Ynt&�y}zt't |ƒƒd ‚d }~wwqÐ|jdv�r2d |_|j�r5|j (|j )¡¡}|j *|¡|jt+|ƒ7_Wd SWd SWd S|j�sD|j ,¡d |_‚)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©r{Úar|rœú!mode must be 'r', 'a', 'w' or 'x'r¸r|FNr†r‡Tr{©r¸r|rœ)-r0r‡Ú_moder~r%ÚexistsÚ bltn_openr›rƒrPr†rSrOÚabspathrŸrSrñÚ dereferenceÚ ignore_zerosr6r7rr)ÚdebugÚ errorlevelÚ copybufsizer¡ÚmembersÚ_loadedrÅrÕÚinodesÚ firstmemberrˆrÈr}rËrvr rrYr5r^r2rŠ)r…r†r‡rŸrSrñr¿rÀr6r7r)rÁrÂrÃZmodesrÏrWr8r8r9rˆ¹s–   ÿ       €ÿø  ú zTarFile.__init__c sä|s|stdƒ‚|dvro‡fdd„}g}tˆj|d�D]G}tˆˆj|ƒ} |dur-| ¡} z | |d|fi|¤ŽWSttfyb} z| d|›d | ›�¡|durX| | ¡WYd} ~ qd} ~ wwd   |¡} td | ›�ƒ‚d |vr¡|  d d ¡\} }| p~d} |p‚d}|ˆjvr‘tˆˆj|ƒ} ntd|ƒ‚| || |fi|¤ŽSd|vrß|  dd ¡\} }| p°d} |p´d}| dvr½tdƒ‚t || |||ƒ}z ˆ|| |fi|¤Ž}Wn|  ¡‚d|_ |S|dvrîˆj|||fi|¤ŽStdƒ‚)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ž©rXr8r9Únot_compressedRrŽz$TarFile.open..not_compressed)ÚkeyNr{z - method z: Ú z'file could not be opened successfully: ú:r#r™ršú|rzzmode must be 'r' or 'w'Frºzundiscernible mode)r0ÚsortedrÊrhrÅrrrËrÈrÌrZr�rŠr›rÉ)rXr†r‡rŸraÚkwargsrÌZ error_msgsržÚfuncZ saved_posrÏZerror_msgs_summaryÚfilemodeÚstreamrÎr8rËr9r(sZ%   €ü   z TarFile.opencKs$|dvrtdƒ‚||||fi|¤ŽS)zCOpen uncompressed tar archive name for reading or writing. r·r¹)r0)rXr†r‡rŸrÒr8r8r9rɆszTarFile.taropenr¯c Ksî|dvrtdƒ‚zddlm}Wn tytdƒd‚wz |||d||ƒ}WntyB}z|dur=|dkr=td ƒ|‚‚d}~wwz |j|||fi|¤Ž}Wn!tyj}z| ¡|dkretd ƒ|‚‚d}~w| ¡‚d |_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. ©r{r|rœúmode must be 'r', 'w' or 'x'r)ÚGzipFilezgzip module is not availableNrdr{r¼F) r0ZgziprØr£rr«rrÉrŠr›) rXr†r‡rŸÚ compresslevelrÒrØrÏrÎr8r8r9ÚgzopenŽs8  ÿ €ý €zTarFile.gzopenc Ks¸|dvrtdƒ‚zddlm}Wn tytdƒd‚w||p!|||d�}z |j|||fi|¤Ž}Wn#ttfyO}z| ¡|dkrJt d ƒ|‚‚d}~w| ¡‚d |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rÖr×r)ÚBZ2Filer–N)rÙr{znot a bzip2 fileF) r0r•rÛr£rrÉr«ÚEOFErrorrŠrr›) rXr†r‡rŸrÙrÒrÛrÎrÏr8r8r9Úbz2open¯s*  ÿ €zTarFile.bz2openc Ks¼|dvrtdƒ‚z ddlm}m}Wn tytdƒd‚w||p#|||d�}z |j|||fi|¤Ž}Wn#|tfyQ} z| ¡|dkrLt d ƒ| ‚‚d} ~ w| ¡‚d |_ |S) zkOpen lzma compressed tar archive name for reading or writing. Appending is not allowed. rÖr×r)ÚLZMAFiler­r˜N)Úpresetr{znot an lzma fileF) r0r¬rÞr­r£rrÉrÜrŠrr›) rXr†r‡rŸrßrÒrÞr­rÎrÏr8r8r9ÚxzopenËs*  ÿ €zTarFile.xzopenrÉrÚrÝrà)r™r”r•r—cCsœ|jrdSd|_z;|jdvr7|j ttd¡|jtd7_t|jtƒ\}}|dkr7|j tt|¡W|j sB|j  ¡dSdS|j sM|j  ¡ww)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¡¡}|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. r Nzfilename %r not found)Ú _getmemberrÚKeyError)r…r†rñr8r8r9Ú getmembers 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Ú getmembersszTarFile.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� sz$TarFile.getnames..)rçr‹r8r8r9ÚgetnamesszTarFile.getnamesc CsJ| d¡|dur |j}|dur|}tj |¡\}}| tjd¡}| d¡}| ¡}||_ |dur@|j s:t  |¡}n t  |¡}nt  | ¡¡}d}|j}t  |¡r|j|jf} |j ss|jdkrs| |jvrs||j| krst} |j| }n;t} | dr~||j| <n/t  |¡r‡t} n't  |¡r�t} nt  |¡rœt} t |¡}nt  |¡r¤t} n t   |¡r¬t!} ndS||_||_"|j#|_$|j%|_&| tkrÅ|j'|_(nd|_(|j)|_*| |_+||_,t-réz t- .|j$¡d|_/Wn t0yèYnwt1�rz t1 2|j&¡d|_3Wn t0�yYnw| tt!fv�r#t4tdƒ�r#t4tdƒ�r#t 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_ISDIRr8ÚS_ISFIFOr«ÚS_ISLNKr§ÚreadlinkÚS_ISCHRr]ÚS_ISBLKr^r‡Ú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&r8r8r9Ú gettarinfo"s„        €        ÿÿzTarFile.gettarinfoT)rÄcCs"| ¡|dur |}|D]‚}|rf|jdurtdƒntt |j¡ƒtd|jp)|j|jp.|jfƒ|  ¡s:|  ¡rGtdd|j |j fƒntd|j ƒ|jdurXtdƒntdt |j¡dd …ƒt|j| ¡rod nd ƒ|r‹| ¡r€td |jƒ| ¡r‹td |jƒtƒq dS)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ªr'r(r'r(r¶Ú localtimer†rrr rrk)r…ÚverboserÄrñr8r8r9r˜…s:   ÿÿ  ÿæz TarFile.list©ÚfiltercCsP| d¡|dur |}|jdur#tj |¡|jkr#| dd|¡dS| d|¡| ||¡}|dur=| dd|¡dS|durS||ƒ}|durS| dd|¡dS| ¡rut|dƒ�}|  ||¡WdƒdS1snwYdS|  ¡r¡|  |¡|r�t t  |¡ƒD]}|j tj ||¡tj ||¡||d �q‡dSdS|  |¡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ñÚfr8r8r9r«s<    "ÿ ÿþz TarFile.addcCs¾| d¡t |¡}| |j|j|j¡}|j |¡|jt |ƒ7_|j }|durWt ||j|j |d�t |j tƒ\}}|dkrN|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år5rArSr6r7rŸr^rÕr2rÃr[r'r\rÐr3rÄrË)r…rñrŸrWrarbrcr8r8r9r Þs   zTarFile.addfilecCsh|dur|j}|dur tSt|tƒrtdƒ‚|St|ƒr|Szt|WSty3td|›d�ƒd‚w)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z not found) Úextraction_filterrrPrSÚ TypeErrorÚcallableÚ_NAMED_FILTERSrãr0)r…r r8r8r9Ú_get_filter_function÷s  ÿ  ÿzTarFile._get_filter_functionÚ.)Ú numeric_ownerr c Cs g}| |¡}|dur |}|D]&}| |||¡\}} |durq| ¡r(| | ¡|j||| ¡ ||d�q|jdd„dd�|D]Œ} zsz|| |ƒ}Wntyf} z| | t| ƒ¡WYd} ~ WqAd} ~ ww|durs| | d¡WqAt j   ||j ¡} zt   | ¡} Wnty’| |d¡YWqAwt | j¡s¡| |d ¡WqA|j|| |d �| || ¡| || ¡WqAtyÍ} z | | ¡WYd} ~ qAd} ~ wwdS) 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_functioncSrÄr‰r.)r¸r8r8r9Ú, sz$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 sb ÿ þ€þÿ  þ   €ÿåzTarFile.extractallcCs| dd|j|f¡dS)Nr$z(tarfile: Not fixing up directory %r (%s))r r†)r…rÚreasonr8r8r9r!N s ÿzTarFile._log_no_directory_fixupr’c Cs@| |¡}| |||¡\}}|dur|j|||||d�dSdS)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)rrr) r…rr%rrr rrñr(r8r8r9ÚextractR s ÿ  ÿÿzTarFile.extractc CsÖt|tƒr | |¡}n|}d}z|||ƒ}Wn/ttfy/}z | |¡WYd}~nd}~wtyE}z | |¡WYd}~nd}~ww|durU| dd|j ¡dS|  ¡rgt   |¡}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)rPrSrär«röÚ_handle_fatal_errorr r'r r†rr5r~r%rÌr r+)r…rrr%r(ÚfilteredrÏr8r8r9rg s(  €€ÿ zTarFile._get_extract_tarinfoc Cs’| d¡z|j|tj ||j¡||||d�WdSty1}z | |¡WYd}~dSd}~wtyH}z |  |¡WYd}~dSd}~ww)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) r{)rrrÚextraction_rootN) råÚ_extract_memberr~r%rÌr†r«r.r r')r…rñr%rrrrÏr8r8r9r… s  ü€€ÿzTarFile._extract_onecCs |jdkr‚| dd|¡dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#ú tarfile: %sN)rÂr ©r…rÏr8r8r9r'™ s zTarFile._handle_nonfatal_errorcCsp|jdkr‚t|tƒr)|jdur| dd|j¡dS| dd|j|jf¡dS| ddt|ƒj|f¡dS)z1Handle "fatal" error according to self.errorlevelrNr#r2ztarfile: %s %rztarfile: %s %s)rÂrPr«Úfilenamer Ústrerrorr&ror3r8r8r9r.  s   zTarFile._handle_fatal_errorcCsz| d¡t|tƒr| |¡}n|}| ¡s|jtvr!| ||¡S| ¡s)|  ¡r;t|j t ƒr3t dƒ‚|  | |¡¡SdS)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. r{z'cannot extract (sym)link as file objectN)rårPrSrärr&r„Ú fileobjectrrrŸr�r Ú extractfileÚ_find_link_target)r…rrñr8r8r9r7¬ s     zTarFile.extractfile©rr0cCs\| d¡}| dtj¡}tj |¡}|rtj |¡st |¡| ¡s'|  ¡r4|  dd|j |j f¡n|  d|j ¡|  ¡rF| ||¡nI| ¡rQ| ||¡n>| ¡r\| ||¡n3| ¡sd| ¡rk| ||¡n$| ¡ss|  ¡r}|j||||d�n|jtvr‰| ||¡n| ||¡|rª| |||¡|  ¡s¬| ||¡| ||¡dSdSdS)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 -> %sr9N)rr³r~rr%rr¼Úmakedirsrrr r†r rÚmakefilerÚmakedirr¬Úmakefifor©rªÚmakedevÚmakelink_with_filterr&r„Ú makeunknownr$r&r%)r…rñÚ targetpathrrrr0Z upperdirsr8r8r9r1Ì s@   ý   üzTarFile._extract_membercCsBz|jdurt |¡WdSt |d¡WdSty YdSw)z,Make a directory called targetpath. NiÀ)r‡r~ÚmkdirÚFileExistsError©r…rñrAr8r8r9r< s  ÿzTarFile.makedircCs´|j}| |j¡|j}t|dƒ�?}|jdur7|jD]\}}| |¡t|||t|ƒq| |j¡|  ¡nt|||jt|ƒWdƒdSWdƒdS1sSwYdS)z'Make a file called targetpath. r¶N) rŸrÈrírÃr½rîr[rr'Útruncate)r…rñrAÚ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 r&rDr8r8r9r@" s  ÿzTarFile.makeunknowncCs ttdƒr t |¡dStdƒ‚)z'Make a fifo called targetpath. Úmkfifozfifo not supported by systemN)rƒr~rHr rDr8r8r9r=* s zTarFile.makefifocCsjttdƒr ttdƒstdƒ‚|j}|durd}| ¡r!|tjO}n|tjO}t ||t  |j |j ¡¡dS)zz'special devices not supported by systemNr ) rƒr~r r‡rªrîÚS_IFBLKÚS_IFCHRrIr>r'r()r…rñrAr‡r8r8r9r>2 s  ÿzTarFile.makedevcCs| ||dd¡Sr‰)r?rDr8r8r9ÚmakelinkD rŒzTarFile.makelinkc Cs.d}z,| ¡rtj |¡rt |¡t |j|¡WdStj |j¡r-t  |j|¡WdSWn t y9d}Ynwz|  |¡}Wnt yP|rOt dƒd‚‚w|durX|}n.|dur`t dƒ‚z||j|jdd�|ƒ|||ƒ}Wnty…}zt||jƒ|‚d}~ww|dur•|j||||d�dSdS)a3Make a (symbolic) link called targetpath. If it cannot be created (platform limitation), we try to make a copy of the referenced file instead of a link. filter_function is only used when extracting a *different* member (e.g. as fallback to creating a link). FNTz%unable to resolve link inside archivez[makelink_with_filter: if filter_function is not None, extraction_root must also not be None)r†rr9)rr~r%ÚlexistsÚunlinkÚsymlinkr r¼r+ÚlinkÚsymlink_exceptionr8rãr r³r†r rr1) r…rñrArr0Zkeyerror_to_extracterrorr(r/Úcauser8r8r9r?G s^   þ ÿ ÿÿûÿþ€ÿ þÿzTarFile.makelink_with_filterc Csttdƒr€t ¡dkr‚|j}|j}|sEztr!|jr!t |j¡d}Wn ty+Ynwzt r:|j r:t   |j ¡d}Wn tyDYnw|durKd}|durQd}z|  ¡rettdƒret  |||¡WdSt |||¡WdSty}ztdƒ|‚d}~wwdSdS)zðSet owner of targetpath according to tarinfo. If numeric_owner is True, use .gid/.uid instead of .gname/.uname. If numeric_owner is False, fall back to .gid/.uid when the search based on name fails. Úgeteuidrr$Nr;Úlchownzcould not change owner)rƒr~rSr*r)rr,Zgetgrnamrãrr+ÚgetpwnamrrTr$r«r )r…rñrArÚgÚurÏr8r8r9r$| s> € ÿ € ÿ €ÿèz TarFile.chownc CsF|jdurdSz t ||j¡WdSty"}ztdƒ|‚d}~ww)zASet file permissions of targetpath according to tarinfo. Nzcould not change mode)r‡r~r&r«r )r…rñrArÏr8r8r9r&� s  €ÿz TarFile.chmodc CsZ|j}|dur dSttdƒsdSz t |||f¡WdSty,}ztdƒ|‚d}~ww)zBSet modification time of targetpath according to tarinfo. Nr%z"could not change modification time)r(rƒr~r%r«r )r…rñrAr(rÏr8r8r9r%§ s  €ÿz TarFile.utimec Cs:| d¡|jdur|j}d|_|S|j|j ¡kr-|j |jd¡|j d¡s-tdƒ‚d} z|j  |¡}WnÑt ye}z!|j r[|  dd|j|f¡|jt 7_WYd}~q/WYd}~n©d}~wty�}z-|j r‡|  dd|j|f¡|jt 7_WYd}~q/|jdkr“tt|ƒƒd‚WYd}~nqd}~wty¯|jdkr­td ƒd‚Yn[tyÌ}z|jdkrÂtt|ƒƒd‚WYd}~nBd}~wtyÞ}ztt|ƒƒd‚d}~wt�y }zzddl}t||jƒrùtd |›�ƒd‚|‚t�y|‚wd}~ww |du�r|j |¡|Sd|_|S) z¨Return the next member of the archive as a TarInfo object, when TarFile is opened for reading. Return None if there is no more available. ZraNr#rYTr$z0x%X: %srz empty filez zlib error: )rårÇrÕrŸrÅrÈr]rrñr}rvrÀr rÐrKrSrtrurwÚ Exceptionr¢rPr§r£rÄrËrÅ)r…ÚmrñrÏr¢r8r8r9rˆµ st     ý€   ÿ€   ÿ  ÿ€€ ÿ€ù  þz TarFile.nextc Cs´| ¡}d}|dur#z| |¡}Wn tyd}Ynw|d|…}|r+tj |¡}t|ƒD]"}|r<|j|jkr;d}q/|rFtj |j¡}n|j}||krQ|Sq/|rXt|ƒ‚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ÄZskippingrZrÚ member_namer8r8r9râô s2 ý    ÿþzTarFile._getmembercCs | ¡}|dur nqd|_dS)zWRead through the entire archive file and look for readable members. TN)rˆrÅrùr8r8r9ræ s ý z TarFile._loadcCs>|jr td|jjƒ‚|dur|j|vrtd|jƒ‚dSdS)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óror‡)r…r‡r8r8r9rå& s ÿzTarFile._checkcCs`| ¡rd 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ñr\zlinkname %r not found) rrÌr r~r%rr†r rârã)r…rñr Úlimitrr8r8r9r8/ s  zTarFile._find_link_targetccsŠ�|jr |jEdHdSd}|jdur| ¡}|d7}|V |t|jƒkr,|j|}n|js;| ¡}|s:d|_dSndS|d7}|Vq)z$Provide an iterator object. Nrr#T)rÅrÄrÇrˆr2)r…rZrñr8r8r9Ú__iter__B s,€   þõzTarFile.__iter__cCs ||jkrt|tjd�dSdS)z.Write debugging output to sys.stderr. ©ÚfileN)rÁrkriÚstderr)r…ÚlevelÚmsgr8r8r9r a s ÿz TarFile._dbgcCs | ¡|Sr‰)rår‹r8r8r9Ú __enter__g szTarFile.__enter__cCs.|dur | ¡dS|js|j ¡d|_dSrÛ)rŠr›rŸr¡)r…r&r@Ú tracebackr8r8r9Ú__exit__k s    zTarFile.__exit__) Nr{NNNNNNr;NNNN)r{N)r{Nr¯)r{NN)NNN©TrÛr‰)rN)r’T)TFrÝ)@rorprqrrrÁr¿rÀrÂrrSr r6r7rrñrìr6rrˆr³rárrÉrÚrÝràrÊrŠrärçrèrr˜rr rr+r!r-rrr'r.r7r1r<r;r@r=r>rLr?r$r&r%rˆrârærår8r_r rergr8r8r8r9r�sž ýo]    ü   c& 3 ÿE ÿ ÿ  ÿ þ85!  ?(   rcCsBzt|dƒr t|d�}nt|ƒ}| ¡WdSty YdSw)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ŸTF)rƒrrŠr)r†rÎr8r8r9ry s   ÿrc Cshddl}d}|j|d�}|jdddddd �|jd d td d �|jdd�}|jddddd�|jdddddd�|jdddddd�|jdd dd!d�| ¡}|jr]|jdur]| d"d#¡|j dur¤|j }t |ƒr™t |d$ƒ�}|  ¡t |  ¡tjd%�Wdƒn1s†wY|jr—t d& |¡ƒdSdS| d"d' |¡¡dS|jdurÛ|j}t |ƒrÐt  |d(¡�}|j|jd)�WdƒdS1sÉwYdS| d"d' |¡¡dS|jdu�rRt|jƒd"krñ|jd}tj}nt|jƒd*krþ|j\}}n| d"| ¡¡t |ƒ�rGt  |d(¡�}|j||jd+�Wdƒn 1�s%wY|j�rE|d,k�r9d- |¡} nd. ||¡} t | ƒdSdS| d"d' |¡¡dS|jdu�r°|j d¡} tj | ¡\} } d/d/d0d0d1d1d1d1d2œ} | | v�r|d3| | nd4}|j}t  | |¡�}|D]}| |¡�qŠWdƒn 1�sžwY|j�r²t d5 | ¡ƒdSdSdS)6Nrz3A simple command-line interface for tarfile module.)Ú descriptionz-vz --verboseÚ store_trueFzVerbose output)ÚactionÚdefaultÚhelpz--filterz zFilter for extraction)ÚmetavarÚchoicesrmT)Zrequiredz-lz--listú zShow listing of a tarfile)rnrmz-ez --extractú+)rpz zExtract tarfile into target dir)Únargsrnrmz-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction r{r`z{!r} is a tar archive.z{!r} is not a tar archive. rÈ)rr$)r%r rz{!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_argumentrZadd_mutually_exclusive_groupÚ parse_argsr r-ÚexitÚtestrrrçrkrirbrrSr˜rr2r~ÚcurdirZ format_helpr+ZcreateÚpopr%Úsplitextr)rsriÚparserr�Úargsr_r™ZtfryrdZtar_nameršZextZ compressionsZtar_modeZ tar_filesÚ file_namer8r8r9ÚmainŒ s²  ÿþ  ÿ þ þ ÿ   þÿ "ÿ    ÿ  ÿ ú  õ ÿÿèrÚ__main__rh)orrÚversionÚ __author__Ú __credits__Úbuiltinsrr½rir~rárZrîr¶rVr5ÚreÚwarningsrr£rÚAttributeErrorÚNotImplementedErrorrQr«Ú NameErrorÚ__all__r3rÐrárIrDrFrEr[r,rsr¨r§r]r^r8r«ZCONTTYPErLrKrtrUrWr�r rrrr„r¤rvr r“rQrIr¡r†r Úgetfilesystemencodingr:r?rNrTrXr[rlrXrr rrr r rtrurvrKrwryr�ÚobjectrœrÔÚBufferedReaderrìrör÷rûrrrrr rrr"r$rr4ÚcompilerŽrrrrror8r8r8r9Ús(   ÿ  ÿ ÿ üÿÿú  uh  Jý ;e _ ÿ