def send_over_stream(connection: socket.socket, raw_message: AbstractFrame, private_key: bytes) -> int: """ Helper for preparing AbstractFrame for sending through socket stream do actual send by doing: * serializing, * escaping, * adding frame separator, * sending over the socket. """ assert isinstance(raw_message, AbstractFrame) assert isinstance(private_key, bytes) return connection.send( append_frame_separator( escape_encode_raw_message( raw_message.serialize( private_key=private_key ) ) ) )
async def send_over_stream_async(frame: AbstractFrame, writer: asyncio.StreamWriter, private_key: bytes) -> None: data = frame.serialize(private_key) writer.write(append_frame_separator(escape_encode_raw_message(data))) await writer.drain()
def _prepare_mocked_reader(frame: AbstractFrame, private_key: bytes = SIGNING_SERVICE_PRIVATE_KEY): serialized = frame.serialize(private_key) data_to_send = append_frame_separator(escape_encode_raw_message(serialized)) return prepare_mocked_reader(data_to_send)