
    k7i                        S r SSKJr  SSKrSSKrSSKrSSKrSSKJrJ	r	J
r
JrJrJrJrJrJr  SSKJr   " S S5      rSS	 jr\S
:X  a  \R,                  " \" 5       5        gg)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                      \ rS rSr% S\S'   S\S'   S\S'   S\S'   S\S'   S\S	'   S\S
'   S rS rS rS rSS jr	SS jr
SS jrSS jrS rS rS rS rS rS r\S 5       r\S 5       rSrg)CommandLineTool   z
str | Nonekeyring_pathkeyring_backendstrget_modeoutput_format	operationserviceusernamec                T   [         R                  " 5       U l        U R                  R                  SSSS SS9  U R                  R                  SSSS S	S9  U R                  R                  S
SSS9  U R                  R                  SSSS9  SS/U R                  l        U R                  R                  SU R                  R                  SSSS9  SS/U R                  l        U R                  R                  SU R                  R
                  SSSS9  / SQU R                  l        U R                  R                  SU R                  R                  SS9  U R                  R                  SSS 9  U R                  R                  S!SS 9  [        R                  " U R                  5        g )"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    E/home/james-whalen/.local/lib/python3.13/site-packages/keyring/cli.py__init__CommandLineTool.__init__"   s   --/  . 	! 	
 	  ". 	! 	
 	  1 	! 	

 	  3M 	! 	
 #-g!6  KK** 	! 	
 (/&7#  KK//  	! 
	
 #D  KK++ 	! 	

 	   	! 	
 	   	! 	
 	4;;'    c                   U R                   R                  U5      n[        U 5      R                  [        U5      5        UR                  (       a(  [
        R                  " 5        H  n[        U5        M     g UR                  (       a  [        R                  " 5         g UR                  S:X  a  U R                  5         g U R                  5         U R                  5         [        U SU R                   3U R                  5      nU" 5       $ )Nr(   do_)r-   
parse_argsvarsupdatelist_backendsr   get_all_keyringprintdisabler   r   r(   _check_args_load_spec_backendgetattr
invalid_op)r4   argvargskmethods        r5   runCommandLineTool.rund   s    {{%%d+T
$t*%,,.a /<<LLN>>Z'MMO!T^^$45tGxr8   c                8  ^  T R                   S:g  =(       d    T R                  S:g  nS/S/U-  -   [        T R                   5      -  n[        U 4S jU 5       5      (       a:  T R                  R                  T R                    SSR                  U5       35        g g )Nr%   r!   r   r   c              3  @   >#    U  H  n[        TU5      S L v   M     g 7fN)rD   ).0paramr4   s     r5   	<genexpr>.CommandLineTool._check_args.<locals>.<genexpr>}   s     BwtU#t+s   z
 requires z and )r   r   boolanyr-   errorjoin)r4   needs_usernamerequireds   `  r5   rB   CommandLineTool._check_argsz   s    50LDMMW4LK:,"??4CWWBBBBKK 0
7<<;Q:RST Cr8   c                    [        U SU R                   35      " 5       nUc  [        S5      e[        U SU R                   35      " U5        g )N_get_r   _emit_)rD   r   
SystemExitr   r4   
credentials     r5   do_getCommandLineTool.do_get   sI    TU4==/#:;=
Q-t11234Z@r8   c                ^    [        [        R                  " UR                  5       5      5        g rN   )r@   r$   dumps_varsr^   s     r5   
_emit_jsonCommandLineTool._emit_json   s    djj))+,-r8   c                d    UR                  5       R                  5        H  n[        U5        M     g rN   )rd   valuesr@   )r4   r_   vals      r5   _emit_plainCommandLineTool._emit_plain   s%    ##%,,.C#J /r8   c                B    [        U R                  U R                  5      $ rN   )r
   r   r   r3   s    r5   
_get_credsCommandLineTool._get_creds   s    dllDMM::r8   c                x    [        U R                  U R                  5      nUb  [        R                  " U5      $ S $ rN   )r   r   r   r   AnonymousCredentialr4   r    s     r5   _get_passwordCommandLineTool._get_password   s6    dmm<9A9MK++H5	
SW	
r8   c                    U R                  SU R                   SU R                   S35      n[        U R                  U R                  U5        g )NzPassword for 'z' in 'z': )input_passwordr   r   r   rq   s     r5   do_setCommandLineTool.do_set   sB    &&T]]O6$,,sC
 	T\\4==(;r8   c                D    [        U R                  U R                  5        g rN   )r	   r   r   r3   s    r5   do_delCommandLineTool.do_del   s    dmm4r8   c                    [         R                  " 5       nUR                  5       (       a  [        SU5        O[        SUS5        [        S[        R
                  " 5       5        g )Nzconfig path:z(absent)z
data root:)r   _config_pathexistsr@   r   	data_root)r4   config_roots     r5   r(   CommandLineTool.diagnose   sH    '').+..+z:lI//12r8   c                    U R                   R                  SSR                  U R                   R                  5       S35        g )NzSpecify operation (z, z).)r-   rU   rV   r1   r3   s    r5   rE   CommandLineTool.invalid_op   s3    /		$++:Q:Q0R/SSUVWr8   c                T   U R                   c  g  U R                  (       a*  [        R                  R	                  SU R                  5        [        [        R                  " U R                   5      5        g ! [         a(  nU R                  R                  SU 35         S nAg S nAff = f)Nr   z"Unable to load specified keyring: )r   r   syspathinsertr   r   load_keyring	Exceptionr-   rU   )r4   excs     r5   rC   "CommandLineTool._load_spec_backend   s    '
	J  4#4#45))$*>*>?@ 	J KK B3%HII	Js   A$A5 5
B'?B""B'c                \    U R                  5       =(       d    [        R                  " U5      $ )zRetrieve password from input.)pass_from_pipegetpass)r4   prompts     r5   ru   CommandLineTool.input_password   s    ""$?(??r8   c                    [         R                  R                  5       (       + nU=(       a-    U R                  [         R                  R	                  5       5      $ )z4Return password from pipe if not on TTY, else False.)r   stdinisattystrip_last_newlineread)clsis_pipes     r5   r   CommandLineTool.pass_from_pipe   s:     ii&&((C311#))..2BCCr8   c                P    [        U R                  S5      (       a  SOS5      nX   $ )zStrip one last newline, if present.

>>> CommandLineTool.strip_last_newline('foo')
'foo'
>>> CommandLineTool.strip_last_newline('foo\n')
'foo'

N)sliceendswith)r   slcs     r5   r   "CommandLineTool.strip_last_newline   s%     #,,t,,B$7xr8   )r-   N)r_   zcredentials.Credential)returnzcredentials.Credential | None)__name__
__module____qualname____firstlineno____annotations__r6   rJ   rB   r`   re   rj   rm   rr   rv   ry   r(   rE   rC   ru   classmethodr   staticmethodr   __static_attributes__ r8   r5   r   r      s    MNLM@(D,UA.;
<53XJ @ D D
 	 	r8   r   c                d    U c  [         R                  SS n [        5       nUR                  U 5      $ )zMain command line interface.Nr   )r   rF   r   rJ   )rF   clis     r5   mainr      s.     |xx|

C774=r8   __main__rN   )__doc__
__future__r   r+   r   r$   r    r   r   r   r   r	   r
   r   r   r   utilr   r   r   r   exitr   r8   r5   <module>r      sZ    F "    

 
 
 v vr zHHTV r8   