
    g.                        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rd dlmZ  ej                  d      Z ej                  d      Z ed      ej"                  dd	              Zdd
ZddZy)    )annotationsN)TYPE_CHECKINGAny)gather_metrics)Iterablez\s*z\s*
echoc              #    K   ddl m}m}m}m} | dk(  r|}|}n |       }|j                  }|j                  }	 t        j                         d   }|j                  |j                  xs d}
}	|j                  |	      5 }|j                         }ddd       t        j                  dj                              }i dfd |       |
   j                  d   j                  dz
  }|
   j                  }||| }t!        j"                  dj                  |            }d  ||d	       y# 1 sw Y   xY w# t$        $ r} |d
|z         Y d}~yd}~ww xY 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 c                    t        | d      sy t        j                  |       D ]&  }t        |d      s||j                  <    |       ( y )Nbodylineno)hasattrastiter_child_nodesr   )nodechildcollect_body_statementsline_to_node_maps     L/var/www/openai/venv/lib/python3.12/site-packages/streamlit/commands/echo.pyr   z%echo.<locals>.collect_body_statementsL   sF    4(--d35(+5:$U\\2+E2	 4       pythonzUnable to display code. %s)r   zast.ASTreturnNone)	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   s                      @@r   r   r   !   sX    & <;	g$$	"**(9 '')"-$~~u||/@q* ))(3{&002L 4 IIbggl34	+-	3 	 	* !1 < A A! D K Ka O.z:EE'(=>QRoobgg.>&?@ 	 	+x(= 43@  91C7889sH   6EAD> ?D2B!D> 1E2D;7D> >	EEEEEc                4    | D ]  }t        |      }||c S  y)zeReturn the indent of the first non-empty line in the list.
    If all lines are empty, return 0.
    r   )_get_indent)lineslineindents      r   _get_initial_indentr@   i   s(     T"M 
 r   c                    t         j                  |       yt        j                  |       }||j                         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>   rC   s     r   r<   r<   u   s>    
 D!-T"E+599;22r   )above)r=   zIterable[str]r   int)r>   strr   z
int | None)
__future__r   r   
contextlibrer*   r"   typingr   r   streamlit.runtime.metrics_utilr   collections.abcr   compilerD   rB   contextmanagerr   r@   r<    r   r   <module>rR      sy    # 
  	   % 9(RZZ
H% C9  C9L		3r   