• File: tarfile.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/proc/self/root/opt/alt/python37/lib64/python3.7/__pycache__/tarfile.cpython-37.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 71.22 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

Nj@s2dZdZdZdZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZyddlZWnek
rdZYnXyddlZWnek
rdZYnXeefZyeef7ZWnek
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,Z3e2Z4e"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@dAZEdBdCZFdDdEZGGdFd
d
eHZIGdGddeIZJGdHddeIZKGdIddeIZLGdJd
d
eIZMGdKddeIZNGdLdMdMeNZOGdNdOdOeNZPGdPdQdQeNZQGdRdSdSeNZRGdTdUdUeNZSGdVdWdWZTGdXdYdYZUGdZd[d[eVZWGd\d]d]eVZXGd^d_d_e	jYZZe[d`Z\GdadbdbeIZ]Gdcdddde]Z^Gdedfdfe]Z_Gdgdhdhe]Z`Gdidjdje]ZaGdkdldle]ZbGdmdndne]Zce]eeJfZdddpdqZedrdsZfdtduZgdvdwZhefegehdxZieVZjGdyddeVZkGdzddeVZld{d	ZmeljZd|d}Zneod~kr.endS)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,)ZatimeZctimer(r)r*r'ntzutf-8cCs8|dkrtd|||}|d||t|tS)z8Convert a string to a null-terminated bytes object.
    Nzmetadata cannot contain None)
ValueErrorencodelenNUL)slengthencodingerrorsr6,/opt/alt/python37/lib64/python3.7/tarfile.pystnsr8cCs*|d}|dkr|d|}|||S)z8Convert a null-terminated bytes object to a string.
    rN)finddecode)r2r4r5pr6r6r7ntss
r=cCs|ddkrfd}x0tt|dD]}|dK}|||d7}q"W|ddkrdt|d|}n@y"t|dd}t|pd	d}Wntk
rtd
YnX|S)z/Convert a number field to a python number.
    r)r#r?asciistrict0zinvalid header)ranger0r=intstripr.InvalidHeaderError)r2nir6r6r7ntisrKr@cCst|}d|kr$d|dkrDnntd|d|fdt}n|tkrd|d|krrd|dkrnnZ|dkrtdg}ntdg}d||}x6t|dD]}|d|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
rQcCs0dttd|}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.
    rAZ
148B8x356BZ
148b8x356b)sumstructZunpack_from)bufZunsigned_chksumZ
signed_chksumr6r6r7calc_chksumss	rUc	Cs|pd}|dkrdS|dkr.t|||dSt||\}}x8t|D],}||}t||krh|d||qFW|dkr||}t||kr|d||dS)zjCopy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    i@rNzunexpected end of data)shutilcopyfileobjdivmodrEreadr0write)	srcdstr3	exceptionbufsizeblocks	remainderbrTr6r6r7rWs$


rWcCs ddl}|dtdt|S)z/Deprecated in this location; use stat.filemode.rNz$deprecated in favor of stat.filemoder$)warningswarnDeprecationWarningstatfilemode)moderbr6r6r7rfsrfcCs8ttjdd}|dk	r(||d|}t|dddS)Nr4backslashreplace )end)getattrsysstdoutr/r;print)r2r4r6r6r7_safe_printsroc@seZdZdZdS)rzBase exception.N)__name__
__module____qualname____doc__r6r6r6r7rsc@seZdZdZdS)r
z%General exception for extract errors.N)rprqrrrsr6r6r6r7r
sc@seZdZdZdS)rz&Exception for unreadable tar archives.N)rprqrrrsr6r6r6r7rsc@seZdZdZdS)rz.Exception for unavailable compression methods.N)rprqrrrsr6r6r6r7rsc@seZdZdZdS)r	z=Exception for unsupported operations on stream-like TarFiles.N)rprqrrrsr6r6r6r7r	!sc@seZdZdZdS)rz!Base exception for header errors.N)rprqrrrsr6r6r6r7r$sc@seZdZdZdS)EmptyHeaderErrorzException for empty headers.N)rprqrrrsr6r6r6r7rt'srtc@seZdZdZdS)TruncatedHeaderErrorz Exception for truncated headers.N)rprqrrrsr6r6r6r7ru*sruc@seZdZdZdS)EOFHeaderErrorz"Exception for end of file headers.N)rprqrrrsr6r6r6r7rv-srvc@seZdZdZdS)rHzException for invalid headers.N)rprqrrrsr6r6r6r7rH0srHc@seZdZdZdS)SubsequentHeaderErrorz3Exception for missing and invalid extended headers.N)rprqrrrsr6r6r6r7rw3srwc@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)N)rwO_BINARYi)	osO_RDONLYO_WRONLYO_CREATO_TRUNChasattrr{rfd)selfnamergr6r6r7__init__@s

z_LowLevelFile.__init__cCst|jdS)N)r|closer)rr6r6r7rIsz_LowLevelFile.closecCst|j|S)N)r|rYr)rr'r6r6r7rYLsz_LowLevelFile.readcCst|j|dS)N)r|rZr)rr2r6r6r7rZOsz_LowLevelFile.writeN)rprqrrrsrrrYrZr6r6r6r7rx:s
	rxc@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|}|}|p<d|_||_||_||_||_d|_	d|_
d|_yL|dkryddl}Wnt
k
rtd	YnX||_|d|_|d
kr||j|_n|n|dkr:yddl}Wnt
k
r
tdYnX|d
kr.d|_||_t|_n
||_n||d
kryddl}Wnt
k
rntdYnX|d
krd|_||_|j|_n
||_n|dkrtd|Wn&|js|jd|_YnXdS)z$Construct a _Stream object.
        TNF*rgzzzlib module is not availablerybz2zbz2 module is not availablexzzlzma module is not availabletarzunknown compression type %r) _extfileobjrx_StreamProxygetcomptyperrgcomptypefileobjr^rTposclosedzlibImportErrorrcrc32crc
_init_read_gzerrorr]_init_write_gzrdbufZBZ2DecompressorcmpOSErrorZ
BZ2CompressorlzmaZLZMADecompressor	LZMAErrorZLZMACompressorr)	rrrgrrr^rrrr6r6r7r]sl












z_Stream.__init__cCst|dr|js|dS)Nr)rrr)rr6r6r7__del__sz_Stream.__del__cCs|jd|jj|jj|jjd|_tdtt		}|
d|d|jdrf|jdd|_|
|j
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|j||j|_|jt|7_|jdkrD|j|}||dS)z&Write string s to the stream.
        rrN)	rrrrrr0rcompressr)rr2r6r6r7rZs

z
_Stream.writecCsR|j|7_x>t|j|jkrL|j|jd|j|j|jd|_qWdS)z]Write string s to the stream if a whole new block
           is ready to be written.
        N)rTr0r^rrZ)rr2r6r6r7Z__writesz_Stream.__writecCs|jr
dSd|_z|jdkr:|jdkr:|j|j7_|jdkr|jr|j|jd|_|jdkr|jt	d|j
|jt	d|jd@Wd|js|j
XdS)	z[Close the _Stream object. No operation should be
           done on it afterwards.
        NTrzrrrz<Ll)rrgrrTrflushrrZrSrrrrr)rr6r6r7rs
z
_Stream.closecCs|j|jj|_d|_|ddkr0td|ddkrFtdt|d}|d|d	@rt|dd
t|d}|	||d@rx|d}|r|t
krPqW|d@rx|d}|r|t
krPqW|d@r|dd
S)z:Initialize for reading a gzip compressed fileobj.
        rr$sznot a gzip filer#zunsupported compression methodrAr@N)rZ
decompressobjrrr
_Stream__readrrordrYr1)rflagZxlenr2r6r6r7rs.
 


z_Stream._init_read_gzcCs|jS)z3Return the stream's file pointer position.
        )r)rr6r6r7tellsz_Stream.tellrcCsb||jdkrTt||j|j\}}x"t|D]}||j}|s.Pq.W||ntd|jS)zXSet the stream's file pointer to pos. Negative seeking
           is forbidden.
        rz seeking backwards is not allowed)rrXr^rErYr	)rrr_r`rJdatar6r6r7seeksz_Stream.seekNcCsZ|dkr:g}x ||j}|s P||qWd|}n
||}|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'trTr6r6r7rYs
z_Stream.readcCs|jdkr||St|j}|jg}xd||kr||j}|sBPy|j|}Wn|jk
rptdYnX|	||t|7}q(Wd
|}||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|j|j}|s0P|||t|7}qWd|}||d|_|d|S)zsReturn size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        rN)r0rTrrYr^rr)rr'rrrTr6r6r7Z__read9s



z_Stream.__read)r)N)rprqrrrsrrrrZrrrrrrYrrr6r6r6r7rRs	F
	

rc@s0eZdZdZddZddZddZdd	Zd
S)rzsSmall proxy class that enables transparent compression
       detection for the Stream interface (mode 'r|*').
    cCs||_|jt|_dS)N)rrY	BLOCKSIZErT)rrr6r6r7rOsz_StreamProxy.__init__cCs|jj|_|jS)N)rrYrT)rr'r6r6r7rYSs
z_StreamProxy.readcCsP|jdrdS|jdddkr8|jdddkr8d	S|jd
rHdSdSdS)
NsrrsBZhr
s1AY&SYr)s]s7zXZrr)rT
startswith)rr6r6r7rWs$z_StreamProxy.getcomptypecCs|jdS)N)rr)rr6r6r7rasz_StreamProxy.closeN)rprqrrrsrrYrrr6r6r6r7rJs

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~|j	d||df|j	d||||f||7}||}qZW||jkr|j	d||jdfdS)NrrFT)
roffsetr'positionrkrr	map_indexmapr)rrrr'Z	blockinfoZlastposZrealposr6r6r7rns(

z_FileInFile.__init__cCsdS)Nr6)rr6r6r7rsz_FileInFile.flushcCsdS)NTr6)rr6r6r7readablesz_FileInFile.readablecCsdS)NFr6)rr6r6r7writablesz_FileInFile.writablecCs
|jS)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\}}}}||jkrd|krlnnPq:|jd7_|jt|jkr:d|_q:Wt|||j}|r|j||j||j|}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'rrrrr0rrrYrr1)	rr'rTrstartstoprr3rar6r6r7rYs.

z_FileInFile.readcCs&|t|}||dt|<t|S)N)rYr0)rrarTr6r6r7readintosz_FileInFile.readintocCs
d|_dS)NT)r)rr6r6r7rsz_FileInFile.close)N)N)rprqrrrsrrrrrrrrrrYrrr6r6r6r7rhs

rcseZdZfddZZS)ExFileObjectcs&t|j|j|j|j}t|dS)N)rroffset_datar'sparsesuperr)rtarfiletarinfor)	__class__r6r7rs
zExFileObject.__init__)rprqrrr
__classcell__r6r6)rr7rsrs([0-9]{1,20}) c@seZdZdS)FilterErrorN)rprqrrr6r6r6r7rsrcseZdZfddZZS)AbsolutePathErrorcs ||_td|jddS)Nzmember z has an absolute path)rrrr)rr)rr6r7rszAbsolutePathError.__init__)rprqrrrrr6r6)rr7rsrcseZdZfddZZS)OutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would be extracted to z, z which is outside the destination)r_pathrrr)rrr%)rr6r7rsz OutsideDestinationError.__init__)rprqrrrrr6r6)rr7rsrcseZdZfddZZS)SpecialFileErrorcs||_t|jddS)Nz is a special file)rrrr)rr)rr6r7rszSpecialFileError.__init__)rprqrrrrr6r6)rr7rsrcseZdZfddZZS)AbsoluteLinkErrorcs||_t|jddS)Nz is a link to an absolute path)rrrr)rr)rr6r7rszAbsoluteLinkError.__init__)rprqrrrrr6r6)rr7rsrcseZdZfddZZS)LinkOutsideDestinationErrorcs.||_||_t|jd|dddS)Nz would link to z, z which is outside the destination)rrrrr)rrr%)rr6r7rsz$LinkOutsideDestinationError.__init__)rprqrrrrr6r6)rr7rsrcseZdZfddZZS)LinkFallbackErrorcs2||_||_td|jdd|ddS)Nzlink z would be extracted as a zcopy of z, which was rejected)rrrrr)rrr%)rr6r7rszLinkFallbackError.__init__)rprqrrrrr6r6)rr7rsrTc	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)rC/rz..i@iirgr)r*r+r,linkname)rr|r%realpath
ALLOW_MISSINGrseplstripisabsrrsplitnormpathr
commonpathrrgisregislnkisdirissymrr)r*r+r,rrdirnamerstripr)	member	dest_pathZfor_data	new_attrsrZ
normalizedZtarget_pathrgZlink_dirr6r6r7_get_filtered_attrssl







rcCs|S)Nr6)rrr6r6r7fully_trusted_filter]srcCs(t||d}|r$|jf|ddiS|S)NFdeep)rr)rrrr6r6r7
tar_filter`srcCs(t||d}|r$|jf|ddiS|S)NTrF)rr)rrrr6r6r7data_filterfsr)Z
fully_trustedrrc@seZdZdZdZd]ddZeddZejddZed	d
Z	e	jdd
Z	dd
Z
eeeeeeeeded
ddZddZ
eedfddZddZddZddZeddZdd Zed!d"Zed#d$Zed%d&Zed'd(Zed)d*Zedd+d,d-Zed.d/Zedd+d0d1Zd2d3Z d4d5Z!d6d7Z"d8d9Z#d:d;Z$d<d=Z%d>d?Z&d@dAZ'dBdCZ(dDdEZ)dFdGZ*dHdIZ+dJdKZ,dLdMZ-dNdOZ.dPdQZ/dRdSZ0dTdUZ1dVdWZ2dXdYZ3dZd[Z4d\S)^raInformational 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.
    )rrgr)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)rrgr)r*r'r(rREGTYPErrr+r,rrrrrr)rrr6r6r7rs"zTarInfo.__init__cCs|jS)N)r)rr6r6r7r%szTarInfo.pathcCs
||_dS)N)r)rrr6r6r7r%scCs|jS)N)r)rr6r6r7r&szTarInfo.linkpathcCs
||_dS)N)r)rrr6r6r7r&scCsd|jj|jt|fS)Nz<%s %r at %#x>)rrprid)rr6r6r7__repr__szTarInfo.__repr__T)
rr(rgrr)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(rgrr)r*r+r,)rrr(rgrr)r*r+r,rrresultr6r6r7rs(
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.
        Ni)
rrgr)r*r'r(rrrr+r,rrrrr)rgrr)r*r'r(rrrr+r,rrDIRTYPEr)rrginfor6r6r7get_infos&


zTarInfo.get_infosurrogateescapecCs~|}x(|D]\}}|dkrtd|qW|tkrH||||S|tkr^||||S|tkrr|||StddS)z<Return a tar header as a string of 512 byte blocks.
        Nz%s may not be Nonezinvalid format)	r
itemsr.r
create_ustar_headerrcreate_gnu_headerrcreate_pax_header)rrPr4r5r	rvaluer6r6r7tobufs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_MAGICr0r/LENGTH_LINKr.LENGTH_NAME_posix_split_name_create_headerr
)rr	r4r5r6r6r7r
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.
        rrrr)
	GNU_MAGICr0r/r_create_gnu_long_headerGNUTYPE_LONGLINKrGNUTYPE_LONGNAMErr)rr	r4r5rTr6r6r7r
szTarInfo.create_gnu_headerc
	Cs0t|d<|j}xddtfddtfddfD]h\}}}||kr@q,y||dd	Wn"tk
rv||||<w,YnXt|||kr,||||<q,Wxhd
D]`\}}||krd||<q||}d|krd|d
krnn
t|t	rt
|||<d||<qW|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.
        rrr%rr&)r+r+ )r,r,rrBrC))r)r@)r*r@)r')r(rrr@r#rr)rrrrrr/UnicodeEncodeErrorr0
isinstancefloatstr_create_pax_generic_headerXHDTYPErr
)
rr	r4rrZhnamer3rOvalrTr6r6r7rs4
*zTarInfo.create_pax_headercCs||tdS)zAReturn the object as a pax global header block sequence.
        zutf-8)r#XGLTYPE)clsrr6r6r7create_pax_global_headerIsz TarInfo.create_pax_global_headercCs|d}xltdt|D]R}d|d|}d||d}t|||tkrt|||tkrPqWtd||fS)zUSplit a name longer than 100 chars into a prefix
           and a name part.
        rr#Nzname is too long)rrEr0rr/
LENGTH_PREFIXrr.)rrr4r5Z
componentsrJrr6r6r7rOs
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.
        rrrr@rrNzTarInfo.type must not be Nonerrrgir)r*r'rr(s        rrr+rr,rrz%dsriz%06orBi)getCHRTYPEBLKTYPErQr8rr.rrSrrrrUrL)r	rPr4r5Zhas_device_fieldsrrZfiletypepartsrTrr6r6r7r_s8
&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)rXr0rr1)Zpayloadr_r`r6r6r7_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'r)r/r1r0rrr
r.)r'rrr4r5r	r6r6r7rszTarInfo._create_gnu_long_headerc	Cs:d}x@|D]4\}}y|ddWqtk
r@d}PYqXqWd}|rV|d7}x|D]\}}|d}|r||d}n
|d}t|t|d}d	}	}
x"|tt|
}	|	|
krP|	}
qW|tt|
d
d|d|d
7}q`Wi}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.
        Fzutf-8rCTrs21 hdrcharset=BINARY
rrrrB =
z././@PaxHeaderrrr'rr)
rr/rr0r"rLrrr
r.)r'rrr4ZbinarykeywordrZrecordslrIr<r	r6r6r7r#s<

*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)r'rTr4r5r6r6r7frombufszTarInfo.frombuf)dircheckc	Cszt|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}	xrtdD]f}
y0t|||d}t||d|d}Wntk
rPYnX|	||f|d7}qWt|d}
t|dd}|	|
|f|_ |!rT|j"d|_|rv|jt#krv|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)iIiQiYirirriii)$r0rtrrucountr1rvrKrUrHr=rrgr)r*r'r(rrrr+r,rrAREGTYPErrGNUTYPE_SPARSErEr.rboolrrr	GNU_TYPES)r'rTr4r5r6robjrrstructsrJrnumbytes
isextendedorigsizer6r6r7r4sZ	 
zTarInfo._frombufcCs
||S)zOReturn the next TarInfo object from TarFile object
           tarfile.
        )_fromtarfile)r'rr6r6r7fromtarfile$szTarInfo.fromtarfilecCs<|jt}|j||j|j|d}|jt|_||S)z;
        See dircheck documentation in _frombuf().
        )r6)	rrYrr4r4r5rr_proc_member)r'rr6rTrDr6r6r7rI+szTarInfo._fromtarfilecCsT|jttfkr||S|jtkr,||S|jtttfkrF|	|S|
|SdS)zYChoose the right processing method depending on
           the type and call it.
        N)rrr
_proc_gnulongrA_proc_sparser$r&SOLARIS_XHDTYPE	_proc_pax
_proc_builtin)rrr6r6r7rK@s



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_inforr4r5)rrrr6r6r7rPMszTarInfo._proc_builtincCs|j||j}y|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.
        F)r6z missing or bad subsequent header)rrYrRr'rIrrwrrrr=r4r5rrr)rrrTnextr6r6r7rL^s

zTarInfo._proc_gnulongc
	Cs|j\}}}|`x|r|jt}d}xvtdD]j}y0t|||d}t||d|d}	Wntk
rzPYnX|r|	r|||	f|d7}q0Wt|d}qW||_	|j
|_|j||j
|_||_
|S)z8Process a GNU sparse header plus extra headers.
        rrr>i)rrrYrrErKr.rrBrrrrRr'r)
rrrErGrHrTrrJrrFr6r6r7rMts(zTarInfo._proc_sparsecCs|j||j}|jtkr&|j}n
|j}d}d}g}x0t||krn||dkrnt	
||}|sttdyt|
d}Wntk
rtdYnX|dkrtd||t|krtd|d|d}	||dd|	}
|
d\}}}
|r"|dks"||	dkr*td||||
f|dkrd|dkrd|
d	kr`|j}nd
}||7}q@W|dkr~d
}x`|D]X\}}}
||d
d
|j}|tkr||
||j|j}n||
d
d
|j}|||<qWy|j|dd}Wntk
rtd
YnXd|kr*|||nFd|krB|||n.|ddkrp|ddkrp|||||jttfkr| ||j|j|j!|_!d|kr|j"}|#s|jt$kr|||j7}||_!|S)zVProcess an extended or global header as described in
           POSIX.1-2008.
        rNzinvalid headerr#r0rs
hdrcharsetsBINARYzutf-8F)r6z missing or bad subsequent headerzGNU.sparse.mapzGNU.sparse.sizezGNU.sparse.major1zGNU.sparse.minorrDr')%rrYrRr'rr&rrr0_header_length_prefix_rematchrHrFgroupr.rrj	partitionrr4_decode_pax_fieldr5PAX_NAME_FIELDSrIrrw_proc_gnusparse_01_proc_gnusparse_00r*_proc_gnusparse_10r$rNrSrrrrQ)rrrTrrr4raw_headersrYr3Zheader_value_end_offsetZkeyword_and_valueZraw_keywordZequalsZ	raw_valuer2rrTrr6r6r7rOsx

 







 
zTarInfo._proc_paxc	Csg}g}x|D]\}}}|dkrVy|t|Wqtk
rRtdYqXq|dkry|t|Wqtk
rtdYqXqWtt|||_dS)z?Process a GNU tar extended sparse header, version 0.0.
        sGNU.sparse.offsetzinvalid headersGNU.sparse.numbytesN)rrFr;r.rHlistzipr)rrTraZoffsetsrF_r2rr6r6r7r_
szTarInfo._proc_gnusparse_00cCs@dd|ddD}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#)rrbrcr)rrTrrr6r6r7r^szTarInfo._proc_gnusparse_01cCsd}g}|jt}|dd\}}t|}xJt||dkrvd|krV||jt7}|dd\}}|t|q.W|j|_t	t
|ddd|ddd|_dS)z?Process a GNU tar extended sparse header, version 1.0.
        Nr1r#r$)rrYrrrFr0rrrrbrcr)rrTrrZfieldsrrTZnumberr6r6r7r`$szTarInfo._proc_gnusparse_10c	Csx|D]\}}|dkr(t|d|q
|dkrBt|dt|q
|dkr\t|dt|q
|tkr
|tkryt||}Wntk
rd}YnX|dkr|d}t|||q
W||_dS)	zoReplace fields with supplemental information from a previous
           pax extended or global header.
        zGNU.sparse.namer%zGNU.sparse.sizer'zGNU.sparse.realsizerrN)	rsetattrrF
PAX_FIELDSPAX_NUMBER_FIELDSr.rrr)rrr4r5r2rr6r6r7rS4s"

zTarInfo._apply_pax_infocCs.y||dStk
r(|||SXdS)z1Decode a single field from a pax record.
        rCN)r;UnicodeDecodeError)rrr4Zfallback_encodingZfallback_errorsr6r6r7r\Ks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#)rHrXr)rr?r_r`r6r6r7rRSszTarInfo._blockcCs
|jtkS)N)r
REGULAR_TYPES)rr6r6r7r_sz
TarInfo.isregcCs|S)N)r)rr6r6r7isfileaszTarInfo.isfilecCs
|jtkS)N)rr)rr6r6r7rcsz
TarInfo.isdircCs
|jtkS)N)rSYMTYPE)rr6r6r7resz
TarInfo.issymcCs
|jtkS)N)rLNKTYPE)rr6r6r7rgsz
TarInfo.islnkcCs
|jtkS)N)rr+)rr6r6r7ischrisz
TarInfo.ischrcCs
|jtkS)N)rr,)rr6r6r7isblkksz
TarInfo.isblkcCs
|jtkS)N)rFIFOTYPE)rr6r6r7isfifomszTarInfo.isfifocCs
|jdk	S)N)r)rr6r6r7issparseoszTarInfo.issparsecCs|jtttfkS)N)rr+r,rs)rr6r6r7isdevqsz
TarInfo.isdevN)r)5rprqrrrs	__slots__rpropertyr%setterr&rrrr
rrrr
rrclassmethodr(rstaticmethodrr.rr#r5r4rJrIrKrPrLrMrOr_r^r`rSr\rRrrnrrrrqrrrtrurvr6r6r6r7rysb

1*
3	C
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#Nryrc
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|_y|jdkrd
|_ |!|_ |jdkr2x|j"|jy|j#|}|j$|WnTt%k
r|j"|jPYn0t&k
r*}zt't|Wd
d
}~XYnXqW|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+bwbZxb)ryarzrfz!mode must be 'r', 'a', 'w' or 'x'r~rzFNrrgTry)r~rzrf)-r.rg_moder|r%exists	bltn_openrrr rr"rLabspathrrPrdereferenceignore_zerosr4r5rrdebug
errorlevelcopybufsizermembers_loadedrrinodesfirstmemberrTrrJrrvrrr(rrZr0r)rrrgrrPrrrr4r5rrrrZmodeserTr6r6r7rs





$
zTarFile.__init__c

s|s|std|dkrfdd}xttj|dD]b}tj|}|dk	rX|}	y||d|f|Sttfk
r|dk	r||	w4Yq4Xq4Wtdnd	|kr|d	d
\}
}|
pd}
|pd}|jkrtj|}ntd||||
|f|Sd
|kr|d
d
\}
}|
p*d}
|p4d}|
dkrHtdt	||
|||}y||
|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)ryzr:*csj|dkS)Ntaropen)	OPEN_METH)r)r'r6r7not_compressed*sz$TarFile.open.<locals>.not_compressed)keyNryz%file could not be opened successfully:r#rzunknown compression type %r|)ryrzzmode must be 'r' or 'w'F)r~rzrfzundiscernible mode)
r.sortedrrkrrrrrrrrr)
r'rrgrr^kwargsrrfuncZ	saved_posrfstreamrr6)r'r7rsP%







zTarFile.opencKs |dkrtd||||f|S)zCOpen uncompressed tar archive name for reading or writing.
        )ryr~rzrfz!mode must be 'r', 'a', 'w' or 'x')r.)r'rrgrrr6r6r7r[szTarFile.taropenrcKs|dkrtdyddlm}Wntk
r<tdYnXy|||d||}Wn.tk
r|dk	r||dkr|td	YnXy|j|||f|}WnBtk
r||dkrtd	Yn|YnXd
|_	|S)zkOpen gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrfzmode must be 'r', 'w' or 'x'r)GzipFilezgzip module is not availableraNryznot a gzip fileF)
r.Zgziprrrrrrrr)r'rrgr
compresslevelrrrr6r6r7gzopencs0zTarFile.gzopenc	Ks|dkrtdyddlm}Wntk
r<tdYnX||pF|||d}y|j|||f|}WnFttfk
r||dkrt	dYn|YnXd	|_
|S)
zlOpen bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrfzmode must be 'r', 'w' or 'x'r)BZ2Filezbz2 module is not available)rryznot a bzip2 fileF)r.rrrrrrEOFErrorrrr)r'rrgrrrrrr6r6r7bz2opens&zTarFile.bz2openc		Ks|dkrtdyddlm}m}Wntk
r@tdYnX||pJ|||d}y|j|||f|}WnF|tfk
r||dkrt	dYn|YnXd	|_
|S)
zkOpen lzma compressed tar archive name for reading or writing.
           Appending is not allowed.
        )ryrzrfzmode must be 'r', 'w' or 'x'r)LZMAFilerzlzma module is not available)presetryznot an lzma fileF)r.rrrrrrrrrr)	r'rrgrrrrrrr6r6r7xzopens&zTarFile.xzopenrrrr)rrrrcCs|jr
dSd|_z`|jdkrn|jttd|jtd7_t|jt\}}|dkrn|jtt|Wd|j	s|j
XdS)zlClose the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NT)r~rzrfr$r)rrgrrZr1rrrX
RECORDSIZErr)rr_r`r6r6r7rs
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)rrrr6r6r7	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_loadr)rr6r6r7
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|]
}|jqSr6)r)rerr6r6r7rgsz$TarFile.getnames.<locals>.<listcomp>)r)rr6r6r7getnamesszTarFile.getnamescCsl|d|dk	r|j}|dkr$|}tj|\}}|tjd}|d}|}||_	|dkrt
tdr~|js~t|}qt
|}nt|}d}|j}t
|r|j|jf}	|js|jdkr|	|jkr||j|	krt}
|j|	}nt}
|	drt||j|	<nht
|rt}
nVt
|r0t}
nDt
|rLt}
t|}n(t
|r^t }
nt
!|rpt"}
ndS||_||_#|j$|_%|j&|_'|
tkr|j(|_)nd|_)|j*|_+|
|_,||_-t.ryt./|j%d|_0Wnt1k
rYnXt2r&yt23|j'd|_4Wnt1k
r$YnX|
t t"fkrht
tdrht
td	rht5|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.
        awxNrlstatrr#rmajorminor):rrr|r%
splitdriverrrrrrrrrefstatfilenost_modeS_ISREGst_inost_devst_nlinkrrprS_ISDIRrS_ISFIFOrsS_ISLNKroreadlinkS_ISCHRr+S_ISBLKr,rgst_uidr)st_gidr*st_sizer'st_mtimer(rrpwdgetpwuidr+rgrpZgetgrgidr,rst_rdevrrr)rrarcnamerZdrvrZstatresrZstmdinoderr6r6r7
gettarinfos~	




zTarFile.gettarinfoT)rcCs0||dkr|}x|D]
}|r|jdkr:tdntt|jtd|jpX|j|jpb|jf|	sz|
rtdd|j|jfntd|j
|jdkrtdntdt|jdd	t|j|rd
nd|r"|r
td|j|r"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 )rrgrorerfr+r)r,r*rqrrrrr'r(rZ	localtimerrrrrrn)rverboserrr6r6r7rb[s2





zTarFile.list)filterc	Cs:|d|dkr|}|jdk	rFtj||jkrF|dd|dS|d||||}|dkrz|dd|dS|dk	r||}|dkr|dd|dS|rt|d}|	||WdQRXnd|
r,|	||r6xHtt|D]*}|j
tj||tj||||d	qWn
|	|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 %rztarfile: Excluded %rr|)r)rrr|r%r_dbgrrraddfilerrlistdiraddr)rrr	recursiverrfr6r6r7rs4



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)r^rr#)rrrrPr4r5rrZrr0rrWr'rXrr1rr)rrrrTr^r_r`r6r6r7rs

zTarFile.addfilecCsp|dkr0|j}|dkrtSt|tr,td|St|r<|Syt|Stk
rjtd|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_FILTERSrr.)rrr6r6r7_get_filter_functions
zTarFile._get_filter_function.)
numeric_ownerrcCsg}||}|dkr|}xT|D]L}||||\}}	|dkr@q |rR||	|j|||||dq W|jddddx$|D]}	yy||	|}Wn4tk
r}
z||	t|
wWdd}
~
XYnX|dkr||	dwt	j
||j}yt	
|}Wn$tk
r.||dwYnXt|jsL||d	w|j|||d
||||||Wqtk
r}
z||
Wdd}
~
XYqXqWdS)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)r~r6r6r7<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%rrrFileNotFoundErrorrerrchownutimechmodr
_handle_nonfatal_error)rr%rrrZdirectoriesrrr
unfilteredexcdirpathrrr6r6r7
extractallsP


zTarFile.extractallcCs|dd|j|fdS)Nr$z(tarfile: Not fixing up directory %r (%s))rr)rrreasonr6r6r7r$	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%rrrrrrr6r6r7extract(	s
zTarFile.extractc
Cst|tr||}n|}d}y|||}WnZttfk
r\}z||Wdd}~XYn,tk
r}z||Wdd}~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$ztarfile: Excluded %r)NN)r r"rrr_handle_fatal_errorr
rrrrrr|r%rrr)rrrr%rfilteredrr6r6r7r=	s"

zTarFile._get_extract_tarinfoc
Cs|dy&|j|tj||j||||dWnVtk
r\}z||Wdd}~XYn,tk
r}z|	|Wdd}~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)
        ry)rrrextraction_rootN)
r_extract_memberr|r%rrrrr
r)rrr%rrrrr6r6r7r[	s
zTarFile._extract_onecCs"|jdkrn|dd|dS)z=Handle non-fatal error (ExtractError) according to errorlevelr#ztarfile: %sN)rr)rrr6r6r7ro	s
zTarFile._handle_nonfatal_errorcCsn|jdkrn\t|trP|jdkr6|dd|jqj|dd|j|jfn|ddt|j|fdS)z1Handle "fatal" error according to self.errorlevelrNr#ztarfile: %sztarfile: %s %rztarfile: %s %s)rr rfilenamerstrerrorrrp)rrr6r6r7rv	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.
        ryz'cannot extract (sym)link as file objectN)rr r"rrrrQ
fileobjectrrrrr	extractfile_find_link_target)rrrr6r6r7r	s


zTarFile.extractfile)rrcCsZ|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 -> %s)rrN)rrr|rr%rrmakedirsrrrrrrmakefilermakedirrtmakefiforqrrmakedevmakelink_with_filterrrQmakeunknownrrr)rr
targetpathrrrrZ	upperdirsr6r6r7r	s:



zTarFile._extract_membercCs@y&|jdkrt|nt|dWntk
r:YnXdS)z,Make a directory called targetpath.
        Ni)rgr|mkdirFileExistsError)rrrr6r6r7r	s
zTarFile.makedirc	Cs|j}||j|j}t|df}|jdk	rrx,|jD]"\}}||t|||t|q6W||j|	nt|||jt|WdQRXdS)z'Make a file called targetpath.
        r}N)
rrrrrrrWrr'truncate)rrrsourcer^targetrr'r6r6r7r	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)rrr)rrrr6r6r7r	szTarFile.makeunknowncCs"ttdrt|ntddS)z'Make a fifo called targetpath.
        mkfifozfifo not supported by systemN)rr|rr
)rrrr6r6r7r	s
zTarFile.makefifocCsjttdrttdstd|j}|dkr.d}|rB|tjO}n
|tjO}t||t	|j
|jdS)z<Make a character or block device called targetpath.
        mknodrz'special devices not supported by systemNi)rr|r
rgrrreS_IFBLKS_IFCHRrrrr)rrrrgr6r6r7r
s
zTarFile.makedevcCs|||ddS)N)r)rrrr6r6r7makelink
szTarFile.makelinkc	
CsPd}y\|r6tj|r$t|t|j|dStj|jr^t	tj
|j|dSWntk
rxd}YnXy||}Wn$t
k
r|rtdnYnX|dkr|}nt|dkrtdy0||j|jdd|}|dkrdS|||}Wn2tk
r.}zt||j|Wdd}~XYnX|dk	rL|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)rr)rr)rr|r%lexistsunlinksymlinkrrrlinkrsymlink_exceptionrrr
rrrrr)	rrrrrZkeyerror_to_extracterrorrrcauser6r6r7r
sJ	

 
zTarFile.makelink_with_filtercCsttdrtdkr|j}|j}|sytrB|jrBt|jd}Wntk
rXYnXyt	rv|j
rvt	|j
d}Wntk
rYnX|dkrd}|dkrd}y4|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$Nr9lchownzcould not change owner)rr|r
r*r)rr,Zgetgrnamrrr+getpwnamrrrrr
)rrrrgur6r6r7rW
s0

z
TarFile.chowncCsL|jdkrdSttdrHyt||jWntk
rFtdYnXdS)zASet file permissions of targetpath according to tarinfo.
        Nrzcould not change mode)rgrr|rrr
)rrrr6r6r7rx
s

z
TarFile.chmodcCsV|j}|dkrdSttds dSyt|||fWntk
rPtdYnXdS)zBSet modification time of targetpath according to tarinfo.
        Nrz"could not change modification time)r(rr|rrr
)rrrr(r6r6r7r
s
z
TarFile.utimec
Cs|d|jdk	r$|j}d|_|S|j|jkrZ|j|jd|jdsZtdd}xby|j	|}WnHt
k
r}z0|jr|dd|j|f|jt
7_wbWdd}~XYntk
r,}zL|jr|dd|j|f|jt
7_wbn|jdkrtt|Wdd}~XYntk
rT|jdkrPtdYnjtk
r}z|jdkr~tt|Wdd}~XYn0tk
r}ztt|Wdd}~XYnXPqbW|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#zunexpected end of datar$z0x%X: %srz
empty fileT)rrrrrrrYrrrJrvrrrrHr"rtrurwrrr)rmrrr6r6r7rT
sL


zTarFile.nextc	Cs|}d}|dk	rHy||}Wntk
r:d}YnX|d|}|rXtj|}xLt|D]@}|r||j|jkrbd}qb|rtj|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|}|dkrPqWd|_dS)zWRead through the entire archive file and look for readable
           members.
        NT)rTr)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)rrrrprg)rrgr6r6r7r
szTarFile._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)rrzlinkname %r not found)
rrrr|r%rrrrr)rrrlimitrr6r6r7rs zTarFile._find_link_targetccs|jr|jEdHdSd}|jdk	r:|}|d7}|VxN|t|jkrV|j|}n"|jst|}|sxd|_dSndS|d7}|Vq<WdS)z$Provide an iterator object.
        Nrr#T)rrrrTr0)rrrr6r6r7__iter__s&
zTarFile.__iter__cCs||jkrt|tjddS)z.Write debugging output to sys.stderr.
        )fileN)rrnrlstderr)rlevelmsgr6r6r7r4s
zTarFile._dbgcCs||S)N)r)rr6r6r7	__enter__:szTarFile.__enter__cCs,|dkr|n|js"|jd|_dS)NT)rrrr)rrr	tracebackr6r6r7__exit__>s


zTarFile.__exit__)
NryNNNNNNrNNNN)ryN)ryNr)ryNr)ryNN)NNN)T)NT)N)rN)rT)N)TF)NF)N)@rprqrrrsrrrrrrPrr4r5rrrrrrrzrrrrrrrrrrrrrbrrrrrrrrrrrrrrrrrrrrrrrTrrrrrrrrr6r6r6r7rus
lZ 

d&3
D
6;!6
(

	cCs.yt|}|dStk
r(dSXdS)zfReturn True if name points to a tar archive that we
       are able to handle, else return False.
    TFN)rrr)rrr6r6r7rLsc	Csddl}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%WdQRX|jr0t
d&|n|d"d'|n|jdk	r|j}t
|rxt|d(}|j|jd)WdQRXn|d"d'|nz|jdk	rbt|jd"kr|jd}tj}n,t|jd*kr|j\}}n|d"|t
|rNt|d(}|j||jd+WdQRX|jr`|d,kr8d-|}	nd.||}	t
|	n|d"d'|n|jdk	r|jd}
tj|
\}}d/d/d0d0d1d1d1d1d2}
||
krd3|
|nd4}|j}t|
| }x|D]}||qWWdQRX|jrt
d5|
dS)6Nrz3A simple command-line interface for tarfile module.)descriptionz-vz	--verbose
store_trueFzVerbose output)actiondefaulthelpz--filterz<filtername>zFilter for extraction)metavarchoicesr!T)Zrequiredz-lz--listz	<tarfile>zShow listing of a tarfile)r"r!z-ez	--extract+)z	<tarfile>z<output_dir>zExtract tarfile into target dir)nargsr"r!z-cz--create)z<name>z<file>zCreate tarfile from sourcesz-tz--testzTest if a tarfile is validr#z&--filter is only valid for extraction
ry)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:rzz{!r} file created.)argparseArgumentParseradd_argumentrZadd_mutually_exclusive_group
parse_argsrrexitZtestrrrrnrlrrrPrbrr0r|curdirZformat_helprZcreatepopr%splitextr)r&rparserrZargsr[rZtfr+rZtar_namerdZextZcompressionsZtar_modeZ	tar_files	file_namer6r6r7mainZs










r1__main__)T)prsversion
__author____credits__builtinsrrrlr|rrVrerrSrrerbrrrAttributeErrorNotImplementedErrorrr	NameError__all__r1rrrrrrr)rr@rpror+r,rrsZCONTTYPErrrAr$r&rNr
rrrrQrmrCrjr]r!rFrkrrgetfilesystemencodingr8r=rKrQrUrWrfro	Exceptionrr
rrr	rrtrurvrHrwrxrobjectrrBufferedReaderrcompilerXrrrrrrrrrrrrrrrrrr1rpr6r6r6r7<module>s



yh	



Q`_