From d6881cd8d5bcffb6906baf15124d6d52429b1b39 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 18 Nov 2023 07:06:10 +0100 Subject: [PATCH] feat: Process boolean True responses over Packet Stream --- ssb/muxrpc.py | 2 +- ssb/packet_stream.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ssb/muxrpc.py b/ssb/muxrpc.py index 46d23cd..594d5cf 100644 --- a/ssb/muxrpc.py +++ b/ssb/muxrpc.py @@ -184,7 +184,7 @@ class MuxRPCMessage: return cls(message.body) - def __init__(self, body: Union[bytes, str, Dict[str, Any]]): + def __init__(self, body: Union[bytes, str, Dict[str, Any], bool]): self.body = body def __repr__(self) -> str: diff --git a/ssb/packet_stream.py b/ssb/packet_stream.py index 2bbe22e..ade07a1 100644 --- a/ssb/packet_stream.py +++ b/ssb/packet_stream.py @@ -131,6 +131,9 @@ class PSMessage: def data(self) -> bytes: """The raw message data""" + if self.body is True: + return b"true" + if self.type == PSMessageType.TEXT: assert isinstance(self.body, str) @@ -147,7 +150,7 @@ class PSMessage: def __init__( self, type_: PSMessageType, - body: Union[bytes, str, Dict[str, Any]], + body: Union[bytes, str, Dict[str, Any], bool], stream: bool, end_err: bool, req: Optional[int] = None, @@ -159,7 +162,10 @@ class PSMessage: self.req = req def __repr__(self) -> str: - if self.type == PSMessageType.BUFFER: + if self.body is True: + body = "EOF" + elif self.type == PSMessageType.BUFFER: + assert isinstance(self.body, bytes) body = f"{len(self.body)} bytes" else: body = str(self.body)