o
    œ©Zhƒ  ã                   @   s`   d 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.
c                   @   s2   e Zd ZdZd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.
    Tc                 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.
        print_on_error:
            A boolean flag to set whether the EventManager will print a warning which a event errors.
        c                 S   s   i | ]}|g “qS © r   )Ú.0Únr   r   úJ/var/www/html/lang_env/lib/python3.10/site-packages/IPython/core/events.pyÚ
<dictcomp>)   s    z)EventManager.__init__.<locals>.<dictcomp>N)ÚshellÚ	callbacksÚprint_on_error)Úselfr   Úavailable_eventsr	   r   r   r   Ú__init__   s   
zEventManager.__init__c                 C   s:   t |ƒs
td| ƒ‚|| j| vr| j|  |¡ dS 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   Úappend©r
   ÚeventÚfunctionr   r   r   Úregister,   s
   ÿzEventManager.registerc                 C   s.   || j | v r| j |  |¡S td ||¡ƒ‚)z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callback)r   ÚremoveÚ
ValueErrorÚformatr   r   r   r   Ú
unregisterC   s   zEventManager.unregisterc                 O   sh   | j | dd… D ](}z	||i |¤Ž W q	 ttfy1   | jr*td ||||¡ƒ | j ¡  Y q	w dS )zÉCall 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 {}), with arguments args {},kwargs {}:)r   Ú	ExceptionÚKeyboardInterruptr	   Úprintr   r   Úshowtraceback)r
   r   ÚargsÚkwargsÚfuncr   r   r   ÚtriggerJ   s   ÿÿùýzEventManager.triggerN)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r      s    

r   c                 C   s   | t | j< | S )N)r   r    )Zcallback_functionr   r   r   Ú_define_event_   s   
r$   c                   C   ó   dS )z©Fires 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_executej   ó   r&   c                 C   r%   )zÏFires 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_cells   ó   	r)   c                   C   r%   )z¨Fires 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~   r'   r+   c                 C   r%   )zÏFires 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‡   r*   r-   c                 C   r%   )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   r/   N)
r#   Úobjectr   r   r$   r&   r)   r+   r-   r/   r   r   r   r   Ú<module>   s    L





