• File: tarfile.cpython-38.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python38/lib64/python3.8/__pycache__/tarfile.cpython-38.pyc
  • Date Modified: 10/26/2026 8:15 PM
  • File size: 71.78 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
U

j8@s*dZdZdZdZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZzddlZWnek
rdZYnXzddlZWnek
rdZYnXeefZzeef7ZWnek
rYnXddd	d
ddd
ddddddddgZdZdZedZdZdZdZdZ dZ!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*Z0dZ1d+Z2d,Z3e3Z4e"e#e$e%e(e)e*e&e'e+e,e-fZ5e"e#e*e-fZ6e+e,e-fZ7d-Z8d.d/d0d1hZ9e:e:e:e;e;e;d2Z<ej=d3krd4Z>ne?Z>d5d6Z@d7d8ZAd9d:ZBd;e4fd<d=ZCd>d?ZDdedfd@dAZEdBdCZFGdDd
d
eGZHGdEddeHZIGdFddeHZJGdGddeHZKGdHd
d
eHZLGdIddeHZMGdJdKdKeMZNGdLdMdMeMZOGdNdOdOeMZPGdPdQdQeMZQGdRdSdSeMZRGdTdUdUZSGdVdWdWZTGdXdYdYeUZVGdZd[d[eUZWGd\d]d]e	jXZYGd^d_d_eHZZGd`dadaeZZ[GdbdcdceZZ\GdddedeeZZ]GdfdgdgeZZ^GdhdidieZZ_GdjdkdkeZZ`eZeeIfZad}dmdnZbdodpZcdqdrZddsdtZeecedeeduZfeUZgehdvZiGdwddeUZjGdxddeUZkdyd	ZlekjZdzd{Zmend|kr&emdS)~z,Read from and write to tar format archives.
z0.9.0u"Lars Gustäbel (lars@gustaebel.de)u4Gustavo Niemeyer, Niels Gustäbel, Richard Townsend.)openNTarFileTarInfo
is_tarfileTarError	ReadErrorCompressionErrorStreamErrorExtractErrorHeaderErrorENCODINGUSTAR_FORMAT
GNU_FORMAT
PAX_FORMATDEFAULT_FORMATrisustar  sustar00d01234567LKSxgX)pathlinkpathsizemtimeuidgidunamegnamer%r&r+r,)Zatimectimer(r)r*r'ntutf-8cCs8|dkrtd|||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    Nzmetadata cannot contain None)
ValueErrorencodelenNUL)slengthencodingerrorsr8,/opt/alt/python38/lib64/python3.8/tarfile.pystnsr:cCs*|d}|dkr|d|}|||S)z8Convert a null-terminated bytes object to a string.
    rN)finddecode)r4r6r7pr8r8r9ntss
r?cCs|ddkrbd}tt|dD]}|dK}|||d7}q |ddkrdt|d|}n@z"t|dd}t|p|d	d}Wntk
rtd
YnX|S)z/Convert a number field to a python number.
    r)r#rAasciistrict0invalid header)ranger2r?intstripr0InvalidHeaderError)r4nir8r8r9ntisrNrBcCst|}d|kr$d|dkrDnntd|d|fdt}n|tkrd|d|krrd|dkrnnV|dkrtdg}ntdg}d||}t|dD]}|d|d@|dL}qntd	|S)
z/Convert a python number to a number field.
    rrBr#z%0*orDrCr@rAzoverflow in number field)rIbytesr3r	bytearrayrHinsertr0)rLdigitsformatr4rMr8r8r9itns 2
rTcCs0dttd|}dttd|}||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.
    rCZ
148B8x356BZ
148b8x356b)sumstructZunpack_from)bufZunsigned_chksumZ
signed_chksumr8r8r9calc_chksumss	rXc	Cs|pd}|dkrdS|dkr.t|||dSt||\}}t|D],}||}t||krf|d||qD|dkr||}t||kr|d||dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    i@rNunexpected end of data)shutilcopyfileobjdivmodrHreadr2write)	srcZdstr5	exceptionbufsizeblocks	remainderbrWr8r8r9r[s$


r[cCs8ttjdd}|dk	r(||d|}t|dddS)Nr6backslashreplace )end)getattrsysstdoutr1r=print)r4r6r8r8r9_safe_printsrlc@seZdZdZdS)rzBase exception.N__name__
__module____qualname____doc__r8r8r8r9rsc@seZdZdZdS)r
z%General exception for extract errors.Nrmr8r8r8r9r
sc@seZdZdZdS)rz&Exception for unreadable tar archives.Nrmr8r8r8r9rsc@seZdZdZdS)rz.Exception for unavailable compression methods.Nrmr8r8r8r9rsc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.Nrmr8r8r8r9r	sc@seZdZdZdS)rz!Base exception for header errors.Nrmr8r8r8r9rsc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.Nrmr8r8r8r9rr srrc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.Nrmr8r8r8r9rs#srsc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.Nrmr8r8r8r9rt&srtc@seZdZdZdS)rKzException for invalid headers.Nrmr8r8r8r9rK)srKc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.Nrmr8r8r8r9ru,sruc@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}t||d|_dS)NrwO_BINARYi)	osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrrzrfd)selfnamemoder8r8r9__init__9s

z_LowLevelFile.__init__cCst|jdSN)r{closerrr8r8r9rBsz_LowLevelFile.closecCst|j|Sr)r{r]rrr'r8r8r9r]Esz_LowLevelFile.readcCst|j|dSr)r{r^rrr4r8r8r9r^Hsz_LowLevelFile.writeN)rnrorprqrrr]r^r8r8r8r9rv3s
	rvc@sreZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZdddZddZ
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|}|}|p<d|_||_||_||_||_d|_	d|_
d|_zL|dkrzddl}Wnt
k
rtd	YnX||_|d|_|d
kr||j|_n|n|dkr:zddl}Wnt
k
r
tdYnX|d
kr.d|_||_t|_n
||_n||d
krzddl}Wnt
k
rntdYnX|d
krd|_||_|j|_n
||_n|dkrtd|Wn&|js|jd|_YnXdS)z$Construct a _Stream object.
        TNF*rgzzzlib module is not availablerxbz2bz2 module is not availablexzlzma module is not availabletarunknown compression type %r) _extfileobjrv_StreamProxygetcomptyperrcomptypefileobjrarWposclosedzlibImportErrorrcrc32crc
_init_read_gzerrorr`_init_write_gzrdbufZBZ2DecompressorcmpOSErrorZ
BZ2CompressorlzmaZLZMADecompressor	LZMAErrorZLZMACompressorr)	rrrrrrarrrr8r8r9rVsl












z_Stream.__init__cCst|dr|js|dS)Nr)rrrrr8r8r9__del__sz_Stream.__del__cCs|jd|jj|jj|jjd|_tdtt		}|
d|d|jdrf|jdd|_t
j|j|_|
|jd	d
tdS)z6Initialize for writing with gzip compression.
        	r<Lss.gzNz
iso-8859-1replace)rZcompressobjZDEFLATED	MAX_WBITSZ
DEF_MEM_LEVELrrVpackrItime_Stream__writerendswithr{r%basenamer1r3)rZ	timestampr8r8r9rsz_Stream._init_write_gzcCsR|jdkr|j||j|_|jt|7_|jdkrD|j|}||dS)z&Write string s to the stream.
        rrN)	rrrrrr2rcompressrrr8r8r9r^s

z
_Stream.writecCsN|j|7_t|j|jkrJ|j|jd|j|j|jd|_qdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rWr2rarr^rr8r8r9Z__writesz_Stream.__writecCs|jr
dSd|_z|jdkr:|jdkr:|j|j7_|jdkr|jr|j	|jd|_|jdkr|j	t
d|j|j	t
d|j
d@W5|js|jXdS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        NTryrrrrl)rrrrrrrWrflushr^rVrrrrr8r8r9rs
z
_Stream.closecCs|j|jj|_d|_|ddkr0td|ddkrFtdt|d}|d|d	@rt|dd
t|d}|	||d@r|d}|r|t
krqq|d@r|d}|r|t
krqq|d@r|dd
S)z:Initialize for reading a gzip compressed fileobj.
        rr$snot a gzip filer#zunsupported compression methodrCrBN)rZ
decompressobjrrr
_Stream__readrrordr]r3)rflagZxlenr4r8r8r9rs*
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )rrr8r8r9tellsz_Stream.tellrcCs`||jdkrRt||j|j\}}t|D]}||j}|s,qFq,||ntd|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)rr\rarHr]r	)rrrbrcrMdatar8r8r9seeksz_Stream.seekcCs,|dk	st||}|jt|7_|S)z5Return the next size number of bytes from the stream.N)AssertionError_readrr2)rr'rWr8r8r9r]s
z_Stream.readcCs|jdkr||St|j}|jg}||kr|jrB|j}d|_n|j|j}|sVqz|j	|}Wn|j
k
rtdYnX|||t|7}q&d
|}||d|_|d|S)z+Return size bytes from the stream.
        rrzinvalid compressed dataN)rrr2rrWrr]rar
decompressr`rappendjoinrr'ctrWr8r8r9rs(




z
_Stream._readcCsjt|j}|jg}||krF|j|j}|s.qF|||t|7}qd|}||d|_|d|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        rN)r2rWrr]rarrrr8r8r9Z__read.s


z_Stream.__readN)r)rnrorprqrrrr^rrrrrr]rrr8r8r8r9rKs
F
	
rc@s0eZdZdZddZddZddZdd	Zd
S)rzsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs||_|jt|_dSr)rr]	BLOCKSIZErW)rrr8r8r9rDsz_StreamProxy.__init__cCs|jj|_|jSr)rr]rWrr8r8r9r]Hs
z_StreamProxy.readcCsP|jdrdS|jdddkr8|jdddkr8d	S|jd
rHdSdSdS)
NsrrsBZhr
s1AY&SYr)s]s7zXZrr)rW
startswithrr8r8r9rLs$z_StreamProxy.getcomptypecCs|jdSr)rrrr8r8r9rVsz_StreamProxy.closeN)rnrorprqrr]rrr8r8r8r9r?s

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}|D]L\}}||kr||j	d||df|j	d||||f||7}||}qX||jkr|j	d||jdfdS)NrrFT)
roffsetr'positionrhrr	map_indexmapr)rrrr'Z	blockinfoZlastposZrealposr8r8r9rcs(


z_FileInFile.__init__cCsdSrr8rr8r8r9r|sz_FileInFile.flushcCsdSNTr8rr8r8r9readablesz_FileInFile.readablecCsdS)NFr8rr8r8r9writablesz_FileInFile.writablecCs
|jSr)rseekablerr8r8r9rsz_FileInFile.seekablecCs|jS)z*Return the current file position.
        )rrr8r8r9rsz_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_ENDr0)rrwhencer8r8r9rs


z_FileInFile.seekc	Cs
|dkr|j|j}nt||j|j}d}|dkr|j|j\}}}}||jkr`|krhqnqq6|jd7_|jt|jkr6d|_q6t|||j}|r|j||j||j|}t||krt	d||7}n|t
|7}||8}|j|7_q,|S)z!Read data from the file.
        Nrrr#rY)r'rrrrr2rrr]rr3)	rr'rWrstartstoprr5rdr8r8r9r]s,

z_FileInFile.readcCs&|t|}||dt|<t|Sr)r]r2)rrdrWr8r8r9readintosz_FileInFile.readintocCs
d|_dSr)rrr8r8r9rsz_FileInFile.close)N)N)rnrorprqrrrrrrrrrr]rrr8r8r8r9r]s

rcseZdZfddZZS)ExFileObjectcs&t|j|j|j|j}t|dSr)rroffset_datar'sparsesuperr)rtarfiletarinfor	__class__r8r9rs

zExFileObject.__init__rnrorpr
__classcell__r8r8rr9rsrc@seZdZdS)FilterErrorN)rnrorpr8r8r8r9rsrcseZdZfddZZS)AbsolutePathErrorcs ||_td|jddS)Nzmember z has an absolute pathrrrrrrrr8r9rszAbsolutePathError.__init__rr8r8rr9rsrcseZdZfddZZS)OutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would be extracted to ,  which is outside the destinationr_pathrrrrrr%rr8r9rs
z OutsideDestinationError.__init__rr8r8rr9rsrcseZdZfddZZS)SpecialFileErrorcs||_t|jddS)Nz is a special filerrrr8r9rszSpecialFileError.__init__rr8r8rr9rsrcseZdZfddZZS)AbsoluteLinkErrorcs||_t|jddS)Nz is a link to an absolute pathrrrr8r9rszAbsoluteLinkError.__init__rr8r8rr9rsrcseZdZfddZZS)LinkOutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would link to rrrrrr8r9rs
z$LinkOutsideDestinationError.__init__rr8r8rr9rsrcseZdZfddZZS)LinkFallbackErrorcs2||_||_td|jdd|ddS)Nzlink z would be extracted as a zcopy of z, which was rejectedrrrr8r9rs

zLinkFallbackError.__init__rr8r8rr9rsrTc	Csi}|j}tjj|tjjd}|dtjfrH|jdtj}|d<tj|r\t	|d|
tjddkrtj|}||kr|}|d<tjjtj
||tjjd}tj||g|krt|||j}|dk	rT|d@}|r@|s|r|d@s|dM}|dO}n"|s2|r8d}nt|||jkrT||d	<|r|jdk	rnd|d
<|jdk	rd|d<|jdk	rd|d<|jdk	rd|d
<|s|rtj|jrt|||krt||tj|j}||jkr||d<|r@tj|dtj}tj
|||}ntj
||}tjj|tjjd}tj||g|krt|||S)N)rE/rz..i@irr)r*r+r,linkname)rr{r%realpath
ALLOW_MISSINGrseplstripisabsrrsplitnormpathr
commonpathrrisregislnkisdirissymrr)r*r+r,rrdirnamerstripr)	member	dest_pathZfor_data	new_attrsrZ
normalizedZtarget_pathrZlink_dirr8r8r9_get_filtered_attrssp







rcCs|Srr8)rrr8r8r9fully_trusted_filterOsrcCs(t||d}|r$|jf|ddiS|S)NFdeeprrrrr
r8r8r9
tar_filterRsrcCs(t||d}|r$|jf|ddiS|S)NTrFrrr8r8r9data_filterXsr)Z
fully_trustedrrs([0-9]{1,20}) c@seZdZdZedddddddd	d
ddd
dddddddddZdnddZeddZej	ddZeddZ
e
j	ddZ
ddZeeeeeeeed ed!
d"d#Z
d$d%Zeed&fd'd(Zd)d*Zd+d,Zd-d.Zed/d0Zd1d2Zed3d4Zed5d6Zed7d8Zed9d:Zed;d<Zed d=d>d?Zed@dAZed d=dBdCZ dDdEZ!dFdGZ"dHdIZ#dJdKZ$dLdMZ%dNdOZ&dPdQZ'dRdSZ(dTdUZ)dVdWZ*dXdYZ+dZd[Z,d\d]Z-d^d_Z.d`daZ/dbdcZ0dddeZ1dfdgZ2dhdiZ3djdkZ4dldmZ5dS)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.
    zName of the archive member.zPermission bits.z6User ID of the user who originally stored this member.z7Group ID of the user who originally stored this member.zSize in bytes.zTime of last modification.zHeader checksum.zFile type. type is usually one of these constants: REGTYPE, AREGTYPE, LNKTYPE, SYMTYPE, DIRTYPE, FIFOTYPE, CONTTYPE, CHRTYPE, BLKTYPE, GNUTYPE_SPARSE.zcName of the target file name, which is only present in TarInfo objects of type LNKTYPE and SYMTYPE.z
User name.zGroup name.zDevice major number.zDevice minor number.zThe tar header starts here.zThe file's data starts here.zMA dictionary containing key-value pairs of an associated pax extended header.zSparse member information.N)rrr)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)rrr)r*r'r(rREGTYPErrr+r,rrrrrrrrr8r8r9rs"zTarInfo.__init__cCs|jS)z(In pax headers, "name" is called "path".rrr8r8r9r%szTarInfo.pathcCs
||_dSrrrr8r8r9r%scCs|jS)z0In pax headers, "linkname" is called "linkpath".rrr8r8r9r&szTarInfo.linkpathcCs
||_dSrr)rrr8r8r9r&scCsd|jj|jt|fS)Nz<%s %r at %#x>)rrnridrr8r8r9__repr__szTarInfo.__repr__T)
rr(rrr)r*r+r,r_KEEPc
Cs|	rt|}n
t|}||
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.
        )
copyZdeepcopyrr(rrr)r*r+r,)rrr(rrr)r*r+r,rr"resultr8r8r9rs(
zTarInfo.replacecCs|jdkrd}n
|jd@}|j||j|j|j|j|j|j|j|j	|j
|j|jd
}|dt
kr||dds||dd7<|S)z9Return the TarInfo's attributes as a dictionary.
        N)
rrr)r*r'r(rrrr+r,rrrrr)rrr)r*r'r(rrrr+r,rrDIRTYPEr)rrinfor8r8r9get_infos(

zTarInfo.get_infosurrogateescapecCsz|}|D]\}}|dkrtd|q|tkrD||||S|tkrZ||||S|tkrn|||StddS)z<Return a tar header as a string of 512 byte blocks.
        Nz%s may not be Nonezinvalid format)	r(itemsr0r
create_ustar_headerrcreate_gnu_headerrcreate_pax_header)rrSr6r7r'rvaluer8r8r9tobufsz
TarInfo.tobufcCsnt|d<t|d||tkr(tdt|d||tkr^||d||\|d<|d<||t||S)z3Return the object as a ustar header block.
        magicrzlinkname is too longrprefix)	POSIX_MAGICr2r1LENGTH_LINKr0LENGTH_NAME_posix_split_name_create_headerr
)rr'r6r7r8r8r9r+szTarInfo.create_ustar_headercCst|d<d}t|d||tkr<|||dt||7}t|d||tkrl|||dt||7}|||t	||S)z:Return the object as a GNU header block sequence.
        r0rrr)
	GNU_MAGICr2r1r3_create_gnu_long_headerGNUTYPE_LONGLINKr4GNUTYPE_LONGNAMEr6r)rr'r6r7rWr8r8r9r,szTarInfo.create_gnu_headerc
	Cs*t|d<|j}ddtfddtfddfD]j\}}}||kr>q*z||dd	Wn$tk
rv||||<Yq*YnXt|||kr*||||<q*d
D]`\}}||krd||<q||}d|krd|d
krnn
t|t	rt
|||<d||<q|r||t|}	nd}	|	|
|tddS)zReturn the object as a ustar header block. If it cannot be
           represented this way, prepend a pax extended header sequence
           with supplement information.
        r0rr%rr&)r+r+ )r,r,r;rDrE))r)rB)r*rB)r')r(r<rrBr#rr)r2rr#r4r3r1UnicodeEncodeErrorr2
isinstancefloatstr_create_pax_generic_headerXHDTYPEr6r
)
rr'r6rrZhnamer5rRvalrWr8r8r9r-"s8

*
zTarInfo.create_pax_headercCs||tdS)zAReturn the object as a pax global header block sequence.
        r/)rAXGLTYPE)clsrr8r8r9create_pax_global_headerSsz TarInfo.create_pax_global_headercCs~|d}tdt|D]T}d|d|}d||d}t|||tkrt|||tkrqvqtd||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        rr#Nzname is too long)rrHr2rr1
LENGTH_PREFIXr4r0)rrr6r7Z
componentsrMr1r8r8r9r5Ys
zTarInfo._posix_split_namecCs|dttfk}|r@t|ddd|}t|ddd|}ntdd||}tdd||}|dt}|dkrxtdt|d	dd
||t|ddd@d|t|d
dd|t|ddd|t|ddd|t|ddd|d|t|ddd
|||dtt|ddd||t|ddd||t|ddd|t|ddd|t|ddd||g}t	dt
d|}	t|	t
dd}
|	ddt
d|
d|	dd}	|	S) zReturn a header block. info is a dictionary with file
           information, format must be one of the *_FORMAT constants.
        rrrrBrrNzTarInfo.type must not be Nonerrrr%r)r*r'r<r(s        rr0r+r;r,r1rz%dsriz%06orDi)getCHRTYPEBLKTYPErTr:rr0r2rVrrrrXrO)r'rSr6r7Zhas_device_fieldsrrZfiletypepartsrWrr8r8r9r6is:
&zTarInfo._create_headercCs.tt|t\}}|dkr*|t|t7}|S)zdReturn the string payload filled with zero bytes
           up to the next 512 byte border.
        r)r\r2rr3)Zpayloadrbrcr8r8r9_create_payloadszTarInfo._create_payloadcCsR|||t}i}d|d<||d<t||d<t|d<||t||||S)zTReturn a GNUTYPE_LONGNAME or GNUTYPE_LONGLINK sequence
           for name.
        z
././@LongLinkrrr'r0)r1r3r2r7r6r
rL)rErrr6r7r'r8r8r9r8szTarInfo._create_gnu_long_headerc	Cs2d}|D]8\}}z|ddWqtk
rBd}YqFYqXqd}|rV|d7}|D]\}}|d}|r||d}n
|d}t|t|d}d	}	}
|tt|
}	|	|
krq|	}
q|tt|
d
d|d|d
7}q^i}d|d<||d<t||d<t|d<||td
d|	|S)zReturn a POSIX.1-2008 extended or global header sequence
           that contains a list of keyword, value pairs. The values
           must be strings.
        Fr/rETrs21 hdrcharset=BINARY
r)rrrD =
z././@PaxHeaderrrr'r0r)
r*r1r=r2r@rOr2r6r
rL)rErrr6Zbinarykeywordr.ZrecordslrLr>r'r8r8r9rAs<

(z"TarInfo._create_pax_generic_headercCs||||S)zConstruct a TarInfo object from a 512 byte bytes object.

        To support the old v7 tar format AREGTYPE headers are
        transformed to DIRTYPE headers if their name ends in '/'.
        )_frombuf)rErWr6r7r8r8r9frombufszTarInfo.frombufdircheckc	Cs|t|dkrtdt|tkr(td|ttkr>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||}|r|jtkr|jdrt|_|jtkr>d}g}	tdD]l}
z0t|||d}t||d|d}Wntk
rYqYnX|	||f|d7}qt|d}
t|dd}|	|
|f|_ |!rV|j"d|_|rx|jt#krx|d|j|_|S)a\Construct a TarInfo object from a 512 byte bytes object.

        If ``dircheck`` is set to ``True`` then ``AREGTYPE`` headers will
        be normalized to ``DIRTYPE`` if the name ends in a trailing slash.
        ``dircheck`` must be set to ``False`` if this function is called
        on a follow-up header such as ``GNUTYPE_LONGNAME``.
        rzempty headerztruncated headerzend of file headerzbad checksumrlt|ii	i)iIiQiYirirr<iii)$r2rrrrscountr3rtrNrXrKr?rrr)r*r'r(rrrr+r,rrAREGTYPErr&GNUTYPE_SPARSErHr0rboolrrr
	GNU_TYPES)rErWr6r7rUrobjr1rstructsrMrnumbytes
isextendedorigsizer8r8r9rRsZ	 
zTarInfo._frombufcCs
||S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )_fromtarfile)rErr8r8r9fromtarfile.szTarInfo.fromtarfilecCs<|jt}|j||j|j|d}|jt|_||S)z;
        See dircheck documentation in _frombuf().
        rT)	rr]rrRr6r7rr_proc_member)rErrUrWrcr8r8r9rh5szTarInfo._fromtarfilecCsT|jttfkr||S|jtkr,||S|jtttfkrF|	|S|
|SdS)zYChoose the right processing method depending on
           the type and call it.
        N)rr:r9
_proc_gnulongr`_proc_sparserBrDSOLARIS_XHDTYPE	_proc_pax
_proc_builtin)rrr8r8r9rjJs



zTarInfo._proc_membercCsR|j|_|j}|s$|jtkr4|||j7}||_|	|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_inforr6r7)rrrr8r8r9roWszTarInfo._proc_builtincCs|j||j}z|j|dd}Wntk
rBtdYnX|j|_|jt	krjt
||j|j|_
n|jtkrt
||j|j|_|S)zSProcess the blocks that hold a GNU longname
           or longlink member.
        FrT missing or bad subsequent header)rr]rqr'rhrrurrr:r?r6r7rr9r)rrrWnextr8r8r9rkhs

zTarInfo._proc_gnulongc
	Cs|j\}}}|`|r|jt}d}tdD]n}z0t|||d}t||d|d}	Wntk
rzYqYnX|r|	r|||	f|d7}q,t|d}q||_	|j
|_|j||j
|_||_
|S)z8Process a GNU sparse header plus extra headers.
        rr<r]i)rrr]rrHrNr0rrarrrrqr'r)
rrrdrfrgrWrrMrrer8r8r9rl~s(
zTarInfo._proc_sparsecCs|j||j}|jtkr&|j}n
|j}d}d}g}t||krj||dkrjt	
||}sptdzt|
d}Wntk
rtdYnX|dkrtd||t|krtd|d|d}	||dd|	}
|
d\}}}
|r|dks||	dkr&td||||
f|dkr`|dkr`|
d	kr\|j}nd
}||7}q<|dkrxd
}|D]X\}}}
||d
d
|j}|tkr||
||j|j}n||
d
d
|j}|||<q|z|j|dd}Wntk
rtd
YnXd|kr |||nFd|kr8|||n.|ddkrf|ddkrf|||||jttfkr| ||j|j|j!|_!d|kr|j"}|#s|jt$kr|||j7}||_!|S)zVProcess an extended or global header as described in
           POSIX.1-2008.
        rNrGr#rNrs
hdrcharsetsBINARYr/FrTrsGNU.sparse.mapGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrFr')%rr]rqr'rrDrr#r2_header_length_prefix_rematchrKrIgroupr0rrg	partitionrr6_decode_pax_fieldr7PAX_NAME_FIELDSrhrru_proc_gnusparse_01_proc_gnusparse_00rH_proc_gnusparse_10rBrmrrrrrrp)rrrWrrr6raw_headersr{r5Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuerPr.rtrr8r8r9rns|









 
zTarInfo._proc_paxc	Csg}g}|D]\}}}|dkrTz|t|Wqtk
rPtdYqXq|dkrz|t|Wqtk
rtdYqXqtt|||_dS)z?Process a GNU tar extended sparse header, version 0.0.
        sGNU.sparse.offsetrGsGNU.sparse.numbytesN)rrIr=r0rKlistzipr)rrtrZoffsetsre_rPr.r8r8r9rszTarInfo._proc_gnusparse_00cCs@dd|ddD}tt|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 0.1.
        cSsg|]}t|qSr8)rI).0xr8r8r9
<listcomp>*sz.TarInfo._proc_gnusparse_01.<locals>.<listcomp>rw,Nr$r#)rrrr)rrtrrr8r8r9r'szTarInfo._proc_gnusparse_01cCsd}g}|jt}|dd\}}t|}t||dkrtd|krT||jt7}|dd\}}|t|q,|j|_t	t
|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        NrOr#r$)rr]rrrIr2rrrrrr)rrtrrZfieldsrrWZnumberr8r8r9r-szTarInfo._proc_gnusparse_10c	Cs|D]\}}|dkr&t|d|q|dkr@t|dt|q|dkrZt|dt|q|tkr|tkrzt||}Wntk
rd}YnX|dkr|d}t|||q||_dS)	zoReplace fields with supplemental information from a previous
           pax extended or global header.
        zGNU.sparse.namer%rxr'zGNU.sparse.realsizerrN)	r*setattrrI
PAX_FIELDSPAX_NUMBER_FIELDSr0r
r#r)rrr6r7rPr.r8r8r9rr=s"

zTarInfo._apply_pax_infocCs4z||dWStk
r.|||YSXdS)z1Decode a single field from a pax record.
        rEN)r=UnicodeDecodeError)rr.r6Zfallback_encodingZfallback_errorsr8r8r9r~TszTarInfo._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#)rKr\r)rr^rbrcr8r8r9rq\szTarInfo._blockcCs
|jtkSz4Return True if the Tarinfo object is a regular file.)r
REGULAR_TYPESrr8r8r9rhsz
TarInfo.isregcCs|Sr)rrr8r8r9isfilelszTarInfo.isfilecCs
|jtkS)z!Return True if it is a directory.)rr&rr8r8r9rpsz
TarInfo.isdircCs
|jtkS)z%Return True if it is a symbolic link.)rSYMTYPErr8r8r9rtsz
TarInfo.issymcCs
|jtkS)z!Return True if it is a hard link.)rLNKTYPErr8r8r9rxsz
TarInfo.islnkcCs
|jtkS)z(Return True if it is a character device.)rrIrr8r8r9ischr|sz
TarInfo.ischrcCs
|jtkS)z$Return True if it is a block device.)rrJrr8r8r9isblksz
TarInfo.isblkcCs
|jtkS)zReturn True if it is a FIFO.)rFIFOTYPErr8r8r9isfifoszTarInfo.isfifocCs
|jdk	Sr)rrr8r8r9issparseszTarInfo.issparsecCs|jtttfkS)zCReturn True if it is one of character device, block device or FIFO.)rrIrJrrr8r8r9isdevsz
TarInfo.isdev)r)6rnrorprqdict	__slots__rpropertyr%setterr&r!r"rr(rrr/r+r,r-classmethodrFr5staticmethodr6rLr8rArSrRrirhrjrorkrlrnrrrrrr~rqrrrrrrrrrrr8r8r8r9rns





1

)
	

2
C

y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#Nrxr)c
Csddddd}||krtd||_|||_|sh|jdkrTtj|sTd|_d|_t||j}d	|_n@|d
krt|drt	|j
ttfr|j
}t|dr|j|_d
|_|rtj
|nd
|_
||_|d
k	r||_|d
k	r||_|d
k	r||_|d
k	r||_|d
k	r||_|	|_|
d
k	r0|jtkr0|
|_ni|_|d
k	rF||_|d
k	rV||_|
|_d	|_g|_d	|_|j|_i|_z|jdkrd
|_ |!|_ |jdkr2|j"|jz|j#|}|j$|WnXt%k
r|j"|jYq2Yn0t&k
r,}zt't|W5d
}~XYnXq|jdkr|d
|_|jr||j(|j)}|j*||jt+|7_Wn&|js|j,d
|_YnXd
S)aOpen an (uncompressed) tar archive `name'. `mode' is either 'r' to
           read from an existing archive, 'a' to append data to an existing
           file or 'w' to create a new file overwriting an existing one. `mode'
           defaults to 'r'.
           If `fileobj' is given, it is used for reading or writing data. If it
           can be determined, `mode' is overridden by `fileobj's mode.
           `fileobj' is not closed, when TarFile is closed.
        rbzr+bwbZxbrxaryr!mode must be 'r', 'a', 'w' or 'x'rryFNrrTrxrryr)-r0r_moder{r%exists	bltn_openrrr>rr@rOabspathrrSrdereferenceignore_zerosr6r7rrdebug
errorlevelcopybufsizermembers_loadedrrinodesfirstmemberrtrrirrtrrrFr#r^r2r)rrrrrSrrrr6r7rrrrZmodeserWr8r8r9rs






"
zTarFile.__init__c

s|s|std|dkrfdd}tj|dD]j}tj|}|dk	rV|}	z||d|f|WSttfk
r|dk	r||	Yq2Yq2Xq2tdnd	|kr|d	d
\}
}|
pd}
|pd}|jkrtj|}ntd||||
|f|Sd
|kr|d
d
\}
}|
p.d}
|p8d}|
dkrLtdt	||
|||}z||
|f|}Wn|
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 open)rxr:*csj|dkS)Ntaropen)	OPEN_METH)rrEr8r9not_compressedEsz$TarFile.open.<locals>.not_compressed)keyNrxz%file could not be opened successfully:r#rr|rwzmode must be 'r' or 'w'Frzundiscernible mode)
r0sortedrrhrrrrrrrrr)
rErrrrakwargsrrfuncZ	saved_posfilemodestreamrr8rr9rsP%







zTarFile.opencKs |dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing.
        rr)r0)rErrrrr8r8r9rvszTarFile.taropenrcKs|dkrtdzddlm}Wntk
r<tdYnXz|||d||}Wn.tk
r|dk	r||dkr|td	YnXz|j|||f|}WnBtk
r||dkrtd	Yn|YnXd
|_	|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        rxryrmode must be 'r', 'w' or 'x'r)GzipFilezgzip module is not availablerdNrxrF)
r0Zgziprrrrrrrr)rErrr
compresslevelrrrr8r8r9gzopen~s0zTarFile.gzopenc	Ks|dkrtdzddlm}Wntk
r<tdYnX||pF|||d}z|j|||f|}WnFttfk
r||dkrt	dYn|YnXd	|_
|S)
zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        rrr)BZ2Filer)rrxznot a bzip2 fileF)r0rrrrrrEOFErrorrrr)rErrrrrrrr8r8r9bz2opens&zTarFile.bz2openc		Ks|dkrtdzddlm}m}Wntk
r@tdYnX||pJ|||d}z|j|||f|}WnF|tfk
r||dkrt	dYn|YnXd	|_
|S)
zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        rrr)LZMAFilerr)presetrxznot an lzma fileF)r0rrrrrrrrrr)	rErrrrrrrrr8r8r9xzopens&zTarFile.xzopenrrrr)rrrrcCs|jr
dSd|_z`|jdkrn|jttd|jtd7_t	|jt
\}}|dkrn|jtt
|W5|js|jXdS)zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NTrr$r)rrrrrr^r3rrr\
RECORDSIZE)rrbrcr8r8r9rs
z
TarFile.closecCs"||}|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)rrrr8r8r9	getmembers
zTarFile.getmembercCs||js||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_loadrrr8r8r9
getmembersszTarFile.getmemberscCsdd|DS)zReturn the members of the archive as a list of their names. It has
           the same order as the list returned by getmembers().
        cSsg|]
}|jqSr8r)rrr8r8r9rsz$TarFile.getnames.<locals>.<listcomp>)rrr8r8r9getnamesszTarFile.getnamescCs^|d|dk	r|j}|dkr$|}tj|\}}|tjd}|d}|}||_	|dkr|j
stt|}qt|}nt
|}d}|j}t|r|j|jf}	|j
s|jdkr|	|jkr||j|	krt}
|j|	}nt}
|	dr||j|	<nht|rt}
nVt|r"t}
nDt|r>t}
t|}n(t|rPt}
nt |rbt!}
ndS||_||_"|j#|_$|j%|_&|
tkr|j'|_(nd|_(|j)|_*|
|_+||_,t-rzt-.|j$d|_/Wnt0k
rYnXt1rzt12|j&d|_3Wnt0k
rYnX|
tt!fkrZt4tdrZt4tdrZt5|j6|_7t8|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.
        awxNrrr#rmajorminor):rrr{r%
splitdriverrrrrrlstatstatfstatfilenost_modeS_ISREGst_inost_devst_nlinkrrrS_ISDIRr&S_ISFIFOrS_ISLNKrreadlinkS_ISCHRrIS_ISBLKrJrst_uidr)st_gidr*st_sizer'st_mtimer(rrpwdgetpwuidr+rgrpZgetgrgidr,rrst_rdevrrr)rrarcnamerZdrvrZstatresrZstmdinoderr8r8r9
gettarinfos	




zTarFile.gettarinfoT)rcCs*||dkr|}|D]
}|r|jdkr6tdntt|jtd|jpT|j|jp^|jf|	sv|
rtdd|j|jfntd|j
|jdkrtdntdt|jdd	t|j|rd
nd|r|rtd|j|rtd
|jtqdS)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 )rrrlrrr+r)r,r*rrrrr'r(r	localtimerrrrrrk)rverboserrr8r8r9rus8







zTarFile.listfilterc	Cs6|d|dkr|}|jdk	rFtj||jkrF|dd|dS|d||||}|dkrz|dd|dS|dk	r||}|dkr|dd|dS|rt|d}|	||W5QRXn`|
r(|	||r2tt|D]*}|j
tj||tj||||d	qn
|	|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. `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.
        rNr$ztarfile: Skipped %rr#ztarfile: Unsupported type %rtarfile: Excluded %rrr)rrr{r%r_dbgrrraddfilerrlistdiraddr)rrr	recursiverrfr8r8r9rs8




zTarFile.addcCs|dt|}||j|j|j}|j||jt	|7_|j
}|dk	rt||j|j|dt
|jt\}}|dkr|jtt||d7}|j|t7_|j|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)rarr#)rr#r/rSr6r7rr^rr2rr[r'r\rr3rr)rrrrWrarbrcr8r8r9rs

zTarFile.addfilecCsr|dkr0|j}|dkrtSt|tr,td|St|r<|Sz
t|WStk
rltd|ddYnXdS)NzrString names are not supported for TarFile.extraction_filter. Use a function such as tarfile.data_filter directly.zfilter z
 not found)	extraction_filterrr>r@	TypeErrorcallable_NAMED_FILTERSrr0)rrr8r8r9_get_filter_functions

zTarFile._get_filter_function.)
numeric_ownerrcCsg}||}|dkr|}|D]L}||||\}}	|dkr>q|rP||	|j|||||dq|jdddd|D]*}	zz||	|}Wn<tk
r}
z||	t|
WYWqW5d}
~
XYnX|dkr||	dWqt	j
||j}zt	
|}Wn(tk
r4||dYWqYnXt|jsT||d	Wq|j|||d
||||||Wqtk
r}
z||
W5d}
~
XYqXqdS)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|jSrr)rr8r8r9<lambda>	rz$TarFile.extractall.<locals>.<lambda>T)rreversezexcluded by filterZmissingznot a directory)r)r_get_extract_tarinforr_extract_onesort_FILTER_ERRORS_log_no_directory_fixupreprr{r%rrrFileNotFoundErrorrrrchownutimechmodr
_handle_nonfatal_error)rr%rrrZdirectoriesrrr
unfilteredexcdirpathrrr8r8r9
extractallsZ


zTarFile.extractallcCs|dd|j|fdS)Nr$z(tarfile: Not fixing up directory %r (%s))rr)rrreasonr8r8r9r>	szTarFile._log_no_directory_fixuprc	Cs<||}||||\}}|dk	r8|j|||||ddS)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)r)rrr	)	rrr%rrrrrrr8r8r9extractB	s
zTarFile.extractc
Cst|tr||}n|}d}z|||}WnZttfk
r\}z||W5d}~XYn,tk
r}z||W5d}~XYnX|dkr|dd|j	dS|
rt|}tj
||j|_||fS)zGet (filtered, unfiltered) TarInfos from *member*

        *member* might be a string.

        Return (None, None) if not found.
        Nr$r)NN)r>r@rrr_handle_fatal_errorr
rrrrr#r{r%rrr)rrrr%rfilteredrr8r8r9rW	s"	

zTarFile._get_extract_tarinfoc
Cs|dz&|j|tj||j||||dWnVtk
r\}z||W5d}~XYn,tk
r}z|	|W5d}~XYnXdS)zExtract from filtered tarinfo to disk.

           filter_function is only used when extracting a *different*
           member (e.g. as fallback to creating a symlink)
        rx)rrrextraction_rootN)
r_extract_memberr{r%rrrrr
r)rrr%rrrrr8r8r9r	v	s

zTarFile._extract_onecCs"|jdkrn|dd|dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#tarfile: %sN)rrrrr8r8r9r	s
zTarFile._handle_nonfatal_errorcCsn|jdkrn\t|trP|jdkr6|dd|jqj|dd|j|jfn|ddt|j|fdS)z1Handle "fatal" error according to self.errorlevelrNr#rztarfile: %s %rztarfile: %s %s)rr>rfilenamerstrerrorrrnrr8r8r9r	s


zTarFile._handle_fatal_errorcCs|dt|tr ||}n|}|s6|jtkrB|||S|sR|	rzt|j
trhtdq~|
||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.
        rxz'cannot extract (sym)link as file objectN)rr>r@rrrrp
fileobjectrrrrr	extractfile_find_link_target)rrrr8r8r9r"	s


zTarFile.extractfilerrcCsZ|d}|dtj}tj|}|r>tj|s>t||sN|	rh|
dd|j|jfn|
d|j|
r|||n|r|||n~|r|||nh|s|r|||nJ|s|	r|j||||dn&|jtkr|||n||||rV|||||	sV||||||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 -> %sr$N)r
rr{rr%r	rmakedirsrrrrrrmakefilermakedirrmakefiforrmakedevmakelink_with_filterrrpmakeunknownrrr)rr
targetpathrrrrZ	upperdirsr8r8r9r	s>


zTarFile._extract_membercCs@z&|jdkrt|nt|dWntk
r:YnXdS)z,Make a directory called targetpath.
        Ni)rr{mkdirFileExistsErrorrrr,r8r8r9r'	s
zTarFile.makedirc	Cs|j}||j|j}t|db}|jdk	rn|jD]"\}}||t|||t|q4||j|	nt|||jt|W5QRXdS)z'Make a file called targetpath.
        rN)
rrrrrrr[rr'truncate)rrr,sourceratargetrr'r8r8r9r&
s


zTarFile.makefilecCs"||||dd|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)r&rrr/r8r8r9r+
szTarFile.makeunknowncCs"ttdrt|ntddS)z'Make a fifo called targetpath.
        mkfifozfifo not supported by systemN)rr{r3r
r/r8r8r9r(
s
zTarFile.makefifocCsjttdrttdstd|j}|dkr.d}|rB|tjO}n
|tjO}t||t	|j
|jdS)z<Make a character or block device called targetpath.
        mknodr)z'special devices not supported by systemNr)rr{r
rrrS_IFBLKS_IFCHRr4r)rr)rrr,rr8r8r9r)"
s
zTarFile.makedevcCs|||ddSr)r*r/r8r8r9makelink4
szTarFile.makelinkc	
CsVd}z`|r8tj|r$t|t|j|WdStj|jrbt	tj
|j|WdSWntk
r|d}YnXz||}Wn$t
k
r|rtdnYnX|dkr|}nv|dkrtdz2||j|jdd|}|dkrWdS|||}Wn2tk
r4}zt||j|W5d}~XYnX|dk	rR|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 archivez[makelink_with_filter: if filter_function is not None, extraction_root must also not be None)rrr$)rr{r%lexistsunlinksymlinkrrrlinkrsymlink_exceptionr#rr
rrrrr)	rrr,rrZkeyerror_to_extracterrorrrcauser8r8r9r*7
sR	


 
zTarFile.makelink_with_filtercCsttdrtdkr|j}|j}|sztrB|jrBt|jd}Wntk
rXYnXzt	rv|j
rvt	|j
d}Wntk
rYnX|dkrd}|dkrd}z4|rttdrt
|||nt|||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 owner)rr{r>r*r)rr,Zgetgrnamrrr+getpwnamrr?rrr
)rrr,rgur8r8r9rr
s0

z
TarFile.chowncCsB|jdkrdSzt||jWntk
r<tdYnXdS)zASet file permissions of targetpath according to tarinfo.
        Nzcould not change mode)rr{rrr
r/r8r8r9r
s
z
TarFile.chmodcCsV|j}|dkrdSttds dSzt|||fWntk
rPtdYnXdS)zBSet modification time of targetpath according to tarinfo.
        Nrz"could not change modification time)r(rr{rrr
)rrr,r(r8r8r9r
s
z
TarFile.utimec
Cs|d|jdk	r$|j}d|_|S|j|jkrZ|j|jd|jdsZtdd}z|j	|}Wqt
k
r}z6|jr|dd|j|f|jt
7_WYq^W5d}~XYqtk
r6}zR|jr|dd|j|f|jt
7_WY q^n|jdkr&tt|W5d}~XYntk
r^|jdkrZtdYnjtk
r}z|jdkrtt|W5d}~XYn0tk
r}ztt|W5d}~XYnXqq^|dk	r|j|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#rYr$z0x%X: %srz
empty fileT)rrrrrrr]rrrirtrrrrKr@rrrsrurrr)rmrrr8r8r9rt
sJ



zTarFile.nextc	Cs|}d}|dk	rHz||}Wntk
r:d}YnX|d|}|rXtj|}t|D]D}|rz|j|jkr`d}q`|rtj|j}n|j}||kr`|Sq`|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)	rindexr0r{r%rreversedrr)	rrr	normalizerZskippingrDrmember_namer8r8r9r
s,

zTarFile._getmembercCs|}|dkrqqd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)rtrrr8r8r9r	sz
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)rrrrnr)rrr8r8r9rszTarFile._checkcCs`|r.dtdtj|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)rrFzlinkname %r not found)
rrrr{r%r	rrrr)rrrlimitrr8r8r9r#s zTarFile._find_link_targetccs|jr|jEdHdSd}|jdk	r:|}|d7}|V|t|jkrT|j|}n"|jsr|}|svd|_dSndS|d7}|Vq:dS)z$Provide an iterator object.
        Nrr#T)rrrrtr2)rrDrr8r8r9__iter__/s$
zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr.
        fileN)rrkristderr)rlevelmsgr8r8r9rNs
zTarFile._dbgcCs||Sr)rrr8r8r9	__enter__TszTarFile.__enter__cCs,|dkr|n|js"|jd|_dSr)rrrr)rrr.	tracebackr8r8r9__exit__Xs


zTarFile.__exit__)
NrxNNNNNNr)NNNN)rxN)rxNr)rxNr)rxNN)NNN)T)NT)N)rN)rT)N)TF)NF)N)@rnrorprqrrrrrrSrr6r7rrrr!rrrrrrrrrrrrrrrrrrrrrrrr	rrr"rr'r&r+r(r)r7r*rrrrtrrrr#rIrrOrQr8r8r8r9rs
oZ 


c&3
E 
8;!
6
(

	cCs2zt|}|WdStk
r,YdSXdS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)rrr)rrr8r8r9rfsc	Csddl}d}|j|d}|jdddddd	|jd
dtdd
|jdd}|jddddd|jdddddd|jdddddd|jdd dd!d|}|jr|jdkr|d"d#|j	dk	r4|j	}t
|rt|d$ }|t
|tjd%W5QRX|jr0t
d&|n|d"d'|n|jdk	r|j}t
|rxt|d(}|j|jd)W5QRXn|d"d'|nv|jdk	rbt|jd"kr|jd}tj}n,t|jd*kr|j\}}n|d"|t
|rNt|d(}|j||jd+W5QRX|jr`|d,kr8d-|}	nd.||}	t
|	n|d"d'|n|jdk	r|jd}
tj|
\}}d/d/d0d0d1d1d1d1d2}
||
krd3|
|nd4}|j}t|
|}|D]}||qW5QRX|jrt
d5|
dS)6Nrz3A simple command-line interface for tarfile module.)descriptionz-vz	--verbose
store_trueFzVerbose output)actiondefaulthelpz--filterz<filtername>zFilter for extraction)metavarchoicesrVT)Zrequiredz-lz--list	<tarfile>zShow listing of a tarfile)rWrVz-ez	--extract+)rYz<output_dir>zExtract tarfile into target dir)nargsrWrVz-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction
rxrJz{!r} is a tar archive.z{!r} is not a tar archive.
r)rr$)r%rrz{!r} file is extracted.z+{!r} file is extracted into {!r} directory.rrr)rz.tgzz.xzz.txzz.bz2z.tbzz.tbz2z.tb2zw:ryz{!r} file created.)argparseArgumentParseradd_argumentrZadd_mutually_exclusive_group
parse_argsrrexitZtestrrrrkrirLrrSrrr2r{curdirZformat_helprZcreatepopr%splitextr)r\rRparserr|argsr_rZtfrarNZtar_namerZextZcompressionsZtar_modeZ	tar_files	file_namer8r8r9maints










rg__main__)T)orqversion
__author____credits__builtinsrrrir{rrZrrrVr#rewarningsrrrAttributeErrorNotImplementedErrorr<r	NameError__all__r3rrr7r2r4r3rGrr_rrrIrJr&rZCONTTYPEr:r9r`rBrDrmr
rrrrprrbrrr?rIrrrgetfilesystemencodingr:r?rNrTrXr[rl	Exceptionrr
rrr	rrrrsrtrKrurvrobjectrrBufferedReaderrrrrrrrrrrrrrrr"compilerzrrrrgrnr8r8r8r9<module>s@


	
uh



Q
(__