B €w¾íÉÍã@sndZdZdZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZy ddlZWnek r„dZYnXy ddlZWnek rªdZYnXeefZyeef7ZWnek rÖYnXdddd d d d d dddddddgZdZdZedZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.dZ/d*Z0d+Z1e0Z2e e!e"e#e&e'e(e$e%e)e*e+f Z3e e!e(e+fZ4e)e*e+fZ5d,Z6d-d.d/d0hZ7e8e8e8e9e9e9d1œZ:ej;d2krÐd3Zd6d7„Z?d8d9„Z@d:e2fd;d<„ZAd=d>„ZBdedfd?d@„ZCdAdB„ZDdCdD„ZEGdEd „d eFƒZGGdFd „d eGƒZHGdGd „d eGƒZIGdHd „d eGƒZJGdId „d eGƒZKGdJd„deGƒZLGdKdL„dLeLƒZMGdMdN„dNeLƒZNGdOdP„dPeLƒZOGdQdR„dReLƒZPGdSdT„dTeLƒZQGdUdV„dVƒZRGdWdX„dXƒZSGdYdZ„dZeTƒZUGd[d\„d\eTƒZVGd]d^„d^ejWƒZXGd_d„deTƒZYGd`d„deTƒZZdad„Z[eZjZdbdc„Z\e]ddkrje\ƒdS)ez0.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Úgnamer%r&r+r,)ZatimeZctimer(r)r*r'Úntzutf-8cCs(| ||¡}|d|…|t|ƒtS)N)ÚencodeÚlenÚNUL)ÚsÚlengthÚencodingÚerrors©r5ú*/opt/alt/python37/lib/python3.7/tarfile.pyÚstnžs r7cCs*| d¡}|dkr|d|…}| ||¡S)Nréÿÿÿÿ)ÚfindÚdecode)r1r3r4Úpr5r5r6Únts¤s  r<cCsª|ddkrfd}x0tt|ƒdƒD]}|dK}|||d7}q"W|ddkr¦dt|ƒd| }n@y"t|ddƒ}t| ¡p€d dƒ}Wntk r¤td ƒ‚YnX|S) Nr)é€éÿr#ér>éÚasciiÚstrictÚ0zinvalid header)Úranger/r<ÚintÚstripÚ ValueErrorÚInvalidHeaderError)r1ÚnÚir5r5r6Únti¬s   rKr?cCsÜt|ƒ}d|kr$d|dkrDnntd|d|fdƒt}n”|tkrÐd|d |krrd|dkrÐnnZ|dkrŠtdgƒ}ntdgƒ}d||}x6t|dƒD]}| d|d@¡|dL}q®Wntd ƒ‚|S) Nrr?r#z%0*orAr@r=r>zoverflow in number field)rEÚbytesr0rÚ bytearrayrDÚinsertrG)rIÚdigitsÚformatr1rJr5r5r6ÚitnÀs  2   rQcCs0dtt d|¡ƒ}dtt d|¡ƒ}||fS)Nr@Z 148B8x356BZ 148b8x356b)ÚsumÚstructÚ unpack_from)ÚbufZunsigned_chksumZ signed_chksumr5r5r6Ú calc_chksumsÝs rVc Csª|pd}|dkrdS|dkr.t |||¡dSt||ƒ\}}x8t|ƒD],}| |¡}t|ƒ|krh|dƒ‚| |¡qFW|dkr¦| |¡}t|ƒ|krœ|dƒ‚| |¡dS)Ni@rzunexpected end of data)ÚshutilÚ copyfileobjÚdivmodrDÚreadr/Úwrite) ÚsrcÚdstr2Ú exceptionÚbufsizeÚblocksÚ remainderÚbrUr5r5r6rXês$     rXcCs ddl}| dtd¡t |¡S)Nrz$deprecated in favor of stat.filemoder$)ÚwarningsÚwarnÚDeprecationWarningÚstatÚfilemode)Úmodercr5r5r6rgsrgcCs8ttjddƒ}|dk r(| |d¡ |¡}t|dddS)Nr3Úbackslashreplaceú )Úend)ÚgetattrÚsysÚstdoutr.r:Úprint)r1r3r5r5r6Ú _safe_print srpc@s eZdZdS)rN)Ú__name__Ú __module__Ú __qualname__r5r5r5r6rsc@s eZdZdS)r N)rqrrrsr5r5r5r6r sc@s eZdZdS)rN)rqrrrsr5r5r5r6rsc@s eZdZdS)rN)rqrrrsr5r5r5r6rsc@s eZdZdS)r N)rqrrrsr5r5r5r6r sc@s eZdZdS)r N)rqrrrsr5r5r5r6r sc@s eZdZdS)ÚEmptyHeaderErrorN)rqrrrsr5r5r5r6rt#srtc@s eZdZdS)ÚTruncatedHeaderErrorN)rqrrrsr5r5r5r6ru&sruc@s eZdZdS)ÚEOFHeaderErrorN)rqrrrsr5r5r5r6rv)srvc@s eZdZdS)rHN)rqrrrsr5r5r5r6rH,srHc@s eZdZdS)ÚSubsequentHeaderErrorN)rqrrrsr5r5r5r6rw/srwc@s,eZdZdd„Zdd„Zdd„Zdd„Zd S) Ú _LowLevelFilecCsFtjtjtjBtjBdœ|}ttdƒr2|tjO}t ||d¡|_dS)N)ÚrÚwÚO_BINARYi¶) ÚosÚO_RDONLYÚO_WRONLYÚO_CREATÚO_TRUNCÚhasattrr{rÚfd)ÚselfÚnamerhr5r5r6Ú__init__<s   z_LowLevelFile.__init__cCst |j¡dS)N)r|Úcloser‚)rƒr5r5r6r†Esz_LowLevelFile.closecCst |j|¡S)N)r|rZr‚)rƒr'r5r5r6rZHsz_LowLevelFile.readcCst |j|¡dS)N)r|r[r‚)rƒr1r5r5r6r[Ksz_LowLevelFile.writeN)rqrrrsr…r†rZr[r5r5r5r6rx6s rxc@speZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z ddd„Z ddd„Z dd„Z dd„ZdS)Ú_Streamc Csäd|_|dkrt||ƒ}d|_|dkr6t|ƒ}| ¡}|pt|jƒ|jkrL|j |jd|j…¡|j|jd…|_qWdS)N)rUr/r_r“r[)rƒr1r5r5r6Z__write»sz_Stream.__writecCs²|jr dSd|_zŠ|jdkr:|jdkr:|j|j ¡7_|jdkr˜|jr˜|j |j¡d|_|jdkr˜|j t  d|j ¡¡|j t  d|j d@¡¡Wd|j s¬|j  ¡XdS)NTrzrŽrŠr‹zd|fg}d|_g|_d}|j}xT|D]L\}}||kr~|j  d||df¡|j  d||||f¡||7}||}qZW||jkrÊ|j  d||jdf¡dS)Nrr„FT) r“Úoffsetr'Úpositionrlr„r•Ú map_indexÚmapr·)rƒr“rÀr'Z blockinfoZlastposZrealposr5r5r6r…hs(   z_FileInFile.__init__cCsdS)Nr5)rƒr5r5r6r¬sz_FileInFile.flushcCsdS)NTr5)rƒr5r5r6Úreadable„sz_FileInFile.readablecCsdS)NFr5)rƒr5r5r6Úwritable‡sz_FileInFile.writablecCs |j ¡S)N)r“Úseekable)rƒr5r5r6rÆŠsz_FileInFile.seekablecCs|jS)N)rÁ)rƒr5r5r6r´sz_FileInFile.tellcCs|tjkr tt|dƒ|jƒ|_nj|tjkr\|dkrFt|j|dƒ|_qŠt|j||jƒ|_n.|tjkr‚tt|j||jƒdƒ|_ntdƒ‚|jS)NrzInvalid argument) ÚioÚSEEK_SETÚminÚmaxr'rÁÚSEEK_CURÚSEEK_ENDrG)rƒrÁÚwhencer5r5r6rµ’s   z_FileInFile.seekc Cs|dkr|j|j}nt||j|jƒ}d}xà|dkr xZ|j|j\}}}}||jkrd|krlnnPq:|jd7_|jt|jƒkr:d|_q:Wt|||jƒ}|rè|j ||j|¡|j |¡}t|ƒ|krÞt dƒ‚||7}n |t |7}||8}|j|7_q.W|S)NrŠrr#zunexpected end of data) r'rÁrÉrÃrÂr/r“rµrZrr0) rƒr'rUÚdataÚstartÚstoprÀr2rbr5r5r6rZ¢s.      z_FileInFile.readcCs&| t|ƒ¡}||dt|ƒ…<t|ƒS)N)rZr/)rƒrbrUr5r5r6ÚreadintoÁsz_FileInFile.readintocCs d|_dS)NT)r•)rƒr5r5r6r†Æsz_FileInFile.close)N)N)rqrrrsr…r¬rÄrÅrÆr´rÇrÈrµrZrÑr†r5r5r5r6r¿bs  r¿cseZdZ‡fdd„Z‡ZS)Ú ExFileObjectcs&t|j|j|j|jƒ}tƒ |¡dS)N)r¿r“Ú offset_datar'ÚsparseÚsuperr…)rƒÚtarfileÚtarinfor“)Ú __class__r5r6r…Ìs  zExFileObject.__init__)rqrrrsr…Ú __classcell__r5r5)rØr6rÒÊsrÒc@sŠeZdZdZdSdd„Zedd„ƒZejdd„ƒZedd „ƒZejd d „ƒZd d „Z d d„Z e e dfdd„Z dd„Zdd„Zdd„Zedd„ƒZdd„Zedd„ƒZedd„ƒZed d!„ƒZed"d#„ƒZed$d%„ƒZed&d'„ƒZd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Z d4d5„Z!d6d7„Z"d8d9„Z#d:d;„Z$dd?„Z&d@dA„Z'dBdC„Z(dDdE„Z)dFdG„Z*dHdI„Z+dJdK„Z,dLdM„Z-dNdO„Z.dPdQ„Z/dRS)Tr)r„rhr)r*r'r(ÚchksumÚtypeÚlinknamer+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)Ni¤rr‰)r„rhr)r*r'r(rÚÚREGTYPErÛrÜr+r,rÝrÞrÀrÓrÔrß)rƒr„r5r5r6r…ãs"zTarInfo.__init__cCs|jS)N)r„)rƒr5r5r6r%ýsz TarInfo.pathcCs ||_dS)N)r„)rƒr„r5r5r6r%scCs|jS)N)rÜ)rƒr5r5r6r&szTarInfo.linkpathcCs ||_dS)N)rÜ)rƒrÜr5r5r6r& scCsd|jj|jt|ƒfS)Nz<%s %r at %#x>)rØrqr„Úid)rƒr5r5r6Ú__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)Niÿ) r„rhr)r*r'r(rÚrÛrÜr+r,rÝrÞrÛr„ú/)r„rhr)r*r'r(rÚrÛrÜr+r,rÝrÞÚDIRTYPErª)rƒÚinfor5r5r6Úget_infos  zTarInfo.get_infoÚsurrogateescapecCsT| ¡}|tkr| |||¡S|tkr4| |||¡S|tkrH| ||¡Stdƒ‚dS)Nzinvalid format)rèr Úcreate_ustar_headerrÚcreate_gnu_headerrÚcreate_pax_headerrG)rƒrPr3r4rçr5r5r6Útobuf(s z TarInfo.tobufcCsnt|d<t|d ||¡ƒtkr(tdƒ‚t|d ||¡ƒtkr^| |d||¡\|d<|d<| |t||¡S)NÚmagicrÜzlinkname is too longr„Úprefix) Ú POSIX_MAGICr/r.Ú LENGTH_LINKrGÚ LENGTH_NAMEÚ_posix_split_nameÚ_create_headerr )rƒrçr3r4r5r5r6rê6s zTarInfo.create_ustar_headercCs€t|d<d}t|d ||¡ƒtkr<|| |dt||¡7}t|d ||¡ƒtkrl|| |dt||¡7}|| |t ||¡S)NrîrŠrÜr„) Ú GNU_MAGICr/r.rñÚ_create_gnu_long_headerÚGNUTYPE_LONGLINKròÚGNUTYPE_LONGNAMErôr)rƒrçr3r4rUr5r5r6rëCszTarInfo.create_gnu_headerc Cs0t|d<|j ¡}x„ddtfddtfddfD]h\}}}||kr@q,y|| dd ¡Wn"tk rv||||<w,YnXt||ƒ|kr,||||<q,Wxhd D]`\}}||kr¸d ||<qž||}d |krÜd |d krênn t|t ƒržt |ƒ||<d ||<qžW|r|  |t |¡} nd} | |  |tdd¡S)Nrîr„r%rÜr&)r+r+é )r,r,rùrArB))r)r?)r*r?)r'é )r(rúrr?r#rŠr¥)rðrßÚcopyròrñr.ÚUnicodeEncodeErrorr/Ú isinstanceÚfloatÚstrÚ_create_pax_generic_headerÚXHDTYPErôr ) rƒrçr3rßr„Zhnamer2rOÚvalrUr5r5r6rìQs4  *  zTarInfo.create_pax_headercCs| |td¡S)Nzutf-8)rÚXGLTYPE)Úclsrßr5r5r6Úcreate_pax_global_header‚sz TarInfo.create_pax_global_headercCs€| d¡}xltdt|ƒƒD]R}d |d|…¡}d ||d…¡}t| ||¡ƒtkrt| ||¡ƒtkrPqWtdƒ‚||fS)Nrår#zname is too long)ÚsplitrDr/r¸r.Ú LENGTH_PREFIXròrG)rƒr„r3r4Z componentsrJrïr5r5r6róˆs zTarInfo._posix_split_namecCsVt| dd¡d||ƒt| dd¡d@d|ƒt| dd¡d|ƒt| d d¡d|ƒt| d d¡d |ƒt| d d¡d |ƒd | dt¡t| dd¡d||ƒ| dt¡t| dd¡d||ƒt| dd¡d||ƒt| dd¡d|ƒt| dd¡d|ƒt| dd¡d||ƒg}t dtd |¡¡}t |t d…ƒd}|dd…t d|dƒ|dd…}|S)Nr„r‰rrhriÿr?r)r*r'rúr(s rÛrÜrîr+rùr,rÝrÞrïrz%dsrŠi”þÿÿz%06orAi›þÿÿ) r7ÚgetrQrârðrSr§r»r¸rVrL)rçrPr3r4ÚpartsrUrÚr5r5r6rô˜s&  &zTarInfo._create_headercCs.tt|ƒtƒ\}}|dkr*|t|t7}|S)Nr)rYr/r»r0)Zpayloadr`rar5r5r6Ú_create_payload´szTarInfo._create_payloadcCsR| ||¡t}i}d|d<||d<t|ƒ|d<t|d<| |t||¡| |¡S)Nz ././@LongLinkr„rÛr'rî)r.r0r/rõrôr r )rr„rÛr3r4rçr5r5r6rö¾s zTarInfo._create_gnu_long_headerc Cs:d}x@| ¡D]4\}}y| dd¡Wqtk r@d}PYqXqWd}|rV|d7}x | ¡D]”\}}| d¡}|r„| |d¡}n | d¡}t|ƒt|ƒd}d } } x"|tt| ƒƒ} | | krÆP| } q¬W|tt| ƒd ƒd |d |d 7}q`Wi} d| d<|| d<t|ƒ| d<t| d<| | td d¡|  |¡S)NFzutf-8rBTrŠs21 hdrcharset=BINARY rér¼rrAó ó=ó z././@PaxHeaderr„rÛr'rîr¥) Úitemsr.rür/rÿrLrðrôr r ) rrßrÛr3ZbinaryÚkeywordÚvalueZrecordsÚlrIr;rçr5r5r6rÏs<   * z"TarInfo._create_pax_generic_headerc Cstt|ƒdkrtdƒ‚t|ƒtkr(tdƒ‚| t¡tkr>tdƒ‚t|dd…ƒ}|t|ƒkrbt dƒ‚|ƒ}t |dd…||ƒ|_ t|dd …ƒ|_ t|d d …ƒ|_ t|d d …ƒ|_t|d d …ƒ|_t|d d…ƒ|_||_|dd …|_t |d d…||ƒ|_t |dd…||ƒ|_t |dd…||ƒ|_t|dd…ƒ|_t|dd…ƒ|_t |dd…||ƒ}|jtkr†|j  d¡r†t|_|jtkr6d}g}xrtdƒD]f} y0t|||d…ƒ} t||d|d…ƒ} Wntk rðPYnX| | | f¡|d7}q¤Wt|dƒ} t|dd…ƒ} || | f|_ | !¡rN|j  "d¡|_ |rp|jt#krp|d|j |_ |S)Nrz empty headerztruncated headerzend of file headeré”éœz bad checksumrélété|éˆéii i)iIiQiYiôråi‚r¯rúéiâiãiï)$r/rtr»ruÚcountr0rvrKrVrHr<r„rhr)r*r'r(rÚrÛrÜr+r,rÝrÞÚAREGTYPErªræÚGNUTYPE_SPARSErDrGr·ÚboolràÚisdirÚrstripÚ GNU_TYPES)rrUr3r4rÚÚobjrïr”ÚstructsrJrÀÚnumbytesÚ isextendedÚorigsizer5r5r6ÚfrombufsZ       zTarInfo.frombufcCs8|j t¡}| ||j|j¡}|j ¡t|_| |¡S)N) r“rZr»r&r3r4r´rÀÚ _proc_member)rrÖrUr!r5r5r6Ú fromtarfileAs zTarInfo.fromtarfilecCsT|jttfkr| |¡S|jtkr,| |¡S|jtttfkrF|  |¡S|  |¡SdS)N) rÛrør÷Ú _proc_gnulongrÚ _proc_sparserrÚSOLARIS_XHDTYPEÚ _proc_paxÚ _proc_builtin)rƒrÖr5r5r6r'Vs    zTarInfo._proc_membercCsR|j ¡|_|j}| ¡s$|jtkr4|| |j¡7}||_|  |j |j |j ¡|S)N) r“r´rÓÚisregrÛÚSUPPORTED_TYPESÚ_blockr'rÀÚ_apply_pax_inforßr3r4)rƒrÖrÀr5r5r6r-cs zTarInfo._proc_builtincCs†|j | |j¡¡}y| |¡}Wntk r>tdƒ‚YnX|j|_|jt krft ||j |j ƒ|_ n|jtkr‚t ||j |j ƒ|_|S)Nz missing or bad subsequent header)r“rZr0r'r(r rwrÀrÛrør<r3r4r„r÷rÜ)rƒrÖrUÚnextr5r5r6r)ts  zTarInfo._proc_gnulongc CsÞ|j\}}}|`xœ|r¬|j t¡}d}xvtdƒD]j}y0t|||d…ƒ}t||d|d…ƒ} Wntk rzPYnX|r’| r’| || f¡|d7}q0Wt|dƒ}qW||_ |j  ¡|_ |j |  |j ¡|_||_ |S)Nrérúriø)ràr“rZr»rDrKrGr·rrÔr´rÓr0r'rÀ) rƒrÖr"r$r%rUr”rJrÀr#r5r5r6r*Šs(    zTarInfo._proc_sparsecCs0|j | |j¡¡}|jtkr&|j}n |j ¡}t  d|¡}|dk rX|  d¡  d¡|d<|  d¡}|dkrr|j }nd}t d¡}d}x²| ||¡}|s˜P| ¡\} } t| ƒ} | dkr¼tdƒ‚|| d ¡d| d¡| d…} | | dd|j¡} | tkr| | ||j |j¡} n| | dd|j¡} | || <|| 7}q†Wy| |¡} Wntk rdtd ƒ‚YnXd |kr~| | |¡nHd |kr˜| | ||¡n.|  d ¡dkrÆ|  d¡dkrÆ| | ||¡|jttfkr,|   ||j |j¡|j!| _!d|kr,| j"} |  #¡s| jt$kr&| |  | j¡7} | |_!| S)Ns\d+ hdrcharset=([^\n]+)\nr#zutf-8Ú hdrcharsetZBINARYs(\d+) ([^=]+)=rzinvalid headerr$z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.majorÚ1zGNU.sparse.minorrCr')%r“rZr0r'rÛrrßrûÚreÚsearchÚgroupr:rr3ÚcompileÚmatchÚgroupsrErHrkrÏÚ_decode_pax_fieldr4ÚPAX_NAME_FIELDSr(r rwÚ_proc_gnusparse_01Ú_proc_gnusparse_00Ú_proc_gnusparse_10rr+r1rÀrÓr.r/)rƒrÖrUrßr:r4r3Zregexr”r2rrr2rÀr5r5r6r,¦sd       $          zTarInfo._proc_paxcCspg}x(t d|¡D]}| t| d¡ƒ¡qWg}x(t d|¡D]}| t| d¡ƒ¡q@Wtt||ƒƒ|_dS)Ns\d+ GNU.sparse.offset=(\d+)\nr#s\d+ GNU.sparse.numbytes=(\d+)\n)r6Úfinditerr·rEr8ÚlistÚziprÔ)rƒr2rßrUZoffsetsr:r#r5r5r6r?szTarInfo._proc_gnusparse_00cCs@dd„|d d¡Dƒ}tt|ddd…|ddd…ƒƒ|_dS)NcSsg|] }t|ƒ‘qSr5)rE)Ú.0Úxr5r5r6ú sz.TarInfo._proc_gnusparse_01..zGNU.sparse.mapú,r$r#)rrBrCrÔ)rƒr2rßrÔr5r5r6r>szTarInfo._proc_gnusparse_01cCs¬d}g}|j t¡}| dd¡\}}t|ƒ}xJt|ƒ|dkrvd|krV||j t¡7}| dd¡\}}| t|ƒ¡q.W|j ¡|_t t |ddd…|ddd…ƒƒ|_ dS)Nr r#r$) r“rZr»rrEr/r·r´rÓrBrCrÔ)rƒr2rßrÖZfieldsrÔrUZnumberr5r5r6r@s  zTarInfo._proc_gnusparse_10c CsÆx¶| ¡D]ª\}}|dkr(t|d|ƒq |dkrBt|dt|ƒƒq |dkr\t|dt|ƒƒq |tkr |tkr–yt||ƒ}Wntk r”d}YnX|dkr¨| d¡}t|||ƒq W| ¡|_dS)NzGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerrå) rÚsetattrrEÚ PAX_FIELDSÚPAX_NUMBER_FIELDSrGrrûrß)rƒrßr3r4rrr5r5r6r1/s"  zTarInfo._apply_pax_infocCs.y | |d¡Stk r(| ||¡SXdS)NrB)r:ÚUnicodeDecodeError)rƒrr3Zfallback_encodingZfallback_errorsr5r5r6r<Fs zTarInfo._decode_pax_fieldcCs"t|tƒ\}}|r|d7}|tS)Nr#)rYr»)rƒrr`rar5r5r6r0NszTarInfo._blockcCs |jtkS)N)rÛÚ REGULAR_TYPES)rƒr5r5r6r.Wsz TarInfo.isregcCs| ¡S)N)r.)rƒr5r5r6ÚisfileYszTarInfo.isfilecCs |jtkS)N)rÛræ)rƒr5r5r6r[sz TarInfo.isdircCs |jtkS)N)rÛÚSYMTYPE)rƒr5r5r6Úissym]sz TarInfo.issymcCs |jtkS)N)rÛÚLNKTYPE)rƒr5r5r6Úislnk_sz TarInfo.islnkcCs |jtkS)N)rÛÚCHRTYPE)rƒr5r5r6Úischrasz TarInfo.ischrcCs |jtkS)N)rÛÚBLKTYPE)rƒr5r5r6Úisblkcsz TarInfo.isblkcCs |jtkS)N)rÛÚFIFOTYPE)rƒr5r5r6ÚisfifoeszTarInfo.isfifocCs |jdk S)N)rÔ)rƒr5r5r6ÚissparsegszTarInfo.issparsecCs|jtttfkS)N)rÛrRrTrV)rƒr5r5r6Úisdevisz TarInfo.isdevN)r‰)0rqrrrsÚ __slots__r…Úpropertyr%Úsetterr&rärèrr rírêrërìÚ classmethodrróÚ staticmethodrôr rörr&r(r'r-r)r*r,r?r>r@r1r<r0r.rMrrOrQrSrUrWrXrYr5r5r5r6rÕsR    1    3 ?  h  c @s°eZdZdZdZdZdZeZe Z dZ e Z eZd[dd„Zedddefd d „ƒZed\d d „ƒZed]dd„ƒZed^dd„ƒZed_dd„ƒZdddddœZdd„Zdd„Zdd„Zdd „Zd`d!d"„Zdadd$œd%d&„Zdbdd'œd(d)„Zdcd*d+„Z dddd-œd.d/„Z!dedd-œd1d2„Z"d3d4„Z#dfd5d6„Z$d7d8„Z%d9d:„Z&d;d<„Z'd=d>„Z(d?d@„Z)dAdB„Z*dCdD„Z+dEdF„Z,dGdH„Z-dIdJ„Z.dgdKdL„Z/dMdN„Z0dhdOdP„Z1dQdR„Z2dSdT„Z3dUdV„Z4dWdX„Z5dYdZ„Z6dS)irrFr#Nryréc Csªdddddœ}||krtdƒ‚||_|||_|sh|jdkrTtj |¡sTd|_d|_t||jƒ}d |_n@|dkrt|d ƒrt |j t t fƒr|j }t|d ƒr¢|j|_d |_|r¸tj  |¡nd|_ ||_|dk rÒ||_|dk rà||_|dk rî||_|dk rü||_|dk r ||_| |_| dk r0|jtkr0| |_ni|_| dk rF| |_| dk rV| |_| |_d |_g|_d |_|j ¡|_i|_yþ|jd kržd|_ | !¡|_ |jdkr2x†|j "|j¡y|j #|¡}|j $|¡WnTt%k rü|j "|j¡PYn0t&k r*}zt't |ƒƒ‚Wdd}~XYnXq¬W|jdkr|d |_|jr||j (|j )¡¡}|j *|¡|jt+|ƒ7_Wn&|js˜|j ,¡d |_‚YnXdS)NÚrbzr+bÚwbZxb)ryÚarzrEz!mode must be 'r', 'a', 'w' or 'x'rarzFr„rhTry)rarzrE)-rGrhÚ_moder|r%ÚexistsÚ bltn_openrrrýr„rÿrLÚabspathr“rPr×Ú dereferenceÚ ignore_zerosr3r4rrßÚdebugÚ errorlevelÚ copybufsizer•ÚmembersÚ_loadedr´rÀÚinodesÚ firstmemberr2rµr(r·rvr rrrûr[r/r†)rƒr„rhr“rPr×rfrgr3r4rßrhrirjZmodesÚerUr5r5r6r…‡sŠ            $   zTarFile.__init__c s¶|s|stdƒ‚|dkr¦‡fdd„}xttˆj|dD]b}tˆˆj|ƒ}|dk rX| ¡} y||d|f|ŽSttfk r”|dk rŽ| | ¡w4Yq4Xq4Wtdƒ‚nd|kr| dd ¡\} }| pÆd} |pÎd }|ˆjkrìtˆˆj|ƒ}n td |ƒ‚||| |f|ŽSd |krŽ| d d ¡\} }| p*d} |p4d }| d krHtdƒ‚t || |||ƒ} yˆ|| | f|Ž} Wn|   ¡‚YnXd| _ | S|dkrªˆj |||f|ŽStdƒ‚dS)Nznothing to open)ryzr:*csˆj|dkS)NÚtaropen)Ú OPEN_METH)r’)rr5r6Únot_compressed sz$TarFile.open..not_compressed)Úkeyryz%file could not be opened successfullyú:r#rŽzunknown compression type %rú|)ryrzzmode must be 'r' or 'w'F)rarzrEzundiscernible mode) rGÚsortedrqrlr´rrrµrr‡r†rrp) rr„rhr“r_Úkwargsrrr’ÚfuncZ saved_posrgÚstreamr¹r5)rr6rösP%            z TarFile.opencKs |dkrtdƒ‚||||f|ŽS)N)ryrarzrEz!mode must be 'r', 'a', 'w' or 'x')rG)rr„rhr“rwr5r5r6rpQszTarFile.taropenr£cKsè|dkrtdƒ‚yddlm}Wntk r<tdƒ‚YnXy|||d||ƒ}Wn.tk r‚|dk r||dkr|tdƒ‚‚YnXy|j|||f|Ž}WnBtk rÈ| ¡|dkrÂtdƒ‚‚Yn| ¡‚YnXd |_ |S) N)ryrzrEzmode must be 'r', 'w' or 'x'r)ÚGzipFilezgzip module is not availablerbryznot a gzip fileF) rGZgziprzr—rrŸrrpr†r)rr„rhr“Ú compresslevelrwrzr¹r5r5r6ÚgzopenYs0zTarFile.gzopenc Ks¸|dkrtdƒ‚yddlm}Wntk r<tdƒ‚YnX||pF|||d}y|j|||f|Ž}WnFttfk r˜| ¡|dkr’t dƒ‚‚Yn| ¡‚YnXd |_ |S) N)ryrzrEzmode must be 'r', 'w' or 'x'r)ÚBZ2Filezbz2 module is not available)r{ryznot a bzip2 fileF) rGrŒr}r—rrprŸÚEOFErrorr†rr)rr„rhr“r{rwr}r¹r5r5r6Úbz2openzs&zTarFile.bz2openc Ks¼|dkrtdƒ‚yddlm}m}Wntk r@tdƒ‚YnX||pJ|||d}y|j|||f|Ž}WnF|tfk rœ| ¡|dkr–t dƒ‚‚Yn| ¡‚YnXd |_ |S) N)ryrzrEzmode must be 'r', 'w' or 'x'r)ÚLZMAFiler¡zlzma module is not available)Úpresetryznot an lzma fileF) rGr r€r¡r—rrpr~r†rr) rr„rhr“rrwr€r¡r¹r5r5r6Úxzopen–s&zTarFile.xzopenrpr|rr‚)rŽr‹rŒrcCsˆ|jr dSd|_z`|jdkrn|j ttd¡|jtd7_t|jtƒ\}}|dkrn|j tt|¡Wd|j s‚|j  ¡XdS)NT)rarzrEr$r) r•rhr“r[r0r»rÀrYÚ RECORDSIZErr†)rƒr`rar5r5r6r†½s z TarFile.closecCs"| |¡}|dkrtd|ƒ‚|S)Nzfilename %r not found)Ú _getmemberÚKeyError)rƒr„r×r5r5r6Ú getmemberÒs  zTarFile.getmembercCs| ¡|js| ¡|jS)N)Ú_checkrlÚ_loadrk)rƒr5r5r6Ú getmembersÝszTarFile.getmemberscCsdd„| ¡DƒS)NcSsg|] }|j‘qSr5)r„)rDr×r5r5r6rFësz$TarFile.getnames..)r‰)rƒr5r5r6ÚgetnamesçszTarFile.getnamesc Csl| d¡|dk r|j}|dkr$|}tj |¡\}}| tjd¡}| d¡}| ¡}||_ |dkrŠt tdƒr~|j s~t  |¡}q˜t  |¡}nt | ¡¡}d}|j}t  |¡r |j|jf} |j sò|jdkrò| |jkrò||j| kròt} |j| }nt} | drt||j| <nht  |¡rt} nVt  |¡r0t} nDt  |¡rLt} t |¡}n(t  |¡r^t } nt  !|¡rpt"} ndS||_||_#|j$|_%|j&|_'| tkr¤|j(|_)nd|_)|j*|_+| |_,||_-t.ròyt. /|j%¡d|_0Wnt1k rðYnXt2r&yt2 3|j'¡d|_4Wnt1k r$YnX| t t"fkrht tdƒrht tdƒrht 5|j6¡|_7t 8|j6¡|_9|S) NÚawxråÚlstatr‰r#rÚmajorÚminor):r‡r„r|r%Ú splitdriver¥ÚsepÚlstripr×rÖrrfrŒrfÚfstatÚfilenoÚst_modeÚS_ISREGÚst_inoÚst_devÚst_nlinkrmrPrâÚS_ISDIRræÚS_ISFIFOrVÚS_ISLNKrNÚreadlinkÚS_ISCHRrRÚS_ISBLKrTrhÚst_uidr)Úst_gidr*Úst_sizer'Úst_mtimer(rÛrÜÚpwdÚgetpwuidr+r…ÚgrpZgetgrgidr,rÚst_rdevrÝrŽrÞ) rƒr„Úarcnamer“Zdrvr×ZstatresrÜZstmdÚinoderÛr5r5r6Ú gettarinfoís~                 zTarFile.gettarinfoT)rkcCsþ| ¡|dkr|}xä|D]Ü}|r¦tt |j¡ƒtd|jp@|j|jpJ|jfƒ|  ¡sb|  ¡r|tdd|j |j fƒntd|j ƒtdt |j¡dd…ƒt|j| ¡r¸dndƒ|rð| ¡rÚtd |jƒ| ¡rðtd |jƒtƒqWdS) Nz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dr®rår‰z-> zlink to )r‡rprfrgrhr+r)r,r*rSrUrÝrÞr'r¨Z localtimer(r„rrOrÜrQro)rƒÚverboserkr×r5r5r6rBQs* z TarFile.list)Úfilterc Cs:| d¡|dkr|}|jdk rFtj |¡|jkrF| dd|¡dS| d|¡| ||¡}|dkrz| dd|¡dS|dk r¦||ƒ}|dkr¦| dd|¡dS| ¡rÒt|dƒ}|  ||¡WdQRXnd|  ¡r,|  |¡|r6xHt t  |¡ƒD]*}|j tj ||¡tj ||¡||dqüWn |  |¡dS) Nr‹r$ztarfile: Skipped %rr#ztarfile: Unsupported type %rztarfile: Excluded %rr_)r«)r‡r„r|r%reÚ_dbgr©r.rdÚaddfilerrvÚlistdirÚaddr¸)rƒr„r§Ú recursiver«r×Úfr5r5r6r¯qs4      z TarFile.addcCs¾| d¡t |¡}| |j|j|j¡}|j |¡|jt |ƒ7_|j }|dk r®t ||j|j |dt |j tƒ\}}|dkrœ|j tt|¡|d7}|j|t7_|j |¡dS)Nr‹)r_rr#)r‡rûrírPr3r4r“r[rÀr/rjrXr'rYr»r0rkr·)rƒr×r“rUr_r`rar5r5r6r­¤s   zTarFile.addfileÚ.)Ú numeric_ownerc Csg}|dkr|}xF|D]>}| ¡r<| |¡t |¡}d|_|j||| ¡ |dqW|jdd„d| ¡xŠ|D]‚}tj  ||j ¡}y,|j |||d|  ||¡|  ||¡Wqvtk rö}z"|jdkrÖ‚n| dd|¡Wdd}~XYqvXqvWdS) NiÀ)Ú set_attrsr³cSs|jS)N)r„)rar5r5r6ÚÕrŠz$TarFile.extractall..)rs)r³r#z tarfile: %s)rr·rûrhÚextractÚsortÚreverser|r%r¸r„ÚchownÚutimeÚchmodr rir¬)rƒr%rkr³Z directoriesr×Údirpathror5r5r6Ú extractall½s,       zTarFile.extractallr‰c Cs | d¡t|tƒr | |¡}n|}| ¡r>tj ||j¡|_ y"|j |tj ||j ¡||dWn¦t k rÆ}zH|j dkr€‚n6|jdkrž| dd|j¡n| dd|j|jf¡Wdd}~XYnBtk r}z"|j dkræ‚n| dd|¡Wdd}~XYnXdS)Nry)r´r³rr#z tarfile: %sztarfile: %s %r)r‡rýrÿr†rQr|r%r¸rÜráÚ_extract_memberr„rŸriÚfilenamer¬Ústrerrorr )rƒÚmemberr%r´r³r×ror5r5r6r¶ås(      ( zTarFile.extractcCs‚| d¡t|tƒr | |¡}n|}| ¡s6|jtkrB| ||¡S| ¡sR|  ¡rzt|j t ƒrht dƒ‚q~|  | |¡¡SndSdS)Nryz'cannot extract (sym)link as file object)r‡rýrÿr†r.rÛr/Ú fileobjectrQrOr“r‡r Ú extractfileÚ_find_link_target)rƒrÁr×r5r5r6rà s      zTarFile.extractfilecCsT| d¡}| dtj¡}tj |¡}|r>tj |¡s>t |¡| ¡sN|  ¡rh|  dd|j |j f¡n|  d|j ¡|  ¡rŒ| ||¡nŽ| ¡r¢| ||¡nx| ¡r¸| ||¡nb| ¡sÈ| ¡rÖ| ||¡nD| ¡sæ|  ¡rô| ||¡n&|jtkr| ||¡n | ||¡|rP| |||¡|  ¡sP| ||¡| ||¡dS)Nrår#z%s -> %s)rr¥r|rr%ÚdirnamercÚmakedirsrQrOr¬r„rÜr.ÚmakefilerÚmakedirrWÚmakefiforSrUÚmakedevÚmakelinkrÛr/Ú makeunknownr¹r»rº)rƒr×Ú targetpathr´r³Z upperdirsr5r5r6r¾*s4       zTarFile._extract_membercCs*yt |d¡Wntk r$YnXdS)NiÀ)r|ÚmkdirÚFileExistsError)rƒr×rÍr5r5r6rÈ[szTarFile.makedirc Cs’|j}| |j¡|j}t|dƒf}|jdk rrx,|jD]"\}}| |¡t|||t|ƒq6W| |j¡|  ¡nt|||jt|ƒWdQRXdS)Nr`) r“rµrÓrjrdrÔrXrr'Útruncate)rƒr×rÍÚsourcer_ÚtargetrÀr'r5r5r6rÇes      zTarFile.makefilecCs"| ||¡| dd|j¡dS)Nr#z9tarfile: Unknown file type %r, extracted as regular file.)rÇr¬rÛ)rƒr×rÍr5r5r6rÌus zTarFile.makeunknowncCs"ttdƒrt |¡ntdƒ‚dS)NÚmkfifozfifo not supported by system)rr|rÓr )rƒr×rÍr5r5r6rÉ}s  zTarFile.makefifocCs^ttdƒrttdƒstdƒ‚|j}| ¡r6|tjO}n |tjO}t ||t  |j |j ¡¡dS)NÚmknodrÊz'special devices not supported by system) rr|r rhrUrfÚS_IFBLKÚS_IFCHRrÔrÊrÝrÞ)rƒr×rÍrhr5r5r6rÊ…s  zTarFile.makedevc CsšyL| ¡rt |j|¡n0tj |j¡r8t |j|¡n| |  |¡|¡WnHt k r”y| |  |¡|¡Wnt k rŽt dƒ‚YnXYnXdS)Nz%unable to resolve link inside archive) rOr|ÚsymlinkrÜr%rcráÚlinkr¾rÄÚsymlink_exceptionr…r )rƒr×rÍr5r5r6rË”s    zTarFile.makelinkcCsØttdƒrÔt ¡dkrÔ|j}|j}|s‚ytrttdƒr:yt ||j¡Wntk r8tdƒ‚YnXdS)Nr»zcould not change mode)rr|r»rhrŸr )rƒr×rÍr5r5r6r»Ès  z TarFile.chmodcCsHttdƒsdSyt ||j|jf¡Wntk rBtdƒ‚YnXdS)Nrºz"could not change modification time)rr|rºr(rŸr )rƒr×rÍr5r5r6rºÑs  z TarFile.utimec Csæ| d¡|jdk r$|j}d|_|S|j|j ¡krZ|j |jd¡|j d¡sZtdƒ‚d}xby|j  |¡}WnHt k rÂ}z0|j r²|  dd|j|f¡|jt 7_wbWdd}~XYnütk r,}zL|j r|  dd|j|f¡|jt 7_wbn|jdkrtt|ƒƒ‚Wdd}~XYn’tk rT|jdkrPtdƒ‚Ynjtk rŽ}z|jdkr~tt|ƒƒ‚Wdd}~XYn0tk r¼}ztt|ƒƒ‚Wdd}~XYnXPqbW|dk rÜ|j |¡nd|_|S) NZrar#zunexpected end of datar$z0x%X: %srz empty fileT)r‡rnrÀr“r´rµrZrr×r(rvrgr¬r»rHrÿrtrurwrkr·rl)rƒÚmr×ror5r5r6r2ÜsL        z TarFile.nextcCsn| ¡}|dk r"|d| |¡…}|r2tj |¡}x6t|ƒD]*}|rTtj |j¡}n|j}||kr<|SqzShow listing of a tarfile)Úmetavarròz-ez --extractú+)z z zExtract tarfile into target dir)Únargsrôròz-cz--create)zzzCreate tarfile from sourcesz-tz--testzTest if a tarfile is validry)rçz{!r} is a tar archive.r#z{!r} is not a tar archive. zr:*)rªr$)r%r²z{!r} file is extracted.z+{!r} file is extracted into {!r} directory.r‹rrŒ)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:rzz{!r} file created.)ÚargparseÚArgumentParserÚ add_argumentÚadd_mutually_exclusive_groupÚ parse_argsZtestrrr‰rormrèrªrPÚexitrBrr¶r/r|ÚcurdirÚ format_helpr½ZcreateÚpopr%Úsplitextr¯)r÷rîÚparserr8Úargsr\rŽZtfrýrêZtar_nameÚ_ZextZ compressionsZtar_modeZ tar_filesÚ file_namer5r5r6Úmain“ s†                     rÚ__main__)^ÚversionÚ __author__Ú __credits__Úbuiltinsrrdrmr|rÇrWrfr¨rSrûr6r£r—r¥ÚAttributeErrorÚNotImplementedErrorrÙrŸÚ NameErrorÚ__all__r0r»rƒrõrðròrñrrârrPrNrRrTrærVZCONTTYPErør÷rrrr+r rrrr/rLr rIr=rþrErJr„r Úgetfilesystemencodingr7r<rKrQrVrXrgrpÚ Exceptionrr rrr r rtrurvrHrwrxr‡Úobjectrr¿ÚBufferedReaderrÒrrrrrqr5r5r5r6Ú sò         wh   W