Skip to content

Commit 544b01a

Browse files
Handle empty argument list for callbacks
Fixes #26
1 parent 21a80ea commit 544b01a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

socketio/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,9 @@ def _handle_event(self, sid, namespace, id, data):
401401
if id is not None:
402402
# send ACK packet with the response returned by the handler
403403
# tuples are expanded as multiple arguments
404-
if isinstance(r, tuple):
404+
if r is None:
405+
data = []
406+
elif isinstance(r, tuple):
405407
data = list(r)
406408
else:
407409
data = [r]

tests/test_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,15 @@ def test_handle_event_with_ack(self, eio):
306306
s.eio.send.assert_called_once_with('123', '31000["foo"]',
307307
binary=False)
308308

309+
def test_handle_event_with_ack_none(self, eio):
310+
s = server.Server()
311+
handler = mock.MagicMock(return_value=None)
312+
s.on('my message', handler)
313+
s._handle_eio_message('123', '21000["my message","foo"]')
314+
handler.assert_called_once_with('123', 'foo')
315+
s.eio.send.assert_called_once_with('123', '31000[]',
316+
binary=False)
317+
309318
def test_handle_event_with_ack_tuple(self, eio):
310319
mgr = mock.MagicMock()
311320
s = server.Server(client_manager=mgr)

0 commit comments

Comments
 (0)