o
    h.                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ er0d dlmZ edZedZedejdd
dZdddZdddZdS )    )annotationsN)TYPE_CHECKINGAny)gather_metrics)Iterablez\s*z\s*
echoabovec              
   #  s>   ddl m}m}m}m} | dkr|}|}n	| }|j}|j}zft d }|j|jp,d}	}
|	|	}|
 }W d   n1 sCw   Y  td|}i d fdd  | |
 jd jd }|
 j}||| }td|}dV  ||d W dS  ty } z|d|  W Y d}~dS d}~ww )a  Use in a `with` block to draw some code on the app, then execute it.

    Parameters
    ----------
    code_location : "above" or "below"
        Whether to show the echoed code before or after the results of the
        executed code block.

    Example
    -------
    >>> import streamlit as st
    >>>
    >>> with st.echo():
    >>>     st.write('This code will be printed')

    r   )codeemptysource_utilwarningbelowN nodeast.ASTreturnNonec                   s>   t | dsd S t| D ]}t |dr||j<  | qd S )Nbodylineno)hasattrastiter_child_nodesr   )r   childcollect_body_statementsline_to_node_map K/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/commands/echo.pyr   L   s   


z%echo.<locals>.collect_body_statements   pythonzUnable to display code. %s)r   r   r   r   )	streamlitr	   r
   r   r   	tracebackextract_stackfilenamer   open_python_file	readlinesr   parsejoinr   
end_linenotextwrapdedentFileNotFoundError)code_locationr	   r
   r   r   	show_codeshow_warningplaceholderframer$   
start_linesource_filesource_lines	root_nodeecho_block_start_lineecho_block_end_linelines_to_displaycode_stringerrr   r   r   r   !   s8   
	
linesIterable[str]r   intc                 C  s&   | D ]}t |}|dur|  S qdS )zeReturn the indent of the first non-empty line in the list.
    If all lines are empty, return 0.
    Nr   )_get_indent)r;   lineindentr   r   r   _get_initial_indenti   s   rA   r?   str
int | Nonec                 C  s0   t | dur	dS t| }|dur| S dS )zGet the number of whitespaces at the beginning of the given line.
    If the line is empty, or if it contains just whitespace and a newline,
    return None.
    Nr   )_EMPTY_LINE_REmatch
_SPACES_REend)r?   rE   r   r   r   r>   u   s   
r>   )r   )r;   r<   r   r=   )r?   rB   r   rC   )
__future__r   r   
contextlibrer*   r"   typingr   r   streamlit.runtime.metrics_utilr   collections.abcr   compilerF   rD   contextmanagerr   rA   r>   r   r   r   r   <module>   s"   


F