Format: application/x-python-code
1 o
2
3 ��h� � @ s� d Z ddlZddlZddlZddlmZ dadd� ZG dd� d�Ze� Z G dd � d �Z
4 d
5 d� Zdd
6 � Zdd� Z
7 dedefdd�ZdS )a�
8 Async helper function that are invalid syntax on Python 3.5 and below.
9
10 This code is best effort, and may have edge cases not behaving as expected. In
11 particular it contain a number of heuristics to detect whether code is
12 effectively async and need to run in an event loop or not.
13
14 Some constructs (like top-level `return`, or `yield`) are taken care of
15 explicitly to actually raise a SyntaxError and stay as close as possible to
16 Python semantics.
17 � N)�wrapsc C s: zt �� W S ty Y nw tdu st�� rt �� atS )aZ asyncio has deprecated get_event_loop
18
19 Replicate it here, with our desired semantics:
20
21 - always returns a valid, not-closed loop
22 - not thread-local like asyncio's,
23 because we only want one loop for IPython
24 - if called from inside a coroutine (e.g. in ipykernel),
25 return the running loop
26
27 .. versionadded:: 8.0
28 N)�asyncio�get_running_loop�RuntimeError�_asyncio_event_loop� is_closed�new_event_loop� r r �Pc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/async_helpers.py�get_asyncio_loop s
29 � r c @ s e Zd Zdd� Zdd� ZdS )�_AsyncIORunnerc C s t � �|�S )z/
30 Handler for asyncio autoawait
31 )r �run_until_complete)�self�coror r r
32 �__call__3 s z_AsyncIORunner.__call__c C s dS )Nr r �r r r r
33 �__str__9 s z_AsyncIORunner.__str__N)�__name__�
34 __module__�__qualname__r r r r r r
35 r 2 s r c @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
36 S )�
37 _AsyncIOProxyz^Proxy-object for an asyncio
38
39 Any coroutine methods will be wrapped in event_loop.run_
40 c C s || _ || _d S �N)�_obj�_event_loop)r �objZ
41 event_loopr r r
42 �__init__F s
43 z_AsyncIOProxy.__init__c C s d| j �d�S )Nz<_AsyncIOProxy(z)>)r r r r r
44 �__repr__J s z_AsyncIOProxy.__repr__c s4 t �j|�� t�� �rt� �� �fdd��}|S � S )Nc s"