
    ZeIi:                    J   d dl m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	 d dl
mZmZmZ d dl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mZmZmZmZmZ d	dlmZ erd dlm Z m!Z!  ej"        dd           G d d                      Z# ej"        dd           G d d                      Z$ ej"        dd           G d de$                      Z% ej"        dd           G d de$                      Z& ej"        dd           G d de$                      Z'dS )    )annotationsN)wraps)TracebackType)TYPE_CHECKINGcastoverload)request)Response)RateLimitItem
parse_many   )CallableIterableIteratorPRSelfSequence)get_qualified_name)LimiterRequestLimitT)equnsafe_hashc                     e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   dZded<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZd	ed<   dZded<   d*d Zed+d!            Zed,d#            Zed+d$            Zd-d)ZdS ).RuntimeLimitzV
    Final representation of a rate limit before it is triggered during a request
    r   limitCallable[[], str]key_func!str | Callable[[str], str] | NonescopeFbool
per_methodNSequence[str] | Nonemethodsstr | Callable[[], str] | Noneerror_messageCallable[[], bool] | Noneexempt_whenbool | Noneoverride_defaults!Callable[[Response], bool] | Nonededuct_when0Callable[[RequestLimit], Response | None] | None	on_breachr   zCallable[[], int] | intcostsharedztuple[RuntimeLimit, ...] | Nonemeta_limitsreturnNonec                ^    | j         r%t          d | j         D                       | _         d S d S )Nc                6    g | ]}|                                 S  lower.0ks     Z/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/flask_limiter/_limits.py
<listcomp>z.RuntimeLimit.__post_init__.<locals>.<listcomp>-        !B!B!B!''))!B!B!B    )r$   tupleselfs    r<   __post_init__zRuntimeLimit.__post_init__+   s=    < 	D !B!BT\!B!B!BCCDLLL	D 	Dr?   c                <    | j         r|                                  S dS )zCheck if the limit is exempt.F)r(   rA   s    r<   	is_exemptzRuntimeLimit.is_exempt/   s&      	&##%%%ur?   intc                `    t          | j                  r|                                 n| j        S )z!How much to deduct from the limit)callabler/   rA   s    r<   deduction_amountzRuntimeLimit.deduction_amount8   s'     'ty11@tyy{{{ty@r?   c                ^    | j         duo$t          j                                        | j         vS )z4Check if the limit is not applicable for this methodN)r$   r	   methodr8   rA   s    r<   method_exemptzRuntimeLimit.method_exempt>   s+     |4'VGN,@,@,B,B$,,VVr?   endpointstrrK   
str | Nonec                    t          | j                  r!|                     t          j        pd          n| j        }|r| j        r|}n
| d| }n|}| j        r|sJ |d|                                 z  }|S )z
        Derive final bucket (scope) for this limit given the endpoint and request method.
        If the limit is shared between multiple routes, the scope does not include the endpoint.
         :)rH   r    r	   rM   r0   r"   upper)rB   rM   rK   limit_scoper    s        r<   	scope_forzRuntimeLimit.scope_forD   s    
 =ETZ<P<P`djj!1!7R888VZV` 	{ 4##33k33E? 	*MMM))))Er?   r2   r3   )r2   r!   )r2   rF   )rM   rN   rK   rO   r2   rN   )__name__
__module____qualname____doc____annotations__r"   r$   r&   r(   r*   r,   r.   r/   r0   r1   rC   propertyrE   rI   rL   rU   r6   r?   r<   r   r      s          ,,,,J$(G((((48M8888-1K1111%*****59K9999BFIFFFF$%D%%%%F37K7777D D D D    X A A A XA
 W W W XW
     r?   r   c                  t   e Zd ZU dZded<   dZded<   dZded<   dZd	ed
<   dZded<   dZ	ded<   dZ
ded<   dZded<   dZded<   dZded<   dZded<   dZded<    ej        dd          Zded<    ej        dddd          Zd ed!<    ej        d"          Zded#<   d/d&Zd0d(Zed1d*            Zd2d.ZdS )3Limita  
    The definition of a rate limit to be used by the extension as a default limit::


        def default_key_function():
            return request.remote_addr

        def username_key_function():
            return request.headers.get("username", "guest")

        limiter = flask_limiter.Limiter(
            default_key_function,
            default_limits = [
                # 10/second by username
                flask_limiter.Limit("10/second", key_function=username_key_function),
                # 100/second by ip (i.e. default_key_function)
                flask_limiter.Limit("100/second),

            ]
        )
        limit.init_app(app)

    - For application wide limits see :class:`ApplicationLimit`
    - For meta limits see :class:`MetaLimit`
    zCallable[[], str] | strlimit_providerNCallable[[], str] | Nonekey_functionr   r    zCallable[[], int] | int | Noner/   Fr!   r0   r#   r$   r"   r%   r&   z4Iterable[Callable[[], str] | str | MetaLimit] | Noner1   r'   r(   r+   r,   r-   r.   )defaultinitr)   r*   T)rc   hashkw_onlyreprzweakref.ProxyType[Limiter]limiterrb   	finalizedr2   r3   c                    | j         r#t          d | j         D                       | _         | j        rt          | j                  | _        d S d S )Nc                6    g | ]}|                                 S r6   r7   r9   s     r<   r=   z'Limit.__post_init__.<locals>.<listcomp>   r>   r?   )r$   r@   r1   rA   s    r<   rC   zLimit.__post_init__   s[    < 	D !B!BT\!B!B!BCCDL 	7$T%566D	7 	7r?   Iterator[RuntimeLimit]c              #     K   t           j                  r                                 n j        }|rt          |          ng }d} j        r,t	          t          j         fd j        D                        }|D ]Y}t          | j         j	         j
         j         j         j         j         j         j         j        pd j        |          V  Zd S )Nr6   c                    g | ]H}t          t          |t                    s"t          |                                        n|          IS r6   )list
isinstance	MetaLimitbind_parent)r:   
meta_limitrB   s     r<   r=   z"Limit.__iter__.<locals>.<listcomp>   se        ' #-j)#D#D,Ij11==dCCC!+   r?   r   )r    r"   r$   r&   r(   r,   r*   r.   r/   r0   r1   )rH   r_   r   r1   r@   	itertoolschainr   limit_byr    r"   r$   r&   r(   r,   r*   r.   r/   r0   )rB   	limit_strlimit_itemsr1   r   s   `    r<   __iter__zLimit.__iter__   s"     -5d6I-J-JcD'')))PTPc	/8@j+++b02 	    +/*:  	 K ! 	 	Ej?"0 , ,"&"8.Y^!{'      	 	r?   r   c                (    | j         p| j        j        S N)ra   rg   	_key_funcrA   s    r<   rv   zLimit.limit_by   s     :DL$::r?   rB   r   r   c                d    t          j                  | _        fd| j        pdD              | S )z
        Returns an instance of the limit definition that binds to a weak reference of an instance
        of :class:`Limiter`.

        :meta private:
        c                d    g | ],}t          |t                    |                              -S r6   )rp   rq   bind)r:   rs   rg   s     r<   r=   zLimit.bind.<locals>.<listcomp>   sE     	
 	
 	
*i00	
OOG$$	
 	
 	
r?   r6   )weakrefproxyrg   r1   )rB   rg   s    `r<   r   z
Limit.bind   sP     }W--	
 	
 	
 	
".4"	
 	
 	
 	
 r?   rV   )r2   rl   r2   r   )rB   r   rg   r   r2   r   )rW   rX   rY   rZ   r[   ra   r    r/   r0   r$   r"   r&   r1   r(   r,   r.   dataclassesfieldr*   rg   ri   rC   ry   r\   rv   r   r6   r?   r<   r^   r^   Z   s         8 ,+++ .2L1111 04E3333 ,0D////F %)G(((( J 59M8888HLKLLLL .2K1111 6:K9999
 CGIFFFF &7[%6u5%Q%Q%QQQQQ +<+*;5+ + +G     (k'555I55557 7 7 7" " " "H ; ; ; X;     r?   r^   )r   re   c                       e Zd ZU dZdZded<    ej        d          Zded<   d fdZ	ddZ
ddZedd            Zed d            Zd!dZ xZS )"
RouteLimita  
    A variant of :class:`Limit` that can be used to to decorate a flask route or blueprint directly
    instead of by using :meth:`Limiter.limit` or :meth:`Limiter.shared_limit`.

    Decorating individual routes::

        limiter = flask_limiter.Limiter(.....)
        limiter.init_app(app)

        @app.route("/")
        @flask_limiter.RouteLimit("2/second", limiter=limiter)
        def view_function():
            ...

    Fr)   r*   )rd   zdataclasses.InitVar[Limiter]rg   r   r2   r3   c                r    |                      |           t                                                       d S r{   )r   superrC   )rB   rg   	__class__s     r<   rC   zRouteLimit.__post_init__  s1    		'r?   c                p   t          j        d          }|d         j         d|d         j         d|d         j         }| j        j                            || d           | j        j                            | j        	                                |           | j        
                    d|           d S )	N   )r   r   rR   T)overrideFin_middlewarecallable_name)	tracebackextract_stackfilenamenamelinenorg   limit_manageradd_decorated_limitadd_endpoint_hintidentify_request_check_request_limit)rB   tbqualified_locations      r<   	__enter__zRouteLimit.__enter__  s    $1--- "1LLALLbelLL
 	"667I4Z^6___"44L))++-?	
 	
 	
 	))M_)`````r?   exc_typetype[BaseException] | None	exc_valueBaseException | Noner   TracebackType | Nonec                    d S r{   r6   )rB   r   r   r   s       r<   __exit__zRouteLimit.__exit__  s	    
 sr?   objCallable[P, R]c                    d S r{   r6   rB   r   s     r<   __call__zRouteLimit.__call__%  s    ?Bsr?   flask.Blueprintc                    d S r{   r6   r   s     r<   r   zRouteLimit.__call__(  s    69cr?    Callable[P, R] | flask.BlueprintCallable[P, R] | Nonec                    t          t          j                  rj        nt	                    t          t          j                  r" j        j                                        d S  j        j        	                                j        j        
                                t                    d	 fd            }t          |d j                   |S )
NaP.argsr;   P.kwargsr2   r   c                    t          dd           j        k    sj                                        }|rZt          j        j                            |d           }|r3t          |          k    s j        j        	                    |           j        
                    d           t          t          t          j                                      | i |          S )N__wrapper-limiter-instanceFr   )getattrrg   r   flaskcurrent_appview_functionsgetr   r   r   r   r   r   ensure_sync)r   r;   identity	view_funcr   r   rB   s       r<   __innerz$RouteLimit.__call__.<locals>.__inner9  s    s$@$GG4<WW#|<<>>H Y$)$5$D$H$HSW$X$X	$ Y-?	-J-Jd-R-R L6HHSWXXXL55EY]5^^^Au0<<SAA1JJJKKKr?   r   )r   r   r;   r   r2   r   )rp   r   	Blueprintr   r   rg   r   add_blueprint_limit_marked_for_limitingaddr   r   setattr)rB   r   _RouteLimit__innerr   s   `` @r<   r   zRouteLimit.__call__+  s    c5?++ 	+8DD%c**Dc5?++ 	L&::4FFF4L-11$777L&::4FFF3ZZL L L L L L L ZL( G94<HHHNr?   )rg   r   r2   r3   rV   )r   r   r   r   r   r   r2   r3   )r   r   r2   r   )r   r   r2   r3   )r   r   r2   r   )rW   rX   rY   rZ   r*   r[   r   r   rg   rC   r   r   r   r   __classcell__)r   s   @r<   r   r      s          , &+****,=K,=5,I,I,IGIIII           a a a a    BBB XB999 X9% % % % % % % %r?   r   )re   r   c                  n    e Zd ZU dZ ej        d          Zded<    ej        dd          Zd	ed
<   dS )ApplicationLimitz
    Variant of :class:`Limit` to be used for declaring an application wide limit that can be passed
    to :class:`Limiter` as one of the members of :paramref:`Limiter.application_limits`
    globalrh   r   r    FTrc   rb   r!   r0   N)	rW   rX   rY   rZ   r   r   r    r[   r0   r6   r?   r<   r   r   S  se           0A{/@/R/R/RERRRR %;$%>>>F>>>>>>r?   r   c                  &   e Zd ZU dZ ej        d          Zded<    ej        dd          Zd	ed
<    ej        dd          Z	ded<    ej        dd          Z
ded<    ej        dd          Zded<   dZded<   edd            ZddZdS )rq   a  
    Variant of :class:`Limit` to be used for declaring a meta limit that can be passed to
    either :class:`Limiter` as one of the  members of :paramref:`Limiter.meta_limits` or to another
    instance of :class:`Limit` as a member of :paramref:`Limit.meta_limits`
    metarh   r   r    FNr   z4Sequence[Callable[[], str] | str | MetaLimit] | Noner1   zLimit | Noneparent_limitTr!   r0   r+   r,   r`   ra   r2   r   c                N    | j         p| j        o| j        j         p| j        j        S r{   )ra   r   rg   r|   rA   s    r<   rv   zMetaLimit.limit_by  s7      &  /!.& |%		
r?   rB   r   parentr^   c                    || _         | S )zt
        Binds this meta limit to be associated as a child of the ``parent`` limit.

        :meta private:
        )r   )rB   r   s     r<   rr   zMetaLimit.bind_parent  s     #r?   r   )rB   r   r   r^   r2   r   )rW   rX   rY   rZ   r   r   r    r[   r1   r   r0   r,   ra   r\   rv   rr   r6   r?   r<   rq   rq   b  s3          0A{/@/P/P/PEPPPP IZHYDI I IK     "3!2t!L!L!LLLLLL %;$%>>>F>>>> 6G[5FE[_5`5`5`K```` .2L1111
 
 
 X
     r?   rq   )(
__future__r   r   rt   r   r   	functoolsr   typesr   typingr   r   r   r   r	   flask.wrappersr
   limitsr   r   _typingr   r   r   r   r   r   r   utilr   flask_limiterr   r   	dataclassr   r^   r   r   rq   r6   r?   r<   <module>r      s   " " " " " "                          0 0 0 0 0 0 0 0 0 0        # # # # # # , , , , , , , , G G G G G G G G G G G G G G G G G G $ $ $ $ $ $ 433333333 $D111? ? ? ? ? ? ? 21?D $D111Q Q Q Q Q Q Q 21Qh 4666` ` ` ` ` ` ` 76`F t666? ? ? ? ?u ? ? 76? t6663 3 3 3 3 3 3 763 3 3r?   