Viewing File: /usr/lib/python3.6/site-packages/pip/_vendor/distlib/_backport/__pycache__/tarfile.cpython-36.pyc

3

aji@sNddlmZdZdZdZdZdZdZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZyddlZddlZWnek
rdZZYnXeefZyeef7ZWnek
rYnXd	d
dd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;dZ<e=dZ>e?e?e?e@e@e@d-ZAd.ZBd/ZCd0ZDd1ZEd2ZFd3ZGd4ZHd5ZIdZJd6ZKd7ZLd8ZMd9ZNd:ZOd;ZPd<ZQd$ZRd#ZSe	jTdkrd?ZUnejVZUd@dAZWdBdCZXdDdEZYd;e8fdFdGZZdHdIZ[ddJdKZ\eBdLfeCdMfeDdNfeEdOfeFdPfeGdQffeKdRffeLdSffeMeHBdTfeHdUfeMdVffeNdRffeOdSffePeIBdTfeIdUfePdVffeQdRffeRdSffeSeJBdWfeJdXfeSdVfff
Z]dYdZZ^Gd[dde_Z`Gd\d]d]e`ZaGd^d_d_e`ZbGd`dadae`ZcGdbdcdce`ZdGdddedee`ZeGdfdgdgeeZfGdhdidieeZgGdjdkdkeeZhGdldmdmeeZiGdndodoeeZjGdpdqdqekZlGdrdsdsekZmGdtduduekZnGdvdwdwekZoGdxdydyekZpGdzd{d{ekZqGd|d
d
ekZrGd}d	d	ekZsGd~ddekZtddZueZvesjZdS))print_functionz
$Revision$z0.9.0u"Lars Gustäbel (lars@gustaebel.de)z5$Date: 2011-02-25 17:42:01 +0200 (Fri, 25 Feb 2011) $z?$Id: tarfile.py 88586 2011-02-25 15:42:01Z marc-andre.lemburg $u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.NTarFileTarInfo
is_tarfileTarErrorisustar  sustar00d01234567LKSxgXpathlinkpathsizemtimeuidgidunamegname)ZatimeZctimerr r!riii`i@i iii@ ntcezutf-8cCs(|j||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    N)encodelenNUL)slengthencodingerrorsr4/usr/lib/python3.6/tarfile.pystnsr6cCs*|jd}|dkr|d|}|j||S)z8Convert a null-terminated bytes object to a string.
    rrN)finddecode)r0r2r3pr4r4r5ntss
r;cCs|dtdkrJytt|ddp"dd}Wqtk
rFtdYqXn:d}x4tt|dD] }|dK}|t||d7}q`W|S)	z/Convert a number field to a python number.
    rr%asciistrict0r)zinvalid headerr)chrintr;
ValueErrorInvalidHeaderErrorranger.ord)r0nir4r4r5ntisrGcCsd|kod|dknr<d|d|fjdt}n|tksT|d|dkr\td|dkr|tjdtjd	|d}t}x,t|dD]}|j	d|d
@|dL}qW|j	dd|S)z/Convert a python number to a number field.
    rr)rz%0*or<r$zoverflow in number fieldLlr%)
r-r/
GNU_FORMATrAstructunpackpack	bytearrayrCinsert)rEdigitsformatr0rFr4r4r5itns	 rScCshdttjd|ddtjd|dd}dttjd|ddtjd	|dd}||fS)
aCalculate 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.
    r$Z148BNZ356BiZ148bZ356b)sumrLrM)bufZunsigned_chksumZ
signed_chksumr4r4r5calc_chksumss	00rXcCs|dkrdS|dkr8x|jd}|s&P|j|qWdSd}t||\}}x8t|D],}|j|}t||krvtd|j|qTW|dkr|j|}t||krtd|j|dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    rNr(izend of file reachedi@i@)readwritedivmodrCr.IOError)srcdstr1rWZBUFSIZEblocks	remainderbr4r4r5copyfileobjs,



rbrI-radcr:rwr0SxtTcCsPg}x@tD]8}x2|D] \}}||@|kr|j|PqW|jdq
Wdj|S)zcConvert a file's mode to a string of the form
       -rwxrwxrwx.
       Used by TarFile.list()
    rc)filemode_tableappendjoin)modeZpermtablebitcharr4r4r5filemode8s

rtc@seZdZdZdS)rzBase exception.N)__name__
__module____qualname____doc__r4r4r4r5rGsc@seZdZdZdS)ExtractErrorz%General exception for extract errors.N)rurvrwrxr4r4r4r5ryJsryc@seZdZdZdS)	ReadErrorz&Exception for unreadable tar archives.N)rurvrwrxr4r4r4r5rzMsrzc@seZdZdZdS)CompressionErrorz.Exception for unavailable compression methods.N)rurvrwrxr4r4r4r5r{Psr{c@seZdZdZdS)StreamErrorz=Exception for unsupported operations on stream-like TarFiles.N)rurvrwrxr4r4r4r5r|Ssr|c@seZdZdZdS)HeaderErrorz!Base exception for header errors.N)rurvrwrxr4r4r4r5r}Vsr}c@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rurvrwrxr4r4r4r5r~Ysr~c@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rurvrwrxr4r4r4r5r\src@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rurvrwrxr4r4r4r5r_src@seZdZdZdS)rBzException for invalid headers.N)rurvrwrxr4r4r4r5rBbsrBc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rurvrwrxr4r4r4r5resrc@s0eZdZdZddZddZddZdd	Zd
S)
_LowLevelFilezLow-level file object. Supports reading and writing.
       It is used instead of a regular file object for streaming
       access.
    cCsFtjtjtjBtjBd|}ttdr2|tjO}tj||d|_dS)N)rfrgO_BINARYi)	osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrropenfd)selfnamerpr4r4r5__init__rs

z_LowLevelFile.__init__cCstj|jdS)N)rcloser)rr4r4r5r{sz_LowLevelFile.closecCstj|j|S)N)rrYr)rrr4r4r5rY~sz_LowLevelFile.readcCstj|j|dS)N)rrZr)rr0r4r4r5rZsz_LowLevelFile.writeN)rurvrwrxrrrYrZr4r4r4r5rls
	rc@steZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZdddZdddZ
ddZddZdS)_StreamaClass 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.
    cCsRd|_|dkrt||}d|_|dkr6t|}|j}|p<d|_||_||_||_||_d|_	d|_
d|_y|dkryddl}Wnt
k
rtd	YnX||_|jd|_|d
kr|jn|j|dkr$yddl}Wnt
k
rtdYnX|d
krd|_|j|_n
|j|_Wn&|js@|jjd|_YnXdS)
z$Construct a _Stream object.
        TNF*rlrgzzzlib module is not availablerfbz2zbz2 module is not available)_extfileobjr_StreamProxygetcomptyperrpcomptypefileobjbufsizerWposclosedzlibImportErrorr{crc32crc
_init_read_gz_init_write_gzrdbufBZ2Decompressorcmp
BZ2Compressorr)rrrprrrrrr4r4r5rsP





z_Stream.__init__cCst|dr|jr|jdS)Nr)rrr)rr4r4r5__del__sz_Stream.__del__cCs|jjd|jj|jj|jjd|_tjdtt	j	}|j
d|d|jjdrf|jdd|_|j
|jj
d	d
tdS)z6Initialize for writing with gzip compression.
        	rz<Lssz.gzNrz
iso-8859-1replace)rZcompressobjZDEFLATED	MAX_WBITSZ
DEF_MEM_LEVELrrLrNr@time_Stream__writerendswithr-r/)rZ	timestampr4r4r5rsz_Stream._init_write_gzcCsR|jdkr|jj||j|_|jt|7_|jdkrD|jj|}|j|dS)z&Write string s to the stream.
        rtarN)	rrrrrr.rcompressr)rr0r4r4r5rZs

z
_Stream.writecCsR|j|7_x>t|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|jd@|js|jj
d|_dS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        Nrgrrrz<LlT)rrprrWrflushrrZrLrNrrrr)rr4r4r5rs

z
_Stream.closecCs|jj|jj|_d|_|jddkr0td|jddkrFtdt|jd}|jd|d	@rt|jdd
t|jd}|j	||d@rx|jd}|s|t
krPqW|d@rx|jd}|s|t
krPqW|d@r|jdd
S)z:Initialize for reading a gzip compressed fileobj.
        rrsznot a gzip filerzunsupported compression methodr*r$r)r(N)rZ
decompressobjrrr
_Stream__readrzr{rDrYr/)rflagZxlenr0r4r4r5rs.
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r)rr4r4r5tell#sz_Stream.tellrcCs\||jdkrNt||j|j\}}xt|D]}|j|jq.W|j|ntd|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)rr[rrCrYr|)rrr_r`rFr4r4r5seek(sz_Stream.seekNcCsZ|dkr:g}x |j|j}|s P|j|qWdj|}n
|j|}|jt|7_|S)zReturn the next size number of bytes from the stream.
           If size is not defined, return all bytes of the stream
           up to EOF.
        Nrl)_readrrnrorr.)rrrjrWr4r4r5rY5s
z_Stream.readcCs|jdkr|j|St|j}xf||kr|j|j}|s:Py|jj|}Wntk
rftdYnX|j|7_|t|7}q W|jd|}|j|d|_|S)z+Return size bytes from the stream.
        rzinvalid compressed dataN)	rrr.rrr
decompressr\rz)rrrerWr4r4r5rGs 



z
_Stream._readcCsht|j}x:||krD|jj|j}|s(P|j|7_|t|7}qW|jd|}|j|d|_|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        N)r.rWrrYr)rrrerWr4r4r5Z__read\s

z_Stream.__read)r)N)rurvrwrxrrrrZrrrrrrYrrr4r4r4r5rs	4
	

rc@s0eZdZdZddZddZddZdd	Zd
S)rzsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs||_|jjt|_dS)N)rrY	BLOCKSIZErW)rrr4r4r5rqsz_StreamProxy.__init__cCs|jj|_|jS)N)rrYrW)rrr4r4r5rYus
z_StreamProxy.readcCs$|jjdrdS|jjdr dSdS)NsrsBZh91rr)rW
startswith)rr4r4r5rys
z_StreamProxy.getcomptypecCs|jjdS)N)rr)rr4r4r5rsz_StreamProxy.closeN)rurvrwrxrrYrrr4r4r4r5rls
rc@sLeZdZdZdZddZddZdd	Zd
dZdd
Z	ddZ
ddZdS)	_BZ2ProxyaSmall 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.
    r(icCs(||_||_t|jdd|_|jdS)Nr)rrpgetattrrinit)rrrpr4r4r5rsz_BZ2Proxy.__init__cCsDddl}d|_|jdkr6|j|_|jjdd|_n
|j|_dS)Nrrfr)	rrrprbz2objrrrWr)rrr4r4r5rs

z_BZ2Proxy.initcCst|j}xF||krP|jj|j}|s(P|jj|}|j|7_|t|7}qW|jd|}|j|d|_|jt|7_|S)N)r.rWrrY	blocksizerrr)rrrirawdatarWr4r4r5rYs

z_BZ2Proxy.readcCs&||jkr|j|j||jdS)N)rrrY)rrr4r4r5rs
z_BZ2Proxy.seekcCs|jS)N)r)rr4r4r5rsz_BZ2Proxy.tellcCs.|jt|7_|jj|}|jj|dS)N)rr.rrrrZ)rrrr4r4r5rZsz_BZ2Proxy.writecCs$|jdkr |jj}|jj|dS)Nrg)rprrrrZ)rrr4r4r5rs

z_BZ2Proxy.closeNi@)rurvrwrxrrrrYrrrZrr4r4r4r5rs
rc@s<eZdZdZd
ddZddZddZd	d
ZdddZdS)_FileInFilezA thin wrapper around an existing file object that
       provides a part of its data as an individual file
       object.
    NcCs||_||_||_d|_|dkr*d|fg}d|_g|_d}|j}xT|D]L\}}||krj|jjd||df|jjd||||f||7}||}qFW||jkr|jjd||jdfdS)NrFT)roffsetrposition	map_indexmaprn)rrrrZ	blockinfoZlastposZrealposr4r4r5rs$

z_FileInFile.__init__cCst|jdsdS|jjS)NseekableT)rrr)rr4r4r5rsz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r)rr4r4r5rsz_FileInFile.tellcCs
||_dS)z(Seek to a position in the file.
        N)r)rrr4r4r5rsz_FileInFile.seekcCs|dkr|j|j}nt||j|j}d}x|dkrxZ|j|j\}}}}||jko`|knrjPq8|jd7_|jt|jkr8d|_q8Wt|||j}|r|jj||j|||jj|7}n|t	|7}||8}|j|7_q.W|S)z!Read data from the file.
        Nrrr)
rrminrrr.rrrYr/)rrrWrstartstoprr1r4r4r5rYs(

z_FileInFile.read)N)N)	rurvrwrxrrrrrYr4r4r4r5rs
rc@szeZdZdZdZddZddZddZd	d
Zddd
Z	e	Z
dddZddZddZ
ejfddZddZddZdS)ExFileObjectzaFile-like object for reading an archive member.
       Is returned by TarFile.extractfile().
    icCsDt|j|j|j|j|_|j|_d|_d|_|j|_d|_d|_	dS)NrfFrr)
rroffset_datarsparserrprrbuffer)rtarfiletarinfor4r4r5rs
zExFileObject.__init__cCsdS)NTr4)rr4r4r5readable!szExFileObject.readablecCsdS)NFr4)rr4r4r5writable$szExFileObject.writablecCs
|jjS)N)rr)rr4r4r5r'szExFileObject.seekableNcCs|jrtdd}|jrL|dkr.|j}d|_n|jd|}|j|d|_|dkrd||jj7}n||jj|t|7}|jt|7_|S)z~Read at most size bytes from the file. If size is not
           present or None, read all data until EOF is reached.
        zI/O operation on closed filerN)rrArrrYr.r)rrrWr4r4r5rY*szExFileObject.readrcCs|jrtd|jjdd}|dkrzxR|jj|j}|j|7_|sRd|kr(|jjdd}|dkrtt|j}Pq(W|dkrt||}|jd|}|j|d|_|j	t|7_	|S)zRead 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.
        zI/O operation on closed file
rrNr7)
rrArr8rrYrr.rr)rrrrWr4r4r5readlineEs$

zExFileObject.readlinecCs&g}x|j}|sP|j|qW|S)z0Return a list with all remaining lines.
        )rrn)rresultliner4r4r5	readlinesbszExFileObject.readlinescCs|jrtd|jS)z*Return the current file position.
        zI/O operation on closed file)rrAr)rr4r4r5rlszExFileObject.tellcCs|jrtd|tjkr.tt|d|j|_nj|tjkrj|dkrTt|j|d|_qt|j||j|_n.|tj	krtt|j||jd|_ntdd|_
|jj|jdS)z(Seek to a position in the file.
        zI/O operation on closed filerzInvalid argumentrN)
rrArSEEK_SETrmaxrrSEEK_CURSEEK_ENDrrr)rrwhencer4r4r5rts


zExFileObject.seekcCs
d|_dS)zClose the file object.
        TN)r)rr4r4r5rszExFileObject.closeccsx|j}|sP|VqWdS)z/Get an iterator over the file's lines.
        N)r)rrr4r4r5__iter__s
zExFileObject.__iter__)Nr7)r7)rurvrwrxrrrrrrYread1rrrrrrrrr4r4r4r5rs



rc@seZdZdZdiZdjddZddZddZeeeZ	ddZ
dd Zee
eZd!d"Z
d#d$Zeed%fd&d'Zd(d)Zd*d+Zd,d-Zed.d/Zd0d1Zed2d3Zed4d5Zed6d7Zed8d9Zed:d;Zed<d=Zd>d?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#devmajordevminorrrpax_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)z<Return a tar header as a string of 512 byte blocks.
        zinvalid formatN)rUSTAR_FORMATcreate_ustar_headerrKcreate_gnu_header
PAX_FORMATcreate_pax_headerrA)rrRr2r3rr4r4r5tobufsz
TarInfo.tobufcCsZt|d<t|dtkr tdt|dtkrJ|j|d\|d<|d<|j|t||S)z3Return the object as a ustar header block.
        magicrzlinkname is too longrprefix)POSIX_MAGICr.LENGTH_LINKrALENGTH_NAME_posix_split_name_create_headerr)rrr2r3r4r4r5rszTarInfo.create_ustar_headercCspt|d<d}t|dtkr4||j|dt||7}t|dtkr\||j|dt||7}||j|t||S)z:Return the object as a GNU header block sequence.
        rrrr)		GNU_MAGICr.r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErrK)rrr2r3rWr4r4r5rszTarInfo.create_gnu_headerc
Cs4t|d<|jj}xddtfddtfddfD]h\}}}||kr@q,y||jd	d
Wn"tk
rv||||<w,YnXt|||kr,||||<q,WxldD]d\}}||krd||<q||}d|kod|dknst|t	rt
|||<d||<qW|r|j|t|}	nd}	|	|j
|td	dS)zReturn the object as a ustar header block. If it cannot be
           represented this way, prepend a pax extended header sequence
           with supplement information.
        rrrrrr"r'r#r<r=r r)r!rrrrrr)r"r"r')r#r#r'r r)r!r)rrrr)rrr	r
)rrcopyrrr-UnicodeEncodeErrorr.
isinstancefloatstr_create_pax_generic_headerXHDTYPErr)
rrr2rrZhnamer1rQvalrWr4r4r5rs4
.zTarInfo.create_pax_headercCs|j|tdS)zAReturn the object as a pax global header block sequence.
        utf8)rXGLTYPE)clsrr4r4r5create_pax_global_headerDsz TarInfo.create_pax_global_headercCsp|dtd}x |r0|ddkr0|dd}qW|t|d}|dd}|s`t|tkrhtd||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        Nrrzname is too longr7r7r7)
LENGTH_PREFIXr.rrA)rrrr4r4r5rJszTarInfo._posix_split_namecCsVt|jddd||t|jddd@d|t|jddd|t|jd	dd|t|jd
dd|t|jddd|d
|jdtt|jddd|||jdtt|jddd||t|jddd||t|jddd|t|jddd|t|jddd||g}tjdtdj|}t	|tdd}|ddd|j
d|d d}|S)!zReturn a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        rrlr
rprir)r r!rrrs        rrrr"r'r#rrrrz%dsrNilz%06or<ieii)r6getrSrrrLrNrrorXr-)rrRr2r3partsrWrr4r4r5rYs&

&zTarInfo._create_headercCs.tt|t\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes
           up to the next 512 byte border.
        r)r[r.rr/)Zpayloadr_r`r4r4r5_create_payloaduszTarInfo._create_payloadcCsR|j||t}i}d|d<||d<t||d<t|d<|j|t|||j|S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
           for name.
        z
././@LongLinkrrrr)r-r/r.rrrr)rrrr2r3rr4r4r5rszTarInfo._create_gnu_long_headercCs:d}x@|jD]4\}}y|jddWqtk
r@d}PYqXqWd}|rV|d7}x|jD]\}}|jd}|r|j|d}n
|jd}t|t|d}d	}	}
x"|tt|
}	|	|
krP|	}
qW|tt|
d
d|d|d
7}q`Wi}d|d<||d<t||d<t|d<|j|td
d|j	|S)zReturn a POSIX.1-2008 extended or global header sequence
           that contains a list of keyword, value pairs. The values
           must be strings.
        Frr=Trs21 hdrcharset=BINARY
rrrr< =rz././@PaxHeaderrrrrr)
itemsr-rr.rbytesrrrr)rrrr2ZbinarykeywordvalueZrecordsrIrEr:rr4r4r5rs<

*z"TarInfo._create_pax_generic_headercCstt|dkrtdt|tkr(td|jttkr>tdt|dd}|t|krbt	d|}t
|dd|||_t|dd	|_t|d	d
|_
t|d
d|_t|dd|_t|dd|_||_|dd
|_t
|d
d|||_t
|dd|||_t
|dd|||_t|dd|_t|dd|_t
|dd||}|jtkr|jjdrt|_|jtkr6d}g}xrtdD]f}	y0t|||d}
t||d|d}Wntk
rPYnX|j|
|f|d7}qWt|d}t|dd}
|||
f|_ |j!rN|jj"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.r4r4r5fromtarfiles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
djd|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=rrrrrresearchgroupr9rr2compilematchgroupsr@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
<listcomp>sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>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,rr)rrr2r3rr r4r4r5r>s"

zTarInfo._apply_pax_infocCs.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_FORMATENCODINGrrrrclassmethodrrstaticmethodrrrrr3r5r4r:r6r7r9rMrLrNr>rJr=r;r[r+r]r_rarcrerfrgr4r4r4r5rs`



1
3?
f	c@seZdZdZdZdZdZdZeZ	e
ZdZe
ZeZdVdd	Zedddefd
dZedWd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)d<d=Z*d>d?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|dkrt	|dr|j
}t	|d
r|j|_d|_|rtjj|nd|_
||_|dk	r||_
|dk	r||_|dk	r||_|dk	r||_|dk	r||_|	|_|
dk	r(|j
tkr(|
|_ni|_|dk	r>||_|dk	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%|
WYdd}
~
XnXqW|jdkrnd|_|jrn|jj&|jj'}|jj(||jt|7_Wn&|js|jj)d|_YnXdS)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_openrrrabspathrrRrdereferenceignore_zerosr2r3rrdebug
errorlevelrmembers_loadedrrinodesfirstmemberr?rr5rnrr}rzrrrrZr)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}|
dkrFtd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
tdYnXd	|_|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.<locals>.<listcomp>)r)rr4r4r5getnamesqszTarFile.getnamescCsp|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
|jfddntd|jddtdt
j|jdd	ddt|j|jrd
nddd|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|||||dq0Wn
|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





zTarFile.addcCs|jdtj|}|j|j|j|j}|jj||jt	|7_|dk	rt
||j|jt|jt
\}}|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)rrrrRr2r3rrZrr.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)rpr4r4r5<lambda>dsz$TarFile.extractall.<locals>.<lambda>)keyrztarfile: %s)r+rnrrpextractsortreverserrrorchownutimechmodryryr)rrrzZdirectoriesrdirpathr~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)rrNrztarfile: %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
trtt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
|jdS)z<Make a character or block device called targetpath.
        mknodrz'special devices not supported by systemN)rrryrprcrS_IFBLKS_IFCHRrrrr)rrrrpr4r4r5r	s
zTarFile.makedevcCsyL|jrtj|j|n0tjj|jr8tj|j|n|j|j	||Wn>t
k
r|jrtjjtjj|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}~Xntk
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<WdS)z}Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        N)rindexrrnormpathreversedr)rrr	normalizerzrmember_namer4r4r5r	szTarFile._getmembercCs"x|j}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r?r{)rrr4r4r5r	s
z
TarFile._loadcCs:|jrtd|jj|dk	r6|j|kr6td|jdS)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)rr\rrurp)rrpr4r4r5r	szTarFile._checkcCsX|jr&tjj|jd|j}d}n
|j}|}|j||dd}|dkrTtd||S)zZFind the target member of a symlink or hardlink member in the
           archive.
        rNT)rrzlinkname %r not found)r]rrrrrrr)rrrlimitrr4r4r5r	szTarFile._find_link_targetcCs|jrt|jSt|SdS)z$Provide an iterator object.
        N)r{iterrzTarIter)rr4r4r5r	s
zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr.
        )fileN)rxrrstderr)rlevelmsgr4r4r5r	s
zTarFile._dbgcCs|j|S)N)r)rr4r4r5	__enter__	szTarFile.__enter__cCs,|dkr|jn|js"|jjd|_dS)NT)rrrr)rrr 	tracebackr4r4r5__exit__	s


zTarFile.__exit__)NrfNNNNNNrNNN)rfN)rfNr)rfNr)NNN)T)NTNN)N)rN)rlT)T)NF)N)7rurvrwrxrxrvrwryrjrRrkr2r3rrrrrrlrrrrrrrrrrrrPrrrrrrrrrrrrrrrr?rrrrrrrrr4r4r4r5r,sl
iK

b

>

&
#&
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__cCsb|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
rcCs.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__rrrrrrLrrCrrrrNotImplementedErrorrZ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~rrrBrobjectrrrrrrrrrrrtr4r4r4r5<module>s>




i?KT*
Back to Directory File Manager