o
    œ¨Êh*  ã                   @   sþ   d Z ddlmZ ddlZddlZddlZzddlZW n	 ey#   Y nw ddlm	Z	m
Z
 ddlmZ ddl
mZ ddlmZmZ e e¡ZG d	d
„ d
ejƒZeeƒG dd„ deƒƒZG dd„ deƒZG dd„ deƒZdd„ Zdd„ Zdd„ Ze
jdd„ ƒZdS )z 
Keyring implementation support
é    )Úabsolute_importNé   )ÚerrorsÚutil©Úbackends)Ú
properties)Úadd_metaclassÚfilterc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚKeyringBackendMetazn
    A metaclass that's both an ABCMeta and a type that keeps a registry of
    all (non-abstract) types.
    c                    sD   t t| ƒ |||¡ t| dƒstƒ | _| j}| js | | ¡ d S d S )NÚ_classes)Úsuperr   Ú__init__ÚhasattrÚsetr   Ú__abstractmethods__Úadd)ÚclsÚnameÚbasesÚdictÚclasses©Ú	__class__© úA/var/www/html/env/lib/python3.10/site-packages/keyring/backend.pyr      s   
ÿzKeyringBackendMeta.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r      s    r   c                   @   s`   e Zd ZdZdd„ Zejedd„ ƒƒZejedd„ ƒƒZ	e
jdd	„ ƒZe
jd
d„ ƒZdd„ ZdS )ÚKeyringBackendz]The abstract base class of the keyring, every backend must implement
    this interface.
    c                 C   ó   dS )a½  
        Each backend class must supply a priority, a number (float or integer)
        indicating the priority of the backend relative to all other backends.
        The priority need not be static -- it may (and should) vary based
        attributes of the environment in which is runs (platform, available
        packages, etc.).

        A higher number indicates a higher priority. The priority should raise
        a RuntimeError with a message indicating the underlying cause if the
        backend is not suitable for the current environment.

        As a rule of thumb, a priority between zero but less than one is
        suitable, but a priority of one or greater is recommended.
        Nr   )r   r   r   r   Úpriority.   s    zKeyringBackend.priorityc                 C   s8   t  ¡ �}| j W d   ƒ n1 sw   Y  t|ƒ S ©N)r   ÚExceptionRaisedContextr#   Úbool)r   Úexcr   r   r   Úviable>   s   
ÿ
zKeyringBackend.viablec                 C   s.   | j  d¡\}}}| dd¡}d || jg¡S )zr
        The keyring name, suitable for display.

        The name is derived from module and class name.
        Ú.Ú_ú )r   Ú
rpartitionÚreplaceÚjoinr   )r   ÚparentÚsepÚmod_namer   r   r   r   E   s   zKeyringBackend.namec                 C   r"   )z5Get password of the username for the service
        Nr   ©ÚselfÚserviceÚusernamer   r   r   Úget_passwordQ   ó   zKeyringBackend.get_passwordc                 C   ó
   t  d¡‚)z5Set password for the username of the service
        Úreason)r   ÚPasswordSetError)r3   r4   r5   Úpasswordr   r   r   Úset_passwordW   s   
zKeyringBackend.set_passwordc                 C   r8   )z=Delete the password for the username of the service.
        r9   )r   ÚPasswordDeleteErrorr2   r   r   r   Údelete_password`   s   
zKeyringBackend.delete_passwordN)r   r   r   r   r#   r   ÚClassPropertyÚclassmethodr(   r   ÚabcÚabstractmethodr6   r<   r>   r   r   r   r   r!   '   s    


r!   c                   @   s,   e Zd ZdZejdd„ ƒZejdd„ ƒZdS )ÚCrypterz3Base class providing encryption and decryption
    c                 C   r"   )zEncrypt the value.
        Nr   ©r3   Úvaluer   r   r   Úencryptj   r7   zCrypter.encryptc                 C   r"   )zDecrypt the value.
        Nr   rD   r   r   r   Údecryptp   r7   zCrypter.decryptN)r   r   r   r   rA   rB   rF   rG   r   r   r   r   rC   f   s    
rC   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚNullCrypterz A crypter that does nothing
    c                 C   ó   |S r$   r   rD   r   r   r   rF   {   ó   zNullCrypter.encryptc                 C   rI   r$   r   rD   r   r   r   rG   ~   rJ   zNullCrypter.decryptN)r   r   r   r   rF   rG   r   r   r   r   rH   w   s    rH   c                 C   s&   t jpt j}t d|  |¡}|j dS )zLoad a backend by namer)   N)r   Ú__package__r   Ú	importlibÚimport_module)r   ÚpackageÚmodr   r   r   Ú_load_backend‚   s   
rP   c                  C   s   d} t tt| ƒƒ tƒ  dS )z.ensure that native keyring backends are loaded)ÚkwalletÚOS_XÚSecretServiceÚWindowsN)ÚlistÚmaprP   Ú_load_pluginsr   r   r   r   Ú_load_backends‹   s   
rX   c               	   C   st   dt ƒ vrdS d} tj| d�}|D ]&}zt d|j¡ | ¡ }t|ƒr&|ƒ  W q ty7   t 	d| ¡ Y qw dS )a  
    Locate all setuptools entry points by the name 'keyring backends'
    and initialize them.
    Any third-party library may register an entry point by adding the
    following to their setup.py::

        entry_points = {
            'keyring.backends': [
                'plugin_name = mylib.mymodule:initialize_func',
            ],
        },

    `plugin_name` can be anything, and is only used to display the name
    of the plugin at initialization time.

    `initialize_func` is optional, but will be invoked if callable.
    Úpkg_resourcesNzkeyring.backends)Úgroupz
Loading %szError initializing plugin %s.)
ÚglobalsrY   Úiter_entry_pointsÚlogÚinfor   ÚloadÚcallableÚ	ExceptionÚ	exception)rZ   Úentry_pointsÚepÚ	init_funcr   r   r   rW   ’   s   
€ÿúrW   c                  C   s0   t ƒ  dd„ } tj}t| |ƒ}ttj|td�ƒS )zc
    Return a list of all implemented keyrings that can be constructed without
    parameters.
    c                 S   s"   z| j  W dS  ty   Y dS w )NFT)r#   ÚRuntimeError)Úkeyring_clsr   r   r   Úis_class_viableº   s   þÿz(get_all_keyring.<locals>.is_class_viable)Ú
exceptions)rX   r!   r   r
   rU   r   Úsuppress_exceptionsÚ	TypeError)rh   Úall_classesÚviable_classesr   r   r   Úget_all_keyring²   s   
ÿrn   )r   Ú
__future__r   rA   ÚloggingrL   rY   ÚImportErrorÚ r   r   r   r   Ú
py27compatr	   r
   Ú	getLoggerr   r]   ÚABCMetar   Úobjectr!   rC   rH   rP   rX   rW   Úoncern   r   r   r   r   Ú<module>   s2    ÿ
>	 