
    g>                        U d dl mZ d dlZd dlZd dlmZmZ d dlZd dl	Z
d dlmZ erd dlmZ  ee      Zded<    G d d	ej$                  j&                        Zy)
    )annotationsN)TYPE_CHECKINGFinal)
get_logger)BaseComponentRegistryr   _LOGGERc                  X    e Zd Zd	dZd
dZd
dZddZddZedd       Z	edd       Z
y)ComponentRequestHandlerc                    || _         y )N)	_registry)selfregistrys     c/var/www/openai/venv/lib/python3.12/site-packages/streamlit/web/server/component_request_handler.py
initializez"ComponentRequestHandler.initialize!   s	    !    c                   |j                  d      }|d   }| j                  j                  |      }|#| j                  d       | j	                  d       y t
        j                  j                  |      }dj                  |dd        }t
        j                  j                  t
        j                  j                  ||            }t
        j                  j                  ||g      |k7  r#| j                  d       | j	                  d       y 	 t        |d      5 }|j                         }d d d        | j                         | j!                  d| j#                  |             | j%                  |       y # 1 sw Y   MxY w# t        $ rD}	t        j                  d	||	
       | j                  d       | j	                  d       Y d }	~	y d }	~	ww xY w)N/r   z	not foundi     	forbiddeni  rbz*ComponentRequestHandler: GET %s read error)exc_infoz
read errorzContent-Type)splitr   get_component_pathwrite
set_statusospathrealpathjoinnormpath
commonpathopenreadOSErrorr   error
set_headerget_content_typeset_extra_headers)
r   r   partscomponent_namecomponent_rootfilenameabspathfilecontentses
             r   getzComponentRequestHandler.get$   sw   

3q::>J!JJ{#OOC  )).988E!"I&''""277<<#IJ 77~w78NJJJ{#OOC 		gt$99; % 	

8(=(=g(FGt$ %$ 	MM<gPQ   JJ|$OOC 	s0   F E8,F 8F=F 	G:GG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.htmlzCache-Controlzno-cachepublicN)lenendswithr&   )r   r   is_index_urls      r   r(   z)ComponentRequestHandler.set_extra_headersG   s;     4yA~4==1OOOZ8OOOX6r   c                    t         j                  j                  j                  j	                         r| j                  dd       y y )NzAccess-Control-Allow-Origin*)	streamlitwebserverroutesallow_cross_origin_requestsr&   r   s    r   set_default_headersz+ComponentRequestHandler.set_default_headersT   s3    ==&&BBDOO93? Er   c                F    | j                  d       | j                          y)z+/OPTIONS handler for preflight CORS checks.   N)r   finishr>   s    r   optionszComponentRequestHandler.optionsX   s    r   c                N    t        j                  |       \  }}|dk(  ry|y||S y)zuReturns the ``Content-Type`` header to be used for this request.
        From tornado.web.StaticFileHandler.
        gzipzapplication/gzipzapplication/octet-stream)	mimetypes
guess_type)r-   	mime_typeencodings      r   r'   z(ComponentRequestHandler.get_content_type]   s@    
 (227;	8v% !-" .r   c                    d|  S )z6Return the URL for a component file with the given ID.zcomponents/ )file_ids    r   get_urlzComponentRequestHandler.get_urlq   s     WI&&r   N)r   r   )r   strreturnNone)rO   rP   )r-   rN   rO   rN   )rL   rN   rO   rN   )__name__
__module____qualname__r   r1   r(   r?   rC   staticmethodr'   rM   rK   r   r   r
   r
       sE    "!%F7@
 . .& ' 'r   r
   )
__future__r   rF   r   typingr   r   tornado.webtornadostreamlit.web.server.routesr9   streamlit.loggerr   2streamlit.components.types.base_component_registryr   rQ   r   __annotations__r:   RequestHandlerr
   rK   r   r   <module>r^      sI    #  	 '  " 'XH% %T'gkk88 T'r   