
    k7im#                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKJr  SSKJrJrJr  SSKJr  SS	KJr  \R.                  " \5      r\R4                  " S
5      rSrS\S'    " S S\R<                  5      r " S S\S9r  " S S5      r! " S S\!5      r"SS jr#\SS j5       r$ " S S5      r%g)z 
Keyring implementation support
    )annotationsN)ExceptionTrap)once   )credentialserrorsutil)
properties)metadatapriorityz.typing.Callable[[KeyringBackend], bool] | None_limitc                  8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )KeyringBackendMeta   z}
Specialized subclass behavior.

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

Wraps set_password to validate the username.
c                f   > [         TU ]  XU5        U R                  5         U R                  5         g N)super__init__	_register"_validate_username_in_set_password)clsnamebasesdict	__class__s       I/home/james-whalen/.local/lib/python3.13/site-packages/keyring/backend.pyr   KeyringBackendMeta.__init__'   s'    d+..0    c                    [        U S5      (       d  [        5       U l        U R                  nU R                  (       d  UR	                  U 5        g g )N_classes)hasattrsetr    __abstractmethods__add)r   classess     r   r   KeyringBackendMeta._register,   s;    sJ''5CL,,&&KK 'r   c                h   ^ U R                   m[        R                  " T5      U4S j5       nXl         g)z=
Wrap ``set_password`` such to validate the passed username.
c                @   > U R                  U5        T" XU/UQ70 UD6$ r   )_validate_username)selfsystemusernameargskwargsorigs        r   wrapperFKeyringBackendMeta._validate_username_in_set_password.<locals>.wrapper9   s(    ##H-h@@@@r   N)set_password	functoolswraps)r   r0   r/   s     @r   r   5KeyringBackendMeta._validate_username_in_set_password3   s5     			A 
	A #r    )
__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes____classcell__)r   s   @r   r   r      s    1
# #r   r   c                  r   \ rS rSrSrS r\R                  SS j5       r\	" 5       R                  r
\R                  \
S 5       5       r\    SS j5       r\R                  SS j5       rSS jr\R"                  SS	 j5       rSS
 jr\R"                  SS j5       rSS jr      SS jrSS jrSS jrSrg)KeyringBackendA   zUThe abstract base class of the keyring, every backend must implement
this interface.
c                $    U R                  5         g r   )set_properties_from_envr*   s    r   r   KeyringBackend.__init__F   s    $$&r   c                    [         e)ae  
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.
)NotImplementedErrorrC   s    r   r   KeyringBackend.priorityI   s
      "!r   c                    U R                     g r   )r   r   s    r   viableKeyringBackend.viable^   s     	r   c                V    [        [        R                  " S5      U R                  5      $ )z&
Return all subclasses deemed viable.
rJ   )filteroperator
attrgetterr    rI   s    r   get_viable_backends"KeyringBackend.get_viable_backendsc   s      h))(3S\\BBr   c                    U R                   R                  S5      u  pnUR                  SS5      nSR                  X0R                  /5      $ )zZ
The keyring name, suitable for display.

The name is derived from module and class name.
._ )r8   
rpartitionreplacejoinr7   )r   parentsepmod_names       r   r   KeyringBackend.namel   sE     !$ 9 9# >X##C-xx<<011r   c                l    [        U 5      nUR                   SUR                   SUR                  S S3$ )NrS   z (priority: g))typer8   r7   r   )r*   keyring_classs     r   __str__KeyringBackend.__str__x   s>    T
**+1]-C-C,DLQ^QgQghiPjjkllr   c                    g)z,Get password of the username for the serviceNr6   r*   servicer,   s      r   get_passwordKeyringBackend.get_password|   s     r   c                H    U(       d  [         R                  " S[        SS9  gg)z#
Ensure the username is not empty.
z(Empty usernames are deprecated. See #668   )
stacklevelN)warningswarnDeprecationWarning)r*   r,   s     r   r)   !KeyringBackend._validate_username   s!     MM:" r   c                .    [         R                  " S5      e)znSet password for the username of the service.

If the backend cannot store passwords, raise
PasswordSetError.
reason)r   PasswordSetErrorr*   rf   r,   passwords       r   r2   KeyringBackend.set_password   s     %%h//r   c                .    [         R                  " S5      e)zyDelete the password for the username of the service.

If the backend cannot delete passwords, raise
PasswordDeleteError.
rq   )r   PasswordDeleteErrorre   s      r   delete_passwordKeyringBackend.delete_password   s     ((22r   c                ^    Ub*  U R                  X5      nUb  [        R                  " X#5      $ g)zGets 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)rg   r   SimpleCredentialrs   s       r   get_credentialKeyringBackend.get_credential   s4     ((;H#"33HGGr   c                    SS jn[        S[        U[        R                  R	                  5       5      5      nU H  u  p4[        XU5        M     g)z6For all KEYRING_PROPERTY_* env var, set that property.c                h    U u  pUR                  S5      u  p4nU=(       a    UR                  5       U4$ )NKEYRING_PROPERTY_)	partitionlower)itemkeyvalueprerZ   r   s         r   parse5KeyringBackend.set_properties_from_env.<locals>.parse   s2    JC ]]+>?NCd0DJJL%00r   N)r   ztuple[str, str])rM   maposenvironitemssetattr)r*   r   propsr   r   s        r   rB   &KeyringBackend.set_properties_from_env   s?    	1
 *0c%AQAQAS6T)U KDD& !r   c                f    [         R                   " U 5      n[        U5      R                  U5        U$ r   )copyvarsupdate)r*   r.   alts      r   with_propertiesKeyringBackend.with_properties   s&    iioS	 
r   r6   N)returnfloat)r   ztype[KeyringBackend]r   zfilter[type[KeyringBackend]])r   str)rf   r   r,   r   r   
str | None)r,   r   r   None)rf   r   r,   r   rt   r   r   r   )rf   r   r,   r   r   r   )rf   r   r,   r   r   zcredentials.Credential | Noner   r   )r.   
typing.Anyr   r?   )r7   r8   r9   r:   r;   r   r
   classpropertyr   r   passesrJ   classmethodrP   r   rb   abcabstractmethodrg   r)   r2   rx   r|   rB   r   r<   r6   r   r   r?   r?   A   s   ' " "$ _##F   C!C	%C C 	2 	2m 	 	 	0 03  
'	&
'r   r?   )	metaclassc                  `    \ rS rSrSr\R                  S 5       r\R                  S 5       rSr	g)Crypter   z.Base class providing encryption and decryptionc                    g)zEncrypt the value.Nr6   r*   r   s     r   encryptCrypter.encrypt        	r   c                    g)zDecrypt the value.Nr6   r   s     r   decryptCrypter.decrypt   r   r   r6   N)
r7   r8   r9   r:   r;   r   r   r   r   r<   r6   r   r   r   r      s7    8  	 r   r   c                  $    \ rS rSrSrS rS rSrg)NullCrypter   zA crypter that does nothingc                    U$ r   r6   r   s     r   r   NullCrypter.encrypt       r   c                    U$ r   r6   r   s     r   r   NullCrypter.decrypt   r   r   r6   N)r7   r8   r9   r:   r;   r   r   r<   r6   r   r   r   r      s    %r   r   c                 "   [         R                  " SS9 HM  n  [        R                  SU R                  5        U R                  5       n[        U5      (       a	  U" 5         MM  MO     g! [         a    [        R                  SU  S35         Mx  f = f)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 rS   N)	r   entry_pointslogdebugr   loadcallable	Exception	exception)ep	init_funcs     r   _load_pluginsr      sx      ##*<=	>IIlBGG,	I	"" #	 >  	>MM6rd!<=	>s   AA''#BBc                     [        5         [        R                  5       n [        R                  " U [
        S9n[        U5      $ )zW
Return a list of all implemented keyrings that can be constructed without
parameters.
)
exceptions)r   r?   rP   r	   suppress_exceptions	TypeErrorlist)viable_classesringss     r   get_all_keyringr      s3     O#779N$$^	JE;r   c                  \    \ rS rSrSrSr\" \" SSS9\" SSS9S	9r S       SS jjrSr	g
)SchemeSelectablei  a  
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,   rf   )r,   rf   UserNameTitle)r   	KeePassXCNc                t    U R                   U R                     n[        Ub  US   UUS   U0OUS   U040 UD6$ )Nr,   rf   )schemesschemer   )r*   rf   r,   baser   s        r   _querySchemeSelectable._query  sa     dkk*
 # z"Hy!7 y!7

 

 
	
r   r6   r   )rf   r   r,   r   r   r   r   zdict[str, str])
r7   r8   r9   r:   r;   r   r   r   r   r<   r6   r   r   r   r     s[      Fj)<
G<G 48

&0
AK
	
 
r   r   r   )r   zlist[KeyringBackend])&r;   
__future__r   r   r   r3   loggingrN   r   typingrl   jaraco.contextr   jaraco.functoolsr    r   r   r	   compatr
   compat.py312r   	getLoggerr7   r   rO   by_priorityr   __annotations__ABCMetar   r?   r   r   r   r   r   r6   r   r   <module>r      s    # 
     	   ( ! ' '  "! !!*-9=6 = #  #FE1 EP ' >4  %
 %
r   