o
    i                     @  s.  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eZdad<ddZd=ddZd>ddZd?ddZd@ddZdAddZdBddZdCd!d"ZdDdEd%d&Z dDdEd'd(Z!dFd+d,Z"dGd-d.Z#dHd0d1Z$d2d3 Z%d4d5 Z&dHd6d7Z'dId:d;Z(dS )Jz1
Core API functions and initialization routines.
    )annotationsN   )backendcredentials)fail)	platform_keyringbackend.KeyringBackendreturnNonec                 C  s   t | tjs
td| adS )zSet current keyring backend.z1The keyring must be an instance of KeyringBackendN)
isinstancer   KeyringBackend	TypeError_keyring_backend)r    r   R/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/keyring/core.pyset_keyring   s   r   c                   C  s   t du rt  ttjt S )zGet current keyring backend.N)r   init_backendtypingcastr   r   r   r   r   r   get_keyring    s   r   c                  C  s   t  } zt|  W n	 ty   Y nw tj| d}tj|r+d| }t|t	|ddd}|
d W d   dS 1 sCw   Y  dS )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filer   r   r   disable'   s   
"r+   service_namestrusername
str | Nonec                 C     t  | |S )z(Get password from the specified service.)r   get_passwordr,   r.   r   r   r   r1   ?   s   r1   passwordc                 C  s   t  | || dS )z3Set password for the user in the specified service.N)r   set_password)r,   r.   r3   r   r   r   r4   D   s   r4   c                 C  s   t  | | dS )z:Delete the password for the user in the specified service.N)r   delete_passwordr2   r   r   r   r5   I   s   r5   credentials.Credential | Nonec                 C  r0   )z+Get a Credential for the specified service.)r   get_credentialr2   r   r   r   r7   N   s   r7   boolc                 C  s
   | j dkS )Nr   )priority)r   r   r   r   recommendedU   s   
r:   limitLimitCallable | Nonec                 C  s   t t|  dS )z"
    Load a detected backend.
    N)r   _detect_backendr;   r   r   r   r   Y   s   r   c                 C  s0   | t _t pt ptt| t  t t j	d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>   r   r   r   r=   `   s   	r=   keyring_nametype[backend.KeyringBackend]c                 C  s,   |  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moduler   r   r   _load_keyring_classv   s   

rU   c                 C  s   t | }|j | S )z
    Load the specified keyring by name (a fully-qualified name to the
    keyring, such as 'keyring.backends.file.PlaintextKeyring')
    )rU   r9   )rI   class_r   r   r   load_keyring   s   rW   backend.KeyringBackend | Nonec                   C  s&   zt tjd W S  ty   Y dS w )z6Load a keyring configured in the environment variable.PYTHON_KEYRING_BACKENDN)rW   r   environKeyErrorr   r   r   r   rB      s
   rB   c                   C  s   t  d S )Nr   )r   r   r   r   r   r   _config_path   s   r\   c                 C  s   |   st| | S N)r#   FileNotFoundError)r!   r   r   r   _ensure_path   s   r_   c               	   C  s   t  } z| jtt dd W n
 ty   Y dS w t|  z| dr.| dd	 }nW dS W t|S  t j
tfyR   td}|ddt    Y dS 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readr_   r\   r^   _load_keyring_pathhas_sectiongetstripNoOptionErrorImportErrorlogging	getLoggerwarningrW   )configrI   loggerr   r   r   rC      s,   


rC   rl   configparser.RawConfigParserc              	   C  sJ   z|  dd }tjdtj| W dS  tjtj	fy$   Y dS w )z)load the keyring-path option (if present)r   zkeyring-pathr   N)
re   rf   rN   r!   insertr   
expanduserr`   rg   NoSectionError)rl   r!   r   r   r   rc      s   rc   )r   r	   r
   r   )r
   r	   )r
   r   )r,   r-   r.   r-   r
   r/   )r,   r-   r.   r-   r3   r-   r
   r   )r,   r-   r.   r-   r
   r   )r,   r-   r.   r/   r
   r6   )r
   r8   r]   )r;   r<   )rI   r-   r
   rJ   )rI   r-   r
   r	   )r
   rX   )rl   rn   r
   r   ))__doc__
__future__r   r`   ri   r   rN   r    r   r   backendsr   utilr   r   Callabler   r8   LimitCallablerj   __name__logr   r   r   r+   r1   r4   r5   r7   r:   r   r=   rU   rW   rB   r\   r_   rC   rc   r   r   r   r   <module>   s<    












