
    gx(                       U d dl mZ d dlZd dlmZm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 erd dlmZ  ee      Zd	ed
<   ddZ G d dej0                  j2                        Z G d dej0                  j4                        Z G d dej0                  j4                        Z G d dej0                  j4                        Z G d de      Zg dZ G d de      Z  G d dej0                  j4                        Z!y)    )annotationsN)TYPE_CHECKINGFinal)config	file_util)
get_logger)serialize_forward_msg) emit_endpoint_deprecation_noticeis_xsrf_enabled)Sequencer   _LOGGERc                 \    t        j                  d       xs t        j                  d      S )a  True if cross-origin requests are allowed.

    We only allow cross-origin requests when CORS protection has been disabled
    with server.enableCORS=False or if using the Node server. When using the
    Node server, we have a dev and prod port, which count as two origins.

    zserver.enableCORSglobal.developmentMode)r   
get_option     P/var/www/openai/venv/lib/python3.12/site-packages/streamlit/web/server/routes.pyallow_cross_origin_requestsr   $   s0       !455 9J9J : r   c                  P     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.initialize2   s      .4!12r   c                    t        |      dk(  }|s|j                  d      r| j                  dd       y| j                  dd       y)zDisable cache for HTML files.

        Other assets like JS and CSS are suffixed with their hash, so they can
        be cached indefinitely.
        r   z.htmlCache-Controlno-cachepublicN)lenendswith
set_header)r   r   is_index_urls      r   set_extra_headersz#StaticFileHandler.set_extra_headers<   s;     4yA~4==1OOOZ8OOOX6r   c                8   	 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   )r&   ).0xurl_paths     r   	<genexpr>z;StaticFileHandler.validate_absolute_path.<locals>.<genexpr>T   s     J5Ix((+5Is   
index.html)r   validate_absolute_pathtornadoweb	HTTPErrorstatus_coder   ossepreplaceanyr   parse_url_pathr   get_absolute_pathroot)r   r>   absolute_pather0   r    s       @r   r3   z(StaticFileHandler.validate_absolute_pathH   s    	71$FF{{$$ 	 }}#99 77;;#%'//SAHJT5I5IJJG //0E0E0UV	 $ 6 6tyy$)) Lw5dMJJG!	s!    DCDDDDc                    |dk(  rDt         j                  j                  t        j                         d      }| j                  |       y t        |   |fi | y )Nr+   r2   )r8   r   joinr   get_static_dirrenderr   write_error)r   r7   kwargs
index_filer    s       r   rE   zStaticFileHandler.write_error]   sF    #i&>&>&@,OJKK
#G6v6r   )Nr   )r   strr   
str | Noner   zSequence[str])r   rH   returnNone)r>   rH   r?   rH   rJ   rI   )r7   intrJ   rK   )__name__
__module____qualname__r   r)   r3   rE   __classcell__)r    s   @r   r   r   1   s@     (,(*	33 %3 &	3
7*7 7r   r   c                  D    e Zd Zej                  j
                  d        Zy)AddSlashHandlerc                     y r   r   r   s    r   getzAddSlashHandler.getf       r   N)rM   rN   rO   r4   r5   addslashrU   r   r   r   rR   rR   e   s    [[ r   rR   c                  D    e Zd Zej                  j
                  d        Zy)RemoveSlashHandlerc                     y r   r   rT   s    r   rU   zRemoveSlashHandler.getl   rV   r   N)rM   rN   rO   r4   r5   removeslashrU   r   r   r   rY   rY   k   s    [[ r   rY   c                      e Zd ZdZd Zd Zy)_SpecialRequestHandlerz2Superclass for "special" endpoints, like /healthz.c                b    | j                  dd       t               r| j                  dd       y y )Nr"   r#   Access-Control-Allow-Origin*)r'   r   rT   s    r   set_default_headersz*_SpecialRequestHandler.set_default_headerst   s*    4&(OO93? )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finishrT   s    r   optionsz_SpecialRequestHandler.optionsy   s    " 	r   N)rM   rN   rO   __doc__ra   rg   r   r   r   r]   r]   q   s    <@
r   r]   c                  $    e Zd Zd Zd Zd Z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_requestrT   s    r   rU   zHealthHandler.get        !!###   c                @   K   | j                          d {    y 7 wr   ro   rT   s    r   headzHealthHandler.head   rq   rr   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  )requesturir
   rl   writere   r   settingsrU   
set_cookie
xsrf_token)r   rv   okmsgcookie_kwargss        r   rp   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)rM   rN   rO   r   rU   rt   rp   r   r   r   rj   rj      s    	"$
$r   rj   )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 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   appendrT   s    r   r   zHostConfigHandler.initialize   sT     @ E E G 67"$*?*?? !!(();< @ 8r   c                p   K   | j                  | j                  ddddd       | j                  d       y w)NF )allowedOriginsuseExternalAuthTokenenableCustomParentMessagesenforceDownloadInNewTab
metricsUrlrw   )r}   r   re   rT   s    r   rU   zHostConfigHandler.get   s:     

"&"7"7(-.3+0 		
 	s   46N)rJ   rK   )rM   rN   rO   r   rU   r   r   r   r   r      s    	=r   r   c                  (    e Zd ZdZd Zd Zd Zd Zy)MessageCacheHandlerz)Returns ForwardMsgs from our MessageCachec                    || _         y)zfInitializes the handler.

        Parameters
        ----------
        cache : MessageCache

        N)_cache)r   caches     r   r   zMessageCacheHandler.initialize   s     r   c                >    t               r| j                  dd       y y )Nr_   r`   )r   r'   rT   s    r   ra   z'MessageCacheHandler.set_default_headers  s    &(OO93? )r   c                   | j                  dd       }t        j                  d      s"| j                  d       | j	                          y |Dt
        j                  d       | j                  d       t        j                  j                         | j                  j                  |      }|Dt
        j                  d       | j                  d       t        j                  j                         t
        j                  d       t        |      }| j                  dd	       | j                  |       | j                  d
       y )Nhashz)global.storeCachedForwardMessagesInMemoryi  z>HTTP request for cached message is missing the hash attribute.r+   zGHTTP request for cached message could not be fulfilled. No such messagezMessageCache HITzContent-Typezapplication/octet-streamrw   )get_argumentr   r   re   rf   r   errorr4   r5   Finishr   get_messagedebugr	   r'   r}   )r   msg_hashmessagemsg_strs       r   rU   zMessageCacheHandler.get  s    $$VT2  !LMOOC KKMMMP OOC ++$$&&++))(3?MM" OOC ++$$&&()'0(BC

7r   c                F    | j                  d       | j                          y)z+/OPTIONS handler for preflight CORS checks.rc   Nrd   rT   s    r   rg   zMessageCacheHandler.options$  s    r   N)rM   rN   rO   rh   r   ra   rU   rg   r   r   r   r   r      s    3@>r   r   )rJ   bool)"
__future__r   r8   typingr   r   tornado.webr4   	streamlitr   r   streamlit.loggerr   streamlit.runtime.runtime_utilr	    streamlit.web.server.server_utilr
   r   collections.abcr   rM   r   __annotations__r   r5   r   RequestHandlerrR   rY   r]   rj   r   r   r   r   r   r   <module>r      s    # 	 '  ' ' @
 (H% %
1755 17hgkk00 33 W[[77 :2* 2j$  .. 43'++44 3r   