
    ez                        d 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ej                  ddfd	Zdej                  fd
Zd dZdededej4                  e   fdZdedededdfdZdededdfdZdedej4                  e   dej4                  ej<                     fdZdefdZ d!dej4                  e   fdZ!d!dej4                  e   fdZ"dedejF                  ej                     fdZ$dedej                  fdZ%dej4                  ej                     fdZ&d Z'd Z(dej4                  ej                     fdZ)dejT                  ddfdZ+y)"z1
Core API functions and initialization routines.
    N   )backendcredentials)	platform_)failkeyringreturnc                 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)r   s    ./usr/lib/python3/dist-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                  x   t        j                         } 	 t        j                  |        t        j
                  j                  | d      }t        j
                  j                  |      rd| }t        |      t        |d      5 }|j                  d       ddd       y# t        $ r Y w xY w# 1 sw Y   yxY w)z4
    Configure the null keyring as the default.
    keyringrc.cfgzRefusing to overwrite wz7[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	 O

MNO O  O Os   B! B0!	B-,B-0B9service_nameusernamec                 6    t               j                  | |      S )z(Get password from the specified service.)r   get_passwordr+   r,   s     r   r.   r.   6   s    =%%lH==r   passwordc                 :    t               j                  | ||       y)z3Set password for the user in the specified service.N)r   set_password)r+   r,   r0   s      r   r2   r2   ;   s    M|Xx@r   c                 8    t               j                  | |       y)z:Delete the password for the user in the specified service.N)r   delete_passwordr/   s     r   r4   r4   @   s    M!!,9r   c                 6    t               j                  | |      S )z+Get a Credential for the specified service.)r   get_credentialr/   s     r   r6   r6   E   s     =''h??r   c                      | j                   dk\  S )Nr   )priority)r   s    r   recommendedr9   L   s    q  r   limitc                 ,    t        t        |              y)z"
    Load a detected backend.
    N)r   _detect_backendr:   s    r   r   r   P   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<   W   sQ     GN
 	
=	
5'1134LLN##	
	r   keyring_namec                     | 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)rI   module_namesep
class_namemodules        r   _load_keyring_classrU   m   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')
    )rU   r8   )rI   class_s     r   load_keyringrX      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)rX   r   environKeyErrorr   r   r   rB   rB      s.    BJJ'?@AA s    	**c                  0    t        j                         dz  S )Nr   )r   r   r   r   r   _config_pathr^      s    !O33r   c                 <    | j                         st        |       | S N)r"   FileNotFoundError)r    s    r   _ensure_pathrb      s    ;;=%%Kr   c                     t        j                         } 	 | j                  t        t	                     d       t        |        	 | j                  d      r!| j                  dd      j                         }nt        j                  dd      	 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.zutf-8)encodingNr   zdefault-keyringr   z/Keyring config file contains incorrect values.
zConfig file: )configparserRawConfigParserreadrb   r^   ra   _load_keyring_pathhas_sectiongetstripNoOptionErrorImportErrorlogging	getLoggerwarningrX   )configrI   loggers      r   rC   rC      s     ))+FL07C vi(!::i1BCIIKL,,Y8IJJ  %%'   &&4 ""9->ln-./	
 s%   $B AB) 	B&%B&)AC98C9rq   c                     	 | j                  dd      j                         }t        j                  j	                  d|       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)rj   rk   rN   r    insertre   rl   NoSectionError)rq   r    s     r   rh   rh      sU    zz)^4::<4 &&(C(CD s   A A #A)(A))r	   Nr`   ),__doc__re   r   rN   rn   r    r   r   utilr   r   backendsr   Callabler   boolLimitCallablero   __name__logr   r   r   r*   strOptionalr.   r2   r4   
Credentialr6   r9   r   r<   TyperU   rX   rB   r^   rb   rC   rf   rh   r   r   r   <module>r      s    	 
   " ' !7!7 8$ >?g! // D AW++ AO">s >c >fooc6J >
As Ac AS AT A
:# : : :
@@!'!5@__[++,@!D !(6 (6??=9 ,'c 'fkk':P:P.Q '*s w'='= &//'"8"89 4&V__W%;%;< &8|;;  r   