B
    't\O	                 @   sb   d dl mZ d dlmZmZ d dlmZ dddgZe ZdddZ	ed	d Z
G d
d deZdS )    )unicode_literals)	TaskLocalTaskLocalNotSetError)contextmanagerget_appset_appNoRunningApplicationErrorFc             C   sN   yt  }W n8 tk
rD   | r&tn|r.dS ddlm} | S Y nX |S dS )an  
    Get the current active (running) Application.
    An :class:`.Application` is active during the
    :meth:`.Application.run_async` call.

    We assume that there can only be one :class:`.Application` active at the
    same time. There is only one terminal window, with only one stdin and
    stdout. This makes the code significantly easier than passing around the
    :class:`.Application` everywhere.

    If no :class:`.Application` is running, then return by default a
    :class:`.DummyApplication`. For practical reasons, we prefer to not raise
    an exception. This way, we don't have to check all over the place whether
    an actual `Application` was returned.

    (For applications like pymux where we can have more than one `Application`,
    we'll use a work-around to handle that.)

    :param raise_exception: When `True`, raise
        :class:`.NoRunningApplicationError` instead of returning a
        :class:`.DummyApplication` if no application is running.
    :param return_none: When `True`, return `None`
        instead of returning a :class:`.DummyApplication` if no application is
        running.
    N   )DummyApplication)_current_appgetr   r   Zdummyr
   )Zraise_exceptionreturn_nonevaluer
    r   Alib/python3.7/site-packages/prompt_toolkit/application/current.pyr      s    c          	   c   s`   ddl m} | dks"t| |s"ttdd}t|  z
dV  W d|rRt| nt  X dS )z
    Context manager that sets the given :class:`.Application` active.

    (Usually, not needed to call outside of prompt_toolkit.)
    r	   )ApplicationNT)r   )Zapplicationr   
isinstanceAssertionErrorr   r   setdelete)Zappr   Zpreviousr   r   r   r   7   s    


c               @   s   e Zd ZdZdS )r   z+ There is no active application right now. N)__name__
__module____qualname____doc__r   r   r   r   r   M   s   N)FF)Z
__future__r   Z prompt_toolkit.eventloop.contextr   r   
contextlibr   __all__r   r   r   	Exceptionr   r   r   r   r   <module>   s   
(