o
    KDi                  	   @  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   F/var/www/Datamplify/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&   granularity	__class__r   r   r+   '   s   zRateLimitItemMeta.__new__)r   r   r$   r%   r&   r'   r
   r#   )r   r   r   r+   __classcell__r   r   r0   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    LIMITERr4   r   r5   
int | Noner3   r   c                 C  s"   || _ t|| _t|pd| _d S )Nr    )r3   r   r4   r5   )selfr4   r5   r3   r   r   r   __init__N   s   
zRateLimitItem.__init__granularity_stringr
   boolc                 C  s   |  | jj| jj dh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`

        s)lowerr)   r   )r.   r:   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   r5   r8   r   r   r   
get_expiryc   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>t   s    z)RateLimitItem.key_for.<locals>.<listcomp>)joinr   r4   r5   r)   r   r3   )r8   rA   	remainderr   r   r   key_forj   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-   r4   r)   r5   r8   rI   r   r   r   __eq__~   s   


zRateLimitItem.__eq__c                 C  s   | j  d| j d| jj S )Nz per r   )r4   r5   r)   r   r?   r   r   r   __repr__   s   zRateLimitItem.__repr__c                 C  s   | j j|j jk S N)r)   r   rK   r   r   r   __lt__   s   zRateLimitItem.__lt__c                 C  s   t | j| j| j| jfS rN   )hashr3   r4   r5   r)   r?   r   r   r   __hash__   s   zRateLimitItem.__hash__N)r    r6   )r4   r   r5   r7   r3   r   )r:   r   r
   r;   )r
   r   )rA   r	   r
   r   )rI   rJ   r
   r;   )r
   r   )rI   r-   r
   r;   )r   r   r   __doc__r(   r   r9   classmethodr>   r@   rH   rL   rM   rO   rQ   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   rR   
TIME_TYPESr)   r   r   r   r   rV          rV   c                   @  rU   )RateLimitItemPerMonthz*
    per month rate limited resource.
    r   NrW   r   r   r   r   rZ      rY   rZ   c                   @  rU   )RateLimitItemPerDayz(
    per day rate limited resource.
    r   NrW   r   r   r   r   r[      rY   r[   c                   @  rU   )RateLimitItemPerHourz)
    per hour rate limited resource.
    r   NrW   r   r   r   r   r\      rY   r\   c                   @  rU   )RateLimitItemPerMinutez+
    per minute rate limited resource.
    r   NrW   r   r   r   r   r]      rY   r]   c                   @  rU   )RateLimitItemPerSecondz+
    per second rate limited resource.
    r!   NrW   r   r   r   r   r^      rY   r^   N)r   r	   r
   r   )rR   
__future__r   	functoolsr   limits.typingr   r   r   r   r   dictrX   r"   r   r,   r#   r-   rV   rZ   r[   r\   r]   r^   r   r   r   r   <module>   s0    
	V					