o
    œ¨Êh>  ã                   @   s–   d Z ddlmZ ddlZddlmZ ddlZddlmZ ddlm	Z	 ddlm
Z
mZmZmZmZ G d	d
„ d
eƒZddd„ZedkrIe eƒ ¡ dS dS )z@Simple command line interface to get/set password from a keyringé    )Úprint_functionN)ÚOptionParseré   )Úcore)Úbackend)Úget_keyringÚset_keyringÚget_passwordÚset_passwordÚdelete_passwordc                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚCommandLineToolc                 C   sN   t dd�| _| jjdddd dd� | jjdd	d
d dd� | jjdddd� d S )Nz$%prog [get|set|del] SERVICE USERNAME)Úusagez-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   )r   ÚparserÚ
add_option)Úself© r   ú=/var/www/html/env/lib/python3.10/site-packages/keyring/cli.pyÚ__init__   s   ÿ
þ
þ
þzCommandLineTool.__init__c           
      C   sp  | j  |¡\}}|jrt ¡ D ]}t|ƒ qd S z|\}}}W n ty<   t|ƒdkr4| j  ¡  Y dS | j  	d¡ Y nw |j
d urpz|jrNtj d|j¡ tt |j
¡ƒ W n tfyo   t ¡ d }| j  	d| ¡ Y nw |dkr†t||ƒ}	|	d u rdS |  |	¡ dS |dkr›|  d||f ¡}	t|||	ƒ dS |dkr¯|  d	||f ¡}	t||ƒ dS | j  	d
¡ 	 d S )Nr   r   zWrong number of argumentsz$Unable to load specified keyring: %sÚgetÚsetzPassword for '%s' in '%s': Údelz$Deleting password for '%s' in '%s': z.You can only 'get', 'del' or 'set' a password.)r   Ú
parse_argsÚlist_backendsr   Úget_all_keyringÚprintÚ
ValueErrorÚlenÚ
print_helpÚerrorr   r   ÚsysÚpathÚinsertr   r   Úload_keyringÚ	ExceptionÚexc_infor	   Úoutput_passwordÚinput_passwordr
   r   )
r   ÚargvÚoptsÚargsÚkÚkindÚserviceÚusernameÚeÚpasswordr   r   r   Úrun   sT   

ú
ù	

ÿÿ
zCommandLineTool.runc                 C   s
   t   |¡S )zaAsk for a password to the user.

        This mostly exists to ease the testing process.
        )Úgetpass)r   Úpromptr   r   r   r-   U   s   
zCommandLineTool.input_passwordc                 C   s   t |tjd� dS )zbOutput the password to the user.

        This mostly exists to ease the testing process.
        )ÚfileN)r!   r&   Ústdout)r   r6   r   r   r   r,   ]   s   zCommandLineTool.output_passwordN)Ú__name__Ú
__module__Ú__qualname__r   r7   r-   r,   r   r   r   r   r      s
    8r   c                 C   s&   | du rt jdd… } tƒ }| | ¡S )zMain command line interface.Nr   )r&   r.   r   r7   )r.   Úclir   r   r   Úmainf   s   
r@   Ú__main__)N)Ú__doc__Ú
__future__r   r8   Úoptparser   r&   Ú r   r   r   r   r	   r
   r   Úobjectr   r@   r<   Úexitr   r   r   r   Ú<module>   s   
W
ÿ