
    Ki                    X   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m	Z	m
Z
 ddlmZ ddlmZ ej                   e	j"                  gef   Z ej(                  e      ZdaddZdd	Zdd
ZddZddZddZ	 	 	 	 	 	 ddZd dZd!d"dZ d!d"dZ!d#dZ"d$dZ#d%dZ$d Z%d Z&d%dZ'd&dZ(y)'z1
Core API functions and initialization routines.
    )annotationsN   )backendcredentials)fail)	platform_c                R    t        | t        j                        st        d      | ay)zSet current keyring backend.z1The keyring must be an instance of KeyringBackendN)
isinstancer   KeyringBackend	TypeError_keyring_backend)keyrings    X/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/keyring/core.pyset_keyringr      s&     gw556KLL    c                 r    t         
t                t        j                  t        j
                  t               S )zGet current keyring backend.)r   init_backendtypingcastr   r    r   r   get_keyringr       s%    ;;w--/?@@r   c                 |   t        j                         } 	 t        j                  |        t        j
                  j                  | d      }t        j
                  j                  |      rd| }t        |      t        |dd      5 }|j                  d       ddd       y# t        $ r Y w xY w# 1 sw Y   yxY w)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	. O$

MNO O  O Os   B# B2#	B/.B/2B;c                6    t               j                  | |      S )z(Get password from the specified service.)r   get_passwordservice_nameusernames     r   r/   r/   ?   s    =%%lH==r   c                :    t               j                  | ||       y)z3Set password for the user in the specified service.N)r   set_password)r1   r2   passwords      r   r4   r4   D   s    M|Xx@r   c                8    t               j                  | |       y)z:Delete the password for the user in the specified service.N)r   delete_passwordr0   s     r   r7   r7   I   s    M!!,9r   c                6    t               j                  | |      S )z+Get a Credential for the specified service.)r   get_credentialr0   s     r   r9   r9   N   s     =''h??r   c                     | j                   dk\  S )Nr   )priority)r   s    r   recommendedr<   U   s    q  r   c                ,    t        t        |              y)z"
    Load a detected backend.
    N)r   _detect_backendlimits    r   r   r   Y   s     &'r   c                    | t         _        t               xsV t               xsJ t	        t        | t        j                               t        j                         t         j                        S )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                    | j                  d      \  }}}t        |       t        j                  |   }t	        ||      S )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#? Kj{[[%F6:&&r   c                >    t        |       }|j                    |       S )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                 Z    	 t        t        j                  d         S # t        $ r Y yw xY w)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                 0    t        j                         dz  S )Nr   )r   r   r   r   r   _config_pathra      s    !O33r   c                <    | j                         st        |       | S N)r%   FileNotFoundError)r#   s    r   _ensure_pathre      s    ;;=%%Kr   c                    t        j                         } 	 | j                  t        t	                     d       t        |        	 | j                  d      r!| j                  dd      j                         }ny	 t        |      S # t
        $ r Y yw xY w# t         j                  t        f$ r7 t        j                  d      }|j                  ddt	                z          Y yw xY w)	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 2B 	BBAC$#C$c                   	 | j                  dd      j                         }t        j                  j	                  dt
        j                  j                  |             y# t        j                  t        j                  f$ r Y yw xY w)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$ >?g! AO0>
A
:
@@!+@"@!(,'*4&8r   