3 υ_i@sNddlmZdZdZdZdZdZdZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZyddlZddlZWnek rdZZYnXeefZyeef7ZWnek rYnXd d d d gZejdd krddlZnddlZejZdZdZedZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1d Z2d!Z3d"Z4dZ5d#Z6d$Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1f Z9e&e'e.e1fZ:e/e0e1fZ;dZe?e?e?e@e@e@d-ZAd.ZBd/ZCd0ZDd1ZEd2ZFd3ZGd4ZHd5ZIdZJd6ZKd7ZLd8ZMd9ZNd:ZOd;ZPdt|j|jkrL|jj|jd|j|j|jd|_qWdS)z]Write string s to the stream if a whole new block is ready to be written. N)rWr.rrrZ)rr0r4r4r5Z__writesz_Stream.__writecCs|jr dS|jdkr2|jdkr2|j|jj7_|jdkr|jr|jj|jd|_|jdkr|jjtj d|j d@|jjtj d|j d@|j s|jj d|_dS) z[Close the _Stream object. No operation should be done on it afterwards. Nrgrrrzd?Zd@dAZ dBdCZ!dDdEZ"dFdGZ#dHdIZ$dJdKZ%dLdMZ&dNdOZ'dPdQZ(dRdSZ)dTdUZ*dVdWZ+dXdYZ,dZd[Z-d\d]Z.d^d_Z/d`daZ0dbdcZ1dddeZ2dfdgZ3dhS)kraInformational 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. rrpr r!rrchksumtypelinknamer"r#devmajordevminorrr pax_headersrr_sparse_structs _link_targetrlcCsj||_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. irrlN)rrpr r!rrrREGTYPErrr"r#rrrrrr)rrr4r4r5rs"zTarInfo.__init__cCs|jS)N)r)rr4r4r5_getpathszTarInfo._getpathcCs ||_dS)N)r)rrr4r4r5_setpathszTarInfo._setpathcCs|jS)N)r)rr4r4r5 _getlinkpathszTarInfo._getlinkpathcCs ||_dS)N)r)rrr4r4r5 _setlinkpathszTarInfo._setlinkpathcCsd|jj|jt|fS)Nz<%s %r at %#x>) __class__rurid)rr4r4r5__repr__szTarInfo.__repr__cCsn|j|jd@|j|j|j|j|j|j|j|j |j |j |j d }|dt krj|djd rj|dd7<|S)z9Return the TarInfo's attributes as a dictionary. i) rrpr r!rrrrrr"r#rrrr/)rrpr r!rrrrrr"r#rrDIRTYPEr)rinfor4r4r5get_infos  zTarInfo.get_infosurrogateescapecCsT|j}|tkr|j|||S|tkr4|j|||S|tkrH|j||StddS)ztdt|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 jdrt|_|jtkr6d}g}xrtdD]f} y0t|||d} t||d|d} Wntk rPYnX|j| | f|d7}qWt|d} t|dd} || | f|_ |j!rN|j j"d|_ |rp|jt#krp|d|j |_ |S)zAConstruct a TarInfo object from a 512 byte bytes object. rz empty headerztruncated headerzend of file headerrTrUz bad checksumr lt|ii i)iIiQiYirir*riii)$r.r~rrcountr/rrGrXrBr;rrpr r!rrrrrr"r#rrAREGTYPErrGNUTYPE_SPARSErCrArnboolrisdirrstrip GNU_TYPES)rrWr2r3robjrrstructsrFrnumbytes isextendedorigsizer4r4r5frombufsZ       zTarInfo.frombufcCs8|jjt}|j||j|j}|jjt|_|j|S)zOReturn the next TarInfo object from TarFile object tarfile. ) rrYrr3r2r3rr _proc_member)rrrWr.r4r4r5 fromtarfiles zTarInfo.fromtarfilecCsT|jttfkr|j|S|jtkr,|j|S|jtttfkrF|j |S|j |SdS)zYChoose the right processing method depending on the type and call it. N) rrr _proc_gnulongr) _proc_sparserrSOLARIS_XHDTYPE _proc_pax _proc_builtin)rrr4r4r5r4s    zTarInfo._proc_membercCsR|jj|_|j}|js$|jtkr4||j|j7}||_|j |j |j |j |S)zfProcess a builtin type or an unknown type which will be treated as a regular file. ) rrrisregrSUPPORTED_TYPES_blockrr_apply_pax_inforr2r3)rrrr4r4r5r:$s zTarInfo._proc_builtinc Cs|jj|j|j}y|j|}Wntk r>tdYnX|j|_|jt krft ||j |j |_ n|jtkrt ||j |j |_|S)zSProcess the blocks that hold a GNU longname or longlink member. z missing or bad subsequent header)rrYr=rr5r}rrrrr;r2r3rrr)rrrWnextr4r4r5r65s  zTarInfo._proc_gnulongc Cs|j\}}}|`x|r|jjt}d}xvtdD]j}y0t|||d}t||d|d} Wntk rzPYnX|r| r|j|| f|d7}q0Wt|d}qW||_ |jj |_ |j |j |j |_||_ |S)z8Process a GNU sparse header plus extra headers. rrr&i)rrrYrrCrGrArnr*rrrr=rr) rrr/r1r2rWrrFrr0r4r4r5r7Ks(    zTarInfo._proc_sparsec Cs |jj|j|j}|jtkr&|j}n |jj}tj d|}|dk rX|j dj d|d<|j d}|dkrr|j }nd}tjd}d}x|j||}|sP|j\} } t| } ||jd d|jd| d} |j| dd|j} | tkr|j| ||j |j} n|j| dd|j} | || <|| 7}qWy|j|} Wntk rTtd YnXd |krn|j| |nHd |kr|j| ||n.|j d dkr|j ddkr|j| |||jttfkr| j||j |j|j | _ d|kr| j!} | j"s| jt#kr| | j| j7} | |_ | S)zVProcess an extended or global header as described in POSIX.1-2008. s\d+ hdrcharset=([^\n]+)\nNrr hdrcharsetZBINARYs(\d+) ([^=]+)=rrz missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorr>r)$rrYr=rrrrr researchgroupr9rr2compilematchgroupsr@endr_decode_pax_fieldr3PAX_NAME_FIELDSr5r}r_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10rr8r>rrr;r<)rrrWrrGrAr2Zregexrr1rr r?rr4r4r5r9gs`       $          zTarInfo._proc_paxcCspg}x(tjd|D]}|jt|jdqWg}x(tjd|D]}|jt|jdq@Wtt|||_dS)z?Process a GNU tar extended sparse header, version 0.0. s\d+ GNU.sparse.offset=(\d+)\nrs\d+ GNU.sparse.numbytes=(\d+)\nN)rCfinditerrnr@rElistzipr)rr?rrWZoffsetsrGr0r4r4r5rMszTarInfo._proc_gnusparse_00cCs@dd|djdD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1. cSsg|] }t|qSr4)r@).0rir4r4r5 sz.TarInfo._proc_gnusparse_01..zGNU.sparse.map,Nrr)splitrPrQr)rr?rrr4r4r5rLszTarInfo._proc_gnusparse_01cCsd}g}|jjt}|jdd\}}t|}xJt||dkrvd|krV||jjt7}|jdd\}}|jt|q.W|jj|_t t |ddd|ddd|_ dS)z?Process a GNU tar extended sparse header, version 1.0. Nrrr) rrYrrUr@r.rnrrrPrQr)rr?rrZfieldsrrWZnumberr4r4r5rNs  zTarInfo._proc_gnusparse_10c Csx|jD]\}}|dkr(t|d|q |dkrBt|dt|q |dkr\t|dt|q |tkr |tkryt||}Wntk rd}YnX|dkr|jd}t|||q W|j|_dS) zoReplace fields with supplemental information from a previous pax extended or global header. zGNU.sparse.namerzGNU.sparse.sizerzGNU.sparse.realsizerrN) rsetattrr@ PAX_FIELDSPAX_NUMBER_FIELDSrAr,r r)rrr2r3rr r4r4r5r>s"  zTarInfo._apply_pax_infoc Cs.y |j|dStk r(|j||SXdS)z1Decode a single field from a pax record. r=N)r9UnicodeDecodeError)rr r2Zfallback_encodingZfallback_errorsr4r4r5rJs zTarInfo._decode_pax_fieldcCs"t|t\}}|r|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it, e.g. _block(834) => 1024. r)r[r)rr'r_r`r4r4r5r= szTarInfo._blockcCs |jtkS)N)r REGULAR_TYPES)rr4r4r5r;sz TarInfo.isregcCs|jS)N)r;)rr4r4r5isfileszTarInfo.isfilecCs |jtkS)N)rr)rr4r4r5r+sz TarInfo.isdircCs |jtkS)N)rSYMTYPE)rr4r4r5issymsz TarInfo.issymcCs |jtkS)N)rLNKTYPE)rr4r4r5islnksz TarInfo.islnkcCs |jtkS)N)rCHRTYPE)rr4r4r5ischr sz TarInfo.ischrcCs |jtkS)N)rBLKTYPE)rr4r4r5isblk"sz TarInfo.isblkcCs |jtkS)N)rFIFOTYPE)rr4r4r5isfifo$szTarInfo.isfifocCs |jdk S)N)r)rr4r4r5issparse&szTarInfo.issparsecCs|jtttfkS)N)rr`rbrd)rr4r4r5isdev(sz TarInfo.isdevN)rrpr r!rrrrrr"r#rrrrrrrrr)rl)4rurvrwrx __slots__rrrpropertyrrrrrrDEFAULT_FORMATENCODINGrrrr classmethodrr staticmethodrrrrr3r5r4r:r6r7r9rMrLrNr>rJr=r;r[r+r]r_rarcrerfrgr4r4r4r5rs`    1    3 ?  f  c @seZdZdZdZdZdZdZeZ e Z dZ e ZeZdVdd Zedddefd d ZedWd d ZedXddZedYddZddddZddZddZddZddZdZdd Zd[d"d#Zd\d$d%Zd]d&d'Z d^d)d*Z!d_d,d-Z"d.d/Z#d`d0d1Z$d2d3Z%d4d5Z&d6d7Z'd8d9Z(d:d;Z)dd?Z+d@dAZ,dBdCZ-dDdEZ.dadFdGZ/dHdIZ0dbdJdKZ1dLdMZ2dNdOZ3dPdQZ4dRdSZ5dTdUZ6dS)crz=The TarFile Class provides an interface to tar archives. rFrNrfrc Cst|dks|dkrtd||_dddd||_|sp|jdkr\tjj| r\d |_d|_t||j}d |_n0|d krt |d r|j }t |d r|j|_d|_|rtjj |nd |_ ||_ |d k r||_ |d k r||_|d k r||_|d k r||_|d k r||_| |_| d k r(|j tkr(| |_ni|_| d k r>| |_| d k rN| |_d |_g|_d |_|j j|_i|_y|jdkrd |_|j|_|jdkr$x|j j|jy|jj |}|jj!|WnTt"k r|j j|jPYn0t#k r} zt$t%| WYd d } ~ XnXqW|jdkrnd|_|jrn|jj&|jj'}|j j(||jt|7_Wn&|js|j j)d|_YnXd S)aOpen 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. rrzmode must be 'r', 'a' or 'w'rbzr+bwb)rfargrprgFNrrpTrfaw)*r.rArp_moderrexists bltn_openrrrabspathrrRr dereference ignore_zerosr2r3rrdebug errorlevelrmembers_loadedrrinodes firstmemberr?rr5rnrr}rzrrr rZr)rrrprrRrrvrwr2r3rrxryerWr4r4r5rFs           $   zTarFile.__init__c Ks| r| rtd|dkrxz|jD]p}t||j|}|dk rH|j}y||d|f|Sttfk r} z|dk r|j|w$WYdd} ~ Xq$Xq$Wtdnd|kr|jdd\} }| pd} |pd}||jkrt||j|}n td |||| |f|Sd |kr|jd d\} }| p(d} |p2d}| d krFtd t|| |||} y||| | f|} Wn| j YnXd | _ | S|dkr|j |||f|StddS)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 '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 znothing to openrfr:*Nz%file could not be opened successfully:rrzunknown compression type %r|rwzmode must be 'r' or 'w'Frqzundiscernible mode)rfr) rA OPEN_METHrrrzr{rrUrrrtaropen) rrrprrkwargsrfuncZ saved_posr~rtstreamrjr4r4r5rsN            z TarFile.opencKs,t|dks|dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing. rrzmode must be 'r', 'a' or 'w')r.rA)rrrprrr4r4r5rszTarFile.taropenrc Kst|dks|dkrtdyddl}|jWn ttfk rNtdYnX|dk }y*|j||d||}|j|||f|}Wn^tk r| r|dk r|j |dkrt dYn$| r|dk r|j YnX||_ |S) zkOpen gzip compressed tar archive name for reading or writing. Appending is not allowed. rrzmode must be 'r' or 'w'rNzgzip module is not availableraznot a gzip file) r.rAgzipZGzipFilerAttributeErrorr{rr\rrzr) rrrpr compresslevelrrZ extfileobjrjr4r4r5gzopens.  zTarFile.gzopencKst|dks|dkrtdy ddl}Wntk rDtdYnX|dk rZt||}n|j|||d}y|j|||f|}Wn(tt fk r|j t dYnXd |_ |S) zlOpen bzip2 compressed tar archive name for reading or writing. Appending is not allowed. rrzmode must be 'r' or 'w'.rNzbz2 module is not available)rznot a bzip2 fileF) r.rArrr{rZBZ2Filerr\EOFErrorrrzr)rrrprrrrrjr4r4r5bz2open$s   zTarFile.bz2openrrr)rrrcCs|jr dS|jdkrf|jjttd|jtd7_t|jt\}}|dkrf|jjtt||j sv|jj d|_dS)zlClose the TarFile. In write-mode, two finishing zero blocks are appended to the archive. NrqrrT) rrprrZr/rrr[ RECORDSIZErr)rr_r`r4r4r5rHs  z TarFile.closecCs"|j|}|dkrtd||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. Nzfilename %r not found) _getmemberKeyError)rrrr4r4r5 getmember\s  zTarFile.getmembercCs|j|js|j|jS)zReturn the members of the archive as a list of TarInfo objects. The list has the same order as the members in the archive. )_checkr{_loadrz)rr4r4r5 getmembersgszTarFile.getmemberscCsdd|jDS)zReturn the members of the archive as a list of their names. It has the same order as the list returned by getmembers(). cSsg|] }|jqSr4)r)rRrr4r4r5rSusz$TarFile.getnames..)r)rr4r4r5getnamesqszTarFile.getnamesc Csp|jd|dk r|j}|dkr$|}tjj|\}}|jtjd}|jd}|j}||_ |dkrt tdr|j rtj |}qtj |}ntj|j}d}|j}t j|r|j|jf} |j r|jdkr| |jkr||j| krt} |j| }nt} | drx||j| <nht j|r"t} nVt j|r4t} nDt j|rPt} tj|}n(t j|rbt } nt j!|rtt"} ndS||_||_#|j$|_%|j&|_'| tkr|j(|_)nd|_)|j*|_+| |_,||_-t.ryt.j/|j%d|_0Wnt1k rYnXt2r*yt2j3|j'd|_4Wnt1k r(YnX| t t"fkrlt tdrlt td rltj5|j6|_7tj8|j6|_9|S) aOCreate 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. rqNrlstatrlrrmajorminor):rrrr splitdriverseplstriprrrrvrstatfstatfilenost_modeS_ISREGst_inost_devst_nlinkr|r^rS_ISDIRrS_ISFIFOrdS_ISLNKr\readlinkS_ISCHRr`S_ISBLKrbrpst_uidr st_gidr!st_sizerst_mtimerrrpwdgetpwuidr"rgrpZgetgrgidr#rst_rdevrrr) rrarcnamerZdrvrZstatresrZstmdinoderr4r4r5 gettarinfows~                 zTarFile.gettarinfoTcCs |jx|D]}|rtt|jddtd|jp6|j|jp@|jfdd|js\|j rztdd|j |j fddntd|j ddtdt j|jdd ddt|j|jrd nd dd|r|jrtd |jdd|jrtd |jddtqWdS)zPrint 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.  )rIz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02dNrrrlz->zlink to)rprintrtrpr"r r#r!rarcrrrrZ localtimerrr+r]rr_)rverboserr4r4r5rPs& z TarFile.listc Csr|jd|dkr|}|dk rPddl}|jdtd||rP|jdd|dS|jdk rtjj||jkr|jdd|dS|jd||j ||}|dkr|jdd |dS|dk r||}|dkr|jdd|dS|j r t |d }|j |||j nd|jrd|j ||rnxHtj|D].}|jtjj||tjj|||||d q0Wn |j |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. `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. rqNrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rrn)filter)rwarningswarnDeprecationWarning_dbgrrrrurr;rtaddfilerr+listdiraddro) rrr recursiveZexcluderrrfr4r4r5rsD         z TarFile.addcCs|jdtj|}|j|j|j|j}|jj||jt |7_|dk rt ||j|j t |j t \}}|dkr|jjtt ||d7}|j|t 7_|jj|dS)a]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. rqNrr)rr rrRr2r3rrZrr.rbrr[rr/rzrn)rrrrWr_r`r4r4r5r4s   zTarFile.addfile.cCsg}|dkr|}xD|D]<}|jr<|j|tj|}d|_|j|||j dqW|jddd|jx|D]~}tjj ||j }y(|j |||j |||j ||Wqttk r}z$|jdkrЂn|jdd|WYdd}~XqtXqtWdS) aMExtract 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(). Ni) set_attrscSs|jS)N)r)rpr4r4r5dsz$TarFile.extractall..)keyrz tarfile: %s)r+rnr rpextractsortreverserrrorchownutimechmodryryr)rrrzZ directoriesrdirpathr~r4r4r5 extractallNs*       zTarFile.extractallrlcCs |jdt|tr |j|}n|}|jr>tjj||j|_ y |j |tjj||j |dWnt k r}zJ|j dkr~n6|jdkr|jdd|jn|jdd|j|jfWYdd}~XnBtk r}z$|j dkrn|jdd|WYdd}~XnXdS)axExtract 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. rf)rrNrz tarfile: %sztarfile: %s %r)rr rrr_rrrorr_extract_memberrEnvironmentErrorryfilenamerstrerrorry)rmemberrrrr~r4r4r5rts&      ( zTarFile.extractcCs|jdt|tr |j|}n|}|jr8|j||S|jtkrN|j||S|js^|j rt|j t rtt dq|j |j|SndSdS)aExtract 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() rfz'cannot extract (sym)link as file objectN)rr rrr; fileobjectrr<r_r]rrr| extractfile_find_link_target)rrrr4r4r5rs        zTarFile.extractfilecCsT|jd}|jdtj}tjj|}|r@tjj| r@tj||jsP|j rj|j dd|j |j fn|j d|j |j r|j||n|jr|j||nx|jr|j||nb|js|jr|j||nD|js|j r|j||n&|jtkr|j||n |j|||rP|j|||j sP|j|||j||dS)z\Extract the TarInfo object tarinfo to a physical file called targetpath. rrz%s -> %sN)r,rrrrdirnamersmakedirsr_r]rrrr;makefiler+makedirremakefiforarcmakedevmakelinkrr< makeunknownrrr)rr targetpathrZ upperdirsr4r4r5rs4        zTarFile._extract_membercCsFytj|dWn0tk r@}z|jtjkr0WYdd}~XnXdS)z,Make a directory called targetpath. iN)rmkdirrerrnoZEEXIST)rrrr~r4r4r5rs  zTarFile.makedircCs|j}|j|jt|d}|jdk rRx8|jD]\}}|j|t|||q.Wnt|||j|j|j|j|jdS)z'Make a file called targetpath. roN) rrrrtrrbrtruncater)rrrsourcetargetrrr4r4r5rs     zTarFile.makefilecCs"|j|||jdd|jdS)zYMake a file from a TarInfo object with an unknown type at targetpath. rz9tarfile: Unknown file type %r, extracted as regular file.N)rrr)rrrr4r4r5r s zTarFile.makeunknowncCs"ttdrtj|ntddS)z'Make a fifo called targetpath. mkfifozfifo not supported by systemN)rrrry)rrrr4r4r5r s  zTarFile.makefifocCsbttd sttd r td|j}|jr:|tjO}n |tjO}tj||tj |j |j dS)zt k r|jrtjj tjj |j |j}n|j}Yn6Xy|j|j ||Wntk rtdYnXdS)zMake 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. z%unable to resolve link inside archiveN)r]rsymlinkrrrsrlinkrrsymlink_exceptionrorrrry)rrrrr4r4r5r' s"      zTarFile.makelinkc Cstrttdrtjdkrytj|jd}Wntk rH|j}YnXytj |j d}Wntk rx|j }YnXy>|j rttdrtj |||ntjdkrtj|||Wn*tk r}ztdWYdd}~XnXdS)z6Set owner of targetpath according to tarinfo. geteuidrrlchownZos2emxzcould not change ownerN)rrrrrZgetgrnamr#rr!getpwnamr"r r]rsysplatformrrry)rrrgur~r4r4r5rD s    z TarFile.chowncCsLttdrHytj||jWn*tk rF}ztdWYdd}~XnXdS)zASet file permissions of targetpath according to tarinfo. rzcould not change modeN)rrrrprry)rrrr~r4r4r5rZ s  z TarFile.chmodcCsVttdsdSytj||j|jfWn*tk rP}ztdWYdd}~XnXdS)zBSet modification time of targetpath according to tarinfo. rNz"could not change modification time)rrrrrry)rrrr~r4r4r5rc s  z TarFile.utimecCs|jd|jdk r$|j}d|_|S|jj|jd}x\y|jj|}WnBtk r}z2|jr|j dd|j|f|jt 7_w:WYdd}~Xnt k r}zJ|jr|j dd|j|f|jt 7_w:n|jdkrt t |WYdd}~Xntk r&|jdkr"t dYnjtk r`}z|jdkrPt t |WYdd}~Xn0tk r}zt t |WYdd}~XnXPq:W|dk r|jj|nd|_|S)zReturn the next member of the archive as a TarInfo object, when TarFile is opened for reading. Return None if there is no more available. ZraNrz0x%X: %srz empty fileT)rr}rrrrr5rrwrrrBrzrr~rrrzrnr{)rmrr~r4r4r5r?n sF       z TarFile.nextcCsn|j}|dk r"|d|j|}|r2tjj|}x6t|D]*}|rTtjj|j}n|j}||kr<|Sq  & #& 0   1  c@s,eZdZdZddZddZddZeZdS) rzMIterator Class. for tarinfo in TarFile(...): suite... cCs||_d|_dS)z$Construct a TarIter object. rN)rr)rrr4r4r5r szTarIter.__init__cCs|S)z Return iterator object. r4)rr4r4r5r szTarIter.__iter__c Csb|jjs$|jj}|sPd|j_tn,y|jj|j}Wntk rNtYnX|jd7_|S)zReturn the next item using TarFile's next() method. When all members have been read, set TarFile as _loaded. Tr)rr{r? StopIterationrzr IndexError)rrr4r4r5__next__ s  zTarIter.__next__N)rurvrwrxrrrr?r4r4r4r5r s rc Cs.yt|}|jdStk r(dSXdS)zfReturn True if name points to a tar archive that we are able to handle, else return False. TFN)rrr)rrjr4r4r5r# s )rrrrr r!r"r#)rrr"r#)r+r,)N)wZ __future__r __version__version __author__Z__date__Z __cvsid__ __credits__rrrrrrLr rCrrrrNotImplementedErrorrZ WindowsError NameError__all__ version_infoZ __builtin__builtinsrZ_openr/rrrrrrrrr(r^r\r`rbrrdZCONTTYPErrr)rrr8rrKrrjr<rZr-rWsetrKrr@rXS_IFLNKS_IFREGrS_IFDIRrS_IFIFOZTSUIDZTSGIDZTSVTXZTUREADZTUWRITEZTUEXECZTGREADZTGWRITEZTGEXECZTOREADZTOWRITEZTOEXECrrkgetfilesystemencodingr6r;rGrSrXrbrmrt Exceptionrryrzr{r|r}r~rrrBrobjectrrrrrrrrrrrtr4r4r4r5s>         i?KT*