本文整理汇总了Python中stompest.protocol.StompParser.canRead方法的典型用法代码示例。如果您正苦于以下问题:Python StompParser.canRead方法的具体用法?Python StompParser.canRead怎么用?Python StompParser.canRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stompest.protocol.StompParser
的用法示例。
在下文中一共展示了StompParser.canRead方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add_throws_FrameError_on_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import canRead [as 别名]
def test_add_throws_FrameError_on_invalid_command(self):
parser = StompParser()
self.assertRaises(StompFrameError, parser.add, b'HELLO\n\n\x00')
self.assertFalse(parser.canRead())
parser.add(('%s\n\n\x00' % StompSpec.DISCONNECT).encode())
self.assertEqual(StompFrame(StompSpec.DISCONNECT), parser.get())
self.assertFalse(parser.canRead())
示例2: test_frames_with_heart_beats_succeeds
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import canRead [as 别名]
def test_frames_with_heart_beats_succeeds(self):
parser = StompParser(version=StompSpec.VERSION_1_1)
disconnect = commands.disconnect()
frame = b'\n' + binaryType(disconnect) + b'\n'
parser.add(2 * frame)
frames = []
while parser.canRead():
frames.append(parser.get())
self.assertEqual(frames, [StompHeartBeat(), disconnect, StompHeartBeat(), StompHeartBeat(), disconnect, StompHeartBeat()])
self.assertIsNone(parser.get())
示例3: main
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import canRead [as 别名]
def main():
parser = StompParser(version=StompSpec.VERSION_1_2)
frame = binaryType(binaryFrame) + binaryType(textFrame) + binaryType(heartBeatFrame)
for _ in createRange(N):
for j in itertools.count():
packet = frame[j * SLICE:(j + 1) * SLICE]
if not packet:
break
parser.add(packet)
while parser.canRead():
parser.get()
示例4: test_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import canRead [as 别名]
def test_invalid_command(self):
messages = [b'RECEIPT\nreceipt-id:message-12345\n\n\x00', b'NACK\nsubscription:0\nmessage-id:007\n\n\x00']
parser = StompParser(StompSpec.VERSION_1_0)
parser.add(messages[0])
self.assertRaises(StompFrameError, parser.add, messages[1])
self.assertEqual(parser.get(), StompFrame(StompSpec.RECEIPT, rawHeaders=(('receipt-id', 'message-12345'),)))
self.assertFalse(parser.canRead())
self.assertIsNone(parser.get())
parser = StompParser(StompSpec.VERSION_1_1)
parser.add(messages[1])
self.assertEqual(parser.get(), StompFrame(command='NACK', rawHeaders=(('subscription', '0'), ('message-id', '007')), version=StompSpec.VERSION_1_1))
示例5: test_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import canRead [as 别名]
def test_invalid_command(self):
messages = ['RECEIPT\nreceipt-id:message-12345\n\n\x00', 'NACK\nsubscription:0\nmessage-id:007\n\n\x00']
parser = StompParser('1.0')
parser.add(messages[0])
self.assertRaises(StompFrameError, parser.add, messages[1])
self.assertEquals(parser.get(), StompFrame(StompSpec.RECEIPT, rawHeaders=((u'receipt-id', u'message-12345'),)))
self.assertFalse(parser.canRead())
self.assertEquals(parser.get(), None)
parser = StompParser('1.1')
parser.add(messages[1])
self.assertEquals(parser.get(), StompFrame(command=u'NACK', rawHeaders=((u'subscription', u'0'), (u'message-id', u'007'))))