
    /_iG&                       U d dl mZ d dlZd dlZd dlmZmZmZmZ d dl	Z
d dlmZmZ d dlmZmZmZ er
d dlmZmZmZ  ej,                  d      ZdZd	ed
<   ddZddZ G d de
j8                  j:                        Z G d de
j8                  j<                        Z G d de
j8                  j<                        Z  G d de
j8                  j<                        Z! G d de!      Z"g dZ# G d de!      Z$y)    )annotationsN)TYPE_CHECKINGAnyFinalcast)config	file_util)allowlisted_origins emit_endpoint_deprecation_noticeis_xsrf_enabled)	AwaitableCallableSequencez(?:\.html$|^manifest\.json$)i3r   "STATIC_ASSET_CACHE_MAX_AGE_SECONDSc                 \    t        j                  d       xs t        j                  d      S )a0  True if cross-origin requests from any origin are allowed.

    We only allow ALL cross-origin requests when CORS protection has been
    disabled with server.enableCORS=False or if using the Node server in dev
    mode. When in dev mode, we have a dev and prod port, which count as two
    origins.
    zserver.enableCORSglobal.developmentMode)r   
get_option     Z/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/web/server/routes.pyallow_all_cross_origin_requestsr   )   s0       !455 9J9J : r   c                <    t        | t              sy| t               v S )NF)
isinstancestrr
   )origins    r   is_allowed_originr   7   s    fc"(***r   c                  T     e Zd Z	 	 d	 	 	 	 	 	 	 d fdZddZd fdZd	 fdZ xZS )
StaticFileHandlerc                4    || _         t        | 	  ||       y N)_reserved_pathssuper
initialize)selfpathdefault_filenamereserved_paths	__class__s       r   r#   zStaticFileHandler.initialize>   s      .4!12r   c                    t        |      dk(  }|st        j                  |      r| j                  dd       y| j                  ddt                y)zDisable cache for HTML files and manifest.json.

        Other assets like JS and CSS are suffixed with their hash, so they can
        be cached indefinitely.
        r   Cache-Controlno-cachezpublic, immutable, max-age=N)lenNO_CACHE_PATTERNsearch
set_headerr   )r$   r%   is_index_urls      r   set_extra_headersz#StaticFileHandler.set_extra_headersH   sM     4yA~+2248OOOZ8 OO-.P-QRr   c                4   	 t         |   ||      S # t        j                  j                  $ r}|j
                  dk(  r| j                  t        j                  j                  dk7  r*j                  t        j                  j                  d      t        fd| j                  D              r | j                  | j                  xs d      | _        | j                  | j                  | j                        }t         |   ||      cY d }~S  d }~ww xY w)N  /c              3  @   K   | ]  }j                  |        y wr    )endswith).0xurl_paths     r   	<genexpr>z;StaticFileHandler.validate_absolute_path.<locals>.<genexpr>e   s     Jx((+Js   
index.html)r"   validate_absolute_pathtornadoweb	HTTPErrorstatus_coder%   ossepreplaceanyr!   parse_url_pathr&   get_absolute_pathroot)r$   rG   absolute_pather9   r(   s       @r   r<   z(StaticFileHandler.validate_absolute_pathY   s    	71$FF{{$$ 	 }}#99 77;;#%'//SAHJT5I5IJJ //0E0E0UV	 $ 6 6tyy$)) Lw5dMJJ!	s!    DCDDDDc                    |dk(  rDt         j                  j                  t        j                         d      }| j                  |       y t        |   |fi | y )Nr3   r;   )rA   r%   joinr	   get_static_dirrenderr"   write_error)r$   r@   kwargs
index_filer(   s       r   rN   zStaticFileHandler.write_errorn   sF    #i&>&>&@,OJKK
#G6v6r   )Nr   )r%   r   r&   
str | Noner'   zSequence[str]returnNone)r%   r   rR   rS   )rG   r   rH   r   rR   rQ   )r@   intrO   r   rR   rS   )__name__
__module____qualname__r#   r1   r<   rN   __classcell__)r(   s   @r   r   r   =   sJ     (,(*	33 %3 &	3
 
3"*7 7r   r   c                  F    e Zd Zej                  j
                  dd       Zy)AddSlashHandlerc                     y r    r   r$   s    r   getzAddSlashHandler.getw       r   NrR   rS   )rU   rV   rW   r=   r>   addslashr]   r   r   r   rZ   rZ   v   s    [[ r   rZ   c                  F    e Zd Zej                  j
                  dd       Zy)RemoveSlashHandlerc                     y r    r   r\   s    r   r]   zRemoveSlashHandler.get}   r^   r   Nr_   )rU   rV   rW   r=   r>   removeslashr]   r   r   r   rb   rb   |   s    [[ r   rb   c                       e Zd ZdZddZddZy)_SpecialRequestHandlerz2Superclass for "special" endpoints, like /healthz.c                    | j                  dd       t               r| j                  dd       y t        | j                  j                  j                  d      x}      r| j                  dt        d|             y y )Nr*   r+   zAccess-Control-Allow-Origin*Originr   )r/   r   r   requestheadersr]   r   )r$   r   s     r   set_default_headersz*_SpecialRequestHandler.set_default_headers   sc    4*,OO93?)=)=)A)A()KKvLOO94v;NO Mr   c                F    | j                  d       | j                          y)a  /OPTIONS handler for preflight CORS checks.

        When a browser is making a CORS request, it may sometimes first
        send an OPTIONS request, to check whether the server understands the
        CORS protocol. This is optional, and doesn't happen for every request
        or in every browser. If an OPTIONS request does get sent, and is not
        then handled by the server, the browser will fail the underlying
        request.

        The proper way to handle this is to send a 204 response ("no content")
        with the CORS headers attached. (These headers are automatically added
        to every outgoing response, including OPTIONS responses,
        via set_default_headers().)

        See https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request
           N)
set_statusfinishr\   s    r   optionsz_SpecialRequestHandler.options   s    " 	r   Nr_   )rU   rV   rW   __doc__rl   rq   r   r   r   rf   rf      s    <Pr   rf   c                  ,    e Zd ZddZddZddZddZy)HealthHandlerc                    || _         y)zInitialize the handler.

        Parameters
        ----------
        callback : callable
            A function that returns True if the server is healthy

        N)	_callback)r$   callbacks     r   r#   zHealthHandler.initialize   s     "r   c                @   K   | j                          d {    y 7 wr    handle_requestr\   s    r   r]   zHealthHandler.get        !!###   c                @   K   | j                          d {    y 7 wr    ry   r\   s    r   headzHealthHandler.head   r{   r|   c                @  K   | j                   j                  rAd| j                   j                  vr)d| j                   j                  v rdnd}t        | |       | j                          d {   \  }}|r| j	                  |       | j                  d       t               rU| j                  j                  di       } | j                  | j                  j                  dd	      | j                  fi | y y | j                  d
       | j	                  |       y 7 w)Nz_stcore/zscript-health-checkz/_stcore/script-health-checkz/_stcore/health)new_path   xsrf_cookie_kwargsxsrf_cookie_name_streamlit_xsrfi  )rj   urir   rv   writero   r   settingsr]   
set_cookie
xsrf_token)r$   r   okmsgcookie_kwargss        r   rz   zHealthHandler.handle_request   s     <<
$,,2B2B B )DLL,<,<< /& 
 -THE((CJJsOOOC    $ 1 12F KMM%%&8:KLOO $ ! OOC JJsO+ )s   A+D-D.B/DN)rw   z)Callable[[], Awaitable[tuple[bool, str]]]rR   rS   r_   )rU   rV   rW   r#   r]   r~   rz   r   r   r   rt   rt      s    	"$
$r   rt   )zhttps://devel.streamlit.testzhttps://*.streamlit.apptestzhttps://*.streamlitapp.testzhttps://*.streamlitapp.comzhttps://share.streamlit.iozhttps://share-demo.streamlit.iozhttps://share-head.streamlit.ioz"https://share-staging.streamlit.iozhttps://*.demo.streamlit.runzhttps://*.head.streamlit.runzhttps://*.staging.streamlit.runzhttps://*.streamlit.runzhttps://*.demo.streamlit.appzhttps://*.head.streamlit.appzhttps://*.staging.streamlit.appzhttps://*.streamlit.appc                      e Zd ZddZddZy)HostConfigHandlerc                    t         j                         | _        t        j                  d      r+d| j                  vr| j                  j                  d       y y y )Nr   zhttp://localhost) _DEFAULT_ALLOWED_MESSAGE_ORIGINScopy_allowed_originsr   r   appendr\   s    r   r#   zHostConfigHandler.initialize   sT     @ E E G 67"$*?*?? !!(();< @ 8r   c           
     t   K   | j                  | j                  dddddd d       | j                  d       y w)NF )allowedOriginsuseExternalAuthTokenenableCustomParentMessagesenforceDownloadInNewTab
metricsUrlblockErrorDialogsresourceCrossOriginModer   )r   r   ro   r\   s    r   r]   zHostConfigHandler.get   sB     

"&"7"7(-.3+0 %* ,0	
 	s   68Nr_   )rU   rV   rW   r#   r]   r   r   r   r   r      s    	=r   r   )rR   bool)r   r   rR   r   )%
__future__r   rA   retypingr   r   r   r   tornado.webr=   	streamlitr   r	    streamlit.web.server.server_utilr
   r   r   collections.abcr   r   r   compiler-   r   __annotations__r   r   r>   r   RequestHandlerrZ   rb   rf   rt   r   r   r   r   r   <module>r      s    # 	 	 2 2  '  == 2::=>  -? "E >+6755 67rgkk00 33 W[[77 >2* 2j$  .. r   