U
    ꥡc>                     @   sH   d dl Z d dlZejdkr"e jZndd ZG dd deZd
dd	ZdS )    N)      c                 C   s
   t | S N)astModule)ZnodelistZtype_ignores r   9/tmp/pip-unpacked-wheel-y9_o96ar/altair/utils/execeval.pyr   	   s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_CatchDisplayz*Class to temporarily catch sys.displayhookc                 C   s
   d | _ d S r   outputselfr   r   r   __init__   s    z_CatchDisplay.__init__c                 C   s   t j| _| t _| S r   )sysdisplayhookold_hookr   r   r   r   	__enter__   s    z_CatchDisplay.__enter__c                 C   s   | j t_dS )NF)r   r   r   )r   typevalue	tracebackr   r   r   __exit__   s    z_CatchDisplay.__exit__c                 C   s
   || _ d S r   r
   )r   r   r   r   r   __call__   s    z_CatchDisplay.__call__N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r	      s
   r	   <string>c           	   	   C   s   t j| ddd}|dkri }t }t|jd t jrT|jdd |jdd  }}n|jg  }}|D ]$}tt|gg |dd}t|| qd|0 |D ]$}tt 	|g|dd}t|| qW 5 Q R X |j
S )z
    Execute a multi-line block of code in the given namespace

    If the final statement in the code is an expression, return
    the result of the expression.
    z<ast>exec)filenamemodeNZsingle)r   parser	   
isinstancebodyZExprcompiler   r   ZInteractiver   )	code	namespacer   treeZcatch_displayZto_execZto_evalnodeZcompiledr   r   r   
eval_block!   s&     
  r)   )Nr   )r   r   version_infor   objectr	   r)   r   r   r   r   <module>   s   
