
    .Ph                        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mZm	Z	m
Z
mZmZ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    )annotationsN   )	backend
completioncorecredentialsdelete_passwordget_credentialget_passwordset_keyringset_password)	platform_c                      e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded	<   d
 Zd Zd Zd ZddZddZ	d dZ
d dZd Zd Zd Zd Zd Zd Zed             Zed             ZdS )!CommandLineToolz
str | Nonekeyring_pathkeyring_backendstrget_modeoutput_format	operationserviceusernamec                   t          j                    | _        | j                            dddd d           | j                            dddd d	           | j                            d
dd           | j                            ddd           ddg| j        _        | j                            d| j        j        ddd           ddg| j        _        | j                            d| j        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-pathr   zPath to the keyring backend)destdefaulthelpz-bz--keyring-backendr   zName of the keyring backendz--list-backends
store_truezList keyring backends and exit)actionr   z	--disablezDisable keyring and exitpasswordcredsz--moder   a  
            Mode for 'get' operation.
            'password' requires a username and will return only the password.
            'creds' does not require a username and will return both the username and password separated by a newline.

            Default is 'password'
            )choicesr   r   r   plainjsonz--outputr   z\
            Output format for 'get' operation.

            Default is 'plain'
            )getsetdeldiagnoser   ?)r!   nargsr   )r)   r   )	argparseArgumentParserparseradd_argument
_get_modes_output_formats_operationsr   installselfs    K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/cli.py__init__zCommandLineTool.__init__"   s   -//  . 	! 	
 	
 	
 	  ". 	! 	
 	
 	
 	  1 	! 	
 	
 	

 	  3M 	! 	
 	
 	
 #-g!6  K* 	! 	
 	
 	
 (/&7#  K/  	! 
	
 
	
 
	
 #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)r3   argvargskmethods        r4   runzCommandLineTool.rund   s    {%%d++T

$t**%%% 	,..  aF< 	LNNNF>Z''MMOOOF!!!5T^55tGGvxxr6   c                     j         dk    p
 j        dk    }dgdg|z  z   t           j                   z  }t           fd|D                       r9 j                             j          dd                    |                      d S d S )Nr$   r    r   r   c              3  <   K   | ]}t          |          d u V  d S N)rB   ).0paramr3   s     r4   	<genexpr>z.CommandLineTool._check_args.<locals>.<genexpr>}   s2      BBwtU##t+BBBBBBr6   z
 requires z and )r   r   boolanyr,   errorjoin)r3   needs_usernamerequireds   `  r4   r@   zCommandLineTool._check_argsz   s    50LDMW4LK:,"??4CWCWWBBBBBBBBB 	UKSS7<<;Q;QSSTTTTT	U 	Ur6   c                     t          | d| j                               }|t          d           t          | d| j                   |           d S )N_get_r   _emit_)rB   r   
SystemExitr   r3   
credentials     r4   do_getzCommandLineTool.do_get   sb    ;WT#:4=#:#:;;==
Q--43t13344Z@@@@@r6   rZ   credentials.Credentialc                l    t          t          j        |                                                     d S rK   )r>   r#   dumps_varsrY   s     r4   
_emit_jsonzCommandLineTool._emit_json   s,    dj))++,,-----r6   c                v    |                                                                 D ]}t          |           d S rK   )r_   valuesr>   )r3   rZ   vals      r4   _emit_plainzCommandLineTool._emit_plain   s@    ##%%,,.. 	 	C#JJJJ	 	r6   returncredentials.Credential | Nonec                6    t          | j        | j                  S rK   )r
   r   r   r2   s    r4   
_get_credszCommandLineTool._get_creds   s    dlDM:::r6   c                f    t          | j        | j                  }|t          j        |          nd S rK   )r   r   r   r   AnonymousCredentialr3   r   s     r4   _get_passwordzCommandLineTool._get_password   s3    dm<<9A9MK+H555SW	
r6   c                    |                      d| j         d| j         d          }t          | j        | j        |           d S )NzPassword for 'z' in 'z': )input_passwordr   r   r   rk   s     r4   do_setzCommandLineTool.do_set   sO    &&CT]CC$,CCC
 
 	T\4=(;;;;;r6   c                :    t          | j        | j                   d S rK   )r	   r   r   r2   s    r4   do_delzCommandLineTool.do_del   s    dm44444r6   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existsr>   r   	data_root)r3   config_roots     r4   r'   zCommandLineTool.diagnose   sh    ')) 	;.+.....+z:::lI/1122222r6   c                |    | j                             dd                    | j         j                   d           d S )NzSpecify operation (z, z).)r,   rQ   rR   r0   r2   s    r4   rC   zCommandLineTool.invalid_op   s;    V		$+:Q0R0RVVVWWWWWr6   c                (   | j         d S 	 | j        r%t          j                            d| j                   t          t          j        | j                              d S # t          $ 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,   rQ   )r3   excs     r4   rA   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)r3   prompts     r4   rn   zCommandLineTool.input_password   s#    ""$$?(?(??r6   c                    t           j                                         }|o0|                     t           j                                                  S )z4Return password from pipe if not on TTY, else False.)ry   stdinisattystrip_last_newlineread)clsis_pipes     r4   r   zCommandLineTool.pass_from_pipe   s?     i&&(((C311#)..2B2BCCCr6   c                ^    t          |                     d          rdnd          }| |         S )zStrip one last newline, if present.

        >>> CommandLineTool.strip_last_newline('foo')
        'foo'
        >>> CommandLineTool.strip_last_newline('foo\n')
        'foo'
        
N)sliceendswith)r   slcs     r4   r   z"CommandLineTool.strip_last_newline   s/     #,,t,,6BB$773xr6   N)rZ   r\   )re   rf   )__name__
__module____qualname____annotations__r5   rH   r@   r[   r`   rd   rh   rl   ro   rq   r'   rC   rA   rn   classmethodr   staticmethodr    r6   r4   r   r      s        MMMNNNLLLMMM@( @( @(D  ,U U UA A A. . . .   ; ; ; ;
 
 
 
< < <5 5 53 3 3X X XJ J J @ @ @ D D [D
 	 	 \	 	 	r6   r   c                t    | t           j        dd         } t                      }|                    |           S )zMain command line interface.Nr   )ry   rD   r   rH   )rD   clis     r4   mainr      s3     |x|


C774==r6   __main__rK   )__doc__
__future__r   r*   r   r#   ry    r   r   r   r   r	   r
   r   r   r   utilr   r   r   r   exitr   r6   r4   <module>r      s;   F F " " " " " "    




 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
      v v v v v v v vr    zCHTTVV r6   