Skip to content

Commit

Permalink
Refactor, but still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
abbiemery committed Aug 1, 2023
1 parent 882da01 commit 1bdcc9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
12 changes: 4 additions & 8 deletions src/tickit/adapters/wrappers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from tickit.adapters.interpreters.wrappers.beheading_interpreter import (
BeheadingInterpreter,
)
from tickit.adapters.interpreters.wrappers.joining_interpreter import JoiningInterpreter
from tickit.adapters.interpreters.wrappers.splitting_interpreter import (
SplittingInterpreter,
)
from .beheading import BeheadingWrapper
from .joining import JoiningWrapper
from .splitting import SplittingWrapper

__all__ = ["BeheadingInterpreter", "SplittingInterpreter", "JoiningInterpreter"]
__all__ = ["SplittingWrapper", "BeheadingWrapper", "JoiningWrapper"]
20 changes: 9 additions & 11 deletions src/tickit/adapters/wrappers/joining.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
from typing import AnyStr, AsyncIterable, Tuple

from tickit.adapters.utils import wrap_as_async_iterator
from tickit.core.adapter import Adapter, Interpreter
from tickit.core.adapter import Interpreter


class JoiningWrapper(Interpreter[AnyStr]):
"""A wrapper for an interpreter that combines responses.
"""A wrapper for an adapter that combines responses.
An interpreter wrapper class that takes the wrapped interpreter's response(s) to a
An adapter wrapper class that takes the wrapped adapters's response(s) to a
message and combines them into a single response.
"""

def __init__(
self,
interpreter: Interpreter[AnyStr],
adapter: Interpreter[AnyStr],
response_delimiter: AnyStr,
) -> None:
"""A decorator for an interpreter that combines multiple responses into one.
Args:
interpreter (Interpreter): The interpreter responding to a message.
adapter (Interpreter): The adapter responding to a message.
response_delimiter (AnyStr): The delimiter separating the responses to the
individual responses when they are combined into a single response
message.
"""
super().__init__()
self.interpreter: Interpreter[AnyStr] = interpreter
self.adapter: Interpreter[AnyStr] = adapter
self.response_delimiter: AnyStr = response_delimiter

async def _combine_responses(
self, responses: AsyncIterable[AnyStr]
) -> AsyncIterable[AnyStr]:
"""Combines results from handling multiple messages.
Takes the responses from when the wrapped interpreter handles multiple messages
Takes the responses from when the wrapped adapter handles multiple messages
and returns an appropriate composite response and interrupt. The composite
response is the concatenation of each of the individual responses, the
composite interrupt is a logical inclusive 'or' of all of the individual
Expand All @@ -54,9 +54,7 @@ async def _combine_responses(
response = self.response_delimiter.join(response_list) # type: ignore
return wrap_as_async_iterator(response)

async def handle(
self, adapter: Adapter, message: AnyStr
) -> Tuple[AsyncIterable[AnyStr], bool]:
async def handle(self, message: AnyStr) -> Tuple[AsyncIterable[AnyStr], bool]:
"""Merges the responses from an interpreter into a single message.
Individual responses to the message are combined into a single response and
Expand All @@ -71,6 +69,6 @@ async def handle(
A tuple of the asynchronous iterable of a single reply message and a
flag indicating whether an interrupt should be raised by the adapter.
"""
responses, interrupt = await self.interpreter.handle(adapter, message)
responses, interrupt = await self.adapter.handle(message)
resp = await self._combine_responses(responses)
return resp, interrupt

0 comments on commit 1bdcc9b

Please sign in to comment.