
    g                       d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZ d dlmZ d dlmZ erd d	lmZ d d
lmZmZ d dlmZ ddZedd       Z G d deeef         Z G d deeef         Z G d d      Z y)    )annotations)IterableIteratorMapping)	lru_cache)MappingProxyType)TYPE_CHECKINGAnycast)runtime)gather_metrics)get_script_run_ctx)Morsel)HTTPHeadersHTTPServerRequest)RequestHandlerc                 
   t               } | y t        j                         j                  | j                        }|y t        |      j                   dt        |      j                   dk7  ry t        d|      j                  S )N.zFstreamlit.web.server.browser_websocket_handler.BrowserWebSocketHandlerr   )
r   r   get_instance
get_client
session_idtype
__module____qualname__r   request)ctxsession_clients     N/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/context.py_get_requestr   !   s    

C
{))+66s~~FN **
+1T.-A-N-N,OPS	T  .1999    c                P    dj                  d | j                  d      D              S )ziMap a header name to Http-Header-Case.

    >>> _normalize_header("coNtent-TYPE")
    'Content-Type'
    -c              3  <   K   | ]  }|j                           y wN)
capitalize).0ws     r   	<genexpr>z$_normalize_header.<locals>.<genexpr>>   s     <OqALLNOs   )joinsplit)names    r   _normalize_headerr,   7   s!     88<DJJsO<<<r    c                  N    e Zd Zd	dZed
d       ZddZddZddZddZ	ddZ
y)StreamlitHeadersc                    i }|D ]1  \  }}|j                  t        |      g       }|j                  |       3 || _        y r$   )
setdefaultr,   append_headers)selfheadersdict_like_headerskeyvalueheader_values         r   __init__zStreamlitHeaders.__init__B   sF    24!JC,778I#8NPRSL& " *r    c                .     | |j                               S r$   )get_all)clstornado_headerss     r   from_tornado_headersz%StreamlitHeaders.from_tornado_headersK   s    ?**,--r    c                ^    t        | j                  j                  t        |      g             S r$   )listr2   getr,   r3   r6   s     r   r;   zStreamlitHeaders.get_allO   s$    DMM%%&7&<bABBr    c                l    	 | j                   t        |         d   S # t        $ r t        |      d w xY w)Nr   )r2   r,   LookupErrorKeyErrorrB   s     r   __getitem__zStreamlitHeaders.__getitem__R   s<    	*==!23!78;; 	*3-T)	*s    3c                ,    t        | j                        S z,Number of unique headers present in request.)lenr2   r3   s    r   __len__zStreamlitHeaders.__len__X       4==!!r    c                ,    t        | j                        S r$   )iterr2   rJ   s    r   __iter__zStreamlitHeaders.__iter__\       DMM""r    c                4    | D ci c]  }|| |   
 c}S c c}w r$    rB   s     r   to_dictzStreamlitHeaders.to_dict_   s"    *./$3T#Y$///s   N)r4   zIterable[tuple[str, str]])r=   r   returnr.   )r6   strrT   z	list[str]r6   rU   rT   rU   rT   intrT   zIterator[str]rT   zdict[str, str])__name__r   r   r9   classmethodr>   r;   rF   rK   rO   rS   rR   r    r   r.   r.   A   s5    * . .C*"#0r    r.   c                  N    e Zd ZddZe	 	 	 	 d	d       Zd
dZddZddZddZ	y)StreamlitCookiesc                $    t        |      | _        y r$   )r   _cookies)r3   cookiess     r   r9   zStreamlitCookies.__init__d   s    (1r    c                d    i }|j                         D ]  \  }}|j                  ||<     | |      S r$   )itemsr7   )r<   tornado_cookiesdict_like_cookiesr6   morsels        r   from_tornado_cookiesz%StreamlitCookies.from_tornado_cookiesg   s<     *002KC%+\\c" 3$%%r    c                     | j                   |   S r$   )r`   rB   s     r   rF   zStreamlitCookies.__getitem__p   s    }}S!!r    c                ,    t        | j                        S rH   )rI   r`   rJ   s    r   rK   zStreamlitCookies.__len__s   rL   r    c                ,    t        | j                        S r$   )rN   r`   rJ   s    r   rO   zStreamlitCookies.__iter__w   rP   r    c                ,    t        | j                        S r$   )dictr`   rJ   s    r   rS   zStreamlitCookies.to_dictz   rP   r    N)ra   zMapping[str, str])rd   zdict[str, Morsel[Any]]rT   r^   rV   rW   rY   rZ   )
r[   r   r   r9   r\   rg   rF   rK   rO   rS   rR   r    r   r^   r^   c   s?    2 &4&	& &""##r    r^   c                  `    e Zd ZdZe ed      dd              Ze ed      dd              Zy)	ContextProxya  An interface to access user session context.

    ``st.context`` provides a read-only interface to access headers and cookies
    for the current user session.

    Each property (``st.context.headers`` and ``st.context.cookies``) returns
    a dictionary of named values.

    zcontext.headersc                n    t               }|t        i       S t        j                  |j                        S )a  A read-only, dict-like object containing headers sent in the initial request.

        Keys are case-insensitive and may be repeated. When keys are repeated,
        dict-like methods will only return the last instance of each key. Use
        ``.get_all(key="your_repeated_key")`` to see all values if the same
        header is set multiple times.

        Examples
        --------
        Show a dictionary of headers (with only the last instance of any
        repeated key):

        >>> import streamlit as st
        >>>
        >>> st.context.headers

        Show the value of a specific header (or the last instance if it's
        repeated):

        >>> import streamlit as st
        >>>
        >>> st.context.headers["host"]

        Show of list of all headers for a given key:

        >>> import streamlit as st
        >>>
        >>> st.context.headers.get_all("pragma")

        )r   r.   r>   r4   )r3   session_client_requests     r   r4   zContextProxy.headers   s6    F ".!)#B''445K5S5STTr    zcontext.cookiesc                r    t               }|t        i       S |j                  }t        j                  |      S )as  A read-only, dict-like object containing cookies sent in the initial request.

        Examples
        --------
        Show a dictionary of cookies:

        >>> import streamlit as st
        >>>
        >>> st.context.cookies

        Show the value of a specific cookie:

        >>> import streamlit as st
        >>>
        >>> st.context.cookies["_ga"]

        )r   r^   ra   rg   )r3   rp   ra   s      r   ra   zContextProxy.cookies   s9    , ".!)#B''(0044W==r    N)rT   r.   )rT   r^   )r[   r   r   __doc__propertyr   r4   ra   rR   r    r   rn   rn   ~   sN     %&&U ' &UP %&> ' >r    rn   N)rT   zHTTPServerRequest | None)r+   rU   rT   rU   )!
__future__r   collections.abcr   r   r   	functoolsr   typesr   typingr	   r
   r   	streamlitr   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   http.cookiesr   tornado.httputilr   r   tornado.webr   r   r,   rU   r.   r^   rn   rR   r    r   <module>r      s    # 7 7  " + +  9 V#?*:, = =0wsCx( 0D#wsCx( #6Q> Q>r    