
    g^                        U d 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
mZmZ ddlmZ erddlmZ dZd	ed
<   dZd	ed<   ddZddZd ZddZdd	 	 	 ddZddZddZddZy)z Server related utility functions    )annotations)TYPE_CHECKINGFinalLiteral)urljoin)confignet_utilurl_util)secrets_singleton)RequestHandleri  r   DEVELOPMENT_PORT_streamlit_userAUTH_COOKIE_NAMEc                    t        j                  d      syt        j                  |       }dddt        t
        j                  t
        j                  g}|D ]  }t        |      r |       }|||k(  s y y)a  Return 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.
    zserver.enableCORST	localhostz0.0.0.0z	127.0.0.1F)	r   
get_optionr
   get_hostname#_get_server_address_if_manually_setr	   get_internal_ipget_external_ipcallable)urlhostnameallowed_domainsallowed_domains       U/var/www/openai/venv/lib/python3.12/site-packages/streamlit/web/server/server_util.pyis_url_from_allowed_originsr   "   s     01$$S)H 	 	,    O *N#+-N!~% *     c                     t        j                  d      } t        j                         r)t        j                  d      }|r|j	                  d|       } | S )zcGet the cookie secret.

    If the user has not set a cookie secret, we generate a random one.
    zserver.cookieSecretauthcookie_secretr   r   r   load_if_toml_existsget)r!   auth_sections     r   get_cookie_secretr&   L   sL    
  **+@AM,,.(,,V4(,,_mLMr   c                     t        j                  d      } | s2t        j                         rt        j                  dd       }| xs |d u} | S )Nzserver.enableXsrfProtectionr    r"   )csrf_enabledr%   s     r   is_xsrf_enabledr)   Y   sI    $$%BCL-AAC(,,VT:#?|4'?r   c                 ~    t        j                  d      r(t        j                  t        j                  d            S y )Nzbrowser.serverAddress)r   is_manually_setr
   r   r    r   r   r   r   a   s1    56$$V%6%67N%OPPr   optional)trailing_slashc                    |D cg c]  }|s|j                  d       }}d}| dk(  rd}n| dk(  rd}|dj                  |      z  S c c}w )zDGet a regex of the form ^/foo/bar/baz/?$ for a path (foo, bar, baz)./z^/%s$r-   z^/%s/?$requiredz^/%s/$)stripjoin)r.   pathxpath_formats       r   make_url_path_regexr7   g   sY     #',$Q!AGGCL$D,K# 	:	%$'' -s
   AAc                    t        j                  d      rdnd}t               }t        j                  d      j                  d      }|rd|z   }| j                  d      } | 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.
    zserver.sslCertFilehttpshttpzserver.baseUrlPathr0   ://:)r   r   _get_browser_address_bar_portr2   )host_ipprotocolport	base_paths       r   get_urlrB   u   sr     !++,@AwvH(*D!!"67==cBI)O	mmC GZs7)1TF9+66r   c                 t    t        j                  d      rt        S t        t        j                  d            S )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.

    zglobal.developmentModezbrowser.serverPort)r   r   r   intr,   r   r   r=   r=      s0     12v  !5677r   c                    | j                  dd       t        | j                  j                   d| j                  j                   |      }| j                  dd| d       y)zR
    Emits the warning about deprecation of HTTP endpoint in the HTTP header.
    DeprecationTr;   Link<z>; rel="alternate"N)
set_headerr   requestr?   host)handlernew_pathnew_urls      r    emit_endpoint_deprecation_noticerO      s[     }d+112#goo6J6J5KLhWGv7)+=>?r   N)r   strreturnbool)rQ   rP   )rQ   z
str | None)r.   z-Literal['optional', 'required', 'prohibited']rQ   rP   )r>   rP   rQ   rP   )rQ   rD   )rL   r   rM   rP   rQ   None)__doc__
__future__r   typingr   r   r   urllib.parser   	streamlitr   r	   r
   streamlit.runtime.secretsr   tornado.webr   r   __annotations__r   r   r&   r)   r   r7   rB   r=   rO   r,   r   r   <module>r\      s~    ' " 0 0   0 0 7*  % + % +'T
 LV(H((72
8@r   