o
    KDi                     @  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__ _/var/www/Datamplify/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   errorsNoAvailableNodes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   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!   r2   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*   )r<   r   )r'   r-   decr)r   r(   r;   r<   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*   )rA   F)rA   r<   )	r'   r-   _expiration_keyincraddr   setr   time)	r   r(   rA   r;   rC   r?   r@   
expire_keyr3   r   r   r   rE   @   s$   
 zMemcachioBridge.incrc                   sN   |   I d H }| |d}||I d H |d }|r#t|jp&t S r8   )r'   rD   r-   r,   rB   r3   rH   )r   r(   r?   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/   r0   r   r1   )r(   r   r   r   )r   F)r(   r   r;   r)   r<   r=   r   r)   )r   T)
r(   r   rA   rB   r;   r)   rC   r=   r   r)   )r(   r   r   rB   )r   r=   )__name__
__module____qualname__r   propertyr   r'   r,   r+   r:   r>   rE   rL   rM   __classcell__r   r   r   r   r	      s    	

	


r	   )
__future__r   rH   mathr   typesr   typingr   r   bridger   	memcachior	   r   r   r   r   <module>   s    