o
    Vh                      @   s  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eZdadejddfd	d
ZdejfddZd1ddZdededeje fddZdedededdfddZdededdfddZdedeje dejej fddZdefddZ d2deje fddZ!d2deje fdd Z"d!edej#ej fd"d#Z$d!edejfd$d%Z%dejej fd&d'Z&d(d) Z'd*d+ Z(dejej fd,d-Z)d.ej*ddfd/d0Z+dS )3z1
Core API functions and initialization routines.
    N   )backendcredentials)fail)	platform_keyringreturnc                 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   `/var/www/html/construction_image-detection-poc/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usernamec                 C      t  | |S )z(Get password from the specified service.)r   get_passwordr)   r*   r   r   r   r,   =   s   r,   passwordc                 C   s   t  | || dS )z3Set password for the user in the specified service.N)r   set_password)r)   r*   r.   r   r   r   r/   B   s   r/   c                 C   s   t  | | dS )z:Delete the password for the user in the specified service.N)r   delete_passwordr-   r   r   r   r0   G   s   r0   c                 C   r+   )z+Get a Credential for the specified service.)r   get_credentialr-   r   r   r   r1   L   s   r1   c                 C   s
   | j dkS )Nr   )priority)r   r   r   r   recommendedS   s   
r3   limitc                 C   s   t t|  dS )z"
    Load a detected backend.
    N)r   _detect_backendr4   r   r   r   r   W   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_priorityr6   r   r   r   r5   ^   s   	r5   keyring_namec                 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)rA   module_namesep
class_namemoduler   r   r   _load_keyring_classt   s   

rL   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')
    )rL   r2   )rA   class_r   r   r   load_keyring   s   rN   c                   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)rN   r   environKeyErrorr   r   r   r   r:      s
   r:   c                   C   s   t  d S )Nr   )r   r   r   r   r   r   _config_path   s   rR   c                 C   s   |   st| | S N)r    FileNotFoundError)r   r   r   r   _ensure_path   s   rU   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readrU   rR   rT   _load_keyring_pathhas_sectiongetstripNoOptionErrorImportErrorlogging	getLoggerwarningrN   )configrA   loggerr   r   r   r;      s,   


r;   rb   c              	   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)
r[   r\   rE   r   insertr   
expanduserrV   r]   NoSectionError)rb   r   r   r   r   rY      s   rY   )r   NrS   ),__doc__rV   r_   r   rE   r    r   r   backendsr   utilr   r   Callabler
   boolLimitCallabler`   __name__logr   r   r   r(   strOptionalr,   r/   r0   
Credentialr1   r3   r   r5   TyperL   rN   r:   rR   rU   r;   rW   rY   r   r   r   r   <module>   sF    



