o
    œ¨Êh›  ã                   @   sà   d 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 ddlmZ ddlmZ e e¡Zdad	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze d¡Zd dd„Zdd„ Zdd„ Zdd„ Z dd„ Z!eƒ  dS )!z1
Core API functions and initialization routines.
é    Né   )ÚconfigparserÚfilter)Úmax©Úbackend)Ú	platform_)Úfailc                 C   s   t | tjƒs
tdƒ‚| adS )z!Set current keyring backend.
    z0The keyring must be a subclass of KeyringBackendN)Ú
isinstancer   ÚKeyringBackendÚ	TypeErrorÚ_keyring_backend)Úkeyring© r   ú>/var/www/html/env/lib/python3.10/site-packages/keyring/core.pyÚset_keyring   s   r   c                   C   s   t S )z!Get current keyring backend.
    )r   r   r   r   r   Úget_keyring    s   r   c                 C   s   t  | |¡S )z-Get password from the specified service.
    )r   Úget_password©Úservice_nameÚusernamer   r   r   r   &   s   r   c                 C   s   t  | ||¡ dS )z8Set password for the user in the specified service.
    N)r   Úset_password)r   r   Úpasswordr   r   r   r   ,   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   r   2   s   r   c                 C   s
   | j dkS )Nr   )Úpriorityr   r   r   r   Úrecommended8   s   
 r   r   c                 C   s,   t | t ¡ ƒ}ttƒ pt|tjtd�ƒ dS )zR
    Load a keyring specified in the config file or infer the best available.
    )ÚdefaultÚkeyN)	r   r   Úget_all_keyringr   Úload_configr   r	   ÚKeyringÚby_priority)ÚlimitÚkeyringsr   r   r   Úinit_backend>   s
   þr$   c                 C   s,   |   d¡\}}}t|ƒ tj| }t||ƒS )aF  
    Load the keyring class indicated by name.

    These popular names are tested to ensure their presence.

    >>> popular_names = [
    ...      'keyring.backends.Windows.WinVaultKeyring',
    ...      'keyring.backends.OS_X.Keyring',
    ...      'keyring.backends.kwallet.DBusKeyring',
    ...      'keyring.backends.SecretService.Keyring',
    ...  ]
    >>> list(map(_load_keyring_class, popular_names))
    [...]

    These legacy names are retained for compatibility.

    >>> legacy_names = [
    ...  ]
    >>> list(map(_load_keyring_class, legacy_names))
    [...]
    Ú.)Ú
rpartitionÚ
__import__ÚsysÚmodulesÚgetattr)Úkeyring_nameÚmodule_nameÚsepÚ
class_nameÚmoduler   r   r   Ú_load_keyring_classJ   s   

r0   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')
    )r0   r   )r+   Úclass_r   r   r   Úload_keyringf   s   r2   c               	   C   sª   d} t j t ¡ | ¡}t j |¡sdS t ¡ }| |¡ t	|ƒ z| 
d¡r/| dd¡ ¡ }nt dd¡‚W t|ƒS  tjtfyT   t d¡}| dd|  ¡ Y dS w )z8Load a keyring using the config file in the config root.zkeyringrc.cfgNr   zdefault-keyringr   z/Keyring config file contains incorrect values.
zConfig file: %s)ÚosÚpathÚjoinÚplatformÚconfig_rootÚexistsr   ÚRawConfigParserÚreadÚ_load_keyring_pathÚhas_sectionÚgetÚstripÚNoOptionErrorÚImportErrorÚloggingÚ	getLoggerÚwarningr2   )ÚfilenameÚkeyring_cfgÚconfigr+   Úloggerr   r   r   r   q   s(   

þ
ú
ÿür   c              	   C   sB   z|   dd¡ ¡ }tj d|¡ 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>   r(   r4   Úinsertr   r?   ÚNoSectionError)rF   r4   r   r   r   r;   �   s   ÿr;   )N)"Ú__doc__r3   r(   rA   ÚoperatorÚ
py27compatr   r   Ú
py33compatr   Ú r   Úutilr   r6   Úbackendsr	   rB   Ú__name__Úlogr   r   r   r   r   r   r   Ú
attrgetterr!   r$   r0   r2   r   r;   r   r   r   r   Ú<module>   s2    
	



