summaryrefslogtreecommitdiff
path: root/dev-python/pexpect/files/pexpect-4.8.0-py311.patch
blob: b7de17a687856f26a87c70dd27c4d77e5c3ff88e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From 52af5b0ae0627139524448a3f2e83d9f40802bc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Thu, 24 Mar 2022 15:15:33 +0100
Subject: [PATCH] Convert @asyncio.coroutine to async def

This is required for Python 3.11+ support.

Fixes https://github.com/pexpect/pexpect/issues/677
---
 pexpect/_async.py | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/pexpect/_async.py b/pexpect/_async.py
index dfbfeef5..bc83261d 100644
--- a/pexpect/_async.py
+++ b/pexpect/_async.py
@@ -4,8 +4,7 @@
 
 from pexpect import EOF
 
-@asyncio.coroutine
-def expect_async(expecter, timeout=None):
+async def expect_async(expecter, timeout=None):
     # First process data that was previously read - if it maches, we don't need
     # async stuff.
     idx = expecter.existing_data()
@@ -14,7 +13,7 @@ def expect_async(expecter, timeout=None):
     if not expecter.spawn.async_pw_transport:
         pw = PatternWaiter()
         pw.set_expecter(expecter)
-        transport, pw = yield from asyncio.get_event_loop()\
+        transport, pw = await asyncio.get_event_loop()\
             .connect_read_pipe(lambda: pw, expecter.spawn)
         expecter.spawn.async_pw_transport = pw, transport
     else:
@@ -22,26 +21,25 @@ def expect_async(expecter, timeout=None):
         pw.set_expecter(expecter)
         transport.resume_reading()
     try:
-        return (yield from asyncio.wait_for(pw.fut, timeout))
+        return (await asyncio.wait_for(pw.fut, timeout))
     except asyncio.TimeoutError as e:
         transport.pause_reading()
         return expecter.timeout(e)
 
-@asyncio.coroutine
-def repl_run_command_async(repl, cmdlines, timeout=-1):
+async def repl_run_command_async(repl, cmdlines, timeout=-1):
     res = []
     repl.child.sendline(cmdlines[0])
     for line in cmdlines[1:]:
-        yield from repl._expect_prompt(timeout=timeout, async_=True)
+        await repl._expect_prompt(timeout=timeout, async_=True)
         res.append(repl.child.before)
         repl.child.sendline(line)
 
     # Command was fully submitted, now wait for the next prompt
-    prompt_idx = yield from repl._expect_prompt(timeout=timeout, async_=True)
+    prompt_idx = await repl._expect_prompt(timeout=timeout, async_=True)
     if prompt_idx == 1:
         # We got the continuation prompt - command was incomplete
         repl.child.kill(signal.SIGINT)
-        yield from repl._expect_prompt(timeout=1, async_=True)
+        await repl._expect_prompt(timeout=1, async_=True)
         raise ValueError("Continuation prompt found - input was incomplete:")
     return u''.join(res + [repl.child.before])