Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional separator argument to TcpIo constructor #209

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/tickit/adapters/io/tcp_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class TcpIo(AdapterIo[CommandAdapter]):
host: str
port: int

def __init__(self, host: str, port: int) -> None:
def __init__(self, host: str, port: int, separator: str = None) -> None:
LeeHudsonDLS marked this conversation as resolved.
Show resolved Hide resolved
self.host = host
self.port = port
self.separator = separator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'm not sure the name separator is completely right, maybe terminator? Or just add a comment explaining what it does, it's not immediately obvious to me from the name (unlike host and port). Not bothered by that enough to block merge though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Callum, i'm not too sure about this name either, the reason I chose separator is because that's the name of the parameter in StreamReader.readUntil. I guess in this context it really is a terminator though. It probably makes sense to change it, i'll do that now


async def setup(
self, adapter: CommandAdapter, raise_interrupt: RaiseInterrupt
Expand Down Expand Up @@ -79,7 +80,11 @@ async def reply(replies: AsyncIterable[Optional[bytes]]) -> None:
tasks.append(asyncio.create_task(reply(on_connect())))

while True:
data: bytes = await reader.read(1024)
if self.separator != None:
LeeHudsonDLS marked this conversation as resolved.
Show resolved Hide resolved
data: bytes = await reader.readuntil(separator=self.separator.encode())
LeeHudsonDLS marked this conversation as resolved.
Show resolved Hide resolved
else:
data: bytes = await reader.read(1024)

if data == b"":
break
addr = writer.get_extra_info("peername")
Expand Down
Loading