ROOTPLOIT
Server: LiteSpeed
System: Linux server71.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
User: niphet (1079)
PHP: 5.3.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.6/__pycache__/tarfile.cpython-36.opt-1.pyc
3

i'@sBdZdZdZdZdZdZddlmZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZyddlZWnek
rdZYnXyddlZWnek
rdZYnXeefZyeef7ZWnek
rYnXd	d
ddd
ddddddddddgZdZdZdZdZedZ dZ!dZ"dZ#dZ$d Z%d!Z&dZ'd"Z(d#Z)d$Z*d%Z+d&Z,d'Z-d(Z.d)Z/d*Z0d+Z1d,Z2d-Z3d.Z4dZ5d/Z6d0Z7e6Z8e&e'e(e)e,e-e.e*e+e/e0e1fZ9e&e'e.e1fZ:e/e0e1fZ;dZ<d1d2d7d8hZ=e>e>e>e?e?e?d9Z@e
jAd:krd;ZBne	jCZBd<d=ZDd>d?ZEd@dAZFdBe8fdCdDZGdEdFZHdedfdGdHZIdIdJZJdKdLZKGdMddeLZMGdNddeMZNGdOd
d
eMZOGdPddeMZPGdQddeMZQGdRddeMZRGdSdTdTeRZSGdUdVdVeRZTGdWdXdXeRZUGdYdZdZeRZVGd[d\d\eRZWGd]d^d^ZXGd_d`d`ZYGdadbdbeZZ[GdcddddeZZ\Gdedfdfej]Z^GdgdhdheMZ_Gdidjdje_Z`Gdkdldle_ZaGdmdndne_ZbGdodpdpe_ZcGdqdrdre_ZdGdsdtdte_Zee_eeNfZfddudvZgdwdxZhdydzZid{d|Zjeheiejd}ZkeZZlejmd~ZnGdd
d
eZZoGdd	d	eZZpddZqepjZddZresdkr>erdS)z,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_FORMATrTz/etc/python/tarfile.cfgisustar  sustar00d01234567LKSxgXpathlinkpathsizemtimeuidgidunamegname)ZatimeZctimer(r)r*r'ntzutf-8cCs8|dkrtd|j||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    Nzmetadata cannot contain None)
ValueErrorencodelenNUL)slengthencodingerrorsr6/usr/lib64/python3.6/tarfile.pystnsr8cCs*|jd}|dkr|d|}|j||S)z8Convert a null-terminated bytes object to a string.
    rr#N)finddecode)r2r4r5pr6r6r7ntss
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?)ranger0r=intstripr.InvalidHeaderError)r2nir6r6r7ntis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*orBrAr>r?zoverflow in number field)rFbytesr1r	bytearrayrEinsertr.)rIdigitsformatr2rJr6r6r7itns 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.
    rAZ
148B8x356BZ
148b8x356b)sumstructZunpack_from)bufZunsigned_chksumZ
signed_chksumr6r6r7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@)shutilcopyfileobjdivmodrEreadr0write)	srcdstr3	exceptionbufsizeblocks	remainderbrTr6r6r7rXs$


rXcCs ddl}|jdtdtj|S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)warningswarnDeprecationWarningstatfilemode)modercr6r6r7rgsrgcCs8ttjdd}|dk	r(|j|dj|}t|dddS)Nr4backslashreplace )end)getattrsysstdoutr/r;print)r2r4r6r6r7_safe_printsrpc@seZdZdZdS)rzBase exception.N)__name__
__module____qualname____doc__r6r6r6r7rsc@seZdZdZdS)r
z%General exception for extract errors.N)rqrrrsrtr6r6r6r7r
!sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rqrrrsrtr6r6r6r7r$sc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rqrrrsrtr6r6r6r7r'sc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.N)rqrrrsrtr6r6r6r7r	*sc@seZdZdZdS)rz!Base exception for header errors.N)rqrrrsrtr6r6r6r7r-sc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rqrrrsrtr6r6r6r7ru0sruc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rqrrrsrtr6r6r6r7rv3srvc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rqrrrsrtr6r6r6r7rw6srwc@seZdZdZdS)rHzException for invalid headers.N)rqrrrsrtr6r6r6r7rH9srHc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rqrrrsrtr6r6r6r7rx<srxc@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)selfnamerhr6r6r7__init__Is

z_LowLevelFile.__init__cCstj|jdS)N)r}closer)rr6r6r7rRsz_LowLevelFile.closecCstj|j|S)N)r}rZr)rr'r6r6r7rZUsz_LowLevelFile.readcCstj|j|dS)N)r}r[r)rr2r6r6r7r[Xsz_LowLevelFile.writeN)rqrrrsrtrrrZr[r6r6r6r7ryCs
	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_rrrr6r6r7rfsl












z_Stream.__init__cCst|dr|jr|jdS)Nr)rrr)rr6r6r7__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_LEVELrrSpackrFtime_Stream__writerendswithr/r1)rZ	timestampr6r6r7rsz_Stream._init_write_gzcCsR|jdkr|jj||j|_|jt|7_|jdkrD|jj|}|j|dS)z&Write string s to the stream.
        rrN)	rrrrrr0rcompressr)rr2r6r6r7r[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)rTr0r_rr[)rr2r6r6r7Z__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)rr6r6r7rs
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 methodrAr@rVN)rZ
decompressobjrrr
_Stream__readrrordrZr1)rflagZxlenr2r6r6r7rs.
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r)rr6r6r7tellsz_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_rErZr	)rrr`rarJr6r6r7seeks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_appendjoinrr0)rr'trTr6r6r7rZs
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)rrr0rr_rZ
decompressr^rrr)rr'crrTr6r6r7r*s"





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)r0rTrrZr_rr)rr'rrrTr6r6r7Z__read@s



z_Stream.__read)r)N)rqrrrsrtrrrr[rrrrrrZrrr6r6r6r7r[s	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)rrr6r6r7rVsz_StreamProxy.__init__cCs|jj|_|jS)N)rrZrT)rr'r6r6r7rZZs
z_StreamProxy.readcCsP|jjdrdS|jdddkr8|jdddkr8d	S|jjdrHdSd
SdS)NsrrrsBZhr
s1AY&SYr]7zXZrr)rr)rT
startswith)rr6r6r7r^s$z_StreamProxy.getcomptypecCs|jjdS)N)rr)rr6r6r7rhsz_StreamProxy.closeN)rqrrrsrtrrZrrr6r6r6r7rQs

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	blockinfoZlastposZrealposr6r6r7rus(

z_FileInFile.__init__cCsdS)Nr6)rr6r6r7rsz_FileInFile.flushcCsdS)NTr6)rr6r6r7readablesz_FileInFile.readablecCsdS)NFr6)rr6r6r7writablesz_FileInFile.writablecCs
|jjS)N)rseekable)rr6r6r7rsz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )r)rr6r6r7rsz_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_ENDr.)rrwhencer6r6r7rs


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'rrrrr0rrrZrr1)	rr'rTdatastartstoprr3rbr6r6r7rZs.

z_FileInFile.readcCs&|jt|}||dt|<t|S)N)rZr0)rrbrTr6r6r7readintosz_FileInFile.readintocCs
d|_dS)NT)r)rr6r6r7rsz_FileInFile.close)N)N)rqrrrsrtrrrrrrrrrrZrrr6r6r6r7ros

rcseZdZfddZZS)ExFileObjectcs&t|j|j|j|j}tj|dS)N)rroffset_datar'sparsesuperr)rtarfiletarinfor)	__class__r6r7rs
zExFileObject.__init__)rqrrrsr
__classcell__r6r6)rr7rsrc@seZdZdS)FilterErrorN)rqrrrsr6r6r6r7rsrcseZdZfddZZS)AbsolutePathErrorcs ||_tjd|jddS)Nzmember z has an absolute path)rrrr)rr)rr6r7rszAbsolutePathError.__init__)rqrrrsrrr6r6)rr7rsrcseZdZfddZZS)OutsideDestinationErrorcs.||_||_tj|jd|dddS)Nz would be extracted to z, z which is outside the destination)r_pathrrr)rrr%)rr6r7rsz OutsideDestinationError.__init__)rqrrrsrrr6r6)rr7rsrcseZdZfddZZS)SpecialFileErrorcs||_tj|jddS)Nz is a special file)rrrr)rr)rr6r7rszSpecialFileError.__init__)rqrrrsrrr6r6)rr7rsrcseZdZfddZZS)AbsoluteLinkErrorcs||_tj|jddS)Nz! is a symlink to an absolute path)rrrr)rr)rr6r7rszAbsoluteLinkError.__init__)rqrrrsrrr6r6)rr7rsrcseZdZfddZZS)LinkOutsideDestinationErrorcs.||_||_tj|jd|dddS)Nz would link to z, z which is outside the destination)rrrrr)rrr%)rr6r7rsz$LinkOutsideDestinationError.__init__)rqrrrsrrr6r6)rr7rsrcseZdZfddZZS)LinkFallbackErrorcs2||_||_tjd|jdd|ddS)Nzlink z would be extracted as a zcopy of z, which was rejected)rrrrr)rrr%)rr6r7rszLinkFallbackError.__init__)rqrrrsrrr6r6)rr7rsrcCs$i}|j}tjj|tjjd}|jdtjfrH|jjdtj}|d<tjj|r\t	|tjjtjj
||tjjd}tjj||g|krt|||j
}|dk	r|d@}|r|js|jr|d@s|dM}|dO}n|js|jrd}nt|||j
kr||d<|r |jdk	r,d|d	<|jdk	r@d|d
<|jdk	rTd|d<|jdk	rhd|d<|js||jr tjj|jrt|tjj|j}||jkr||d
<|jrtjj
|tjj||j}ntjj
||j}tjj|tjjd}tjj||g|kr t|||S)N)rC/ri@Iirhr)r*r+r,linknamei)rr}r%realpath
ALLOW_MISSINGrseplstripisabsrr
commonpathrrhisregislnkisdirissymrr)r*r+r,rrnormpathdirnamer)member	dest_pathZfor_data	new_attrsrZtarget_pathrhZ
normalizedr6r6r7_get_filtered_attrssd






rcCs|S)Nr6)rrr6r6r7fully_trusted_filterTsrcCs(t||d}|r$|jf|ddiS|S)NFdeep)rr)rrrr6r6r7
tar_filterWsrcCs(t||d}|r$|jf|ddiS|S)NTrF)rr)rrrr6r6r7data_filter]sr)Z
fully_trustedrrs([0-9]{1,20}) c@seZdZdZdmZdnddZddZddZeeeZ	ddZ
dd Zee
eZd!d"Z
eeeeeeeed#ed$
d%d&Zd'd(Zeed)fd*d+Zd,d-Zd.d/Zd0d1Zed2d3Zd4d5Zed6d7Zed8d9Zed:d;Zed<d=Zed>d?Zed@dAZ dBdCZ!dDdEZ"dFdGZ#dHdIZ$dJdKZ%dLdMZ&dNdOZ'dPdQZ(dRdSZ)dTdUZ*dVdWZ+dXdYZ,dZd[Z-d\d]Z.d^d_Z/d`daZ0dbdcZ1dddeZ2dfdgZ3dhdiZ4djdkZ5dlS)oraInformational 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(chksumtyperr+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)rrr6r6r7rs"zTarInfo.__init__cCs|jS)N)r)rr6r6r7_getpathszTarInfo._getpathcCs
||_dS)N)r)rrr6r6r7_setpathszTarInfo._setpathcCs|jS)N)r)rr6r6r7_getlinkpathszTarInfo._getlinkpathcCs
||_dS)N)r)rrr6r6r7_setlinkpathszTarInfo._setlinkpathcCsd|jj|jt|fS)Nz<%s %r at %#x>)rrqrid)rr6r6r7__repr__szTarInfo.__repr__T)
rr(rhrr)r*r+r,r_KEEPc
Cs|	rtj|}n
tj|}||
k	r(||_||
k	r6||_||
k	rD||_||
k	rR||_||
k	r`||_||
k	rn||_||
k	r|||_||
k	r||_	|S)zGReturn a deep copy of self with the given attributes replaced.
        )
copydeepcopyrr(rhrr)r*r+r,)rrr(rhrr)r*r+r,rr
resultr6r6r7rs(
zTarInfo.replacecCs|jdkrd}n
|jd@}|j||j|j|j|j|j|j|j|j	|j
|j|jd
}|dt
kr~|djdr~|dd7<|S)z9Return the TarInfo's attributes as a dictionary.
        Ni)
rrhr)r*r'r(rrrr+r,rrrrr)rhrr)r*r'r(rrrr+r,rrDIRTYPEr)rrhinfor6r6r7get_infos&


zTarInfo.get_infosurrogateescapecCs~|j}x(|jD]\}}|dkrtd|qW|tkrH|j|||S|tkr^|j|||S|tkrr|j||StddS)z<Return a tar header as a string of 512 byte blocks.
        Nz%s may not be Nonezinvalid format)	ritemsr.r
create_ustar_headerrcreate_gnu_headerrcreate_pax_header)rrPr4r5rrvaluer6r6r7tobufs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_MAGICr0r/LENGTH_LINKr.LENGTH_NAME_posix_split_name_create_headerr
)rrr4r5r6r6r7rs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_MAGICr0r/r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErr)rrr4r5rTr6r6r7rszTarInfo.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,rBrCr)r@r*r'r(rr#rr)r+r+r#)r,r,r#r)r@r*r@r'r$r(r$)r%r&r'r()rrrrrr/UnicodeEncodeErrorr0
isinstancefloatstr_create_pax_generic_headerXHDTYPErr
)
rrr4rrZhnamer3rOvalrTr6r6r7rs4
.zTarInfo.create_pax_headercCs|j|tdS)zAReturn the object as a pax global header block sequence.
        zutf-8)r-XGLTYPE)clsrr6r6r7create_pax_global_header?sz 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)splitrEr0rr/
LENGTH_PREFIXrr.)rrr4r5Z
componentsrJrr6r6r7rEs
zTarInfo._posix_split_namecCs|jdttfk}|r@t|jddd|}t|jddd|}ntdd||}tdd||}|jdt}|dkrxtdt|jd	dd
||t|jddd@d|t|jd
dd|t|jddd|t|jddd|t|jddd|d|t|jddd
|||jdtt|jddd||t|jddd||t|jddd|t|jddd|t|jddd||g}tj	dt
dj|}	t|	t
dd}
|	dd t
d|
d|	d!d}	|	S)"zReturn a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        rrrr@rrNzTarInfo.type must not be Nonerrrhir)r*r'r$r(s        rrr+r#r,rrz%dsrilz%06orBieii)getCHRTYPEBLKTYPErQr8rr.rrSrrrrUrL)rrPr4r5Zhas_device_fieldsrrZfiletypepartsrTrr6r6r7rUs8
&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)rYr0rr1)Zpayloadr`rar6r6r7_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/r1r0rrr
r9)r1rrr4r5rr6r6r7r s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-8rCTrs21 hdrcharset=BINARY
rrrrB =
z././@PaxHeaderrrr'rr)
rr/r)r0r,rLrrr
r9)r1rrr4ZbinarykeywordrZrecordslrIr<rr6r6r7r-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)iIiQiYirirr$iii)$r0rurrvcountr1rwrKrUrHr=rrhr)r*r'r(rrrr+r,rrAREGTYPErrGNUTYPE_SPARSErEr.rboolrrrstrip	GNU_TYPES)r1rTr4r5robjrrstructsrJrnumbytes
isextendedorigsizer6r6r7frombufsZ
zTarInfo.frombufcCs8|jjt}|j||j|j}|jjt|_|j|S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )	rrZrrRr4r5rr_proc_member)r1rrTrMr6r6r7fromtarfile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)rr"r!
_proc_gnulongrI_proc_sparser.r0SOLARIS_XHDTYPE	_proc_pax
_proc_builtin)rrr6r6r7rS!s



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.
        )
rrrrrSUPPORTED_TYPES_blockr'r_apply_pax_inforr4r5)rrrr6r6r7rY.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)rrZr[r'rTrrxrrr"r=r4r5rr!r)rrrTnextr6r6r7rU?s

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.
        rr$rFi)rrrZrrErKr.rrJrrrr[r'r)
rrrNrPrQrTrrJrrOr6r6r7rVUs(zTarInfo._proc_sparsecCs|jj|j|j}|jtkr&|j}n
|jj}d}d}g}x0t||koV||dkrnt	j
||}|srtdyt|j
d}Wntk
rtdYnX|dkrtd||t|krtd|jd|d}	||jdd|	}
|
jd\}}}
|s"|dks"||	dkr*td|j|||
f|dkrd|dkrd|
d	kr`|j}nd
}||7}q@W|dkr~d
}x`|D]X\}}}
|j|d
d
|j}|tkr|j|
||j|j}n|j|
d
d
|j}|||<qWy|j|}Wntk
rtdYnXd|kr&|j||nFd
|kr>|j||n.|jddkrl|jddkrl|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.
        rNzinvalid headerr#r;rs
hdrcharsetsBINARYzutf-8z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrDr')%rrZr[r'rr0rrr0_header_length_prefix_rematchrHrFgroupr.rrk	partitionrr4_decode_pax_fieldr5PAX_NAME_FIELDSrTrrx_proc_gnusparse_01_proc_gnusparse_00r5_proc_gnusparse_10r.rWr\rrrrZ)rrrTrrr4raw_headersrbr3Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuer=rr]rr6r6r7rXqsx

 







 
zTarInfo._proc_paxcCsg}g}x|D]\}}}|dkrVy|jt|jWqtk
rRtdYqXq|dkry|jt|jWqtk
rtdYqXqWtt|||_dS)z?Process a GNU tar extended sparse header, version 0.0.
        sGNU.sparse.offsetzinvalid headersGNU.sparse.numbytesN)rrFr;r.rHlistzipr)rr]rjZoffsetsrO_r=rr6r6r7rhszTarInfo._proc_gnusparse_00cCs@dd|djdD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|qSr6)rF).0xr6r6r7
<listcomp>sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>zGNU.sparse.map,Nr$r#)r3rkrlr)rr]rrr6r6r7rgszTarInfo._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.
        Nr<r#r$)rrZrr3rFr0rrrrkrlr)rr]rrZfieldsrrTZnumberr6r6r7ris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)	rsetattrrF
PAX_FIELDSPAX_NUMBER_FIELDSr.rKrr)rrr4r5r=rr6r6r7r\s"

zTarInfo._apply_pax_infocCs.y|j|dStk
r(|j||SXdS)z1Decode a single field from a pax record.
        rCN)r;UnicodeDecodeError)rrr4Zfallback_encodingZfallback_errorsr6r6r7re,szTarInfo._decode_pax_fieldcCs2|dkrtdt|t\}}|r*|d7}|tS)z_Round up a byte count by BLOCKSIZE and return it,
           e.g. _block(834) => 1024.
        rzinvalid offsetr#)rHrYr)rrGr`rar6r6r7r[4szTarInfo._blockcCs
|jtkS)N)r
REGULAR_TYPES)rr6r6r7r@sz
TarInfo.isregcCs|jS)N)r)rr6r6r7isfileBszTarInfo.isfilecCs
|jtkS)N)rr)rr6r6r7rDsz
TarInfo.isdircCs
|jtkS)N)rSYMTYPE)rr6r6r7rFsz
TarInfo.issymcCs
|jtkS)N)rLNKTYPE)rr6r6r7rHsz
TarInfo.islnkcCs
|jtkS)N)rr6)rr6r6r7ischrJsz
TarInfo.ischrcCs
|jtkS)N)rr7)rr6r6r7isblkLsz
TarInfo.isblkcCs
|jtkS)N)rFIFOTYPE)rr6r6r7isfifoNszTarInfo.isfifocCs
|jdk	S)N)r)rr6r6r7issparsePszTarInfo.issparsecCs|jtttfkS)N)rr6r7r|)rr6r6r7isdevRsz
TarInfo.isdevN)rrhr)r*r'r(rrrr+r,rrrrrrrrr)r)6rqrrrsrt	__slots__rrrpropertyr%rrr&r	r
rrrrrrrrclassmethodr2rstaticmethodrr9r r-rRrTrSrYrUrVrXrhrgrir\rer[rrwrrrrzr{r}r~rr6r6r6r7rssf



1*
3?
zc
@seZdZdZdZdZdZdZeZ	e
ZdZe
ZeZdZdkdd	Zedddefd
dZedldd
ZedmddZednddZedoddZdddddZddZddZddZd d!Zdpd"d#Zdqdd%d&d'Z drdd(d)d*Z!dsd+d,Z"d-d.Z#dtddd0d1d2Z$d3d4Z%duddd0d6d7Z&d8d9Z'dvd:d;Z(d<d=Z)d>d?Z*d@dAZ+dwdddBdCdDZ,dEdFZ-dGdHZ.dIdJZ/dKdLZ0dMdNZ1dOdPZ2dQdRZ3dSdTZ4dUdVZ5dWdXZ6dYdZZ7dxd[d\Z8d]d^Z9dyd_d`Z:dadbZ;dcddZ<dedfZ=dgdhZ>didjZ?dS)zrz=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'rr{FNrrhTrzro)rr{ro)-r.rh_moder}r%exists	bltn_openrrr*rr,rLabspathrrPrdereferenceignore_zerosr4r5rrdebug
errorlevelcopybufsizermembers_loadedrrinodesfirstmemberr]rrTrrwrrr2rr[r0r)rrrhrrPrrrr4r5rrrrZmodeserTr6r6r7rrs






$
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)r1r6r7not_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'Frrozundiscernible mode)rzr)rzr{)rr{ro)
r.sortedrrlrrrrr3rrrr)
r1rrhrr_kwargsrrfuncZ	saved_posrgstreamrr6)r1r7rsP%







zTarFile.opencKs |dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing.
        rzrr{roz!mode must be 'r', 'a', 'w' or 'x')rzrr{ro)r.)r1rrhrrr6r6r7r<szTarFile.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)r.gzipZGzipFilerAttributeErrorrrrrrr)r1rrhr
compresslevelrrrr6r6r7gzopenDs2
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)r.rrrZBZ2FilerrEOFErrorrrr)r1rrhrrrrrr6r6r7bz2openfs(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)r.rrrZLZMAFilerrrrrr)r1rrhrrrrrr6r6r7xzopens&zTarFile.xzopenrrrr)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.
        NTrr{ror$r)rr{ro)rrhrr[r1rrrY
RECORDSIZErr)rr`rar6r6r7rs
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)rrrr6r6r7	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.
        )_checkr_loadr)rr6r6r7
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|]
}|jqSr6)r)rnrr6r6r7rpsz$TarFile.getnames.<locals>.<listcomp>)r)rr6r6r7getnamesszTarFile.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%
splitdriverrrrrrrrrffstatfilenost_modeS_ISREGst_inost_devst_nlinkrryrS_ISDIRrS_ISFIFOr|S_ISLNKrxreadlinkS_ISCHRr6S_ISBLKr7rhst_uidr)st_gidr*st_sizer'st_mtimer(rrpwdgetpwuidr+rgrpZgetgrgidr,rst_rdevrrr)rrarcnamerZdrvrZstatresrZstmdinoderr6r6r7
gettarinfos~	




zTarFile.gettarinfoT)rcCs0|j|dkr|}x|D]
}|r|jdkr:tdnttj|jtd|jpX|j|jpb|jf|j	sz|j
rtdd|j|jfntd|j
|jdkrtdntdtj|jdd	t|j|jrd
nd|r"|jr
td|j|jr"td
|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
??????????z%s/%sz%10sz%d,%dz%10dz????-??-?? ??:??:??z%d-%02d-%02d %02d:%02d:%02drrrz-> zlink to )rrhrprfrgr+r)r,r*rzr{rrr'r(rZ	localtimerrrrrro)rverboserrr6r6r7rk>s2





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 %rr)r)rrcrdre_dbgrr}r%rrrraddfilerlistdiraddr)	rrr	recursiveZexcluderrcrfr6r6r7rdsB



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#)rrrrPr4r5rr[rr0rrXr'rYrr1rr)rrrrTr_r`rar6r6r7rs

zTarFile.addfilec"CsH|dkr|j}|dkrtjjd}|dkrytt}Wntk
rNYnBXddl}|jddd}||j	|WdQRX|jdddd}|ryt
|}Wn&tk
rtd|d	dYnX||_|St
rtjdttStSt|trtd|St|r|Syt
|Stk
rBtd|d	dYnXdS)NZ PYTHON_TARFILE_EXTRACTION_FILTERr#)Z
interpolationZcomment_prefixesrr)Zfallbackzfilter z
 not foundz4The default behavior of tarfile extraction has been z$changed to disallow common exploits z(including CVE-2007-4559). z1By default, absolute/parent paths are disallowed z and some mode bits are cleared. z/See https://access.redhat.com/articles/7004769 zfor more details.z#String names are not supported for z2TarFile.extraction_filter. Use a function such as ztarfile.data_filter directly.)rzXThe default behavior of tarfile extraction has been changed to disallow common exploits zsThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). zThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed zThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. zThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 aThe default behavior of tarfile extraction has been changed to disallow common exploits (including CVE-2007-4559). By default, absolute/parent paths are disallowed and some mode bits are cleared. See https://access.redhat.com/articles/7004769 for more details.zUString names are not supported for TarFile.extraction_filter. Use a function such as zrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.)extraction_filterr}environr5r_CONFIG_FILENAMEFileNotFoundErrorconfigparserZConfigParserZ	read_file_NAMED_FILTERSrr._RH_SAFER_DEFAULTrcrdRuntimeWarningrrr*r,	TypeErrorcallable)rrrfilerZconfr6r6r7_get_filter_functionsR


zTarFile._get_filter_function.)
numeric_ownerrc"Csg}|j|}|dkr|}xT|D]L}|j|||\}}	|dkr@q |jrR|j|	|j|||j||dq W|jddddx$|D]}	yy||	|}Wn4tk
r}
z|j|	t|
wWYdd}
~
XnX|dkr|j|	dwt	j
j||j}yt	j
|}Wn$tk
r.|j|dwYnXtj|jsL|j|d	w|j|||d
|j|||j||Wqtk
r}
z|j|
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.

           The `filter` function will be called on each member just
           before extraction.
           It can return a changed TarInfo or None to skip the member.
           String names of common filters are accepted.
        N)	set_attrsrfilter_functioncSs|jS)N)r)rr6r6r7<lambda>	sz$TarFile.extractall.<locals>.<lambda>T)rreversezexcluded by filterZmissingznot a directory)r)r_get_extract_tarinforr_extract_onesort_FILTER_ERRORS_log_no_directory_fixupreprr}r%rrrrrfrrchownutimechmodr
_handle_nonfatal_error)rr%rrrZdirectoriesrrr
unfilteredexcdirpathrrr6r6r7
extractallsP


zTarFile.extractallcCs|jdd|j|fdS)Nr$z(tarfile: Not fixing up directory %r (%s))rr)rrreasonr6r6r7r4	szTarFile._log_no_directory_fixuprc	Cs8|j|}|j|||\}}|dk	r4|j||||dS)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.

           The `filter` function will be called before extraction.
           It can return a changed TarInfo or None to skip the member.
           String names of common filters are accepted.
        N)rrr)	rrr%rrrrrrr6r6r7extract8	s

zTarFile.extractcCst|tr|j|}n|}d}y|||}WnZttfk
r\}z|j|WYdd}~Xn,tk
r}z|j|WYdd}~XnX|dkr|jdd|j	dS|j
rtj|}tj
j||j|_||fS)zGet (filtered, unfiltered) TarInfos from *member*

        *member* might be a string.

        Return (None, None) if not found.
        Nr$ztarfile: Excluded %r)NN)r*r,rrr_handle_fatal_errorr
rrrrrr}r%rrr)rrrr%rfilteredrr6r6r7rL	s"

zTarFile._get_extract_tarinfocCs|jdy&|j|tjj||j||||dWnVtk
r\}z|j|WYdd}~Xn,tk
r}z|j	|WYdd}~XnXdS)zExtract from filtered tarinfo to disk.

           filter_function is only used when extracting a *different*
           member (e.g. as fallback to creating a symlink)
        rz)rrrextraction_rootN)
r_extract_memberr}r%rrrrr
r)rrr%rrrrr6r6r7rj	s
zTarFile._extract_onecCs"|jdkrn|jdd|dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#ztarfile: %sN)rr)rrr6r6r7r~	s
zTarFile._handle_nonfatal_errorcCsn|jdkrn\t|trP|jdkr6|jdd|jqj|jdd|j|jfn|jddt|j|fdS)z1Handle "fatal" error according to self.errorlevelrNr#ztarfile: %sztarfile: %s %rztarfile: %s %s)rr*rfilenamerstrerrorrrq)rrr6r6r7r	s


zTarFile._handle_fatal_errorcCs|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)rr*r,rrrrZ
fileobjectrrrrr	extractfile_find_link_target)rrrr6r6r7r	s


zTarFile.extractfile)rrcCs\|jd}|jdtj}tjj|}|r@tjj|r@tj||jsP|j	rj|j
dd|j|jfn|j
d|j|j
r|j||n|jr|j||n~|jr|j||nh|js|jr|j||nJ|js|j	r|j||||dn&|jtkr|j||n|j|||rX|j||||j	sX|j|||j||dS)zExtract the filtered TarInfo object tarinfo to a physical
           file called targetpath.

           filter_function is only used when extracting a *different*
           member (e.g. as fallback to creating a symlink)
        rr#z%s -> %s)rrN)rKrr}rr%rrmakedirsrrrrrrmakefilermakedirr}makefiforzr{makedevmakelink_with_filterrrZmakeunknownrrr)rr
targetpathrrrrZ	upperdirsr6r6r7r	s:



zTarFile._extract_membercCs@y&|jdkrtj|ntj|dWntk
r:YnXdS)z,Make a directory called targetpath.
        Ni)rhr}mkdirFileExistsError)rrrr6r6r7r	s
zTarFile.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.
        rN)
rrrrrrrXrr'truncate)rrrsourcer_targetrr'r6r6r7r	s


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)rrrr6r6r7r
szTarFile.makeunknowncCs"ttdrtj|ntddS)z'Make a fifo called targetpath.
        mkfifozfifo not supported by systemN)rr}rr
)rrrr6r6r7r
s
zTarFile.makefifocCsnttdsttdr td|j}|dkr2d}|jrF|tjO}n
|tjO}tj||tj	|j
|jdS)z<Make a character or block device called targetpath.
        mknodrz'special devices not supported by systemNi)rr}r
rhr{rfS_IFBLKS_IFCHRrrrr)rrrrhr6r6r7r
s
zTarFile.makedevcCs|j||ddS)N)r)rrrr6r6r7makelink(
szTarFile.makelinkc	$Cs&d}yT|jr6tjj|r$tj|tj|j|dStjj|jrVtj	|j|dSWnt
k
rpd}YnXy|j|}Wn$tk
r|rt
dnYnX|dkr|}nR|dkrt
dy|||}Wn2tk
r}zt||j|WYdd}~XnX|dk	r"|j||||ddS)	a3Make 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.

          filter_function is only used when extracting a *different*
          member (e.g. as fallback to creating a link).
        FNTz%unable to resolve link inside archivez6makelink_with_filter: if filter_function is not None, z%extraction_root must also not be None)rrz[makelink_with_filter: if filter_function is not None, extraction_root must also not be None)rr}r%lexistsunlinksymlinkrrrlinksymlink_exceptionrrr
rrrr)	rrrrrZkeyerror_to_extracterrorrrcauser6r6r7r+
sB	

 
zTarFile.makelink_with_filtercCsttdrtjdkr|j}|j}|sytrB|jrBtj|jd}Wntk
rXYnXyt	rv|j
rvt	j|j
d}Wntk
rYnX|dkrd}|dkrd	}y4|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$Nr#lchownzcould not change ownerr9r9)rr}rr*r)rr,Zgetgrnamrrr+getpwnamrrrrr
)rrrrgur6r6r7r]
s0

z
TarFile.chowncCsL|jdkrdSttdrHytj||jWntk
rFtdYnXdS)zASet file permissions of targetpath according to tarinfo.
        Nrzcould not change mode)rhrr}rrr
)rrrr6r6r7r~
s

z
TarFile.chmodcCsV|j}|dkrdSttds dSytj|||fWntk
rPtdYnXdS)zBSet modification time of targetpath according to tarinfo.
        Nrz"could not change modification time)r(rr}rrr
)rrrr(r6r6r7r
s
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)rrrrrrrZrrrTrwrrrrHr,rurvrxrrr)rmrrr6r6r7r]
sL


zTarFile.nextc	Cs|j}d}|dk	rHy|j|}Wntk
r:d}YnX|d|}|rXtjj|}xLt|D]@}|r||j|jkrbd}qb|rtjj|j}n|j}||krb|SqbW|rt|dS)z}Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        FNT)	rindexr.r}r%rreversedrr)	rrr	normalizerZskippingrrmember_namer6r6r7r
s,
zTarFile._getmembercCs"x|j}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)r]r)rrr6r6r7r
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)rrhr6r6r7r
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)rr!zlinkname %r not found)
rrrr}r%rrrrr)rrrlimitrr6r6r7rs 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)rrrr]r0)rrrr6r6r7__iter__s&
zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr.
        )rN)rrormstderr)rlevelmsgr6r6r7r:s
zTarFile._dbgcCs|j|S)N)r)rr6r6r7	__enter__@szTarFile.__enter__cCs,|dkr|jn|js"|jjd|_dS)NT)rrrr)rrr	tracebackr6r6r7__exit__Ds


zTarFile.__exit__)
NrzNNNNNNrNNNN)rzN)rzNr)rzNr)rzNN)NNN)T)NTN)N)rN)rT)N)TF)NF)N)@rqrrrsrtrrrrrrPrr4r5rrrrrrrrrrrrrrrrrrrrkrrrrrrrrrrrrrrrrrrrrrrr]rrrrr$rr(r*r6r6r6r7rVs
lZ!

d&=
5D
62!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)rrr6r6r7rRscCsddl}d}|j|d}|jdddddd	|jd
dtdd
|j}|jddddd|jdddd5dd|jdddd6dd|jdddd d|j}|jr|jr|jd!d"|j	r*|j	}t
|rt|d# }|jt
|jtjd$WdQRX|jr&t
d%j|n|jd!d&j|n|jr|j}t
|rjtj|d'}|j|jd(WdQRXn|jd!d&j|n|jrPt|jd!kr|jd}tj}n,t|jd)kr|j\}}n|jd!|jt
|r<tj|d'}|j||jd*WdQRX|jrN|d+kr&d,j|}	nd-j||}	t
|	n|jd!d&j|n|jr|jjd}
tjj|
\}}d.d.d/d/d0d0d0d0d1}
||
krd2|
|nd3}|j}tj|
| }x|D]}|j|qWWdQRX|jrt
d4j|
n|jd!|jdS)7Nrz3A simple command line interface for tarfile module.)descriptionz-vz	--verbose
store_trueFzVerbose output)actiondefaulthelpz--filterz<filtername>zFilter for extraction)metavarchoicesr/z-lz--list	<tarfile>zShow listing of a tarfile)r0r/z-ez	--extract+<output_dir>zExtract tarfile into target dir)nargsr0r/z-cz--create<name><file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction
rz)rz{!r} is a tar archive.z{!r} is not a tar archive.
zr:*)rr$)r%rrz{!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.)r2r4)r6r7)argparseArgumentParseradd_argumentrZadd_mutually_exclusive_group
parse_argsrrexitZtestrrrrormr%rrPrkrr0r}curdirZformat_helprZcreatepopr%splitextr)r8r+parserrcargsr\rZtfr=r'Ztar_namermZextZcompressionsZtar_modeZ	tar_files	file_namer6r6r7main`s










rC__main__)r%r&r'r(r)r*r+r,)T)trtversion
__author__Z__date__Z	__cvsid____credits__builtinsrrrmr}rrWrfrrSrrercrrrrNotImplementedErrorrr	NameError__all__rrr1rrrrrrr4rrHryrxr6r7rr|ZCONTTYPEr"r!rIr.r0rWr
rrrrZrvrLrsrfr+rFrtrrgetfilesystemencodingr8r=rKrQrUrXrgrp	Exceptionrr
rrr	rrurvrwrHrxryrobjectrrBufferedReaderrrrrrrrrrrrrrrr
compilerarrrrCrqr6r6r6r7<module>s&



wh



D
hb