ó
ñ±$Nc           @   s“   d  Z  e e  ƒ Z d Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 e
 d	 k r e d
 ƒ Z d j e j ƒ  ƒ GHn  d S(   s   !<arch>
i<   s   `
t   ArErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR       s   t   ArFilec           B   s}   e  Z d  Z d d d d „ Z d „  Z d „  Z d „  Z e e ƒ Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s   Representation of an ar archive, see man 1 ar.
    
    The interface of this class tries to mimick that of the TarFile module in
    the standard library.
    
    ArFile objects have the following (read-only) properties:
        - members       same as getmembers()
    t   rc         C   sA   g  |  _  i  |  _ | |  _ | |  _ | d k r= |  j ƒ  n  d S(   s„    Build an ar file representation starting from either a filename or
        an existing file object. The only supported mode is 'r' R   N(   t   _ArFile__memberst   _ArFile__members_dictt   _ArFile__fnamet   _ArFile__fileobjt   _ArFile__index_archive(   t   selft   filenamet   modet   fileobj(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   __init__%   s    				c         C   s  |  j  r t |  j  d ƒ } n |  j r3 |  j } n	 t d ‚ | j t ƒ t k r] t d ‚ n  x‰ t rè t j	 | |  j  ƒ } | s… Pn  |  j
 j | ƒ | |  j | j <| j d d k rÎ | j | j d ƒ q` | j | j d d ƒ q` W|  j  rÿ | j ƒ  n  d  S(   Nt   rbs   Unable to open valid files   Unable to find global headeri   i    i   (   R   t   openR   R    t   readt   GLOBAL_HEADER_LENGTHt   GLOBAL_HEADERt   Truet   ArMembert	   from_fileR   t   appendR   t   namet   sizet   seekt   close(   R
   t   fpt	   newmember(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   __index_archive2   s$    					c         C   s   |  j  | S(   s   Return the (last occurrence of a) member in the archive whose name
        is 'name'. Raise KeyError if no member matches the given name.

        Note that in case of name collisions the only way to retrieve all
        members matching a given name is to use getmembers. (   R   (   R
   R   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt	   getmemberK   s    c         C   s   |  j  S(   sø    Return a list of all members contained in the archive.

        The list has the same order of members in the archive and can contain
        duplicate members (i.e. members with the same name) if they are
        duplicate in the archive itself. (   R   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt
   getmembersT   s    c         C   s   t  d „  |  j ƒ S(   s3    Return a list of all member names in the archive. c         S   s   |  j  S(   N(   R   (   t   f(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   <lambda>b   s    (   t   mapR   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   getnames_   s    c           C   s
   t  ‚ d S(   s    Not (yet) implemented. N(   t   NotImpelementedError(    (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt
   extractalld   s    c         C   s
   t  ‚ d S(   s    Not (yet) implemented. N(   R%   (   R
   t   membert   path(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   extracti   s    c         C   sT   xM |  j  D]B } t | t ƒ r5 | j | j k r5 | S| | j k rH | Sd Sq
 Wd S(   s     Return a file object corresponding to the requested member. A member
        can be specified either as a string (its name) or as a ArMember
        instance. N(   R   t
   isinstanceR   R   t   None(   R
   R'   t   m(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   extractfilen   s    !c         C   s   t  |  j ƒ S(   s5    Iterate over the members of the present ar archive. (   t   iterR   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   __iter__}   s    c         C   s   |  j  | ƒ S(   s    Same as .getmember(name). (   R   (   R
   R   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   __getitem__‚   s    N(   R   R   t   __doc__R+   R   R	   R   R    t   propertyt   membersR$   R&   R)   R-   R/   R0   (    (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR      s   										R   c           B   sé   e  Z d  Z d „  Z d „  Z e e ƒ Z d d „ Z d d „ Z d d „ Z	 d d „ Z
 d „  Z d	 „  Z d
 „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   sÂ   Member of an ar archive.

    Implements most of a file object interface: read, readline, next,
    readlines, seek, tell, close.
    
    ArMember objects have the following (read-only) properties:
        - name      member name in an ar archive
        - mtime     modification time
        - owner     owner user
        - group     owner group
        - fmode     file permissions
        - size      size in bytes
        - fname     file namec         C   s^   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  S(   N(   R+   t   _ArMember__namet   _ArMember__mtimet   _ArMember__ownert   _ArMember__groupt   _ArMember__fmodet   _ArMember__sizet   _ArMember__fnamet   _ArMember__fpt   _ArMember__offsett   _ArMember__end(   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR   —   s    									c         C   s  |  j  t ƒ } | s d St | ƒ t k  r7 t d ‚ n  | d d !t k rV t d ‚ n  t ƒ  } | d d !j d ƒ d j ƒ  | _	 t
 | d d !ƒ | _ t
 | d d	 !ƒ | _ t
 | d	 d
 !ƒ | _ | d
 d !| _ t
 | d d !ƒ | _ | | _ |  j ƒ  | _ | j | j | _ | S(   sŒ   fp is an open File object positioned on a valid file header inside
        an ar archive. Return a new ArMember on success, None otherwise. s   Incorrect header lengthi:   i<   s   Incorrect file magici    i   t   /i   i"   i(   i0   N(   R   t   FILE_HEADER_LENGTHR+   t   lent   IOErrort
   FILE_MAGICR   t   splitt   stripR4   t   intR5   R6   R7   R8   R9   R:   t   tellR<   R=   (   R   t   fnamet   bufR!   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR   £   s$    	#	i    c         C   s±   |  j  d  k r: t |  j d ƒ |  _  |  j  j |  j ƒ n  |  j  j ƒ  } | d k rx | |  j | k rx |  j  j | ƒ S| |  j k s– | |  j k  rš d S|  j  j |  j | ƒ S(   NR   i    t    (	   R;   R+   R   R:   R   R<   RF   R=   R   (   R
   R   t   cur(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR   Ñ   s    c         C   s«   |  j  d  k r: t |  j d ƒ |  _  |  j  j |  j ƒ n  | d  k	 rx |  j  j | ƒ } |  j  j ƒ  |  j k rt d S| S|  j  j ƒ  } |  j  j ƒ  |  j k r£ d S| Sd  S(   NR   RI   (	   R;   R+   R   R:   R   R<   t   readlineRF   R=   (   R
   R   RH   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyRK   à   s    c         C   sz   |  j  d  k r: t |  j d ƒ |  _  |  j  j |  j ƒ n  d  } g  } x- t ru |  j ƒ  } | se Pn  | j | ƒ qI W| S(   NR   (	   R;   R+   R   R:   R   R<   R   RK   R   (   R
   t   sizehintRH   t   lines(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt	   readlinesò   s    	c         C   s  |  j  d  k r: t |  j d ƒ |  _  |  j  j |  j ƒ n  |  j  j ƒ  |  j k  rh |  j  j |  j ƒ n  | d k  r  | |  j  j ƒ  |  j k  r  t d | ‚ n  | d k rÂ |  j  j | d ƒ nR | d k rë |  j  j |  j | d ƒ n) | d k r|  j  j |  j | d ƒ n  d  S(   NR   i   s   Can't seek at %di   i    (	   R;   R+   R   R:   R   R<   RF   RA   R=   (   R
   t   offsett   whence(    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR     s    (c         C   sk   |  j  d  k r: t |  j d ƒ |  _  |  j  j |  j ƒ n  |  j  j ƒ  } | |  j k  r\ d S| |  j Sd  S(   NR   l    (   R;   R+   R   R:   R   R<   RF   (   R
   RJ   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyRF     s    c         C   s#   |  j  d  k	 r |  j  j ƒ  n  d  S(   N(   R;   R+   R   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR     s    c         C   s
   |  j  ƒ  S(   N(   RK   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   next#  s    c            s   ‡  f d †  } t  | ƒ  ƒ S(   Nc          3   s   ˆ  j  ƒ  }  |  r |  Vn  d  S(   N(   RK   (   t   line(   R
   (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   nextline'  s    (   R.   (   R
   RS   (    (   R
   s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR/   &  s    c         C   s   |  j  S(   N(   R4   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   .  s    c         C   s   |  j  S(   N(   R5   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   /  s    c         C   s   |  j  S(   N(   R6   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   0  s    c         C   s   |  j  S(   N(   R7   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   1  s    c         C   s   |  j  S(   N(   R8   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   2  s    c         C   s   |  j  S(   N(   R9   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   3  s    c         C   s   |  j  S(   N(   R:   (   R
   (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR"   4  s    N(   R   R   R1   R   R   t   staticmethodR   R+   RK   RN   R   RF   R   RQ   R/   R2   R   t   mtimet   ownert   groupt   fmodeR   RG   (    (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyR   ˆ   s&   		)				t   __main__s   test.ars   
N(   R   R@   R   R?   RB   t	   ExceptionR    t   objectR   R   R   t   at   joinR$   (    (    (    s1   /usr/lib/python2.7/dist-packages/debian/arfile.pyt   <module>   s   m®