
    %e                     6   d dl mZ d dlmZ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 d dlmZ d dlmZ d dlmZ  ed	          d
eeee         f         fd            Z ed          ded
dfd            Zdeeeee         ef         f         ded
efdZdS )    N)AnyDictListUnion)util)EMBED_OPTIONS_QUERY_PARAMEMBED_QUERY_PARAMEMBED_QUERY_PARAMS_KEYS)StreamlitAPIException)
ForwardMsg)gather_metrics)get_script_run_ctxexperimental_get_query_paramsreturnc                      t                      } | i S |                                  t          j        t	          j        | j        d          t                    S )as  Return the query parameters that is currently showing in the browser's URL bar.

    Returns
    -------
    dict
      The current query parameters as a dict. "Query parameters" are the part of the URL that comes
      after the first "?".

    Example
    -------
    Let's say the user's web browser is at
    `http://localhost:8501/?show_map=True&selected=asia&selected=america`.
    Then, you can get the query parameters using the following:

    >>> import streamlit as st
    >>>
    >>> st.experimental_get_query_params()
    {"show_map": ["True"], "selected": ["asia", "america"]}

    Note that the values in the returned dict are *always* lists. This is
    because we internally use Python's urllib.parse.parse_qs(), which behaves
    this way. And this behavior makes sense when you consider that every item
    in a query string is potentially a 1-element array.

    NTkeep_blank_valueskeys_to_exclude)r   #mark_experimental_query_params_usedr   exclude_keys_in_dictparseparse_qsquery_stringr
   )ctxs    Llib/python3.11/site-packages/streamlit/commands/experimental_query_params.pyget_query_paramsr      s]    6 

C
{	++---$s'4@@@/       experimental_set_query_paramsquery_paramsc                      t                      }|dS |                                 t                      }t          | |j                  |j        _        |j        j        |_        |                    |           dS )ad  Set the query parameters that are shown in the browser's URL bar.

    .. warning::
        Query param `embed` cannot be set using this method.

    Parameters
    ----------
    **query_params : dict
        The query parameters to set, as key-value pairs.

    Example
    -------

    To point the user's web browser to something like
    "http://localhost:8501/?show_map=True&selected=asia&selected=america",
    you would do the following:

    >>> import streamlit as st
    >>>
    >>> st.experimental_set_query_params(
    ...     show_map=True,
    ...     selected=["asia", "america"],
    ... )

    N)r   r   r   _ensure_no_embed_paramsr   page_info_changedenqueue)r    r   msgs      r   set_query_paramsr&   D   sy    6 

C
{++---
,,C)@c&* *C& ,9CKKr   r   c           
         t          j        | t                    }| |k    rt          d          t	          j        |d          }t	          j        t          d t          j        |t                    D             t          d t          j        |t                    D             id          }t	          j        | d          }|r|rd	nd
}|
                    ||g          S |S )zEnsures there are no embed params set (raises StreamlitAPIException) if there is a try,
    also makes sure old param values in query_string are preserved. Returns query_string : str.r   zcQuery param embed and embed_options (case-insensitive) cannot be set using set_query_params method.Tr   c                     g | ]}|S  r)   .0params     r   
<listcomp>z+_ensure_no_embed_params.<locals>.<listcomp>}   s(                r   )	param_keyc                     g | ]}|S r)   r)   r*   s     r   r-   z+_ensure_no_embed_params.<locals>.<listcomp>   s(     ( ( ( ( ( (r   )doseq& )r   r   r
   r   r   r   	urlencoder	   extract_key_query_paramsr   join)r    r   query_params_without_embedall_current_paramscurrent_embed_params	separators         r   r"   r"   l   s8    "&!:&=" " " 111#q
 
 	
 MMM ?    !:&2C        & ( (!:&2K  ( ( (	
   " ?<t<<<L D/7CCR	~~|-ABCCCr   )urllib.parser   typingr   r   r   r   	streamlitr   streamlit.constantsr   r	   r
   streamlit.errorsr   streamlit.proto.ForwardMsg_pb2r   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   strr   r&   r"   r)   r   r   <module>rC      s         ) ) ) ) ) ) ) ) ) ) ) )               
 3 2 2 2 2 2 5 5 5 5 5 5 9 9 9 9 9 9 = = = = = = /00"$sDI~. " " " 10"J /00$S $T $ $ $ 10$N% sE$s)S.112% BE% %  %  %  %  %  % r   