
    ZeIi(                        d dl mZ d dlZd dlZd dlmZ d dlm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 erdd
lmZ  G d d          ZdS )    )annotationsN)Iterable)TYPE_CHECKING)
OrderedSet   )ApplicationLimitRuntimeLimit)ExemptionScope)get_qualified_name)Limitc                      e Zd Zd5dZed6d            Zed6d            Zd7dZd8dZd9d:dZ	d;dZ
d<d Zd=d!Zd>d$Zd?d%Z	 	 	 	 	 d@dAd.ZdBd/ZdCd0ZdDd1ZdEd4Zd&S )FLimitManagerapplication_limitslist[ApplicationLimit]default_limitslist[Limit]decorated_limitsdict[str, OrderedSet[Limit]]blueprint_limitsroute_exemptionsdict[str, ExemptionScope]blueprint_exemptionsreturnNonec                    || _         || _        || _        || _        || _        || _        i | _        t          j        d          | _	        d S )Nzflask-limiter)
_application_limits_default_limits_decorated_limits_blueprint_limits_route_exemptions_blueprint_exemptions_endpoint_hintslogging	getLogger_logger)selfr   r   r   r   r   r   s          [/var/www/html/MCyber-Diagnostic/venv/lib/python3.11/site-packages/flask_limiter/_manager.py__init__zLimitManager.__init__   sR     $6 -!1!1!1%9";=(99    list[RuntimeLimit]c                B    t          t          j        | j                   S N)list	itertoolschainr   r&   s    r'   r   zLimitManager.application_limits&   s    IOT%=>???r)   c                B    t          t          j        | j                   S r,   )r-   r.   r/   r   r0   s    r'   r   zLimitManager.default_limits*   s    IOT%9:;;;r)   limitsc                    || _         d S r,   )r   r&   r2   s     r'   set_application_limitsz#LimitManager.set_application_limits.   s    #)   r)   c                    || _         d S r,   )r   r4   s     r'   set_default_limitszLimitManager.set_default_limits1   s    %r)   FroutestrlimitLimit | Noneoverrideboolc                    |rX|s<| j                             |t                                                    |           d S t          |g          | j         |<   d S d S r,   )r   
setdefaultr   add)r&   r8   r:   r<   s       r'   add_decorated_limitz LimitManager.add_decorated_limit4   sn     	D D&11%FFJJ5QQQQQ0:E70C0C&u---		D 	Dr)   	blueprintc                    |r<| j                             |t                                                    |           d S d S r,   )r   r?   r   r@   )r&   rB   r:   s      r'   add_blueprint_limitz LimitManager.add_blueprint_limit;   sH     	R"--iFFJJ5QQQQQ	R 	Rr)   scoper
   c                    || j         |<   d S r,   )r    )r&   r8   rE   s      r'   add_route_exemptionz LimitManager.add_route_exemption?   s    (-u%%%r)   c                    || j         |<   d S r,   )r!   )r&   rB   rE   s      r'   add_blueprint_exemptionz$LimitManager.add_blueprint_exemptionB   s    05"9---r)   endpointcallablec                z    | j                             |t                                                    |           d S r,   )r"   r?   r   r@   )r&   rJ   rK   s      r'   add_endpoint_hintzLimitManager.add_endpoint_hintE   s3    ''*,,??CCHMMMMMr)   c                P    t          | j                            |                    S r,   )r=   r"   get)r&   rJ   s     r'   	has_hintszLimitManager.has_hintsH   s!    D(,,X66777r)   Nappflask.Flask
str | Nonecallable_namein_middlewaremarked_for_limitingtuple[list[RuntimeLimit], ...]c                N   |o|}g }g }	|r|s[|s/|j                             |d           }
|
rt          |
          nd}n|}|                    |                     |                     | j                            |t                                D ]*}|	                    |                     |                     +|rF|sD|rt          d |D                       r)|                    |                     ||                     | 	                    |||          }|r|t          j        z  s| j        ng }t          d |D                       }t          d |D                       }|	rt          d |	D                       nd}|s|r|s|t          j        z  r|r
|| j        z  }||fS )N c              3  &   K   | ]}|j          V  d S r,   override_defaults.0r:   s     r'   	<genexpr>z.LimitManager.resolve_limits.<locals>.<genexpr>f   s(      QQu522QQQQQQr)   c              3  $   K   | ]}|j         V  d S r,   )method_exemptr]   s     r'   r_   z.LimitManager.resolve_limits.<locals>.<genexpr>q   s%      $W$WUU%8$W$W$W$W$W$Wr)   c              3  &   K   | ]}|j          V  d S r,   r[   r]   s     r'   r_   z.LimitManager.resolve_limits.<locals>.<genexpr>v   s(      ZZE$; ;ZZZZZZr)   c              3  &   K   | ]}|j          V  d S r,   r[   r]   s     r'   r_   z.LimitManager.resolve_limits.<locals>.<genexpr>|   s(      GGE++GGGGGGr)   F)view_functionsrO   r   extendr   r"   r   allr   exemption_scoper
   APPLICATIONr   DEFAULTr   )r&   rQ   rJ   rB   rT   rU   rV   before_request_contextr   hinted_limits	view_funcnamehintrg   
all_limitsexplicit_limits_exemptcombined_defaultshinted_limits_request_defaultss                     r'   resolve_limitszLimitManager.resolve_limitsK   s;    "/!F3F 
	B  E$ ) # 2 6 6x F FI<EM-i8882DD(D ''(=(=d(C(CDDD,00:<<HH B B$$T%:%:4%@%@AAAA 	O) O$OQQ@PQQQQQO !''(=(=c9(M(MNNN..sHiHH &58R&RD## 	 "%$W$WFV$W$W$W!W!W
  ZZIYZZZZZ LYcCGGGGGGGG^c 	' $	.'8	.,	.0?.BX0X	. ,	. $--J+++r)   c                   |j                             |pdd           }|rt          |          nd}| j                            |t          j                  }|r|j                            |          nd }|s|S |sJ |                     ||          \  }}	|t          j        t          j	        z   z  s|	r|	
                                D ]}
||
z  }||z  S )NrY   )rd   rO   r   r    r
   NONE
blueprints_blueprint_exemption_scoperi   rh   values)r&   rQ   rJ   rB   rl   rm   route_exemption_scopeblueprint_instanceblueprint_exemption_scopeancestor_exemption_scopes	exemptions              r'   rg   zLimitManager.exemption_scope   s    &**8>r4@@	09A!),,,r $ 6 : :4AT U U>GQS^//	:::T! 	E(( //Y??)) *n.D~Ga.a,bb;,; ";!A!A!C!C ; ;I-:--(+DDDr)   c                *   g }| j                             |t          j                  sk|| j        v rb| j        |         D ]T}	 |D ]}|                    |           # t          $ r*}| j                            d| d|            Y d }~Md }~ww xY w|S )Nz&failed to load ratelimit for function : )	r    rO   r
   ru   r   append
ValueErrorr%   error)r&   rT   r2   groupr:   es         r'   r   zLimitManager.decorated_limits   s    %))-9LMM 		 666!3MB  E%* 1 1E"MM%00001%   **Y]YYVWYY        s   A
B& BBc                H    g }|r|j                             |          nd }|r}|j        }t          |r|                    d          ng           }                     ||          \  }}|t          j        t          j        z   z  s j	                            |t                                }	|	rt          d |	D                       sw j                            |t          j                  t          j        z  sEt          j         fd|                     j	                                      |          D              n|	}
|
r\|
D ]Y}	 |                    d |D                        ## t(          $ r*} j                            d| d|            Y d }~Rd }~ww xY w|S )N.c              3  $   K   | ]}|j         V  d S r,   r[   r]   s     r'   r_   z0LimitManager.blueprint_limits.<locals>.<genexpr>   s%      [[E 7[[[[[[r)   c              3  N   K   | ]}j                             |g           V   d S r,   )r   rO   )r^   memberr&   s     r'   r_   z0LimitManager.blueprint_limits.<locals>.<genexpr>   sJ         & !266vrBB     r)   c                    g | ]X}t          |j        |j        |j        |j        |j        |j        |j        |j        |j	        |j
        |j        |j                  YS  )r	   r:   key_funcrE   
per_methodmethodserror_messageexempt_whenr\   deduct_when	on_breachcostsharedr]   s     r'   
<listcomp>z1LimitManager.blueprint_limits.<locals>.<listcomp>   su     !" !" !" ). %1(-(-(-(-(8(-(-(;(-(9(-(?(-(9(-(-
(-%& %&!" !" !"r)   z'failed to load ratelimit for blueprint r   )rv   rO   rm   setsplitrw   r
   ri   rh   r   r   rf   r!   ru   	ANCESTORSr.   r/   intersection
differencere   r   r%   r   )r&   rQ   rB   r2   rz   blueprint_nameblueprint_ancestoryself_exemptionancestor_exemptionsblueprint_self_limitsr   limit_groupr   s   `            r'   r   zLimitManager.blueprint_limits   s3   %'>GQS^//	:::T 2	/4N"%i&Oiooc&:&:&:R"P"P262Q2QRUW`2a2a/N/"~'=@Z'Z%[[ ,(,(>(B(B>S]S_S_(`(`% ./  [[EZ[[[[[/ !6::>>K^__$.//IO   *=*J*J $ 6+ +(j)<==	    / !" $ '7  "MM!" !" 2=!" !" !"   &  *    L.. _. _ _\] _ _        s   E++
F5 FFr   0tuple[ExemptionScope, dict[str, ExemptionScope]]c                ^    |j         |         j        } j                            |t          j                  t          j         z  }t          |                    d                    }d  j        	                                D             
                    |          }| fd|D             fS )Nr   c                6    h | ]\  }}|t           j        z  |S r   )r
   DESCENDENTS)r^   kfs      r'   	<setcomp>z:LimitManager._blueprint_exemption_scope.<locals>.<setcomp>   s9     
 
 
!QND^@^

 
 
r)   c                \    i | ](}|j                             |t          j                  )S r   )r!   rO   r
   ru   )r^   r   r&   s     r'   
<dictcomp>z;LimitManager._blueprint_exemption_scope.<locals>.<dictcomp>   s>     
 
 
JKAt)--a1DEE
 
 
r)   )rv   rm   r!   rO   r
   ru   r   r   r   itemsr   )r&   rQ   r   rm   r}   	ancestoryancestor_exemptions   `      r'   rw   z'LimitManager._blueprint_exemption_scope   s     ~n-2.2249LMM$Q
 
	 ,,S1122	
 
4::<<
 
 

,y
!
! 	  
 
 
 
Oa
 
 
 
 	
r)   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r*   )r2   r   r   r   )r2   r   r   r   )F)r8   r9   r:   r;   r<   r=   r   r   )rB   r9   r:   r;   r   r   )r8   r9   rE   r
   r   r   )rB   r9   rE   r
   r   r   )rJ   r9   rK   r9   r   r   )rJ   r9   r   r=   )NNNFF)rQ   rR   rJ   rS   rB   rS   rT   rS   rU   r=   rV   r=   r   rW   )rQ   rR   rJ   rS   rB   rS   r   r
   )rT   r9   r   r*   )rQ   rR   rB   r9   r   r*   )rQ   rR   r   r9   r   r   )__name__
__module____qualname__r(   propertyr   r   r5   r7   rA   rD   rG   rI   rM   rP   rs   rg   r   r   rw   r   r)   r'   r   r      s       : : : :$ @ @ @ X@ < < < X<* * * *& & & &D D D D DR R R R. . . .6 6 6 6N N N N8 8 8 8  $ $$(#$)8, 8, 8, 8, 8,tE E E E0   7 7 7 7r
 
 
 
 
 
r)   r   )
__future__r   r.   r#   collections.abcr   typingr   flaskordered_setr   _limitsr   r	   	constantsr
   utilr   rY   r   r   r   r)   r'   <module>r      s    " " " " " "      $ $ $ $ $ $              " " " " " " 3 3 3 3 3 3 3 3 % % % % % % $ $ $ $ $ $ `
 `
 `
 `
 `
 `
 `
 `
 `
 `
r)   