build: Remove async_generator as a dependency

Python 3.6+ can do this natively.
This commit is contained in:
Gergely Polonkai 2023-11-01 06:03:06 +01:00
parent 9aa3389902
commit 160ca7109e
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
5 changed files with 34 additions and 42 deletions

13
poetry.lock generated
View File

@ -25,17 +25,6 @@ files = [
[package.extras] [package.extras]
test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] test = ["coverage", "mypy", "pexpect", "ruff", "wheel"]
[[package]]
name = "async-generator"
version = "1.8"
description = "Async generators for Python 3.5"
optional = false
python-versions = "*"
files = [
{file = "async_generator-1.8-py3-none-any.whl", hash = "sha256:d9253336202cb9df50ba617893fe794c61394a7eb4b9054f285c860f395ac6ff"},
{file = "async_generator-1.8.zip", hash = "sha256:928b644cfc92be498f2d6c431e0082ae79ea736fbdf1ce4247881071dd525348"},
]
[[package]] [[package]]
name = "babel" name = "babel"
version = "2.13.1" version = "2.13.1"
@ -1107,4 +1096,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.9" python-versions = "^3.9"
content-hash = "07928049d2f542da0c873096fbebaf417d657980d89b578beda482a56d002924" content-hash = "f36d397c63377df66056beb600b8db2e6fe32f8f8224c4cafb3d472723069854"

View File

@ -8,7 +8,6 @@ readme = "README.rst"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.9" python = "^3.9"
async_generator = "^1.8"
PyNaCl = "^1.1.0" PyNaCl = "^1.1.0"
PyYAML = "^6.0.1" PyYAML = "^6.0.1"
secret-handshake = { git = "https://gitea.polonkai.eu/gergely/PySecretHandshake", branch = "main" } secret-handshake = { git = "https://gitea.polonkai.eu/gergely/PySecretHandshake", branch = "main" }

View File

@ -1,7 +1,5 @@
from functools import wraps from functools import wraps
from async_generator import async_generator, yield_
from ssb.packet_stream import PSMessageType from ssb.packet_stream import PSMessageType
@ -9,7 +7,7 @@ class MuxRPCAPIException(Exception):
pass pass
class MuxRPCHandler(object): class MuxRPCHandler:
def check_message(self, msg): def check_message(self, msg):
body = msg.body body = msg.body
if isinstance(body, dict) and 'name' in body and body['name'] == 'Error': if isinstance(body, dict) and 'name' in body and body['name'] == 'Error':
@ -30,14 +28,14 @@ class MuxRPCSourceHandler(MuxRPCHandler):
def __init__(self, ps_handler): def __init__(self, ps_handler):
self.ps_handler = ps_handler self.ps_handler = ps_handler
@async_generator def __aiter__(self):
async def __aiter__(self): return self
async for msg in self.ps_handler:
try: async def __anext__(self):
msg = await self.ps_handler.__anext__()
self.check_message(msg) self.check_message(msg)
await yield_(msg)
except MuxRPCAPIException: return msg
raise
class MuxRPCSinkHandlerMixin(object): class MuxRPCSinkHandlerMixin(object):

View File

@ -6,7 +6,6 @@ from time import time
from math import ceil from math import ceil
import simplejson import simplejson
from async_generator import async_generator, yield_
from secret_handshake import SHSClient, SHSServer from secret_handshake import SHSClient, SHSServer
@ -32,13 +31,16 @@ class PSStreamHandler(object):
async def stop(self): async def stop(self):
await self.queue.put(None) await self.queue.put(None)
@async_generator def __aiter__(self):
async def __aiter__(self): return self
while True:
async def __anext__(self):
elem = await self.queue.get() elem = await self.queue.get()
if not elem: if not elem:
return raise StopAsyncIteration()
await yield_(elem)
return elem
class PSRequestHandler(object): class PSRequestHandler(object):
@ -113,15 +115,19 @@ class PacketStream(object):
def is_connected(self): def is_connected(self):
return self.connection.is_connected return self.connection.is_connected
@async_generator def __aiter__(self):
async def __aiter__(self): return self
while True:
async def __anext__(self):
msg = await self.read() msg = await self.read()
if not msg: if not msg:
return raise StopAsyncIteration()
# filter out replies
if msg.req >= 0: if msg.req >= 0:
await yield_(msg) return msg
return None
async def __await__(self): async def __await__(self):
async for data in self: async for data in self:

View File

@ -221,7 +221,7 @@ async def test_message_stream(ps_client, mocker):
collected, handled = await gather(_collect_messages(ps), _collect_messages(stream_handler)) collected, handled = await gather(_collect_messages(ps), _collect_messages(stream_handler))
# No messages collected, since they're all responses # No messages collected, since they're all responses
assert collected == [] assert collected == [None, None]
assert mock_process.call_count == 2 assert mock_process.call_count == 2