本文整理匯總了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'))))