a
    a*j+                  	   @  s   U d Z ddlmZ ddlmZ ddlmZmZmZ ddddd	Z	G d
d deZ
ee
dde
dde
dde
dde
dde
dddZi Zded< G dd deZeG dd dedZG d d! d!eZG d"d# d#eZG d$d% d%eZG d&d' d'eZG d(d) d)eZG d*d+ d+eZd,S )-     )annotations)total_ordering)ClassVar
NamedTuplecastbytes | str | int | floatstr)valuereturnc                 C  s   t | tr|  S t| S )z4
    normalize a byte/str/int or float to a str
    )
isinstancebytesdecoder	   )r
    r   I/var/www/html/assistant/venv/lib/python3.9/site-packages/limits/limits.pysafe_string
   s    
r   c                   @  s   e Zd ZU ded< ded< dS )Granularityintsecondsr	   nameN)__name__
__module____qualname____annotations__r   r   r   r   r      s   
r   iQ dayi ' monthi yeari  hour<   minute   second)r   r   r   r   r   r!   zdict[str, type[RateLimitItem]]GRANULARITIESc                      s(   e Zd Zdddd d fddZ  ZS )RateLimitItemMetar	   ztuple[type, ...]z"dict[str, Granularity | list[str]])r   parentsdctr   c                   sH   d|vrg |d< t  | |||}d|v rDttt |t|d d < |S )N	__slots__GRANULARITYr    )super__new__r   typeRateLimitItemr"   )clsr   r$   r%   Zgranularity	__class__r   r   r)   '   s    zRateLimitItemMeta.__new__)r   r   r   r)   __classcell__r   r   r-   r   r#   &   s   r#   c                   @  s   e Zd ZU dZg dZded< d#ddd	d
ddZed	ddddZddddZ	dd	dddZ
dddddZd	dddZd ddddZddd d!Zd"S )$r+   a]  
    defines a Rate limited resource which contains the characteristic
    namespace, amount and granularity multiples of the rate limiting window.

    :param amount: the rate limit amount
    :param multiples: multiple of the 'per' :attr:`GRANULARITY`
     (e.g. 'n' per 'm' seconds)
    :param namespace: category for the specific rate limit
    )	namespaceamount	multipleszClassVar[Granularity]r'   r    LIMITERr   z
int | Noner	   )r1   r2   r0   c                 C  s"   || _ t|| _t|pd| _d S )Nr    )r0   r   r1   r2   )selfr1   r2   r0   r   r   r   __init__N   s    
zRateLimitItem.__init__bool)granularity_stringr   c                 C  s   |  | jjv S )z
        Checks if this instance matches a *granularity_string*
        of type ``n per hour``, ``n per minute`` etc,
        by comparing with :attr:`GRANULARITY`

        )lowerr'   r   )r,   r7   r   r   r   check_granularity_stringU   s    	z&RateLimitItem.check_granularity_string)r   c                 C  s   | j j| j S )zM
        :return: the duration the limit is enforced for in seconds.
        )r'   r   r2   r4   r   r   r   
get_expiry`   s    zRateLimitItem.get_expiryr   )identifiersr   c                 G  s>   d dd |D t| jt| j| jjg }| j d| S )a#  
        Constructs a key for the current limit and any additional
        identifiers provided.

        :param identifiers: a list of strings to append to the key
        :return: a string key identifying this resource with
         each identifier separated with a '/' delimiter.
        /c                 S  s   g | ]}t |qS r   )r   ).0kr   r   r   
<listcomp>q       z)RateLimitItem.key_for.<locals>.<listcomp>)joinr   r1   r2   r'   r   r0   )r4   r<   	remainderr   r   r   key_forg   s    		zRateLimitItem.key_forobject)otherr   c                 C  s2   t |tr.| j|jko,| j|jko,| j|jkS dS )NF)r   r+   r1   r'   r2   r4   rF   r   r   r   __eq__{   s    


zRateLimitItem.__eq__c                 C  s   | j  d| j d| jj S )Nz per r   )r1   r2   r'   r   r:   r   r   r   __repr__   s    zRateLimitItem.__repr__c                 C  s   | j j|j jk S N)r'   r   rG   r   r   r   __lt__   s    zRateLimitItem.__lt__c                 C  s   t | j| j| j| jfS rJ   )hashr0   r1   r2   r'   r:   r   r   r   __hash__   s    zRateLimitItem.__hash__N)r    r3   )r   r   r   __doc__r&   r   r5   classmethodr9   r;   rD   rH   rI   rK   rM   r   r   r   r   r+   :   s   

 
	r+   )	metaclassc                   @  s   e Zd ZdZed ZdS )RateLimitItemPerYearz)
    per year rate limited resource.
    r   Nr   r   r   rN   
TIME_TYPESr'   r   r   r   r   rQ      s   rQ   c                   @  s   e Zd ZdZed ZdS )RateLimitItemPerMonthz*
    per month rate limited resource.
    r   NrR   r   r   r   r   rT      s   rT   c                   @  s   e Zd ZdZed ZdS )RateLimitItemPerDayz(
    per day rate limited resource.
    r   NrR   r   r   r   r   rU      s   rU   c                   @  s   e Zd ZdZed ZdS )RateLimitItemPerHourz)
    per hour rate limited resource.
    r   NrR   r   r   r   r   rV      s   rV   c                   @  s   e Zd ZdZed ZdS )RateLimitItemPerMinutez+
    per minute rate limited resource.
    r   NrR   r   r   r   r   rW      s   rW   c                   @  s   e Zd ZdZed ZdS )RateLimitItemPerSecondz+
    per second rate limited resource.
    r!   NrR   r   r   r   r   rX      s   rX   N)rN   
__future__r   	functoolsr   Zlimits.typingr   r   r   r   r   dictrS   r"   r   r*   r#   r+   rQ   rT   rU   rV   rW   rX   r   r   r   r   <module>   s.   	S					