B
    \                 @   s   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ G dd	 d	ejZd
d add Zdd Zdd ZdS )a  Global IPython app to support test running.

We must start our own ipython object and heavily muck with it so that all the
modifications IPython makes to system behavior don't send the doctest machinery
into a fit.  This code should be considered a gross hack, but it gets the job
done.
    N   )tools)page)io)TerminalInteractiveShellc               @   s,   e Zd ZdZdd Zedd Zdd ZdS )	StreamProxya  Proxy for sys.stdout/err.  This will request the stream *at call time*
    allowing for nose's Capture plugin's redirection of sys.stdout/err.

    Parameters
    ----------
    name : str
        The name of the stream. This will be requested anew at every call
    c             C   s   t jdtdd || _d S )Nz4StreamProxy is deprecated and unused as of IPython 5   )
stacklevel)warningswarnDeprecationWarningname)selfr    r   :lib/python3.7/site-packages/IPython/testing/globalipapp.py__init__"   s    zStreamProxy.__init__c             C   s   t t| jS )N)getattrsysr   )r   r   r   r   stream(   s    zStreamProxy.streamc             C   s   | j   d S )N)r   flush)r   r   r   r   r   ,   s    zStreamProxy.flushN)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   r      s   r   c               C   s   t  S )N)start_ipythonr   r   r   r   get_ipython0   s    r   c             C   s.   t | j|ddd dtjd tj  dS )zFReplace the default system call with a capturing one for doctest.
    Fr   )splitZdepth )endfileN)printZ	getoutputrstripr   stdoutr   )r   cmdr   r   r   xsys9   s     r%   c             C   s   t | j|tjd dS )zDPrint the traceback purely on stdout for doctest to capture it.
    )r    N)r!   ZInteractiveTBZstb2textr   r#   )r   etypeZevalueZstbr   r   r   _showtracebackB   s    r'   c              C   s   t tdrdS dt_tj} tj}tjd}t	 }d|j
_t
j|d}|j|jj |j  tt||_tt||_|tjd< | t_|t_|}|ja|t_tt_d	dd}tjt_|t_|S )
zMStart a global IPython shell, which we need for IPython-specific syntax.
    already_calledNT__main__)configr   c             S   s"   t | tr| dd} t|  d S )Nz
text/plainr   )
isinstancedictgetr!   )ZstrngstartZscreen_linesZ	pager_cmdr   r   r   nopage   s    
zstart_ipython.<locals>.nopage)r   r   N)hasattrr   r(   r   displayhook
excepthookmodulesr-   r   Zdefault_configr   Zsimple_promptinstanceZ	tempfilesappendZHistoryManagerZ	hist_fileZbuiltin_trapZactivatetypes
MethodTyper%   systemr'   r   builtin_mod_ipr   Z
pager_pageZ	orig_page)Z_displayhookZ_excepthook_mainr*   shellr:   r/   r   r   r   r   H   s0    



r   )r   builtinsr9   r   r6   r
   r   r   ZIPython.corer   ZIPython.utilsr   Z!IPython.terminal.interactiveshellr   ZIOStreamr   r   r%   r'   r   r   r   r   r   <module>   s   		