Skip to content

Commit

Permalink
allow event names with hyphens
Browse files Browse the repository at this point in the history
Fixes #51
  • Loading branch information
miguelgrinberg committed Jan 23, 2017
1 parent 923ded0 commit 940d262
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 0 additions & 2 deletions socketio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ def message_handler(sid, msg):
client's acknowledgement callback function if it exists. The
``'disconnect'`` handler does not take a second argument.
"""
if '-' in event:
raise ValueError('event names cannot contain hypens')
namespace = namespace or '/'

def set_handler(handler):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ def test_decode_namespace_with_hyphens(self):
self.assertEqual(pkt.namespace, '/b-a-r')
self.assertEqual(pkt.encode(), '2/b-a-r,["foo"]')

def test_encode_event_with_hyphens(self):
pkt = packet.Packet(packet_type=packet.EVENT,
data=[six.text_type('f-o-o')])
self.assertEqual(pkt.namespace, None)
self.assertEqual(pkt.encode(), '2["f-o-o"]')

def test_decode_event_with_hyphens(self):
pkt = packet.Packet(encoded_packet='2["f-o-o"]')
self.assertEqual(pkt.namespace, None)
self.assertEqual(pkt.encode(), '2["f-o-o"]')

def test_encode_id(self):
pkt = packet.Packet(packet_type=packet.EVENT,
data=[six.text_type('foo')], id=123)
Expand Down
4 changes: 0 additions & 4 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ def bar():
self.assertEqual(s.handlers['/']['disconnect'], bar)
self.assertEqual(s.handlers['/foo']['disconnect'], bar)

def test_on_bad_event_name(self, eio):
s = server.Server()
self.assertRaises(ValueError, s.on, 'two-words')

def test_emit(self, eio):
mgr = mock.MagicMock()
s = server.Server(client_manager=mgr)
Expand Down

0 comments on commit 940d262

Please sign in to comment.