
    d                       U 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Zddl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d	ed
<    G d dej                  Z G d de          Z G d d          Z G d de          ZddZej        dd            Z G d d          Z dS )z 
Keyring implementation support
    )annotationsN   )metadata)credentialserrorsutil)
propertiespriorityz8typing.Optional[typing.Callable[[KeyringBackend], bool]]_limitc                  "     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        S/home/feoh/.local/pipx/venvs/poetry/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ej        dd            Zej        d             Ze	dd
            Z
ej        dd            ZddZej        d d            Zej        d!d            Zd"dZd#dZd$dZd%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   returntyping.Union[int, float]c                    t           )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.
        )NotImplementedErrorr(   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.viableB   sq    *,, 	LL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	ws   (,,r   typing.Type[KeyringBackend]#filter[typing.Type[KeyringBackend]]c                P    t          t          j        d          | j                  S )z6
        Return all subclasses deemed viable.
        r1   )filteroperator
attrgetterr   )r   s    r   get_viable_backendsz"KeyringBackend.get_viable_backendsH   s!     h)(33S\BBBr   strc                    | 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.nameQ   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__\   s5    T

'..$m&<m>T
 
 	
r   serviceusernametyping.Optional[str]c                    dS )z,Get password of the username for the serviceN r)   rI   rJ   s      r   get_passwordzKeyringBackend.get_passwordb   s	     tr   passwordNonec                *    t          j        d          )zSet password for the username of the service.

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

        If the backend cannot delete passwords, raise
        PasswordDeleteError.
        rS   )r   PasswordDeleteErrorrN   s      r   delete_passwordzKeyringBackend.delete_passwords   s     (222r   'typing.Optional[credentials.Credential]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)rO   r   SimpleCredentialrU   s       r   get_credentialzKeyringBackend.get_credential~   s=     (((;;H#"3HhGGGtr   c                    dd}t          dt          |t          j                                                            }|D ]\  }}t          | ||           dS )z6For all KEYRING_PROPERTY_* env var, set that property.itemtyping.Tuple[str, str]c                n    | \  }}|                     d          \  }}}|o|                                |fS )NKEYRING_PROPERTY_)	partitionlower)r_   keyvalueprerB   r   s         r   parsez5KeyringBackend.set_properties_from_env.<locals>.parse   s;    JC ]]+>??NCd0DJJLL%00r   N)r_   r`   )r5   maposenvironitemssetattr)r)   rh   propsr   rf   s        r   r'   z&KeyringBackend.set_properties_from_env   sx    	1 	1 	1 	1
 17#eRZ--//001
 1
 ! 	' 	'KD%D$&&&&	' 	'r   kwargs
typing.Anyc                r    t          j         |           }t          |                              |           |S r&   )copyvarsupdate)r)   ro   alts      r   with_propertieszKeyringBackend.with_properties   s.    iooS		   
r   N)r*   r+   )r   r2   r*   r3   )r*   r9   )rI   r9   rJ   r9   r*   rK   )rI   r9   rJ   r9   rP   r9   r*   rQ   )rI   r9   rJ   r9   r*   rQ   )rI   r9   rJ   rK   r*   rZ   r*   rQ   )ro   rp   r*   r$   )r   r   r    r!   r   r	   classpropertyr
   r1   classmethodr8   r   rH   abcabstractmethodrO   rV   rY   r]   r'   rv   rM   r   r   r$   r$   (   sd        ' ' ' " " " ""   
 C C C [C 2 2 2 2
 
 
 
 	    	0 0 0 0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.NrM   r)   rf   s     r   encryptzCrypter.encrypt   	     	r   c                    dS )zDecrypt the value.NrM   r   s     r   decryptzCrypter.decrypt   r   r   N)r   r   r    r!   rz   r{   r   r   rM   r   r   r~   r~      sV        88   	    r   r~   c                      e Zd ZdZd Zd ZdS )NullCrypterzA crypter that does nothingc                    |S r&   rM   r   s     r   r   zNullCrypter.encrypt       r   c                    |S r&   rM   r   s     r   r   zNullCrypter.decrypt   r   r   N)r   r   r    r!   r   r   rM   r   r   r   r      s8        %%      r   r   r*   rQ   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 r;   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typing.List[KeyringBackend]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$   r8   r   suppress_exceptions	TypeErrorlist)viable_classesringss     r   get_all_keyringr      s?     OOO#7799N$^	JJJE;;r   c                  h    e Zd ZdZdZ e edd           edd                    Z	 d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'}
    defaultrJ   rI   )rJ   rI   UserNameTitle)r   	KeePassXCNr9   rK   baserp   r*   typing.Dict[str, str]c                x    | j         | j                 }t          ||d         ||d         |in	|d         |ifi |S )NrJ   rI   )schemesschemer   )r)   rI   rJ   r   r   s        r   _queryzSchemeSelectable._query   sl     dk*
 # z"Hy!7  y!7

 

 

 

 
	
r   r&   )rI   r9   rJ   rK   r   rp   r*   r   )r   r   r    r!   r   r   r   r   rM   r   r   r   r      s~           Fdj)<<<$
G<<<  G >B
 
 
 
 
 
 
r   r   rw   )r*   r   )!r!   
__future__r   rj   rz   loggingr6   rr   typingpy312compatr    r   r   r   _compatr	   	getLoggerr   r   r7   by_priorityr   __annotations__ABCMetar   r$   r~   r   r   oncer   r   rM   r   r   <module>r      s     # " " " " " 				 



     ! ! ! ! ! ! ' ' ' ' ' ' ' ' ' '      g!! "h!*--CG G G G G       z z z z z1 z z z zz           '   > > > >4    %
 %
 %
 %
 %
 %
 %
 %
 %
 %
r   