本文整理汇总了Python中socketio.packet.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_encode_error
def test_encode_error(self):
"""encoding error packet """
encoded_message = encode({'type': 'error',
'reason': '',
'advice': '',
'endpoint': ''
})
self.assertEqual(encoded_message, '7:::')
# encoding error packet with reason
encoded_message = encode({'type': 'error',
'reason': 'transport not supported',
'advice': '',
'endpoint': ''
})
self.assertEqual(encoded_message, '7:::0')
# encoding error packet with reason and advice
encoded_message = encode({'type': 'error',
'reason': 'unauthorized',
'advice': 'reconnect',
'endpoint': ''
})
self.assertEqual(encoded_message, '7:::2+0')
# encoding error packet with endpoint
encoded_message = encode({'type': 'error',
'reason': '',
'advice': '',
'endpoint': '/woot'
})
self.assertEqual(encoded_message, '7:::/woot')
示例2: test_encode_event
def test_encode_event(self):
"""encoding an event packet """
encoded_message = encode({'type': 'event',
'endpoint': '',
'name': 'woot',
'args': []
})
self.assertEqual(encoded_message, '5:::{"name":"woot"}')
# encoding an event packet with message id and ack
encoded_message = encode({'type': 'event',
'name': 'tobi',
'id': 1,
'ack': True,
'data': ''
})
self.assertEqual(encoded_message, '5:1+::{"name":"tobi"}')
# encoding an event packet with data
encoded_message = encode({'type': 'event',
'name': 'edwald',
'ack': True,
'endpoint': '',
'args': [{"a":"b"}, 2,"3"]
})
self.assertEqual(encoded_message,
'5:::{"args":[{"a":"b"},2,"3"],"name":"edwald"}')
示例3: test_encode_connect
def test_encode_connect(self):
"""encoding a connection packet """
encoded_message = encode({'type': 'connect',
'endpoint': '/tobi',
'qs': '',
})
self.assertEqual(encoded_message, '1::/tobi')
# encoding a connection packet with query string
encoded_message = encode({'type': 'connect',
'endpoint': '/test',
'qs': '?test=1'
})
self.assertEqual(encoded_message, '1::/test:?test=1')
示例4: test_encode_json
def test_encode_json(self):
"""encoding JSON packet """
encoded_message = encode({'type': 'json',
'endpoint': '',
'data': '2'
})
self.assertEqual(encoded_message, '4:::"2"')
# encoding json packet with message id and ack data
encoded_message = encode({'type': 'json',
'id': 1,
'ack': 'data',
'endpoint': '',
'data': {'a' : 'b'}
})
self.assertEqual(encoded_message, '4:1+::{"a":"b"}')
示例5: test_encode_message
def test_encode_message(self):
"""encoding a message packet """
encoded_message = encode({'type': 'message',
'endpoint': '',
'data': 'woot'
})
self.assertEqual(encoded_message, '3:::woot')
# encoding a message packet with id and endpoint
encoded_message = encode({'type': 'message',
'endpoint': '/tobi',
'id': 5,
'ack': True,
'data': ''
})
self.assertEqual(encoded_message, '3:5:/tobi')
示例6: test_encode_noop
def test_encode_noop(self):
"""encoding a noop packet """
encoded_message = encode({'type': 'noop',
'endpoint': '',
'data': ''
})
self.assertEqual(encoded_message, '8::')
示例7: test_encode_ack
def test_encode_ack(self):
"""encoding ack packet """
encoded_message = encode({'type': 'ack',
'ackId': 140,
'endpoint': '',
'args': []
})
self.assertEqual(encoded_message, '6:::140')
# encoding ack packet with args
encoded_message = encode({'type': 'ack',
'ackId': 12,
'endpoint': '',
'args': ["woot","wa"]
})
self.assertEqual(encoded_message, '6:::12+["woot","wa"]')
示例8: test_encode_message_with_no_endpoint
def test_encode_message_with_no_endpoint(self):
"""encoding a message packet """
encoded_message = encode({'type': 'message',
'endpoint': None,
'data': 'woot'
})
self.assertEqual(encoded_message, '3:::woot')
示例9: test_encode_json_decimals
def test_encode_json_decimals(self):
"""encoding JSON packet with a decimal"""
# encoding json packet with message id and ack data
encoded_message = encode({'type': 'json',
'id': 1,
'ack': 'data',
'endpoint': '',
'data': {'a' : decimal.Decimal('%f' % (0.5))}
})
self.assertEqual(encoded_message, '4:1+::{"a":0.5}')
示例10: send_packet
def send_packet(self, pkt):
"""Low-level interface to queue a packet on the wire (encoded as wire
protocol"""
self.put_client_msg(packet.encode(pkt))
示例11: test_encode_heartbeat
def test_encode_heartbeat(self):
"""encoding a connection packet """
encoded_message = encode({'type': 'heartbeat',
'endpoint': ''
})
self.assertEqual(encoded_message, '2::')
示例12: test_encode_disconnect
def test_encode_disconnect(self):
"""encoding a disconnection packet """
encoded_message = encode({'type': 'disconnect',
'endpoint': '/woot'
})
self.assertEqual(encoded_message, '0::/woot')