
    gE                    |    d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZ erd dlmZ  G d deeef         Zy	)
    )annotations)IterableIteratorMutableMapping)TYPE_CHECKINGoverload)gather_metrics)get_session_state)SupportsKeysAndGetItemc                     e Zd ZdZd dZd!dZd"dZ ed      d#d       Zd$dZ	 ed      d%d	       Z
 ed
      d#d       Zd$dZe	 	 	 	 	 	 d&d       Ze	 	 	 	 	 	 d'd       Zed(d       Zd)dZ ed      d%d       Z ed      d*d       Z ed      d+d       Z ed      d,d       Ze	 	 	 	 d-d       Ze	 	 	 	 d.d       Z ed      d        Zed#d       Zed#d       Zy)/QueryParamsProxyz
    A stateless singleton that proxies ``st.query_params`` interactions
    to the current script thread's QueryParams instance.
    c                t    t               j                         5 }t        |      cd d d        S # 1 sw Y   y xY wN)r
   query_paramsiterselfqps     _/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/state/query_params_proxy.py__iter__zQueryParamsProxy.__iter__!   s&     --/28 0//   .7c                t    t               j                         5 }t        |      cd d d        S # 1 sw Y   y xY wr   )r
   r   lenr   s     r   __len__zQueryParamsProxy.__len__%   &     --/2r7 0//r   c                t    t               j                         5 }t        |      cd d d        S # 1 sw Y   y xY wr   )r
   r   strr   s     r   __str__zQueryParamsProxy.__str__)   r   r   zquery_params.get_itemc                    t               j                         5 }	 ||   cd d d        S # t        $ r t        | j                  |            w xY w# 1 sw Y   y xY wr   )r
   r   KeyErrormissing_key_error_messager   keyr   s      r   __getitem__zQueryParamsProxy.__getitem__-   sZ     --/2D#w 0/  Dt==cBCCD 0/   A)$AAAc                d    t               j                         5 }||= d d d        y # 1 sw Y   y xY wr   r
   r   r"   s      r   __delitem__zQueryParamsProxy.__delitem__5   s&     --/23 0//s   &/zquery_params.set_itemc                h    t               j                         5 }|||<   d d d        y # 1 sw Y   y xY wr   r'   r   r#   valuer   s       r   __setitem__zQueryParamsProxy.__setitem__9   (     --/2BsG 0//   (1zquery_params.get_attrc                    t               j                         5 }	 ||   cd d d        S # t        $ r t        | j	                  |            w xY w# 1 sw Y   y xY wr   )r
   r   r    AttributeErrormissing_attr_error_messager"   s      r   __getattr__zQueryParamsProxy.__getattr__>   sZ     --/2K#w 0/  K$T%D%DS%IJJK 0/r%   c                    t               j                         5 }	 ||= 	 d d d        y # t        $ r t        | j	                  |            w xY w# 1 sw Y   y xY wr   )r
   r   r    r0   r!   r"   s      r   __delattr__zQueryParamsProxy.__delattr__F   sZ     --/2JsG 0/  J$T%C%CC%HIIJ 0/s   A($AAAc                    y r    )r   mappingkwdss      r   updatezQueryParamsProxy.updateM            c                    y r   r6   )r   keys_and_valuesr8   s      r   r9   zQueryParamsProxy.updateR   r:   r;   c                     y r   r6   )r   r8   s     r   r9   zQueryParamsProxy.updateW   s    ;>r;   c                   t               j                         5 } |j                  |fi | ddd       y# 1 sw Y   yxY w)a  
        Update one or more values in query_params at once from a dictionary or
        dictionary-like object.

        See `Mapping.update()` from Python's `collections` library.

        Parameters
        ----------
        other: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]]
            A dictionary or mapping of strings to strings.
        **kwds: str
            Additional key/value pairs to update passed as keyword arguments.
        N)r
   r   r9   )r   otherr8   r   s       r   r9   zQueryParamsProxy.updateZ   s4      --/2BIIe$t$ 0//s   6?zquery_params.set_attrc                h    t               j                         5 }|||<   d d d        y # 1 sw Y   y xY wr   r'   r*   s       r   __setattr__zQueryParamsProxy.__setattr__k   r-   r.   zquery_params.get_allc                    t               j                         5 }|j                  |      cddd       S # 1 sw Y   yxY w)aK  
        Get a list of all query parameter values associated to a given key.

        When a key is repeated as a query parameter within the URL, this method
        allows all values to be obtained. In contrast, dict-like methods only
        retrieve the last value when a key is repeated in the URL.

        Parameters
        ----------
        key: str
            The label of the query parameter in the URL.

        Returns
        -------
        List[str]
            A list of values associated to the given key. May return zero, one,
            or multiple values.
        N)r
   r   get_allr"   s      r   rD   zQueryParamsProxy.get_allp   s,    (  --/2::c? 0//   4=zquery_params.clearc                ~    t               j                         5 }|j                          ddd       y# 1 sw Y   yxY w)zs
        Clear all query parameters from the URL of the app.

        Returns
        -------
        None
        N)r
   r   clearr   s     r   rG   zQueryParamsProxy.clear   s*      --/2HHJ 0//s   3<zquery_params.to_dictc                ~    t               j                         5 }|j                         cddd       S # 1 sw Y   yxY w)a   
        Get all query parameters as a dictionary.

        This method primarily exists for internal use and is not needed for
        most cases. ``st.query_params`` returns an object that inherits from
        ``dict`` by default.

        When a key is repeated as a query parameter within the URL, this method
        will return only the last value of each unique key.

        Returns
        -------
        Dict[str,str]
            A dictionary of the current query paramters in the app's URL.
        N)r
   r   to_dictr   s     r   rI   zQueryParamsProxy.to_dict   s*    "  --/2::< 0//s   3<c                     y r   r6   )r   r=   s     r   	from_dictzQueryParamsProxy.from_dict   r:   r;   c                     y r   r6   )r   r7   s     r   rK   zQueryParamsProxy.from_dict   r:   r;   zquery_params.from_dictc                    t               j                         5 }|j                  |      cddd       S # 1 sw Y   yxY w)a  
        Set all of the query parameters from a dictionary or dictionary-like object.

        This method primarily exists for advanced users who want to control
        multiple query parameters in a single update. To set individual query
        parameters, use key or attribute notation instead.

        This method inherits limitations from ``st.query_params`` and can't be
        used to set embedding options as described in `Embed your app         <https://docs.streamlit.io/deploy/streamlit-community-cloud/share-your-app/embed-your-app#embed-options>`_.

        To handle repeated keys, the value in a key-value pair should be a list.

        .. note::
            ``.from_dict()`` is not a direct inverse of ``.to_dict()`` if
            you are working with repeated keys. A true inverse operation is
            ``{key: st.query_params.get_all(key) for key in st.query_params}``.

        Parameters
        ----------
        params: dict
            A dictionary used to replace the current query parameters.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> st.query_params.from_dict({"foo": "bar", "baz": [1, "two"]})

        N)r
   r   rK   )r   paramsr   s      r   rK   zQueryParamsProxy.from_dict   s.    @  --/2<<' 0//rE   c                    d|  dS )Nzst.query_params has no key "".r6   r#   s    r   r!   z*QueryParamsProxy.missing_key_error_message   s    -cU"55r;   c                    d|  dS )Nz"st.query_params has no attribute "rP   r6   rQ   s    r   r1   z+QueryParamsProxy.missing_attr_error_message   s    3C5;;r;   N)returnzIterator[str])rS   int)rS   r   )r#   r   rS   r   )r#   r   rS   None)r#   r   r+   str | Iterable[str]rS   rU   )r7   0SupportsKeysAndGetItem[str, str | Iterable[str]]r8   r   rS   rU   )r=   )Iterable[tuple[str, str | Iterable[str]]]r8   r   rS   rU   )r8   rV   rS   rU   )r6   )r#   r   rS   z	list[str])rS   rU   )rS   zdict[str, str])r=   rX   rS   rU   )r7   rW   rS   rU   )__name__
__module____qualname____doc__r   r   r   r	   r$   r(   r,   r2   r4   r   r9   rB   rD   rG   rI   rK   staticmethodr!   r1   r6   r;   r   r   r      s   
 +,D -D +, - +,K -KJ GTW	  HUX	  > >%" +, - *+# ,#, ()	 *	 *+  , & H	  G	  ,- ( . (D 6 6 < <r;   r   N)
__future__r   collections.abcr   r   r   typingr   r   streamlit.runtime.metrics_utilr	   +streamlit.runtime.state.session_state_proxyr
   	_typeshedr   r   r   r6   r;   r   <module>rd      s6    # > > * 9 I0<~c3h/ <r;   