zfc @sGdZdZdZdZdZdZdZddlmZ dd l Z dd l Z dd l Z dd l Z dd lZdd lZdd lZdd lZdd lZdd lZydd lZdd lZWnek reZZnXd d d d gZdZdZedZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,d Z-d!Z.d"Z/d#Z0d$Z1d%Z2e1Z3e!e"e#e$e'e(e)e%e&e*e+e,f Z4e!e"e)e,fZ5e*e+e,fZ6d&d'd(d)d*d+d,d-fZ7ie8d.6e8d/6e8d)6e9d*6e9d+6e9d(6Z:d0Z;d1Z<d2Z=d3Z>d4Z?d5Z@d6ZAd7ZBdZCd8ZDd9ZEd:ZFd;ZGd<ZHd=ZId>ZJd%ZKd$ZLe jMZNeNekre jOZNnd?ZPd@ZQdAZRd=e3dBZSdCZTdDZUedEZVe;dFfe<dGfe=dHfe>dIfe?dJfe@dKffeDdLffeEdMffeFeABdNfeAdfeFd ffeGdLffeHdMffeIeBBdNfeBdfeId ffeJdLffeKdMffeLeCBdOfeCdPfeLd fff ZWdQZXd eYfdRYZZdSeZfdTYZ[dUeZfdVYZ\dWeZfdXYZ]dYeZfdZYZ^d[eZfd\YZ_d]e_fd^YZ`d_e_fd`YZadae_fdbYZbdce_fddYZcdee_fdfYZddgfdhYZedifdjYZfdkegfdlYZhdmegfdnYZidoegfdpYZjdqegfdrYZkd egfdsYZld egfdtYZmdufdvYZndwfdxYZodyeofdzYZpd{eofd|YZqd}erfd~YZsd#Ztd=ZudfdYZvdZwemjZd S(s,Read from and write to tar format archives. s$Revision: 85213 $s0.9.0s!Lars Gustbel (lars@gustaebel.de)s$Date$s$Id$s3Gustavo Niemeyer, Niels Gustbel, Richard Townsend.i(topenNtTarFiletTarInfot is_tarfiletTarErrorsiisustar sustar00idit0t1t2t3t4t5t6t7tLtKtStxtgtXiiitpathtlinkpathtsizetmtimetuidtgidtunametgnametatimetctimeiii`i@i iiiiii@i iiicCs|| |t|tS(s@Convert a python string to a null-terminated string buffer. (tlentNUL(tstlength((s/usr/lib64/python2.7/tarfile.pytstnscCs'|jd}|dkr|S|| S(s?Convert a null-terminated string field to a python string. si(tfind(Rtp((s/usr/lib64/python2.7/tarfile.pytntss cCs|dtdkr^y%tt|jp1dd}Wqtk rZtdqXnId}x@tt|dD](}|dK}|t||d7}q{W|S(s/Convert a number field to a python number. iiRisinvalid headerli( tchrtintR$tstript ValueErrortInvalidHeaderErrortxrangeRtord(Rtnti((s/usr/lib64/python2.7/tarfile.pytntis%  cCsd|kod|dknr?d|d|ft}n|tks_|d|dkrntdn|dkrtjdtjd|d}nd }x6t|dD]$}t|d @|}|dL}qWtd |}|S( s/Convert a python number to a number field. iiis%0*oisoverflow in number fieldR tltii(Rt GNU_FORMATR(tstructtunpacktpackR*R%(R,tdigitstformatRR-((s/usr/lib64/python2.7/tarfile.pytitns $  %cCs|dkry|j|dSWqtk rg}xU|D]M}y|j|j|dWq=tk r|j|jdq=Xq=Wdj|SXn|j||SdS(s*Convert a unicode object to a string. sutf-8tstricttutf8R0N(tencodetUnicodeEncodeErrortappendtjoin(RtencodingterrorsRtc((s/usr/lib64/python2.7/tarfile.pytutss    cCsxdttjd|d tjd|dd!}dttjd|d tjd|dd!}||fS( sCalculate 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. it148Bit356Biit148bt356b(tsumR2R3(tbuftunsigned_chksumt signed_chksum((s/usr/lib64/python2.7/tarfile.pyt calc_chksumss 77cCs|dkrdS|dkr0tj||dSd}t||\}}xQt|D]C}|j|}t||krtdn|j|qXW|dkr|j|}t||krtdn|j|ndS(sjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. iNiisend of file reachedi@( tNonetshutilt copyfileobjtdivmodR*treadRtIOErrortwrite(tsrctdstR tBUFSIZEtblockst remaindertbRG((s/usr/lib64/python2.7/tarfile.pyRMs$   R/t-RWtdR@R#trtwRtttTcCsig}xStD]K}xB|D]-\}}||@|kr|j|PqqW|jdq Wdj|S(scConvert a file's mode to a string of the form -rwxrwxrwx. Used by TarFile.list() RXR0(tfilemode_tableR<R=(tmodetpermttabletbittchar((s/usr/lib64/python2.7/tarfile.pytfilemode7s  cBseZdZRS(sBase exception.(t__name__t __module__t__doc__(((s/usr/lib64/python2.7/tarfile.pyRFst ExtractErrorcBseZdZRS(s%General exception for extract errors.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRhIst ReadErrorcBseZdZRS(s&Exception for unreadable tar archives.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRiLstCompressionErrorcBseZdZRS(s.Exception for unavailable compression methods.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRjOst StreamErrorcBseZdZRS(s=Exception for unsupported operations on stream-like TarFiles.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRkRst HeaderErrorcBseZdZRS(s!Base exception for header errors.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRlUstEmptyHeaderErrorcBseZdZRS(sException for empty headers.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRmXstTruncatedHeaderErrorcBseZdZRS(s Exception for truncated headers.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRn[stEOFHeaderErrorcBseZdZRS(s"Exception for end of file headers.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRo^sR)cBseZdZRS(sException for invalid headers.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyR)astSubsequentHeaderErrorcBseZdZRS(s3Exception for missing and invalid extended headers.(ReRfRg(((s/usr/lib64/python2.7/tarfile.pyRpdst _LowLevelFilecBs2eZdZdZdZdZdZRS(sLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. cCsgitjd6tjtjBtjBd6|}ttdrK|tjO}ntj||d|_dS(NRZR[tO_BINARYi( tostO_RDONLYtO_WRONLYtO_CREATtO_TRUNCthasattrRrRtfd(tselftnameR_((s/usr/lib64/python2.7/tarfile.pyt__init__qs cCstj|jdS(N(RstcloseRy(Rz((s/usr/lib64/python2.7/tarfile.pyR}zscCstj|j|S(N(RsRORy(RzR((s/usr/lib64/python2.7/tarfile.pyRO}scCstj|j|dS(N(RsRQRy(RzR((s/usr/lib64/python2.7/tarfile.pyRQs(ReRfRgR|R}RORQ(((s/usr/lib64/python2.7/tarfile.pyRqks   t_StreamcBseZdZdZdZdZdZdZdZdZ dZ d d Z dd Z d Zd ZRS(sClass 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. cCst|_|dkr0t||}t|_n|dkrWt|}|j}n|p`d|_||_||_ ||_ ||_ d|_ d|_ t|_y|dkr)yddl}Wntk rtdnX||_|jdd@|_|d kr|jq|jnu|d kryddl}Wntk rdtd nX|d krd|_|j|_q|j|_nWn,|js|j jnt|_nXdS( s$Construct a _Stream object. t*R0ltgziNszlib module is not availablelRZtbz2sbz2 module is not available(tTruet _extfileobjRKRqtFalset _StreamProxyt getcomptypeR{R_tcomptypetfileobjtbufsizeRGtpostclosedtzlibt ImportErrorRjtcrc32tcrct _init_read_gzt_init_write_gzRtdbuftBZ2Decompressortcmpt BZ2CompressorR}(RzR{R_RRRRR((s/usr/lib64/python2.7/tarfile.pyR|sP                        cCs*t|dr&|j r&|jndS(NR(RxRR}(Rz((s/usr/lib64/python2.7/tarfile.pyt__del__scCs|jjd|jj|jj |jjd|_tjdtt j }|j d|t |j t kr|j jdd|_ n|j jdr|j d |_ n|j |j td S( s6Initialize for writing with gzip compression. i is(t __class__ReR{tid(Rz((s/usr/lib64/python2.7/tarfile.pyt__repr__scCs i |jd6|jd@d6|jd6|jd6|jd6|jd6|jd6|jd 6|jd 6|j d 6|j d 6|j d 6|j d6}|d t kr|djd r|dcd7R?tinfotkey((s/usr/lib64/python2.7/tarfile.pytget_infos(            $ !R8cCss|j||}|tkr+|j|S|tkrD|j|S|tkrc|j|||StddS(s<Return a tar header as a string of 512 byte blocks. sinvalid formatN(Rt USTAR_FORMATtcreate_ustar_headerR1tcreate_gnu_headert PAX_FORMATtcreate_pax_headerR((RzR6R>R?R((s/usr/lib64/python2.7/tarfile.pyttobufs     cCsyt|dn||j||}y|jd Wntk r|||nXt|||kr>|||q>WxddddfD]\}} ||kr d||R?RR{thnameR tvalR5RG((s/usr/lib64/python2.7/tarfile.pyRs6       4cCs|j|dtS(sAReturn the object as a pax global header block sequence. R(RtXGLTYPE(tclsR((s/usr/lib64/python2.7/tarfile.pytcreate_pax_global_headerDscCs|td }x$|r4|ddkr4|d }qW|t|}|d }| sht|tkrwtdn||fS(sUSplit a name longer than 100 chars into a prefix and a name part. iiRsname is too long(t LENGTH_PREFIXRRR((RzR{R((s/usr/lib64/python2.7/tarfile.pyRJs cCst|jdddt|jddd@d|t|jddd|t|jd dd|t|jd dd |t|jd dd |d |jdtt|jdddt|jdtdt|jdddt|jdddt|jddd|t|jddd|t|jdddg}tjdtdj|}t |t d}|d d||d}|S(sReturn a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants. R{R0idR_iiiRRRi Rs RRRRi RRRRis%dsis%06oi( R!tgetR7RRR2R4RR=RJ(RR6tpartsRGR((s/usr/lib64/python2.7/tarfile.pyRYs&cCs@tt|t\}}|dkr<|t|t7}n|S(sdReturn the string payload filled with zero bytes up to the next 512 byte border. i(RNRRR(tpayloadRURV((s/usr/lib64/python2.7/tarfile.pyt_create_payloadus cCs[|t7}i}d|d<||d|j|S|jtttfkrc|j |S|j |SdS(sYChoose the right processing method depending on the type and call it. N( RRRt _proc_gnulongtGNUTYPE_SPARSEt _proc_sparsetXHDTYPERtSOLARIS_XHDTYPEt _proc_paxt _proc_builtin(RzR((s/usr/lib64/python2.7/tarfile.pyRs   cCsx|jj|_|j}|js6|jtkrO||j|j7}n||_|j |j |j |j |S(sfProcess a builtin type or an unknown type which will be treated as a regular file. ( RRRtisregRtSUPPORTED_TYPESt_blockRRt_apply_pax_infoRR>R?(RzRR((s/usr/lib64/python2.7/tarfile.pyRs  cCs|jj|j|j}y|j|}Wntk rPtdnX|j|_|jt kr~t ||_ n!|jt krt ||_ n|S(sSProcess the blocks that hold a GNU longname or longlink member. s missing or bad subsequent header(RROR RRRlRpRRRR$R{RR(RzRRGtnext((s/usr/lib64/python2.7/tarfile.pyRs  c Css|j}t}d}d}d}xtdD]}y6t|||d!}t||d|d!} Wntk rPnX||kr|jt|||n|jt|| ||| 7}|| }|d7}q1Wt|d} t|dd!} x| d kr|j j t }d }xtd D]}y6t|||d!}t||d|d!} Wntk rPnX||kr|jt|||n|jt|| ||| 7}|| }|d7}q=Wt|d } q W|| kr/|jt|| |n||_ |j j |_|j|j|j|_| |_|S( s8Process a GNU sparse header plus extra headers. ilii iiiiiiii(RGt _ringbufferR*R.R(R<t_holeRR+RRORRRRR RR( RzRRGtspRtlastposRR-Rtnumbytest isextendedtorigsize((s/usr/lib64/python2.7/tarfile.pyR'sT             c Cs|jj|j|j}|jtkr9|j}n|jj}tj dtj }d}xt r!|j ||}|sPn|j \}}t|}|dkrtdn||jdd|jd|d!} |jd}| jd} | ||<||7}qfWy|j|} Wntk rTtdnX|jttfkr| j||j|j|j| _d|kr| j} | js| jtkr| | j| j7} n| |_qn| S( sVProcess an extended or global header as described in POSIX.1-2001. s(\d+) ([^=]+)=isinvalid headeriiR9s missing or bad subsequent headerR(RROR RRRRRtretcompiletURtmatchtgroupsR&R)tendtstartRRRlRpRRR!R>R?RRRR( RzRRGRtregexRR-R R R R"R((s/usr/lib64/python2.7/tarfile.pyR_s@    +     cCsx|jD]\}}|tkr+q n|dkrI|jd}n|tkryt||}Wqtk rd}qXnt|||}t|||q W|j|_dS(soReplace fields with supplemental information from a previous pax extended or global header. RRiN( R t PAX_FIELDSRtPAX_NUMBER_FIELDSR(RAtsetattrRR(RzRR>R?R R ((s/usr/lib64/python2.7/tarfile.pyR!s     cCs0t|t\}}|r(|d7}n|tS(s_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. i(RNR(RzRRURV((s/usr/lib64/python2.7/tarfile.pyR s cCs |jtkS(N(Rt REGULAR_TYPES(Rz((s/usr/lib64/python2.7/tarfile.pyRscCs |jS(N(R(Rz((s/usr/lib64/python2.7/tarfile.pytisfilescCs |jtkS(N(RR(Rz((s/usr/lib64/python2.7/tarfile.pyRscCs |jtkS(N(RtSYMTYPE(Rz((s/usr/lib64/python2.7/tarfile.pytissymscCs |jtkS(N(RtLNKTYPE(Rz((s/usr/lib64/python2.7/tarfile.pytislnkscCs |jtkS(N(RtCHRTYPE(Rz((s/usr/lib64/python2.7/tarfile.pytischrscCs |jtkS(N(RtBLKTYPE(Rz((s/usr/lib64/python2.7/tarfile.pytisblkscCs |jtkS(N(RtFIFOTYPE(Rz((s/usr/lib64/python2.7/tarfile.pytisfifoscCs |jtkS(N(RR(Rz((s/usr/lib64/python2.7/tarfile.pytissparsescCs|jtttfkS(N(RR;R=R?(Rz((s/usr/lib64/python2.7/tarfile.pytisdevs(/ReRfRgR|RRtpropertyRRRRRRtDEFAULT_FORMATtENCODINGRRRRt classmethodRRt staticmethodRRRRRRRRRRRRR!R RR6RR8R:R<R>R@RARB(((s/usr/lib64/python2.7/tarfile.pyRsP         3  .   8 <          c BsHeZdZdZeZeZdZeZ e Z d2Z eZeZd2dd2d2d2d2d2d2d2d2d2d2d ZdZdZeeeZed2dd2edZedd2dZedd2d d Zedd2d d Zid d 6dd6dd6ZdZdZdZ dZ!d2d2d2dZ"e#dZ$d2e#d2d2dZ%d2dZ&dd2dZ'ddZ(dZ)dZ*d Z+d!Z,d"Z-d#Z.d$Z/d%Z0d&Z1d'Z2d(Z3d)Z4d2ed*Z5d+Z6d2d,Z7d-Z8d.Z9d/Z:d0Z;d1Z<RS(3s=The TarFile Class provides an interface to tar archives. iiRZc Csidd6dd6dd6} || kr6tdn||_| ||_|s|jdkrtjj| rd|_d|_nt||j}t|_nN|d krt |dr|j }nt |d r|j|_nt |_|r tjj |nd |_ ||_|d k r7||_n|d k rO||_n|d k rg||_n|d k r||_n|d k r||_n| d k r| |_n!|dkrd |_n d |_| d k r|jtkr| |_n i|_| d k r| |_n| d k r0| |_nt|_g|_t|_|jj|_i|_y9|jdkrd |_|j |_n|jdkr7xt r3|jj!|jy&|jj"|}|jj#|Wqt$k r |jj!|jPqt%k r/}t&t'|qXqWn|jd krt |_|jr|jj(|jj)}|jj*||jt+|7_qnWn,|js|jj,nt |_nXd S(sOpen 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. trbRZsr+btatwbR[smode must be 'r', 'a' or 'w'R{R_sutf-8R8tawN(-R(R_t_modeRsRtexistst bltn_openRRRKRxR{RtabspathRR6Rt dereferencet ignore_zerosR>R?RRtdebugt errorlevelRtmemberst_loadedRRtinodest firstmemberR"RRR<RoRlRiR RRRQRR}(RzR{R_RR6RRPRQR>R?RRRRStmodesteRG((s/usr/lib64/python2.7/tarfile.pyR|s    "     !                                 cCs |jtkS(N(R6R(Rz((s/usr/lib64/python2.7/tarfile.pyt _getposixRscCs>ddl}|jdtd|r1t|_n t|_dS(Nis use the format attribute insteadi(twarningstwarntDeprecationWarningRR6R1(RzR R[((s/usr/lib64/python2.7/tarfile.pyt _setposixTs    c sO| r| rtdn|dkrfd}xtjd|D]}tj|}|dk r|j} ny||d||SWqNttfk r} |dk rN|j| qNqNqNXqNWtdnUd|krq|j dd\} }| pd} |p#d }|jkrNtj|}ntd |||| ||Sd |kr|j d d\} }| pd} |pd }| dkrtd nt || |||} y|| | |} Wn| j nXt | _ | S|dkr?j||||StddS(s|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 '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 '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 '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 snothing to openRZsr:*csj|dkS(Nttaropen(t OPEN_METH(R(R(s/usr/lib64/python2.7/tarfile.pytnot_compressedsRs%file could not be opened successfullyt:iRsunknown compression type %rt|R[smode must be 'r' or 'w'RIsundiscernible modeN(RZsr:*(RZR[(RIR[(R(tsortedR`RRKRRiRjRtsplitR~R}RRR_(RR{R_RRtkwargsRaRtfunct saved_posRYRdtstreamR\((Rs/usr/lib64/python2.7/tarfile.pyRisP              cKs.|dkrtdn|||||S(sCOpen uncompressed tar archive name for reading or writing. RZRIR[smode must be 'r', 'a' or 'w'(RZRIR[(R((RR{R_RRf((s/usr/lib64/python2.7/tarfile.pyR_s i cKs*|dkrtdnyddl}|jWn#ttfk rWtdnXy|j||||}Wn;tk r|dk r|dkrtdnnXy|j ||||}WnLt k r |j |dkrtdnn|j nXt |_ |S( skOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. RZR[smode must be 'r' or 'w'iNsgzip module is not availablesnot a gzip file(RZR[(R(tgziptGzipFileRtAttributeErrorRjtOSErrorRKRiR_RPR}RR(RR{R_Rt compresslevelRfRjR\((s/usr/lib64/python2.7/tarfile.pytgzopens2         cKs|d krtdnyddl}Wntk rJtdnX|dk rit||}n|j||d|}y|j||||}WnRtt fk r|j |dkrt dnn|j nXt |_ |S( slOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. RZR[smode must be 'r' or 'w'.iNsbz2 module is not availableRnsnot a bzip2 file(RZR[(R(RRRjRKRtBZ2FileR_RPtEOFErrorR}RiRR(RR{R_RRnRfRR\((s/usr/lib64/python2.7/tarfile.pytbz2opens*       R_RRoRRrRcCs|jr dSt|_z|jdkr|jjttd|jtd7_t|jt \}}|dkr|jjtt |qnWd|j s|jj nXdS(slClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NRKii( RRR_RRQRRRRNt RECORDSIZERR}(RzRURV((s/usr/lib64/python2.7/tarfile.pyR} s   " cCs2|j|}|dkr.td|n|S(sReturn 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. sfilename %r not foundN(t _getmemberRKtKeyError(RzR{R((s/usr/lib64/python2.7/tarfile.pyt getmembers cCs'|j|js |jn|jS(sReturn the members of the archive as a list of TarInfo objects. The list has the same order as the members in the archive. (t_checkRUt_loadRT(Rz((s/usr/lib64/python2.7/tarfile.pyt getmembers*s   cCs g|jD]}|j^q S(sReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). (RyR{(RzR((s/usr/lib64/python2.7/tarfile.pytgetnames4sc Cs\|jd|d k r%|j}n|d kr:|}ntjj|\}}|jtjd}|jd}|j }||_ |d krt tdr|j rtj |}qtj|}ntj|j}d}|j}tj|r|j|jf} |j rj|jdkrj| |jkrj||j| krjt} |j| }qt} | dr||j| slink toN(RwRdR_RRRRR<R>RRRRt localtimeRR{RR8RR:(RztverboseR((s/usr/lib64/python2.7/tarfile.pytlists&      c Cs|jd|dkr"|}n|dk rtddl}|jdtd||rt|jdd|dSn|jdk rtjj ||jkr|jdd|dS|jd||j ||}|dkr|jdd |dS|dk r;||}|dkr;|jdd|dSn|j rrt |d }|j ||WdQXn|jr|j ||rxQtj|D]=}|jtjj||tjj|||||qWqn |j |dS( s~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. `exclude' is a function that should return True for each filename to be excluded. `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. RKiNsuse the filter argument insteadistarfile: Excluded %rstarfile: Skipped %ristarfile: Unsupported type %rRH(RwRKR[R\R]t_dbgR{RsRRORRRNtaddfileRtlistdirtaddR=( RzR{Rt recursivetexcludetfilterR[Rtf((s/usr/lib64/python2.7/tarfile.pyRsB        *       *cCs|jdtj|}|j|j|j|j}|jj||jt |7_|dk rt ||j|j t |j t\}}|dkr|jjtt||d7}n|j|t7_n|jj|dS(smAdd the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size. RKiiN(RwRRR6R>R?RRQRRRKRMRRNRRRTR<(RzRRRGRURV((s/usr/lib64/python2.7/tarfile.pyRs    t.cCs3g}|dkr|}nxR|D]J}|jr\|j|tj|}d|_n|j||q"W|jdtjd|j x|D]}t j j ||j }y4|j|||j|||j||Wqtk r*}|jdkrq+|jdd|qXqWdS(sMExtract 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(). iRR{is tarfile: %sN(RKRR<RR_textracttsorttoperatort attrgettertreverseRsRR=R{tchowntutimetchmodRhRSR(RzRRTt directoriesRtdirpathRY((s/usr/lib64/python2.7/tarfile.pyt extractalls*        R0cCs7|jdt|tr.|j|}n|}|jr^tjj||j|_ ny&|j |tjj||j Wnt k r}|j dkrq3|jdkr|jdd|jq3|jdd|j|jfn<tk r2}|j dkrq3|jdd|nXdS(s#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'. RZiis tarfile: %sstarfile: %s %rN(RwRt basestringRvR:RsRR=Rt _link_targett_extract_memberR{tEnvironmentErrorRStfilenameRKRtstrerrorRh(RztmemberRRRY((s/usr/lib64/python2.7/tarfile.pyR6s$  &#cCs|jdt|tr.|j|}n|}|jrP|j||S|jtkro|j||S|js|j rt|j t rt dq|j |j|SndSdS(sExtract a member from the archive as a file object. `member' may be a filename or a TarInfo object. If `member' is a regular file, a file-like object is returned. If `member' is a link, a file-like object is constructed from the link's target. If `member' is none of the above, None is returned. The file-like object is read-only and provides the following methods: read(), readline(), readlines(), seek() and tell() RZs'cannot extract (sym)link as file objectN(RwRRRvRt fileobjectRRR:R8RR~Rkt extractfilet_find_link_targetRK(RzRR((s/usr/lib64/python2.7/tarfile.pyRWs  cCs|jd}|jdtj}tjj|}|r_tjj| r_tj|n|jsw|j r|j dd|j |j fn|j d|j |j r|j||n|jr|j||n|jr |j||n|js"|jr5|j||n]|jsM|j r`|j||n2|jtkr|j||n|j|||j|||j s|j|||j||ndS(s\Extract the TarInfo object tarinfo to a physical file called targetpath. Ris%s -> %sN(RRRsRRtdirnameRMtmakedirsR:R8RR{RRtmakefileRtmakedirR@tmakefifoR<R>tmakedevtmakelinkRRt makeunknownRRR(RzRt targetpatht upperdirs((s/usr/lib64/python2.7/tarfile.pyR}s2#    cCsFytj|dWn+tk rA}|jtjkrBqBnXdS(s,Make a directory called targetpath. iN(RstmkdirRterrnotEEXIST(RzRRRY((s/usr/lib64/python2.7/tarfile.pyRs cCsJ|j|}z)t|d}t||WdQXWd|jXdS(s'Make a file called targetpath. RJN(RRNRMR}(RzRRtsourcettarget((s/usr/lib64/python2.7/tarfile.pyRs cCs+|j|||jdd|jdS(sYMake a file from a TarInfo object with an unknown type at targetpath. is9tarfile: Unknown file type %r, extracted as regular file.N(RRR(RzRR((s/usr/lib64/python2.7/tarfile.pyRs cCs/ttdrtj|n tddS(s'Make a fifo called targetpath. tmkfifosfifo not supported by systemN(RxRsRRh(RzRR((s/usr/lib64/python2.7/tarfile.pyRscCsttd s ttd r/tdn|j}|jrT|tjO}n |tjO}tj||tj |j |j dS(s<Make a character or block device called targetpath. tmknodRs'special devices not supported by systemN( RxRsRhR_R>RtS_IFBLKtS_IFCHRRRRR(RzRRR_((s/usr/lib64/python2.7/tarfile.pyRs     cCs ttdrttdr|jrbtjj|rLtj|ntj|j|qtjj|j rtjj|rtj|ntj |j |q|j |j ||n=y|j |j ||Wnt k rtdnXdS(sMake 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. tsymlinktlinks%unable to resolve link inside archiveN(RxRsR8RtlexiststunlinkRRRMRRRRRuRh(RzRR((s/usr/lib64/python2.7/tarfile.pyRs  cCstrttdrtjdkrytj|jd}Wntk r]|j}nXytj |j d}Wntk r|j }nXyZ|j rttdrtj |||n%tjdkrtj|||nWqtk r}tdqXndS(s6Set owner of targetpath according to tarinfo. tgeteuidiitlchowntos2emxscould not change ownerN(RRxRsRRtgetgrnamRRuRtgetpwnamRRR8RtsystplatformRRRh(RzRRRtuRY((s/usr/lib64/python2.7/tarfile.pyRs '    cCsOttdrKytj||jWqKtk rG}tdqKXndS(sASet file permissions of targetpath according to tarinfo. Rscould not change modeN(RxRsRR_RRh(RzRRRY((s/usr/lib64/python2.7/tarfile.pyR s cCsYttdsdSy tj||j|jfWntk rT}tdnXdS(sBSet modification time of targetpath according to tarinfo. RNs"could not change modification time(RxRsRRRRh(RzRRRY((s/usr/lib64/python2.7/tarfile.pyR s  cCs%|jd|jdk r2|j}d|_|S|j|jjkr|jj|jd|jjdstdqnd}xkt ry|j j |}WnGt k r}|j r|jdd|j|f|jt7_qqntk rk}|j rD|jdd|j|f|jt7_qq|jdkrtt|qntk r|jdkrtdqn[tk r}|jdkrtt|qn%tk r}tt|nXPqW|dk r|jj|n t |_|S( sReturn the next member of the archive as a TarInfo object, when TarFile is opened for reading. Return None if there is no more available. traisunexpected end of datais0x%X: %sis empty fileN(RwRWRKRRRRRORiRRRRoRQRRR)R RmRnRpRTR<RU(RztmRRY((s/usr/lib64/python2.7/tarfile.pyR"# sL          cCs|j}|dk r.||j| }n|rItjj|}nxKt|D]=}|rztjj|j}n |j}||krV|SqVWdS(s}Find an archive member by name from bottom to top. If tarinfo is given, it is used as the starting point. N(RyRKtindexRsRtnormpathtreversedR{(RzR{Rt normalizeRTRt member_name((s/usr/lib64/python2.7/tarfile.pyRtY s    cCs6x&tr(|j}|dkrPqqWt|_dS(sWRead through the entire archive file and look for readable members. N(RR"RKRU(RzR((s/usr/lib64/python2.7/tarfile.pyRxp s    cCsW|jr"td|jjn|dk rS|j|krStd|jndS(snCheck if TarFile is still open, and if the operation's mode corresponds to TarFile's mode. s %s is closedsbad operation for mode %rN(RRPRReRKR_(RzR_((s/usr/lib64/python2.7/tarfile.pyRwz s cCs|jrEdjtdtjj|j|jf}d}n|j}|}|j |d|dt }|dkrt d|n|S(sZFind the target member of a symlink or hardlink member in the archive. RRRslinkname %r not foundN( R8R=RRKRsRRR{RRtRRu(RzRRtlimitR((s/usr/lib64/python2.7/tarfile.pyR s 0   cCs$|jrt|jSt|SdS(s$Provide an iterator object. N(RUtiterRTtTarIter(Rz((s/usr/lib64/python2.7/tarfile.pyR s  cCs#||jkrtj|IJndS(s.Write debugging output to sys.stderr. N(RRRtstderr(Rztleveltmsg((s/usr/lib64/python2.7/tarfile.pyR scCs|j|S(N(Rw(Rz((s/usr/lib64/python2.7/tarfile.pyt __enter__ s cCs?|dkr|jn"|js2|jjnt|_dS(N(RKR}RRRR(RzRR t traceback((s/usr/lib64/python2.7/tarfile.pyt__exit__ s    N(=ReRfRgRRRRPRQRSRDR6RER>RKR?RRRRR|RZR^RCtposixRFRsRR_RoRrR`R}RvRyRzRRRRRRRRRRRRRRRRRRR"RtRxRwRRRRR(((s/usr/lib64/python2.7/tarfile.pyRst  e   M!   c = % ! & /      6    RcBs)eZdZdZdZdZRS(sMIterator Class. for tarinfo in TarFile(...): suite... cCs||_d|_dS(s$Construct a TarIter object. iN(RR(RzR((s/usr/lib64/python2.7/tarfile.pyR| s cCs|S(s Return iterator object. ((Rz((s/usr/lib64/python2.7/tarfile.pyR scCs|jdkr3|jjdk r3|jj}np|jt|jjkrd|jj|j}n?|jjs|jj}|st|j_t qnt |jd7_|S(sReturn the next item using TarFile's next() method. When all members have been read, set TarFile as _loaded. iiN( RRRWRKR"RRTRURt StopIteration(RzR((s/usr/lib64/python2.7/tarfile.pyR" s!   (ReRfRgR|RR"(((s/usr/lib64/python2.7/tarfile.pyR s  t_sectioncBs eZdZdZdZRS(s$Base class for _data and _hole. cCs||_||_dS(N(RR(RzRR((s/usr/lib64/python2.7/tarfile.pyR| s cCs%|j|ko"|j|jkSS(N(RR(RzR((s/usr/lib64/python2.7/tarfile.pyt __contains__ s(ReRfRgR|R(((s/usr/lib64/python2.7/tarfile.pyR s RcBseZdZdZRS(s/Represent a data section in a sparse file. cCs tj|||||_dS(N(RR|R(RzRRR((s/usr/lib64/python2.7/tarfile.pyR| s(ReRfRgR|(((s/usr/lib64/python2.7/tarfile.pyR sR$cBseZdZRS(s/Represent a hole section in a sparse file. (ReRfRg(((s/usr/lib64/python2.7/tarfile.pyR$ sR#cBs eZdZdZdZRS(sMRingbuffer class which increases performance over a regular list. cCs d|_dS(Ni(tidx(Rz((s/usr/lib64/python2.7/tarfile.pyR| scCsu|j}x\trg||}||kr,Pn|d7}|t|krQd}n||jkr dSq W||_|S(Nii(RRRRK(RzRRtitem((s/usr/lib64/python2.7/tarfile.pyR" s       (ReRfRgR|R"(((s/usr/lib64/python2.7/tarfile.pyR# s t TarFileCompatcBsteZdZdedZdZdZdZdZdZ dZ d d d Z d Z d ZRS( sRTarFile class compatible with standard module zipfile's ZipFile class. RZcCsddlm}|ddd|tkrDtj|||_n0|tkrhtj|||_n td|dd!d kr|jj }xB|D]7}|j |_ |j |_ tj|jd |_qWndS( Ni(twarnpy3ks6the TarFileCompat class has been removed in Python 3.0t stacklevelisunknown compression constantiiRZi(R[Rt TAR_PLAINRR_Rt TAR_GZIPPEDRoR(RyR{RRt file_sizeRtgmtimeRt date_time(RztfileR_t compressionRRTR((s/usr/lib64/python2.7/tarfile.pyR| s       cCstd|jS(NcSs|jS(N(R{(R((s/usr/lib64/python2.7/tarfile.pyt R0(tmaptinfolist(Rz((s/usr/lib64/python2.7/tarfile.pytnamelist scCstd|jjS(NcSs |jtkS(N(RR5(R((s/usr/lib64/python2.7/tarfile.pyR R0(RRRy(Rz((s/usr/lib64/python2.7/tarfile.pyR s cCs|jjdS(N(RR(Rz((s/usr/lib64/python2.7/tarfile.pytprintdir" scCsdS(N((Rz((s/usr/lib64/python2.7/tarfile.pyttestzip$ scCs|jj|S(N(RRv(RzR{((s/usr/lib64/python2.7/tarfile.pytgetinfo& scCs"|jj|jj|jS(N(RRRvRO(RzR{((s/usr/lib64/python2.7/tarfile.pyRO( scCs|jj||dS(N(RR(RzRRt compress_type((s/usr/lib64/python2.7/tarfile.pyRQ* scCsyddlm}Wn!tk r7ddlm}nXddl}t|j}t||_|j|j |_ |j j |||dS(Ni(tStringIO( t cStringIORRtcalendarRRRRttimegmRRRR(RztzinfotbytesRRttinfo((s/usr/lib64/python2.7/tarfile.pytwritestr, s  cCs|jjdS(N(RR}(Rz((s/usr/lib64/python2.7/tarfile.pyR}6 sN(ReRfRgRR|RRRRRRORKRQR R}(((s/usr/lib64/python2.7/tarfile.pyR s       cCs7yt|}|jtSWntk r2tSXdS(sfReturn True if name points to a tar archive that we are able to handle, else return False. N(RR}RRR(R{R\((s/usr/lib64/python2.7/tarfile.pyR= s    (xRgt __version__tversiont __author__t__date__t __cvsid__t __credits__t __builtin__RRNRRsRLRRRR2RR*RRRRRKt__all__RRRsRRRRRRRR9R7R;R=RR?tCONTTYPERRRRRRRR1RRDRR5RR2RR&R3tS_IFLNKtS_IFREGRtS_IFDIRRtS_IFIFOtTSUIDtTSGIDtTSVTXtTUREADtTUWRITEtTUEXECtTGREADtTGWRITEtTGEXECtTOREADtTOWRITEtTOEXECtgetfilesystemencodingREtgetdefaultencodingR!R$R.R7RARJRMR^Rdt ExceptionRRhRiRjRkRlRmRnRoR)RpRqR~tobjectRRRRRRRRRR$RR#RRRR(((s/usr/lib64/python2.7/tarfile.pyts.                                               AR7' 4