Browse Source

allow event names with hyphens

Fixes #51
pull/31/merge
Miguel Grinberg 8 years ago
parent
commit
940d262a1e
  1. 2
      socketio/server.py
  2. 11
      tests/test_packet.py
  3. 4
      tests/test_server.py

2
socketio/server.py

@ -149,8 +149,6 @@ class Server(object):
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):

11
tests/test_packet.py

@ -117,6 +117,17 @@ class TestPacket(unittest.TestCase):
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)

4
tests/test_server.py

@ -48,10 +48,6 @@ class TestServer(unittest.TestCase):
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)

Loading…
Cancel
Save