�
��c@s)dZdZdZdZdZdZdZddkZddkZddk Z ddk
Z
ddkZddkZddk
Z
ddkZeid jo
ed
�nyddkZddkZWnej
oeZZnXddd
dgZdZdZedZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd Z(d!Z)eee e!e$e%e&e"e#e'e(e)fZ*eee&e)fZ+d"Z,d#Z-d$Z.d%Z/d&Z0d'Z1d(Z2d)Z3dZ4d*Z5d+Z6d,Z7d-Z8d.Z9d/Z:d0Z;d1Z<d2Z=d3�Z>d4�Z?d/e@d5�ZAd6�ZBed7�ZCe,d8fe-d9fe.d:fe/d;fe0d<fe1d=ffe5d>ffe6d?ffe7e2Bd@fe2d!fe7dAffe8d>ffe9d?ffe:e3Bd@fe3d!fe:dAffe;d>ffe<d?ffe=e4BdBfe4dCfe=dAfff
ZDdD�ZEeiFdEjo
dF�ZGn
eiHiGZGdeIfdG��YZJdHeJfdI��YZKdJeJfdK��YZLdLeJfdM��YZMdNeJfdO��YZNdPfdQ��YZOdRfdS��YZPdTeQfdU��YZRdVeQfdW��YZSdXeQfdY��YZTdZeQfd[��YZUdeQfd\��YZVdeQfd]��YZWd^fd_��YZXd`fda��YZYdbeYfdc��YZZddeYfde��YZ[dfe\fdg��YZ]dhZ^d/Z_difdj��YZ`dk�ZaeWibZbdS(ls,Read from and write to tar format archives.
s$Revision: 53162 $s0.8.0s!Lars Gust�l ([email protected])s5$Date: 2006-12-27 21:36:58 +1100 (Wed, 27 Dec 2006) $s;$Id: tarfile.py 53162 2006-12-27 10:36:58Z lars.gustaebel $s3Gustavo Niemeyer, Niels Gust�l, Richard Townsend.i�Ntmacs'tarfile does not work for platform==mactTarFiletTarInfot
is_tarfiletTarErrortiitustart00idi�l�t0t1t2t3t4t5t6t7tLtKtSi�i�i`i@i iiiii�i@i iiiiicCs|| |t|�tS(s@Convert a python string to a null-terminated string buffer.
(tlentNUL(tstlength((s/sys/lib/python/tarfile.pytstn�scCs�|dtd�jo't|itd�pdd�}nJd}x@tt|�d�D](}|dK}|t||d�7}q[W|S(s/Convert a number field to a python number.
ii�t Rili(tchrtinttrstripRtxrangeRtord(Rtnti((s/sys/lib/python/tarfile.pytnti�s'
cCs�d|jod|djnod|d|ft}n�|otd��n|djo&tidtid|��d}nd}x6t|d�D]$}t|d @�|}|dL}q�Wtd
�|}|S(s/Convert a python number to a number field.
iiis%0*osoverflow in number fieldRtlti�i�(Rt
ValueErrortstructtunpacktpackRR(RtdigitstposixRR((s/sys/lib/python/tarfile.pytitn�s &
&cCsxdttid|d �tid|dd!��}dttid|d �tid|dd!��}||fS( s�Calculate 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.
it148Bi�t356Bi�it148bt356b(tsumR$R%(tbuftunsigned_chksumt
signed_chksum((s/sys/lib/python/tarfile.pytcalc_chksums�s 77cCs�|djodSn|djoti||�dSnd}t||�\}}xSt|�D]E}|i|�}t|�|jotd��n|i|�qbW|djoC|i|�}t|�|jotd��n|i|�ndS(sjCopy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
iNiisend of file reachedi@( tNonetshutiltcopyfileobjtdivmodRtreadRtIOErrortwrite(tsrctdstRtBUFSIZEtblockst remaindertbR/((s/sys/lib/python/tarfile.pyR5�s&
R!t-R?tdtctptrtwRtxtttTcCskg}xUtD]M}xD|D]/\}}||@|jo|i|�PqqW|id�q
Wdi|�S(scConvert a file's mode to a string of the form
-rwxrwxrwx.
Used by TarFile.list()
R@R"(tfilemode_tabletappendtjoin(tmodetpermttabletbittchar((s/sys/lib/python/tarfile.pytfilemode�s
t/cCstii|�itid�S(RR(tostpathtnormpathtreplacetsep(RT((s/sys/lib/python/tarfile.pyt<lambda>scBseZdZRS(sBase exception.(t__name__t
__module__t__doc__(((s/sys/lib/python/tarfile.pyRstExtractErrorcBseZdZRS(s%General exception for extract errors.(RYRZR[(((s/sys/lib/python/tarfile.pyR\st ReadErrorcBseZdZRS(s%Exception for unreadble tar archives.(RYRZR[(((s/sys/lib/python/tarfile.pyR]stCompressionErrorcBseZdZRS(s.Exception for unavailable compression methods.(RYRZR[(((s/sys/lib/python/tarfile.pyR^stStreamErrorcBseZdZRS(s=Exception for unsupported operations on stream-like TarFiles.(RYRZR[(((s/sys/lib/python/tarfile.pyR_st
_LowLevelFilecBs2eZdZd�Zd�Zd�Zd�ZRS(s�Low-level file object. Supports reading and writing.
It is used instead of a regular file object for streaming
access.
cCsjhtid<titiBtiBd<|}ttd�o|tiO}nti||�|_dS(NRDREtO_BINARY( RStO_RDONLYtO_WRONLYtO_CREATtO_TRUNCthasattrRatopentfd(tselftnameRL((s/sys/lib/python/tarfile.pyt__init__%scCsti|i�dS(N(RStcloseRh(Ri((s/sys/lib/python/tarfile.pyRl.scCsti|i|�S(N(RSR7Rh(Ritsize((s/sys/lib/python/tarfile.pyR71scCsti|i|�dS(N(RSR9Rh(RiR((s/sys/lib/python/tarfile.pyR94s(RYRZR[RkRlR7R9(((s/sys/lib/python/tarfile.pyR`s
t_StreamcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d d
�Zdd�Z
d�Zd
�ZRS(s�Class that serves as an adapter between TarFile and
a stream-like object. The stream-like object only
needs to have a read() or write() method and is accessed
blockwise. Use of gzip or bzip2 compression is possible.
A stream-like object could be for example: sys.stdin,
sys.stdout, a socket, a tape device etc.
_Stream is intended to be used only internally.
c
Cs�t|_|djot||�}t|_n|djot|�}|i�}n|pd|_||_||_ ||_
||_d|_d|_
t|_|djovyddk}Wntj
otd��nX||_|id�|_|djo|i�q-|i�n|d jonyddk}Wntj
otd
��nX|djod|_|i�|_q�|i�|_ndS(s$Construct a _Stream object.
t*R"ltgzi�Nszlib module is not availableRDtbz2sbz2 module is not available(tTruet_extfileobjR3R`tFalset_StreamProxytgetcomptypeRjRLtcomptypetfileobjtbufsizeR/tpostclosedtzlibtImportErrorR^tcrc32tcrct
_init_read_gzt_init_write_gzRqtdbuftBZ2Decompressortcmpt
BZ2Compressor(RiRjRLRwRxRyR|Rq((s/sys/lib/python/tarfile.pyRkBsD
cCs-t|d�o|io|i�ndS(NR{(RfR{Rl(Ri((s/sys/lib/python/tarfile.pyt__del__pscCs�|iid|ii|ii|iid�|_tidtt i ���}|i
d|�|iid�o|id |_n|i
|it
�dS(s6Initialize for writing with gzip compression.
i is<Ls�%s�.gzi�N(R|tcompressobjtDEFLATEDt MAX_WBITSt
DEF_MEM_LEVELR�R$R&tlongttimet_Stream__writeRjtendswithR(Rit timestamp((s/sys/lib/python/tarfile.pyR�ts
cCs{|idjo|ii||i�|_n|it|�7_|idjo|ii|�}n|i|�dS(s&Write string s to the stream.
RpttarN( RwR|R~RRzRR�tcompressR�(RiR((s/sys/lib/python/tarfile.pyR9�scCsa|i|7_xKt|i�|ijo1|ii|i|i �|i|i|_qWdS(s]Write string s to the stream if a whole new block
is ready to be written.
N(R/RRyRxR9(RiR((s/sys/lib/python/tarfile.pyt__write�scCs
|iodSn|idjo,|idjo|i|ii�7_n|idjo�|ioz|ii|i�d|_|idjoJ|iiti d|i
d@��|iiti d|id@��q�n|ip|ii
�nt|_dS(s[Close the _Stream object. No operation should be
done on it afterwards.
NRER�R"Rps<Ll�(R{RLRwR/R�tflushRxR9R$R&RRzRsRlRr(Ri((s/sys/lib/python/tarfile.pyRl�s
#+
cCs�|ii|ii�|_d|_|id�djotd��n|id�djotd��nt|id��}|id�|d @o=t|id��d
t|id��}|i |�n|d@o<x9t
o-|id�}|p
|tjoPq�q�Wn|d@o<x9t
o-|id�}|p
|tjoPq0q0Wn|d@o|id�nd
S(s:Initialize for reading a gzip compressed fileobj.
R"is�not a gzip fileissunsupported compression methodiiiiiN(R|t
decompressobjR�R�R�t
_Stream__readR]R^RR7RrR(RitflagtxlenR((s/sys/lib/python/tarfile.pyR��s.
,
cCs|iS(s3Return the stream's file pointer position.
(Rz(Ri((s/sys/lib/python/tarfile.pyttell�sicCs~||idjoWt||i|i�\}}x$t|�D]}|i|i�q@W|i|�n
td��|iS(sXSet the stream's file pointer to pos. Negative seeking
is forbidden.
is seeking backwards is not allowed(RzR6RyRR7R_(RiRzR=R>R((s/sys/lib/python/tarfile.pytseek�s
cCs�|djoSg}x7to/|i|i�}|pPn|i|�qWdi|�}n|i|�}|it|�7_|S(s�Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
R"N(R3Rrt_readRyRJRKRzR(RiRmRGR/((s/sys/lib/python/tarfile.pyR7�s
cCs�|idjo|i|�Snt|i�}|ig}x_||joQ|i|i�}|pPn|ii|�}|i|�|t|�7}q?Wdi|�}|||_|| S(s+Return size bytes from the stream.
R�R"( RwR�RR�RyR�t
decompressRJRK(RiRmRBRGR/((s/sys/lib/python/tarfile.pyR��s
cCs�t|i�}|ig}xP||joB|ii|i�}|pPn|i|�|t|�7}qWdi|�}|||_|| S(ssReturn size bytes from stream. If internal buffer is empty,
read another block from the stream.
R"(RR/RxR7RyRJRK(RiRmRBRGR/((s/sys/lib/python/tarfile.pyt__reads
N(RYRZR[RkR�R�R9R�RlR�R�R�R3R7R�R�(((s/sys/lib/python/tarfile.pyRn7s .
RucBs2eZdZd�Zd�Zd�Zd�ZRS(ssSmall proxy class that enables transparent compression
detection for the Stream interface (mode 'r|*').
cCs"||_|iit�|_dS(N(RxR7t BLOCKSIZER/(RiRx((s/sys/lib/python/tarfile.pyRks cCs|ii|_|iS(N(RxR7R/(RiRm((s/sys/lib/python/tarfile.pyR7 scCs:|iid�odSn|iid�odSndS(Ns�RptBZh91RqR�(R/t
startswith(Ri((s/sys/lib/python/tarfile.pyRv$s
cCs|ii�dS(N(RxRl(Ri((s/sys/lib/python/tarfile.pyRl+s(RYRZR[RkR7RvRl(((s/sys/lib/python/tarfile.pyRus
t _BZ2ProxycBsSeZdZd
Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z
RS(sSmall proxy class that enables external file object
support for "r:bz2" and "w:bz2" modes. This is actually
a workaround for a limitation in bz2 module's BZ2File
class which (unlike gzip.GzipFile) has no support for
a file object argument.
iicCs ||_||_|i�dS(N(RxRLtinit(RiRxRL((s/sys/lib/python/tarfile.pyRk9s cCsdddk}d|_|idjo,|i�|_|iid�d|_n|i�|_dS(Ni�iRDR"( RqRzRLR�tbz2objRxR�R/R�(RiRq((s/sys/lib/python/tarfile.pyR�>s
cCs�|ig}t|i�}xq||jocy8|ii|i�}|ii|�}|i|�Wntj
oPnX|t|�7}qWdi |�|_|i| }|i||_|i
t|�7_
|S(NR"(R/RRxR7t blocksizeR�R�RJtEOFErrorRKRz(RiRmR?RFtrawtdataR/((s/sys/lib/python/tarfile.pyR7Hs
cCs6||ijo|i�n|i||i�dS(N(RzR�R7(RiRz((s/sys/lib/python/tarfile.pyR�ZscCs|iS(N(Rz(Ri((s/sys/lib/python/tarfile.pyR�_scCs;|it|�7_|ii|�}|ii|�dS(N(RzRR�R�RxR9(RiR�R�((s/sys/lib/python/tarfile.pyR9bscCsD|idjo#|ii�}|ii|�n|ii�dS(NRE(RLR�R�RxR9Rl(RiR�((s/sys/lib/python/tarfile.pyRlgsi@(RYRZR[R�RkR�R7R�R�R9Rl(((s/sys/lib/python/tarfile.pyR�/s
t_FileInFilecBsSeZdZdd�Zd�Zd�Zdd�Zd�Zd�Z d�Z
RS( sA thin wrapper around an existing file object that
provides a part of its data as an individual file
object.
cCs1||_||_||_||_d|_dS(Ni(RxtoffsetRmtsparsetposition(RiRxR�RmR�((s/sys/lib/python/tarfile.pyRkws
cCs|iS(s*Return the current file position.
(R�(Ri((s/sys/lib/python/tarfile.pyR�~scCs
||_dS(s(Seek to a position in the file.
N(R�(RiR�((s/sys/lib/python/tarfile.pyR��scCsl|djo|i|i}nt||i|i�}|idjo|i|�Sn|i|�SdS(s!Read data from the file.
N(R3RmR�tminR�t
readnormalt
readsparse(RiRm((s/sys/lib/python/tarfile.pyR7�s
cCs9|ii|i|i�|i|7_|ii|�S(s*Read operation for regular files.
(RxR�R�R�R7(RiRm((s/sys/lib/python/tarfile.pyR��scCs`g}xJ|djo<|i|�}|pPn|t|�8}|i|�q Wdi|�S(s)Read operation for sparse files.
iR"(treadsparsesectionRRJRK(RiRmR�R/((s/sys/lib/python/tarfile.pyR��scCs�|ii|i�}|djodSnt||i|i|i�}t|t�oQ|i |i|i}|i
i|i|�|i|7_|i
i|�Sn|i|7_t
|SdS(s0Read a single section of a sparse file.
R"N(R�tfindR�R3R�R�Rmt
isinstancet_datatrealposRxR�R7R(RiRmtsectionR�((s/sys/lib/python/tarfile.pyR��s
N(RYRZR[R3RkR�R�R7R�R�R�(((s/sys/lib/python/tarfile.pyR�qs
tExFileObjectcBsheZdZdZd�Zdd�Zdd�Zd�Zd�Z e
id�Zd �Z
d
�ZRS(saFile-like object for reading an archive member.
Is returned by TarFile.extractfile().
icCsmt|i|i|it|dd��|_|i|_d|_t|_ |i|_d|_
d|_dS(NR�RDiR"(R�Rxtoffset_dataRmtgetattrR3RjRLRtR{R�tbuffer(Rittarfilettarinfo((s/sys/lib/python/tarfile.pyRk�s cCs�|iotd��nd}|ioD|djo|i}d|_qn|i| }|i||_n|djo||ii�7}n!||ii|t|��7}|it|�7_|S(s~Read at most size bytes from the file. If size is not
present or None, read all data until EOF is reached.
sI/O operation on closed fileR"N(R{R#R�R3RxR7RR�(RiRmR/((s/sys/lib/python/tarfile.pyR7�s
i�cCs9|iotd��nd|ijo|iid�d}n�|ig}x�to�|ii|i�}|i|�|p
d|joMdi |�|_|iid�d}|djot
|i�}nPqSqSW|djot||�}n|i| }|i||_|it
|�7_|S(s�Read one entire line from the file. If size is present
and non-negative, return a string with at most that
size, which may be an incomplete line.
sI/O operation on closed files
iR"ii�(
R{R#R�R�RrRxR7R�RJRKRR�R�(RiRmRztbuffersR/((s/sys/lib/python/tarfile.pytreadline�s(
cCs>g}x1to)|i�}|pPn|i|�q W|S(s0Return a list with all remaining lines.
(RrR�RJ(Ritresulttline((s/sys/lib/python/tarfile.pyt readliness
cCs!|iotd��n|iS(s*Return the current file position.
sI/O operation on closed file(R{R#R�(Ri((s/sys/lib/python/tarfile.pyR�s
cCs|iotd��n|tijo"tt|d�|i�|_n�|tijoJ|djot|i|d�|_q�t|i||i�|_nF|ti jo)tt|i||i�d�|_n
td��d|_
|ii|i�dS(s(Seek to a position in the file.
sI/O operation on closed fileisInvalid argumentR"N(
R{R#RStSEEK_SETR�tmaxRmR�tSEEK_CURtSEEK_ENDR�RxR�(RiRztwhence((s/sys/lib/python/tarfile.pyR�s
"
) cCs
t|_dS(sClose the file object.
N(RrR{(Ri((s/sys/lib/python/tarfile.pyRl.sccs0x)to!|i�}|pPn|VqWdS(s/Get an iterator over the file's lines.
N(RrR�(RiR�((s/sys/lib/python/tarfile.pyt__iter__3s
N(RYRZR[R�RkR3R7R�R�R�RSR�R�RlR�(((s/sys/lib/python/tarfile.pyR��s
cBs�eZdZdd�Zd�Zed��Zed�Zd�Z d�Z
d�Zd �Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�ZRS(sInformational class which holds the details about an
archive member given by a tar header block.
TarInfo objects are returned by TarFile.getmember(),
TarFile.getmembers() and TarFile.gettarinfo() and are
usually created internally.
R"cCs�||_d|_d|_d|_d|_d|_d|_t|_d|_ d|_
d|_d|_d|_
d|_d|_dS(sXConstruct a TarInfo object. name is the optional name
of the member.
i�iR"tusertgroupN(RjRLtuidtgidRmtmtimetchksumtREGTYPEttypetlinknametunametgnametdevmajortdevminorR�R�(RiRj((s/sys/lib/python/tarfile.pyRkHs cCs d|ii|it|�fS(Ns<%s %r at %#x>(t __class__RYRjtid(Ri((s/sys/lib/python/tarfile.pyt__repr__]scCs�t|�tjotd��n|it�tjotd��n|�}||_|dd!it�|_t|dd!�|_ t|dd!�|_
t|dd!�|_t|dd!�|_t|dd !�|_
t|d d
!�|_|d
d!|_|dd!it�|_|d
d!it�|_|dd!it�|_t|dd!�|_t|dd!�|_|dd!it�}|o&|i�o|d|i|_n|it|�jotd��n|S(sBConstruct a TarInfo object from a 512 byte string buffer.
struncated headersempty headeriidiliti|i�i�i�i�ii i)iIiQiYi�RRsinvalid header(RR�R#tcountRR/RRjR RLR�R�RmR�R�R�R�R�R�R�R�tissparseR2(tclsR/R�tprefix((s/sys/lib/python/tarfile.pytfrombuf`s2 c Cs/d}|i}d}|iid�o
t}n|ttfjo
|i}nt|i�}|tjo|d7}n|i}|ot|�}n|o�|it jot
d��nt|i�tjot
dt��nt|�t
jo�|td }x'|o|ddjo|d }qW|t|�}|d }|pt|�t
jot
d��q�q�nat|i�tjo||i|it�7}nt|�t
jo||i|t�7}nt|d�t|id @d
|�t|id
|�t|id
|�t|id|�t|id|�d|t|id�ttd
�ttd�t|id�t|id�t|id
|�t|id
|�t|d�g}|tidtdi|��7}t |t�d}|d d||d}||_!|S(s<Return a tar header as a string of 512 byte blocks.
R"RRsfile is too large (>= 8 GB)slinkname is too long (>%d)ii�sname is too longidi�iis iii i�s%dsii��%06oi��R�RjR�tDIRTYPEtGNUTYPE_LONGNAMEtGNUTYPE_LONGLINKRUR�RmtMAXSIZE_MEMBERR#RtLENGTH_LINKtLENGTH_NAMEt
LENGTH_PREFIXt_create_gnulongRR)RLR�R�R�tMAGICtVERSIONR�R�R�R�R$R&R�RKR2R/( RiR(R/R�R�RjR�tpartsR�((s/sys/lib/python/tarfile.pyttobuf�sf
# cCs�|t7}|i�}d|_||_d|_t|�|_|i�}||7}tt|�t �\}}|djo|t |t7}n|S(s�Create a GNU longname/longlink header from name.
It consists of an extended tar header, with the length
of the longname as size, followed by data blocks,
which contain the longname as a null terminated string.
s
././@LongLinki(
RR�RjR�RLRRmR�R6R�(RiRjR�R�R/R=R>((s/sys/lib/python/tarfile.pyR��s
cCs
|itjS(N(R�t
REGULAR_TYPES(Ri((s/sys/lib/python/tarfile.pytisreg�scCs
|i�S(N(R�(Ri((s/sys/lib/python/tarfile.pytisfile�scCs
|itjS(N(R�R�(Ri((s/sys/lib/python/tarfile.pytisdir�scCs
|itjS(N(R�tSYMTYPE(Ri((s/sys/lib/python/tarfile.pytissym�scCs
|itjS(N(R�tLNKTYPE(Ri((s/sys/lib/python/tarfile.pytislnk�scCs
|itjS(N(R�tCHRTYPE(Ri((s/sys/lib/python/tarfile.pytischr�scCs
|itjS(N(R�tBLKTYPE(Ri((s/sys/lib/python/tarfile.pytisblk�scCs
|itjS(N(R�tFIFOTYPE(Ri((s/sys/lib/python/tarfile.pytisfifo�scCs
|itjS(N(R�tGNUTYPE_SPARSE(Ri((s/sys/lib/python/tarfile.pyR��scCs|itttfjS(N(R�R�R�R�(Ri((s/sys/lib/python/tarfile.pytisdev�s(RYRZR[RkR�tclassmethodR�RtR�R�R�R�R�R�R�R�R�R�R�R�(((s/sys/lib/python/tarfile.pyR@s !K cBs eZdZdZeZeZdZeZe Z
d3dd3d�Ze
d3dd3d4d��Ze
dd3d��Ze
dd3dd ��Ze
dd3dd
��Zhdd<d
d<dd<Zd�Zd�Zd�Zd�Zd3d3d3d�Zed�Zd3ed�Zd3d�Zdd3d�Zdd�Zd�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d%�Z&d&�Z'd'�Z(d(�Z)d)�Z*d*�Z+d+�Z,d,�Z-d-�Z.d3d.�Z/d/�Z0d3d0�Z1d1�Z2d2�Z3RS(5s=The TarFile Class provides an interface to tar archives.
iRDcCstii|�|_t|�djp
|djotd��n||_hdd<dd<dd <||_|p"t|i|i�}t |_
nf|idjo,t|d
�otii|i�|_nt|d�o|i|_nt
|_
||_t |_g|_t |_d|_h|_|idjod|_|i�|_n|idjoyd|_xmt
oay|i�}Wn$tj
o|iid
�PnX|djo|iitd�Pq�q�Wn|idjo
t
|_ndS(s�Open 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.
iR�smode must be 'r', 'a' or 'w'trbRDsr+btatwbRERjRLlitawN(RSRTtabspathRjRR#t_modeRLtfileRtRsR3RfRrRxR{tmemberst_loadedR�tinodestfirstmembertnextR]R�R�(RiRjRLRxR�((s/sys/lib/python/tarfile.pyRksF (
iic
Cs'|o|otd��n|djo�x�|iD]�}t||i|�}|dj o|i�}ny||d|�SWq7ttfj
o(|dj o|i|�q7q7q7Xq7Wtd��nCd|jo�|idd�\}}|pd}|pd}||ijot||i|�}ntd|��||||�Sn�d |jo�|id d�\}}|pd}|pd}|d
jotd��n|||t |||||��} t
| _| Sn%|djo|i|||�Sntd
��dS(s\Open 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
'a' or 'a:' open for appending
'w' or 'w:' open for writing without compression
'w:gz' open for writing with gzip compression
'w:bz2' open for writing with bzip2 compression
'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
'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
snothing to openRDsr:*s%file could not be opened successfullyt:iR�sunknown compression type %rt|trwsmode must be 'r' or 'w'R�sundiscernible modeN(RDsr:*(
R#t OPEN_METHR�R3R�R]R^R�tsplitRnRtRsttaropen(
R�RjRLRxRyRwtfunct saved_posRQRG((s/sys/lib/python/tarfile.pyRgQsH
cCs@t|�djp
|djotd��n||||�S(sCOpen uncompressed tar archive name for reading or writing.
iR�smode must be 'r', 'a' or 'w'(RR#(R�RjRLRx((s/sys/lib/python/tarfile.pyR�s i cCs�t|�djp
|djotd��nyddk}|iWn%ttfj
otd��nX|djot||d�}ny+|i |||i||||��}Wnt
j
otd��nXt|_
|S( skOpen gzip compressed tar archive name for reading or writing.
Appending is not allowed.
iRsmode must be 'r' or 'w'i�Nsgzip module is not availableR?snot a gzip file(RR#tgziptGzipFileR}tAttributeErrorR^R3R�RR8R]RtRs(R�RjRLRxt
compresslevelRRG((s/sys/lib/python/tarfile.pytgzopen�s
cCs�t|�djp
|djotd��nyddk}Wntj
otd��nX|dj ot||�}n|i||d|�}y|i|||�}Wnt j
ot
d��nXt|_|S( slOpen bzip2 compressed tar archive name for reading or writing.
Appending is not allowed.
iRsmode must be 'r' or 'w'.i�Nsbz2 module is not availableRsnot a bzip2 file(
RR#RqR}R^R3R�tBZ2FileRR8R]RtRs(R�RjRLRxRRqRG((s/sys/lib/python/tarfile.pytbz2open�s
RR�RRpRRqcCs�|iodSn|idjop|iittd�|itd7_t|it�\}}|djo|iitt|�q�n|i p|ii
�nt|_dS(slClose the TarFile. In write-mode, two finishing zero blocks are
appended to the archive.
NR�ii(R{R�RxR9RR�R�R6t
RECORDSIZERsRlRr(RiR=R>((s/sys/lib/python/tarfile.pyRl�s
cCs4|i|�}|djotd|��n|S(sReturn 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 occurence is assumed to be the
most up-to-date version.
sfilename %r not foundN(t
_getmemberR3tKeyError(RiRjR�((s/sys/lib/python/tarfile.pyt getmember�s
cCs)|i�|ip|i�n|iS(s�Return the members of the archive as a list of TarInfo objects. The
list has the same order as the members in the archive.
(t_checkR�t_loadR�(Ri((s/sys/lib/python/tarfile.pyt
getmembers�s
cCs(g}|i�D]}||iq~S(s�Return the members of the archive as a list of their names. It has
the same order as the list returned by getmembers().
(RRj(Rit_[1]R�((s/sys/lib/python/tarfile.pytgetnamesscCs�|id�|dj o
|i}n|djo
|}nt|�}tii|�\}}x#|dd!djo|d}qeWt�}|djoAttd�o|i oti
|�}q�i|�}nti|i
��}d}|i}ti|�oz|i|if} |i o7|idjo'| |ijot}
|i| }qAt}
| do||i| <qAn�ti|�o)t}
|ddjo|d7}qAn|ti|�o
t}
nbti|�ot}
ti|�}n9ti|�o
t}
nti|�o
t }
ndS||_||_!|i"|_#|i$|_%ti|�o|i&|_'n
d|_'|i(|_)|
|_*||_+t,o7yt,i-|i#�d|_.Wq�/j
oq�nt0o7yt0i1|i%�d|_2Wq.t/j
oq.Xn|
tt fjoRttd �o>ttd
�o.ti3|i4�|_5ti6|i4�|_7q�n|S(sOCreate a TarInfo object for either the file `name' or the file
object `fileobj' (using os.fstat on its file descriptor). You can
modify some of the TarInfo's attributes before you add it using
addfile(). If given, `arcname' specifies an alternative name for the
file in the archive.
R�iiRRtlstatR"i�ltmajortminorN(8RR3RjRURSRTt
splitdriveRRftdereferenceRtstattfstattfilenotst_modetS_ISREGtst_inotst_devtst_nlinkRR�R�tS_ISDIRR�tS_ISFIFOR�tS_ISLNKR�treadlinktS_ISCHRR�tS_ISBLKR�RLtst_uidR�tst_gidR�tst_sizeRmtst_mtimeR�R�R�tpwdtgetpwuidR�RtgrptgetgrgidR�Rtst_rdevR�RR�(RiRjtarcnameRxtdrvR�tstatresR�tstmdtinodeR�((s/sys/lib/python/tarfile.pyt
gettarinfos�
cCs|i�x�D]�|o�t|i�Gd|ip|i|ip|ifG|i�p
|i�odd|i |i
fGnd|iGdti
|i�d Gn|iG|o<|i�odG|iGn|i�odG|iGq�HqWd S(
s�Print 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.
s%s/%ss%10ss%d,%ds%10ds%d-%02d-%02d %02d:%02d:%02dis->slink toN(RRQRLR�R�R�R�R�R�R�R�RmR�t localtimeR�RjR�R�R�(RitverboseR�((s/sys/lib/python/tarfile.pytlistps(
cCs�|id�|djo
|}n|idj o8tii|�|ijo|idd|�dSn|djoc|oT|djo
d}nx:tid�D]%}|i|tii ||��q�WndSn|id|�|i
||�}|djo|idd|�dSn|i�o-t|d �}|i
||�|i�n|i�od|i
|�|oLxIti|�D]4}|itii ||�tii ||��q�Wq�n|i
|�dS(
sQAdd 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.
R�istarfile: Skipped %rNt.R"istarfile: Unsupported type %rR�(RR3RjRSRTR�t_dbgtlistdirtaddRKR<R�R�taddfileRlR�(RiRjR7t recursivetfR�((s/sys/lib/python/tarfile.pyRC�s<
,
'
:cCs�|id�ti|�}|i|i�}|ii|�|it|�7_|dj oxt ||i|i
�t|i
t�\}}|djo&|iit
t|�|d7}n|i|t7_n|ii|�dS(s]Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
given, tarinfo.size bytes are read from it and added to the archive.
You can create TarInfo objects using gettarinfo().
On Windows platforms, `fileobj' should always be opened with mode
'rb' to avoid irritation about the file size.
R�iiN(RtcopyR�R(RxR9R�RR3R5RmR6R�RR�RJ(RiR�RxR/R=R>((s/sys/lib/python/tarfile.pyRD�s
R@c CsVg}|djo
|}nxx|D]p}|i�oMy&titii||i�d�Wntj
onX|i|�q$|i ||�q$W|i
d��|i�x�|D]�}tii||i�}y4|i||�|i
||�|i||�Wq�tj
o4}|idjo�qN|idd|�q�Xq�WdS(sMExtract 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().
i�cSst|i|i�S((R�Rj(R�R?((s/sys/lib/python/tarfile.pyRX�sistarfile: %sN(R3R�RStmakedirsRTRKRjtEnvironmentErrorRJtextracttsorttreversetchowntutimetchmodR\t
errorlevelRA(RiRTR�tdirectoriesR�te((s/sys/lib/python/tarfile.pyt
extractall�s2
&
R"cCsE|id�t|t�o
|}n|i|�}|i�otii||i�|_ ny&|i
|tii||i��Wn�tj
ok}|i
djo�qA|idjo|idd|i�qA|idd|i|if�nAtj
o4}|i
djo�qA|idd|�nXdS(s#Extract 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'.
RDiistarfile: %sstarfile: %s %rN(RR�RRR�RSRTRKR�t_link_targett_extract_memberRjRIRPtfilenameR3RAtstrerrorR\(RitmemberRTR�RR((s/sys/lib/python/tarfile.pyRJs$
&$cCs�|id�t|t�o
|}n|i|�}|i�o|i||�Sn�|itjo|i||�Snb|i�p
|i �oCt|i
t�otd��q�|i
|i|i|��SndSdS(s�Extract a member from the archive as a file object. `member' may be
a filename or a TarInfo object. If `member' is a regular file, a
file-like object is returned. If `member' is a link, a file-like
object is constructed from the link's target. If `member' is none of
the above, None is returned.
The file-like object is read-only and provides the following
methods: read(), readline(), readlines(), seek() and tell()
RDs'cannot extract (sym)link as file objectN(RR�RRR�t
fileobjectR�tSUPPORTED_TYPESR�R�RxRnR_textractfileRR�R3(RiRXR�((s/sys/lib/python/tarfile.pyR[$s
c
Csl|ddjo|d }ntii|�}tii|�}|o�tii|�o�t�}||_t|_d|_ |i
|_
|i|_|i|_|i
|_
|i|_y|i||i�Wq�q�n|i�p
|i�o$|idd|i|if�n|id|i�|i�o|i||�n�|i�o|i||�n�|i�o|i||�n�|i�p
|i�o|i||�nc|i�p
|i�o|i||�n5|itjo|i||�n|i||�|i ||�|i�p$|i!||�|i"||�ndS(s\Extract the TarInfo object tarinfo to a physical
file called targetpath.
i�RRi�is%s -> %sN(#RSRTRUtdirnametexistsRRjR�R�RLR�R�R�R�R�RUR�R�RAR�R�tmakefileR�tmakedirR�tmakefifoR�R�tmakedevtmakelinkRZtmakeunknownRMRORN(RiR�t
targetpatht upperdirstti((s/sys/lib/python/tarfile.pyRUKsL $
cCsGyti|�Wn/tj
o#}|itijo�qCnXdS(s,Make a directory called targetpath.
N(RStmkdirRIterrnotEEXIST(RiR�RdRR((s/sys/lib/python/tarfile.pyR_�s
cCsC|i|�}t|d�}t||�|i�|i�dS(s'Make a file called targetpath.
R�N(R[R�R5Rl(RiR�Rdtsourcettarget((s/sys/lib/python/tarfile.pyR^�s
cCs+|i||�|idd|i�dS(sYMake a file from a TarInfo object with an unknown type
at targetpath.
is9tarfile: Unknown file type %r, extracted as regular file.N(R^RAR�(RiR�Rd((s/sys/lib/python/tarfile.pyRc�scCs1ttd�oti|�n
td��dS(s'Make a fifo called targetpath.
tmkfifosfifo not supported by systemN(RfRSRlR\(RiR�Rd((s/sys/lib/python/tarfile.pyR`�scCs�ttd�pttd�otd��n|i}|i�o|tiO}n|tiO}ti||ti |i
|i��dS(s<Make a character or block device called targetpath.
tmknodRas'special devices not supported by systemN(RfRSR\RLR�R tS_IFBLKtS_IFCHRRmRaR�R�(RiR�RdRL((s/sys/lib/python/tarfile.pyRa�s"
cCs!|i}y8|i�oti||�nti|i|�Wn�tj
o�|i�o4tiitii |i
�|�}t|�}ny|i|i
|�|�Wqttfj
oS}tii|�}yti||�Wqtj
o}td��qXqXnXdS(s�Make 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.
slink could not be createdN(R�R�RStsymlinktlinkRTR
RTRKR\RjRURURRIRR4tcopy2R8(RiR�RdtlinkpathRR((s/sys/lib/python/tarfile.pyRb�s$
c
Cs�to�ttd�orti�djo_yti|i�d}WnOtj
oCyti|i �d}Wq�tj
oti
�}q�XnXyti|i�d}WnOtj
oCyti
|i�d}Wqtj
oti�}qXnXy_|i�o'ttd�oti|||�n(tidjoti|||�nWq�tj
o}td��q�XndS(s6Set owner of targetpath according to tarinfo.
tgeteuidiitlchowntos2emxscould not change ownerN(R2RfRSRtR4tgetgrnamR�RR5R�tgetgidtgetpwnamR�R3R�tgetuidR�RutsystplatformRMRIR\(RiR�RdtgtuRR((s/sys/lib/python/tarfile.pyRM�s,*cCsSttd�o?yti||i�WqOtj
o}td��qOXndS(sASet file permissions of targetpath according to tarinfo.
ROscould not change modeN(RfRSRORLRIR\(RiR�RdRR((s/sys/lib/python/tarfile.pyRO�s
cCs�ttd�pdSntidjo|i�odSny ti||i|if�Wn!tj
o}td��nXdS(sBSet modification time of targetpath according to tarinfo.
RNNtwin32s"could not change modification time( RfRSR{R|R�RNR�RIR\(RiR�RdRR((s/sys/lib/python/tarfile.pyRN�s cCs�|id�|idj o|i}d|_|Sn|ii|i�x�o�|iit�}|pdSny=t i
|�}|i|_|it7_|i|�}Wnztj
on}|i
o3|idd|i|f�|it7_qMq/|idjotd|��ndSnXPqMW|i�o |iid�o
t|_n|i�o|id7_n|ii|�|S(s�Return the next member of the archive as a TarInfo object, when
TarFile is opened for reading. Return None if there is no more
available.
trais 0x%X: empty or invalid block: %sis(empty, unreadable or compressed file: %sRRN(RRR3RxR�R�RrR7R�RR�tproc_memberR#tignore_zerosRAR]R�RjR�R�R�R�R�RJ(RitmR/R�RR((s/sys/lib/python/tarfile.pyRs@
cCsY|ittfjo|i|�Sn/|itjo|i|�Sn|i|�SdS(seChoose the right processing method for tarinfo depending
on its type and call it.
N(R�R�R�tproc_gnulongR�tproc_sparsetproc_builtin(RiR�((s/sys/lib/python/tarfile.pyR�Gs
cCsL|i|_|i�p|itjo|i|i|i�7_n|S(soProcess a builtin type member or an unknown member
which will be treated as a regular file.
(R�R�R�R�RZt_blockRm(RiR�((s/sys/lib/python/tarfile.pyR�RscCsd}|i}xG|djo9|iit�}||7}|it7_|t8}qW|iit�}ti|�}|i|_|it7_|i|�}|i|_|it jo|i
t�|_n'|it
jo|i
t�|_n|S(sSProcess the blocks that hold a GNU longname
or longlink member.
R"i(RmRxR7R�R�RR�R�R�R�RRRjR�R�(RiR�R/R�tblockR?RGR((s/sys/lib/python/tarfile.pyR�\s$
cCs�|i}t�}d}d}d}x�td�D]�}y6t|||d!�}t||d|d!�} Wntj
oPnX||jo|it|||��n|it|| |��|| 7}|| }|d7}q1Wt|d�}
t|dd!�}x|
d jo|i i
t�}|it7_d
}x�td�D]�}y6t|||d!�}t||d|d!�} Wntj
oPnX||jo|it|||��n|it|| |��|| 7}|| }|d7}qQWt|d�}
qW||jo|it|||��n||_
|i|_|i|i|i�7_||_|S(
s8Process a GNU sparse header plus extra headers.
i�liiii�i�i�iiii�(R/t_ringbufferRR R#RJt_holeR�RRxR7R�R�R�R�R�Rm(RiR�R/tspRztlastposR�RR�tnumbytest
isextendedtorigsize((s/sys/lib/python/tarfile.pyR�ysZ
cCs2t|t�\}}|o|d7}n|tS(s_Round up a byte count by BLOCKSIZE and return it,
e.g. _block(834) => 1024.
i(R6R�(RiR�R=R>((s/sys/lib/python/tarfile.pyR��scCs}|i�}|djot|�}n|i|�}x>t|ddd�D]&}|||ijo||SqOqOWdS(s}Find an archive member by name from bottom to top.
If tarinfo is given, it is used as the starting point.
ii�N(RR3RtindexRRj(RiRjR�R�tendR((s/sys/lib/python/tarfile.pyR�s
cCs:x*to"|i�}|djoPqqWt|_dS(sWRead through the entire archive file and look for readable
members.
N(RrRR3R�(RiR�((s/sys/lib/python/tarfile.pyR�s
cCs\|iotd|ii��n|dj o'|i|jotd|i��ndS(snCheck if TarFile is still open, and if the operation's mode
corresponds to TarFile's mode.
s%s is closedsbad operation for mode %rN(R{R8R�RYR3R�(RiRL((s/sys/lib/python/tarfile.pyR�s
cCs)|iot|i�Snt|�SdS(s$Provide an iterator object.
N(R�titerR�tTarIter(Ri((s/sys/lib/python/tarfile.pyR��s
cCs%||ijoti|IJndS(s.Write debugging output to sys.stderr.
N(tdebugR{tstderr(Ritleveltmsg((s/sys/lib/python/tarfile.pyRA�sNi((4RYRZR[R�RtRR�RPR(R�RYR3RkR�RgRRRRRlRRRR<RrR?RCRDRSRJR[RUR_R^RcR`RaRbRMRORNRR�R�R�R�R�RRRR�RA(((s/sys/lib/python/tarfile.pyR�shCG
d3)! ' : B
<
R�cBs)eZdZd�Zd�Zd�ZRS(sMIterator Class.
for tarinfo in TarFile(...):
suite...
cCs||_d|_dS(s$Construct a TarIter object.
iN(R�R�(RiR�((s/sys/lib/python/tarfile.pyRk�s cCs|S(s Return iterator object.
((Ri((s/sys/lib/python/tarfile.pyR��scCs�|iip0|ii�}|pt|i_t�qpn4y|ii|i}Wntj
o
t�nX|id7_|S(s�Return the next item using TarFile's next() method.
When all members have been read, set TarFile as _loaded.
i(R�R�RRrt
StopIterationR�R�t
IndexError(RiR�((s/sys/lib/python/tarfile.pyRs
(RYRZR[RkR�R(((s/sys/lib/python/tarfile.pyR��s t_sectioncBs eZdZd�Zd�ZRS(s$Base class for _data and _hole.
cCs||_||_dS(N(R�Rm(RiR�Rm((s/sys/lib/python/tarfile.pyRks cCs(|i|jo|i|ijnS(N(R�Rm(RiR�((s/sys/lib/python/tarfile.pyt__contains__s(RYRZR[RkR�(((s/sys/lib/python/tarfile.pyR�s R�cBseZdZd�ZRS(s/Represent a data section in a sparse file.
cCs ti|||�||_dS(N(R�RkR�(RiR�RmR�((s/sys/lib/python/tarfile.pyRk!s(RYRZR[Rk(((s/sys/lib/python/tarfile.pyR�sR�cBseZdZRS(s/Represent a hole section in a sparse file.
(RYRZR[(((s/sys/lib/python/tarfile.pyR�%sR�cBs eZdZd�Zd�ZRS(sMRingbuffer class which increases performance
over a regular list.
cCs
d|_dS(Ni(tidx(Ri((s/sys/lib/python/tarfile.pyRk.scCs�|i}xgto_||}||joPn|d7}|t|�jo
d}n||ijodSqqW||_|S(Nii(R�RrRR3(RiR�R�titem((s/sys/lib/python/tarfile.pyR�0s
(RYRZR[RkR�(((s/sys/lib/python/tarfile.pyR�*s it
TarFileCompatcBsteZdZded�Zd�Zd�Zd�Zd�Zd�Z d�Z
ddd �Zd
�Z
d�ZRS(
sRTarFile class compatible with standard module zipfile's
ZipFile class.
RDcCs�|tjoti||�|_n3|tjoti||�|_n
td��|dd!djoU|ii�}xC|D]7}|i|_ |i
|_ti
|i�d |_q�WndS(Nsunknown compression constantiiRDi(t TAR_PLAINRRR�tTAR_GZIPPEDRR#RRjRVRmt file_sizeR�tgmtimeR�t date_time(RiR�RLtcompressionR�R�((s/sys/lib/python/tarfile.pyRkHs
cCstd�|i��S(NcSs|iS((Rj(R�((s/sys/lib/python/tarfile.pyRXVs(tmaptinfolist(Ri((s/sys/lib/python/tarfile.pytnamelistUscCstd�|ii��S(NcSs
|itjS((R�R�(R�((s/sys/lib/python/tarfile.pyRXXs(tfilterR�R(Ri((s/sys/lib/python/tarfile.pyR�Ws cCs|ii�dS(N(R�R?(Ri((s/sys/lib/python/tarfile.pytprintdirZscCsdS(N((Ri((s/sys/lib/python/tarfile.pyttestzip\scCs|ii|�S(N(R�R(RiRj((s/sys/lib/python/tarfile.pytgetinfo^scCs"|ii|ii|��i�S(N(R�R[RR7(RiRj((s/sys/lib/python/tarfile.pyR7`scCs|ii||�dS(N(R�RC(RiRVR7t
compress_type((s/sys/lib/python/tarfile.pyR9bsc Cs�yddkl}Wn#tj
oddkl}nXddk}|i|_|i|_|i|i �|_
|ii|||��dS(Ni�(tStringIO(
t cStringIOR�R}tcalendarRVRjR�RmttimegmR�R�R�RD(RitzinfotbytesR�R�((s/sys/lib/python/tarfile.pytwritestrdscCs|ii�dS(N(R�Rl(Ri((s/sys/lib/python/tarfile.pyRlnsN(RYRZR[R�RkR�R�R�R�R�R7R3R9R�Rl(((s/sys/lib/python/tarfile.pyR�Ds
cCs<yt|�}|i�tSWntj
otSnXdS(sfReturn True if name points to a tar archive that we
are able to handle, else return False.
N(RgRlRrRRt(RjRG((s/sys/lib/python/tarfile.pyRus
(cR[t__version__tversiont
__author__t__date__t __cvsid__t__credits__R{RSR4R RhR�R$RGR|R}R4R2R3t__all__RR�RR�R�R�R�R�R�R�tAREGTYPER�R�R�R�R�R�tCONTTYPER�R�R�RZR�tS_IFLNKtS_IFREGRntS_IFDIRRotS_IFIFOtTSUIDtTSGIDtTSVTXtTUREADtTUWRITEtTUEXECtTGREADtTGWRITEtTGEXECtTOREADtTOWRITEtTOEXECRR RtR)R2R5RIRQRWRURTt ExceptionRR\R]R^R_R`RntobjectRuR�R�R�RRR�R�R�R�R?R�R�R�R�RRg(((s/sys/lib/python/tarfile.pys<module>s�
�BL����% 1
|