Skip to content

Commit

Permalink
allow @socket.on decorators to be chained
Browse files Browse the repository at this point in the history
Fixes #408
  • Loading branch information
miguelgrinberg committed Feb 17, 2017
1 parent 32affb9 commit 4a01d81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_socketio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _handler(sid, *args):
self.server.on(message, _handler, namespace=namespace)
else:
self.handlers.append((message, _handler, namespace))
return _handler
return handler
return decorator

def on_error(self, namespace=None):
Expand Down
5 changes: 5 additions & 0 deletions test_socketio.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def on_custom_event(data):


@socketio.on('other custom event')
@socketio.on('and another custom event')
def get_request_event(data):
global request_event_data
request_event_data = request.event
Expand Down Expand Up @@ -317,6 +318,10 @@ def test_request_event_data(self):
client.emit('other custom event', 'foo')
expected_data = {'message': 'other custom event', 'args': ('foo',)}
self.assertEqual(request_event_data, expected_data)
client.emit('and another custom event', 'bar')
expected_data = {'message': 'and another custom event',
'args': ('bar',)}
self.assertEqual(request_event_data, expected_data)

def test_emit_namespace(self):
client = socketio.test_client(app, namespace='/test')
Expand Down

0 comments on commit 4a01d81

Please sign in to comment.