| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/IPython/core/__pycache__/ |
Upload File : |
�
�@�c� � � � d Z ddlmZ G d� de� � Zi Zd� Zed� � � Zed� � � Zed� � � Z ed � � � Z
ed
� � � ZdS )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 Zd ZdZd� Zd� Zd� Zd� ZdS )�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 �6 � || _ d� |D � � | _ dS )a Initialise the :class:`CallbackManager`.
Parameters
----------
shell
The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
available_events
An iterable of names for callback events.
c � � i | ]}|g ��S � r )�.0�ns �5/usr/lib/python3/dist-packages/IPython/core/events.py�
<dictcomp>z)EventManager.__init__.<locals>.<dictcomp>( s � �9�9�9�1�!�B�9�9�9� N)�shell� callbacks)�selfr �available_eventss r �__init__zEventManager.__init__ s% � � ��
�9�9�(8�9�9�9����r
c � � t |� � st d|z � � �t � |� � }|| j | vr5| j | � |� |� � � � dS dS )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.
zNeed a callable, got %rN)�callable� TypeErrorr �getr �append�adapt)r �event�function�callback_protos r �registerzEventManager.register* s� � �$ ��!�!� B��5��@�A�A�A�)�-�-�e�4�4���4�>�%�0�0�0��N�5�!�(�(��)=�)=�h�)G�)G�H�H�H�H�H� 1�0r
c �> � || j | v r | j | � |� � S | j | D ]>} |j |u r"| j | � |� � c S �/# t $ r Y �;w xY wt d� ||� � � � �)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 �
unregisterzEventManager.unregisterB s� � ��t�~�e�,�,�,��>�%�(�/�/��9�9�9� ��u�-� � �H�
��'�8�3�3��>�%�0�7�7��A�A�A�A�A� 4��!�
�
�
���
���� �K�R�R�S[�]b�c�c�d�d�ds � (A,�,
A9�8A9c �� � | j | dd� D ]^} ||i |�� �# t t f$ r? t d� ||� � � � | j � � � Y �[w xY wdS )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.
NzError in callback {} (for {}):)r � Exception�KeyboardInterrupt�printr"