
    ijX                       U d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ d dlmZmZmZmZmZ d dlmZmZ  ej2                  e      Zeed	f   Zeed	d
df   Zeedf   Zeedf   Z eedf   Z!eeddf   Z"ee
e#edf   Z$ ed       G d d             Z% G d ded      Z& G d de&d      Z'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/d Z0d!Z1g d"Z2g d#Z3d$Z4ejj                  Z6 e7d%      Z8 e7e'jr                         e7e'jt                        z  Z;d&e2d&ddddddd'dddd(Z<de=d)<   d=d*Z>d>d+Z?d?d,Z@d@d-ZA	 	 	 	 	 	 	 	 dAd.ZBdBd/ZCdCd0ZDdDd1ZEdEdFd2ZFdEdGd3ZGdHd4ZHdId5ZIdJdKd6ZJdLd7ZKdMd8ZLdNd9ZMdOd:ZNdPd;ZOdQd<ZPy)R    )annotationsN)IterableMapping)	dataclass)	timedelta)Any	TypedDictUnioncast)	BlueprintFlaskResponsecurrent_apprequest)Headers	MultiDictzre.Pattern[str]list[ResourcePattern]z%dict[ResourcePattern, dict[str, Any]]Iterable[ResourcePattern]zIterable[str]T)frozenc                      e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   y)_ComputedCorsOptionsa	  The fully-resolved CORS options for a single route.

    Private internal representation, built only by :func:`serialize_options`.
    Configure CORS via :class:`~flask_cors.CORS` / :func:`cross_origin` keyword
    arguments, not by constructing this directly.
    r   originsallow_headersboolallow_all_origins
str | Nonemethodsexpose_headerszstr | int | Nonemax_agesupports_credentialssend_wildcardautomatic_optionsvary_headerintercept_exceptionsalways_sendallow_private_networkN__name__
__module____qualname____doc____annotations__     d/var/www/html/emotional.easysim.app/public_html/venv/lib/python3.12/site-packages/flask_cors/core.pyr   r   &   s[     #"((  r.   r   c                      e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   d
ed<   d
ed<   d
ed<   d
ed<   d
ed<   y)CrossOriginOptionsInputaC  The keyword options accepted by :func:`cross_origin`.

    Every key is optional (``total=False``): only the options a caller
    actually passes are forwarded, so app-level ``CORS_*`` configuration and
    the defaults still apply to anything left out. Used with PEP 692
    ``Unpack`` to type ``**kwargs`` precisely.
    OriginsInputr   MethodsInputr   ExposeHeadersInputr   HeadersInputr   r   r    MaxAgeInputr   r!   r#   r"   r%   r&   Nr'   r-   r.   r/   r1   r1   G   sK     &&r.   r1   F)totalc                  &    e Zd ZU dZded<   ded<   y)CorsOptionsInputzThe keyword options accepted by :class:`CORS` / :meth:`CORS.init_app`.

    Extends :class:`CrossOriginOptionsInput` with the application-level options that
    only make sense for the extension.
    ResourceSpec	resourcesr   r$   Nr'   r-   r.   r/   r9   r9   ]   s     r.   r9   zAccess-Control-Allow-OriginzAccess-Control-Allow-MethodszAccess-Control-Allow-HeaderszAccess-Control-Expose-Headersz Access-Control-Allow-CredentialszAccess-Control-Max-Agez$Access-Control-Allow-Private-NetworkzAccess-Control-Request-MethodzAccess-Control-Request-Headersz&Access-Control-Request-Private-Network)GETHEADPOSTOPTIONSPUTPATCHDELETE)CORS_ORIGINSCORS_METHODSCORS_ALLOW_HEADERSCORS_EXPOSE_HEADERSCORS_SUPPORTS_CREDENTIALSCORS_MAX_AGECORS_SEND_WILDCARDCORS_AUTOMATIC_OPTIONSCORS_VARY_HEADERCORS_RESOURCESCORS_INTERCEPT_EXCEPTIONSCORS_ALWAYS_SENDCORS_ALLOW_PRIVATE_NETWORK_FLASK_CORS_EVALUATEDz
*\]?$^[]()*z/*)r   r   r   r   r    r   r!   r"   r#   r;   r$   r%   r&   DEFAULT_OPTIONSc                   t        | t              rD| j                         D cg c]  \  }}t        |      |f }}}dd}|j	                  |       n~t        | t
              rt        |       i fg}n_t        | t              r| D cg c]  }t        |      i f }}n4t        | t        j                        rt        |       i fg}nt        d      |D cg c]  \  }}t        |d      |f c}}S c c}}w c c}w c c}}w )Nc                >   | \  }}t        |t        j                        r4dd|j                  j	                  d       t        |j                         fS t        |      r dd|j	                  d       t        |       fS dd|j	                  d       t        |       fS )N   r   /)
isinstancerePatternpatterncountlenprobably_regex)pairrZ   _s      r/   sort_keyz!parse_resources.<locals>.sort_key   s    JGQ'2::.1w44S99C<P;PQQ(1w}}S11CL=AA1w}}S11CL=AAr.   )keyz(Unexpected value for resources argument.Fignore_case)r^   ztuple[ResourcePattern, Any]returnztuple[int, int, int, int])rW   dictitemsre_fixsortstrr   rX   rY   
ValueError_resolve_pattern)r;   kvresource_pairsr`   rrZ   optss           r/   parse_resourcesrq      s    )T" 6?__5FGTQ6!9a.GG	B 	)	Is	#!),b12	Ix	(3<=a6!9b/== 
Irzz	*!),b12
 CDD
 Ygg_gtg594@ggC H$ > hs   C5C;D c                d    t        | t        j                        r| j                  S t	        |       S )z
    Helper that returns regexp pattern from given value.

    :param regexp: regular expression to stringify
    :type regexp: re.Pattern or str
    :returns: string representation of given regexp pattern
    :rtype: str
    )rW   rX   rY   rZ   ri   )regexps    r/   get_regexp_patternrt      s&     &"**%~~v;r.   c                   | j                   }| j                  }|rxt        j                  d|       |r$| j                  rt        j                  d       dgS t        ||d      rt        j                  d       |gS t        j                  d       y | j                  r$|r| j                  ry dgS t        d |D              S t        j                  d	       y )
Nz&CORS request received with 'Origin' %sz=Allowed origins are set to '*'. Sending wildcard CORS header.rQ   FcaseSensitivez:The request's Origin header matches. Sending CORS headers.zBThe request's Origin header does not match any of allowed origins.c              3  B   K   | ]  }t        |t              s|  y wN)rW   ri   .0os     r/   	<genexpr>z#get_cors_origins.<locals>.<genexpr>  s     C
1c0B!Cs   zThe request did not contain an 'Origin' header. This means the browser or client did not request CORS, ensure the Origin Header is set.)	r   r   LOGdebugr!   try_match_any_patternr%   r    sorted)optionsrequest_originr   wildcards       r/   get_cors_originsr      s    ooG((H 		:NK --IIUV5L #>7%PIIL ###IIZ[			 ++u CWCCC 			 V	
 r.   c                    |ra| j                   |j                  d      D cg c]  }|j                          }}t        fd|      }dj	                  t        |            S y c c}w )N,c                     t        | d      S )NFrv   )r   )hr   s    r/   <lambda>z#get_allow_headers.<locals>.<lambda>  s    +A}ER r.   , )r   splitstripfilterjoinr   )r   acl_request_headersr   request_headersmatching_headersr   s        @r/   get_allow_headersr     sh    --.A.G.G.LM1779MM "R

 yy 0122 Ns   A&c                x   t        | |j                  d            }t               }|s|S |j                  t        |       | j
                  |t        <   | j                  r	d|t        <   t        |v r1|j                  t              dk(  r| j                  rdnd}||t        <   |dk(  r|j                  t        d      j                         }| j                  }|rI|rG||v rCt        | |j                  t                     |t"        <   | j$                  |t&        <   ||t(        <   nt*        j-                  d       | j.                  rZ| j0                  }|t           dk(  }	|	s@t3        |      dkD  s t3        |      dkD  st5        d	 |D              r|j7                  d
d       t        d |j9                         D              S )NOrigintruefalser?    ztThe request's Access-Control-Request-Method header does not match allowed methods. CORS headers will not be applied.rQ   rU   c              3  P   K   | ]  }t        |t        j                           y wry   )rW   rX   rY   rz   s     r/   r}   z#get_cors_headers.<locals>.<genexpr>^  s     >j]^z!RZZ?X>js   $&Varyc              3  0   K   | ]  \  }}|s	||f  y wry   r-   )r{   rl   rm   s      r/   r}   z#get_cors_headers.<locals>.<genexpr>b  s     =11aV=s   
	)r   getr   setlist
ACL_ORIGINr   ACL_EXPOSE_HEADERSr    ACL_CREDENTIALS"ACL_REQUEST_HEADER_PRIVATE_NETWORKr&   ACL_RESPONSE_PRIVATE_NETWORKACL_REQUEST_METHODupperr   r   ACL_REQUEST_HEADERSACL_ALLOW_HEADERSr   ACL_MAX_AGEACL_METHODSr~   infor#   r   r\   anyaddrf   )
r   r   request_methodorigins_to_setheadersr&   acl_request_methodr   r   returns_wildcards
             r/   get_cors_headersr   (  s    &g/B/B8/LMN 1:GOOJ/")"8"8G###)  	+o= BCvM*1*G*GW0E,- ",001CRHNNP //'.@G.K *;7ODWDWXkDl)mG%&#*??GK #*GK HH G
  //":.#5L1N 3a 73>jbi>j;jKK)====r.   c                   t        | t              rt        j                  d       | S t	        | j
                  t              s4t	        | j
                  t              st        | j
                        | _        t        |t        j
                  t        j                        }t        j                  dt        |             |j                         D ]!  \  }}| j
                  j                  ||       # | S )z
    Performs the actual evaluation of Flask-CORS options and actually
    modifies the response object.

    This function is used both in the decorator and the after_request
    callback
    z*CORS have been already evaluated, skippingzSettings CORS headers: %s)hasattrFLASK_CORS_EVALUATEDr~   r   rW   r   r   r   r   r   methodri   rf   r   )respr   headers_to_setrl   rm   s        r/   set_cors_headersr   e  s     t)*		>?
 dllG,Zi5X !.%gwONII)3~+>?$$& 1A Kr.   c                d    t        | t        j                        ryt        j	                  |        S )NT)rW   rX   rY   _REGEX_HINT_CHARS
isdisjoint)maybe_regexs    r/   r]   r]     s)    +rzz* !++K888r.   c                    | dk(  rdS | S )z
    Replace the invalid regex r'*' with the valid, wildcard regex r'/.*' to
    enable the CORS app extension to have a more user friendly api.
    rQ   .*r-   )regs    r/   rg   rg     s    
 4K5(S(r.   c                0     t         fd|D              S )Nc              3  8   K   | ]  }t        |        y wry   )try_match_pattern)r{   rZ   rw   insts     r/   r}   z(try_match_any_pattern.<locals>.<genexpr>  s     W7 w>Ws   )r   )r   patternsrw   s   ` `r/   r   r     s    WhWWWr.   c                "   t        |t        j                        rt        |j	                  |             S 	 t        |       }t        |      }|r||k(  S |j                         |j                         k(  S # t        $ r t        | |k(        cY S w xY w)aO  
    Match a value against a *resolved* pattern: a compiled ``re.Pattern``
    (whose case-sensitivity is already baked in) or a literal string. Used to
    match request origins, headers, or paths; ``caseSensitive`` only affects
    the literal comparison (origins and headers are case insensitive, paths are
    case sensitive).
    )rW   rX   rY   r   matchri   	Exceptioncasefold)valuerZ   rw   rm   ps        r/   r   r     s     '2::&GMM%())&JL #16D



(DD  &EW$%%&s   A4 4BBc                    t        t              }|j                  t        |              |D ]  }|j                  |        |S )z
    Merge the DEFAULT_OPTIONS, the app's configuration-specified options and any
    dictionaries passed into a single raw options mapping. The last specified
    option wins.
    )re   rR   updateget_app_kwarg_dict)appInstancedictsr   ds       r/   merge_optionsr     s@     #?3GNN%k23 qNr.   c                ,    t        t        | g|       S )zICompute the resolved CORS options for an application (see merge_options).)serialize_optionsr   )r   r   s     r/   get_cors_optionsr     s    ];??@@r.   c                    | xs t         }t        |di       }t        D ci c]7  }|j                  |      x}|j	                         j                  dd      |9 c}S c c}w )z;Returns the dictionary of CORS specific app configurations.configcors_r   )r   getattrCONFIG_OPTIONSr   lowerreplace)r   app
app_configrl   r   s        r/   r   r     s_    

$C h+J;IvaWaWeWefgWhNheMuAGGIgr*E1vvvs
   A#Ac                    | yt        | t              s1t        | t              r!dj                  d t	        |       D              S t        |       S )z
    A more flexible str function which intelligently handles stringifying
    strings, lists and other iterables. The results are lexographically sorted
    to ensure generated responses are consistent when iterables such as Set
    are used.
    Nr   c              3  2   K   | ]  }t        |        y wry   )ri   )r{   items     r/   r}   zflexible_str.<locals>.<genexpr>  s     ;tT;s   )rW   ri   r   r   r   )objs    r/   flexible_strr     sA     {S!jh&?yy;vc{;;;3xr.   c                `    t        | t              st        | t              s| gS t        d|       S )zT
    Wraps scalars or string types as a list, or returns the iterable instance.
    Iterable[Any])rW   ri   r   r   )r   s    r/   ensure_iterabler     s+     $JtX$>vOT**r.   c                P    t        |       D cg c]  }t        |       c}S c c}w ry   )r   rg   )paramxs     r/   sanitize_regex_paramr     s    .u56!F1I666s   #c                   t        | t              r8t        |       r-	 t        j                  | |rt        j
                        S d      S | S # t        j                  $ r}t        d|       |d}~ww xY w)a  Resolve a single raw pattern once, at configuration time.

    A regex-like string is compiled to a ``re.Pattern`` (with the correct
    case-sensitivity baked in); a literal string and an already-compiled
    pattern are returned unchanged. An invalid regular expression raises a
    ``ValueError`` so the misconfiguration fails fast at setup time rather than
    silently never matching.
    r   z8Invalid regular expression in Flask-CORS configuration: N)rW   ri   r]   rX   compile
IGNORECASEerrorrj   )rZ   rc   excs      r/   rk   rk     sq     '3N7$;	n::gr}}KKKK N xx 	nWX_Wbcdjmm	ns   %A A A2A--A2c               B    | D cg c]  }t        ||       c}S c c}w )zResolve a list of patterns (see :func:`_resolve_pattern`).

    After this, the request path can simply test ``isinstance(p, re.Pattern)``
    instead of re-running the :func:`probably_regex` heuristic on every request.
    rb   )rk   )r   rc   r   s      r/   _resolve_patternsr     s"     CKKQQK8KKKs   c                   | D ]!  }|t         vst        j                  d|       # t        | j	                  d            }d|v }t        | j	                  d            }t        | j	                  d            }|r|r|rt        d      t        |d      }t        t        | j	                  d	            d      }t        | j	                  d
            }||j                         }| j	                  d      }	t        |	t              r"t        t        |	j                                     }	t        ||||t        | j	                  d            |	||t        | j	                  d            t        | j	                  d            t        | j	                  d            t        | j	                  d            t        | j	                  d                  S )a7  
    Normalize a raw options mapping into a strongly-typed :class:`_ComputedCorsOptions`.

    This is the single boundary where loosely-typed user input (arbitrary
    keyword arguments, app config, resource dictionaries) is parsed into the
    concrete, per-field types the rest of the package relies on.
    z'Unknown option passed to Flask-CORS: %sr   r   r    r!   z}Cannot use supports_credentials in conjunction withan origin string of '*'. See: http://www.w3.org/TR/cors/#resource-requestsTrb   r   r   r   r   r"   r#   r$   r%   r&   )r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )_KNOWN_OPTIONSr~   warningr   r   r   rj   r   r   r   rW   r   ri   inttotal_secondsr   )
rp   ra   sanitized_originsr   r    r!   r   r   r   r   s
             r/   r   r     s     Hn$KKA3GH -TXXi-@A!22)? @A/23M 1m;
 	
   1tDG%&:488O;T&UcghM488I./G--/hhy!G'9%c'//123#+#DHH-=$>?1#txx(;<=-01!$((+A"BC-01"488,C#DE r.   )r;   r:   rd   z,list[tuple[ResourcePattern, dict[str, Any]]])rs   ResourcePatternrd   ri   )r   r   r   r   rd   zlist[str] | None)r   r   r   r   rd   r   )r   r   r   r   r   ri   rd   z MultiDict[str, str | int | None])r   r   r   r   rd   r   )r   r   rd   r   )r   r   rd   r   )T)r   ri   r   r   rw   r   rd   r   )r   r   rZ   r   rw   r   rd   r   )r   Flask | Blueprint | Noner   Mapping[str, Any]rd   dict[str, Any])r   r   r   r   rd   r   ry   )r   r   rd   r   )r   r   rd   r   )r   r   rd   r   )r   r   rd   r   )rZ   r   rc   r   rd   r   )r   r   rc   r   rd   r   )rp   r   rd   r   )Q
__future__r   loggingrX   collections.abcr   r   dataclassesr   datetimer   typingr   r	   r
   r   flaskr   r   r   r   r   werkzeug.datastructuresr   r   	getLoggerr(   r~   ri   r   r:   r2   r5   r3   r4   r   r6   r   r1   r9   r   r   r   r   r   r   r   r   r   r   ALL_METHODSr   r   rY   RegexObject	frozensetr   __required_keys____optional_keys__r   rR   r,   rq   rt   r   r   r   r   r]   rg   r   r   r   r   r   r   r   r   rk   r   r   r-   r.   r/   <module>r	     sF   "  	 - !  . . B B 6g! ../ +- _&AAB_&AABS/)*356 IsC-. $     @ iu  ,.e  +
,2 4 4&E  5 6 %M "J$ /  jj m, 
 +==>K[KmKmAnn ! "%! "%hP2j :>!:>4;:>MP:>%:>z@9)XE$
A
w+7"L6r.   