
    g`                        d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZ  ed	      dd
       Z ed      dd       Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZy)    )annotationsN)Any)StreamlitAPIException)
ForwardMsg)gather_metrics)get_script_run_ctx)EMBED_OPTIONS_QUERY_PARAMEMBED_QUERY_PARAMEMBED_QUERY_PARAMS_KEYSexperimental_get_query_paramsc                     t               } | i S | j                          t        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.

    Tkeep_blank_valueskeys_to_exclude)r   #mark_experimental_query_params_used_exclude_keys_in_dictparseparse_qsquery_stringr   )ctxs    a/var/www/openai/venv/lib/python3.12/site-packages/streamlit/commands/experimental_query_params.pyget_query_paramsr      sF    6 
C
{	++- s''4@/     experimental_set_query_paramsc                     t               }|y|j                          t               }t        | |j                        |j
                  _        |j
                  j                  |_        |j                  |       y)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)query_paramsr   msgs      r   set_query_paramsr"   E   sg    6 
C
{++-
,C)@c&&*C& ,,99CKKr   c                |    | j                         D ci c]  \  }}|j                         |vs|| c}}S c c}}w )z>Returns new object but without keys defined in keys_to_exclude)itemslower)dr   keyvalues       r   r   r   m   s@    
 &'WWY%.zsE#))+_2TU
Y  s   88c           	     4   | j                         D cg c]G  }|j                         |k(  r2| j                  |      r!| |   D cg c]  }|j                          c}I c}}D ch c]  }|D ]  }|j                           c}}S c c}w c c}}w c c}}w )zWExtracts key (case-insensitive) query params from Dict, and returns them as Set of str.)keysr%   get)r    	param_keyr'   r(   sublistitems         r   _extract_key_query_paramsr/   v   s     $((*
*yy{i'L,<,<S,A )5S(9:(9uU[[](9:*

G
 D 	

  	
  ;
s   0BB	B'B	Bc                   t        | t              }| |k7  rt        d      t        j                  |d      }t        j
                  t        t        t        |t                    t        t        t        |t                    id      }t        j
                  | d      }|r|rdnd}|j                  ||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   )r,   )doseq& )r   r   r   r   r   	urlencoder
   listr/   r	   join)r    r   query_params_without_embedall_current_paramscurrent_embed_params	separators         r   r   r      s     "7&=" 11#q
 	
 M ??t)&2C 
 &t)&2K(	
  ??<t<L/CR	~~|-ABCCr   )returndict[str, list[str]])r    r   r;   None)r&   dict[str, Any]r   z	list[str]r;   r>   )r    r<   r,   strr;   zset[str])r    zdict[str, list[str] | str]r   r?   r;   r?   )
__future__r   urllib.parser   typingr   streamlit.errorsr   streamlit.proto.ForwardMsg_pb2r   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   $streamlit.runtime.state.query_paramsr	   r
   r   r   r"   r   r/   r    r   r   <module>rI      s    #   2 5 9 V  /0" 1"J /0$ 1$N(1&36$ ,$ <?$ $ r   