Replace asyncio.coroutine to fix Python 3.11 support (#2019843)

This commit is contained in:
Scott Talbert 2022-03-24 19:42:55 -04:00
parent 740948a80c
commit c05ef6adbf
2 changed files with 73 additions and 2 deletions

View File

@ -0,0 +1,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])

View File

@ -5,11 +5,12 @@
Name: python-%{modname}
Summary: Unicode-aware Pure Python Expect-like module
Version: 4.8.0
Release: 10%{?dist}
Release: 11%{?dist}
License: ISC
URL: https://github.com/pexpect/pexpect
Source0: %{url}/archive/%{version}/%{modname}-%{version}.tar.gz
Patch0: %{url}/pull/715/commits/52af5b0ae0627139524448a3f2e83d9f40802bc2.patch
BuildRequires: /usr/bin/man
%if %{with check}
@ -60,7 +61,7 @@ compiled. It should work on any platform that supports the standard Python
pty module.
%prep
%autosetup -n %{modname}-%{version}
%autosetup -n %{modname}-%{version} -p 1
%build
%py3_build
@ -92,6 +93,9 @@ TRAVIS=true py.test-3 --verbose
%{python3_sitelib}/%{modname}-*.egg-info
%changelog
* Thu Mar 24 2022 Scott Talbert <swt@techie.net> - 4.8.0-11
- Replace asyncio.coroutine to fix Python 3.11 support (#2019843)
* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 4.8.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild