o
    ;h                     @  sh   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	 ddl
mZ er*d dlZG dd	 d	eZdS )
    )annotationsN)ceil)
ModuleType)TYPE_CHECKINGIterable   )MemcachedBridgec                      s   e Zd Zd- fd	d
Zed.ddZd/ddZd0ddZd1ddZd2ddZ	d3d4d!d"Z
	#d5d6d'd(Zd7d)d*Zd8d+d,Z  ZS )9MemcachioBridgeuristr
dependencyr   optionsfloat | str | boolreturnNonec                   s    t  j||fi | d | _d S N)super__init___storage)selfr
   r   r   	__class__ Y/var/www/html/venv/lib/python3.10/site-packages/limits/aio/storage/memcached/memcachio.pyr      s   
zMemcachioBridge.__init__-type[Exception] | tuple[type[Exception], ...]c                 C  s   | j jj| j jjfS r   )r   errorsZNoAvailableNodesZMemcachioConnectionErrorr   r   r   r   base_exceptions   s   zMemcachioBridge.base_exceptionsmemcachio.Client[bytes]c                   s<   | j s| jjdd | jD fi | j| _ | j sJ | j S )Nc                 S  s   g | ]\}}||fqS r   r   ).0hpr   r   r   
<listcomp>$   s    z/MemcachioBridge.get_storage.<locals>.<listcomp>)r   r   ZClienthostsr   r   r   r   r   get_storage!   s   
zMemcachioBridge.get_storagekeyintc                   s"   |  |gI d H |ddS )Nutf-8r   )get_manygetencoder   r%   r   r   r   r)   *   s    zMemcachioBridge.getkeysIterable[str]dict[bytes, int]c                   s8   |   I dH jdd |D  I dH }dd | D S )zo
        Return multiple counters at once

        :param keys: the keys to get the counter values for
        Nc                 S  s   g | ]}| d qS )r'   )r*   )r   kr   r   r   r"   4   s    z,MemcachioBridge.get_many.<locals>.<listcomp>c                 S  s   i | ]
\}}|t |jqS r   )r&   value)r   r/   vr   r   r   
<dictcomp>6   s    z,MemcachioBridge.get_many.<locals>.<dictcomp>)r$   r)   items)r   r,   resultsr   r   r   r(   -   s
   
zMemcachioBridge.get_manyc                   s&   |   I d H |dI d H  d S Nr'   )r$   deleter*   r+   r   r   r   clear8   s   $zMemcachioBridge.clearr   Famountnoreplyboolc                   s4   |   I d H }|d}|j|||dI d H pdS )Nr'   )r9   r   )r$   r*   decr)r   r%   r8   r9   storage	limit_keyr   r   r   r;   ;   s   
zMemcachioBridge.decrTexpiryfloatset_expiration_keyc           	        s   |   I d H }|d}| | }|||I d H  }d u re|   I d H }|j||  t|dI d H rS|rQ|j|t|t  dt|ddI d H  |S |   I d H }|||I d H pd|S |S )Nr'   )r>   F)r>   r9   )	r$   r*   _expiration_keyincraddr   setr   time)	r   r%   r>   r8   r@   r<   r=   Z
expire_keyr0   r   r   r   rB   @   s$   
 zMemcachioBridge.incrc                   sN   |   I d H }| |d}||I d H |d }|r#t|jp&t S r5   )r$   rA   r*   r)   r?   r0   rE   )r   r%   r<   Zexpiration_keyitemr   r   r   
get_expiryV   s
   zMemcachioBridge.get_expiryc                   s4   z|   I dH }|dI dH  W dS    Y dS )zq
        Check if storage is healthy by calling the ``get`` command
        on the key ``limiter-check``
        Ns   limiter-checkTF)r$   r)   )r   r<   r   r   r   check]   s   zMemcachioBridge.check)r
   r   r   r   r   r   r   r   )r   r   )r   r   )r%   r   r   r&   )r,   r-   r   r.   )r%   r   r   r   )r   F)r%   r   r8   r&   r9   r:   r   r&   )r   T)
r%   r   r>   r?   r8   r&   r@   r:   r   r&   )r%   r   r   r?   )r   r:   )__name__
__module____qualname__r   propertyr   r$   r)   r(   r7   r;   rB   rG   rH   __classcell__r   r   r   r   r	      s    	

	


r	   )
__future__r   rE   mathr   typesr   typingr   r   Zbridger   Z	memcachior	   r   r   r   r   <module>   s    