
    陜im#                       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	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 dd	lmZ  ej.                  e      Z ej4                  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dd       Z$ G d d      Z%y)z 
Keyring implementation support
    )annotationsN)ExceptionTrap)once   )credentialserrorsutil)
properties)metadatapriorityz.typing.Callable[[KeyringBackend], bool] | None_limitc                  .     e Zd ZdZ fdZd Zd Z xZS )KeyringBackendMetaz
    Specialized subclass behavior.

    Keeps a registry of all (non-abstract) types.

    Wraps set_password to validate the username.
    c                h    t         |   |||       | j                          | j                          y N)super__init__	_register"_validate_username_in_set_password)clsnamebasesdict	__class__s       K/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/keyring/backend.pyr   zKeyringBackendMeta.__init__'   s)    ud+..0    c                    t        | d      st               | _        | j                  }| j                  s|j	                  |        y y )N_classes)hasattrsetr   __abstractmethods__add)r   classess     r   r   zKeyringBackendMeta._register,   s8    sJ'5CL,,&&KK 'r   c                f    | j                   t        j                        fd       }|| _         y)zM
        Wrap ``set_password`` such to validate the passed username.
        c                B    | j                  |        | ||g|i |S r   )_validate_username)selfsystemusernameargskwargsorigs        r   wrapperzFKeyringBackendMeta._validate_username_in_set_password.<locals>.wrapper9   s*    ##H-fh@@@@r   N)set_password	functoolswraps)r   r-   r,   s     @r   r   z5KeyringBackendMeta._validate_username_in_set_password3   s7     			A 
	A #r   )__name__
__module____qualname____doc__r   r   r   __classcell__)r   s   @r   r   r      s    1
#r   r   c                  T   e Zd ZdZd Zej                  dd       Z e       j                  Z	ej                  e	d               Z
e	 	 	 	 dd       Zej                  dd       ZddZej                   dd       Z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 r   )set_properties_from_envr'   s    r   r   zKeyringBackend.__init__F   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.priorityI   s
      "!r   c                    | j                    y r   )r   r   s    r   viablezKeyringBackend.viable^   s     	r   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_backendsc   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.
        ._ )r2   
rpartitionreplacejoinr1   )r   parentsepmod_names       r   r   zKeyringBackend.namel   sI     !$ 9 9# >X##C-xx3<<011r   c                l    t        |       }|j                   d|j                   d|j                  ddS )NrF   z (priority: g))typer2   r1   r   )r'   keyring_classs     r   __str__zKeyringBackend.__str__x   s>    T
**+1]-C-C,DLQ^QgQghiPjjkllr   c                     y)z,Get password of the username for the serviceN r'   servicer)   s      r   get_passwordzKeyringBackend.get_password|   s     r   c                B    |st        j                  dt        d       yy)z3
        Ensure the username is not empty.
        z(Empty usernames are deprecated. See #668   )
stacklevelN)warningswarnDeprecationWarning)r'   r)   s     r   r&   z!KeyringBackend._validate_username   s!     MM:" 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'   rX   r)   passwords       r   r.   zKeyringBackend.set_password   s     %%h//r   c                ,    t        j                  d      )zDelete the password for the username of the service.

        If the backend cannot delete passwords, raise
        PasswordDeleteError.
        ra   )r   PasswordDeleteErrorrW   s      r   delete_passwordzKeyringBackend.delete_password   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)rY   r   SimpleCredentialrc   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prerM   r   s         r   parsez5KeyringBackend.set_properties_from_env.<locals>.parse   s6    JC ]]+>?NCd0DJJL%00r   N)rp   ztuple[str, str])rA   maposenvironitemssetattr)r'   rt   propsr   rr   s        r   r9   z&KeyringBackend.set_properties_from_env   sH    	1
 *0c%AQAQAS6T)U  	'KD%D$&	'r   c                d    t        j                   |       }t        |      j                  |       |S r   )copyvarsupdate)r'   r+   alts      r   with_propertieszKeyringBackend.with_properties   s&    iioS	 
r   N)returnfloat)r   ztype[KeyringBackend]r   zfilter[type[KeyringBackend]])r   str)rX   r   r)   r   r   
str | None)r)   r   r   None)rX   r   r)   r   rd   r   r   r   )rX   r   r)   r   r   r   )rX   r   r)   r   r   zcredentials.Credential | Noner   r   )r+   
typing.Anyr   r7   )r1   r2   r3   r4   r   r
   classpropertyr   r   passesr?   classmethodrD   r   rT   abcabstractmethodrY   r&   r.   rg   rj   r9   r   rV   r   r   r7   r7   A   s   ' " "$ _##F   C!C	%C C 	2 	2m 	 	 	0 03  
'	&
'r   r7   )	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.NrV   r'   rr   s     r   encryptzCrypter.encrypt        	r   c                     y)zDecrypt the value.NrV   r   s     r   decryptzCrypter.decrypt   r   r   N)r1   r2   r3   r4   r   r   r   r   rV   r   r   r   r      s7    8  	 r   r   c                      e Zd ZdZd Zd Zy)NullCrypterzA crypter that does nothingc                    |S r   rV   r   s     r   r   zNullCrypter.encrypt       r   c                    |S r   rV   r   s     r   r   zNullCrypter.decrypt   r   r   N)r1   r2   r3   r4   r   r   rV   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 rF   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   r7   rD   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'}
    defaultr)   rX   )r)   rX   UserNameTitle)r   	KeePassXCNc                r    | j                   | j                     }t        ||d   ||d   |in|d   |ifi |S )Nr)   rX   )schemesschemer   )r'   rX   r)   baser   s        r   _queryzSchemeSelectable._query  sa     dkk*
 # z"Hy!7 y!7

 

 
	
r   r   )rX   r   r)   r   r   r   r   zdict[str, str])r1   r2   r3   r4   r   r   r   r   rV   r   r   r   r     sV      Fj)<
G<G 48

&0
AK
	
r   r   r   )r   zlist[KeyringBackend])&r4   
__future__r   r   r|   r/   loggingrB   rv   typingr]   jaraco.contextr   jaraco.functoolsr    r   r   r	   compatr
   compat.py312r   	getLoggerr1   r   rC   by_priorityr   __annotations__ABCMetar   r7   r   r   r   r   r   rV   r   r   <module>r      s    # 
     	   ( ! ' '  "g! "h!!*-9=6 = #  #FE1 EP ' >4  %
 %
r   