L i <DddlmZddlmZmZmZddlmZddlm Z ddl m Z m Z m Z mZddlmZddlmZmZddlmZdd lmZdd lmZe rdd lmZdd lmZmZdd lm Z ddZ!eddZ"GddeZ#Gddee$e$fZ%Gddee$e$fZ&GddZ'y)) annotations)IterableIteratorMapping) lru_cache)MappingProxyType) TYPE_CHECKINGAnyLiteralcast)runtime)maybe_add_page_pathmaybe_trim_page_path)gather_metrics)get_script_run_ctx)AttributeDictionary)Morsel) HTTPHeadersHTTPServerRequest)RequestHandlerc t}|ytjj|j}|yt |j dt |jdk7rytd|jS)N.zFstreamlit.web.server.browser_websocket_handler.BrowserWebSocketHandlerr) rr get_instance get_client session_idtype __module__ __qualname__r request)ctxsession_clients _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/runtime/context.py _get_requestr##s  C {))+66s~~FN   * * +1T.-A-N-N,OP S T  . 1 9 99cPdjd|jdDS)ziMap a header name to Http-Header-Case. >>> _normalize_header("coNtent-TYPE") 'Content-Type' -c3<K|]}|jywN) capitalize).0ws r" z$_normalize_header..@sreturnr2) __name__rr__doc____annotations__r5 classmethodr= __classcell__)r8s@r"r2r2Cs) *)%!!r$r2cNeZdZd dZed dZd dZd dZd dZddZ ddZ y)StreamlitHeadersci}|D]1\}}|jt|g}|j|3||_yr() setdefaultr0append_headers)r6headersdict_like_headerskeyvalue header_values r"r5zStreamlitHeaders.__init__XsK24! 'JC,778I#8NPRSL    & '* r$c.||jSr()get_all)r;tornado_headerss r"from_tornado_headersz%StreamlitHeaders.from_tornado_headersas?**,--r$c^t|jjt|gSr()listrJgetr0r6rMs r"rQzStreamlitHeaders.get_alles$DMM%%&7&>> import streamlit as st >>> >>> st.context.headers **Example 2: Access a specific header** 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#rFrSrK)r6session_client_requests r"rKzContextProxy.headerss6N". ! )#B' '445K5S5STTr$zcontext.cookiescrt}| tiS|j}tj|S)aA read-only, dict-like object containing cookies sent in the initial request. Examples -------- **Example 1: Access all available cookies** Show a dictionary of cookies: >>> import streamlit as st >>> >>> st.context.cookies **Example 2: Access a specific cookie** Show the value of a specific cookie: >>> import streamlit as st >>> >>> st.context.cookies["_ga"] )r#rprsry)r6rrss r"rszContextProxy.cookiess94". ! )#B' '(0044W==r$z context.themect}| |j tddiStjd|jjiS)a8A read-only, dictionary-like object containing theme information. Theme information is restricted to the ``type`` of the theme (dark or light) and is inferred from the background color of the app. .. note:: Changes made to the background color through CSS are not included. Additionally, the theme type may be incorrect during a change in theme, like in the following situations: - When the app is first loaded within a session - When the user changes the theme in the settings menu For more information and to upvote an improvement, see GitHub issue `#11920 `_. Attributes ---------- type : "light", "dark" The theme type inferred from the background color of the app. Example ------- Access the theme type of the app: >>> import streamlit as st >>> >>> st.write(f"The current theme type is {st.context.theme.type}.") Nr)r context_infor2r= color_schemer6r s r"themezContextProxy.themesNB!" ;#**2!64.1 1//9I9I9V9V0WXXr$zcontext.timezonec`t}| |jy|jjS)aFThe read-only timezone of the user's browser. Example ------- Access the user's timezone, and format a datetime to display locally: >>> import streamlit as st >>> from datetime import datetime, timezone >>> import pytz >>> >>> tz = st.context.timezone >>> tz_obj = pytz.timezone(tz) >>> >>> now = datetime.now(timezone.utc) >>> >>> f"The user's timezone is {tz}." >>> f"The UTC time is {now}." >>> f"The user's local time is {now.astimezone(tz_obj)}" N)rrtimezoners r"rzContextProxy.timezones1.!" ;#**2(((r$zcontext.timezone_offsetc`t}| |jy|jjS)acThe read-only timezone offset of the user's browser. Example ------- Access the user's timezone offset, and format a datetime to display locally: >>> import streamlit as st >>> from datetime import datetime, timezone, timedelta >>> >>> tzoff = st.context.timezone_offset >>> tz_obj = timezone(-timedelta(minutes=tzoff)) >>> >>> now = datetime.now(timezone.utc) >>> >>> f"The user's timezone is {tz}." >>> f"The UTC time is {now}." >>> f"The user's local time is {now.astimezone(tz_obj)}" N)rrtimezone_offsetrs r"rzContextProxy.timezone_offset4s1,!" ;#**2///r$zcontext.localec`t}| |jy|jjS)aThe read-only locale of the user's browser. ``st.context.locale`` returns the value of |navigator.language|_ from the user's DOM. This is a string representing the user's preferred language (e.g. "en-US"). .. |navigator.language| replace:: ``navigator.language`` .. _navigator.language: https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language Example ------- Access the user's locale to display locally: >>> import streamlit as st >>> >>> if st.context.locale == "fr-FR": >>> st.write("Bonjour!") >>> else: >>> st.write("Hello!") N)rrlocalers r"rzContextProxy.localeOs10!" ;#**2&&&r$z context.urlct}| |jy|jj}t||j}t ||jS)asThe read-only URL of the app in the user's browser. ``st.context.url`` returns the URL through which the user is accessing the app. This includes the scheme, domain name, port, and path. If query parameters or anchors are present in the URL, they are removed and not included in this value. Example ------- Conditionally show content when you access your app through ``localhost``: >>> import streamlit as st >>> >>> if st.context.url.startswith("http://localhost"): >>> st.write("You are running the app locally.") N)rrurlr pages_managerr)r6r url_from_frontendurl_without_page_prefixs r"rzContextProxy.urlls](!" ;#**2,,00"6 s00# ##:C>> import streamlit as st >>> >>> ip = st.context.ip_address >>> if ip is None: >>> st.write("No IP address. This is expected in local development.") >>> elif ip.contains(":"): >>> st.write("You have an IPv6 address.") >>> elif ip.contains("."): >>> st.write("You have an IPv4 address.") >>> else: >>> st.error("This should not happen.") N>::1 127.0.0.1)r# remote_ip)r6rrs r" ip_addresszContextProxy.ip_addresss2<". ! -.88I00 r$zcontext.is_embeddedc`t}| |jy|jjS)aWhether the app is embedded. This property returns a boolean value indicating whether the app is running in an embedded context. This is determined by the presence of ``embed=true`` as a query parameter in the URL. This is the only way to determine if the app is currently configured for embedding because embedding settings are not accessible through ``st.query_params`` or ``st.context.url``. Example ------- Conditionally show content when the app is running in an embedded context: >>> import streamlit as st >>> >>> if st.context.is_embedded: >>> st.write("You are running the app in an embedded context.") N)rr is_embeddedrs r"rzContextProxy.is_embeddeds1,!" ;#**2+++r$N)r?rF)r?rp)r?r2)r?z str | None)r?z int | None)r?z bool | None)r@rrrApropertyrrKrsrrrrrrrr:r$r"rrsA%&*U'*UX%&>'>@O$$Y%$YL&')()6-.0/02$%'&'6M"O#O8()"*"H)*,+,r$rN)r?zHTTPServerRequest | None)r/rir?ri)( __future__rcollections.abcrrr functoolsrtypesrtypingr r r r streamlitr streamlit.runtime.context_utilrrstreamlit.runtime.metrics_utilr7streamlit.runtime.scriptrunner_utils.script_run_contextrstreamlit.utilr http.cookiesrtornado.httputilrr tornado.webrr#r0r2rirFrprr:r$r"rs#77"44T9V.#?*:, = =!(!(0wsCx(0D#wsCx(#6u,u,r$