
    .Phm#                       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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dd            Z$ G d d          Z%dS )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                    t                                          |||           |                                  |                                  d S N)super__init__	_register"_validate_username_in_set_password)clsnamebasesdict	__class__s       O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/backend.pyr   zKeyringBackendMeta.__init__'   sD    ud+++..00000    c                    t          | d          st                      | _        | j        }| j        s|                    |            d S d S )N_classes)hasattrsetr   __abstractmethods__add)r   classess     r   r   zKeyringBackendMeta._register,   sS    sJ'' 	!55CL,& 	KK	 	r   c                b    | j         t          j                  fd            }|| _         dS )zM
        Wrap ``set_password`` such to validate the passed username.
        c                J    |                      |            | ||g|R i |S r   )_validate_username)selfsystemusernameargskwargsorigs        r   wrapperzFKeyringBackendMeta._validate_username_in_set_password.<locals>.wrapper9   s;    ##H---4fh@@@@@@@r   N)set_password	functoolswraps)r   r-   r,   s     @r   r   z5KeyringBackendMeta._validate_username_in_set_password3   sP     				A 	A 	A 	A 
		A #r   )__name__
__module____qualname____doc__r   r   r   __classcell__)r   s   @r   r   r      s`         1 1 1 1 1
  # # # # # # #r   r   c                  6   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dS )(KeyringBackendz]The abstract base class of the keyring, every backend must implement
    this interface.
    c                .    |                                   d S r   )set_properties_from_envr'   s    r   r   zKeyringBackend.__init__F   s    $$&&&&&r   returnfloatc                    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          d S r   )r   r   s    r   viablezKeyringBackend.viable^   s     	r   r   type[KeyringBackend]filter[type[KeyringBackend]]c                P    t          t          j        d          | j                  S )z6
        Return all subclasses deemed viable.
        rA   )filteroperator
attrgetterr   r@   s    r   get_viable_backendsz"KeyringBackend.get_viable_backendsc   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.
        ._ )r2   
rpartitionreplacejoinr1   )r   parentsepmod_names       r   r   zKeyringBackend.namel   sN     !$ 9 9# > >X##C--xx3<0111r   c                V    t          |           }|j         d|j         d|j        ddS )NrK   z (priority: g))typer2   r1   r   )r'   keyring_classs     r   __str__zKeyringBackend.__str__x   s9    T

*ll]-CllQ^Qglllllr   servicer)   
str | Nonec                    dS )z,Get password of the username for the serviceN r'   rZ   r)   s      r   get_passwordzKeyringBackend.get_password|   s	     tr   Nonec                F    |st          j        dt          d           dS dS )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   sB      	M:"     	 	r   passwordc                *    t          j        d          )zSet password for the username of the service.

        If the backend cannot store passwords, raise
        PasswordSetError.
        reason)r   PasswordSetErrorr'   rZ   r)   rg   s       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.
        ri   )r   PasswordDeleteErrorr^   s      r   delete_passwordzKeyringBackend.delete_password   s     (222r   credentials.Credential | Nonec                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)r_   r   SimpleCredentialrk   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tuple[str, str]c                n    | \  }}|                     d          \  }}}|o|                                |fS )NKEYRING_PROPERTY_)	partitionlower)rt   keyvalueprerR   r   s         r   parsez5KeyringBackend.set_properties_from_env.<locals>.parse   s;    JC ]]+>??NCd0DJJLL%00r   N)rt   ru   )rE   maposenvironitemssetattr)r'   r}   propsr   r{   s        r   r9   z&KeyringBackend.set_properties_from_env   sq    	1 	1 	1 	1
 *0c%AQAQASAS6T6T)U)U  	' 	'KD%D$&&&&	' 	'r   r+   
typing.Anyc                r    t          j         |           }t          |                              |           |S r   )copyvarsupdate)r'   r+   alts      r   with_propertieszKeyringBackend.with_properties   s.    iooS		   
r   N)r;   r<   )r   rB   r;   rC   )r;   rI   )rZ   rI   r)   rI   r;   r[   )r)   rI   r;   r`   )rZ   rI   r)   rI   rg   rI   r;   r`   )rZ   rI   r)   rI   r;   r`   )rZ   rI   r)   r[   r;   ro   r;   r`   )r+   r   r;   r7   )r1   r2   r3   r4   r   r
   classpropertyr   r   passesrA   classmethodrH   r   rY   abcabstractmethodr_   r&   r.   rn   rr   r9   r   r]   r   r   r7   r7   A   s        ' ' ' " " " "$ ]__#F  V  C C C [C 	2 	2 	2 	2m m m m 	   	 	 	 	 	0 0 0 03 3 3 3   &
' 
' 
' 
'     r   r7   )	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]   r   s     r   decryptzCrypter.decrypt   r   r   N)r1   r2   r3   r4   r   r   r   r   r]   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   r]   r   s     r   r   zNullCrypter.encrypt       r   c                    |S r   r]   r   s     r   r   zNullCrypter.decrypt   r   r   N)r1   r2   r3   r4   r   r   r]   r   r   r   r      s8        %%      r   r   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 rK   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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   r7   rH   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'}
    defaultr)   rZ   )r)   rZ   UserNameTitle)r   	KeePassXCNrI   r[   baser   r;   dict[str, str]c                x    | j         | j                 }t          ||d         ||d         |in	|d         |ifi |S )Nr)   rZ   )schemesschemer   )r'   rZ   r)   r   r   s        r   _queryzSchemeSelectable._query  sl     dk*
 # z"Hy!7  y!7

 

 

 

 
	
r   r   )rZ   rI   r)   r[   r   r   r;   r   )r1   r2   r3   r4   r   r   r   r   r]   r   r   r   r     s}           Fdj)<<<$
G<<<  G 48
 
 
 
 
 
 
r   r   r   )r;   r   )&r4   
__future__r   r   r   r/   loggingrF   r   typingrd   jaraco.contextr   jaraco.functoolsr    r   r   r	   compatr
   compat.py312r   	getLoggerr1   r   rG   by_priorityr   __annotations__ABCMetar   r7   r   r   r   r   r   r]   r   r   <module>r      s/     # " " " " " 



        				   ( ( ( ( ( ( ! ! ! ! ! ! ' ' ' ' ' ' ' ' ' '       " " " " " "g!! "h!*--9= = = = = #  #  #  #  #  #  #  #FE E E E E1 E E E EP           '   > > > >4    %
 %
 %
 %
 %
 %
 %
 %
 %
 %
r   