lJc@s)dZdZdZdZdZdZdZddkZddkZddk Z ddk Z ddk Z ddk Z ddk Z ddkZeid jo ed nyddkZddkZWnej oeZZnXd d d dgZdZdZedZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd Z(d!Z)eee e!e$e%e&e"e#e'e(e)f Z*eee&e)fZ+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3dZ4d*Z5d+Z6d,Z7d-Z8d.Z9d/Z:d0Z;d1Z<d2Z=d3Z>d4Z?d/e@d5ZAd6ZBed7ZCe,d8fe-d9fe.d:fe/d;fe0d<fe1d=ffe5d>ffe6d?ffe7e2Bd@fe2d!fe7dAffe8d>ffe9d?ffe:e3Bd@fe3d!fe:dAffe;d>ffe<d?ffe=e4BdBfe4dCfe=dAfff ZDdDZEeiFdEjo dFZGn eiHiGZGdeIfdGYZJdHeJfdIYZKdJeJfdKYZLdLeJfdMYZMdNeJfdOYZNdPfdQYZOdRfdSYZPdTeQfdUYZRdVeQfdWYZSdXeQfdYYZTdZeQfd[YZUd eQfd\YZVd eQfd]YZWd^fd_YZXd`fdaYZYdbeYfdcYZZddeYfdeYZ[dfe\fdgYZ]dhZ^d/Z_difdjYZ`dkZaeWibZbdS(ls,Read from and write to tar format archives. s$Revision: 53162 $s0.8.0s!Lars Gustbel (lars@gustaebel.de)s5$Date: 2006-12-27 21:36:58 +1100 (Wed, 27 Dec 2006) $s;$Id: tarfile.py 53162 2006-12-27 10:36:58Z lars.gustaebel $s3Gustavo Niemeyer, Niels Gustbel, Richard Townsend.iNtmacs'tarfile does not work for platform==mactTarFiletTarInfot is_tarfiletTarErrortiitustart00idilt0t1t2t3t4t5t6t7tLtKtSiii`i@i iiiiii@i iiiiicCs|| |t|tS(s@Convert a python string to a null-terminated string buffer. (tlentNUL(tstlength((s/sys/lib/python/tarfile.pytstnscCs|dtdjo't|itdpdd}nJd}x@tt|dD](}|dK}|t||d7}q[W|S(s/Convert a number field to a python number. iit Rili(tchrtinttrstripRtxrangeRtord(Rtnti((s/sys/lib/python/tarfile.pytntis' cCsd|jod|djnod|d|ft}n|otdn|djo&tidtid|d}nd}x6t|dD]$}t|d @|}|dL}qWtd |}|S( s/Convert a python number to a number field. iiis%0*osoverflow in number fieldRtltii(Rt ValueErrortstructtunpacktpackRR(RtdigitstposixRR((s/sys/lib/python/tarfile.pytitns & &c Csxdttid|d tid|dd!}dttid|d tid|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(tsumR$R%(tbuftunsigned_chksumt signed_chksum((s/sys/lib/python/tarfile.pyt calc_chksumss 77cCs|djodSn|djoti||dSnd}t||\}}xSt|D]E}|i|}t||jotdn|i|qbW|djoC|i|}t||jotdn|i|ndS(sjCopy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content. iNiisend of file reachedi@( tNonetshutilt copyfileobjtdivmodRtreadRtIOErrortwrite(tsrctdstRtBUFSIZEtblockst remaindertbR/((s/sys/lib/python/tarfile.pyR5s&    R!t-R?tdtctptrtwRtxtttTcCskg}xUtD]M}xD|D]/\}}||@|jo|i|PqqW|idq Wdi|S(scConvert a file's mode to a string of the form -rwxrwxrwx. Used by TarFile.list() R@R"(tfilemode_tabletappendtjoin(tmodetpermttabletbittchar((s/sys/lib/python/tarfile.pytfilemodes   t/cCstii|itidS(RR(tostpathtnormpathtreplacetsep(RT((s/sys/lib/python/tarfile.pytscBseZdZRS(sBase exception.(t__name__t __module__t__doc__(((s/sys/lib/python/tarfile.pyR st ExtractErrorcBseZdZRS(s%General exception for extract errors.(RYRZR[(((s/sys/lib/python/tarfile.pyR\st ReadErrorcBseZdZRS(s%Exception for unreadble tar archives.(RYRZR[(((s/sys/lib/python/tarfile.pyR]stCompressionErrorcBseZdZRS(s.Exception for unavailable compression methods.(RYRZR[(((s/sys/lib/python/tarfile.pyR^st StreamErrorcBseZdZRS(s=Exception for unsupported operations on stream-like TarFiles.(RYRZR[(((s/sys/lib/python/tarfile.pyR_st _LowLevelFilecBs2eZdZdZdZdZdZRS(sLow-level file object. Supports reading and writing. It is used instead of a regular file object for streaming access. cCsjhtid<titiBtiBd<|}ttdo|tiO}nti|||_dS(NRDREtO_BINARY( RStO_RDONLYtO_WRONLYtO_CREATtO_TRUNCthasattrRatopentfd(tselftnameRL((s/sys/lib/python/tarfile.pyt__init__%s cCsti|idS(N(RStcloseRh(Ri((s/sys/lib/python/tarfile.pyRl.scCsti|i|S(N(RSR7Rh(Ritsize((s/sys/lib/python/tarfile.pyR71scCsti|i|dS(N(RSR9Rh(RiR((s/sys/lib/python/tarfile.pyR94s(RYRZR[RkRlR7R9(((s/sys/lib/python/tarfile.pyR`s   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. c Cst|_|djot||}t|_n|djot|}|i}n|pd|_||_||_ ||_ ||_ d|_ d|_ t|_|djovyddk}Wntj otdnX||_|id|_|djo|iq-|in|d jonyddk}Wntj otd nX|djod|_|i|_q|i|_ndS( s$Construct a _Stream object. t*R"ltgziNszlib module is not availableRDtbz2sbz2 module is not available(tTruet _extfileobjR3R`tFalset _StreamProxyt getcomptypeRjRLtcomptypetfileobjtbufsizeR/tpostclosedtzlibt ImportErrorR^tcrc32tcrct _init_read_gzt_init_write_gzRqtdbuftBZ2Decompressortcmpt BZ2Compressor(RiRjRLRwRxRyR|Rq((s/sys/lib/python/tarfile.pyRkBsD                  cCs-t|do|i o|indS(NR{(RfR{Rl(Ri((s/sys/lib/python/tarfile.pyt__del__pscCs|iid|ii|ii |iid|_tidtt i }|i d||i i do|i d |_ n|i |i t dS(s6Initialize for writing with gzip compression. i isR((s/sys/lib/python/tarfile.pytseeks  cCs|djoSg}x7to/|i|i}|pPn|i|qWdi|}n|i|}|it|7_|S(sReturn the next size number of bytes from the stream. If size is not defined, return all bytes of the stream up to EOF. R"N(R3Rrt_readRyRJRKRzR(RiRmRGR/((s/sys/lib/python/tarfile.pyR7s  cCs|idjo|i|Snt|i}|ig}x_||joQ|i|i}|pPn|ii|}|i||t|7}q?Wdi|}|||_|| S(s+Return size bytes from the stream. RR"( RwRRRRyRt decompressRJRK(RiRmRBRGR/((s/sys/lib/python/tarfile.pyRs   cCst|i}|ig}xP||joB|ii|i}|pPn|i||t|7}qWdi|}|||_|| S(ssReturn size bytes from stream. If internal buffer is empty, read another block from the stream. R"(RR/RxR7RyRJRK(RiRmRBRGR/((s/sys/lib/python/tarfile.pyt__reads   N(RYRZR[RkRRR9RRlRRRR3R7RR(((s/sys/lib/python/tarfile.pyRn7s  .      RucBs2eZdZdZdZdZdZRS(ssSmall proxy class that enables transparent compression detection for the Stream interface (mode 'r|*'). cCs"||_|iit|_dS(N(RxR7t BLOCKSIZER/(RiRx((s/sys/lib/python/tarfile.pyRks cCs|ii|_|iS(N(RxR7R/(RiRm((s/sys/lib/python/tarfile.pyR7 scCs:|iidodSn|iidodSndS(NsRptBZh91RqR(R/t startswith(Ri((s/sys/lib/python/tarfile.pyRv$s cCs|iidS(N(RxRl(Ri((s/sys/lib/python/tarfile.pyRl+s(RYRZR[RkR7RvRl(((s/sys/lib/python/tarfile.pyRus    t _BZ2ProxycBsSeZdZd ZdZdZdZdZdZdZ d Z RS( sSmall proxy class that enables external file object support for "r:bz2" and "w:bz2" modes. This is actually a workaround for a limitation in bz2 module's BZ2File class which (unlike gzip.GzipFile) has no support for a file object argument. iicCs ||_||_|idS(N(RxRLtinit(RiRxRL((s/sys/lib/python/tarfile.pyRk9s  cCsdddk}d|_|idjo,|i|_|iidd|_n|i|_dS(NiiRDR"( RqRzRLRtbz2objRxRR/R(RiRq((s/sys/lib/python/tarfile.pyR>s   cCs|ig}t|i}xq||jocy8|ii|i}|ii|}|i|Wntj oPnX|t|7}qWdi ||_|i| }|i||_|i t|7_ |S(NR"( R/RRxR7t blocksizeRRRJtEOFErrorRKRz(RiRmR?RFtrawtdataR/((s/sys/lib/python/tarfile.pyR7Hs  cCs6||ijo|in|i||idS(N(RzRR7(RiRz((s/sys/lib/python/tarfile.pyRZscCs|iS(N(Rz(Ri((s/sys/lib/python/tarfile.pyR_scCs;|it|7_|ii|}|ii|dS(N(RzRRRRxR9(RiRR((s/sys/lib/python/tarfile.pyR9bscCsD|idjo#|ii}|ii|n|iidS(NRE(RLRRRxR9Rl(RiR((s/sys/lib/python/tarfile.pyRlgsi@( RYRZR[RRkRR7RRR9Rl(((s/sys/lib/python/tarfile.pyR/s     t _FileInFilecBsSeZdZddZdZdZddZdZdZ dZ RS( sA thin wrapper around an existing file object that provides a part of its data as an individual file object. cCs1||_||_||_||_d|_dS(Ni(RxtoffsetRmtsparsetposition(RiRxRRmR((s/sys/lib/python/tarfile.pyRkws     cCs|iS(s*Return the current file position. (R(Ri((s/sys/lib/python/tarfile.pyR~scCs ||_dS(s(Seek to a position in the file. N(R(RiR((s/sys/lib/python/tarfile.pyRscCsl|djo|i|i}nt||i|i}|idjo|i|Sn|i|SdS(s!Read data from the file. N(R3RmRtminRt readnormalt readsparse(RiRm((s/sys/lib/python/tarfile.pyR7s  cCs9|ii|i|i|i|7_|ii|S(s*Read operation for regular files. (RxRRRR7(RiRm((s/sys/lib/python/tarfile.pyRscCs`g}xJ|djo<|i|}|pPn|t|8}|i|q Wdi|S(s)Read operation for sparse files. iR"(treadsparsesectionRRJRK(RiRmRR/((s/sys/lib/python/tarfile.pyRscCs|ii|i}|djodSnt||i|i|i}t|toQ|i |i|i}|i i |i||i|7_|i i |Sn|i|7_t |SdS(s0Read a single section of a sparse file. R"N(RtfindRR3RRRmt isinstancet_datatrealposRxRR7R(RiRmtsectionR((s/sys/lib/python/tarfile.pyRs  N( RYRZR[R3RkRRR7RRR(((s/sys/lib/python/tarfile.pyRqs     t ExFileObjectcBsheZdZdZdZd dZddZdZdZ e i dZ d Z d ZRS( saFile-like object for reading an archive member. Is returned by TarFile.extractfile(). icCsmt|i|i|it|dd|_|i|_d|_t|_ |i|_d|_ d|_ dS(NRRDiR"( RRxt offset_dataRmtgetattrR3RjRLRtR{Rtbuffer(Rittarfilettarinfo((s/sys/lib/python/tarfile.pyRks      cCs|iotdnd}|ioD|djo|i}d|_qn|i| }|i||_n|djo||ii7}n!||ii|t|7}|it|7_|S(s~Read at most size bytes from the file. If size is not present or None, read all data until EOF is reached. sI/O operation on closed fileR"N(R{R#RR3RxR7RR(RiRmR/((s/sys/lib/python/tarfile.pyR7s        icCs9|iotdnd|ijo|iidd}n|ig}xto|ii|i}|i|| p d|joMdi ||_|iidd}|djot |i}nPqSqSW|djot ||}n|i| }|i||_|i t |7_ |S(sRead one entire line from the file. If size is present and non-negative, return a string with at most that size, which may be an incomplete line. sI/O operation on closed files iR"ii( R{R#RRRrRxR7RRJRKRRR(RiRmRztbuffersR/((s/sys/lib/python/tarfile.pytreadlines(        cCs>g}x1to)|i}|pPn|i|q W|S(s0Return a list with all remaining lines. (RrRRJ(Ritresulttline((s/sys/lib/python/tarfile.pyt readliness    cCs!|iotdn|iS(s*Return the current file position. sI/O operation on closed file(R{R#R(Ri((s/sys/lib/python/tarfile.pyRs cCs |iotdn|tijo"tt|d|i|_n|tijoJ|djot|i|d|_qt|i||i|_nF|ti jo)tt|i||id|_n tdd|_ |i i |idS(s(Seek to a position in the file. sI/O operation on closed fileisInvalid argumentR"N( R{R#RStSEEK_SETRtmaxRmRtSEEK_CURtSEEK_ENDRRxR(RiRztwhence((s/sys/lib/python/tarfile.pyRs "  )  cCs t|_dS(sClose the file object. N(RrR{(Ri((s/sys/lib/python/tarfile.pyRl.sccs0x)to!|i}|pPn|VqWdS(s/Get an iterator over the file's lines. N(RrR(RiR((s/sys/lib/python/tarfile.pyt__iter__3s   N(RYRZR[RRkR3R7RRRRSRRRlR(((s/sys/lib/python/tarfile.pyRs    cBseZdZddZdZedZedZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZRS(sInformational 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"cCs||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_ d|_ d|_ d|_ d|_d|_dS(sXConstruct a TarInfo object. name is the optional name of the member. iiR"tusertgroupN(RjRLtuidtgidRmtmtimetchksumtREGTYPEttypetlinknametunametgnametdevmajortdevminorRR(RiRj((s/sys/lib/python/tarfile.pyRkHs              cCs d|ii|it|fS(Ns<%s %r at %#x>(t __class__RYRjtid(Ri((s/sys/lib/python/tarfile.pyt__repr__]scCst|tjotdn|ittjotdn|}||_|dd!it|_t|dd!|_ t|dd!|_ t|dd!|_ t|dd!|_ t|dd !|_ t|d d !|_|d d !|_|d d !it|_|d d!it|_|dd!it|_t|dd!|_t|dd!|_|dd!it}|o&|i o|d|i|_n|it|jotdn|S(sBConstruct a TarInfo object from a 512 byte string buffer. struncated headers empty headeriidiliti|iiiiii i)iIiQiYiRRsinvalid header(RRR#tcountRR/RRjR RLRRRmRRRRRRRRtissparseR2(tclsR/Rtprefix((s/sys/lib/python/tarfile.pytfrombuf`s2  c Cs/d}|i}d}|iido t}n|ttfjo |i}nt|i}|tjo|d7}n|i}|ot|}n|o|it jot dnt |it jot dt nt |t jo|td }x'|o|ddjo|d }qW|t |}|d }| pt |t jot dqqnat |it jo||i|it7}nt |t jo||i|t7}nt|dt|id @d |t|id |t|id |t|id |t|id |d |t|idttd ttdt|idt|idt|id |t|id |t|dg}|tidtdi|7}t |t d}|d d||d}||_!|S(s<Return a tar header as a string of 512 byte blocks. R"RRsfile is too large (>= 8 GB)slinkname is too long (>%d)iisname is too longidiii s iii is%dsiis%06oi("RRjRtDIRTYPEtGNUTYPE_LONGNAMEtGNUTYPE_LONGLINKRURRmtMAXSIZE_MEMBERR#Rt LENGTH_LINKt LENGTH_NAMEt LENGTH_PREFIXt_create_gnulongRR)RLRRRtMAGICtVERSIONRRRRR$R&RRKR2R/( RiR(R/RRRjRtpartsR((s/sys/lib/python/tarfile.pyttobufsf         # cCs|t7}|i}d|_||_d|_t||_|i}||7}tt|t \}}|djo|t |t7}n|S(sCreate a GNU longname/longlink header from name. It consists of an extended tar header, with the length of the longname as size, followed by data blocks, which contain the longname as a null terminated string. s ././@LongLinki( RRRjRRLRRmRR6R(RiRjRRR/R=R>((s/sys/lib/python/tarfile.pyRs        cCs |itjS(N(Rt REGULAR_TYPES(Ri((s/sys/lib/python/tarfile.pytisregscCs |iS(N(R(Ri((s/sys/lib/python/tarfile.pytisfilescCs |itjS(N(RR(Ri((s/sys/lib/python/tarfile.pytisdirscCs |itjS(N(RtSYMTYPE(Ri((s/sys/lib/python/tarfile.pytissymscCs |itjS(N(RtLNKTYPE(Ri((s/sys/lib/python/tarfile.pytislnkscCs |itjS(N(RtCHRTYPE(Ri((s/sys/lib/python/tarfile.pytischrscCs |itjS(N(RtBLKTYPE(Ri((s/sys/lib/python/tarfile.pytisblkscCs |itjS(N(RtFIFOTYPE(Ri((s/sys/lib/python/tarfile.pytisfifoscCs |itjS(N(RtGNUTYPE_SPARSE(Ri((s/sys/lib/python/tarfile.pyRscCs|itttfjS(N(RRRR(Ri((s/sys/lib/python/tarfile.pytisdevs(RYRZR[RkRt classmethodRRtRRRRRRRRRRRR(((s/sys/lib/python/tarfile.pyR@s   ! K          cBs eZdZdZeZeZdZeZe Z d3dd3dZ e d3dd3d4dZe dd3dZe dd3dd Ze dd3dd Zhd d <d d<dd((s/sys/lib/python/tarfile.pyRls    cCs4|i|}|djotd|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 occurence is assumed to be the most up-to-date version. sfilename %r not foundN(t _getmemberR3tKeyError(RiRjR((s/sys/lib/python/tarfile.pyt getmembers cCs)|i|ip|in|iS(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_checkRt_loadR(Ri((s/sys/lib/python/tarfile.pyt getmemberss  cCs(g}|iD]}||iq~S(sReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). (RRj(Rit_[1]R((s/sys/lib/python/tarfile.pytgetnamessc Cs|id|d j o |i}n|d jo |}nt|}tii|\}}x#|dd!djo|d}qeWt}|d joAttdo|i oti |}qti |}nti |i }d}|i}t i|oz|i|if} |i o7|idjo'| |ijot} |i| }qAt} | do||i| ttd o.ti3|i4|_5ti6|i4|_7qn|S( sOCreate a TarInfo object for either the file `name' or the file object `fileobj' (using os.fstat on its file descriptor). You can modify some of the TarInfo's attributes before you add it using addfile(). If given, `arcname' specifies an alternative name for the file in the archive. RiiRRtlstatR"iltmajortminorN(8RR3RjRURSRTt splitdriveRRft dereferenceRtstattfstattfilenotst_modetS_ISREGtst_inotst_devtst_nlinkRRRtS_ISDIRRtS_ISFIFORtS_ISLNKRtreadlinktS_ISCHRRtS_ISBLKRRLtst_uidRtst_gidRtst_sizeRmtst_mtimeRRRtpwdtgetpwuidRRtgrptgetgrgidRRtst_rdevRRR( RiRjtarcnameRxtdrvRtstatresRtstmdtinodeR((s/sys/lib/python/tarfile.pyt gettarinfo s                          cCs|ix|D]}|ot|iGd|ip|i|ip|ifG|ip |iodd|i |i fGn d|i Gdt i |id Gn|iG|o<|iodG|iGn|iodG|iGqnHqWd S( sPrint 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. s%s/%ss%10ss%d,%ds%10ds%d-%02d-%02d %02d:%02d:%02dis->slink toN(RRQRLRRRRRRRRRmRt localtimeRRjRRR(RitverboseR((s/sys/lib/python/tarfile.pytlistps(     cCs|id|djo |}n|idj o8tii||ijo|idd|dSn|djoc|oT|djo d}nx:tidD]%}|i|tii ||qWndSn|id||i ||}|djo|idd|dSn|i o-t |d }|i |||in|iod|i ||oLxIti|D]4}|itii ||tii ||qWqn|i |dS( sQAdd 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. Ristarfile: Skipped %rNt.R"istarfile: Unsupported type %rR(RR3RjRSRTRt_dbgtlistdirtaddRKR<RRtaddfileRlR(RiRjR7t recursivetfR((s/sys/lib/python/tarfile.pyRCs<   ,   '    :cCs|idti|}|i|i}|ii||it|7_|dj oxt ||i|i t |i t \}}|djo&|iit t ||d7}n|i|t 7_n|ii|dS(s]Add 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 using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size. RiiN(RtcopyRR(RxR9RRR3R5RmR6RRRRJ(RiRRxR/R=R>((s/sys/lib/python/tarfile.pyRDs   R@c CsVg}|djo |}nxx|D]p}|ioMy&titii||idWntj onX|i|q$|i ||q$W|i d|i x|D]}tii||i}y4|i |||i |||i||Wqtj o4}|idjoqN|idd|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(). icSst|i|iS((RRj(RR?((s/sys/lib/python/tarfile.pyRXsis tarfile: %sN(R3RRStmakedirsRTRKRjtEnvironmentErrorRJtextracttsorttreversetchowntutimetchmodR\t errorlevelRA(RiRTRt directoriesRte((s/sys/lib/python/tarfile.pyt extractalls2   & R"cCsE|idt|to |}n|i|}|iotii||i|_ ny&|i |tii||i Wnt j ok}|i djoqA|idjo|idd|iqA|idd|i|ifnAtj o4}|i djoqA|idd|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'. RDiis tarfile: %sstarfile: %s %rN(RRRRRRSRTRKRt _link_targett_extract_memberRjRIRPtfilenameR3RAtstrerrorR\(RitmemberRTRRR((s/sys/lib/python/tarfile.pyRJs$   &$cCs|idt|to |}n|i|}|io|i||Sn|itjo|i||Snb|ip |i oCt|i t ot dq|i |i|i|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() RDs'cannot extract (sym)link as file objectN(RRRRRt fileobjectRtSUPPORTED_TYPESRRRxRnR_t extractfileRRR3(RiRXR((s/sys/lib/python/tarfile.pyR[$s   c Csl|ddjo|d }ntii|}tii|}|otii| ot}||_t|_d|_ |i |_ |i |_ |i |_ |i |_ |i|_y|i||iWqqXn|ip |io$|idd|i|ifn|id|i|io|i||n|io|i||n|io|i||n|ip |io|i||nc|ip |io|i||n5|itjo|i||n|i|||i |||ip$|i!|||i"||ndS(s\Extract the TarInfo object tarinfo to a physical file called targetpath. iRRiis%s -> %sN(#RSRTRUtdirnametexistsRRjRRRLRRRRRRURRRARRtmakefileRtmakedirRtmakefifoRRtmakedevtmakelinkRZt makeunknownRMRORN(RiRt targetpatht upperdirstti((s/sys/lib/python/tarfile.pyRUKsL         $    cCsGyti|Wn/tj o#}|itijoqCnXdS(s,Make a directory called targetpath. N(RStmkdirRIterrnotEEXIST(RiRRdRR((s/sys/lib/python/tarfile.pyR_s cCsC|i|}t|d}t|||i|idS(s'Make a file called targetpath. RN(R[RR5Rl(RiRRdtsourcettarget((s/sys/lib/python/tarfile.pyR^s   cCs+|i|||idd|idS(sYMake a file from a TarInfo object with an unknown type at targetpath. is9tarfile: Unknown file type %r, extracted as regular file.N(R^RAR(RiRRd((s/sys/lib/python/tarfile.pyRcs cCs1ttdoti|n tddS(s'Make a fifo called targetpath. tmkfifosfifo not supported by systemN(RfRSRlR\(RiRRd((s/sys/lib/python/tarfile.pyR`scCsttd pttd otdn|i}|io|tiO}n|tiO}ti||ti |i |i dS(s<Make a character or block device called targetpath. tmknodRas'special devices not supported by systemN( RfRSR\RLRR tS_IFBLKtS_IFCHRRmRaRR(RiRRdRL((s/sys/lib/python/tarfile.pyRas"    cCs!|i}y8|ioti||nti|i|Wntj o|io4tiitii |i |}t |}ny|i |i ||Wqttfj oS}tii |}yti||Wqtj o}tdqXqXnXdS(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. slink could not be createdN(RRRStsymlinktlinkRTR RTRKR\RjRURURRIRR4tcopy2R8(RiRRdtlinkpathRR((s/sys/lib/python/tarfile.pyRbs$    c Cstottdortidjo_yti|id}WnOtj oCyti|i d}Wqtj oti }qXnXyti |i d}WnOtj oCyti |id}Wqtj oti}qXnXy_|io'ttdoti|||n(tidjoti|||nWqtj o}tdqXndS(s6Set owner of targetpath according to tarinfo. tgeteuidiitlchowntos2emxscould not change ownerN(R2RfRSRtR4tgetgrnamRRR5RtgetgidtgetpwnamRR3RtgetuidRRutsystplatformRMRIR\(RiRRdtgtuRR((s/sys/lib/python/tarfile.pyRMs,*cCsSttdo?yti||iWqOtj o}tdqOXndS(sASet file permissions of targetpath according to tarinfo. ROscould not change modeN(RfRSRORLRIR\(RiRRdRR((s/sys/lib/python/tarfile.pyROs cCsttdpdSntidjo|iodSny ti||i|ifWn!tj o}tdnXdS(sBSet modification time of targetpath according to tarinfo. RNNtwin32s"could not change modification time( RfRSR{R|RRNRRIR\(RiRRdRR((s/sys/lib/python/tarfile.pyRNs cCs|id|idj o|i}d|_|Sn|ii|ixto|iit}|pdSny=t i |}|i|_|it7_|i |}Wnzt j on}|i o3|idd|i|f|it7_qMq/|idjotd|ndSnXPqMW|io |iido t|_n|io|id7_n|ii||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. trais 0x%X: empty or invalid block: %sis(empty, unreadable or compressed file: %sRRN(RRR3RxRRRrR7RRRt proc_memberR#t ignore_zerosRAR]RRjRRRRRRJ(RitmR/RRR((s/sys/lib/python/tarfile.pyRs@           cCsY|ittfjo|i|Sn/|itjo|i|Sn|i|SdS(seChoose the right processing method for tarinfo depending on its type and call it. N(RRRt proc_gnulongRt proc_sparset proc_builtin(RiR((s/sys/lib/python/tarfile.pyRGs cCsL|i|_|ip|itjo|i|i|i7_n|S(soProcess a builtin type member or an unknown member which will be treated as a regular file. (RRRRRZt_blockRm(RiR((s/sys/lib/python/tarfile.pyRRs cCsd}|i}xG|djo9|iit}||7}|it7_|t8}qW|iit}ti|}|i|_|it7_|i|}|i|_|it jo|i t |_ n'|it jo|i t |_n|S(sSProcess the blocks that hold a GNU longname or longlink member. R"i(RmRxR7RRRRRRRRRRjRR(RiRR/RtblockR?RGR((s/sys/lib/python/tarfile.pyR\s$    c Cs|i}t}d}d}d}xtdD]}y6t|||d!}t||d|d!} Wntj oPnX||jo|it|||n|it|| ||| 7}|| }|d7}q1Wt|d} t|dd!} x| d jo|i i t }|i t 7_ d }xtd D]}y6t|||d!}t||d|d!} Wntj oPnX||jo|it|||n|it|| ||| 7}|| }|d7}qQWt|d } qW|| jo|it|| |n||_ |i |_|i |i|i7_ | |_|S( s8Process a GNU sparse header plus extra headers. ilii iiiiiiii(R/t _ringbufferRR R#RJt_holeRRRxR7RRRRRRm( RiRR/tspRztlastposRRRtnumbytest isextendedtorigsize((s/sys/lib/python/tarfile.pyRysZ              cCs2t|t\}}|o|d7}n|tS(s_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. i(R6R(RiRR=R>((s/sys/lib/python/tarfile.pyRscCs}|i}|djot|}n|i|}x>t|dddD]&}|||ijo ||SqOqOWdS(s}Find an archive member by name from bottom to top. If tarinfo is given, it is used as the starting point. iiN(RR3RtindexRRj(RiRjRRtendR((s/sys/lib/python/tarfile.pyRs  cCs:x*to"|i}|djoPqqWt|_dS(sWRead through the entire archive file and look for readable members. N(RrRR3R(RiR((s/sys/lib/python/tarfile.pyRs     cCs\|iotd|iin|dj o'|i|jotd|indS(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(R{R8RRYR3R(RiRL((s/sys/lib/python/tarfile.pyRs cCs)|iot|iSn t|SdS(s$Provide an iterator object. N(RtiterRtTarIter(Ri((s/sys/lib/python/tarfile.pyRs cCs%||ijoti|IJndS(s.Write debugging output to sys.stderr. N(tdebugR{tstderr(Ritleveltmsg((s/sys/lib/python/tarfile.pyRAsNi((4RYRZR[RRtRRRPR(RRYR3RkRRgRRRRRlRRRR<RrR?RCRDRSRJR[RUR_R^RcR`RaRbRMRORNRRRRRRRRRRRA(((s/sys/lib/python/tarfile.pyRshCG     d 3 ) ! ' :       B  <  RcBs)eZdZdZdZdZRS(sMIterator Class. for tarinfo in TarFile(...): suite... cCs||_d|_dS(s$Construct a TarIter object. iN(RR(RiR((s/sys/lib/python/tarfile.pyRks cCs|S(s Return iterator object. ((Ri((s/sys/lib/python/tarfile.pyRscCs|iip0|ii}|pt|i_tqpn4y|ii|i}Wntj o tnX|id7_|S(sReturn the next item using TarFile's next() method. When all members have been read, set TarFile as _loaded. i(RRRRrt StopIterationRRt IndexError(RiR((s/sys/lib/python/tarfile.pyRs   (RYRZR[RkRR(((s/sys/lib/python/tarfile.pyRs  t_sectioncBs eZdZdZdZRS(s$Base class for _data and _hole. cCs||_||_dS(N(RRm(RiRRm((s/sys/lib/python/tarfile.pyRks cCs(|i|jo|i|ijnS(N(RRm(RiR((s/sys/lib/python/tarfile.pyt __contains__s(RYRZR[RkR(((s/sys/lib/python/tarfile.pyRs RcBseZdZdZRS(s/Represent a data section in a sparse file. cCs ti|||||_dS(N(RRkR(RiRRmR((s/sys/lib/python/tarfile.pyRk!s(RYRZR[Rk(((s/sys/lib/python/tarfile.pyRsRcBseZdZRS(s/Represent a hole section in a sparse file. (RYRZR[(((s/sys/lib/python/tarfile.pyR%sRcBs eZdZdZdZRS(sMRingbuffer class which increases performance over a regular list. cCs d|_dS(Ni(tidx(Ri((s/sys/lib/python/tarfile.pyRk.scCs|i}xgto_||}||joPn|d7}|t|jo d}n||ijodSq q W||_|S(Nii(RRrRR3(RiRRtitem((s/sys/lib/python/tarfile.pyR0s        (RYRZR[RkR(((s/sys/lib/python/tarfile.pyR*s it TarFileCompatcBsteZdZdedZdZdZdZdZdZ dZ d d d Z d Z d ZRS( sRTarFile class compatible with standard module zipfile's ZipFile class. RDcCs|tjoti|||_n3|tjoti|||_n td|dd!djoU|ii}xC|D]7}|i|_ |i |_ t i |id |_qWndS(Nsunknown compression constantiiRDi(t TAR_PLAINRRRt TAR_GZIPPEDRR#RRjRVRmt file_sizeRtgmtimeRt date_time(RiRRLt compressionRR((s/sys/lib/python/tarfile.pyRkHs     cCstd|iS(NcSs|iS((Rj(R((s/sys/lib/python/tarfile.pyRXVs(tmaptinfolist(Ri((s/sys/lib/python/tarfile.pytnamelistUscCstd|iiS(NcSs |itjS((RR(R((s/sys/lib/python/tarfile.pyRXXs(tfilterRR(Ri((s/sys/lib/python/tarfile.pyRWs cCs|iidS(N(RR?(Ri((s/sys/lib/python/tarfile.pytprintdirZscCsdS(N((Ri((s/sys/lib/python/tarfile.pyttestzip\scCs|ii|S(N(RR(RiRj((s/sys/lib/python/tarfile.pytgetinfo^scCs"|ii|ii|iS(N(RR[RR7(RiRj((s/sys/lib/python/tarfile.pyR7`scCs|ii||dS(N(RRC(RiRVR7t compress_type((s/sys/lib/python/tarfile.pyR9bsc Csyddkl}Wn#tj oddkl}nXddk}|i|_|i|_|i|i |_ |i i |||dS(Ni(tStringIO( t cStringIORR}tcalendarRVRjRRmttimegmRRRRD(RitzinfotbytesRR((s/sys/lib/python/tarfile.pytwritestrds   cCs|iidS(N(RRl(Ri((s/sys/lib/python/tarfile.pyRlnsN(RYRZR[RRkRRRRRR7R3R9RRl(((s/sys/lib/python/tarfile.pyRDs       cCs<yt|}|itSWntj o tSnXdS(sfReturn True if name points to a tar archive that we are able to handle, else return False. N(RgRlRrRRt(RjRG((s/sys/lib/python/tarfile.pyRus   (cR[t __version__tversiont __author__t__date__t __cvsid__t __credits__R{RSR4R RhRR$RGR|R}R4R2R3t__all__RRRRRRRRRRtAREGTYPERRRRRRtCONTTYPERRRRZRtS_IFLNKtS_IFREGRntS_IFDIRRotS_IFIFOtTSUIDtTSGIDtTSVTXtTUREADtTUWRITEtTUEXECtTGREADtTGWRITEtTGEXECtTOREADtTOWRITEtTOEXECRR RtR)R2R5RIRQRWRURTt ExceptionRR\R]R^R_R`RntobjectRuRRRRRRRRRR?RRRRRRg(((s/sys/lib/python/tarfile.pyss                                         BL% 1