MINI MINI MANI MO

Path : /usr/lib64/python3.6/__pycache__/
File Upload :
Current File : //usr/lib64/python3.6/__pycache__/tarfile.cpython-36.pyc

3


 \ l'@szdZdZdZdZdZdZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZyddlZWnek
rdZYnXyddlZWnek
rdZYnXeefZyeef7ZWnek
rYnXd	d
ddd
ddddddddddgZdZdZedZdZdZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/d+Z0d,Z1dZ2d-Z3d.Z4e3Z5e#e$e%e&e)e*e+e'e(e,e-e.fZ6e#e$e+e.fZ7e,e-e.fZ8dkZ9d/d0d5d6hZ:e;e;e;e<e<e<d7Z=e
j>d8krd9Z?ne	j@Z?d:d;ZAd<d=ZBd>d?ZCd@e5fdAdBZDdCdDZEdedfdEdFZFdGdHZGdIdJZHGdKddeIZJGdLddeJZKGdMd
d
eJZLGdNddeJZMGdOddeJZNGdPddeJZOGdQdRdReOZPGdSdTdTeOZQGdUdVdVeOZRGdWdXdXeOZSGdYdZdZeOZTGd[d\d\ZUGd]d^d^ZVGd_d`d`eWZXGdadbdbeWZYGdcddddejZZ[Gded
d
eWZ\Gdfd	d	eWZ]dgdZ^e]jZdhdiZ_e`djkrve_dS)lz,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_tarfileTarError	ReadErrorCompressionErrorStreamErrorExtractErrorHeaderErrorENCODINGUSTAR_FORMAT
GNU_FORMAT
PAX_FORMATDEFAULT_FORMATrisustar  sustar00d01234567LKSxgXpathlinkpathsizemtimeuidgidunamegname)ZatimeZctimer(r)r*r'ntzutf-8cCs(|j||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    N)encodelenNUL)slengthencodingerrorsr5/usr/lib64/python3.6/tarfile.pystnsr7cCs*|jd}|dkr|d|}|j||S)z8Convert a null-terminated bytes object to a string.
    rr#N)finddecode)r1r3r4pr5r5r6ntss
r<cCs|ddkrfd}x0tt|dD]}|dK}|||d7}q"W|ddkrdt|d|}n@y"t|dd}t|jpd	d}Wntk
rtd
YnX|S)z/Convert a number field to a python number.
    rr#asciistrict0zinvalid header)r=r>)ranger/r<intstrip
ValueErrorInvalidHeaderError)r1nir5r5r6ntisrKr?cCst|}d|ko"d|dknrDtd|d|fdt}n|tkrd|d|kopd|dknr|dkrtdg}ntdg}d||}x6t|dD]}|jd|d@|dL}qWntd	|S)
z/Convert a python number to a number field.
    rr?r#z%0*orAr@r=r>zoverflow in number field)rEbytesr0r	bytearrayrDinsertrG)rIdigitsformatr1rJr5r5r6itns 2
rQcCs0dttjd|}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.
    r@Z
148B8x356BZ
148b8x356b)sumstructZunpack_from)bufZunsigned_chksumZ
signed_chksumr5r5r6calc_chksumss	rUc	Cs|pd}|dkrdS|dkr.tj|||dSt||\}}x8t|D],}|j|}t||krh|d|j|qFW|dkr|j|}t||kr|d|j|dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    irNzunexpected end of datai@)shutilcopyfileobjdivmodrDreadr/write)	srcdstr2	exceptionbufsizeblocks	remainderbrTr5r5r6rXs$


rXcCs ddl}|jdtdtj|S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)warningswarnDeprecationWarningstatfilemode)modercr5r5r6rgsrgcCs8ttjdd}|dk	r(|j|dj|}t|dddS)Nr3backslashreplace )end)getattrsysstdoutr.r:print)r1r3r5r5r6_safe_printsrpc@seZdZdZdS)rzBase exception.N)__name__
__module____qualname____doc__r5r5r5r6rsc@seZdZdZdS)r
z%General exception for extract errors.N)rqrrrsrtr5r5r5r6r
sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rqrrrsrtr5r5r5r6rsc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rqrrrsrtr5r5r5r6rsc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.N)rqrrrsrtr5r5r5r6r	sc@seZdZdZdS)rz!Base exception for header errors.N)rqrrrsrtr5r5r5r6r"sc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rqrrrsrtr5r5r5r6ru%sruc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rqrrrsrtr5r5r5r6rv(srvc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rqrrrsrtr5r5r5r6rw+srwc@seZdZdZdS)rHzException for invalid headers.N)rqrrrsrtr5r5r5r6rH.srHc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rqrrrsrtr5r5r5r6rx1srxc@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)rwO_BINARYi)	osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrr|rfd)selfnamerhr5r5r6__init__>s

z_LowLevelFile.__init__cCstj|jdS)N)r}closer)rr5r5r6rGsz_LowLevelFile.closecCstj|j|S)N)r}rZr)rr'r5r5r6rZJsz_LowLevelFile.readcCstj|j|dS)N)r}r[r)rr1r5r5r6r[Msz_LowLevelFile.writeN)rqrrrsrtrrrZr[r5r5r5r6ry8s
	ryc@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.
    c	Csd|_|dkrt||}d|_|dkr6t|}|j}|p<d|_||_||_||_||_d|_	d|_
d|_yL|dkryddl}Wnt
k
rtd	YnX||_|jd|_|d
kr|j|j|_n|jn|dkr:yddl}Wnt
k
r
tdYnX|d
kr.d|_|j|_t|_n
|j|_n||d
kryddl}Wnt
k
rntdYnX|d
krd|_|j|_|j|_n
|j|_n|dkrtd|Wn&|js|jjd|_YnXdS)z$Construct a _Stream object.
        TNF*rgzzzlib module is not availablerzbz2zbz2 module is not availablexzzlzma module is not availabletarzunknown compression type %r) _extfileobjry_StreamProxygetcomptyperrhcomptypefileobjr_rTposclosedzlibImportErrorrcrc32crc
_init_read_gzerrorr^_init_write_gzrdbufZBZ2DecompressorcmpOSErrorZ
BZ2CompressorlzmaZLZMADecompressor	LZMAErrorZLZMACompressorr)	rrrhrrr_rrrr5r5r6r[sl












z_Stream.__init__cCst|dr|jr|jdS)Nr)rrr)rr5r5r6__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.gzNz
iso-8859-1replace)rZcompressobjZDEFLATED	MAX_WBITSZ
DEF_MEM_LEVELrrSpackrEtime_Stream__writerendswithr.r0)rZ	timestampr5r5r6rsz_Stream._init_write_gzcCsR|jdkr|jj||j|_|jt|7_|jdkrD|jj|}|j|dS)z&Write string s to the stream.
        rrN)	rrrrrr/rcompressr)rr1r5r5r6r[s

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)rTr/r_rr[)rr1r5r5r6Z__writesz_Stream.__writecCs|jr
dSd|_z|jdkr:|jdkr:|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.
        NTr{rrrz<Ll)rrhrrTrflushrr[rSrrrrr)rr5r5r6rs
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.
        rr$sznot a gzip filer#zunsupported compression methodr@r?rVN)rZ
decompressobjrrr
_Stream__readrrordrZr0)rflagZxlenr1r5r5r6rs.
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r)rr5r5r6tellsz_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)rrYr_rDrZr	)rrr`rarJr5r5r6seeks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.
        Nr)_readr_appendjoinrr/)rr'trTr5r5r6rZ
s
z_Stream.readcCs|jdkr|j|St|j}|jg}xd||kr|j|j}|sBPy|jj|}Wn|jk
rptdYnX|j	||t|7}q(Wdj
|}||d|_|d|S)z+Return size bytes from the stream.
        rzinvalid compressed datarN)rrr/rr_rZ
decompressr^rrr)rr'crrTr5r5r6rs"





z
_Stream._readcCsnt|j}|jg}x6||krH|jj|j}|s0P|j||t|7}qWdj|}||d|_|d|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        rN)r/rTrrZr_rr)rr'rrrTr5r5r6Z__read5s



z_Stream.__read)r)N)rqrrrsrtrrrr[rrrrrrZrrr5r5r5r6rPs	F
	

rc@s0eZdZdZddZddZddZdd	Zd
S)rzsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs||_|jjt|_dS)N)rrZ	BLOCKSIZErT)rrr5r5r6rKsz_StreamProxy.__init__cCs|jj|_|jS)N)rrZrT)rr'r5r5r6rZOs
z_StreamProxy.readcCsP|jjdrdS|jdddkr8|jdddkr8d	S|jjdrHdSd
SdS)NsrrrsBZhr
s1AY&SYr]7zXZrr)rr)rT
startswith)rr5r5r6rSs$z_StreamProxy.getcomptypecCs|jjdS)N)rr)rr5r5r6r]sz_StreamProxy.closeN)rqrrrsrtrrZrrr5r5r5r6rFs

rc@sjeZdZdZdddZddZddZd	d
ZddZd
dZ	e
jfddZ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}xT|D]L\}}||kr~|jj	d||df|jj	d||||f||7}||}qZW||jkr|jj	d||jdfdS)NrrFT)
roffsetr'positionrlrr	map_indexmapr)rrrr'Z	blockinfoZlastposZrealposr5r5r6rjs(

z_FileInFile.__init__cCsdS)Nr5)rr5r5r6rsz_FileInFile.flushcCsdS)NTr5)rr5r5r6readablesz_FileInFile.readablecCsdS)NFr5)rr5r5r6writablesz_FileInFile.writablecCs
|jjS)N)rseekable)rr5r5r6rsz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r)rr5r5r6rsz_FileInFile.tellcCs|tjkr tt|d|j|_nj|tjkr\|dkrFt|j|d|_qt|j||j|_n.|tjkrtt|j||jd|_ntd|jS)z(Seek to a position in the file.
        rzInvalid argument)	ioSEEK_SETminmaxr'rSEEK_CURSEEK_ENDrG)rrwhencer5r5r6rs


z_FileInFile.seekc	Cs|dkr|j|j}nt||j|j}d}x|dkrxZ|j|j\}}}}||jkob|knrlPq:|jd7_|jt|jkr:d|_q:Wt|||j}|r|jj||j||jj|}t||krt	d||7}n|t
|7}||8}|j|7_q.W|S)z!Read data from the file.
        Nrrr#zunexpected end of data)r'rrrrr/rrrZrr0)	rr'rTdatastartstoprr2rbr5r5r6rZs.

z_FileInFile.readcCs&|jt|}||dt|<t|S)N)rZr/)rrbrTr5r5r6readintosz_FileInFile.readintocCs
d|_dS)NT)r)rr5r5r6rsz_FileInFile.close)N)N)rqrrrsrtrrrrrrrrrrZrrr5r5r5r6rds

rcseZdZfddZZS)ExFileObjectcs&t|j|j|j|j}tj|dS)N)rroffset_datar'sparsesuperr)rtarfiletarinfor)	__class__r5r6rs
zExFileObject.__init__)rqrrrsr
__classcell__r5r5)rr6rsrc@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.
    rrhr)r*r'r(chksumtypelinknamer+r,devmajordevminorrrpax_headersrr_sparse_structs_link_targetrcCsj||_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)rrhr)r*r'r(rREGTYPErrr+r,rrrrrr)rrr5r5r6rs"zTarInfo.__init__cCs|jS)N)r)rr5r5r6_getpathszTarInfo._getpathcCs
||_dS)N)r)rrr5r5r6_setpathszTarInfo._setpathcCs|jS)N)r)rr5r5r6_getlinkpathszTarInfo._getlinkpathcCs
||_dS)N)r)rrr5r5r6_setlinkpathszTarInfo._setlinkpathcCsd|jj|jt|fS)Nz<%s %r at %#x>)rrqrid)rr5r5r6__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)
rrhr)r*r'r(rrrr+r,rrrr/)rrhr)r*r'r(rrrr+r,rrDIRTYPEr)rinfor5r5r6get_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)rr
create_ustar_headerrcreate_gnu_headerrcreate_pax_headerrG)rrPr3r4rr5r5r6tobuf&sz
TarInfo.tobufcCsnt|d<t|dj||tkr(tdt|dj||tkr^|j|d||\|d<|d<|j|t||S)z3Return the object as a ustar header block.
        magicrzlinkname is too longrprefix)	POSIX_MAGICr/r.LENGTH_LINKrGLENGTH_NAME_posix_split_name_create_headerr
)rrr3r4r5r5r6r4szTarInfo.create_ustar_headercCst|d<d}t|dj||tkr<||j|dt||7}t|dj||tkrl||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_LONGNAMErr)rrr3r4rTr5r5r6rAszTarInfo.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.
        rrr%rr&r+ r,rArBr)r?r*r'r(rr#rr)r+r+r)r,r,rr)r?r*r?r'rr(r)rrrr)rrcopyrrr.UnicodeEncodeErrorr/
isinstancefloatstr_create_pax_generic_headerXHDTYPErr
)
rrr3rrZhnamer2rOvalrTr5r5r6rOs4
.zTarInfo.create_pax_headercCs|j|tdS)zAReturn the object as a pax global header block sequence.
        zutf-8)r
XGLTYPE)clsrr5r5r6create_pax_global_headersz TarInfo.create_pax_global_headercCs|jd}xltdt|D]R}dj|d|}dj||d}t|j||tkrt|j||tkrPqWtd||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        rr#Nzname is too long)splitrDr/rr.
LENGTH_PREFIXrrG)rrr3r4Z
componentsrJrr5r5r6rs
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}|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.
        rrrrhrir?r)r*r'rr(s        rrrr+rr,rrrrz%dsrNilz%06orAieii)r7getrQrrrSrrrrUrL)rrPr3r4partsrTrr5r5r6rs&

&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)rYr/rr0)Zpayloadr`rar5r5r6_create_payloadszTarInfo._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
././@LongLinkrrr'r)r.r0r/rrr
r)rrrr3r4rr5r5r6rs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.
        Fzutf-8rBTrs21 hdrcharset=BINARY
rrrrA =
z././@PaxHeaderrrr'rr)
itemsr.rr/r	rLrrr
r)rrrr3ZbinarykeywordvalueZrecordslrIr;rr5r5r6r
s<

*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 headerzbad checksumrlt|ii	i)iIiQiYirirriii)$r/rurrvcountr0rwrKrUrHr<rrhr)r*r'r(rrrr+r,rrAREGTYPErrGNUTYPE_SPARSErDrGrboolrisdirrstrip	GNU_TYPES)rrTr3r4robjrrstructsrJrnumbytes
isextendedorigsizer5r5r6frombufsZ
zTarInfo.frombufcCs8|jjt}|j||j|j}|jjt|_|j|S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	rrZrr0r3r4rr_proc_member)rrrTr+r5r5r6fromtarfile?s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_sparserr
SOLARIS_XHDTYPE	_proc_pax
_proc_builtin)rrr5r5r6r1Ts



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_blockr'r_apply_pax_inforr3r4)rrrr5r5r6r7as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)rrZr:r'r2rrxrrrr<r3r4rrr)rrrTnextr5r5r6r3rs

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)rrrZrrDrKrGrr'rrrr:r'r)
rrr,r.r/rTrrJrr-r5r5r6r4s(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]+)\nNr#zutf-8
hdrcharsetZBINARYs(\d+) ([^=]+)=rr$z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrCr')$rrZr:r'rr
rrresearchgroupr:rr3compilematchgroupsrErkr_decode_pax_fieldr4PAX_NAME_FIELDSr2rrx_proc_gnusparse_01_proc_gnusparse_00_proc_gnusparse_10rr5r;rrr8r9)rrrTrrDr>r3Zregexrr2rrr<rr5r5r6r6s`



$	





 
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+)\nr#s\d+ GNU.sparse.numbytes=(\d+)\nN)r@finditerrrErBlistzipr)rr<rrTZoffsetsrDr-r5r5r6rI
szTarInfo._proc_gnusparse_00cCs@dd|djdD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|qSr5)rE).0xr5r5r6
<listcomp>sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>zGNU.sparse.map,Nr$r#)rrLrMr)rr<rrr5r5r6rHszTarInfo._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.
        Nrr#r$)rrZrrrEr/rrrrLrMr)rr<rrZfieldsrrTZnumberr5r5r6rJs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.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerrN)	rsetattrrE
PAX_FIELDSPAX_NUMBER_FIELDSrGr)rr)rrr3r4rrr5r5r6r;+s"

zTarInfo._apply_pax_infocCs.y|j|dStk
r(|j||SXdS)z1Decode a single field from a pax record.
        rBN)r:UnicodeDecodeError)rrr3Zfallback_encodingZfallback_errorsr5r5r6rFBs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#)rYr)rr$r`rar5r5r6r:JszTarInfo._blockcCs
|jtkS)N)r
REGULAR_TYPES)rr5r5r6r8Ssz
TarInfo.isregcCs|jS)N)r8)rr5r5r6isfileUszTarInfo.isfilecCs
|jtkS)N)rr)rr5r5r6r(Wsz
TarInfo.isdircCs
|jtkS)N)rSYMTYPE)rr5r5r6issymYsz
TarInfo.issymcCs
|jtkS)N)rLNKTYPE)rr5r5r6islnk[sz
TarInfo.islnkcCs
|jtkS)N)rCHRTYPE)rr5r5r6ischr]sz
TarInfo.ischrcCs
|jtkS)N)rBLKTYPE)rr5r5r6isblk_sz
TarInfo.isblkcCs
|jtkS)N)rFIFOTYPE)rr5r5r6isfifoaszTarInfo.isfifocCs
|jdk	S)N)r)rr5r5r6issparsecszTarInfo.issparsecCs|jtttfkS)N)rr\r^r`)rr5r5r6isdevesz
TarInfo.isdevN)rrhr)r*r'r(rrrr+r,rrrrrrrrr)r)4rqrrrsrt	__slots__rrrpropertyr%rrr&rrrrrrrrclassmethodrrstaticmethodrrrr
r0r2r1r7r3r4r6rIrHrJr;rFr:r8rWr(rYr[r]r_rarbrcr5r5r5r6rs`



1
3?
f	c
@seZdZdZdZdZdZdZeZ	e
ZdZe
ZeZd\dd	Zedddefd
dZed]dd
Zed^ddZed_ddZed`ddZdddddZddZddZddZd d!Zdad"d#Zdbdd%d&d'Zdcdd(d)d*Z ddd+d,Z!dedd.d/d0Z"dfdd.d2d3Z#d4d5Z$dgd6d7Z%d8d9Z&d:d;Z'd<d=Z(d>d?Z)d@dAZ*dBdCZ+dDdEZ,dFdGZ-dHdIZ.dJdKZ/dhdLdMZ0dNdOZ1didPdQZ2dRdSZ3dTdUZ4dVdWZ5dXdYZ6dZd[Z7dS)jrz=The TarFile Class provides an interface to tar archives.
    rFr#NrzrcCsddddd}||krtd||_|||_|sj|jdkrVtjj|rVd|_d|_t||j}d	|_n@|d
krt|drt	|j
ttfr|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	r4|jtkr4|
|_ni|_|d
k	rJ||_|d
k	rZ||_|
|_d	|_g|_d	|_|jj|_i|_y|jdkrd
|_ |j!|_ |jdkr8x|jj"|jy|jj#|}|jj$|WnTt%k
r|jj"|jPYn0t&k
r0}zt't|WYd
d
}~XnXqW|jdkrd
|_|jr|jj(|jj)}|jj*||jt+|7_Wn&|js|jj,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.
        rbzr+bwbZxb)rzar{rOz!mode must be 'r', 'a', 'w' or 'x'rjr{FNrrhTrzrO)rjr{rO)-rGrh_moder}r%exists	bltn_openrrrrr	rLabspathrrPrdereferenceignore_zerosr3r4rrdebug
errorlevelcopybufsizermembers_loadedrrinodesfirstmemberr<rr2rrwrrrrr[r/r)rrrhrrPrrorpr3r4rrqrrrsZmodeserTr5r5r6rs






$
zTarFile.__init__c

s|r|rtd|dkrfdd}xttj|dD]b}tj|}|dk	r\|j}	y||d|f|Sttfk
r|dk	r|j|	w8Yq8Xq8Wtdnd	|kr|jd	d
\}
}|
pd}
|pd}|jkrtj|}ntd||||
|f|Sd
|kr|jd
d
\}
}|
p.d}
|p8d}|
dkrLtdt	||
|||}y||
|f|}Wn|j
YnXd|_|S|dkrj|||f|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 openrzr:*csj|dkS)Ntaropen)	OPEN_METH)r)rr5r6not_compressedsz$TarFile.open.<locals>.not_compressed)keyNz%file could not be opened successfully:r#rzunknown compression type %r|r{zmode must be 'r' or 'w'FrjrOzundiscernible mode)rzry)rzr{)rjr{rO)
rGsortedr{rlrrrrrrrrrz)
rrrhrr_kwargsr|rfuncZ	saved_posrgstreamrr5)rr6rsP%







zTarFile.opencKs |dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing.
        rzrjr{rOz!mode must be 'r', 'a', 'w' or 'x')rzrjr{rO)rG)rrrhrrr5r5r6rzMszTarFile.taropenrcKs|dkrtdyddl}|jWn ttfk
rBtdYnXy|j||d||}Wn.tk
r|dk	r|dkrtd	YnXy|j|||f|}WnBtk
r|j	|dkrtd	Yn|j	YnXd
|_
|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        rzr{rOzmode must be 'r', 'w' or 'x'rNzgzip module is not availablerbznot a gzip fileF)rzr{rO)rGgzipZGzipFilerAttributeErrorrrrrzrr)rrrhr
compresslevelrrrr5r5r6gzopenUs2
zTarFile.gzopencKs|dkrtdyddl}Wntk
r8tdYnX|j|pD|||d}y|j|||f|}WnFttfk
r|j|dkrt	d	Yn|jYnXd
|_
|S)zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        rzr{rOzmode must be 'r', 'w' or 'x'rNzbz2 module is not available)rznot a bzip2 fileF)rzr{rO)rGrrrZBZ2FilerzrEOFErrorrrr)rrrhrrrrrr5r5r6bz2openws(zTarFile.bz2opencKs|dkrtdyddl}Wntk
r8tdYnX|j|pD|||d}y|j|||f|}WnH|jtfk
r|j|dkrt	d	Yn|jYnXd
|_
|S)zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        rzr{rOzmode must be 'r', 'w' or 'x'rNzlzma module is not available)presetznot an lzma fileF)rzr{rO)rGrrrZLZMAFilerzrrrrr)rrrhrrrrrr5r5r6xzopens&zTarFile.xzopenrzrrr)rrrrc
Cs|jr
dSd|_z`|jdkrn|jjttd|jtd7_t|jt\}}|dkrn|jjtt|Wd|j	s|jj
XdS)	zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NTrjr{rOr$r)rjr{rO)rrhrr[r0rrrY
RECORDSIZErr)rr`rar5r5r6rs
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)rrrr5r5r6	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.
        )_checkru_loadrt)rr5r5r6
getmembersszTarFile.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|]
}|jqSr5)r)rNrr5r5r6rPsz$TarFile.getnames.<locals>.<listcomp>)r)rr5r5r6getnamesszTarFile.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)
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.
        awxNrlstatrr#rmajorminor):rrr}r%
splitdriverseplstriprrrrorrffstatfilenost_modeS_ISREGst_inost_devst_nlinkrvrZrS_ISDIRrS_ISFIFOr`S_ISLNKrXreadlinkS_ISCHRr\S_ISBLKr^rhst_uidr)st_gidr*st_sizer'st_mtimer(rrpwdgetpwuidr+rgrpZgetgrgidr,rst_rdevrrr)rrarcnamerZdrvrZstatresrZstmdinoderr5r5r6
gettarinfos~	




zTarFile.gettarinfoT)rtcCs|j|dkr|}x|D]}|rttj|jtd|jp@|j|jpJ|jf|j	sb|j
r|tdd|j|jfntd|j
tdtj|jddt|j|jrdnd	|r|jrtd
|j|jrtd|jtqWdS)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 )rrprfrgrhr+r)r,r*r]r_rrr'rZ	localtimer(rr(rYrr[ro)rverbosertrr5r5r6rLOs*
zTarFile.list)filterc	
Csv|jd|dkr|}|dk	rPddl}|jdtd||rP|jdd|dS|jdk	rtjj||jkr|jdd|dS|jd||j	||}|dkr|jdd	|dS|dk	r||}|dkr|jdd|dS|j
rt|d
}|j||WdQRXnd|j
rh|j||rrxHtj|D].}|jtjj||tjj|||||dq4Wn
|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 insteadr$ztarfile: Excluded %rztarfile: Skipped %rr#ztarfile: Unsupported type %rrh)r)rrcrdre_dbgrr}r%rnrr8rmaddfiler(listdiraddr)	rrr	recursiveZexcluderrcrfr5r5r6rosB



zTarFile.addcCs|jdtj|}|j|j|j|j}|jj||jt	|7_|j
}|dk	rt||j|j|dt
|jt\}}|dkr|jjtt||d7}|j|t7_|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().
        rN)r_rr#)rrrrPr3r4rr[rr/rsrXr'rYrr0rtr)rrrrTr_r`rar5r5r6rs

zTarFile.addfile.)
numeric_ownercCsg}|dkr|}xF|D]>}|jr<|j|tj|}d|_|j|||j|dqW|jddd|jx|D]}tjj	||j
}y,|j|||d|j|||j
||Wqvtk
r}z$|jdkrւn|jdd	|WYdd}~XqvXqvWdS)
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_attrsrcSs|jS)N)r)rjr5r5r6<lambda>sz$TarFile.extractall.<locals>.<lambda>)r})rr#ztarfile: %s)r(rrrhextractsortreverser}r%rrchownutimechmodr
rrr)rr%rtrZdirectoriesrdirpathrxr5r5r6
extractalls,




zTarFile.extractallrcCs|jdt|tr |j|}n|}|jr>tjj||j|_	y"|j
|tjj||j||dWntk
r}zJ|j
dkrn6|jdkr|jdd|jn|jdd|j|jfWYdd}~XnBtk
r}z$|j
dkrn|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.
        rz)rrrNr#ztarfile: %sztarfile: %s %r)rrr	rr[r}r%rrr_extract_memberrrrrfilenamerstrerrorr
)rmemberr%rrrrxr5r5r6rs(	



(
zTarFile.extractcCs|jdt|tr |j|}n|}|js6|jtkrB|j||S|jsR|j	rzt|j
trht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.
        rzz'cannot extract (sym)link as file objectN)rrr	rr8rr9
fileobjectr[rYrrr	extractfile_find_link_target)rrrr5r5r6rs


zTarFile.extractfilecCsV|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|||rR|j||||j	sR|j|||j||dS)z\Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        rr#z%s -> %sN)r)rr}rr%dirnamerlmakedirsr[rYrrrr8makefiler(makedirramakefifor]r_makedevmakelinkrr9makeunknownrrr)rr
targetpathrrZ	upperdirsr5r5r6r2s4


zTarFile._extract_membercCs*ytj|dWntk
r$YnXdS)z,Make a directory called targetpath.
        iN)r}mkdirFileExistsError)rrrr5r5r6rcszTarFile.makedircCs|j}|j|j|j}t|df}|jdk	rrx,|jD]"\}}|j|t|||t|q6W|j|j|j	nt|||jt|WdQRXdS)z'Make a file called targetpath.
        riN)
rrrrsrmrrXrr'truncate)rrrsourcer_targetrr'r5r5r6rms


zTarFile.makefilecCs"|j|||jdd|jdS)zYMake a file from a TarInfo object with an unknown type
           at targetpath.
        r#z9tarfile: Unknown file type %r, extracted as regular file.N)rrr)rrrr5r5r6r}szTarFile.makeunknowncCs"ttdrtj|ntddS)z'Make a fifo called targetpath.
        mkfifozfifo not supported by systemN)rr}rr
)rrrr5r5r6rs
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)rr}r
rhr_rfS_IFBLKS_IFCHRrrrr)rrrrhr5r5r6rs
zTarFile.makedevcCsyL|jrtj|j|n0tjj|jr8tj|j|n|j|j	||WnHt
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)
rYr}symlinkrr%rlrlinkrrsymlink_exceptionrr
)rrrr5r5r6rs

zTarFile.makelinkcCsttdrtjdkr|j}|j}|sytr<tj|jd}Wntk
rRYnXyt	rjt	j
|jd}Wntk
rYnXy4|jrttdrtj
|||ntj|||Wntk
rtdYnXdS)zSet owner of targetpath according to tarinfo. If numeric_owner
           is True, use .gid/.uid instead of .gname/.uname. If numeric_owner
           is False, fall back to .gid/.uid when the search based on name
           fails.
        geteuidrr$lchownzcould not change ownerN)rr}rr*r)rZgetgrnamr,rrgetpwnamr+rYrrrr
)rrrrgur5r5r6rs(z
TarFile.chowncCs>ttdr:ytj||jWntk
r8tdYnXdS)zASet file permissions of targetpath according to tarinfo.
        rzcould not change modeN)rr}rrhrr
)rrrr5r5r6rs

z
TarFile.chmodcCsHttdsdSytj||j|jfWntk
rBtdYnXdS)zBSet modification time of targetpath according to tarinfo.
        rNz"could not change modification time)rr}rr(rr
)rrrr5r5r6rs
z
TarFile.utimecCs|jd|jdk	r$|j}d|_|S|j|jjkrZ|jj|jd|jjdsZtdd}xby|jj	|}WnHt
k
r}z2|jr|jdd|j|f|jt
7_wbWYdd}~Xntk
r,}zN|jr|jdd|j|f|jt
7_wbn|jdkrtt|WYdd}~Xntk
rT|jdkrPtdYnjtk
r}z|jdkr~tt|WYdd}~Xn0tk
r}ztt|WYdd}~XnXPqbW|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.
        ZraNr#zunexpected end of datar$z0x%X: %srz
empty fileT)rrwrrrrrZrrr2rwrprrrHr	rurvrxrtrru)rmrrxr5r5r6r<sL


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)rindexr}r%normpathreversedr)rrr	normalizertrmember_namer5r5r6r	szTarFile._getmembercCs"x|j}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r<ru)rrr5r5r6r1	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)rrrrqrh)rrhr5r5r6r;	szTarFile._checkcCs`|jr.djtdtjj|j|jf}d}n
|j}|}|j||dd}|dkr\t	d||S)zZFind the target member of a symlink or hardlink member in the
           archive.
        rNT)rrzlinkname %r not found)
rYrrr}r%rrrrr)rrrlimitrr5r5r6rD	s zTarFile._find_link_targetccs|jr|jEdHdSd}|jdk	r:|j}|d7}|VxN|t|jkrV|j|}n"|jst|j}|sxd|_dSndS|d7}|Vq<WdS)z$Provide an iterator object.
        Nrr#T)rurtrwr<r/)rrrr5r5r6__iter__W	s&
zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr.
        )fileN)rqrormstderr)rlevelmsgr5r5r6rv	s
zTarFile._dbgcCs|j|S)N)r)rr5r5r6	__enter__|	szTarFile.__enter__cCs,|dkr|jn|js"|jjd|_dS)NT)rrrr)rrr	tracebackr5r5r6__exit__	s


zTarFile.__exit__)
NrzNNNNNNrNNNN)rzN)rzNr)rzNr)rzNN)NNN)T)NTN)N)rN)rT)TF)NF)N)8rqrrrsrtrqrorprrrrPrr3r4rrrrrrfrrrzrrrr{rrrrrrLrrrrrrrrrrrrrrrr<rrrrrrrrr5r5r5r6risv
lZ!

d =
(&
0
	6


	cCs.yt|}|jdStk
r(dSXdS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)rrr)rrr5r5r6r	scCsddl}d}|j|d}|jdddddd	|j}|jd
ddd
d|jdddd0dd|jdddd1dd|jddddd|j}|jr|j}t|rt|d }|jt	|jt
jdWdQRX|jrt	dj
|n|jd d!j
|n|jrP|j}t|r:tj|d"}|j|jd#WdQRXn|jd d!j
|n|jrt|jd krz|jd}tj}n,t|jd$kr|j\}}n|jd |jt|rtj|d"}|j|d%WdQRX|jr|d&krd'j
|}	nd(j
||}	t	|	n|jd d!j
|n|jr|jjd}
tjj|
\}}d)d)d*d*d+d+d+d+d,}
||
krld-|
|nd.}|j}tj|
| }x|D]}|j|qWWdQRX|jrt	d/j
|
n|jd |jdS)2Nrz3A simple command line interface for tarfile module.)descriptionz-vz	--verbose
store_trueFzVerbose output)actiondefaulthelpz-lz--list	<tarfile>zShow listing of a tarfile)metavarrz-ez	--extract+<output_dir>zExtract tarfile into target dir)nargsrrz-cz--create<name><file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validrz)rz{!r} is a tar archive.r#z{!r} is not a tar archive.
zr:*)rr$)r%rz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rrr)z.gzz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:r{z{!r} file created.)rr)rr)argparseArgumentParseradd_argumentZadd_mutually_exclusive_group
parse_argsZtestrrrrormrrrPexitrLrrr/r}curdirZformat_helprZcreatepopr%splitextr)rrparserrBargsr\rZtfrrZtar_name_ZextZcompressionsZtar_modeZ	tar_files	file_namer5r5r6main	s









r__main__)r%r&r'r(r)r*r+r,)artversion
__author__Z__date__Z	__cvsid____credits__builtinsrrmrmr}rrWrfrrSrr@rrrrNotImplementedErrorrr	NameError__all__r0rrrrrrrrr%rZrXr\r^rr`ZCONTTYPErrr&rr
r5r
rrrr9rVr*rSrGrrErTrrgetfilesystemencodingr7r<rKrQrUrXrgrp	Exceptionrr
rrr	rrurvrwrHrxryrobjectrrBufferedReaderrrrrrrqr5r5r5r6<module>s



wh,Z


OHA YOOOO