
    ^j                        U d Z ddlmZ ddlmZmZmZmZmZ er
ddl	m
Z
mZmZ  G d d      Zi Zded<    ed	ed
ef         ZddZedd       Zedd       Zedd       Zedd       Zed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.
    )annotations)TYPE_CHECKINGAnyCallableIterableTypeVar)ExecutionInfoExecutionResultInteractiveShellc                  B    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZd	dZd	dZd
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                V    || _         |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.
        print_on_error:
            A boolean flag to set whether the EventManager will print a warning which a event errors.
        N)shell	callbacksprint_on_error)selfr   available_eventsr   ns        L/opt/ringagent/.cad-venv/lib/python3.12/site-packages/IPython/core/events.py__init__zEventManager.__init__'   s5    " 
+?
ArE?
 -?
s   
&c                    t        |      st        d|z        || j                  |   vr| 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   appendr   eventfunctions      r   registerzEventManager.register>   sJ    $ !5@AA4>>%00NN5!((2 1    c                    || j                   |   v r| j                   |   j                  |      S t        dj                  ||            )z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callback)r   remove
ValueErrorformatr   s      r   
unregisterzEventManager.unregisterU   sH    t~~e,,>>%(//99KRRS[]bcddr   c           
         | j                   |   dd D ]  }	  ||i |  y# t        t        f$ rF | j                  rt	        dj                  ||||             | j                  j                          Y cw 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 {}), with arguments args {},kwargs {}:)r   	ExceptionKeyboardInterruptr   printr#   r   showtraceback)r   r   argskwargsfuncs        r   triggerzEventManager.trigger\   s     NN5)!, 
	+D	+d%f%
	+ 01 +&&Zaa %v
 

((*+s   "AA76A7N)T)r   r   r   zIterable[str]r   boolreturnNone)r   strr   zCallable[..., Any]r/   r0   )r   r1   r*   r   r+   r   r/   r0   )__name__
__module____qualname____doc__r   r   r$   r-    r   r   r   r      sG      $	-- (- 	-
 
-.3.e+r   r   zdict[str, Callable[..., Any]]r   
_CallbackT.)boundc                ,    | t         | j                  <   | S )zADecorator to register a function as an available event prototype.)r   r2   )callback_functions    r   _define_eventr;   s   s    3D&//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.
    Nr6   r6   r   r   pre_executer=           	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.
    Nr6   )infos    r   pre_run_cellrA           	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.
    Nr6   r6   r   r   post_executerD      r>   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.
    Nr6   )results    r   post_run_cellrG      rB   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.
    Nr6   )ips    r   shell_initializedrJ      s     	r   N)r:   r7   r/   r7   )r/   r0   )r@   r	   r/   r0   )rF   r
   r/   r0   )rI   r   r/   r0   )r5   
__future__r   typingr   r   r   r   r   IPython.core.interactiveshellr	   r
   r   r   r   __annotations__r7   r;   r=   rA   rD   rG   rJ   r6   r   r   <module>rO      s    # B B P+ P+f 35 / 4\#s();<
 	 	 	 	 	 	 	 	 	 	r   