
    i0                        d Z ddlZddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0  ed          Z1ee2ede2f         f         Z3 G d d          Z4 G d d          Z5dZ6de&de-de)fdZ7 G d d          Z8dS ) z0
The starlette extension to rate-limit requests
    N)datetime)
formatdateparsedate_to_datetime)wraps)	AnyCallableDictListOptionalSetTupleTypeVarUnion)RateLimitItem)ConfigurationError)MemoryStoragestorage_from_string)
STRATEGIESRateLimiter)Config)MutableHeaders)Request)JSONResponseResponse)Literal   )RateLimitExceeded)Limit
LimitGroupT.c                   R    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdS )CRATELIMIT_ENABLEDRATELIMIT_HEADERS_ENABLEDRATELIMIT_STORAGE_URLRATELIMIT_STORAGE_OPTIONSRATELIMIT_STRATEGYRATELIMIT_GLOBALRATELIMIT_DEFAULTRATELIMIT_APPLICATIONRATELIMIT_HEADER_LIMITRATELIMIT_HEADER_REMAININGRATELIMIT_HEADER_RESETRATELIMIT_SWALLOW_ERRORSRATELIMIT_IN_MEMORY_FALLBACK$RATELIMIT_IN_MEMORY_FALLBACK_ENABLEDRATELIMIT_HEADER_RETRY_AFTER"RATELIMIT_HEADER_RETRY_AFTER_VALUERATELIMIT_KEY_PREFIXN)__name__
__module____qualname__ENABLEDHEADERS_ENABLEDSTORAGE_URLSTORAGE_OPTIONSSTRATEGYGLOBAL_LIMITSDEFAULT_LIMITSAPPLICATION_LIMITSHEADER_LIMITHEADER_REMAININGHEADER_RESETSWALLOW_ERRORSIN_MEMORY_FALLBACKIN_MEMORY_FALLBACK_ENABLEDHEADER_RETRY_AFTERHEADER_RETRY_AFTER_VALUE
KEY_PREFIX     a/var/www/html/crypto-mining-system/backend/venv/lib/python3.11/site-packages/slowapi/extension.pyr"   r"   -   si        !G1O)K1O#H&M(N0+L3+L/N7!G7C'JJJrI   r"   c                       e Zd ZdZdZdZdZdS )HEADERSr            N)r4   r5   r6   RESET	REMAININGLIMITRETRY_AFTERrH   rI   rJ   rL   rL   A   s"        EIEKKKrI   rL      requestexcreturnc                     t          dd|j         id          }| j        j        j                            || j        j                  }|S )z
    Build a simple JSON response that includes the details of the rate limit
    that was hit. If no limit is hit, the countdown is added to headers.
    errorzRate limit exceeded: i  )status_code)r   detailappstatelimiter_inject_headersview_rate_limit)rU   rV   responses      rJ   _rate_limit_exceeded_handlerrb   K   s]    
 	6#*667S  H { (88'-/ H OrI   c            #       J   e Zd ZdZg g dddi ddg ddddddfdedef         d	ee         d
ee         dede	e         de	e         de
eef         dededee         dede	e         dedede	e         ded         ddf"dZd=dZd>dededefdZdefdZd=d Zedefd!            Zd"ed#eeee         f         defd$Zd%ed#eeee         f         defd&Zd'ed(ed)ee         ddfd*Zdefd+Z	 d?d'ed,e	ede f                  d-eddfd.Z!	 	 	 	 	 	 	 	 	 d@d0ede	edef                  d1ed2e	e         d3ed4e	ee                  d5e	e         d6e	edef                  d7e"eedef         f         d8edede f         fd9Z#	 	 	 	 	 	 	 dAd0ede	edef                  d3ed4e	ee                  d5e	e         d6e	edef                  d7e"eedef         f         d8edefd:Z$	 	 	 	 	 dBd0ed2ede	edef                  d5e	e         d6e	edef                  d7e"eedef         f         d8edefd;Z%d< Z&dS )CLimitera1  
    Initializes the slowapi rate limiter.

    ** parameter **

    * **app**: `Starlette/FastAPI` instance to initialize the extension
     with.

    * **default_limits**: a variable list of strings or callables returning strings denoting global
     limits to apply to all routes. `ratelimit-string` for  more details.

    * **application_limits**: a variable list of strings or callables returning strings for limits that
     are applied to the entire application (i.e a shared limit for all routes)

    * **key_func**: a callable that returns the domain to rate limit by.

    * **headers_enabled**: whether ``X-RateLimit`` response headers are written.

    * **strategy:** the strategy to use. refer to `ratelimit-strategy`

    * **storage_uri**: the storage location. refer to `ratelimit-conf`

    * **storage_options**: kwargs to pass to the storage implementation upon
      instantiation.
    * **auto_check**: whether to automatically check the rate limit in the before_request
     chain of the application. default ``True``
    * **swallow_errors**: whether to swallow errors when hitting a rate limit.
     An exception will still be logged. default ``False``
    * **in_memory_fallback**: a variable list of strings or callables returning strings denoting fallback
     limits to apply when the storage is down.
    * **in_memory_fallback_enabled**: simply falls back to in memory storage
     when the main storage is down and inherits the original limits.
    * **key_prefix**: prefix prepended to rate limiter keys.
    * **enabled**: set to False to deactivate the limiter (default: True)
    * **config_filename**: name of the config file for Starlette from which to load settings
     for the rate limiter. Defaults to ".env".
    * **key_style**: set to "url" to use the url, "endpoint" to use the view_func
    FNT urlkey_func.default_limitsapplication_limitsheaders_enabledstrategystorage_uristorage_options
auto_checkswallow_errorsin_memory_fallbackin_memory_fallback_enabledretry_after
key_prefixenabledconfig_filename	key_style)endpointrf   rW   c                    t          j        d          | _        t          j                            d          }t          |r|dn|          | _        || _        g | _	        g | _
        g | _        |pt          |
          dk    | _        t                      | _        g | _        || _        i | _        || _        || _        || _        || _        || _        |	| _        || _        || _        || _        t          |          D ]7}| j	                            t;          || j        ddddddd	  	        g           8|D ]7}| j
                            t;          || j        ddddddd	  	        g           8|
D ]7}| j                            t;          || j        ddddddd	  	        g           8i | _        i | _        d| _         d| _!        d| _"        tG          j#                    | _$        i | _%         G d d	t           j&                  }| j        '                     |                       | (                    tR          j*        | j                  | _        | (                    tR          j+        | j                  | _        | j        p| (                    tR          j,        d          | _        | j        -                    | (                    tR          j.        i                      t_          | j        p| (                    tR          j0        d
          fi | j        | _1        | j        p| (                    tR          j2        d          }|tf          vrti          d|z            tg          |         | j1                  | _5        | j        -                    tl          j7        | j        8                    tl          j7        | (                    tR          j9        d                    tl          j:        | j        8                    tl          j:        | (                    tR          j;        d                    tl          j<        | j        8                    tl          j<        | (                    tR          j=        d                    tl          j>        | j        8                    tl          j>        | (                    tR          j?        d                    i           | j        p| (                    tR          j@                  | _        | j        p| (                    tR          jA                  | _        | (                    tR          jB        d          }| j
        s$|r"t;          || j        ddddddd	  	        g| _
        | (                    tR          jC        d          }| j	        s$|r"t;          || j        ddddddd	  	        g| _	        | (                    tR          jD        d          }| (                    tR          jE        d          }| j        s$|r"t;          || j        ddddddd	  	        g| _        | j        s|pt          | j                  dk    | _        | j        r4t                      | _G        tg          |         | jG                  | _!        dS dS )z9
        Configure the rate limiter at app level
        slowapiz.envNr   Fr   globalc                       e Zd Zd ZdS )*Limiter.__init__.<locals>.BlackHoleHandlerc                      d S NrH   )_s    rJ   emitz/Limiter.__init__.<locals>.BlackHoleHandler.emit   s    rI   N)r4   r5   r6   r   rH   rI   rJ   BlackHoleHandlerr|      s#            rI   r   z	memory://zfixed-windowz!Invalid rate limiting strategy %szX-RateLimit-ResetzX-RateLimit-RemainingzX-RateLimit-LimitRetry-After)Hlogging	getLoggerloggerospathisfiler   
app_configrt   _default_limits_application_limits_in_memory_fallbacklen_in_memory_fallback_enabledset_exempt_routes_request_filters_headers_enabled_header_mapping_retry_after	_strategy_storage_uri_storage_options_auto_check_swallow_errors	_key_func_key_prefix
_key_styleextendr   _route_limits_dynamic_route_limits_storage_dead_fallback_limiter_Limiter__check_backend_counttime_Limiter__last_check_backend_Limiter__marked_for_limitingStreamHandler
addHandlerget_app_configr"   r7   rB   r8   updater:   r   r9   _storager;   r   r   _limiterrL   rP   getrA   rQ   r@   rR   r?   rS   rE   rF   rG   r>   r=   rD   rC   r   _fallback_storage)selfrg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   dotenv_file_existslimitr   
app_limitsconf_limitsfallback_enabledfallback_limitss                           rJ   __init__zLimiter.__init__   s   6 '	22W^^F33 !!&5&= F 
 
 !#% 57 &E#.@*A*AA*E 	( ),;= //1+6!' /%-!%#(( 	 	E ''t~tUD$aQV     ( 	 	E$++ 
 
    ( 	 	E$++t~tUD$aQV     68BD"#(!%%&"$(IKK!@B"	 	 	 	 	w4 	 	 	 	//11222**19dlCC#22d2 
  
 !% 5 !
9L9Lu:
 :
 	$$T%8%89JB%O%OPPP+P!4!4Q]K!P!P
 
#
 
 >TT%8%8^%T%T:%%$%H8%STTT%/%9$-%H%H##t377M''8KLL    !4#7#;#;%''(:<STT$ $ t377M''8KLL    #T%9%=%='''(<mLL& &	
 	
 	
( !- 
1D1D&2
 2
  +Pt/B/B1</P/P151D1D $2
 2

 ' 	J 	N
 
(D$ 372E2Ed3
 3
 # 	 	udD$PQSX $D 
  ..q/KUSS6:6I6I $7
 7
 ' 	O 	#N
 
(D$ / 	 EC(@$A$AA$E , + 	R%2__D"%/%9$:P%Q%QD"""	R 	RrI   c                 r    | t           j        _        t                               t          t
                     dS )z_
        Starlette startup event handler that links the app with the Limiter instance.
        N)r\   r]   r^   add_exception_handlerr   rb   r   s    rJ   slowapi_startupzLimiter.slowapi_startupH  s,     !	!!"35QRRRRRrI   keydefault_valuec                 ~    |r%|                      ||t          |                    n|                      ||          S )zQ
        Place holder until we find a better way to load config from app
        )defaultcast)r   )r   type)r   r   r   s      rJ   r   zLimiter.get_app_configO  sC     =DOOCT-=P=POQQQm<<	
rI   c                     | j         t          k    rd| _         t          j                    | j        z
  t	          d| j                   k    r*t          j                    | _        | xj         dz  c_         dS dS )Nr   rM   r   TF)r   MAX_BACKEND_CHECKSr   r   powr   s    rJ   __should_check_backendzLimiter.__should_check_backendY  sk    %(:::)*D&9;;22SD<V5W5WWW(,	D%&&!+&&4urI   c                     	 | j                                          | j                            d           dS # t          $ r | j                            d           Y dS w xY w)z?
        resets the storage if it supports being reset
        z-Storage has been reset and all limits clearedz.This storage type does not support being resetN)r   resetr   infoNotImplementedErrorwarningr   s    rJ   r   zLimiter.resetb  sx    	RM!!!KLMMMMM" 	R 	R 	RK PQQQQQQ	Rs   37 $AAc                 \    | j         r| j        r| j        s
J d            | j        S | j        S )zT
        The backend that keeps track of consumption of endpoints vs limits
        z=Fallback limiter is needed when in memory fallback is enabled)r   r   r   r   r   s    rJ   r^   zLimiter.limiterl  sN    
  	!$"B 	!&O ONO O&))= rI   ra   current_limitc                    | j         r8| j        r0|-t          |t                    st	          d          	  | j        j        |d         g|d         R  }d|d         z   }|j                            | j	        t          j                 t          |d         j                             |j                            | j	        t          j                 t          |d                              |j                            | j	        t          j                 t          |                     |j                            d          }|#t#          |                     |          |          }| j        dk    rt)          |          n/t          t+          |t-          j                    z
                      |j        | j	        t          j                 <   no#  | j        r>| j        s7| j                            d           d| _        |                     ||          }| j        r| j                            d           n Y nxY w|S )	NzHparameter `response` must be an instance of starlette.responses.Responser   r   r   	http-dateBRate limit storage unreachable - falling back to in-memory storageT5Failed to update rate limit headers. Swallowing error)rt   r   
isinstancer   	Exceptionr^   get_window_statsheadersappendr   rL   rR   stramountrQ   rP   r   max_determine_retry_timer   r   intr   rS   r   r   r   r   r_   r   	exception)r   ra   r   window_statsreset_inexisting_retry_after_headers         rJ   r_   zLimiter._inject_headersy  sk    < /	D1 /	m6Oh11 ^  *0M0M!!$1'4Q'71 1 1 |A. ''(7]1=M=T9U9U    ''():;Sa=Q=Q    ''(7X  
 /7.>.B.B=.Q.Q+.:"223NOO    H (K77 x(((SDIKK!78899  !5g6I!JKK
+ MD4F MK''-   *.D&#33HmLLH' K))O    	 
 s   FG A*H>r   c                    | j         r| j        r|	  | j        j        |d         g|d         R  }d|d         z   }t	          |d         j                  || j        t          j                 <   t	          |d                   || j        t          j	                 <   t	          |          || j        t          j
                 <   |                    d          }|#t          |                     |          |          }| j        dk    rt          |          n/t	          t!          |t#          j                    z
                      || j        t          j                 <   nx# t&          $ rk | j        r>| j        s7| j                            d           d| _        |                     ||          }| j        r| j                            d           n Y nw xY w|S )	a!  
        Injects 'X-RateLimit-Reset', 'X-RateLimit-Remaining', 'X-RateLimit-Limit'
        and 'Retry-After' headers into :headers parameter if needed.

        Basically the same as _inject_headers, but without access to the Response object.
        -> supports ASGI Middlewares.
        Nr   r   r   r   r   Tr   )rt   r   r^   r   r   r   r   rL   rR   rQ   rP   r   r   r   r   r   r   r   rS   r   r   r   r   r   _inject_asgi_headersr   r   )r   r   r   r   r   r   s         rJ   r   zLimiter._inject_asgi_headers  s    < '	D1 '	m6O&0M0M!!$1'4Q'71 1 1 |A.?B!!$+@ @,W];< DG|TUCWCW,W->?@?B8}},W];< /6kk-.H.H+.:"223NOO    H (K77 x(((SDIKK!78899 ,W-@ABB
    + PD4F PK''-   *.D&"77OOG' K))O    	  s   EE" "A2GGrU   rw   limitsc                 b   d }d }|D ]}|j         p|}|j        r|j        !|j                                        |j        vr<|j        r|d|j        z  z  }dt          j        |j                  j	        
                                v r|                    |          }n|                                }||g}	t          |	          r| j        r| j        g|	z   }	|r|j        |d         k     r	|j        |	f}t          |j                  r|                    |          n|j        }
 | j        j        |j        g|	R d|
is/| j                            d|j        ||           |}|j        |	f} n$i| j                            d|j                   ||j        _        |rt/          |          d S )Nz:%srU   r   costz*ratelimit %s (%s) exceeded at endpoint: %sz4Skipping limit: %s. Empty value found in parameters.)scope	is_exemptmethodsmethodlower
per_methodinspect	signaturerg   
parameterskeysallr   r   callabler   r^   hitr   r   rY   r]   r`   r   )r   rU   rw   r   failed_limitlimit_for_headerlimlimit_scope	limit_keyargsr   s              rJ   __evaluate_limitszLimiter.__evaluate_limits  s      $	 $	C)/xK} {&7>+?+?+A+A+T+T~ 6uw~55G-cl;;FKKMMMMLL11		LLNN	{+D4yy # 5 ,-4D' 9397G7J+J+J(+	4'8$,4SX,>,>Lsxx(((CH't|'	DDDDDtDD 	K''D	!#	   $'L(+	4'8$E	 !!JCI   (8% 	2#L111	2 	2rI   c                 b   	 t          |          }n# t          t          f$ r d }Y nw xY w|3t          t	          j        |                                                    S 	 t          |          }n# t          $ r t          d          w xY wt          t	          j                    |z             S )NzQRetry-After Header does not meet RFC2616 - value is not of http-date or int type.)r   	TypeError
ValueErrorr   r   mktime	timetuple)r   retry_header_valueretry_after_dateretry_after_ints       rJ   r   zLimiter._determine_retry_time  s    	$3H"4 4 :& 	$ 	$ 	$#	$ 't{#3#=#=#?#?@@AAA	#&'9#:#:OO 	 	 	c  	
 49;;0111s    ((!A1 1Bendpoint_funcin_middlewarec                    |d         pd}|}|r|j          d|j         nd}| j        dk    r|n|}|r.| j        r'|| j        v st          d | j        D                       rdS g }g }	|s|| j        v r| j        |         ng }g }	|| j        v ry| j        |         D ]k}
	 |		                    t          |
                    |                               9# t          $ r&}| j                            d||           Y d}~dd}~ww xY w	 g }| j        r| j        r|r
|| j        v rnv|                                 rB| j                                        r)| j                            d           d	| _        d
| _        n t          t/          j        | j                   }|sy||	z   }|r t          t/          j        | j                   ng }||z  }t7          d |D                       }|s|r|| j        v r|r#|t          t/          j        | j                   z  }|                     |||           dS # t<          $ r}t?          |t@                    r | j!        r@| j        s9| j        "                    d           d| _        | #                    |||           n#| j$        r| j        %                    d           n Y d}~dS Y d}~dS d}~ww xY w)z;
        Determine if the request is within limits
        r   re   .rf   c              3   *   K   | ]} |            V  d S r~   rH   ).0fns     rJ   	<genexpr>z/Limiter._check_request_limit.<locals>.<genexpr>=  s(      88B2244888888rI   Nz2failed to load ratelimit for view function %s (%s)zRate limit storage recoveredFr   c              3   &   K   | ]}|j          V  d S r~   )override_defaults)r  r   s     rJ   r  z/Limiter._check_request_limit.<locals>.<genexpr>i  s9       ( (49//( ( ( ( ( (rI   r   Tz&Failed to rate limit. Swallowing error)&r5   r4   r   rt   r   anyr   r   r   r   listwith_requestr   r   rY   r   r   r   _Limiter__should_check_backendr   checkr   r   	itertoolschainr   r   r   r   _Limiter__evaluate_limitsr   r   r   r   warn_check_request_limitr   r   )r   rU   r   r   endpoint_url	view_funcendpoint_func_name_endpoint_keyr   dynamic_limitsr   e
all_limitsroute_limitscombined_defaultss                  rJ   r  zLimiter._check_request_limit&  s     v,"!	 ?HOy#::i&8:::R 	 )-5(@(@FX 	<	
 "T%88888$"788888 9 F &( 	 &);;; "#566 
  N!T%???56HI  C&--d33C3CG3L3L.M.MNNNN%   ))P.       0	&(J! 	Vd&< 	V  V%74;U%U%U2244 V9L9L9N9N V(()GHHH-2*5622%))/4;S*T%U%U
 O,2^,C %D$*BCDDD 
 l*
$' ( (=I( ( ( % %! %O &O /$2LLL( M $y8L'M"N"NNJ""7M:FFFFF 	 	 	!.// / 8J   )   &*"))'=-PPPP' K))*RSSSS QPPPPP TSSSSS	s2   5C
DC==DD$H, ,
K6B KKr   limit_valuesharedr   r   r   error_messageexempt_whenr   r  c                 l    	
 |r|nd dt           dt          f         f	
 f
d}|S )Nfunc.c                 R  
  pj         } j         d j         }d }g }t                    rt	          |	  	        }nY	 t          t	          |	  	                  }n3# t          $ r&}j                            d||           Y d }~nd }~ww xY wj	        
                    |g                                           |r/j        
                    |g                               |           n.j        
                    |g                               |           d }t          j                   }t#          |j                                                  D ]$\  }|j        dk    s|j        dk    r	|j        } n%t+          d  d          t-          j                   r9t1          j                   dt4          dt4          d	t6          f fd
            }	|	S t1          j                   dt4          dt4          d	t6          f fd            }
|
S )Nr  z*Failed to configure throttling for %s (%s)rU   	websocketz2No "request" or "websocket" argument on function ""r   kwargsrW   c                    K   j         r|                    d| r|          nd           }t          |t                    st	          d          j        r9t          |j        dd          s#                    |d           d|j        _	         | i | d {V }j         rit          |t                    s4                    |                    d          |j        j                   n                     ||j        j                   |S NrU   zEparameter `request` must be an instance of starlette.requests.Request_rate_limiting_completeFTra   rt   r   r   r   r   r   getattrr]   r  r'  r   r_   r`   r   r$  rU   ra   r   idxr   s       rJ   async_wrapperzCLimiter.__limit_decorator.<locals>.decorator.<locals>.async_wrapper  sI      | I"(**YT8SS		t"T"T)'7;; "+ g# #   + IG#M+De5 5 I !55gtUKKKDHGMA%)T4%:6%:%:::::::H| 	)(H==  00 &

: 6 68U    !00 ('-*G   $OrI   c                     j         r|                    d| r|          nd           }t          |t                    st	          d          j        r9t          |j        dd          s#                    |d           d|j        _	         | i |}j         rit          |t                    s4                    |                    d          |j        j                   n                     ||j        j                   |S r&  r(  r*  s       rJ   sync_wrapperzBLimiter.__limit_decorator.<locals>.decorator.<locals>.sync_wrapper  s3    | I"(**YT8SS		t"T"T)'7;; "+ g# #   + IG#M+De5 5 I !55gtUKKKDHGMA#tT4V44H| 	)(H==  00 &

: 6 68U    !00 ('-*G   $OrI   )r   r5   r4   r   r   r	  r   r   rY   r   
setdefaultr   r   r   r   r   r   	enumerater   valuesnamer   asyncioiscoroutinefunction	functoolsr   r   r   )r   keyfuncr2  dynamic_limitstatic_limitsr  connection_typesig	parameterr,  r.  r+  _scoper   r  r  rg   r  r   r  r   r   s   `          @rJ   	decoratorz,Limiter.__limit_decorator.<locals>.decorator  s   0$.Go7777D M)+M$$   *!%
! 
!$("'#"&#)' -
 
% %MM "   K%%D        &11$;;BB4HHH N*55dB??FF}UUUU"--dB77>>}MMM-1O#D))C"+CN,A,A,C,C"D"D  Y>Y..).K2O2O&/nOE 3P  PPPP   *400 >$&&$s $c $h $ $ $ $ $ $ $ '&$6 %$ &&$ $s $x $ $ $ $ $ $ $ '&$6 $#s   
$A/ /
B9BB)r   r   )r   r  rg   r  r   r   r   r  r  r   r  r=  r<  s   ```  `````` @rJ   __limit_decoratorzLimiter.__limit_decorator  s     !*du	$HS(]3 u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$ u	$n rI   c	           
      <    |                      ||||||||          S )a  
        Decorator to be used for rate limiting individual routes.

        * **limit_value**: rate limit string or a callable that returns a string.
         :ref:`ratelimit-string` for more details.
        * **key_func**: function/lambda to extract the unique identifier for
         the rate limit. defaults to remote address of the request.
        * **per_method**: whether the limit is sub categorized into the http
         method of the request.
        * **methods**: if specified, only the methods in this list will be rate
         limited (default: None).
        * **error_message**: string (or callable that returns one) to override the
         error message used in the response.
        * **exempt_when**: function returning a boolean indicating whether to exempt
        the route from the limit
        * **cost**: integer (or callable that returns one) which is the cost of a hit
        * **override_defaults**: whether to override the default limits (default: True)
        )r   r   r  r  r   r  _Limiter__limit_decorator)	r   r  rg   r   r   r  r  r   r  s	            rJ   r   zLimiter.limit  s9    : %%!'#/ & 	
 	
 		
rI   c           
      <    |                      ||d|||||          S )ab  
        Decorator to be applied to multiple routes sharing the same rate limit.

        * **limit_value**: rate limit string or a callable that returns a string.
         :ref:`ratelimit-string` for more details.
        * **scope**: a string or callable that returns a string
         for defining the rate limiting scope.
        * **key_func**: function/lambda to extract the unique identifier for
         the rate limit. defaults to remote address of the request.
        * **per_method**: whether the limit is sub categorized into the http
         method of the request.
        * **methods**: if specified, only the methods in this list will be rate
         limited (default: None).
        * **error_message**: string (or callable that returns one) to override the
         error message used in the response.
        * **exempt_when**: function returning a boolean indicating whether to exempt
        the route from the limit
        * **cost**: integer (or callable that returns one) which is the cost of a hit
        * **override_defaults**: whether to override the default limits (default: True)
        T)r  r  r   r  r@  )r   r  r   rg   r  r  r   r  s           rJ   shared_limitzLimiter.shared_limit7  s9    < %%'#/ & 	
 	
 		
rI   c                     j         dj        }| j                            |           t	          j                  rt                    fd            }|S t                    fd            }|S )zF
        Decorator to mark a view as exempt from rate limits.
        r  c                  $   K    | i | d {V S r~   rH   akobjs     rJ   __async_innerz%Limiter.exempt.<locals>.__async_innerj  s+       S!\q\\)))))))rI   c                       | i |S r~   rH   rF  s     rJ   __innerzLimiter.exempt.<locals>.__innerq  s    sA|||#rI   )r5   r4   r   addr3  r4  r   )r   rI  r2  _Limiter__async_inner_Limiter__inners    `   rJ   exemptzLimiter.exempt`  s     ...#,,7%%%&s++ 	3ZZ* * * * Z* !  3ZZ$ $ $ $ Z$ NrI   )rW   Nr~   )T)	NFNFNNNr   T)NFNNNr   T)NNNr   T)'r4   r5   r6   __doc__r   r   r
   StrOrCallableStrboolr   r	   r   r   r   r    r   r  r   propertyr   r^   r   r   r   r_   r   r   r   r   r  r   r   r   r  r   rA  r   rC  rP  rH   rI   rJ   rd   rd   Y   s       % %V 2457 %"&%)*,$57+0%))-05%ER ER 38$ER -.	ER
 !!12ER ER 3-ER c]ER c3hER ER ER !!12ER %)ER c]ER ER  !ER" "##ER$ ,-%ER& 
'ER ER ER ERNS S S S
 
# 
a 
1 
 
 
 
    R R R R 
! 
! 
! 
! X
!3 316}d3i7O1P3	3 3 3 3j2%26;M4PS9<T6U2	2 2 2 2h.2.2*-.27;E{.2	.2 .2 .2 .2`23 2 2 2 20 #	_ __  c 23_ 	_
 
_ _ _ _H 26,0 '+'+59/0"&F F%F 8CH-.F 	F
 ()F F $s)$F  }F hsDy12F C#s(++,F  F 
#s(	F F F FV 26 '+'+59/0"&&
 &
%&
 8CH-.&
 	&

 $s)$&
  }&
 hsDy12&
 C#s(++,&
  &
 
&
 &
 &
 &
X 26'+59/0"&'
 '
%'
  '
 8CH-.	'

  }'
 hsDy12'
 C#s(++,'
  '
 
'
 '
 '
 '
R    rI   rd   )9rQ  r3  r5  r   r  r   r   r   r   email.utilsr   r   r   typingr   r   r	   r
   r   r   r   r   r   r   r   limits.errorsr   limits.storager   r   limits.strategiesr   r   starlette.configr   starlette.datastructuresr   starlette.requestsr   starlette.responsesr   r   typing_extensionsr   errorsr   wrappersr   r   r    r   rR  r"   rL   r   rb   rd   rH   rI   rJ   <module>ra     s               				        9 9 9 9 9 9 9 9      
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 !           , , , , , , = = = = = = = = 5 5 5 5 5 5 5 5 # # # # # # 3 3 3 3 3 3 & & & & & & 6 6 6 6 6 6 6 6 % % % % % % % % % % % % ' ' ' ' ' ' ' ' GCLLhsCx001 ( ( ( ( ( ( ( ((         ' 8I h    \ \ \ \ \ \ \ \ \ \rI   