
    %e                        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j        d          Z ej        d          Z ed          ej        dd                        Zd	ee         d
efdZded
e	e         fdZdS )    N)AnyDictIterableOptional)gather_metricsz\s*z\s*
echoabovec              #     K   ddl m}m}m}m} | dk    r|}|}n |            }|j        }|j        }	 t          j                    d         }|j        |j        pd}
}	|	                    |	          5 }|
                                }ddd           n# 1 swxY w Y   t          j        d                    |                    }i dt          j        ddffd	 |           |
         j        d         j        d
z
  }|
         j        }|||         }t#          j        d                    |                    }dV   ||d           dS # t&          $ r} |d|z             Y d}~dS d}~ww xY 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returnc                     t          | d          sd S t          j        |           D ]'}t          |d          r||j        <    |           (d S )Nbodylineno)hasattrastiter_child_nodesr   )r   childcollect_body_statementsline_to_node_maps     .lib/python3.11/site-packages/streamlit/echo.pyr   z%echo.<locals>.collect_body_statementsG   so    4(( -d33 3 35(++ 35:$U\2++E222	3 3       pythonzUnable to display code. %s)	streamlitr   r   r   r   	tracebackextract_stackfilenamer   open_python_file	readlinesr   parsejoinASTr   
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   s                      @@r   r   r      s3     & <;;;;;;;;;;;	egg$	"*(9 '))"-$~u|/@q* ))(33 	3{&0022L	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 Ibggl3344	+-	3#' 	3d 	3 	3 	3 	3 	3 	3 	3 	 	*** !1 < A! D Ka O.z:E'(=>Q(QRobgg.>&?&?@@ 	 		+x((((( 9 9 91C78888888889s<   >E 3BE BE BB5E 
E6E11E6linesr   c                 :    | D ]}t          |          }||c S 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indents      r   _get_initial_indentrA   d   s;       T""MMM  1r   r?   c                     t                               |           dS t                              |           }||                                n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?   rD   s     r   r>   r>   p   sG    
 D!!-tT""E+599;;;2r   )r	   )r   
contextlibrer+   r"   typingr   r   r   r   streamlit.runtime.metrics_utilr   compilerE   rC   contextmanagerr   strintrA   r>    r   r   <module>rP      s&   


     				      0 0 0 0 0 0 0 0 0 0 0 0 9 9 9 9 9 9RZ
H%% C9 C9 C9  C9L	x} 	 	 	 	 		3c 	3hsm 	3 	3 	3 	3 	3 	3r   