
    g!                       d dl mZ d dlZd dlmZ d dlmZ d dl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d      dd       Z	 	 	 	 	 	 ddZ ed      dd	 	 	 dd       Z ed      dd       Zy)    )annotationsN)	dropwhile)Path)LiteralNoReturn)NoSessionContextStreamlitAPIException)get_main_script_directorynormalize_path_join)StreamlitPage)gather_metrics)	RerunDataScriptRunContextget_script_run_ctx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    Y/var/www/openai/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|            x}sJ 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>_   s    A)@)@$@r   zRCould not find current_fragment_id in fragment_id_queue. This should never happen.)fragment_ids_this_runr	   listr   )r   scope
curr_queue	new_queues   `   r   _new_fragment_id_queuer%   <   ss     ~	 ..
& '4  @*M I 	

 a	
 r   rerunr   )r"   c           
         | dvrt        d|  d      t               }|ro|j                  rb|j                  }|j                  }|j                  j                  t        ||t        ||       | dk(               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'.r(   )query_stringpage_script_hashfragment_id_queueis_fragment_scoped_rerunN)
r	   r   r   r*   r+   request_rerunr   r%   r   r   )r"   r   r*   r+   s       r   r&   r&   h   s    : ''#wYZ
 	
 
C
s""''//)))!1"8e"D).*)<		
 	
 #sr   switch_pagec                R   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 }|j-                          ddd       |j                  j/                  t1        |j2                  |	             t5        j6                          yc c}w # 1 sw Y   SxY w)
u  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.


    Example
    -------
    Consider the following example given this file structure:

    >>> 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

     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+   N)r*   r+   )r   r   r   
isinstancer   _script_hashr   strr
   main_script_pathospathrealpathr   pages_manager	get_pagesvalueslenr	   basenamesession_statequery_paramsclearr.   r   r*   r   r   )	pager   r+   main_script_directoryrequested_pageall_app_pagespmatched_pagesqps	            r   r/   r/      s   T 
Cc))  $&,, dD!t9D 9#:N:N O)) 5t<
 ))335<<>$1XMqQ}5E5WMX}"'(.yz|  {B  {B  {K  {K  La  {b  zc  co  p  )+,>? 
			'	'	)R

 
* %%))-	
 HHJ) Y 
*	)s   FF:FF&)returnr   )r   r   r"   Literal['app', 'fragment']rI   z	list[str])r"   rJ   rI   r   )rB   zstr | Path | StreamlitPagerI   r   )
__future__r   r7   	itertoolsr   pathlibr   typingr   r   	streamlitr   streamlit.errorsr   r	   streamlit.file_utilr
   r   streamlit.navigation.pager   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   r   r   r%   r&   r/    r   r   <module>rV      s    # 	   $  D N 3 9   2)	)%) )X  ).0%0 0 0f Q Qr   