
    /d                         d 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  G d d	          Zdd
Zedk    r ej         e                       dS dS )z@Simple command line interface to get/set password from a keyring    N   )core)backend)
completion)set_keyringget_passwordset_passworddelete_passwordc                   p    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zed
             Zed             ZdS )CommandLineToolc                    t          j                    | _        | j                            dddd d           | j                            dddd d	           | j                            d
dd           | j                            ddd           | j                            dg dd           | j                            dd           | j                            dd           t	          j        | j                   d S )Nz-pz--keyring-pathkeyring_pathzPath to the keyring backend)destdefaulthelpz-bz--keyring-backendkeyring_backendzName of the keyring backendz--list-backends
store_truezList keyring backends and exit)actionr   z	--disablezDisable keyring and exit	operation)getsetdel?)choicesnargsservice)r   username)argparseArgumentParserparseradd_argumentr   installselfs    +lib/python3.11/site-packages/keyring/cli.py__init__zCommandLineTool.__init__   s\   -//  . 	! 	
 	
 	
 	  ". 	! 	
 	
 	
 	  1 	! 	
 	
 	

 	  3M 	! 	
 	
 	
 	  ))) 	! 	
 	
 	

 	   	! 	
 	
 	
 	   	! 	
 	
 	
 	4;'''''    c                    | j                             |          }t          |                               t          |                     |j        r't          j                    D ]}t          |           d S |j        rt          j                     d S | 
                                 |                                  t          | d| j         | j                  } |            S )Ndo_)r    
parse_argsvarsupdatelist_backendsr   get_all_keyringprintdisabler   _check_args_load_spec_backendgetattrr   
invalid_op)r$   argvargskmethods        r%   runzCommandLineTool.run6   s    {%%d++T

$t**%%% 	,..  aF< 	LNNNF!!!5T^55tGGvxxr'   c                 |    | j         r2| j        | j        &| j                            | j          d           d S d S d S )Nz requires service and username)r   r   r   r    errorr#   s    r%   r1   zCommandLineTool._check_argsH   sa    > 	U| Ut} U!!T^"S"S"STTTTT	U 	UU Ur'   c                 z    t          | j        | j                  }|t          d          t	          |           d S )Nr   )r   r   r   
SystemExitr/   r$   passwords     r%   do_getzCommandLineTool.do_getM   s8    dm<< 	 Q--hr'   c                     |                      d| j         d| j         d          }t          | j        | j        |           d S )NzPassword for 'z' in 'z': )input_passwordr   r   r	   r>   s     r%   do_setzCommandLineTool.do_setS   sO    &&CT]CC$,CCC
 
 	T\4=(;;;;;r'   c                 :    t          | j        | j                   d S N)r
   r   r   r#   s    r%   do_delzCommandLineTool.do_delY   s    dm44444r'   c                 :    | j                             d           d S )Nz)Specify operation 'get', 'del', or 'set'.)r    r;   r#   s    r%   r4   zCommandLineTool.invalid_op\   s    EFFFFFr'   c                 *   | j         d S 	 | j        r%t          j                            d| j                   t          t          j        | j                              d S # t          f$ r(}| j	        
                    d|            Y d }~d S d }~ww xY w)Nr   z"Unable to load specified keyring: )r   r   syspathinsertr   r   load_keyring	Exceptionr    r;   )r$   excs     r%   r2   z"CommandLineTool._load_spec_backend_   s     	F
	J  64#4555)$*>??@@@@@| 	J 	J 	J KH3HHIIIIIIIII	Js   AA B*BBc                 R    |                                  pt          j        |          S )zRetrieve password from input.)pass_from_pipegetpass)r$   prompts     r%   rB   zCommandLineTool.input_passwordo   s#    ""$$?(?(??r'   c                     t           j                                         }|o0|                     t           j                                                  S )z4Return password from pipe if not on TTY, else False.)rI   stdinisattystrip_last_newlineread)clsis_pipes     r%   rP   zCommandLineTool.pass_from_pipes   s?     i&&(((C311#)..2B2BCCCr'   c                 >    | d|                      d                    S )z#Strip one last newline, if present.N
)endswith)strs    r%   rV   z"CommandLineTool.strip_last_newliney   s$     (cll4(((())r'   N)__name__
__module____qualname__r&   r9   r1   r@   rC   rF   r4   r2   rB   classmethodrP   staticmethodrV    r'   r%   r   r      s        %( %( %(N  $U U U
  < < <5 5 5G G GJ J J @ @ @ D D [D
 * * \* * *r'   r   c                 t    | t           j        dd         } t                      }|                    |           S )zMain command line interface.Nr   )rI   r5   r   r9   )r5   clis     r%   mainrf      s6      x|


C774==r'   __main__rE   )__doc__rQ   r   rI    r   r   r   r   r   r	   r
   r   rf   r^   exitrc   r'   r%   <module>rk      s    F F   



                   F F F F F F F F F F F Fn* n* n* n* n* n* n* n*b    z CHTTVV r'   