
    9i                       U d Z ddlmZ ddlmZ ddlmZmZmZ d)dZ	 G d de      Z
 e e
dd	       e
d
d       e
dd       e
dd       e
dd       e
dd            Zi Zded<    G d de      Ze G d de             Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Z G d$ d%e      Z G d& d'e      Zy()*     )annotations)total_ordering)ClassVar
NamedTuplecastc                X    t        | t              r| j                         S t        |       S )z4
    normalize a byte/str/int or float to a str
    )
isinstancebytesdecodestr)values    @/var/www/html/venv/lib/python3.12/site-packages/limits/limits.pysafe_stringr   
   s$    
 %||~u:    c                  "    e Zd ZU ded<   ded<   y)Granularityintsecondsr   nameN)__name__
__module____qualname____annotations__ r   r   r   r      s    L
Ir   r   iQ dayi ' monthi yeari  hour<   minute   second)r   r   r   r   r!   r#   zdict[str, type[RateLimitItem]]GRANULARITIESc                  0     e Zd Z	 	 	 	 	 	 	 	 d fdZ xZS )RateLimitItemMetac                    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   parentsdctgranularity	__class__s        r   r+   zRateLimitItemMeta.__new__'   s^     c!!Cgoc4#>C37]#[4M#m,Q/0 r   )r   r   r/   ztuple[type, ...]r0   z"dict[str, Granularity | list[str]]returnr&   )r   r   r   r+   __classcell__)r2   s   @r   r&   r&   &   s3     " 0	
 
 r   r&   c                  ~    e Zd ZU dZg dZded<   	 	 d	 	 	 	 	 ddZedd       ZddZ	ddZ
dd	Zdd
ZddZddZy)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)   c                Z    || _         t        |      | _        t        |xs d      | _        y )Nr"   )r6   r   r7   r8   )selfr7   r8   r6   s       r   __init__zRateLimitItem.__init__N   s&     #&kY^!,r   c                    |j                         | 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.   granularity_strings     r   check_granularity_stringz&RateLimitItem.check_granularity_stringU   sA     "'')OO  ##$A&.
 
 	
r   c                H    | j                   j                  | j                  z  S )zM
        :return: the duration the limit is enforced for in seconds.
        )r)   r   r8   r:   s    r   
get_expiryzRateLimitItem.get_expiryc   s    
 ''$..88r   c                    dj                  |D cg c]  }t        |       c}t        | j                        t        | j                        | j                  j
                  gz         }| j                   d| S c c}w )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.
        /)joinr   r7   r8   r)   r   r6   )r:   identifiersk	remainders       r   key_forzRateLimitItem.key_forj   sr     HH%01[^1DKK(DNN+  %%
	 ..!9+.. 2s   A:c                    t        |t              rO| j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S y)NF)r
   r-   r7   r)   r8   r:   others     r   __eq__zRateLimitItem.__eq__~   sT    e]+u||+ 6$$(9(996NNeoo5
 r   c                f    | j                    d| j                   d| j                  j                   S )Nz per r   )r7   r8   r)   r   rB   s    r   __repr__zRateLimitItem.__repr__   s/    ++eDNN#31T5E5E5J5J4KLLr   c                \    | j                   j                  |j                   j                  k  S N)r)   r   rL   s     r   __lt__zRateLimitItem.__lt__   s%    ''%*;*;*C*CCCr   c                p    t        | j                  | j                  | j                  | j                  f      S rR   )hashr6   r7   r8   r)   rB   s    r   __hash__zRateLimitItem.__hash__   s(    T^^T[[$..$BRBRSTTr   N)r"   LIMITER)r7   r   r8   z
int | Noner6   r   )r?   r   r3   bool)r3   r   )rG   bytes | str | int | floatr3   r   )rM   objectr3   rX   )r3   r   )rM   r-   r3   rX   )r   r   r   __doc__r(   r   r;   classmethodr@   rC   rJ   rN   rP   rS   rV   r   r   r   r-   r-   :   sr     5I&& HQ--&0-AD- 
 
9/(MDUr   r-   )	metaclassc                      e Zd ZdZed   Zy)RateLimitItemPerYearz)
    per year rate limited resource.
    r   Nr   r   r   r[   
TIME_TYPESr)   r   r   r   r_   r_      s     V$Kr   r_   c                      e Zd ZdZed   Zy)RateLimitItemPerMonthz*
    per month rate limited resource.
    r   Nr`   r   r   r   rc   rc      s     W%Kr   rc   c                      e Zd ZdZed   Zy)RateLimitItemPerDayz(
    per day rate limited resource.
    r   Nr`   r   r   r   re   re      s     U#Kr   re   c                      e Zd ZdZed   Zy)RateLimitItemPerHourz)
    per hour rate limited resource.
    r   Nr`   r   r   r   rg   rg      s     V$Kr   rg   c                      e Zd ZdZed   Zy)RateLimitItemPerMinutez+
    per minute rate limited resource.
    r!   Nr`   r   r   r   ri   ri           X&Kr   ri   c                      e Zd ZdZed   Zy)RateLimitItemPerSecondz+
    per second rate limited resource.
    r#   Nr`   r   r   r   rl   rl      rj   r   rl   N)r   rY   r3   r   )r[   
__future__r   	functoolsr   limits.typingr   r   r   r   r   dictra   r$   r   r,   r&   r-   r_   rc   re   rg   ri   rl   r   r   r   <module>rq      s     " $ 4 4* 
 L%(
'
1	+V	4	Wf	%r8$q(#
 13- 2 ( SU/ SU SUl= M - = ] ] r   