ó
>ò†[c           @  sç   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z m Z e j d ƒ Z d	 „  Z e d
 „ Z d „  Z d „  Z d „  Z d S(   u   
Authenticate a user
iÿÿÿÿ(   t   unicode_literalsN(   t   urlparse(   t   input(   t   errors(   t
   get_configt   get_server_apit   store_tokent
   bool_inputu   binstar.loginc         K  s¹   y |  |   SWn¤ t  j k
 r´ } | j d ƒ r® t | j ƒ d k r® | j d d k r® t j d t j ƒ  ƒ t j d ƒ t j d ƒ t	 d ƒ r® t
 | d <|  |   Sn  ‚  n Xd S(	   ug   
    Authenticates using the given *authenticate*, retrying if the token needs
    to be replaced.
    u   fail_if_already_existsi   i  u1   It appears you are already logged in from host %suy   Logging in again will remove the previous token. (This could cause troubles with virtual machines with the same hostname)uP   Otherwise you can login again and specify a different hostname with "--hostname"u   Would you like to continueN(   R   t   BinstarErrort   gett   lent   argst   loggert   warningt   sockett   gethostnameR   t   False(   t   authenticatet   kwargst   err(    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyt   try_replace_token   s    7
c         C  s£  t  |  j |  j ƒ } t d |  j ƒ } d  } t |  d t j ƒ  ƒ } |  j pZ | j d ƒ } | j d d ƒ } d } | r˜ | d! k r˜ | d	 | 7} n  | d
 t	 j
 ƒ  | f 7} | j ƒ  | j ƒ  }	 |	 d k r.t | j d | d | d d j t j ƒ d | d | ƒ} | d  k rŸt j d ƒ ‚ qŸnqt |  d d  ƒ rL|  j }
 n t d ƒ }
 t |  d d  ƒ } xÃ t d ƒ D]µ } y‚ t j j d |
 ƒ | d  k r¸t	 j	 d t j ƒ } n  t | j d |
 d | d | d | d d j t j ƒ d | d | ƒ} PWqwt j k
 r+t j d ƒ d  } qwqwXqwW| d  k rŸt | ƒ } | j j d ƒ rcd } n	 | j } | j  | f } d d | d  } t j | ƒ ‚ n  | S("   Nt   siteu   hostnameu   default_siteu   urlu   https://api.anaconda.orgu   binstar_client:u   binstaru   anacondau   %s:u   %s@%su   kerberost   applicationt   application_urlt   created_withu    t   fail_if_already_existst   hostnameuU   Unable to authenticate via Kerberos. Try refreshing your authentication using `kinit`u   login_usernameu
   Username: u   login_passwordi   u   %s's t   streamt   usernamet   passwordu7   Invalid Username password combination, please try againu   api.anaconda.orgu   anaconda.orgu   Sorry. Please try again u'   (go to %s://%s/account/forgot_password u   to reset your password)(   u   binstaru   anaconda(!   R   t   tokenR   R   t   Nonet   getattrt   platformt   nodeR	   t   getpasst   getusert   check_servert   authentication_typeR   t   krb_authenticatet   joint   syst   argvR   R   t   login_usernameR   t   ranget   stderrt   writeR   t   UnauthorizedR   t   errorR   t   netloct
   startswitht   scheme(   R   R   t   bst   configR   R   R   t   urlt	   auth_namet	   auth_typeR   R   t   _t
   parsed_urlR1   t	   hostpartst   msg(    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyt   interactive_get_token,   sp    
						c         C  s*   t  |  ƒ } t | |  ƒ t j d ƒ d  S(   Nu   login successful(   R=   R   R   t   info(   R   R   (    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyt   interactive_login~   s    c         C  s   t  |  ƒ d  S(   N(   R?   (   R   (    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyt   main„   s    c         C  s€   |  j  d d d d t ƒ} | j d d t j ƒ  d d ƒ| j d d	 d
 d d ƒ| j d d	 d d d ƒ| j d t ƒ d  S(   Nu   logint   helpu   Authenticate a usert   descriptionu
   --hostnamet   defaultuQ   Specify the host name of this login, this should be unique (default: %(default)s)u
   --usernamet   destu   login_usernameuA   Specify your username. If this is not given, you will be promptedu
   --passwordu   login_passworduA   Specify your password. If this is not given, you will be promptedR@   (   t
   add_parsert   __doc__t   add_argumentR!   R"   t   set_defaultsR@   (   t
   subparserst	   subparser(    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyRE   ˆ   s    (   RF   t
   __future__R    R#   t   loggingR!   R   R)   t   six.moves.urllib.parseR   t	   six.movesR   t   binstar_clientR   t   binstar_client.utilsR   R   R   R   t	   getLoggerR   R   t   TrueR=   R?   R@   RE   (    (    (    s\   lib/python2.7/site-packages/anaconda_client-1.7.2-py2.7.egg/binstar_client/commands/login.pyt   <module>   s    "	R		