
    k7i                    z   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J	r	J
r
  SSKJr  SSKJr  \R                   \	R"                  /\4   r\R(                  " \5      rSqSS jrSS	 jrSS
 jrSS jrSS jrSS jr      SS jrS S jrS!S"S jjr S!S"S jjr!S#S jr"S$S jr#S%S jr$S r%S r&S%S jr'S&S jr(g)'z1
Core API functions and initialization routines.
    )annotationsN   )backendcredentials)fail)	platform_c                \    [        U [        R                  5      (       d  [        S5      eU qg)zSet current keyring backend.z1The keyring must be an instance of KeyringBackendN)
isinstancer   KeyringBackend	TypeError_keyring_backend)keyrings    F/home/james-whalen/.local/lib/python3.13/site-packages/keyring/core.pyset_keyringr      s)     gw5566KLL    c                 v    [         c
  [        5         [        R                  " [        R
                  [         5      $ )zGet current keyring backend.)r   init_backendtypingcastr   r    r   r   get_keyringr       s%    ;;w--/?@@r   c                    [         R                  " 5       n  [        R                  " U 5        [        R
                  R                  U S5      n[        R
                  R                  U5      (       a  SU 3n[        U5      e[        USSS9 nUR                  S5        SSS5        g! [         a     Nf = f! , (       d  f       g= f)z
Configure the null keyring as the default.

>>> fs = getfixture('fs')
>>> disable()
>>> disable()
Traceback (most recent call last):
...
RuntimeError: Refusing to overwrite...
keyringrc.cfgzRefusing to overwrite wutf-8encodingz7[backend]
default-keyring=keyring.backends.null.KeyringN)platformconfig_rootosmakedirsOSErrorpathjoinexistsRuntimeErroropenwrite)rootfilenamemsgfiles       r   disabler-   '   s     !D
D ww||D/2H	ww~~h&xj13	hg	.$

MN 
/	.   
/	.s   B' B7'
B43B47
Cc                4    [        5       R                  X5      $ )z(Get password from the specified service.)r   get_passwordservice_nameusernames     r   r/   r/   ?   s    =%%l==r   c                8    [        5       R                  XU5        g)z3Set password for the user in the specified service.N)r   set_password)r1   r2   passwords      r   r4   r4   D   s    M|x@r   c                6    [        5       R                  X5        g)z:Delete the password for the user in the specified service.N)r   delete_passwordr0   s     r   r7   r7   I   s    M!!,9r   c                4    [        5       R                  X5      $ )z+Get a Credential for the specified service.)r   get_credentialr0   s     r   r9   r9   N   s     =''??r   c                     U R                   S:  $ )Nr   )priority)r   s    r   recommendedr<   U   s    q  r   c                ,    [        [        U 5      5        g)z
Load a detected backend.
N)r   _detect_backendlimits    r   r   r   Y   s     &'r   c                    U [         l        [        5       =(       dZ    [        5       =(       dI    [	        [        U [         R                  " 5       5      [        R                  " 5       [         R                  S9$ )z
Return a keyring specified in the config file or infer the best available.

Limit, if supplied, should be a callable taking a backend and returning
True if that backend should be included for consideration.
)defaultkey)
r   _limitload_envload_configmaxfilterget_all_keyringr   Keyringby_priorityr?   s    r   r>   r>   `   sQ     GN
 	
=	
5'1134LLN##	
	r   c                |    U R                  S5      u  pn[        U5        [        R                  U   n[	        XC5      $ )a  
Load the keyring class indicated by name.

These popular names are tested to ensure their presence.

>>> popular_names = [
...      'keyring.backends.Windows.WinVaultKeyring',
...      'keyring.backends.macOS.Keyring',
...      'keyring.backends.kwallet.DBusKeyring',
...      'keyring.backends.SecretService.Keyring',
...  ]
>>> list(map(_load_keyring_class, popular_names))
[...]
.)
rpartition
__import__sysmodulesgetattr)keyring_namemodule_namesep
class_namemodules        r   _load_keyring_classrX   v   s:     $0#:#:3#? Kj{[[%F6&&r   c                >    [        U 5      nUR                    U" 5       $ )z~
Load the specified keyring by name (a fully-qualified name to the
keyring, such as 'keyring.backends.file.PlaintextKeyring')
)rX   r;   )rS   class_s     r   load_keyringr[      s    
 !.F
OO8Or   c                 \     [        [        R                  S   5      $ ! [         a     gf = f)z6Load a keyring configured in the environment variable.PYTHON_KEYRING_BACKENDN)r[   r    environKeyErrorr   r   r   rE   rE      s.    BJJ'?@AA s    
++c                 2    [         R                  " 5       S-  $ )Nr   )r   r   r   r   r   _config_pathra      s    !O33r   c                F    U R                  5       (       d  [        U 5      eU $ N)r%   FileNotFoundError)r#   s    r   _ensure_pathre      s    ;;==%%Kr   c                    [         R                  " 5       n  U R                  [        [	        5       5      SS9  [        U 5         U R                  S5      (       a!  U R                  SS5      R                  5       nOg[        U5      $ ! [
         a     gf = f! [         R                  [        4 a8    [        R                  " S5      nUR                  SS[	        5        3-   5         gf = f)	z8Load a keyring using the config file in the config root.r   r   Nr   zdefault-keyringr   z/Keyring config file contains incorrect values.
zConfig file: )configparserRawConfigParserreadre   ra   rd   _load_keyring_pathhas_sectiongetstripNoOptionErrorImportErrorlogging	getLoggerwarningr[   )configrS   loggers      r   rF   rF      s     ))+FL07C vi((!::i1BCIIKL %%'   &&4 ""9->ln-./	
 s$   !B 6B 
BBAC)(C)c                    U R                  SS5      R                  5       n[        R                  R	                  S[
        R                  R                  U5      5        g! [        R                  [        R                  4 a     gf = f)z)load the keyring-path option (if present)r   zkeyring-pathr   N)
rl   rm   rP   r#   insertr    
expanduserrg   rn   NoSectionError)rs   r#   s     r   rj   rj      sd    zz)^4::<277--d34&&(C(CD s   AA   $BB)r   backend.KeyringBackendreturnNone)rz   ry   )rz   r{   )r1   strr2   r|   rz   
str | None)r1   r|   r2   r|   r5   r|   rz   r{   )r1   r|   r2   r|   rz   r{   )r1   r|   r2   r}   rz   zcredentials.Credential | None)rz   boolrc   )r@   zLimitCallable | None)rS   r|   rz   ztype[backend.KeyringBackend])rS   r|   rz   ry   )rz   zbackend.KeyringBackend | None)rs   zconfigparser.RawConfigParserrz   r{   ))__doc__
__future__r   rg   rp   r    rP   r    r   r   backendsr   utilr   r   Callabler   r~   LimitCallablerq   __name__logr   r   r   r-   r/   r4   r7   r9   r<   r   r>   rX   r[   rE   ra   re   rF   rj   r   r   r   <module>r      s    #   	 
  "  '!7!7 8$ >?! AO0>
A
:
@@!+@"@!(,'*4&8r   