
    /_iV,                    b   d dl mZ d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlmZmZmZ d dlZd dlmZmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZmZmZ erd dlm Z m!Z!  ed      dd       Z"	 	 	 	 	 	 ddZ#	 	 	 	 	 	 ddZ$ ed      dd	 	 	 dd       Z% ed      dd	 	 	 	 	 dd       Z&y)    )annotationsN)IterableMapping)	dropwhile)Path)TYPE_CHECKINGLiteralNoReturn)NoSessionContextStreamlitAPIException)get_main_script_directorynormalize_path_join)StreamlitPage)gather_metrics)	RerunDataScriptRunContextget_script_run_ctx)QueryParamsQueryParamsInputstopc                     t               } | r<| j                  r/| j                  j                          t        j                          yyy)a  Stops execution immediately.

    Streamlit will not run any statements after `st.stop()`.
    We recommend rendering a message to explain why the script has stopped.

    Example
    -------
    >>> import streamlit as st
    >>>
    >>> name = st.text_input("Name")
    >>> if not name:
    >>>   st.warning('Please input a name.')
    >>>   st.stop()
    >>> st.success("Thank you for inputting a name.")

    N)r   script_requestsrequest_stopstempty)ctxs    c/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/commands/execution_control.pyr   r   '   s9    $ 
C
s""((*

 #s    c                     |dk(  rg S  j                   }|st        d      t        t         fd|            }|st	        d      |S )Nappzfscope="fragment" can only be specified from `@st.fragment`-decorated functions during fragment reruns.c                "    | j                   k7  S )N)current_fragment_id)xr   s    r   <lambda>z(_new_fragment_id_queue.<locals>.<lambda>b   s    c.E.E)E r   zRCould not find current_fragment_id in fragment_id_queue. This should never happen.)fragment_ids_this_runr   listr   RuntimeError)r   scope
curr_queue	new_queues   `   r   _new_fragment_id_queuer+   A   sd     ~	 **J& #0
 	

 YEzRSI`
 	
 r   c                    || j                          yt        |t              s&t        |t              r(t        |t        t
        f      s| j                  |       yt        dt        |       d      )z#Set query params for a switch page.NzM`query_params` must be a mapping or an iterable of (key, value) pairs not a `z`.)	clear
isinstancer   r   strbytes	from_dictr   type)query_params_statenew_query_paramss     r   _set_query_params_for_switchr5   k   sw       ""G,#X.%L

 	$$%56

WX\]mXnWooqr r   rerunr    )r(   c           
     P   | dvrt        d|  d      t               }|r|j                  rz|j                  }|j                  }|j
                  }|j                  j                  t        ||t        ||       | dk(  ||j                               t        j                          yyy)a  Rerun the script immediately.

    When ``st.rerun()`` is called, Streamlit halts the current script run and
    executes no further statements. Streamlit immediately queues the script to
    rerun.

    When using ``st.rerun`` in a fragment, you can scope the rerun to the
    fragment. However, if a fragment is running as part of a full-app rerun,
    a fragment-scoped rerun is not allowed.

    Parameters
    ----------
    scope : "app" or "fragment"
        Specifies what part of the app should rerun. If ``scope`` is ``"app"``
        (default), the full app reruns. If ``scope`` is ``"fragment"``,
        Streamlit only reruns the fragment from which this command is called.

        Setting ``scope="fragment"`` is only valid inside a fragment during a
        fragment rerun. If ``st.rerun(scope="fragment")`` is called during a
        full-app rerun or outside of a fragment, Streamlit will raise a
        ``StreamlitAPIException``.

    )r    fragment'zC'is not a valid rerun scope. Valid scopes are 'app' and 'fragment'.r8   )query_stringpage_script_hashfragment_id_queueis_fragment_scoped_reruncached_message_hashescontext_infoN)r   r   r   r:   r;   r>   request_rerunr   r+   r?   r   r   )r(   r   r:   r;   r>   s        r   r6   r6      s    : ''#wYZ
 	
 
C
s""''// # 9 9)))!1"8e"D).*)<&; --		
 	
! #sr   switch_page)query_paramsc                  t               }|r|j                  s
t               d}t        | t              r| j
                  }nt        | t              rt        |       } t        |j                        }t        j                  j                  t        ||             }|j                  j                         j!                         }|D cg c]  }|d   |k(  s| }}t#        |      dk(  r/t%        d|  dt        j                  j'                  |       d      |d   d   }|j(                  j+                         5 }	t-        |	|       t/        j0                  d       d	d	d	       |j                  j3                  t5        |j6                  ||j8                  |j:                  
             t=        j>                          y	c c}w # 1 sw Y   ixY w)uu	  Programmatically switch the current page in a multipage app.

    When ``st.switch_page`` is called, the current page execution stops and
    the specified page runs as if the user clicked on it in the sidebar
    navigation. The specified page must be recognized by Streamlit's multipage
    architecture (your main Python file or a Python file in a ``pages/``
    folder). Arbitrary Python scripts cannot be passed to ``st.switch_page``.

    Parameters
    ----------
    page : str, Path, or st.Page
        The file path (relative to the main script) or an st.Page indicating
        the page to switch to.

    query_params : dict, list of tuples, or None
        Query parameters to apply when navigating to the target page.
        This can be a dictionary or an iterable of key-value tuples. Values can
        be strings or iterables of strings (for repeated keys). When this is
        ``None`` (default), all non-embed query parameters are cleared during
        navigation.

    Examples
    --------
    **Example 1: Basic usage**

    The following example shows how to switch to a different page in a
    multipage app that uses the ``pages/`` directory:

    .. code-block:: text

        your-repository/
        ├── pages/
        │   ├── page_1.py
        │   └── page_2.py
        └── your_app.py

    >>> import streamlit as st
    >>>
    >>> if st.button("Home"):
    >>>     st.switch_page("your_app.py")
    >>> if st.button("Page 1"):
    >>>     st.switch_page("pages/page_1.py")
    >>> if st.button("Page 2"):
    >>>     st.switch_page("pages/page_2.py")

    .. output::
        https://doc-switch-page.streamlit.app/
        height: 350px

    **Example 2: Passing query parameters**

    The following example shows how to pass query parameters when switching to a
    different page. This example uses ``st.navigation`` to create a multipage app.

    .. code-block:: text

        your-repository/
        ├── page_2.py
        └── your_app.py

    >>> import streamlit as st
    >>>
    >>> def page_1():
    >>>     st.title("Page 1")
    >>>     if st.button("Switch to Page 2"):
    >>>         st.switch_page("page_2.py", query_params={"utm_source": "page_1"})
    >>>
    >>> pg = st.navigation([page_1, "page_2.py"])
    >>> pg.run()

    .. output::
        https://doc-switch-page-query-params.streamlit.app/
        height: 350px

     script_pathr   zCould not find page: `zK`. Must be the file path relative to the main script, from the directory: `zL`. Only the main app file and files in the `pages/` directory are supported.r;   g{Gz?N)r:   r;   r>   r?   ) r   r   r   r.   r   _script_hashr   r/   r   main_script_pathospathrealpathr   pages_manager	get_pagesvalueslenr   basenamesession_staterB   r5   timesleepr@   r   r:   r>   r?   r   r   )
pagerB   r   r;   main_script_directoryrequested_pageall_app_pagespmatched_pagesqps
             r   rA   rA      s   d 
Cc))  $&,, dD!t9D 9#:N:N O)) 5t<
 ))335<<>$1XqQ}5E5WXX}"'( /((*(8(89N(O'P QEE  )+,>? 
			'	'	) R$R6
 	

4 %%))-"%";";))		
 HHJ; Y s   F?F?:"GG)returnr
   )r   r   r(   Literal['app', 'fragment']rZ   z	list[str])r3   r   r4   QueryParamsInput | NonerZ   None)r(   r[   rZ   r
   )rS   zstr | Path | StreamlitPagerB   r\   rZ   r
   )'
__future__r   rH   rQ   collections.abcr   r   	itertoolsr   pathlibr   typingr   r	   r
   	streamlitr   streamlit.errorsr   r   streamlit.file_utilr   r   streamlit.navigation.pager   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   r   $streamlit.runtime.state.query_paramsr   r   r   r+   r5   r6   rA    r   r   <module>rk      s   # 	  -   3 3  D N 3 9  R  2'	'%' 'T#- 
2  ).3%3 3 3l  -1B
$B *B 	B Br   