m
fIc           @   s  d  Z  d Z d Z d Z d Z d Z d Z d k Z d k Z d k	 Z	 d k
 Z
 d k Z d k Z d k Z e i d j o e d	  n y d k Z d k Z Wn e j
 o e Z Z n Xd
 d d d g Z d Z d Z e 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# d Z$ d Z% d Z& d Z' d  Z( e e e e  e# e$ e% e! e" e& e' e( f Z) e e e% e( f Z* d! Z+ d" Z, d# Z- d$ Z. d% Z/ d& Z0 d' Z1 d( Z2 d Z3 d) Z4 d* Z5 d+ Z6 d, Z7 d- Z8 d. Z9 d/ Z: d0 Z; d1 Z< d2   Z= d3   Z> e d4  Z? e+ d5 f e, d6 f e- d7 f e. d8 f e/ d9 f e0 d: f f e4 d; f f e5 d< f f e6 e1 Bd= f e1 d  f e6 d> f f e7 d; f f e8 d< f f e9 e2 Bd= f e2 d  f e9 d> f f e: d; f f e; d< f f e< e3 Bd? f e3 d@ f e< d> f f f
 Z@ dA   ZA e iB dB j o dC   ZC n e iD iC ZC d eE f dD     YZF dE eF f dF     YZG dG eF f dH     YZH dI eF f dJ     YZI dK eF f dL     YZJ dM f  dN     YZK dO f  dP     YZL dQ eM f dR     YZN d eM f dS     YZO d
 eM f dT     YZP dU f  dV     YZQ dW f  dX     YZR dY eR f dZ     YZS d[ eR f d\     YZT d] eU f d^     YZV d_ ZW d. ZX d` f  da     YZY db   ZZ eP i[ Z[ d S(c   s,   Read from and write to tar format archives.
s   $Revision: 41341 $s   0.6.4s!   Lars Gustbel (lars@gustaebel.de)s5   $Date: 2005-10-28 08:00:51 +0200 (Fri, 28 Oct 2005) $s9   $Id: tarfile.py 41341 2005-10-28 06:00:51Z neal.norwitz $s3   Gustavo Niemeyer, Niels Gustbel, Richard Townsend.Nt   macs'   tarfile does not work for platform==mact   TarFilet   TarInfot
   is_tarfilet   TarErrort    i   i   t   ustart   00id   i   l    t   0t   1t   2t   3t   4t   5t   6t   7t   Lt   Kt   Si   i   i `  i @  i    i   i   i   i   i   i@   i    i   i   i   i   i   c         C   s   |  i t  S(   s@   Convert a null-terminated string buffer to a python string.
    N(   t   st   rstript   NUL(   R   (    (    t$   /mit/python/lib/python2.4/tarfile.pyt   nts   s     c         C   sT   d } x" |  d  D] } | t |  7} q Wx" |  d D] } | t |  7} q6 W| S(   s   Calculate the checksum for a member's header. It's a simple addition
       of all bytes, treating the chksum field as if filled with spaces.
       buf is a 512 byte long string buffer which holds the header.
    i   i   i   N(   t   chkt   buft   ct   ord(   R   R   R   (    (    R   t   calc_chksum   s         c         C   s   | d j o d Sn | d j o t i |  |  d Sn d d } t | |  \ } } xP t
 |  D]B } |  i |  } t |  | j  o t d  n | i |  qf W| d j o@ |  i |  } t |  | j  o t d  n | i |  n d S(   sj   Copy length bytes from fileobj src to fileobj dst.
       If length is None, copy the entire content.
    i    Ni   i   s   end of file reached(   t   lengtht   Nonet   shutilt   copyfileobjt   srct   dstt   BUFSIZEt   divmodt   blockst	   remaindert   xranget   bt   readR   t   lent   IOErrort   write(   R!   R"   R   R#   R%   R   R(   R&   (    (    R   R       s(     
 t   lt   -R(   t   dR   t   pt   rt   wR   t   xt   tt   Tc         C   sk   g  } xU t D]M } xD | D]/ \ } } |  | @| j o | i |  Pq q W| i d  q Wd i |  S(   sc   Convert a file's mode to a string of the form
       -rwxrwxrwx.
       Used by TarFile.list()
    R.   t    N(   t   permt   filemode_tablet   tablet   bitt   chart   modet   appendt   join(   R<   R7   R;   R9   R:   (    (    R   t   filemode   s       	t   /c         C   s   t  i i |   i t  i d  S(   NR@   (   t   ost   patht   normpatht   replacet   sep(   RB   (    (    R   t   <lambda>   s    c           B   s   t  Z d  Z RS(   s   Base exception.(   t   __name__t
   __module__t   __doc__(    (    (    R   R      s   t   ExtractErrorc           B   s   t  Z d  Z RS(   s%   General exception for extract errors.(   RG   RH   RI   (    (    (    R   RJ      s   t	   ReadErrorc           B   s   t  Z d  Z RS(   s%   Exception for unreadble tar archives.(   RG   RH   RI   (    (    (    R   RK      s   t   CompressionErrorc           B   s   t  Z d  Z RS(   s.   Exception for unavailable compression methods.(   RG   RH   RI   (    (    (    R   RL      s   t   StreamErrorc           B   s   t  Z d  Z RS(   s=   Exception for unsupported operations on stream-like TarFiles.(   RG   RH   RI   (    (    (    R   RM      s   t   _LowLevelFilec           B   s2   t  Z d  Z d   Z d   Z d   Z d   Z RS(   s   Low-level file object. Supports reading and writing.
       It is used instead of a regular file object for streaming
       access.
    c         C   sj   h  d t  i <d t  i t  i Bt  i B<| } t t  d  o | t  i O} n t  i | |  |  _ d  S(   NR1   R2   t   O_BINARY(   RA   t   O_RDONLYt   O_WRONLYt   O_CREATt   O_TRUNCR<   t   hasattrRO   t   opent   namet   selft   fd(   RW   RV   R<   (    (    R   t   __init__   s    0c         C   s   t  i |  i  d  S(   N(   RA   t   closeRW   RX   (   RW   (    (    R   RZ     s    c         C   s   t  i |  i |  S(   N(   RA   R)   RW   RX   t   size(   RW   R[   (    (    R   R)     s    c         C   s   t  i |  i |  d  S(   N(   RA   R,   RW   RX   R   (   RW   R   (    (    R   R,     s    (   RG   RH   RI   RY   RZ   R)   R,   (    (    (    R   RN      s
    				t   _Streamc           B   s   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	 d
  Z e d  Z d   Z d   Z RS(   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         C   sw  t  |  _ | d j o t | |  } t |  _ n | p d |  _ | |  _ | |  _	 | |  _ | |  _
 d |  _ d |  _ t |  _ | d j op y d k } Wn t j
 o t d  n X| |  _ | i d  |  _ | d j o |  i   q |  i   n | d j oh y d k } Wn t j
 o t d  n X| d j o d |  _ | i   |  _ qs| i   |  _ n d S(	   s$   Construct a _Stream object.
        R6   l    t   gzNs   zlib module is not availableR1   t   bz2s   bz2 module is not available(   t   TrueRW   t   _extfileobjt   fileobjR   RN   RV   R<   t   Falset   typet   bufsizeR   t   post   closedt   zlibt   ImportErrorRL   t   crc32t   crct   _init_read_gzt   _init_write_gzR^   t   dbuft   BZ2Decompressort   cmpt   BZ2Compressor(   RW   RV   R<   Rc   Ra   Rd   Rg   R^   (    (    R   RY     s@     										c         C   s   |  i p |  i   n d  S(   N(   RW   Rf   RZ   (   RW   (    (    R   t   __del__=  s    
c         C   s   |  i i d |  i i |  i i |  i i d  |  _ t i d t	 t
 i
     } |  i d |  |  i i d  o |  i d  |  _ n |  i |  i t  d S(   s6   Initialize for writing with gzip compression.
        i	   i    s   <Ls   %ss   .gziN(   RW   Rg   t   compressobjt   DEFLATEDt	   MAX_WBITSt   DEF_MEM_LEVELRo   t   structt   packt   longt   timet	   timestampt   _Stream__writeRV   t   endswithR   (   RW   Rz   (    (    R   Rl   A  s     
	c         C   s{   |  i d j o |  i i | |  i  |  _ n |  i t |  7_ |  i d j o |  i i	 |  } n |  i
 |  d S(   s&   Write string s to the stream.
        R]   t   tarN(   RW   Rc   Rg   Ri   R   Rj   Re   R*   Ro   t   compressR{   (   RW   R   (    (    R   R,   N  s     c         C   sa   |  i | 7_ xK t |  i  |  i j o1 |  i i |  i |  i   |  i |  i |  _ q Wd S(   s]   Write string s to the stream if a whole new block
           is ready to be written.
        N(   RW   R   R   R*   Rd   Ra   R,   (   RW   R   (    (    R   t   __writeX  s      c         C   s  |  i o d Sn |  i d j o, |  i d j o |  i |  i i   7_ n |  i d j o |  i ov |  i i |  i  d |  _ |  i d j oF |  i i t	 i
 d |  i   |  i i t	 i
 d |  i d @  q n |  i p |  i i   n t |  _ d S(	   s[   Close the _Stream object. No operation should be
           done on it afterwards.
        NR2   R}   R6   R]   s   <ls   <Ll    (   RW   Rf   R<   Rc   R   Ro   t   flushRa   R,   Rv   Rw   Rj   Re   R`   RZ   R_   (   RW   (    (    R   RZ   a  s     
 	+
c         C   s  |  i i |  i i  |  _ d |  _ |  i d  d j o t d  n |  i d  d j o t d  n t	 |  i d   } |  i d  | d	 @o= t	 |  i d   d
 t	 |  i d   } |  i |  n | d @o< x9 t o- |  i d  } | p | t j o Pq q Wn | d @o< x9 t o- |  i d  } | p | t j o Pq*q*Wn | d @o |  i d  n d S(   s:   Initialize for reading a gzip compressed fileobj.
        R6   i   s   s   not a gzip filei   s   s   unsupported compression methodi   i   i   i   i   N(   RW   Rg   t   decompressobjRt   Ro   Rm   t   _Stream__readRK   RL   R   t   flagt   xlenR)   R_   R   R   (   RW   R   R   R   (    (    R   Rk   v  s4     	,  c         C   s   |  i S(   s3   Return the stream's file pointer position.
        N(   RW   Re   (   RW   (    (    R   t   tell  s     i    c         C   s{   | |  i  d j oW t | |  i  |  i  \ } } x$ t |  D] } |  i |  i  q@ W|  i |  n
 t	 d  |  i  S(   sX   Set the stream's file pointer to pos. Negative seeking
           is forbidden.
        i    s    seeking backwards is not allowedN(
   Re   RW   R$   Rd   R%   R&   R'   t   iR)   RM   (   RW   Re   R%   R   R&   (    (    R   t   seek  s      	c         C   s   | d j oS g  } x7 t o/ |  i |  i  } | p Pn | i |  q Wd i	 |  } n |  i |  } |  i
 t |  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.
        R6   N(   R[   R   R4   R_   RW   t   _readRd   R   R=   R>   Re   R*   (   RW   R[   R4   R   (    (    R   R)     s      c         C   s   |  i d j o |  i |  Sn t |  i  } |  i g } x_ | | j  oQ |  i |  i  } | p Pn |  i
 i |  } | i |  | t |  7} q? Wd i |  } | | |  _ | |  S(   s+   Return size bytes from the stream.
        R}   R6   N(   RW   Rc   R   R[   R*   Rm   R   R4   Rd   R   Ro   t
   decompressR=   R>   (   RW   R[   R   R4   R   (    (    R   R     s       c         C   s   t  |  i  } |  i g } xP | | j  oB |  i i |  i  } | p Pn | i	 |  | t  |  7} q Wd i
 |  } | | |  _ | |  S(   ss   Return size bytes from stream. If internal buffer is empty,
           read another block from the stream.
        R6   N(   R*   RW   R   R   R4   R[   Ra   R)   Rd   R=   R>   (   RW   R[   R   R4   R   (    (    R   t   __read  s      (   RG   RH   RI   RY   Rq   Rl   R,   R{   RZ   Rk   R   R   R   R)   R   R   (    (    (    R   R\   
  s   	 	(			
						t   ExFileObjectc           B   st   t  Z d  Z d   Z d   Z d d  Z d   Z e d  Z e d  Z	 d   Z
 d	   Z d
 d  Z d   Z RS(   s   File-like object for reading an archive member.
       Is returned by TarFile.extractfile(). Support for
       sparse files included.
    c         C   s   | i |  _ | i |  _ d |  _ t |  _ | i |  _	 | i
 |  _
 d |  _ d |  _ | i   o | i |  _ |  i |  _ n |  i |  _ d  S(   NR1   l    R6   (   t   tarfileRa   RW   t   tarinfoRV   R<   Rb   Rf   t   offset_datat   offsetR[   Re   t
   linebuffert   issparset   sparset   _readsparseR)   t   _readnormal(   RW   R   R   (    (    R   RY     s    				c         C   s   |  i i |  S(   s"   Overloadable read method.
        N(   RW   Ra   R)   R[   (   RW   R[   (    (    R   R     s     ic         C   sI  | d j  o t i } n |  i i d  } | d j o t | |  } n | t |  i  8} xt | d j  of | d j oY |  i	 t | d   } | p Pn |  i | 7_ | t |  8} |  i i d  } qb W| d j o |  i } d |  _ | Sn |  i |  } |  i | d |  _ x  | d d j o | d  } q!W| d S(	   s   Read a line with approx. size. If size is negative,
           read a whole line. readline() and read() must not
           be mixed up (!).
        i    s   
id   iR6   i   s   N(   R[   t   syst   maxintRW   R   t   findt   nlt   minR*   R)   R   R   (   RW   R[   R   R   R   (    (    R   t   readline  s2      		 c         C   s>   g  } x1 t o) |  i   } | p Pn | i |  q	 W| S(   s2   Return a list with all (following) lines.
        N(   t   resultR_   RW   R   t   lineR=   (   RW   R   R   (    (    R   t	   readlines  s       c         C   s   |  i o t d  n |  i i |  i |  i  |  i |  i } | d j o
 | } n t | |  } |  i | 7_ |  i |  S(   s*   Read operation for regular files.
        s   file is closedN(   RW   Rf   t
   ValueErrorRa   R   R   Re   R[   t	   bytesleftR   t   bytestoreadR   t   _ExFileObject__read(   RW   R[   R   R   (    (    R   R   "  s     

c         C   s   |  i o t d  n | d j o |  i |  i } n g  } xJ | d j o< |  i |  } | p Pn | t	 |  8} | i
 |  qA Wd i |  S(   s)   Read operation for sparse files.
        s   file is closedi    R6   N(   RW   Rf   R   R[   R   Re   t   datat   _readsparsesectionR   R*   R=   R>   (   RW   R[   R   R   (    (    R   R   0  s     
 c         C   s   |  i i |  i  } | d j o d Sn t | | i | i |  i  } t
 | t  oN | i |  i | i } |  i | 7_ |  i i |  i |  |  i |  Sn |  i | 7_ t | Sd S(   s0   Read a single section of a sparse file.
        R6   N(   RW   R   R   Re   t   sectionR   R   R[   R   t   toreadt
   isinstancet   _datat   realposRa   R   R   R   (   RW   R[   R   R   R   (    (    R   R   B  s      c         C   s   |  i S(   s*   Return the current file position.
        N(   RW   Re   (   RW   (    (    R   R   T  s     i    c         C   s   d |  _ | d j o" t t | d  |  i  |  _ n | d j oJ | d j  o t |  i | d  |  _ q t |  i | |  i  |  _ n | d j o) t t |  i | |  i  d  |  _ n d S(   s(   Seek to a position in the file.
        R6   i    i   i   N(   RW   R   t   whenceR   t   maxRe   R[   (   RW   Re   R   (    (    R   R   Y  s     	" c         C   s   t  |  _ d S(   s   Close the file object.
        N(   R_   RW   Rf   (   RW   (    (    R   RZ   g  s     (   RG   RH   RI   RY   R   R   R   R   R   R   R   R   R   RZ   (    (    (    R   R     s    			
		c           B   s   t  Z d  Z d d  Z d   Z d   Z e e  Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Informational 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.
    R6   c         C   s   | |  _  d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ t |  _	 d |  _
 d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d S(   sX   Construct a TarInfo object. name is the optional name
           of the member.
        i  i    R6   t   usert   groupN(   RV   RW   R<   t   uidt   gidR[   t   mtimet   chksumt   REGTYPERc   t   linknamet   unamet   gnamet   devmajort   devminort   prefixR   R   (   RW   RV   (    (    R   RY   x  s"     															c         C   s    d |  i i |  i t |   f S(   Ns   <%s %r at %#x>(   RW   t	   __class__RG   RV   t   id(   RW   (    (    R   t   __repr__  s    c         C   si  |    } t | d d ! | _ t | d d !d  | _ t | d d !d  | _ t | d d !d  | _ | d t	 d  j o t
 | d d !d  | _ nM d	 | _ x@ t d
  D]2 } | i d K_ | i t | d |  7_ q Wt
 | d d !d  | _ t | d d !d  | _ | d d !| _ t | d d ! | _ t | d d ! | _ t | d d ! | _ y6 t | d d !d  | _ t | d d !d  | _ Wn# t j
 o d | _ | _ n X| d d !| _ | i   o  | i i d  o t | _ n | i t j o. t t i i  t | i  | i   | _ n | i!   o | i d 7_ n | S(   sB   Construct a TarInfo object from a 512 byte string buffer.
        i    id   il   i   it   i|   i   i   l    i   i}   i   i   i   i  i	  i)  iI  iQ  iY  i  R@   N("   t   clsR   R   R   RV   t   intR<   R   R   t   chrRx   R[   t   rangeR   R   R   R   Rc   R   R   R   R   R   R   R   t   isregR|   t   DIRTYPEt   GNUTYPE_SPARSERC   RA   RB   R>   t   isdir(   R   R   R   R   (    (    R   t   frombuf  s@     		 ! .c   
      C   s  |  i t j o d |  i }	 nU |  i } d }	 x2 t d  D]$ } t | d @ |	 }	 | d L} q= Wt d  |	 }	 g  } x|  i d f d |  i	 d	 @d f d |  i
 d f d |  i d f |	 d
 f d |  i d
 f d |  i d f |  i d f t d f t d f |  i d f |  i d f d |  i d f d |  i d f |  i d f f D]5 \ } } t |  } | i | |  | | t  qLWd i |  } t |  } | d  d | | d } | t  t |  t 7} | |  _ | S(   s8   Return a tar header block as a 512 byte string.
        s   %011oR6   i   i   i   i   id   s   %07oi  i   s           i   i   i   i    i   i   s   %06o N(   s           i   (!   RW   R[   t   MAXSIZE_MEMBERR   R   R   R   t   partsRV   R<   R   R   R   Rc   R   t   MAGICt   VERSIONR   R   R   R   R   t   valuet	   fieldsizeR*   R-   R=   R   R>   R   R   R   t	   BLOCKSIZE(
   RW   R   R   R   R-   R   R   R   R   R[   (    (    R   t   tobuf  s*     	  !	c         C   s   |  i t j S(   N(   RW   Rc   t   REGULAR_TYPES(   RW   (    (    R   R     s    c         C   s
   |  i   S(   N(   RW   R   (   RW   (    (    R   t   isfile  s    c         C   s   |  i t j S(   N(   RW   Rc   R   (   RW   (    (    R   R     s    c         C   s   |  i t j S(   N(   RW   Rc   t   SYMTYPE(   RW   (    (    R   t   issym  s    c         C   s   |  i t j S(   N(   RW   Rc   t   LNKTYPE(   RW   (    (    R   t   islnk  s    c         C   s   |  i t j S(   N(   RW   Rc   t   CHRTYPE(   RW   (    (    R   t   ischr  s    c         C   s   |  i t j S(   N(   RW   Rc   t   BLKTYPE(   RW   (    (    R   t   isblk   s    c         C   s   |  i t j S(   N(   RW   Rc   t   FIFOTYPE(   RW   (    (    R   t   isfifo  s    c         C   s   |  i t j S(   N(   RW   Rc   R   (   RW   (    (    R   R     s    c         C   s   |  i t t t f j S(   N(   RW   Rc   R   R   R   (   RW   (    (    R   t   isdev  s    (   RG   RH   RI   RY   R   R   t   classmethodR   R   R   R   R   R   R   R   R   R   R   (    (    (    R   R   p  s     		0	/									c           B   s.  t  Z d  Z d Z e Z e Z d Z e Z e	 Z
 e d e d  Z e d e d d d  Z e e  Z d e d  Z e e  Z d e d d	  Z e e  Z d e d d
  Z e e  Z h  d d <d d <d d <Z d   Z d   Z d   Z d   Z e e e d  Z e d  Z e e d  Z e d  Z d 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) d(   Z* h  e+ e) <e, e) <e- e* <Z. d)   Z/ e d*  Z0 d+   Z1 e d,  Z2 d-   Z3 d.   Z4 d/   Z5 RS(0   s=   The TarFile Class provides an interface to tar archives.
    i    R1   c         C   s  | |  _  t |  d j p | d j o t d  n | |  _ h  d d <d d <d d	 <| |  _ | p" t |  i  |  i  } t |  _	 nZ |  i  d j o  t | d
  o | i  |  _  n t | d  o | i |  _ n t |  _	 | |  _ t |  _ g  |  _ t |  _ d |  _ h  |  _ |  i d j o d |  _ |  i   |  _ n |  i d j oy d |  _ xm t oa y |  i   } Wn$ t j
 o |  i i d  Pn X| d j o |  i i t d  PqgqgWn |  i d j o t |  _ n d S(   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.
        i   t   raws   mode must be 'r', 'a' or 'w'R1   t   rbt   as   r+bR2   t   wbRV   R<   l    i    t   awN(   RV   RW   R*   R<   R   t   _modeRa   t   fileRb   R`   R   RT   R_   Rf   t   memberst   _loadedR   t   inodest   firstmembert   nextR   RK   R   R   (   RW   RV   R<   Ra   R   (    (    R   RY     sJ     	 	( 									 i   i   c   	   	   C   s  | o | o t d  n d | j o} | i d d  \ } } | p d } | p d } | |  i j o t	 |  |  i |  } n t d |  | | | |  Sn*d | j o | i d d  \ } } | p d } | p d } | d j o t d	  n |  | | t | | | | |   } t | _ | Sn | d j oj xZ |  i D]O } t	 |  |  i |  } y | | d |  SWqLt t f j
 o
 qLqLXqLWt d
  n% | d j o |  i | | |  Sn t d  d S(   s
  Open a tar archive for reading, writing or appending. Return
           an appropriate TarFile class.

           mode:
           '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 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
        s   nothing to opent   :i   R1   R}   s   unknown compression type %rt   |t   rws   mode must be 'r' or 'w's%   file could not be opened successfullyR   s   undiscernible modeN(   RV   Ra   R   R<   t   splitR?   t   comptypeR   t	   OPEN_METHt   getattrt   funcRL   R\   Rd   R4   Rb   R`   RK   t   taropen(	   R   RV   R<   Ra   Rd   R   R   R?   R4   (    (    R   RU   b  sB     		
 c         C   s=   t  |  d j p | d j o t d  n |  | | |  S(   sC   Open uncompressed tar archive name for reading or writing.
        i   R   s   mode must be 'r', 'a' or 'w'N(   R*   R<   R   R   RV   Ra   (   R   RV   R<   Ra   (    (    R   R     s      i	   c   
      C   sZ  t  |  d j p | d j o t d  n y d k }	 |	 i Wn" t t f j
 o t d  n Xt i	 i
 |  \ } } t i	 i |  } | d j o
 d } n | d j o
 d	 } n | | } | d j o t | | d
  } n | d j o
 | } n y+ |  i | | |	 i | | | |   } Wn t j
 o t d  n Xt | _ | S(   sk   Open gzip compressed tar archive name for reading or writing.
           Appending is not allowed.
        i   R   s   mode must be 'r' or 'w'Ns   gzip module is not availables   .tgzs   .tars   .gzR6   R(   R1   s   not a gzip file(   R*   R<   R   t   gzipt   GzipFileRh   t   AttributeErrorRL   RA   RB   t   splitextRV   t   pret   extt   basenamet   tarnameRa   R   R   R   R   t   compresslevelR4   R+   RK   Rb   R`   (
   R   RV   R<   Ra   R   R   R   R4   R   R   (    (    R   t   gzopen  s4      	



	c   
      C   s,  t  |  d j p | d j o t d  n y d k }	 Wn t j
 o t d  n Xt i i |  \ } } t i i |  } | d j o
 d } n | d j o
 d	 } n | | } | d j	 o t d
  n y+ |  i | | |	 i | | d |  } Wn t j
 o t d  n Xt | _ | S(   sl   Open bzip2 compressed tar archive name for reading or writing.
           Appending is not allowed.
        i   R   s   mode must be 'r' or 'w'.Ns   bz2 module is not availables   .tbz2s   .tars   .bz2R6   s$   no support for external file objectsR   s   not a bzip2 file(   R*   R<   R   R^   Rh   RL   RA   RB   R   RV   R   R   R   R   Ra   R   R   R   t   BZ2FileR   R4   R+   RK   Rb   R`   (
   R   RV   R<   Ra   R   R   R   R4   R   R^   (    (    R   t   bz2open  s,      


+	R}   R   R]   R   R^   R   c         C   s   |  i o d Sn |  i d j op |  i i t t d  |  i t d 7_ t |  i t	  \ } } | d j o |  i i t t	 |  q n |  i p |  i i   n t |  _ d S(   sl   Close the TarFile. In write-mode, two finishing zero blocks are
           appended to the archive.
        NR   i   i    (   RW   Rf   R   Ra   R,   R   R   R   R$   t
   RECORDSIZER%   R&   R`   RZ   R_   (   RW   R%   R&   (    (    R   RZ     s     
 
c         C   s1   |  i |  } | d j o t d |  n | S(   s  Return 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.
        s   filename %r not foundN(   RW   t
   _getmemberRV   R   R   t   KeyError(   RW   RV   R   (    (    R   t	   getmember  s
     c         C   s)   |  i   |  i p |  i   n |  i S(   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.
        N(   RW   t   _checkR   t   _loadR   (   RW   (    (    R   t
   getmembers  s
     

c         C   s(   g  } |  i   D] } | | i q ~ 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().
        N(   t   _[1]RW   R  R   RV   (   RW   R  R   (    (    R   t   getnames'  s     c         C   s  |  i d  | d j	 o | i } n | d j o
 | } n t |  } t i i	 |  \ } } x# | d d !d j o | d } qe Wt   }
 | d j oA t t d  o |  i o t i |  } q t i |  } n t i | i    } d } | i }	 t i |	  oz | i | i f } |  i o7 | i d j o' | |  i j o t } |  i | } qAt } | d o | |  i | <qAn t i  |	  o) t! } | d d j o | d 7} qAn| t i" |	  o
 t# } nb t i$ |	  o t% } t i& |  } n9 t i' |	  o
 t( } n t i) |	  o
 t* } n d S| |
 _ |	 |
 _+ | i, |
 _- | i. |
 _/ t i |	  o | i0 |
 _1 n
 d |
 _1 | i2 |
 _3 | |
 _ | |
 _ t4 o7 y t4 i5 |
 i-  d |
 _6 Wqt7 j
 o qXn t8 o7 y t8 i9 |
 i/  d |
 _: Wq.t7 j
 o q.Xn | t( t* f j oR t t d	  o> t t d
  o. t i; | i<  |
 _= t i> | i<  |
 _? qn |
 S(   sO  Create 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   i    i   R@   t   lstatR6   il    t   majort   minorN(@   RW   R   Ra   R   RV   t   arcnameRC   RA   RB   t
   splitdrivet   drvR   R   RT   t   dereferenceR  t   statrest   statt   fstatt   filenoR   t   st_modet   stmdt   S_ISREGt   st_inot   st_devt   inodet   st_nlinkR   R   Rc   R   t   S_ISDIRR   t   S_ISFIFOR   t   S_ISLNKR   t   readlinkt   S_ISCHRR   t   S_ISBLKR   R<   t   st_uidR   t   st_gidR   t   st_sizeR[   t   st_mtimeR   t   pwdt   getpwuidR   R   t   grpt   getgrgidR   R  t   st_rdevR   R  R   (   RW   RV   R  Ra   R	  R  R   R  Rc   R  R   (    (    R   t
   gettarinfo-  s     
 		+


							 c         C   s  |  i   x |  D] } | o t | i  Gd | i p | i | i p | i	 f G| i
   p | i   o d d | i | i f Gn d | i Gd t i | i  d  Gn | i G| o< | i   o d G| i Gn | i   o d G| i Gq n Hq Wd	 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:%02di   s   ->s   link toN(   RW   R   R   t   verboseR?   R<   R   R   R   R   R   R   R   R   R[   Ry   t	   localtimeR   RV   R   R   R   (   RW   R&  R   (    (    R   t   list  s$     
 (c         C   s  |  i d  | d j o
 | } n |  i d j	 oD t i i |  t i i |  i  j o |  i d d |  d Sn | d j oc | oT | d j o
 d } n x: t i
 d  D]% } |  i | t i i | |   q Wn d Sn |  i d |  |  i | |  } | d j o |  i d d |  d Sn | i   o- t | d	  } |  i | |  | i   n | i   od |  i |  | oL xI t i
 |  D]4 } |  i t i i | |  t i i | |   qWqn |  i |  d S(
   sQ  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.
        R   i   s   tarfile: Skipped %rNt   .R6   i   s   tarfile: Unsupported type %rR   (   RW   R   R  R   RV   RA   RB   t   abspatht   _dbgt	   recursivet   listdirt   ft   addR>   R%  R   R   R   t   addfileRZ   R   (   RW   RV   R  R,  R.  R   (    (    R   R/    s>     
8
 ' :c         C   s  |  i d  t | i  | _ | i   o | i d 7_ n | i o t | i  | _ n | i t j o+ |  i	 o t
 d  q |  i d d  n t | i  t j oV |  i	 o t
 d t  q|  i | i t  | i t d  | _ |  i d d  n t | i  t j o |  i	 o | i t d  } x' | o | d	 d j o | d	  } q:W| i t |  } | d	  } | p t |  t j o t
 d
 t  n | | _ | | _ q|  i | i t  | i t d  | _ |  i d d  n |  i i | i    |  i t 7_ | d j	 ox t | |  i | i  t | i t  \ } } | d j o& |  i i t t |  | d 7} n |  i | t 7_ n |  i i  |  d S(   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   R@   s   file is too large (>= 8 GB)i   s)   tarfile: Created GNU tar largefile headers   linkname is too long (>%d)i   s+   tarfile: Created GNU tar extension LONGLINKis   name is too long (>%d)s+   tarfile: Created GNU tar extension LONGNAMEi    N(!   RW   R   RC   R   RV   R   R   R[   R   t   posixR   R+  R*   t   LENGTH_LINKt   _create_gnulongt   GNUTYPE_LONGLINKt   LENGTH_NAMEt   LENGTH_PREFIXR   t   GNUTYPE_LONGNAMERa   R,   R   R   R   R   R    R$   R%   R&   R   R   R=   (   RW   R   Ra   RV   R   R%   R&   (    (    R   R0    sT     



 
	R6   c         C   sE  |  i d  t | t  o
 | } n |  i |  } | i   o t i	 i
 | | i  | _ n y& |  i | t i	 i
 | | i   Wn t j
 ok } |  i d j o   qA| i d j o |  i d d | i  qA|  i d d | i | i f  nA t j
 o4 } |  i d j o   qA|  i d d |  n Xd S(   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'.
        R1   i    i   s   tarfile: %ss   tarfile: %s %rN(   RW   R   R   t   memberR   R   R   R   RA   RB   R>   R   t   _link_targett   _extract_memberRV   t   EnvironmentErrort   et
   errorlevelt   filenameR   R+  t   strerrorRJ   (   RW   R8  RB   R<  R   (    (    R   t   extract%  s&     
&$c         C   s   |  i d  t | t  o
 | } n |  i |  } | i   o |  i |  |  Sn | i	 t
 j o |  i |  |  Sn_ | i   p | i   o@ t |  i t  o t d  q |  i |  i | i |   Sn d Sd S(   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()
        R1   s'   cannot extract (sym)link as file objectN(   RW   R   R   R8  R   R   R   R   t
   fileobjectRc   t   SUPPORTED_TYPESR   R   Ra   R\   RM   t   extractfileR   R   R   (   RW   R8  R   (    (    R   RC  F  s     
c         C   sl  | d d j o | d  } n t i i |  } t i i |  } | o t i i |  o t   } | | _	 t
 | _ d | _ | i | _ | i | _ | i | _ | i | _ | i | _ y |  i | | i	  Wq q Xn | i   p | i   o$ |  i d d | i	 | i f  n |  i d | 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 | i t# j o |  i$ | |  n |  i | |  |  i% | |  | i   p$ |  i& | |  |  i' | |  n d S(   s\   Extract the TarInfo object tarinfo to a physical
           file called targetpath.
        iR@   i  i   s   %s -> %sN((   t
   targetpathRA   RB   RC   t   dirnamet	   upperdirst   existsR   t   tiRV   R   Rc   R<   R   R   R   R   R   R   RW   R:  R   R   R+  R   R   t   makefileR   t   makedirR   t   makefifoR   R   t   makedevt   makelinkRB  t   makeunknownt   chownt   chmodt   utime(   RW   R   RD  RH  RF  (    (    R   R:  m  sN     				$c         C   sG   y t  i |  Wn/ t j
 o# } | i t i j o   qC n Xd S(   s,   Make a directory called targetpath.
        N(   RA   t   mkdirRD  R;  R<  t   errnot   EEXIST(   RW   R   RD  R<  (    (    R   RJ    s     c         C   sC   |  i |  } t | d  } t | |  | i   | i   d S(   s'   Make a file called targetpath.
        R   N(	   RW   RC  R   t   sourceR   RD  t   targetR    RZ   (   RW   R   RD  RV  RU  (    (    R   RI    s     
c         C   s+   |  i | |  |  i d d | i  d S(   sY   Make a file from a TarInfo object with an unknown type
           at targetpath.
        i   s9   tarfile: Unknown file type %r, extracted as regular file.N(   RW   RI  R   RD  R+  Rc   (   RW   R   RD  (    (    R   RN    s     c         C   s.   t  t d  o t i |  n
 t d  d S(   s'   Make a fifo called targetpath.
        t   mkfifos   fifo not supported by systemN(   RT   RA   RW  RD  RJ   (   RW   R   RD  (    (    R   RK    s     c         C   s   t  t d  p t  t d  o t d  n | i } | i   o | t i O} n | t i O} t i	 | | t i | i | i   d S(   s<   Make a character or block device called targetpath.
        t   mknodRL  s'   special devices not supported by systemN(   RT   RA   RJ   R   R<   R   R  t   S_IFBLKt   S_IFCHRRX  RD  RL  R   R   (   RW   R   RD  R<   (    (    R   RL    s     "	c         C   s  | i } y8 | i   o t i | |  n t i | i |  Wn t	 j
 o | i   o4 t i
 i t i
 i | i  |  } t |  } n y |  i |  i |  |  Wqt t f j
 oP } t i
 i |  } y t i | |  Wqt j
 o } t d  qXqXn Xd S(   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.
        s   link could not be createdN(   R   R   t   linkpathR   RA   t   symlinkRD  t   linkR9  R   RB   R>   RE  RV   RC   RW   R:  R   R;  R   R<  R   t   copy2R+   (   RW   R   RD  R<  R[  (    (    R   RM    s&     		c         C   s  t  ot t d  oot i   d j o\y t i | i  d } WnO t	 j
 oC y t i
 | i  d } Wq t	 j
 o t i   } q Xn Xy t  i | i  d } WnO t	 j
 oC y t  i | i  d } Wqt	 j
 o t i   } qXn Xy_ | i   o' t t d  o t i | | |  n( t i d j o t i | | |  n Wqt j
 o } t d  qXn d S(   s6   Set owner of targetpath according to tarinfo.
        t   geteuidi    i   t   lchownt   os2emxs   could not change ownerN(   R   RT   RA   R_  R"  t   getgrnamR   R   t   gR   R#  R   t   getgidt   getpwnamR   t   uR!  R   t   getuidR   R`  RD  R   t   platformRO  R;  R<  RJ   (   RW   R   RD  R<  Rc  Rf  (    (    R   RO    s.     *c         C   sP   t  t d  o< y t i | | i  WqL t j
 o } t d  qL Xn d S(   sA   Set file permissions of targetpath according to tarinfo.
        RP  s   could not change modeN(	   RT   RA   RP  RD  R   R<   R;  R<  RJ   (   RW   R   RD  R<  (    (    R   RP    s     c         C   s   t  t d  p d Sn t i d j o | i   o d Sn y  t i | | i | i f  Wn t	 j
 o } t d  n Xd S(   sB   Set modification time of targetpath according to tarinfo.
        RQ  Nt   win32s"   could not change modification time(   RT   RA   R   Rh  R   R   RQ  RD  R   R;  R<  RJ   (   RW   R   RD  R<  (    (    R   RQ    s      c         C   s  |  i d  |  i d
 j	 o |  i } d
 |  _ | Sn |  i i |  i  x t o |  i i	 t
  } | p d
 Sn y t i |  } Wn t j
 o |  i oY | i t  t
 j o
 d } n d } |  i d d |  i | f  |  i t
 7_ qM q"|  i d j o t d  n d
 Sn XPqM W| i t |  j o |  i d d	 | i  n |  i | _ |  i t
 7_ | i |  i j o |  i | i |  |  Sn |  i | _ | i   p | i t j o |  i |  i | i  7_ n |  i  i! |  | 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.
        t   rat   emptyt   invalidi   s   0x%X: %s blocki    s$   empty, unreadable or compressed filei   s   tarfile: Bad Checksum %rN("   RW   R   R   R   t   mRa   R   R   R_   R)   R   R   R   R   R   R   t   ignore_zerost   countR   t   adjR+  RK   R   R   RV   Rc   t	   TYPE_METHR   R   RB  t   _blockR[   R   R=   (   RW   Rm  R   R   Rp  (    (    R   R   (  sJ     		 

	c         C   s   d } | i } xG | d j o9 |  i i t  } | | 7} |  i	 t 7_	 | t 8} q W|  i
   } | i	 | _	 | i t j o t |  | _ n$ | i t j o t |  | _ n | S(   sT   Evaluate the blocks that hold a GNU longname
           or longlink member.
        R6   i    N(   R   R   R[   Ro  RW   Ra   R)   R   t   blockR   R   Rc   R7  R   RV   R4  R   (   RW   R   Ro  R   R   Rs  (    (    R   t   proc_gnulongw  s      	 
c         C   s  | i   } t   } d } d } d } x t d  D] }	 y< t
 | | | d !d  } t
 | | d | d !d  } Wn t j
 o Pn X| | j o | i t | | |   n | i t | | |   | | 7} | | } | d 7} q4 Wt | d  }
 t
 | d d	 !d  } x|
 d
 j o|  i i t  } |  i t 7_ d } x t d  D] }	 y< t
 | | | d !d  } t
 | | d | d !d  } Wn t j
 o Pn X| | j o | i t | | |   n | i t | | |   | | 7} | | } | d 7} q]Wt | d  }
 qW| | j  o | i t | | |   n | | _ |  i | _ |  i |  i | i  7_ | | _ |  i i |  | S(   s8   Analyze a GNU sparse header plus extra headers.
        i  l    i   i   i   i   i  i  i  i   i    i   i  N(   R   R   R   t   _ringbuffert   spRe   t   lastposR   R'   R   R   R   t   numbytesR   R=   t   _holeR   R   t
   isextendedt   origsizeRW   Ra   R)   R   R   R   Rr  R[   R   (   RW   R   R{  R   Rx  Rw  Rv  Re   R   R   Rz  R   (    (    R   t   proc_sparse  s`     	 "

  "

		c         C   s2   t  | t  \ } } | o | d 7} n | t S(   s_   Round up a byte count by BLOCKSIZE and return it,
           e.g. _block(834) => 1024.
        i   N(   R$   Ro  R   R%   R&   (   RW   Ro  R%   R&   (    (    R   Rr    s
     c         C   s}   |  i   } | d j o t |  } n | i |  } x> t | d d d  D]& } | | | i
 j o | | SqO qO Wd S(   s}   Find an archive member by name from bottom to top.
           If tarinfo is given, it is used as the starting point.
        i   iN(   RW   R  R   R   R   R*   t   endt   indexR'   R   RV   (   RW   RV   R   R}  R   R   (    (    R   R     s      c         C   s:   x* t  o" |  i   } | d j o Pq q Wt  |  _ d S(   sW   Read through the entire archive file and look for readable
           members.
        N(   R_   RW   R   R   R   R   (   RW   R   (    (    R   R     s      
c         C   sV   |  i o t d |  i i  n | d j	 o$ |  i | j o t d |  i  n d S(   sn   Check if TarFile is still open, and if the operation's mode
           corresponds to TarFile's mode.
        s   %s is closeds   bad operation for mode %rN(   RW   Rf   R+   R   RG   R<   R   R   (   RW   R<   (    (    R   R     s
     
c         C   s)   |  i o t |  i  Sn t |   Sd S(   s$   Provide an iterator object.
        N(   RW   R   t   iterR   t   TarIter(   RW   (    (    R   t   __iter__   s     
c         C   s   | t 7} t   } d | _  | | _ d | _ t |  | _ |  i	 i
 | i    |  i t 7_ |  i	 i
 |  t | i t  \ } } | d j o& |  i	 i
 t t |  | d 7} n |  i | t 7_ d S(   s   Write a GNU longname/longlink member to the TarFile.
           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    i   N(   RV   R   R   R   Rc   R<   R*   R[   RW   Ra   R,   R   R   R   R$   R%   R&   (   RW   RV   Rc   R%   R   R&   (    (    R   R3    s     
				c         C   s%   | |  i j o t i | IJn d S(   s.   Write debugging output to sys.stderr.
        N(   t   levelRW   t   debugR   t   stderrt   msg(   RW   R  R  (    (    R   R+  !  s     (6   RG   RH   RI   R  Rb   R
  Rn  R=  R1  R   RA  R   RY   RU   R   R   R   R   R   RZ   R   R  R  R%  R_   R(  R/  R0  R@  RC  R:  RJ  RI  RN  RK  RL  RM  RO  RP  RQ  R   Rt  R|  R7  R4  R   Rq  Rr  R   R   R   R  R3  R+  (    (    (    R   R   
  s`    CA$!				
	d4C!	'	:													O		=!				
			R  c           B   s)   t  Z d  Z d   Z d   Z d   Z RS(   sM   Iterator Class.

       for tarinfo in TarFile(...):
           suite...
    c         C   s   | |  _  d |  _ d S(   s$   Construct a TarIter object.
        i    N(   R   RW   R~  (   RW   R   (    (    R   RY   /  s     	c         C   s   |  S(   s    Return iterator object.
        N(   RW   (   RW   (    (    R   R  4  s     c         C   s   |  i i p0 |  i i   } | p t |  i _ t  qp n4 y |  i i |  i } Wn t	 j
 o t  n X|  i d 7_ | S(   s   Return the next item using TarFile's next() method.
           When all members have been read, set TarFile as _loaded.
        i   N(
   RW   R   R   R   R   R_   t   StopIterationR   R~  t
   IndexError(   RW   R   (    (    R   R   8  s     (   RG   RH   RI   RY   R  R   (    (    (    R   R  (  s    		t   _sectionc           B   s    t  Z d  Z d   Z d   Z RS(   s$   Base class for _data and _hole.
    c         C   s   | |  _  | |  _ d  S(   N(   R   RW   R[   (   RW   R   R[   (    (    R   RY   P  s    	c         C   s(   |  i | j o |  i |  i j  n S(   N(   RW   R   R[   (   RW   R   (    (    R   t   __contains__S  s    (   RG   RH   RI   RY   R  (    (    (    R   R  M  s    	R   c           B   s   t  Z d  Z d   Z RS(   s/   Represent a data section in a sparse file.
    c         C   s    t  i |  | |  | |  _ d  S(   N(   R  RY   RW   R   R[   R   (   RW   R   R[   R   (    (    R   RY   Y  s    (   RG   RH   RI   RY   (    (    (    R   R   V  s    Ry  c           B   s   t  Z d  Z RS(   s/   Represent a hole section in a sparse file.
    (   RG   RH   RI   (    (    (    R   Ry  ]  s   Ru  c           B   s    t  Z d  Z d   Z d   Z RS(   sM   Ringbuffer class which increases performance
       over a regular list.
    c         C   s   d |  _ d  S(   Ni    (   RW   t   idx(   RW   (    (    R   RY   f  s    c         C   s   |  i } xg t o_ |  | } | | j o Pn | d 7} | t |   j o
 d } n | |  i j o d  Sq q W| |  _ | S(   Ni   i    (   RW   R  R_   t   itemR   R*   R   (   RW   R   R  R  (    (    R   R   h  s    	 


	(   RG   RH   RI   RY   R   (    (    (    R   Ru  b  s    	i    t   TarFileCompatc           B   st   t  Z d  Z d e d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e e d	  Z d
   Z d   Z RS(   sR   TarFile class compatible with standard module zipfile's
       ZipFile class.
    R1   c         C   s   | t j o t i | |  |  _ n0 | t j o t i	 | |  |  _ n
 t
 d  | d d !d j ok |  i i   } xY t t |   D]A } | | } | i | _ | i | _ t i | i  d  | _ q Wn d  S(   Ns   unknown compression constanti    i   R1   i   (   t   compressiont	   TAR_PLAINR   R   R   R<   RW   R   t   TAR_GZIPPEDR   R   R  R   R'   R*   R   Rm  RV   R>  R[   t	   file_sizeRy   t   gmtimeR   t	   date_time(   RW   R   R<   R  R   Rm  R   (    (    R   RY     s    	 
c         C   s   t  d   |  i    S(   Nc         C   s   |  i S(   N(   Rm  RV   (   Rm  (    (    R   RF     s    (   t   mapRW   t   infolist(   RW   (    (    R   t   namelist  s    c         C   s   t  d   |  i i    S(   Nc         C   s   |  i t j S(   N(   Rm  Rc   R   (   Rm  (    (    R   RF     s    (   t   filterRW   R   R  (   RW   (    (    R   R    s    	c         C   s   |  i i   d  S(   N(   RW   R   R(  (   RW   (    (    R   t   printdir  s    c         C   s   d  S(   N(    (   RW   (    (    R   t   testzip  s    c         C   s   |  i i |  S(   N(   RW   R   R   RV   (   RW   RV   (    (    R   t   getinfo  s    c         C   s"   |  i i |  i i |   i   S(   N(   RW   R   RC  R   RV   R)   (   RW   RV   (    (    R   R)     s    c         C   s   |  i i | |  d  S(   N(   RW   R   R/  R>  R  (   RW   R>  R  t   compress_type(    (    R   R,     s    c         C   s_   d  k  } d  k } | i | _ | i | _ | i | i  | _	 |  i i | | i  |   d  S(   N(   t   StringIOt   calendart   zinfoR>  RV   R  R[   t   timegmR  R   RW   R   R0  t   bytes(   RW   R  R  R  R  (    (    R   t   writestr  s    		c         C   s   |  i i   d  S(   N(   RW   R   RZ   (   RW   (    (    R   RZ     s    (   RG   RH   RI   R  RY   R  R  R  R  R  R)   R   R,   R  RZ   (    (    (    R   R  |  s    							c         C   s<   y t  |   } | i   t SWn t j
 o t Sn Xd S(   sf   Return True if name points to a tar archive that we
       are able to handle, else return False.
    N(   RU   RV   R4   RZ   R_   R   Rb   (   RV   R4   (    (    R   R     s     
(\   RI   t   __version__t   versiont
   __author__t   __date__t	   __cvsid__t   __credits__R   RA   R   R  RS  Ry   Rv   Rh  Rh   R"  R   R   t   __all__R   R   R   R   R   R5  R2  R6  R   R   t   AREGTYPER   R   R   R   R   R   t   CONTTYPER7  R4  R   RB  R   t   S_IFLNKt   S_IFREGRY  t   S_IFDIRRZ  t   S_IFIFOt   TSUIDt   TSGIDt   TSVTXt   TUREADt   TUWRITEt   TUEXECt   TGREADt   TGWRITEt   TGEXECt   TOREADt   TOWRITEt   TOEXECR   R   R    R8   R?   RE   RC   RB   t	   ExceptionR   RJ   RK   RL   RM   RN   R\   t   objectR   R   R   R  R  R   Ry  R(  Ru  R  R  R  R   RU   (S   RL   Rv   R  R   RN   R   R\   R   R   R  R   RZ  R  R  R  RM   R   R  R  R  R   R   R    R  R  RY  R   R  R   R4  R   R   R   R  RK   R8   Ru  R   RA   R   R  R   R  Ry  RU   R7  R   R  R   RS  R   R  R  R  R  R   R2  R  R  R?   R  R   R  R  RJ   R6  R  R   R  R   R   R  R   RB  R5  R  R"  R  R  RC   R  Ry   R   (    (    R   t   ?   s   							
*			    "%	/	