
    f                         d Z ddlmZ  G d de      Zi Zd Zed        Zed        Zed        Z	ed	        Z
ed
        Zy)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                   (    e Zd ZdZd Zd Zd Zd Zy)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                 H    || _         |D ci c]  }|g  c}| _        yc c}w )a  Initialise the :class:`CallbackManager`.

        Parameters
        ----------
        shell
            The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
        available_events
            An iterable of names for callback events.
        N)shell	callbacks)selfr   available_eventsns       N/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/core/events.py__init__zEventManager.__init__   s$     
(891!B$99s   
c                     t        |      st        d|z        t        j                  |      }|| j                  |   vr.| j                  |   j                  |j                  |             yy)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   appendadapt)r	   eventfunctioncallback_protos       r   registerzEventManager.register*   se    $ !5@AA)--e44>>%00NN5!(()=)=h)GH 1    c                 :   || j                   |   v r| j                   |   j                  |      S | j                   |   D ]1  }	 |j                  |u r | j                   |   j                  |      c S 3 t	        dj                  ||            # t        $ r Y Zw xY w)z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callback)r   remove__wrapped__AttributeError
ValueErrorformat)r	   r   r   callbacks       r   
unregisterzEventManager.unregisterB   s    t~~e,,>>%(//99 u- 	H''83>>%077AA 4	 KRRS[]bcdd " s   +B	BBc                     | j                   |   dd D ]  }	  ||i |  y# t        t        f$ r8 t        dj	                  ||             | j
                  j                          Y Uw xY w)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funcs        r   triggerzEventManager.triggerQ   sp     NN5)!, 	+D+d%f%	+ 01 +6==dEJK

((*+s   "AA)(A)N)__name__
__module____qualname____doc__r   r   r    r)    r   r   r   r      s    :I0e+r   r   c                 B    t        |       }|t        | j                  <   |S )N)r   r
   r*   )callback_functionr   s     r   _define_eventr1   a   s%    '(9:N3A&//0r   c                       y)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   pre_executer3   m        	r   c                      y)zFires before user-entered code runs.

    Parameters
    ----------
    info : :class:`~IPython.core.interactiveshell.ExecutionInfo`
        An object containing information used for the code execution.
    Nr.   )infos    r   pre_run_cellr7   v        	r   c                       y)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   post_executer:      r4   r   c                      y)zFires after user-entered code runs.

    Parameters
    ----------
    result : :class:`~IPython.core.interactiveshell.ExecutionResult`
        The object which will be returned as the execution result.
    Nr.   )results    r   post_run_cellr=      r8   r   c                      y)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.   )ips    r   shell_initializedr@      s     	r   N)r-   backcallr   objectr   r
   r1   r3   r7   r:   r=   r@   r.   r   r   <module>rC      s    (I+6 I+X   	 	 	 	 	 	 	 	 	 	r   