From 544b01ad3df74cd92199c251292d6a8fdb09f47b Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Tue, 9 Aug 2016 23:43:59 -0700 Subject: [PATCH] Handle empty argument list for callbacks Fixes #26 --- socketio/server.py | 4 +++- tests/test_server.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/socketio/server.py b/socketio/server.py index b1e4154..227ff80 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -401,7 +401,9 @@ class Server(object): if id is not None: # send ACK packet with the response returned by the handler # tuples are expanded as multiple arguments - if isinstance(r, tuple): + if r is None: + data = [] + elif isinstance(r, tuple): data = list(r) else: data = [r] diff --git a/tests/test_server.py b/tests/test_server.py index 6ade1d4..372f61a 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -306,6 +306,15 @@ class TestServer(unittest.TestCase): s.eio.send.assert_called_once_with('123', '31000["foo"]', binary=False) + def test_handle_event_with_ack_none(self, eio): + s = server.Server() + handler = mock.MagicMock(return_value=None) + s.on('my message', handler) + s._handle_eio_message('123', '21000["my message","foo"]') + handler.assert_called_once_with('123', 'foo') + s.eio.send.assert_called_once_with('123', '31000[]', + binary=False) + def test_handle_event_with_ack_tuple(self, eio): mgr = mock.MagicMock() s = server.Server(client_manager=mgr)