o
    Vh                     @   s>   d Z ddlmZ ddlmZ ddlmZ G dd dejZdS )	zV
Keyring Chainer - iterates over other viable backends to
discover passwords in each.
   )backend)
properties   )failc                   @   sV   e Zd ZdZdZejdefddZejdd Z	dd	 Z
d
d Zdd Zdd ZdS )ChainerBackendzZ
    >>> ChainerBackend()
    <keyring.backends.chainer.ChainerBackend object at ...>
    Treturnc                 C   s   t | jdkr	dS tjjd S )z
        If there are backends to chain, high priority
        Otherwise very low priority since our operation when empty
        is the same as null.
        r   
   )lenbackendsr   Keyringpriority)cls r   l/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/keyring/backends/chainer.pyr      s   zChainerBackend.priorityc                 C   s&   dd }t |t }t|tjddS )z5
        Discover all keyrings for chaining.
        c                 S   s(   t jpt}t| t o|| o| jdkS )N    )r   _limitbool
isinstancer   r   )keyringlimitr   r   r   allow$   s   
z&ChainerBackend.backends.<locals>.allowT)keyreverse)filterr   get_all_keyringsortedby_priority)r   r   allowedr   r   r   r
      s   zChainerBackend.backendsc                 C   ,   | j D ]}|||}|d ur|  S qd S N)r
   get_password)selfserviceusernamer   passwordr   r   r   r    /      
zChainerBackend.get_passwordc              	   C   s6   | j D ]}z
||||W   S  ty   Y qw d S r   )r
   set_passwordNotImplementedError)r!   r"   r#   r$   r   r   r   r   r&   5   s   
zChainerBackend.set_passwordc              	   C   s4   | j D ]}z	|||W   S  ty   Y qw d S r   )r
   delete_passwordr'   )r!   r"   r#   r   r   r   r   r(   <   s   
zChainerBackend.delete_passwordc                 C   r   r   )r
   get_credential)r!   r"   r#   r   
credentialr   r   r   r)   C   r%   zChainerBackend.get_credentialN)__name__
__module____qualname____doc__viabler   classpropertyfloatr   r
   r    r&   r(   r)   r   r   r   r   r      s    
r   N)r.    r   compatr   r   KeyringBackendr   r   r   r   r   <module>   s
    