HEX

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit - prohibited by configuration in /home/u547966/brikov.ru/www/wp-content/plugins/admin-menu-editor/menu-editor.php on line 745
Server: Apache
System: Linux 4.19.0-0.bpo.9-amd64 x86_64 at red40
User: u547966 (5490)
PHP: 5.3.29-mh2
Disabled: syslog, dl, popen, proc_open, proc_nice, proc_get_status, proc_close, proc_terminate, posix_mkfifo, chown, chgrp, accelerator_reset, opcache_reset, accelerator_get_status, opcache_get_status, pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wifcontinued, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority
Upload Files
File: //usr/lib/python3.5/__pycache__/tarfile.cpython-35.pyc


Fak@sdZdZdZdZdZdZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZyddlZddlZWnek
rdZZYnXeefZyeef7ZWnek
rYnXd	d
ddgZd
ZdZedZdZdZdZ dZ!dZ"dZ#d
Z$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0d!Z1dZ2d"Z3d#Z4e3Z5e#e$e%e&e)e*e+e'e(e,e-e.fZ6e#e$e+e.fZ7e,e-e.fZ8d$d%d&d'd(d)d*d+fZ9d$d%d*d+hZ:d,e;d-e;d'e;d(e<d)e<d&e<iZ=e
j>d.d/fkrd0Z?ne	j@Z?d1d2ZAd3d4ZBd5d6ZCd7e5d8d9ZDd:d;ZEded<d=ZFd>d?ZGd@dAZHGdBddeIZJGdCdDdDeJZKGdEdFdFeJZLGdGdHdHeJZMGdIdJdJeJZNGdKdLdLeJZOGdMdNdNeOZPGdOdPdPeOZQGdQdRdReOZRGdSdTdTeOZSGdUdVdVeOZTGdWdXdXZUGdYdZdZZVGd[d\d\eWZXGd]d^d^eWZYGd_d`d`ejZZ[Gdad
d
eWZ\Gdbd	d	eWZ]GdcddddZ^dedZ_e]jZdfdgZ`eadhkre`dS)iz,Read from and write to tar format archives.
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.)openNTarFileTarInfo
is_tarfileTarErrorsisustar  sustar00d01234567LKSxgXpathlinkpathsizemtimeuidgidunamegnameZatimeZctimentZcezutf-8cCs2|j||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    N)encodelenNUL)slengthencodingerrorsr*/usr/lib/python3.5/tarfile.pystnsr,cCs;|jd}|dkr+|d|}|j||S)z8Convert a null-terminated bytes object to a string.
    srN)finddecode)r&r(r)pr*r*r+ntssr1cCs|ddkrd}x:tt|dD]"}|dK}|||d7}q-W|ddkrdt|d|}nRy1t|dd}t|jpd	d}Wntk
rtd
YnX|S)z/Convert a number field to a python number.
    rrasciistrict0zinvalid header)r2r3)ranger$r1intstrip
ValueErrorInvalidHeaderError)r&nir*r*r+ntis

r@r4cCsd|kod|dknrNtd|dt|fdt}n|tkrd|d|kod|dknr|dkrtdg}ntdg}d||}xEt|dD]$}|jd|d@|dL}qWntd	|S)
z/Convert a python number to a number field.
    rr4rz%0*or6r5r2r3zoverflow in number field)bytesr:r%
GNU_FORMAT	bytearrayr9insertr<)r>digitsformatr&r?r*r*r+itns$*9rGcCsBdttjd|}dttjd|}||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.
    r5Z
148B8x356BZ
148b8x356b)sumstructZunpack_from)bufZunsigned_chksumZ
signed_chksumr*r*r+calc_chksumss	rKc	Cs|dkrdS|dkr0tj||dSd}t||\}}xNt|D]@}|j|}t||kr|d|j|qXW|dkr|j|}t||kr|d|j|dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    rNizunexpected end of datai@)shutilcopyfileobjdivmodr9readr$write)	srcZdstr'	exceptionZBUFSIZEblocks	remainderbrJr*r*r+rNs$
rNcCs,ddl}|jdtdtj|S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder)warningswarnDeprecationWarningstatfilemode)moderWr*r*r+r[s	
r[cCsPttjdd}|dk	r<|j|dj|}t|dddS)Nr(backslashreplaceend )getattrsysstdoutr#r/print)r&r(r*r*r+_safe_printsrdc@seZdZdZdS)rzBase exception.N)__name__
__module____qualname____doc__r*r*r*r+rsc@seZdZdZdS)ExtractErrorz%General exception for extract errors.N)rerfrgrhr*r*r*r+risric@seZdZdZdS)	ReadErrorz&Exception for unreadable tar archives.N)rerfrgrhr*r*r*r+rjsrjc@seZdZdZdS)CompressionErrorz.Exception for unavailable compression methods.N)rerfrgrhr*r*r*r+rksrkc@seZdZdZdS)StreamErrorz=Exception for unsupported operations on stream-like TarFiles.N)rerfrgrhr*r*r*r+rlsrlc@seZdZdZdS)HeaderErrorz!Base exception for header errors.N)rerfrgrhr*r*r*r+rmsrmc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rerfrgrhr*r*r*r+rnsrnc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rerfrgrhr*r*r*r+ro sroc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rerfrgrhr*r*r*r+rp#srpc@seZdZdZdS)r=zException for invalid headers.N)rerfrgrhr*r*r*r+r=&sr=c@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rerfrgrhr*r*r*r+rq)srqc@sFeZdZdZddZddZddZdd	Zd
S)
_LowLevelFilezLow-level file object. Supports reading and writing.
       It is used instead of a regular file object for streaming
       access.
    cCsbdtjdtjtjBtjBi|}ttdrF|tjO}tj||d|_dS)NrwO_BINARYi)	osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrrurfd)selfnamer\r*r*r+__init__6s	
z_LowLevelFile.__init__cCstj|jdS)N)rvcloser|)r}r*r*r+r?sz_LowLevelFile.closecCstj|j|S)N)rvrPr|)r}rr*r*r+rPBsz_LowLevelFile.readcCstj|j|dS)N)rvrQr|)r}r&r*r*r+rQEsz_LowLevelFile.writeN)rerfrgrhrrrPrQr*r*r*r+rr0s
	rrc@seZdZdZddZddZddZdd	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.
    c	Cs{d|_|dkr-t||}d|_|dkrQt|}|j}|pZd|_||_||_||_||_d|_	d|_
d|_y|dkr,yddl}Wnt
k
rtd	YnX||_|jd|_|d
kr|j|j|_qI|jn|dkryddl}Wnt
k
rhtdYnX|d
krd|_|j|_t|_qI|j|_n|d
kr-yddl}Wnt
k
rtdYnX|d
krd|_|j|_|j|_qI|j|_n|dkrItd|Wn*|jsf|jjd|_YnXdS)z$Construct a _Stream object.
        TNF*rgzzzlib module is not availablersbz2zbz2 module is not availablexzzlzma module is not availabletarzunknown compression type %r) _extfileobjrr_StreamProxygetcomptyper~r\comptypefileobjbufsizerJposclosedzlibImportErrorrkcrc32crc
_init_read_gzerrorrS_init_write_gzrdbufZBZ2DecompressorcmpOSErrorZ
BZ2CompressorlzmaZLZMADecompressor	LZMAErrorZLZMACompressorr)	r}r~r\rrrrrrr*r*r+rSsl									
	


	
		
	z_Stream.__init__cCs't|dr#|jr#|jdS)Nr)r{rr)r}r*r*r+__del__sz_Stream.__del__cCs|jjd|jj|jj|jjd|_tjdtt	j	}|j
d|d|jjdr|jdd|_|j
|jj
d	d
tdS)z6Initialize for writing with gzip compression.
        	rz<Lssz.gzNz
iso-8859-1replace)rZcompressobjZDEFLATED	MAX_WBITSZ
DEF_MEM_LEVELrrIpackr:time_Stream__writer~endswithr#r%)r}Z	timestampr*r*r+rs
	z_Stream._init_write_gzcCsq|jdkr*|jj||j|_|jt|7_|jdkr`|jj|}|j|dS)z&Write string s to the stream.
        rrN)	rrrrrr$rcompressr)r}r&r*r*r+rQsz
_Stream.writecCsk|j|7_xUt|j|jkrf|jj|jd|j|j|jd|_qWdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rJr$rrrQ)r}r&r*r*r+Z__writes z_Stream.__writecCs|jr
dSd|_z|jdkrO|jdkrO|j|jj7_|jdkr|jr|jj|jd|_|jdkr|jjtj	d|j
|jjtj	d|jd@Wd|js|jj
XdS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        NTrtrrrz<Ll)rr\rrJrflushrrQrIrrrrr)r}r*r*r+rs			'	z
_Stream.closecCsO|jj|jj|_d|_|jddkrFtd|jddkrgtdt|jd}|jd|d	@rt|jdd
t|jd}|j	||d@rx'|jd}|s|t
krPqW|d@r4x'|jd}|s/|t
kr
Pq
W|d@rK|jdd
S)z:Initialize for reading a gzip compressed fileobj.
        rrsznot a gzip filerszunsupported compression methodr5r4rLN)rZ
decompressobjrrr
_Stream__readrjrkordrPr%)r}ZflagZxlenr&r*r*r+rs.	

,



z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r)r}r*r*r+tellsz_Stream.tellrcCs|||jdkrit||j|j\}}x$t|D]}|j|jq?W|j|ntd|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)rrOrr9rPrl)r}rrTrUr?r*r*r+seeksz_Stream.seekNcCsy|dkrQg}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.
        Nr)_readrappendjoinrr$)r}rtrJr*r*r+rPsz_Stream.readcCs|jdkr|j|St|j}x||kr|j|j}|sSPy|jj|}Wn!|jk
rtdYnX|j|7_|t|7}q.W|jd|}|j|d|_|S)z+Return size bytes from the stream.
        rzinvalid compressed dataN)	rrr$rrrZ
decompressrSrj)r}rcrJr*r*r+rs 
z
_Stream._readcCst|j}xK||kr\|jj|j}|s:P|j|7_|t|7}qW|jd|}|j|d|_|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        N)r$rJrrPr)r}rrrJr*r*r+Z__read,sz_Stream.__read)rerfrgrhrrrrQrrrrrrPrrr*r*r*r+rHs	F
	
rc@sFeZdZdZddZddZddZdd	Zd
S)rzsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs"||_|jjt|_dS)N)rrP	BLOCKSIZErJ)r}rr*r*r+rAs	z_StreamProxy.__init__cCs|jj|_|jS)N)rrPrJ)r}rr*r*r+rPEsz_StreamProxy.readcCsj|jjdrdS|jdddkrL|jdddkrLd	S|jjdrbdSd
SdS)NsrrrsBZhr
s1AY&SYr]7zXZrr)rr)rJ
startswith)r}r*r*r+rIs2z_StreamProxy.getcomptypecCs|jjdS)N)rr)r}r*r*r+rSsz_StreamProxy.closeN)rerfrgrhrrPrrr*r*r*r+r<s

rc@seZdZdZdddZddZddZd	d
ZddZd
dZ	e
jddZdddZ
ddZddZdS)_FileInFilezA thin wrapper around an existing file object that
       provides a part of its data as an individual file
       object.
    NcCs#||_||_||_d|_t|dd|_d|_|dkr]d|fg}d|_g|_d}|j}xp|D]h\}}||kr|jj	d||df|jj	d||||f||7}||}qW||jkr|jj	d||jdfdS)Nrr~FT)
roffsetrpositionr`r~r	map_indexmapr)r}rrrZ	blockinfoZlastposZrealposr*r*r+r`s(								 
z_FileInFile.__init__cCsdS)Nr*)r}r*r*r+rysz_FileInFile.flushcCsdS)NTr*)r}r*r*r+readable|sz_FileInFile.readablecCsdS)NFr*)r}r*r*r+writablesz_FileInFile.writablecCs
|jjS)N)rseekable)r}r*r*r+rsz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r)r}r*r*r+rsz_FileInFile.tellcCs|tjkr0tt|d|j|_n|tjkr|dkrgt|j|d|_qt|j||j|_nC|tjkrtt|j||jd|_ntd|jS)z(Seek to a position in the file.
        rzInvalid argument)	ioSEEK_SETminmaxrrSEEK_CURSEEK_ENDr<)r}rwhencer*r*r+rs!(z_FileInFile.seekc	Csf|dkr|j|j}nt||j|j}d}x!|dkraxs|j|j\}}}}||jko|knrPqP|jd7_|jt|jkrPd|_qPWt|||j}|r7|jj||j||jj|}t||kr*t	d||7}n|t
|7}||8}|j|7_qAW|S)z!Read data from the file.
        Nrrrzunexpected end of data)rrrrrr$rrrPrjr%)	r}rrJdatastartstoprr'rVr*r*r+rPs.


z_FileInFile.readcCs5|jt|}||dt|<t|S)N)rPr$)r}rVrJr*r*r+readintosz_FileInFile.readintocCs
d|_dS)NT)r)r}r*r*r+rsz_FileInFile.close)rerfrgrhrrrrrrrrrrPrrr*r*r*r+rZsrcs"eZdZfddZS)ExFileObjectcs5t|j|j|j|j}tj|dS)N)rroffset_datarsparsesuperr)r}tarfiletarinfor)	__class__r*r+rszExFileObject.__init__)rerfrgrr*r*)rr+rsrc@sPeZdZdZdiZdddZddZddZeeeZ	ddZ
dd Zee
eZd!d"Z
d#d$Zeed%d&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)jraInformational 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~r\rrrrchksumtypelinknamer r!devmajordevminorrrpax_headersrr_sparse_structs_link_targetrcCs||_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.
        irrN)r~r\rrrrrREGTYPErrr r!rrrrrr)r}r~r*r*r+rs"																zTarInfo.__init__cCs|jS)N)r~)r}r*r*r+_getpathszTarInfo._getpathcCs
||_dS)N)r~)r}r~r*r*r+_setpathszTarInfo._setpathcCs|jS)N)r)r}r*r*r+_getlinkpathszTarInfo._getlinkpathcCs
||_dS)N)r)r}rr*r*r+_setlinkpathszTarInfo._setlinkpathcCs d|jj|jt|fS)Nz<%s %r at %#x>)rrer~id)r}r*r*r+__repr__szTarInfo.__repr__cCsd|jd|jd@d|jd|jd|jd|jd|jd	|jd
|jd|j	d|j
d
|jd|ji
}|d	t
kr|djdr|dd7<|S)z9Return the TarInfo's attributes as a dictionary.
        r~r\irrrrrrrr r!rr/)r~r\rrrrrrrr r!rrDIRTYPEr)r}infor*r*r+get_infos 	
										$zTarInfo.get_infosurrogateescapecCsv|j}|tkr+|j|||S|tkrJ|j|||S|tkrf|j||StddS)z<Return a tar header as a string of 512 byte blocks.
        zinvalid formatN)rUSTAR_FORMATcreate_ustar_headerrBcreate_gnu_header
PAX_FORMATcreate_pax_headerr<)r}rFr(r)rr*r*r+tobufsz
TarInfo.tobufcCst|d<t|dj||tkr8tdt|dj||tkr|j|d||\|d<|d<|j|t||S)z3Return the object as a ustar header block.
        magicrzlinkname is too longr~prefix)	POSIX_MAGICr$r#LENGTH_LINKr<LENGTH_NAME_posix_split_name_create_headerr)r}rr(r)r*r*r+r*s
""'zTarInfo.create_ustar_headercCst|d<d}t|dj||tkrR||j|dt||7}t|dj||tkr||j|dt||7}||j|t	||S)z:Return the object as a GNU header block sequence.
        rrrr~)
	GNU_MAGICr$r#r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErrB)r}rr(r)rJr*r*r+r7s
" " zTarInfo.create_gnu_headerc
Cst|d<|jj}xddtfddtfddfD]\}}}||kr\q>y||jd	d
Wn#tk
r||||<w>YnXt|||kr>||||<q>WxdD]}\}}||krd||<q||}d|kod|dkns,t|t	rt
|||<d||<qW|rh|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.
        rr~rrrr  r!r6r7rr4rrrrrrr)r r r)r!r!rrr4rr4rrrr)rrrr)rrcopyrrr#UnicodeEncodeErrorr$
isinstancefloatstr_create_pax_generic_headerXHDTYPErr)
r}rr(rr~Zhnamer'rEvalrJr*r*r+rEs4



4zTarInfo.create_pax_headercCs|j|tdS)zAReturn the object as a pax global header block sequence.
        zutf-8)rXGLTYPE)clsrr*r*r+create_pax_global_headervsz TarInfo.create_pax_global_headercCs|jd}xtdt|D]u}dj|d|}dj||d}t|j||tkr%t|j||tkr%Pq%Wtd||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        rrNzname is too long)splitr9r$rr#
LENGTH_PREFIXrr<)r}r~r(r)Z
componentsr?rr*r*r+r|szTarInfo._posix_split_namecCst|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}|ddt
d|d|d d}|S)!zReturn a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        r~rrr\rir4rrrrrs        rrrr rr!rrrr	z%dsrNilz%06or6ieii)r,getrGrrrIrrrrKrA)rrFr(r)partsrJrr*r*r+rs&$/zTarInfo._create_headercCs=tt|t\}}|dkr9|t|t7}|S)zdReturn the string payload filled with zero bytes
           up to the next 512 byte border.
        r)rOr$rr%)ZpayloadrTrUr*r*r+_create_payloadszTarInfo._create_payloadcCsm|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
././@LongLinkr~rrr)r#r%r$rrrr
)rr~rr(r)rr*r*r+rs


zTarInfo._create_gnu_long_headercCsd}xJ|jD]<\}}y|jddWqtk
rNd}PYqXqWd}|ri|d7}x|jD]\}}|jd}|r|j|d}n|jd}t|t|d}d	}	}
x-|tt|
}	|	|
krP|	}
qW|tt|
d
d|d|d
7}qvWi}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.
        Fzutf-8r7Trs21 hdrcharset=BINARY
rrrr6 =s
z././@PaxHeaderr~rrrr)
itemsr#rr$rrArrrr
)rrrr(ZbinarykeywordvalueZrecordslr>r0rr*r*r+rs<




1


z"TarInfo._create_pax_generic_headercCsNt|dkrtdt|tkr<td|jttkr]tdt|dd}|t|krt	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'|jjdr't|_|jtkrd}g}xtdD]u}	y<t|||d}
t||d|d}Wntk
rPYnX|j|
|f|d7}qOWt|d}t|dd}
|||
f|_ |j!r!|jj"d|_|rJ|jt#krJ|d|j|_|S)zAConstruct a TarInfo object from a 512 byte bytes object.
        rzempty headerztruncated headerzend of file headerzbad checksumrlt|ii	i)iIiQiYirirriii)$r$rnrrocountr%rpr@rKr=r1r~r\rrrrrrrr r!rrAREGTYPErrGNUTYPE_SPARSEr9r<rboolrisdirrstrip	GNU_TYPES)rrJr(r)robjrrstructsr?rnumbytes
isextendedorigsizer*r*r+frombufsZ		!	"
zTarInfo.frombufcCsP|jjt}|j||j|j}|jjt|_|j|S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	rrPrr(r(r)rr_proc_member)rrrJr#r*r*r+fromtarfile5szTarInfo.fromtarfilecCst|jttfkr"|j|S|jtkr>|j|S|jtttfkrc|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)r}rr*r*r+r)Js


zTarInfo._proc_membercCsu|jj|_|j}|js6|jtkrL||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_inforr(r))r}rrr*r*r+r/Ws		zTarInfo._proc_builtincCs|jj|j|j}y|j|}Wntk
rQtdYnX|j|_|jt	krt
||j|j|_
n*|jtkrt
||j|j|_|S)zSProcess the blocks that hold a GNU longname
           or longlink member.
        z missing or bad subsequent header)rrPr2rr*rmrqrrrr1r(r)r~rr)r}rrJnextr*r*r+r+hs
zTarInfo._proc_gnulongc
Cs#|j\}}}|`x|r|jjt}d}xtdD]}y<t|||d}t||d|d}	Wntk
rPYnX|r|	r|j||	f|d7}qFWt|d}qW||_	|jj
|_|j|j|j
|_||_
|S)z8Process a GNU sparse header plus extra headers.
        rrri)rrrPrr9r@r<rrrrrr2rr)
r}rr$r&r'rJrr?rr%r*r*r+r,~s(	"
		zTarInfo._proc_sparsecCs|jj|j|j}|jtkr9|j}n|jj}tj	d|}|dk	r|j
djd|d<|jd}|dkr|j
}nd}tjd}d}x|j||}|sP|j\}	}
t|	}	|	dkrtd	||jd
d|jd|	d}|j|
dd|j}
|
tkr|j|||j
|j}n|j|dd|j}|||
<||	7}qWy|j|}Wntk
rtdYnXd|kr|j||n_d
|kr4|j|||n=|jddkrq|jddkrq|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]+)\nNrzutf-8
hdrcharsetZBINARYs(\d+) ([^=]+)=rzinvalid headerrz missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorr8r)%rrPr2rrrrrresearchgroupr/rr(compilematchgroupsr:r=r^r_decode_pax_fieldr)PAX_NAME_FIELDSr*rmrq_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10rr-r3rrr0r1)r}rrJrr<r6r(Zregexrr'rrr4rr*r*r+r.sd.	

*		zTarInfo._proc_paxcCsg}x6tjd|D]"}|jt|jdqWg}x6tjd|D]"}|jt|jdqXWtt|||_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)r8finditerrr:r:listzipr)r}r4rrJZoffsetsr<r%r*r*r+rAs  zTarInfo._proc_gnusparse_00cCsVdd|djdD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|qSr*)r:).0xr*r*r+
<listcomp>s	z.TarInfo._proc_gnusparse_01.<locals>.<listcomp>zGNU.sparse.map,Nrr)r	rDrEr)r}r4rrr*r*r+r@
s zTarInfo._proc_gnusparse_01cCsd}g}|jjt}|jdd\}}t|}xgt||dkrd|kr}||jjt7}|jdd\}}|jt|qEW|jj|_t	t
|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        Ns
rr)rrPrr	r:r$rrrrDrEr)r}r4rrZfieldsrrJZnumberr*r*r+rBszTarInfo._proc_gnusparse_10c
Csx|jD]\}}|dkr8t|d|q
|dkr]t|dt|q
|dkrt|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_FIELDSr<r!rr)r}rr(r)rrr*r*r+r3#s"
zTarInfo._apply_pax_infocCs=y|j|dSWn"tk
r8|j||SYnXdS)z1Decode a single field from a pax record.
        r7N)r/UnicodeDecodeError)r}rr(Zfallback_encodingZfallback_errorsr*r*r+r>:s
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)rOr)r}rrTrUr*r*r+r2Bs
zTarInfo._blockcCs
|jtkS)N)r
REGULAR_TYPES)r}r*r*r+r0Ksz
TarInfo.isregcCs
|jS)N)r0)r}r*r*r+isfileMszTarInfo.isfilecCs
|jtkS)N)rr)r}r*r*r+r Osz
TarInfo.isdircCs
|jtkS)N)rSYMTYPE)r}r*r*r+issymQsz
TarInfo.issymcCs
|jtkS)N)rLNKTYPE)r}r*r*r+islnkSsz
TarInfo.islnkcCs
|jtkS)N)rCHRTYPE)r}r*r*r+ischrUsz
TarInfo.ischrcCs
|jtkS)N)rBLKTYPE)r}r*r*r+isblkWsz
TarInfo.isblkcCs
|jtkS)N)rFIFOTYPE)r}r*r*r+isfifoYszTarInfo.isfifocCs
|jdk	S)N)r)r}r*r*r+issparse[szTarInfo.issparsecCs|jtttfkS)N)rrTrVrX)r}r*r*r+isdev]sz
TarInfo.isdevN)r~r\rrrrrrrr r!rrrrrrrrr)4rerfrgrh	__slots__rrrpropertyrrrrrrDEFAULT_FORMATENCODINGrrrrclassmethodrrstaticmethodrr
rrr(r*r)r/r+r,r.rAr@rBr3r>r2r0rOr rQrSrUrWrYrZr[r*r*r*r+rs`
1
3?
h	c@seZdZdZdZdZdZdZeZ	e
ZdZe
ZeZdddddddddddddd	Zeddded
dZedddd
ZedddddZedddddZedddddZddddddddiZddZdd Zd!d"Zd#d$Zdddd%d&Zd'd(dd)d*Zdd'dd+dd,d-Z dd.d/Z!d0dd1dd2d3Z"d4d'd1dd5d6Z#d7d8Z$d'dd9d:Z%d;d<Z&d=d>Z'd?d@Z(dAdBZ)dCdDZ*dEdFZ+dGdHZ,dIdJZ-dKdLZ.dMdNZ/dddOdPZ0dQdRZ1ddSdTZ2dUdVZ3dWdXZ4dYdZZ5d[d\Z6d]d^Z7dS)_rz=The TarFile Class provides an interface to tar archives.
    rFrNrsrc
Csddddddddi}
||
kr6td	||_|
||_|s|jdkrtjj|rd|_d|_t||j}d
|_n`|dkrt|drt	|j
ttfr|j
}t|d
r|j|_d|_|rtjj
|nd|_
||_|dk	rC||_|dk	rX||_|dk	rm||_|dk	r||_|dk	r||_|	|_|
dk	r|jtkr|
|_n	i|_|dk	r||_|dk	r||_d
|_g|_d
|_|jj|_i|_y:|jdkrZd|_|j |_|jdkrx|jj!|jy&|jj"|}|jj#|Wqlt$k
r|jj!|jPYqlt%k
r}zt&t|WYdd}~XqlXqlW|jdkrid|_|jri|jj'|jj(}|jj)||jt*|7_Wn*|js|jj+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.
        rsrbazr+brtwbrGZxbz!mode must be 'r', 'a', 'w' or 'x'FNr~r\T)rcrtrG),r<r\_modervrexists	bltn_openrr{rr~rrAabspathrrFrdereferenceignore_zerosr(r)rrdebug
errorlevelrmembers_loadedrrinodesfirstmemberr4rr*rrprmrjrrrQr$r)r}r~r\rrFrrirjr(r)rrkrlZmodeserJr*r*r+r{s	
"				!															
)			
	zTarFile.__init__csY|r|rtd|dkrfdd}xtjd|D]}tj|}|dk	r|j}	y||d||SWqNttfk
r}
z!|dk	r|j|	wNWYdd}
~
XqNXqNWtdnSd	|kr}|jd	d
\}}|p#d}|p/d}|jkrZtj|}ntd||||||Sd
|kr'|jd
d
\}}|pd}|pd}|dkrtdt	|||||}y||||}
Wn|j
YnXd|
_|
S|dkrIj||||StddS)aOpen 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
           'r:xz'       open for reading with lzma 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
           'w:xz'       open for writing with lzma compression

           'x' or 'x:'  create a tarfile exclusively without compression, raise
                        an exception if the file is already created
           'x:gz'       create a gzip compressed tarfile, raise an exception
                        if the file is already created
           'x:bz2'      create a bzip2 compressed tarfile, raise an exception
                        if the file is already created
           'x:xz'       create an lzma compressed tarfile, raise an exception
                        if the file is already created

           '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
           'r|xz'       open an lzma 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
           'w|xz'       open an lzma compressed stream for writing
        znothing to openrsr:*csj|dkS)Ntaropen)	OPEN_METH)r)rr*r+not_compressedsz$TarFile.open.<locals>.not_compressedkeyNz%file could not be opened successfully:rrzunknown compression type %r|rtzmode must be 'r' or 'w'FrcrGzundiscernible mode)rsrr)rsrt)rcrtrG)
r<sortedrtr`rrjrkrr	rrrrs)rr~r\rrkwargsrurfuncZ	saved_posrqr[streamrr*)rr+rsP%

	zTarFile.opencKs+|dkrtd|||||S)zCOpen uncompressed tar archive name for reading or writing.
        rsrcrtrGz!mode must be 'r', 'a', 'w' or 'x')rsrcrtrG)r<)rr~r\rrzr*r*r+rsCszTarFile.taropenrcKs)|dkrtdyddl}|jWn$ttfk
rUtdYnXy |j||d||}Wn9tk
r|dk	r|dkrtd	YnXy|j||||}WnKtk
r|j	|dkrtd	Yn|j	YnXd
|_
|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        rsrtrGzmode must be 'r', 'w' or 'x'rNzgzip module is not availablerVznot a gzip fileF)rsrtrG)r<gzipZGzipFilerAttributeErrorrkrrjrsrr)rr~r\r
compresslevelrzr}rr*r*r+gzopenKs2 



	zTarFile.gzopencKs|dkrtdyddl}Wntk
rHtdYnX|j|pX||d|}y|j||||}WnQttfk
r|j|dkrt	d	Yn|jYnXd
|_
|S)zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        rsrtrGzmode must be 'r', 'w' or 'x'rNzbz2 module is not availablerznot a bzip2 fileF)rsrtrG)r<rrrkZBZ2FilersrEOFErrorrrjr)rr~r\rrrzrrr*r*r+bz2openms(
	

	zTarFile.bz2opencKs|dkrtdyddl}Wntk
rHtdYnX|j|pX||d|}y|j||||}WnT|jtfk
r|j|dkrt	d	Yn|jYnXd
|_
|S)zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        rsrtrGzmode must be 'r', 'w' or 'x'rNzlzma module is not availablepresetznot an lzma fileF)rsrtrG)r<rrrkZLZMAFilersrrrrjr)rr~r\rrrzrrr*r*r+xzopens&


	zTarFile.xzopenrrsrrrrrrc
Cs|jr
dSd|_zz|jdkr|jjttd|jtd7_t|jt\}}|dkr|jjtt|Wd|j	s|jj
XdS)	zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NTrcrtrGrr)rcrtrG)rr\rrQr%rrrO
RECORDSIZErr)r}rTrUr*r*r+rs			z
TarFile.closecCs/|j|}|dkr+td||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)r}r~rr*r*r+	getmembers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.
        )_checkrn_loadrm)r}r*r*r+
getmemberss
	
zTarFile.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|]}|jqSr*)r~)rFrr*r*r+rHs	z$TarFile.getnames.<locals>.<listcomp>)r)r}r*r*r+getnamesszTarFile.getnamescCsI|jd|dk	r"|j}|dkr4|}tjj|\}}|jtjd}|jd}|j}||_	|dkrt
tdr|jrtj|}qtj
|}ntj|j}d}|j}t
j|r|j|jf}	|jrd|jdkrd|	|jkrd||j|	krdt}
|j|	}qt}
|	dr||j|	<nt
j|rt}
nst
j|rt}
n[t
j|rt}
tj|}n4t
j|rt }
nt
j!|rt"}
ndS||_||_#|j$|_%|j&|_'|
tkrT|j(|_)n	d|_)|j*|_+|
|_,||_-t.ryt.j/|j%d|_0Wnt1k
rYnXt2ryt2j3|j'd|_4Wnt1k
rYnX|
t t"fkrEt
tdrEt
td	rEtj5|j6|_7tj8|j6|_9|S)
aCreate a TarInfo object from the result of os.stat or equivalent
           on an existing file. The file is either named by `name', or
           specified as a file object `fileobj' with a file descriptor. If
           given, `arcname' specifies an alternative name for the file in the
           archive, otherwise, the name is taken from the 'name' attribute of
           'fileobj', or the 'name' argument. The name should be a text
           string.
        awxNrlstatrrrmajorminor):rr~rvr
splitdriverseplstriprrr{rirrZfstatfilenost_modeS_ISREGst_inost_devst_nlinkrorRrS_ISDIRrS_ISFIFOrXS_ISLNKrPreadlinkS_ISCHRrTS_ISBLKrVr\st_uidrst_gidrst_sizerst_mtimerrrpwdgetpwuidr rgrpZgetgrgidr!rst_rdevrrr)r}r~arcnamerZdrvrZstatresrZstmdinoderr*r*r+
gettarinfos~	
			"
									

zTarFile.gettarinfoTrmcCsQ|j|dkr|}x.|D]&}|rttj|jtd|jpZ|j|jpi|jf|j	s|j
rtdd|j|jfntd|j
tdtj|jddt|j|jrdnd	|rB|jr%td
|j|jrBtd|jtq#WdS)aPrint 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. `members' is optional and must be a subset of the
           list returned by getmembers().
        Nz%s/%sz%10sz%d,%dz%10dz%d-%02d-%02d %02d:%02d:%02drrrz-> zlink to )rrdrZr[r\r rr!rrUrWrrrrZ	localtimerr~r rQrrSrc)r}verbosermrr*r*r+rDEs*

#zTarFile.listfilterc	
Cs|jd|dkr|}|dk	rnddl}|jdtd||rn|jdd|dS|jdk	rtjj||jkr|jdd|dS|jd||j	||}|dkr|jdd	|dS|dk	r2||}|dkr2|jdd|dS|j
rjt|d
}|j||WdQRXn|j
r|j||rxatj|D]@}|jtjj||tjj||||d|qWn
|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.
        rNrzuse the filter argument insteadrztarfile: Excluded %rztarfile: Skipped %rrztarfile: Unsupported type %rrbr)rrWrXrY_dbgr~rvrrhrr0rgaddfiler listdiraddr)	r}r~rZ	recursiveZexcluderrWrfr*r*r+resB
	
*
*zTarFile.addcCs|jdtj|}|j|j|j|j}|jj||jt	|7_|dk	rt
||j|jt|jt
\}}|dkr|jjtt
||d7}|j|t
7_|jj|dS)aAdd the TarInfo object `tarinfo' to the archive. If `fileobj' is
           given, it should be a binary file, and tarinfo.size bytes are read
           from it and added to the archive. You can create TarInfo objects
           directly, or by using gettarinfo().
        rNrr)rrrrFr(r)rrQrr$rNrrOrr%rmr)r}rrrJrTrUr*r*r+rs

zTarFile.addfile.
numeric_ownercCsUg}|dkr|}xb|D]Z}|jrV|j|tj|}d|_|j||d|jd|qW|jddd|jx|D]}tjj	||j
}y:|j||d||j|||j
||Wqtk
rL}z.|jdkr&n|jdd	|WYdd}~XqXqWdS)
aExtract 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(). If `numeric_owner` is True, only
           the numbers for user/group names are used and not the names.
        Ni	set_attrsrrvcSs|jS)N)r~)rcr*r*r+<lambda>sz$TarFile.extractall.<locals>.<lambda>rztarfile: %s)r rrr\extractsortreverservrrr~chownutimechmodrirlr)r}rrmrZdirectoriesrdirpathrqr*r*r+
extractalls,

	

zTarFile.extractallrcCsd|jdt|tr.|j|}n|}|jr[tjj||j|_	y2|j
|tjj||jd|d|Wntk
r}zc|j
dkrnI|jdkr|jdd|jn |jdd|j|jfWYdd}~XnNtk
r_}z.|j
dkr9n|jdd|WYdd}~XnXdS)	aExtract 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. If `numeric_owner`
           is True, only the numbers for user/group names are used and not
           the names.
        rsrrrNrztarfile: %sztarfile: %s %r)rrrrrSrvrrrr_extract_memberr~rrlfilenamerstrerrorri)r}memberrrrrrqr*r*r+rs(	
!2zTarFile.extractcCs|jdt|tr.|j|}n|}|jsO|jtkr_|j||S|jsw|j	rt|j
trtdq|j
|j|SndSdS)zExtract a member from the archive as a file object. `member' may be
           a filename or a TarInfo object. If `member' is a regular file or a
           link, an io.BufferedReader object is returned. Otherwise, None is
           returned.
        rsz'cannot extract (sym)link as file objectN)rrrrr0rr1
fileobjectrSrQrrrlextractfile_find_link_target)r}rrr*r*r+r	s
zTarFile.extractfilecCs|jd}|jdtj}tjj|}|r\tjj|r\tj||jst|j	r|j
dd|j|jfn|j
d|j|j
r|j||n|jr|j||n|jr|j||n|js|jr2|j||n]|jsJ|j	r]|j||n2|jtkr|j||n|j|||r|j||||j	s|j|||j||dS)z\Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        rrz%s -> %sN)r!rrvrrdirnamerfmakedirsrSrQrr~rr0makefiler makedirrYmakefiforUrWmakedevmakelinkrr1makeunknownrrr)r}r
targetpathrrZ	upperdirsr*r*r+r(s4
#zTarFile._extract_membercCs-ytj|dWntk
r(YnXdS)z,Make a directory called targetpath.
        iN)rvmkdirFileExistsError)r}rrr*r*r+rYs
zTarFile.makedirc
Cs|j}|j|jt|d}|jdk	rx7|jD],\}}|j|t|||tqDW|j|j|jnt|||jtWdQRXdS)z'Make a file called targetpath.
        rdN)	rrrrgrrNrjrtruncate)r}rrsourcetargetrrr*r*r+rcs	

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)r}rrr*r*r+rrszTarFile.makeunknowncCs/ttdrtj|ntddS)z'Make a fifo called targetpath.
        mkfifozfifo not supported by systemN)r{rvrri)r}rrr*r*r+rzszTarFile.makefifocCsttds ttdr,td|j}|jrQ|tjO}n
|tjO}tj||tj	|j
|jdS)z<Make a character or block device called targetpath.
        mknodrz'special devices not supported by systemN)r{rvrir\rWrZS_IFBLKS_IFCHRrrrr)r}rrr\r*r*r+rs 	
zTarFile.makedevcCsyj|jr%tj|j|nDtjj|jrPtj|j|n|j|j	||WnPt
k
ry|j|j	||Wntk
rtdYnXYnXdS)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)
rQrvsymlinkrrrfrlinkrrsymlink_exceptionrri)r}rrr*r*r+rs

zTarFile.makelinkc Cs2tr.ttdr.tjdkr.|rB|j}|j}npytj|jd}Wnt	k
ry|j}YnXytj
|jd}Wnt	k
r|j}YnXyH|jrttdrtj
|||ntj|||Wn1tk
r-}ztdWYdd}~XnXdS)zSet owner of targetpath according to tarinfo. If numeric_owner
           is True, use .gid/.uid instead of .gname/.uname.
        geteuidrrlchownzcould not change ownerN)rr{rvrrrrZgetgrnamr!rgetpwnamr rQrrrri)r}rrrgurqr*r*r+rs$'	

z
TarFile.chowncCs^ttdrZytj||jWn1tk
rY}ztdWYdd}~XnXdS)zASet file permissions of targetpath according to tarinfo.
        rzcould not change modeN)r{rvrr\rri)r}rrrqr*r*r+rs
z
TarFile.chmodcCskttdsdSy tj||j|jfWn1tk
rf}ztdWYdd}~XnXdS)zBSet modification time of targetpath according to tarinfo.
        rNz"could not change modification time)r{rvrrrri)r}rrrqr*r*r+rs z
TarFile.utimecCsV|jd|jdk	r2|j}d|_|S|j|jjkr|jj|jd|jjdstdd}xy|jj	|}Wnt
k
r}z=|jr|jdd|j|f|jt
7_wWYdd}~Xn(tk
r}}za|jrJ|jdd|j|f|jt
7_wn!|jdkrktt|WYdd}~Xntk
r|jdkrtdYn|tk
r}z&|jdkrtt|WYdd}~Xn7tk
r$}ztt|WYdd}~XnXPqW|dk	rI|jj|n	d	|_|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.
        ZraNrzunexpected end of datarz0x%X: %srz
empty fileT)rrprrrrrPrjrr*rprjrrr=rrnrorqrmrrn)r}mrrqr*r*r+r4sL
				$
$%	zTarFile.nextcCs|j}|dk	r1|d|j|}|rItjj|}xKt|D]=}|rztjj|j}n	|j}||krV|SqVWdS)z}Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        N)rindexrvrnormpathreversedr~)r}r~r	normalizermrZmember_namer*r*r+r	s	zTarFile._getmembercCs-x|j}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r4rn)r}rr*r*r+r#	s
z
TarFile._loadcCsQ|jrtd|jj|dk	rM|j|krMtd|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)rrrrer\)r}r\r*r*r+r-	s	zTarFile._checkcCs|jrEdjtdtjj|j|jf}d}n|j}|}|j|d|dd}|dkrt	d||S)zZFind the target member of a symlink or hardlink member in the
           archive.
        rNrrTzlinkname %r not found)
rQrrrvrrr~rrr)r}rrlimitrr*r*r+r6	s0		zTarFile._find_link_targetcCs$|jrt|jSt|SdS)z$Provide an iterator object.
        N)rniterrmTarIter)r}r*r*r+__iter__I	s	
zTarFile.__iter__cCs&||jkr"t|dtjdS)z.Write debugging output to sys.stderr.
        fileN)rkrcrastderr)r}levelmsgr*r*r+rQ	szTarFile._dbgcCs|j|S)N)r)r}r*r*r+	__enter__W	s
zTarFile.__enter__cCs<|dkr|jn|js/|jjd|_dS)NT)rrrr)r}rr	tracebackr*r*r+__exit__[	s

	
zTarFile.__exit__)8rerfrgrhrkrirjrlr^rFr_r(r)rrrrrr`rrrsrrrrtrrrrrrDrrrrrrrrrrrrrrrr4rrrrrrrrr*r*r*r+rastkZ!
d =(&0
	6
	c@s:eZdZdZddZddZddZdS)	rzMIterator Class.

       for tarinfo in TarFile(...):
           suite...
    cCs||_d|_dS)z$Construct a TarIter object.
        rN)rr)r}rr*r*r+rm	s	zTarIter.__init__cCs|S)z Return iterator object.
        r*)r}r*r*r+rr	szTarIter.__iter__cCs|jdkr3|jjdk	r3|jj}nm|jt|jjkrd|jj|j}n<|jjs|jj}|sd|j_tnt|jd7_|S)zReturn the next item using TarFile's next() method.
           When all members have been read, set TarFile as _loaded.
        rNTr)rrrpr4r$rmrn
StopIteration)r}rr*r*r+__next__v	s!	zTarIter.__next__N)rerfrgrhrrrr*r*r*r+rf	srcCs;yt|}|jdSWntk
r6dSYnXdS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)rrr)r~rr*r*r+r	s

cCsddl}d}|jd|}|jdddddd	d
d|j}|jdd
ddd
d|jdddddd9d
d|jdddddd:d
d|jddddd
d|j}|jro|j}t|rSt|d*}|jt	|jd t
jWdQRX|jrlt	d!j
|q|jd"d#j
|n{|jr|j}t|rtj|d$}|jd%|jWdQRXq|jd"d#j
|n|jrt|jd"kr|jd}tj}n=t|jd&kr9|j\}}n|jd"|jt|rtj|d$}|jd'|WdQRX|jr|d(krd)j
|}	nd*j
||}	t	|	q|jd"d#j
|n|jr|jjd}
tjj|
\}}d+d,d-d,d.d/d0d/d1d2d3d2d4d2d5d2i}
||
krld6|
|nd7}|j}tj|
|%}x|D]}|j|qWWdQRX|jrt	d8j
|
n|jd"|jdS);Nrz3A simple command line interface for tarfile module.descriptionz-vz	--verboseaction
store_truedefaultFhelpzVerbose outputz-lz--listmetavar	<tarfile>zShow listing of a tarfilez-ez	--extractnargs+<output_dir>zExtract tarfile into target dirz-cz--create<name><file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrsrz{!r} is a tar archive.rz{!r} is not a tar archive.
zr:*rrrrz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.z.gzrz.tgzz.xzrz.txzz.bz2rz.tbzz.tbz2z.tb2zw:rtz{!r} file created.)rr)rr)argparseArgumentParseradd_argumentZadd_mutually_exclusive_group
parse_argsZtestrrrrcrarrrFexitrDrrr$rvcurdirZformat_helprZcreatepoprsplitextr)rrparserr:argsrRrZtfrrZtar_name_ZextZcompressionsZtar_modeZ	tar_files	file_namer*r*r+main	s		
 				
	
	 	
	r
__main__)brhversion
__author__Z__date__Z	__cvsid____credits__builtinsrrgrarvrrMrZrrIrr8rrrr~NotImplementedErrorrr	NameError__all__r%rrrrrrr
rrrRrPrTrVrrXZCONTTYPErrrrrr-rrBrr^r1rNr"rKr?rr:rLr~r_getfilesystemencodingr,r1r@rGrKrNr[rd	Exceptionrrirjrkrlrmrnrorpr=rqrrrobjectrrBufferedReaderrrrrrr
rer*r*r*r+<module>s


						
h	)	Z