ó
â·sWc           @   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 rG| j ƒ  } g  |  j	 | <d	 | _
 xF | j j ƒ  }	 |	 s|	 d
 k r*d | _
 Pn  |  j	 | j |	 ƒ qû q9 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 r2| j ƒ  }
 q€| d k rM| j ƒ  } q€| d k rwt j d k rh| rht j | j ƒ  ƒ } | j t j ƒ  k r6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@rht d | | j ƒ ‚ qhn  | j ƒ  } q€t d | | | j ƒ ‚ q€q9 d  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 } x‰ |  j  j ƒ  D]x } |  j  | } | d | d t | d ƒ d } | d rr | d t | d ƒ } n  | d t | d	 ƒ d } q WxU |  j j ƒ  D]D } | d
 | d } x |  j | D] } | | } qÈ W| d } q¢ W| S(   s3   Dump the class data in the format of a .netrc file.R   s   machine s   
	login i    s   
i   s   account s
   	password i   s   macdef (   R   t   keysR2   R   (   R   t   repRF   t   attrst   macroRC   (    (    s   /usr/lib/python2.7/netrc.pyt   __repr__€   s    $
 N(   R
   R   R   R   R   RG   RL   (    (    (    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