
    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 ddl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_password)	platform_c                   v    e Zd 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                 2   t          j                    | _        | j                            dddd d           | j                            dddd d	           | j                            d
dd           | j                            ddd           g d| j        _        | j                            d| j        j        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)getsetdeldiagnose	operation?)choicesnargsservice)r   username)argparseArgumentParserparseradd_argument_operationsr   installselfs    O/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/keyring/cli.py__init__zCommandLineTool.__init__   sl   -//  . 	! 	
 	
 	
 	  ". 	! 	
 	
 	
 	  1 	! 	
 	
 	

 	  3M 	! 	
 	
 	
 #D"C"C  K+ 	! 	
 	
 	

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

$t**%%% 	,..  aF< 	LNNNF>Z''MMOOO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(   r4   zCommandLineTool._check_argsN   sU    > 	U|#t}'<!!T^"S"S"STTTTT	U 	U'<'<r*   c                 z    t          | j        | j                  }|t          d          t	          |           d S )Nr   )r   r   r   
SystemExitr2   r'   passwords     r(   do_getzCommandLineTool.do_getS   s6    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	   rA   s     r(   do_setzCommandLineTool.do_setY   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_del_   s    dm44444r*   c                     t          j                    }|                                rt          d|           nt          d|d           t          dt	          j                               d S )Nzconfig path:z(absent)z
data root:)r   _config_pathexistsr2   r   	data_root)r'   config_roots     r(   r   zCommandLineTool.diagnoseb   sh    ')) 	;.+.....+z:::lI/1122222r*   c                 |    | j                             dd                    | j         j                   d           d S )NzSpecify operation (z, z).)r"   r>   joinr$   r&   s    r(   r7   zCommandLineTool.invalid_opj   s;    V		$+:Q0R0RVVVWWWWWr*   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(   r5   z"CommandLineTool._load_spec_backendm   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(   rE   zCommandLineTool.input_password}   s#    ""$$?(?(??r*   c                     t           j                                         }|o0|                     t           j                                                  S )z4Return password from pipe if not on TTY, else False.)rR   stdinisattystrip_last_newlineread)clsis_pipes     r(   rY   zCommandLineTool.pass_from_pipe   s?     i&&(((C311#)..2B2BCCCr*   c                 >    | d|                      d                    S )z#Strip one last newline, if present.N
)endswith)strs    r(   r_   z"CommandLineTool.strip_last_newline   s$     (cll4(((())r*   N)__name__
__module____qualname__r)   r<   r4   rC   rF   rI   r   r7   r5   rE   classmethodrY   staticmethodr_    r*   r(   r   r      s        &( &( &(P  ,U U U
  < < <5 5 53 3 3X X XJ J J @ @ @ D D [D
 * * \* * *r*   r   c                 t    | t           j        dd         } t                      }|                    |           S )zMain command line interface.Nr   )rR   r8   r   r<   )r8   clis     r(   mainro      s3     |x|


C774==r*   __main__rH   )__doc__rZ   r    rR    r   r   r   r   r   r	   r
   utilr   r   ro   rg   exitrl   r*   r(   <module>ru      s
   F F   



                   F F F F F F F F F F F F      {* {* {* {* {* {* {* {*|    zCHTTVV r*   