ó
è¾bc           @   s˜   d  Z  d d l Z d d l Z d d l Z e j d k rH d d l Z n  d d g Z d e f d „  ƒ  YZ d d	 d „  ƒ  YZ	 e
 d k r” e	 ƒ  GHn  d S(
   s-   An object-oriented interface to .netrc files.iÿÿÿÿNt   posixt   netrct   NetrcParseErrorc           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s5   Exception raised on syntax errors in the .netrc file.c         C   s/   | |  _  | |  _ | |  _ t j |  | ƒ d  S(   N(   t   filenamet   linenot   msgt	   Exceptiont   __init__(   t   selfR   R   R   (    (    s   /usr/lib/python2.7/netrc.pyR      s    			c         C   s   d |  j  |  j |  j f S(   Ns   %s (%s, line %s)(   R   R   R   (   R   (    (    s   /usr/lib/python2.7/netrc.pyt   __str__   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R	   (    (    (    s   /usr/lib/python2.7/netrc.pyR      s   c           B   s/   e  Z d d  „ Z d „  Z d „  Z d „  Z RS(   c         C   s™   | d  k } | d  k r[ y  t j j t j d d ƒ } Wq[ t k
 rW t d ƒ ‚ q[ Xn  i  |  _ i  |  _ t	 | ƒ  } |  j
 | | | ƒ Wd  QXd  S(   Nt   HOMEs   .netrcs'   Could not find .netrc: $HOME is not set(   R   t   ost   patht   joint   environt   KeyErrort   IOErrort   hostst   macrost   opent   _parse(   R   t   filet   default_netrct   fp(    (    s   /usr/lib/python2.7/netrc.pyR      s     		c         C   s  t  j  | ƒ } | j d 7_ | j j d d ƒ | _ x`| j ƒ  } } | sS Pn| d d k rš t | ƒ d } | j j | d ƒ | j j ƒ  q9 nÇ | d k rµ | j ƒ  } n¬ | d k rÊ d } n— | d k rH| j ƒ  } g  |  j	 | <d	 | _
 xG | j j ƒ  }	 |	 s|	 d
 k r*d | _
 Pn  |  j	 | j |	 ƒ qû Wq9 n t d | | | j ƒ ‚ d }
 d  } } i  |  j | <x| j ƒ  } | j d ƒ s´| d d d d h k r| rá|
 | | f |  j | <| j | ƒ Pq‘t d | | t | ƒ f | | j ƒ ‚ q| d k s$| d k r3| j ƒ  }
 q| d k rN| j ƒ  } q| d k rxt j d k ri| rit j | j ƒ  ƒ } | j t j ƒ  k r7y t j | j ƒ d } Wn t k
 rÓd | j } n Xy t j t j ƒ  ƒ d } Wn! t k
 rd t j ƒ  } n Xt d | | f | | j ƒ ‚ n  | j t j t j B@rit d | | j ƒ ‚ qin  | j ƒ  } qt d | | | j ƒ ‚ qWq9 Wd  S(   Ns    !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~t   #t    i    i   t   machinet   defaultt   macdefs    	s   
s    	
s   bad toplevel token %rs&   malformed %s entry %s terminated by %st   logint   usert   accountt   passwordR    s   uid %ss9   ~/.netrc file owner (%s) does not match current user (%s)sY   ~/.netrc access too permissive: access permissions must restrict access to only the owners   bad follower token %r(    t   shlext	   wordcharst
   commenterst   replacet	   get_tokent   lent   instreamt   seekt   readlineR   t
   whitespacet   appendR   R   R   R   t
   startswitht
   push_tokent   reprR   t   namet   fstatt   filenot   st_uidt   getuidt   pwdt   getpwuidR   t   st_modet   statt   S_IRWXGt   S_IRWXO(   R   R   R   R   t   lexert   toplevelt   ttt   post	   entrynamet   lineR!   R#   R$   t   propt   fownerR"   (    (    s   /usr/lib/python2.7/netrc.pyR   %   sŽ    			


c         C   s<   | |  j  k r |  j  | Sd |  j  k r4 |  j  d Sd Sd S(   s8   Return a (user, account, password) tuple for given host.R   N(   R   R   (   R   t   host(    (    s   /usr/lib/python2.7/netrc.pyt   authenticatorsw   s
    c         C   sâ   d } xy |  j  j ƒ  D]h } |  j  | } | d j d | d | ƒ 7} | d rh | d j d | ƒ 7} n  | d j d | ƒ 7} q WxY |  j j ƒ  D]H } | d j d	 | ƒ 7} x |  j | D] } | | 7} q¼ W| d
 7} q’ W| S(   s3   Dump the class data in the format of a .netrc file.R   s!   machine {host}
	login {attrs[0]}
RF   t   attrsi   s   	account {attrs[1]}
s   	password {attrs[2]}
s   macdef {macro}
t   macros   
(   R   t   keyst   formatR   (   R   t   repRF   RH   RI   RC   (    (    s   /usr/lib/python2.7/netrc.pyt   __repr__€   s    
N(   R
   R   R   R   R   RG   RM   (    (    (    s   /usr/lib/python2.7/netrc.pyR      s   	R		t   __main__(    (   R   R   R;   R%   R3   R8   t   __all__R   R   R   R
   (    (    (    s   /usr/lib/python2.7/netrc.pyt   <module>   s   $x