U
    ARds                     @   s   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 d dlm	Z	 e
dZe
dZe	de jdddZee ed	d
dZeee dddZdS )    N)IterableListOptional)gather_metricsz\s*z\s*
echoabovec              
   c   s  ddl m}m}m}m} | dkr*|}|}n| }|j}|j}zt d }|j|j }	}
|	|	}|
 }W 5 Q R X t||
d }g }||
d D ]*}t|}|dk	r||k r q|| qtd|}dV  ||d W n0 tk
r } z|d|  W 5 d}~X Y nX dS )	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warningZbelowN pythonzUnable to display code. %s)Z	streamlitr   r	   r
   r   	tracebackextract_stackfilenamelinenoZopen_python_file	readlines_get_initial_indent_get_indentappendtextwrapdedentjoinFileNotFoundError)Zcode_locationr   r	   r
   r   	show_codeZshow_warningplaceholderframer   Z
start_lineZsource_fileZsource_linesinitial_indentZlines_to_displaylineindentZcode_stringerr r"   2/tmp/pip-unpacked-wheel-b9et7o5g/streamlit/echo.pyr      s0    )linesreturnc                 C   s&   | D ]}t |}|dk	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   )r   )r$   r   r    r"   r"   r#   r   b   s
    
r   )r   r%   c                 C   s0   t | dk	rdS t| }|dk	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   r'   r"   r"   r#   r   n   s    
r   )r   )
contextlibrer   r   typingr   r   r   Zstreamlit.runtime.metrics_utilr   compiler(   r&   contextmanagerr   strintr   r   r"   r"   r"   r#   <module>   s   

E