o
    ;h+                  	   @  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
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valuebytes | str | int | floatreturnstrc                 C  s   t | tr	|  S t| S )z4
    normalize a byte/str/int or float to a str
    )
isinstancebytesdecoder   )r    r   @/var/www/html/venv/lib/python3.10/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
 fdd	Z  ZS )RateLimitItemMetar   r   parentstuple[type, ...]dct"dict[str, Granularity | list[str]]r
   c                   sH   d|vrg |d< t  | |||}d|v r"t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%   r&   r'   r
   r#   )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Zed'ddZd(ddZ	d)ddZ
d*ddZd+ddZd,d d!Z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    LIMITERr3   r   r4   
int | Noner2   r   c                 C  s"   || _ t|| _t|pd| _d S )Nr    )r2   r   r3   r4   )selfr3   r4   r2   r   r   r   __init__N   s   
zRateLimitItem.__init__granularity_stringr
   boolc                 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.   r9   r   r   r   check_granularity_stringU   s   	z&RateLimitItem.check_granularity_stringc                 C  s   | j j| j S )zM
        :return: the duration the limit is enforced for in seconds.
        )r)   r   r4   r7   r   r   r   
get_expiry`   s   zRateLimitItem.get_expiry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   s    z)RateLimitItem.key_for.<locals>.<listcomp>)joinr   r3   r4   r)   r   r2   )r7   r?   	remainderr   r   r   key_forg   s   		zRateLimitItem.key_forotherobjectc                 C  s2   t |tr| j|jko| j|jko| j|jkS dS )NF)r   r-   r3   r)   r4   r7   rG   r   r   r   __eq__{   s   


zRateLimitItem.__eq__c                 C  s   | j  d| j d| jj S )Nz per r   )r3   r4   r)   r   r=   r   r   r   __repr__   s   zRateLimitItem.__repr__c                 C  s   | j j|j jk S N)r)   r   rI   r   r   r   __lt__   s   zRateLimitItem.__lt__c                 C  s   t | j| j| j| jfS rL   )hashr2   r3   r4   r)   r=   r   r   r   __hash__   s   zRateLimitItem.__hash__N)r    r5   )r3   r   r4   r6   r2   r   )r9   r   r
   r:   )r
   r   )r?   r	   r
   r   )rG   rH   r
   r:   )r
   r   )rG   r-   r
   r:   )r   r   r   __doc__r(   r   r8   classmethodr<   r>   rF   rJ   rK   rM   rO   r   r   r   r   r-   :   s   
 





	
r-   )	metaclassc                   @     e Zd ZdZed ZdS )RateLimitItemPerYearz)
    per year rate limited resource.
    r   Nr   r   r   rP   
TIME_TYPESr)   r   r   r   r   rT          rT   c                   @  rS   )RateLimitItemPerMonthz*
    per month rate limited resource.
    r   NrU   r   r   r   r   rX      rW   rX   c                   @  rS   )RateLimitItemPerDayz(
    per day rate limited resource.
    r   NrU   r   r   r   r   rY      rW   rY   c                   @  rS   )RateLimitItemPerHourz)
    per hour rate limited resource.
    r   NrU   r   r   r   r   rZ      rW   rZ   c                   @  rS   )RateLimitItemPerMinutez+
    per minute rate limited resource.
    r   NrU   r   r   r   r   r[      rW   r[   c                   @  rS   )RateLimitItemPerSecondz+
    per second rate limited resource.
    r!   NrU   r   r   r   r   r\      rW   r\   N)r   r	   r
   r   )rP   
__future__r   	functoolsr   Zlimits.typingr   r   r   r   r   dictrV   r"   r   r,   r#   r-   rT   rX   rY   rZ   r[   r\   r   r   r   r   <module>   s0    
	S					