L iUdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZddlmZer ddlmZdd lmZd Zd ed <d Zd ed<ddZddZddZddZd dZd!dZdd d"dZd#dZ d$dZ!d%dZ"y)&z!Server related utility functions.) annotations) TYPE_CHECKINGFinalLiteralcast)urljoin)confignet_utilurl_util)secrets_singleton)is_version_less_than)Callable)RequestHandleri rDEVELOPMENT_PORT_streamlit_userAUTH_COOKIE_NAMEcntjdDchc]}|jc}Scc}w)Nzserver.corsAllowedOrigins)r get_optionstrip)origins f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/web/server/server_util.pyallowlisted_originsr%s()/):):;V)W XvFLLN XX Xs2c6ddl}t|j|S)aReturn True if the current Tornado version is less than the input version. Parameters ---------- v : str Version string, e.g. "0.25.0" Returns ------- bool Raises ------ InvalidVersion If the version strings are not valid. rN)tornador version)vrs ris_tornado_version_less_thanr)s$  33cVtjdsytj|}t Dcgc]}tj|}}dddt t jt jg|}|D] }t|r|n|}|||k(s yycc}w)aReturn True if URL is from allowed origins (for CORS purpose). Allowed origins: 1. localhost 2. The internal and external IP addresses of the machine where this function was called from. If `server.enableCORS` is False, this allows all origins. zserver.enableCORST localhostz0.0.0.0z 127.0.0.1F) r rr get_hostnamer#_get_server_address_if_manually_setr get_internal_ipget_external_ipcallable)urlhostnamerallowlisted_domainsallowed_domainsallowed_domainallowed_domain_strs ris_url_from_allowed_originsr,@s   0 1$$S)H5H4I*0f%  ,     D  DO*  ( 8N n   %  ) )  ;sB&ctjd}tjr)tjd}|r|j d|}|S)zcGet the cookie secret. If the user has not set a cookie secret, we generate a random one. zserver.cookieSecretauth cookie_secret)r rr load_if_toml_existsget)r/ auth_sections rget_cookie_secretr3psL  **+@AM,,.(,,V4 (,,_mLM rctjd}|s2tjrtjdd}|xs|du}t d|S)Nzserver.enableXsrfProtectionr.bool)r rr r0r1r) csrf_enabledr2s ris_xsrf_enabledr7}sP$$%BCL -AAC(,,VT: #?|4'?  %%rc~tjdr(tjtjdSy)Nzbrowser.serverAddress)r is_manually_setr r!rrrr"r"s1 56$$V%6%67N%OPP roptional)trailing_slashc|Dcgc]}|s|jd}}d}|dk(rd}n|dk(rd}|dj|zScc}w)zDGet a regex of the form ^/foo/bar/baz/?$ for a path (foo, bar, baz)./z^/%s$r;z^/%s/?$requiredz^/%s/$)rjoin)r<pathxfiltered_paths path_formats rmake_url_path_regexrEsY -16qAaggcl6N6K# : % .1 117s AActjdrdnd}t}tjdjd}|rd|z}|jd}|d|d||S)zGet the URL for any app served at the given host_ip. Parameters ---------- host_ip : str The IP address of the machine that is running the Streamlit Server. Returns ------- str The URL. zserver.sslCertFilehttpshttpzserver.baseUrlPathr>://:)r r_get_browser_address_bar_portr)host_ipprotocolport base_paths rget_urlrPsr!++,@AwvH ( *D!!"67==cBI)O mmC GZs7)1TF9+ 66rcttjdrtSttjdS)zGet the app URL that will be shown in the browser's address bar. That is, this is the port where static assets will be served from. In dev, this is different from the URL that will be used to connect to the server-browser websocket. zglobal.developmentModezbrowser.serverPort)r rrintr:rrrKrKs012 v  !56 77rc|jddt|jjd|jj|}|jdd|dy)zHEmits the warning about deprecation of HTTP endpoint in the HTTP header. DeprecationTrILink; rel="alternate"N) set_headerrrequestrMhost)handlernew_pathnew_urls r emit_endpoint_deprecation_noticer]sY }d+112#goo6J6J5KLhWG v7)+=>?rN)returnzset[str])rstrr^r5)r&r_r^r5)r^r_)r^r5)r^z str | None)rAr_r<z-Literal['optional', 'required', 'prohibited']r^r_)rLr_r^r_)r^rR)rZrr[r_r^None)#__doc__ __future__rtypingrrrr urllib.parser streamlitr r r streamlit.runtime.secretsr streamlit.type_utilr collections.abcr tornado.webrr__annotations__rrrr,r3r7r"rErPrKr]r:rrrks("66 0074(*%+%+Y4.-` &EO 2  2A 2  272 8@r