Browse Source

Merge c091a17795 into 3c868255a4

pull/66/merge
Aleksandr Kurlov 9 years ago
committed by GitHub
parent
commit
b3d6d1272e
  1. 19
      socketio/packet.py
  2. 11
      tests/test_packet.py

19
socketio/packet.py

@ -78,12 +78,21 @@ class Packet(object):
self.namespace = None self.namespace = None
self.data = None self.data = None
ep = ep[1:] ep = ep[1:]
dash = (ep + '-').find('-')
comma = (ep + ',').find(',')
attachment_count = 0 attachment_count = 0
if dash < comma: if ep and ep[0].isdigit():
attachment_count = int(ep[0:dash]) # build number so it's either attachment count or id
ep = ep[dash + 1:] ind = 0
ep_len = len(ep)
while ind < ep_len and ep[ind].isdigit():
ind += 1
num = int(ep[0:ind])
ep = ep[ind:]
if ep:
if ep[0] == '-':
attachment_count = num
ep = ep[1:]
else:
self.id = num
if ep and ep[0:1] == '/': if ep and ep[0:1] == '/':
sep = ep.find(',') sep = ep.find(',')
if sep == -1: if sep == -1:

11
tests/test_packet.py

@ -106,6 +106,17 @@ class TestPacket(unittest.TestCase):
self.assertEqual(pkt.namespace, '/bar') self.assertEqual(pkt.namespace, '/bar')
self.assertEqual(pkt.encode(), '2/bar') self.assertEqual(pkt.encode(), '2/bar')
def test_encode_namespace_with_hyphens(self):
pkt = packet.Packet(packet_type=packet.EVENT,
data=[six.text_type('foo')], namespace='/b-a-r')
self.assertEqual(pkt.namespace, '/b-a-r')
self.assertEqual(pkt.encode(), '2/b-a-r,["foo"]')
def test_decode_namespace_with_hyphens(self):
pkt = packet.Packet(encoded_packet='2/b-a-r,["foo"]')
self.assertEqual(pkt.namespace, '/b-a-r')
self.assertEqual(pkt.encode(), '2/b-a-r,["foo"]')
def test_encode_id(self): def test_encode_id(self):
pkt = packet.Packet(packet_type=packet.EVENT, pkt = packet.Packet(packet_type=packet.EVENT,
data=[six.text_type('foo')], id=123) data=[six.text_type('foo')], id=123)

Loading…
Cancel
Save