o
    Yh                     @  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	m
Z
mZ d dlmZ er6d dlmZmZ edZedZedej		ddddZdddZdddZdS )    )annotationsN)TYPE_CHECKINGAnyLiteralcast)gather_metrics)	GeneratorIterablez\s*z\s*
echoabovecode_locationLiteral['above', 'below']returnGenerator[None, None, None]c              
   #  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.ASTr   Nonec                   sD   t | dsd S t| D ]}t |dr|td|j<  | qd S )Nbodylinenoint)hasattrastiter_child_nodesr   r   )r   childcollect_body_statementsline_to_node_map X/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/commands/echo.pyr"   N   s   

z%echo.<locals>.collect_body_statements   pythonzUnable to display code. )r   r   r   r   )	streamlitr   r   r   r   	tracebackextract_stackfilenamer   open_python_file	readlinesr   parsejoinr   
end_linenotextwrapdedentFileNotFoundError)r   r   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   c                 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)rA   lineindentr$   r$   r%   _get_initial_indentk   s   rF   rD   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)rD   rJ   r$   r$   r%   rC   w   s   
rC   )r   )r   r   r   r   )rA   rB   r   r   )rD   rG   r   rH   )
__future__r   r   
contextlibrer1   r)   typingr   r   r   r   streamlit.runtime.metrics_utilr   collections.abcr   r	   compilerK   rI   contextmanagerr
   rF   rC   r$   r$   r$   r%   <module>   s$   


H