Commit 9b9afed2 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add more message alias groups

… and use them to fix message typing in test/example_filter.py
parent 2919c810
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ repos:
  rev: v1.4.1
  hooks:
  - id: mypy
    args: [--follow-imports=silent, kilter/protocol]
    args: [--follow-imports=silent, kilter/protocol, tests]
    pass_filenames: false
    additional_dependencies:
    - trio-typing
+22 −3
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ EventMessage: TypeAlias = Union[
	Abort,
]
"""
Messages sent from an MTA to a filter
Messages sent from an MTA to a filter to indicate an event occurrence
"""

ResponseMessage: TypeAlias = Union[
@@ -72,6 +72,25 @@ EditMessage: TypeAlias = Union[
Messages send from a filter to an MTA after an `EndOfMessage` to modify a message
"""

MTAMessage: TypeAlias = Union[
	EventMessage,
	Negotiate,
	Close,
]
"""
All messages that can be sent from an MTA to a filter
"""

FilterMessage: TypeAlias = Union[
	ResponseMessage,
	EditMessage,
	Negotiate,
	Skip,
]
"""
All messages that can be sent from a filter to an MTA
"""


class Unimplemented(messages.BytesMessage, ident=b"\x00"):
	"""
@@ -194,7 +213,7 @@ class FilterProtocol:
	def read_from(
		self,
		buf: FixedSizeBuffer,
	) -> Iterable[Negotiate|EventMessage|Close|Unimplemented]:
	) -> Iterable[MTAMessage|Unimplemented]:
		"""
		Return an iterator yielding each complete message from a buffer

@@ -223,7 +242,7 @@ class FilterProtocol:
	def write_to(
		self,
		buf: FixedSizeBuffer,
		message: ResponseMessage|EditMessage|Negotiate|Skip,
		message: FilterMessage,
	) -> None:
		"""
		Validate and pack response and modification messages into a buffer
+3 −2
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ import trio

from kilter.protocol import messages
from kilter.protocol.buffer import SimpleBuffer
from kilter.protocol.core import FilterMessage
from kilter.protocol.core import FilterProtocol
from kilter.protocol.core import Unimplemented

@@ -40,7 +41,7 @@ async def process_client(client: trio.SocketStream, nursery: trio.Nursery) -> No

	buf = SimpleBuffer(2**20)
	proto = FilterProtocol()
	send_channel, recv_channel = trio.open_memory_channel[messages.Message](4)
	send_channel, recv_channel = trio.open_memory_channel[FilterMessage](4)
	nursery.start_soon(client_sender, recv_channel, client, proto)

	async with client:
@@ -70,7 +71,7 @@ async def process_client(client: trio.SocketStream, nursery: trio.Nursery) -> No


async def client_sender(
	channel: trio.MemoryReceiveChannel[messages.Message],
	channel: trio.MemoryReceiveChannel[FilterMessage],
	client: trio.SocketStream,
	proto: FilterProtocol,
) -> None: