Format: application/x-python-code
1 o
2
3 ��h� � @ s` d Z G dd� de�Zi Zdd� Zedd� �Zedd� �Zed d
4 � �Zedd� �Zed
5 d� �Z dS )ao Infrastructure for registering and firing callbacks on application events.
6
7 Unlike :mod:`IPython.core.hooks`, which lets end users set single functions to
8 be called at specific times, or a collection of alternative methods to try,
9 callbacks are designed to be used by extension authors. A number of callbacks
10 can be registered for the same event without needing to be aware of one another.
11
12 The functions defined in this module are no-ops indicating the names of available
13 events and the arguments which will be passed to them.
14
15 .. note::
16
17 This API is experimental in IPython 2.0, and may be revised in future versions.
18 c @ s2 e Zd ZdZddd�Zdd� Zdd� Zd d
19 � ZdS )
20 �EventManagera3 Manage a collection of events and a sequence of callbacks for each.
21
22 This is attached to :class:`~IPython.core.interactiveshell.InteractiveShell`
23 instances as an ``events`` attribute.
24
25 .. note::
26
27 This API is experimental in IPython 2.0, and may be revised in future versions.
28 Tc C s || _ dd� |D �| _|| _dS )a� Initialise the :class:`CallbackManager`.
29
30 Parameters
31 ----------
32 shell
33 The :class:`~IPython.core.interactiveshell.InteractiveShell` instance
34 available_events
35 An iterable of names for callback events.
36 print_on_error:
37 A boolean flag to set whether the EventManager will print a warning which a event errors.
38 c S s i | ]}|g �qS � r )�.0�nr r �Ic:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/events.py�
39 <dictcomp>) s z)EventManager.__init__.<locals>.<dictcomp>N)�shell� callbacks�print_on_error)�selfr �available_eventsr r r r �__init__ s
40 zEventManager.__init__c C s: t |�s
41 td| ��|| j| vr| j| �|� dS dS )a� Register a new event callback.
42
43 Parameters
44 ----------
45 event : str
46 The event for which to register this callback.
47 function : callable
48 A function to be called on the given event. It should take the same
49 parameters as the appropriate callback prototype.
50
51 Raises
52 ------
53 TypeError
54 If ``function`` is not callable.
55 KeyError
56 If ``event`` is not one of the known events.
57 zNeed a callable, got %rN)�callable� TypeErrorr �append�r
58 �event�functionr r r �register, s
59 �zEventManager.registerc C s. || j | v r| j | �|�S td�||���)z'Remove a callback from the given event.z0Function {!r} is not registered as a {} callback)r �remove�
60 ValueError�formatr r r r �
61 unregisterC s zEventManager.unregisterc O sh | j | dd� D ](}z ||i |�� W q ttfy1 | jr*td�||||�� | j�� Y q w dS )z�Call callbacks for ``event``.
62
63 Any additional arguments are passed to all callbacks registered for this
64 event. Exceptions raised by callbacks are caught, and a message printed.
65 Nz@Error in callback {} (for {}), with arguments args {},kwargs {}:)r � Exception�KeyboardInterruptr �printr r �
66 showtraceback)r
67 r �args�kwargs�funcr r r �triggerJ s ����zEventManager.triggerN)T)�__name__�
68 __module__�__qualname__�__doc__r r r r r r r r r s
69
70 r c C s | t | j<