
    e                    v   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j0                        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 y)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|j                  |        y y )N_classes)super__init__hasattrsetr   __abstractmethods__add)clsnamebasesdictclasses	__class__s        1/usr/lib/python3/dist-packages/keyring/backend.pyr   zKeyringBackendMeta.__init__    sJ    ud+sJ'5CL,,&&KK '    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      s    
 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y)KeyringBackendz]The abstract base class of the keyring, every backend must implement
    this interface.
    c                $    | j                          y N)set_properties_from_envselfs    r   r   zKeyringBackend.__init__.   s    $$&r   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.priority1   s
      "!r   c                v    t        j                         5 }| j                   d d d        | S # 1 sw Y    S xY wr&   )r   ExceptionRaisedContextr
   )r   excs     r   viablezKeyringBackend.viableC   s5    **, 	LL	w	ws   -8c                T    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_backendsI   s      h))(3S\\BBr   c                    | j                   j                  d      \  }}}|j                  dd      }dj                  || 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.nameR   sI     !$ 9 9# >X##C-xx3<<011r   c                z    t        |       }dj                  |j                  |j                  |j                        S )Nz{}.{} (priority: {:g}))typeformatr   r   r
   )r)   keyring_classs     r   __str__zKeyringBackend.__str__]   s7    T
'..$$m&<&<m>T>T
 	
r   c                     y)z,Get password of the username for the serviceN r)   serviceusernames      r   get_passwordzKeyringBackend.get_passwordc   s     r   c                ,    t        j                  d      )zSet password for the username of the service.

        If the backend cannot store passwords, raise
        PasswordSetError.
        reason)r   PasswordSetErrorr)   rG   rH   passwords       r   set_passwordzKeyringBackend.set_passwordh   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   PasswordDeleteErrorrF   s      r   delete_passwordzKeyringBackend.delete_passwordt   s     ((22r   c                \    |*| j                  ||      }|t        j                  ||      S y)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)rI   r   SimpleCredentialrM   s       r   get_credentialzKeyringBackend.get_credential   s8     (((;H#"33HhGGr   c                    dd}t        dt        |t        j                  j	                                     }|D ]  \  }}t        | ||        y)z6For all KEYRING_PROPERTY_* env var, set that property.c                b    | \  }}|j                  d      \  }}}|xr |j                         |fS )NKEYRING_PROPERTY_)	partitionlower)itemkeyvalueprer=   r   s         r   parsez5KeyringBackend.set_properties_from_env.<locals>.parse   s6    JC ]]+>?NCd0DJJL%00r   N)r[   ztyping.Tuple[str, str])r1   maposenvironitemssetattr)r)   r_   propsr   r]   s        r   r'   z&KeyringBackend.set_properties_from_env   sM    	1
 17#eRZZ--/01
 ! 	'KD%D$&	'r   c                d    t        j                   |       }t        |      j                  |       |S r&   )copyvarsupdate)r)   kwargsalts      r   with_propertieszKeyringBackend.with_properties   s&    iioS	 
r   N)returnfloat)r   ztyping.Type[KeyringBackend]rm   z#filter[typing.Type[KeyringBackend]])rm   str)rG   ro   rH   ro   rm   typing.Optional[str])rG   ro   rH   ro   rN   ro   rm   None)rG   ro   rH   ro   rm   rq   )rG   ro   rH   rp   rm   z'typing.Optional[credentials.Credential]rm   rq   )rj   
typing.Anyrm   r$   )r   r   r    r!   r   r	   classpropertyr
   r/   classmethodr4   r   rC   abcabstractmethodrI   rO   rR   rU   r'   rl   rE   r   r   r$   r$   )   s    ' " ""  
 C(C	,C C 2 2
 	  	0 03 ' 
1	&'r   r$   )	metaclassc                  X    e Zd ZdZej
                  d        Zej
                  d        Zy)Crypterz.Base class providing encryption and decryptionc                     y)zEncrypt the value.NrE   r)   r]   s     r   encryptzCrypter.encrypt        	r   c                     y)zDecrypt the value.NrE   r|   s     r   decryptzCrypter.decrypt   r~   r   N)r   r   r    r!   rv   rw   r}   r   rE   r   r   rz   rz      s7    8  	 r   rz   c                      e Zd ZdZd Zd Zy)NullCrypterzA crypter that does nothingc                    |S r&   rE   r|   s     r   r}   zNullCrypter.encrypt       r   c                    |S r&   rE   r|   s     r   r   zNullCrypter.decrypt   r   r   N)r   r   r    r!   r}   r   rE   r   r   r   r      s    %r   r   c                    t        j                  d      D ]E  } 	 t        j                  d| j                         | j                         }t        |      r |        G y# t        $ r t        j                  d|  d       Y mw xY w)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 r6   N)	r   entry_pointslogdebugr   loadcallable	Exception	exception)ep	init_funcs     r   _load_pluginsr      sv      ##*<= >	>IIlBGG,	I	">  	>MM6rd!<=	>s   AA  "BBc                     t                t        j                         } t        j                  | t
              }t        |      S )zc
    Return a list of all implemented keyrings that can be constructed without
    parameters.
    )
exceptions)r   r$   r4   r   suppress_exceptions	TypeErrorlist)viable_classesringss     r   get_all_keyringr      s3     O#779N$$^	JE;r   c                  b    e Zd ZdZdZ e edd       edd            Z	 d	 	 	 	 	 	 	 dd
Zy	)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'}
    defaultrH   rG   )rH   rG   UserNameTitle)r   	KeePassXCNc                r    | j                   | j                     }t        ||d   ||d   |in|d   |ifi |S )NrH   rG   )schemesschemer   )r)   rG   rH   baser   s        r   _queryzSchemeSelectable._query   sa     dkk*
 # z"Hy!7 y!7

 

 
	
r   r&   )rG   ro   rH   rp   r   rs   rm   ztyping.Dict[str, str])r   r   r    r!   r   r   r   r   rE   r   r   r   r      sW      Fj)<
G<G >B

&:
KU
	
r   r   rr   )rm   ztyping.List[KeyringBackend])!r!   
__future__r   ra   rv   loggingr2   rg   typingpy312compatr    r   r   r   _compatr	   	getLoggerr   r   r3   by_priorityr   __annotations__ABCMetar   r$   rz   r   r   oncer   r   rE   r   r   <module>r      s    # 	 
     ! ' ' g! "h!!*-CG@ G z1 zz ' >4  %
 %
r   