Miguel Grinberg
3 years ago
No known key found for this signature in database
GPG Key ID: 36848B262DF5F06C
4 changed files with
24 additions and
2 deletions
-
src/socketio/asyncio_server.py
-
src/socketio/server.py
-
tests/asyncio/test_asyncio_server.py
-
tests/common/test_server.py
|
|
@ -514,7 +514,7 @@ class AsyncServer(server.Server): |
|
|
|
async def _handle_event_internal(self, server, sid, eio_sid, data, |
|
|
|
namespace, id): |
|
|
|
r = await server._trigger_event(data[0], namespace, sid, *data[1:]) |
|
|
|
if id is not None: |
|
|
|
if r != self.not_handled and id is not None: |
|
|
|
# send ACK packet with the response returned by the handler |
|
|
|
# tuples are expanded as multiple arguments |
|
|
|
if r is None: |
|
|
@ -553,6 +553,8 @@ class AsyncServer(server.Server): |
|
|
|
else: |
|
|
|
ret = handler(*args) |
|
|
|
return ret |
|
|
|
else: |
|
|
|
return self.not_handled |
|
|
|
|
|
|
|
# or else, forward the event to a namepsace handler if one exists |
|
|
|
elif namespace in self.namespace_handlers: # pragma: no branch |
|
|
|
|
|
@ -134,6 +134,7 @@ class Server(object): |
|
|
|
self.environ = {} |
|
|
|
self.handlers = {} |
|
|
|
self.namespace_handlers = {} |
|
|
|
self.not_handled = object() |
|
|
|
|
|
|
|
self._binary_packet = {} |
|
|
|
|
|
|
@ -720,7 +721,7 @@ class Server(object): |
|
|
|
def _handle_event_internal(self, server, sid, eio_sid, data, namespace, |
|
|
|
id): |
|
|
|
r = server._trigger_event(data[0], namespace, sid, *data[1:]) |
|
|
|
if id is not None: |
|
|
|
if r != self.not_handled and id is not None: |
|
|
|
# send ACK packet with the response returned by the handler |
|
|
|
# tuples are expanded as multiple arguments |
|
|
|
if r is None: |
|
|
@ -748,6 +749,8 @@ class Server(object): |
|
|
|
elif event not in self.reserved_events and \ |
|
|
|
'*' in self.handlers[namespace]: |
|
|
|
return self.handlers[namespace]['*'](event, *args) |
|
|
|
else: |
|
|
|
return self.not_handled |
|
|
|
|
|
|
|
# or else, forward the event to a namespace handler if one exists |
|
|
|
elif namespace in self.namespace_handlers: # pragma: no branch |
|
|
|
|
|
@ -703,6 +703,15 @@ class TestAsyncServer(unittest.TestCase): |
|
|
|
'123', '31000["foo"]' |
|
|
|
) |
|
|
|
|
|
|
|
def test_handle_unknown_event_with_ack(self, eio): |
|
|
|
eio.return_value.send = AsyncMock() |
|
|
|
s = asyncio_server.AsyncServer(async_handlers=False) |
|
|
|
s.manager.connect('123', '/') |
|
|
|
handler = mock.MagicMock(return_value='foo') |
|
|
|
s.on('my message', handler) |
|
|
|
_run(s._handle_eio_message('123', '21000["another message","foo"]')) |
|
|
|
s.eio.send.mock.assert_not_called() |
|
|
|
|
|
|
|
def test_handle_event_with_ack_none(self, eio): |
|
|
|
eio.return_value.send = AsyncMock() |
|
|
|
s = asyncio_server.AsyncServer(async_handlers=False) |
|
|
|
|
|
@ -618,6 +618,14 @@ class TestServer(unittest.TestCase): |
|
|
|
handler.assert_called_once_with(sid, 'foo') |
|
|
|
s.eio.send.assert_called_once_with('123', '31000["foo"]') |
|
|
|
|
|
|
|
def test_handle_unknown_event_with_ack(self, eio): |
|
|
|
s = server.Server(async_handlers=False) |
|
|
|
s.manager.connect('123', '/') |
|
|
|
handler = mock.MagicMock(return_value='foo') |
|
|
|
s.on('my message', handler) |
|
|
|
s._handle_eio_message('123', '21000["another message","foo"]') |
|
|
|
s.eio.send.assert_not_called() |
|
|
|
|
|
|
|
def test_handle_event_with_ack_none(self, eio): |
|
|
|
s = server.Server(async_handlers=False) |
|
|
|
sid = s.manager.connect('123', '/') |
|
|
|