ó
F+ÞOc           @   s‹   d  Z  d d l Z d d l m Z d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d d „ Z
 e d k r‡ e j e
 ƒ  ƒ n  d S(   s@   Simple command line interface to get/set password from a keyringiÿÿÿÿN(   t   OptionParsert   CommandLineToolc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c      	   C   s`   t  d d ƒ |  _ |  j j d d d d d d  d d	 ƒ|  j j d
 d d d d d  d d ƒd  S(   Nt   usages    %prog [get|set] SERVICE USERNAMEs   -ps   --keyring-patht   destt   keyring_patht   defaultt   helps   Path to the keyring backends   -bs   --keyring-backendt   keyring_backends   Name of the keyring backend(   R    t   parsert
   add_optiont   None(   t   self(    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyt   __init__   s    c   
      C   si  |  j  j | ƒ \ } } y | \ } } } WnD t k
 rq t | ƒ d k r^ |  j  j ƒ  d S|  j  j d ƒ n X| j d  k	 rÚ y, t j	 j
 | j | j ƒ } t j | ƒ WqÚ t k
 rÖ } |  j  j d | ƒ qÚ Xn  | d k rt j | | ƒ }	 |	 d  k rd S|  j |	 ƒ d S| d k rU|  j d | | f ƒ }	 t j | | |	 ƒ d S|  j  j d ƒ d  S(	   Ni    i   s   Wrong number of argumentss$   Unable to load specified keyring: %st   gett   sets   Password for '%s' in '%s': s'   You can only 'get' or 'set' a password.(   R   t
   parse_argst
   ValueErrort   lent
   print_helpt   errorR   R
   t   keyringt   coret   load_keyringR   t   set_keyringt	   Exceptiont   get_passwordt   output_passwordt   input_passwordt   set_password(
   R   t   argvt   optst   argst   kindt   servicet   usernamet   backendt   et   password(    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyt   run   s8    	c         C   s   t  j  | ƒ S(   sa   Ask for a password to the user.

        This mostly exists to ease the testing process.
        (   t   getpass(   R   t   prompt(    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyR   C   s    c         C   s	   | GHd S(   sb   Output the password to the user.

        This mostly exists to ease the testing process.
        N(    (   R   R%   (    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyR   L   s    (   t   __name__t
   __module__R   R&   R   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyR      s   			-		c         C   s2   |  d k r t j d }  n  t ƒ  } | j |  ƒ S(   s   Main command line interface.i   N(   R
   t   sysR   R   R&   (   R   t   cli(    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyt   mainU   s    	t   __main__(   t   __doc__R'   t   optparseR    R+   R   t   keyring.coret   objectR   R
   R-   R)   t   exit(    (    (    s/   /usr/lib/python2.7/dist-packages/keyring/cli.pyt   <module>   s   I