U
    -e                     @   sl   d Z ddlmZ G dd deZi Zdd Zedd Zed	d
 Zedd Z	edd Z
edd ZdS )ao  Infrastructure for registering and firing callbacks on application events.

Unlike :mod:`IPython.core.hooks`, which lets end users set single functions to
be called at specific times, or a collection of alternative methods to try,
callbacks are designed to be used by extension authors. A number of callbacks
can be registered for the same event without needing to be aware of one another.

The functions defined in this module are no-ops indicating the names of available
events and the arguments which will be passed to them.

.. note::

   This API is experimental in IPython 2.0, and may be revised in future versions.
    )callback_prototypec                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )EventManagera3  Manage a collection of events and a sequence of callbacks for each.
    
    This is attached to :class:`~IPython.core.interactiveshell.InteractiveShell`
    instances as an ``events`` attribute.
    
    .. note::

       This API is experimental in IPython 2.0, and may be revised in future versions.
    c                 C   s   || _ dd |D | _dS )a  Initialise the :class:`CallbackManager`.

        Parameters
        ----------
        shell
            The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
        available_events
            An iterable of names for callback events.
        c                 S   s   i | ]
}|g qS  r   ).0nr   r   T/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/core/events.py
<dictcomp>(   s      z)EventManager.__init__.<locals>.<dictcomp>N)shell	callbacks)selfr	   available_eventsr   r   r   __init__   s    
zEventManager.__init__c                 C   sF   t |std| t|}|| j| krB| j| || dS )a  Register a new event callback.

        Parameters
        ----------
        event : str
            The event for which to register this callback.
        function : callable
            A function to be called on the given event. It should take the same
            parameters as the appropriate callback prototype.

        Raises
        ------
        TypeError
            If ``function`` is not callable.
        KeyError
            If ``event`` is not one of the known events.
        zNeed a callable, got %rN)callable	TypeErrorr   getr
   appendZadapt)r   eventfunctioncallback_protor   r   r   register*   s
    
zEventManager.registerc              	   C   s|   || j | kr| j | |S | j | D ]>}z$|j|krN| j | |W   S W q( tk
rd   Y q(X q(td||dS )z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callbackN)r
   remove__wrapped__AttributeError
ValueErrorformat)r   r   r   callbackr   r   r   
unregisterB   s    
zEventManager.unregisterc              
   O   s^   | j | dd D ]F}z||| W q ttfk
rV   td|| | j  Y qX qdS )zCall callbacks for ``event``.

        Any additional arguments are passed to all callbacks registered for this
        event. Exceptions raised by callbacks are caught, and a message printed.
        NzError in callback {} (for {}):)r
   	ExceptionKeyboardInterruptprintr   r	   showtraceback)r   r   argskwargsfuncr   r   r   triggerQ   s    zEventManager.triggerN)__name__
__module____qualname____doc__r   r   r   r$   r   r   r   r   r      s
   	r   c                 C   s   t | }|t| j< |S )N)r   r   r%   )Zcallback_functionr   r   r   r   _define_eventa   s    
r)   c                   C   s   dS )zFires before code is executed in response to user/frontend action.

    This includes comm and widget messages and silent execution, as well as user
    code cells.
    Nr   r   r   r   r   pre_executem   s    r*   c                 C   s   dS )zFires before user-entered code runs.

    Parameters
    ----------
    info : :class:`~IPython.core.interactiveshell.ExecutionInfo`
        An object containing information used for the code execution.
    Nr   )infor   r   r   pre_run_cellv   s    	r,   c                   C   s   dS )zFires after code is executed in response to user/frontend action.

    This includes comm and widget messages and silent execution, as well as user
    code cells.
    Nr   r   r   r   r   post_execute   s    r-   c                 C   s   dS )zFires after user-entered code runs.

    Parameters
    ----------
    result : :class:`~IPython.core.interactiveshell.ExecutionResult`
        The object which will be returned as the execution result.
    Nr   )resultr   r   r   post_run_cell   s    	r/   c                 C   s   dS )aK  Fires after initialisation of :class:`~IPython.core.interactiveshell.InteractiveShell`.

    This is before extensions and startup scripts are loaded, so it can only be
    set by subclassing.

    Parameters
    ----------
    ip : :class:`~IPython.core.interactiveshell.InteractiveShell`
        The newly initialised shell.
    Nr   )ipr   r   r   shell_initialized   s    r1   N)r(   Zbackcallr   objectr   r   r)   r*   r,   r-   r/   r1   r   r   r   r   <module>   s   L





