o
    hE                     @  st   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 deeef Zd	S )
    )annotations)IterableIteratorMutableMapping)TYPE_CHECKINGoverload)gather_metrics)get_session_state)SupportsKeysAndGetItemc                   @  s<  e Zd ZdZd@ddZdAddZdBd
dZeddCddZdDddZ	eddEddZ
eddCddZdDddZedFd d!ZedGd$d!ZedHd%d!ZdId'd!Zed(dEd)d*Zed+dJd-d.Zed/dKd0d1Zed2dLd4d5ZedMd6d7ZedNd8d7Zed9d:d7 ZedCd;d<ZedCd=d>Zd?S )OQueryParamsProxyz
    A stateless singleton that proxies ``st.query_params`` interactions
    to the current script thread's QueryParams instance.
    returnIterator[str]c                 C  6   t   }t|W  d    S 1 sw   Y  d S N)r	   query_paramsiterselfqp r   ^/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/runtime/state/query_params_proxy.py__iter__!      $zQueryParamsProxy.__iter__intc                 C  r   r   )r	   r   lenr   r   r   r   __len__%   r   zQueryParamsProxy.__len__strc                 C  r   r   )r	   r   r   r   r   r   r   __str__)   r   zQueryParamsProxy.__str__zquery_params.get_itemkeyc              	   C  sV   t   }z|| W W  d    S  ty    t| |w 1 s$w   Y  d S r   )r	   r   KeyErrormissing_key_error_messager   r   r   r   r   r   __getitem__-      zQueryParamsProxy.__getitem__Nonec                 C  s6   t   }||= W d    d S 1 sw   Y  d S r   r	   r   r!   r   r   r   __delitem__5   s   "zQueryParamsProxy.__delitem__zquery_params.set_itemvaluestr | Iterable[str]c                 C  8   t   }|||< W d    d S 1 sw   Y  d S r   r%   r   r   r'   r   r   r   r   __setitem__9      
"zQueryParamsProxy.__setitem__zquery_params.get_attrc              	   C  sV   t   }z|| W W  d    S  ty    t| |w 1 s$w   Y  d S r   )r	   r   r   AttributeErrormissing_attr_error_messager!   r   r   r   __getattr__>   r#   zQueryParamsProxy.__getattr__c              	   C  sX   t   }z||= W n ty   t| |w W d    d S 1 s%w   Y  d S r   )r	   r   r   r-   r    r!   r   r   r   __delattr__F   s   
"zQueryParamsProxy.__delattr__mapping0SupportsKeysAndGetItem[str, str | Iterable[str]]kwdsc                K     d S r   r   )r   r1   r3   r   r   r   updateM      zQueryParamsProxy.updatekeys_and_values)Iterable[tuple[str, str | Iterable[str]]]c                K  r4   r   r   )r   r7   r3   r   r   r   r5   R   r6   c                 K  r4   r   r   )r   r3   r   r   r   r5   W   s   r   c                K  sB   t   }|j|fi | W d   dS 1 sw   Y  dS )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   r5   )r   otherr3   r   r   r   r   r5   Z   s   "zquery_params.set_attrc                 C  r)   r   r%   r*   r   r   r   __setattr__k   r,   zQueryParamsProxy.__setattr__zquery_params.get_all	list[str]c                 C  8   t   }||W  d   S 1 sw   Y  dS )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!   r   r   r   r=   p   s   $zQueryParamsProxy.get_allzquery_params.clearc                 C  s8   t   }|  W d   dS 1 sw   Y  dS )zs
        Clear all query parameters from the URL of the app.

        Returns
        -------
        None
        N)r	   r   clearr   r   r   r   r>      s   	
"zQueryParamsProxy.clearzquery_params.to_dictdict[str, str]c                 C  s6   t   }| W  d   S 1 sw   Y  dS )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   r   r   r   r@      s   $zQueryParamsProxy.to_dictc                 C  r4   r   r   )r   r7   r   r   r   	from_dict   r6   zQueryParamsProxy.from_dictc                 C  r4   r   r   )r   r1   r   r   r   rA      r6   zquery_params.from_dictc                 C  r<   )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   rA   )r   paramsr   r   r   r   rA      s    $c                 C     d|  dS )Nzst.query_params has no key "".r   r   r   r   r   r          z*QueryParamsProxy.missing_key_error_messagec                 C  rC   )Nz"st.query_params has no attribute "rD   r   rE   r   r   r   r.      rF   z+QueryParamsProxy.missing_attr_error_messageN)r   r   )r   r   )r   r   )r   r   r   r   )r   r   r   r$   )r   r   r'   r(   r   r$   )r1   r2   r3   r   r   r$   )r7   r8   r3   r   r   r$   )r3   r(   r   r$   )r   )r   r   r   r;   )r   r$   )r   r?   )r7   r8   r   r$   )r1   r2   r   r$   )__name__
__module____qualname____doc__r   r   r   r   r"   r&   r+   r/   r0   r   r5   r:   r=   r>   r@   rA   staticmethodr    r.   r   r   r   r   r      sL    






"r   N)
__future__r   collections.abcr   r   r   typingr   r   streamlit.runtime.metrics_utilr   +streamlit.runtime.state.session_state_proxyr	   	_typeshedr
   r   r   r   r   r   r   <module>   s   