
    /d                     h   d Z ddlZddl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mZmZ ddlmZ  ej        e          Z ej        d          ZdZ G d	 d
ej                  Z G d de          Z G d d          Z G d de          Zd Zej        d             Z G d d          ZdS )z 
Keyring implementation support
    N)Optional   )metadata)credentialserrorsutil)
propertiespriorityc                   "     e Zd ZdZ fdZ xZS )KeyringBackendMetazn
    A metaclass that's both an ABCMeta and a type that keeps a registry of
    all (non-abstract) types.
    c                     t                                          |||           t          | d          st                      | _        | j        }| j        s|                    |            d S d S )N_classes)super__init__hasattrsetr   __abstractmethods__add)clsnamebasesdictclasses	__class__s        /lib/python3.11/site-packages/keyring/backend.pyr   zKeyringBackendMeta.__init__   sp    ud+++sJ'' 	!55CL,& 	KK	 	    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      sB         
        r   r   c            	       <   e Zd ZdZd Zd Zej        d             Ze	d             Z
ej        d             Zd Zej        ded	ed
ee         fd            Zej        ded	eded
dfd            Zded	ed
dfdZded	ee         d
eej                 fdZd Zd ZdS )KeyringBackendz]The abstract base class of the keyring, every backend must implement
    this interface.
    c                 .    |                                   d S N)set_properties_from_env)selfs    r   r   zKeyringBackend.__init__,   s    $$&&&&&r   c                     dS )a  
        Each backend class must supply a priority, a number (float or integer)
        indicating the priority of the backend relative to all other backends.
        The priority need not be static -- it may (and should) vary based
        attributes of the environment in which is runs (platform, available
        packages, etc.).

        A higher number indicates a higher priority. The priority should raise
        a RuntimeError with a message indicating the underlying cause if the
        backend is not suitable for the current environment.

        As a rule of thumb, a priority between zero but less than one is
        suitable, but a priority of one or greater is recommended.
        N r   s    r   r
   zKeyringBackend.priority0   s      r   c                 l    t          j                    5 }| j         d d d            n# 1 swxY w Y   | S r%   )r   ExceptionRaisedContextr
   )r   excs     r   viablezKeyringBackend.viable@   sq    *,, 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	ws   (,,c                 P    t          t          j        d          | j                  S )z6
        Return all subclasses deemed viable.
        r.   )filteroperator
attrgetterr   r*   s    r   get_viable_backendsz"KeyringBackend.get_viable_backendsF   s!    
 h)(33S\BBBr   c                     | j                             d          \  }}}|                    dd          }d                    || j        g          S )zr
        The keyring name, suitable for display.

        The name is derived from module and class name.
        ._ )r   
rpartitionreplacejoinr   )r   parentsepmod_names       r   r   zKeyringBackend.nameM   sN     !$ 9 9# > >X##C--xx3<0111r   c                 l    t          |           }d                    |j        |j        |j                  S )Nz{}.{} (priority: {:g}))typeformatr   r   r
   )r'   keyring_classs     r   __str__zKeyringBackend.__str__X   s5    T

'..$m&<m>T
 
 	
r   serviceusernamereturnc                     dS )z,Get password of the username for the serviceNr)   r'   rC   rD   s      r   get_passwordzKeyringBackend.get_password^   s	     tr   passwordNc                 *    t          j        d          )zSet password for the username of the service.

        If the backend cannot store passwords, raise
        PasswordSetError.
        reason)r   PasswordSetErrorr'   rC   rD   rI   s       r   set_passwordzKeyringBackend.set_passwordc   s     %h///r   c                 *    t          j        d          )zDelete the password for the username of the service.

        If the backend cannot delete passwords, raise
        PasswordDeleteError.
        rK   )r   PasswordDeleteErrorrG   s      r   delete_passwordzKeyringBackend.delete_passwordo   s     (222r   c                 d    |-|                      ||          }|t          j        ||          S dS )a   Gets the username and password for the service.
        Returns a Credential instance.

        The *username* argument is optional and may be omitted by
        the caller or ignored by the backend. Callers must use the
        returned username.
        N)rH   r   SimpleCredentialrM   s       r   get_credentialzKeyringBackend.get_credentialz   sC      	H(((;;H H"3HhGGGtr   c                     d }t          dt          |t          j                                                            }|D ]\  }}t          | ||           dS )z6For all KEYRING_PROPERTY_* env var, set that property.c                 n    | \  }}|                     d          \  }}}|o|                                |fS )NKEYRING_PROPERTY_)	partitionlower)itemkeyvalueprer<   r   s         r   parsez5KeyringBackend.set_properties_from_env.<locals>.parse   s;    JC ]]+>??NCd0DJJLL%00r   N)r0   maposenvironitemssetattr)r'   r^   propsr   r\   s        r   r&   z&KeyringBackend.set_properties_from_env   sl    	1 	1 	1
 tS
(8(8(:(:;;<<  	' 	'KD%D$&&&&	' 	'r   c                 r    t          j         |           }t          |                              |           |S r%   )copyvarsupdate)r'   kwargsalts      r   with_propertieszKeyringBackend.with_properties   s.    iooS		   
r   )r   r   r   r    r   r
   r	   classpropertyr.   classmethodr3   r   rB   abcabstractmethodstrr   rH   rN   rQ   r   
CredentialrT   r&   rk   r)   r   r   r#   r#   '   s        ' ' '      
 C C [C 2 2 2
 
 
 	C 3 8C=     	0C 03 0# 0$ 0 0 0 03s 3c 3d 3 3 3 3 3- 
+(	)	   &
' 
' 
'    r   r#   )	metaclassc                   R    e Zd ZdZej        d             Zej        d             ZdS )Crypterz.Base class providing encryption and decryptionc                     dS )zEncrypt the value.Nr)   r'   r\   s     r   encryptzCrypter.encrypt   	     	r   c                     dS )zDecrypt the value.Nr)   rv   s     r   decryptzCrypter.decrypt   rx   r   N)r   r   r   r    rn   ro   rw   rz   r)   r   r   rt   rt      sV        88   	    r   rt   c                       e Zd ZdZd Zd ZdS )NullCrypterzA crypter that does nothingc                     |S r%   r)   rv   s     r   rw   zNullCrypter.encrypt       r   c                     |S r%   r)   rv   s     r   rz   zNullCrypter.decrypt   r~   r   N)r   r   r   r    rw   rz   r)   r   r   r|   r|      s8        %%      r   r|   c                  .   t          j        d          D ]~} 	 t                              d| j                   |                                 }t          |          r
 |             Q# t          $ r! t                              d|  d           Y {w xY wdS )a  
    Locate all setuptools entry points by the name 'keyring backends'
    and initialize them.
    Any third-party library may register an entry point by adding the
    following to their setup.cfg::

        [options.entry_points]
        keyring.backends =
            plugin_name = mylib.mymodule:initialize_func

    `plugin_name` can be anything, and is only used to display the name
    of the plugin at initialization time.

    `initialize_func` is optional, but will be invoked if callable.
    zkeyring.backends)groupz
Loading %szError initializing plugin r5   N)	r   entry_pointslogdebugr   loadcallable	Exception	exception)ep	init_funcs     r   _load_pluginsr      s      #*<=== > >	>IIlBG,,,		I	"" 	 	> 	> 	>MM<r<<<=====	>> >s   AA''(BBc                      t                       t                                          } t          j        | t
                    }t          |          S )zc
    Return a list of all implemented keyrings that can be constructed without
    parameters.
    )
exceptions)r   r#   r3   r   suppress_exceptions	TypeErrorlist)viable_classesringss     r   get_all_keyringr      s?     OOO#7799N$^	JJJE;;r   c                   d    e Zd ZdZdZ e edd           edd                    Zdd
Zd	S )SchemeSelectablea  
    Allow a backend to select different "schemes" for the
    username and service.

    >>> backend = SchemeSelectable()
    >>> backend._query('contoso', 'alice')
    {'username': 'alice', 'service': 'contoso'}
    >>> backend._query('contoso')
    {'service': 'contoso'}
    >>> backend.scheme = 'KeePassXC'
    >>> backend._query('contoso', 'alice')
    {'UserName': 'alice', 'Title': 'contoso'}
    >>> backend._query('contoso', 'alice', foo='bar')
    {'UserName': 'alice', 'Title': 'contoso', 'foo': 'bar'}
    defaultrD   rC   )rD   rC   UserNameTitle)r   	KeePassXCNc                 x    | j         | j                 }t          ||d         ||d         |in	|d         |ifi |S )NrD   rC   )schemesschemer   )r'   rC   rD   baser   s        r   _queryzSchemeSelectable._query   sj    dk*
 	z"Hy!7  y!7

 

 

 

 
	
r   r%   )r   r   r   r    r   r   r   r   r)   r   r   r   r      ss           Fdj)<<<$
G<<<  G

 
 
 
 
 
r   r   )r    r`   rn   loggingr1   rf   typingr   py312compatr    r   r   r   _compatr	   	getLoggerr   r   r2   by_priority_limitABCMetar   r#   rt   r|   r   oncer   r   r)   r   r   <module>r      s    
			 



          ! ! ! ! ! ! ' ' ' ' ' ' ' ' ' '      g!! "h!*--	       u u u u u1 u u u up           '   > > >4   #
 #
 #
 #
 #
 #
 #
 #
 #
 #
r   