Skip to content

Commit

Permalink
Expect Dispatcher replies to be tuples, not lists
Browse files Browse the repository at this point in the history
As mentioned in issue 176, according to the documentation one of the ways a
callback function may pass a reply back to a client is by returning a message
encapsulated thusly: `tuple(<Address>, <ArgValue>)`.

Whilst the code for the UDP servers does conform to this, the code to TCP
servers was expecting `list(<Address>, <ArgValue>)` in all cases.

This PR resolves that, updating the tests as well.
  • Loading branch information
s0600204 committed Jan 3, 2025
1 parent e50f481 commit f8244e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions pythonosc/osc_tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def handle(self) -> None:
)
# resp = _call_handlers_for_packet(data, self.server.dispatcher)
for r in resp:
if not isinstance(r, list):
if not isinstance(r, tuple):
r = [r]
msg = osc_message_builder.build_msg(r[0], r[1:])
b = struct.pack("!I", len(msg.dgram))
Expand Down Expand Up @@ -117,7 +117,7 @@ def handle(self) -> None:
p, self.client_address
)
for r in resp:
if not isinstance(r, list):
if not isinstance(r, tuple):
r = [r]
msg = osc_message_builder.build_msg(r[0], r[1:])
self.request.sendall(slip.encode(msg.dgram))
Expand Down Expand Up @@ -284,7 +284,7 @@ async def handle1_0(
buf, client_address
)
for r in result:
if not isinstance(r, list):
if not isinstance(r, tuple):
r = [r]
msg = osc_message_builder.build_msg(r[0], r[1:])
b = struct.pack("!I", len(msg.dgram))
Expand Down Expand Up @@ -319,7 +319,7 @@ async def handle_1_1(
p, client_address
)
for r in result:
if not isinstance(r, list):
if not isinstance(r, tuple):
r = [r]
msg = osc_message_builder.build_msg(r[0], r[1:])
writer.write(slip.encode(msg.dgram))
Expand Down
16 changes: 8 additions & 8 deletions pythonosc/test/test_osc_tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def respond(*args, **kwargs):

def test_response_with_args(self):
def respond(*args, **kwargs):
return [
return (
"/SYNC",
1,
"2",
3.0,
]
)

self.dispatcher.map("/SYNC", respond)
mock_sock = mock.Mock()
Expand Down Expand Up @@ -208,12 +208,12 @@ def respond(*args, **kwargs):

def test_response_with_args(self):
def respond(*args, **kwargs):
return [
return (
"/SYNC",
1,
"2",
3.0,
]
)

self.dispatcher.map("/SYNC", respond)
mock_sock = mock.Mock()
Expand Down Expand Up @@ -314,12 +314,12 @@ def respond(*args, **kwargs):

async def test_response_with_args(self):
def respond(*args, **kwargs):
return [
return (
"/SYNC",
1,
"2",
3.0,
]
)

self.dispatcher.map("/SYNC", respond)
self.mock_reader.read.side_effect = [_SIMPLE_MSG_NO_PARAMS_1_1, b""]
Expand All @@ -332,12 +332,12 @@ def respond(*args, **kwargs):

async def test_async_response_with_args(self):
async def respond(*args, **kwargs):
return [
return (
"/SYNC",
1,
"2",
3.0,
]
)

self.dispatcher.map("/SYNC", respond)
self.mock_reader.read.side_effect = [_SIMPLE_MSG_NO_PARAMS_1_1, b""]
Expand Down

0 comments on commit f8244e5

Please sign in to comment.