本文整理汇总了Python中stompest.protocol.StompParser.add方法的典型用法代码示例。如果您正苦于以下问题:Python StompParser.add方法的具体用法?Python StompParser.add怎么用?Python StompParser.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stompest.protocol.StompParser
的用法示例。
在下文中一共展示了StompParser.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary_body
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_binary_body(self):
body = b'\xf0\x00\x0a\x09'
headers = {StompSpec.CONTENT_LENGTH_HEADER: textType(len(body))}
frame = StompFrame(StompSpec.MESSAGE, body=body)
frame.setContentLength()
frameBytes = binaryType(frame)
self.assertTrue(frameBytes.endswith(b'\x00'))
parser = StompParser()
for _ in range(2):
for (j, _) in enumerate(frameBytes):
parser.add(frameBytes[j:j + 1])
frame = parser.get()
self.assertEqual(StompSpec.MESSAGE, frame.command)
self.assertEqual(headers, frame.headers)
self.assertEqual(body, frame.body)
self.assertEqual(parser.get(), None)
frames = 2 * frameBytes
split = len(frameBytes) - 1
chunks = [frames[:split], frames[split:]]
parser.add(chunks.pop(0))
self.assertEqual(parser.get(), None)
parser.add(chunks.pop(0))
self.assertEqual(parser.get(), frame)
self.assertEqual(parser.get(), frame)
self.assertEqual(parser.get(), None)
split = len(frameBytes) + 1
chunks = [frames[:split], frames[split:]]
parser.add(chunks.pop(0))
self.assertEqual(parser.get(), frame)
self.assertEqual(parser.get(), None)
parser.add(chunks.pop(0))
self.assertEqual(parser.get(), frame)
self.assertEqual(parser.get(), None)
示例2: test_frames_with_optional_newlines_succeeds
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_frames_with_optional_newlines_succeeds(self):
parser = StompParser()
disconnect = commands.disconnect()
frame = b'\n' + binaryType(disconnect) + b'\n'
parser.add(2 * frame)
for _ in range(2):
self.assertEqual(parser.get(), disconnect)
self.assertIsNone(parser.get())
示例3: test_frames_with_optional_newlines_succeeds
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_frames_with_optional_newlines_succeeds(self):
parser = StompParser()
disconnect = commands.disconnect()
frame = '\n%s\n' % disconnect
parser.add(2 * frame)
for _ in xrange(2):
self.assertEqual(parser.get(), disconnect)
self.assertEqual(parser.get(), None)
示例4: test_add_throws_FrameError_on_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [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())
示例5: test_dont_unescape_bad_characters
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_dont_unescape_bad_characters(self):
parser = StompParser(StompSpec.VERSION_1_2)
frame = commands.send('*queue')
parser.add(binaryType(frame))
self.assertEqual(parser.get(), frame)
for badCharacter in (b'\r', b'\n', b'\c', b'\\', b':', b'\\h'):
self.assertRaises(StompFrameError, parser.add, binaryType(frame).replace(b'*', badCharacter))
self.assertRaises(StompFrameError, parser.add, binaryType(commands.send('queue\\')))
self.assertIsNone(parser.get())
示例6: test_frames_with_heart_beats_succeeds
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [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())
示例7: test_keep_first_of_repeated_headers
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_keep_first_of_repeated_headers(self):
parser = StompParser()
parser.add(("""
%s
repeat:1
repeat:2
\x00""" % StompSpec.CONNECT).encode())
frame = parser.get()
self.assertEqual(frame.headers['repeat'], '1')
示例8: test_frame_parse_succeeds
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_frame_parse_succeeds(self):
frame = StompFrame(
StompSpec.SEND,
{'foo': 'bar', 'hello ': 'there-world with space ', 'empty-value':'', '':'empty-header', StompSpec.DESTINATION_HEADER: '/queue/blah'},
b'some stuff\nand more'
)
parser = StompParser()
parser.add(binaryType(frame))
self.assertEqual(parser.get(), frame)
self.assertIsNone(parser.get())
示例9: test_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [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'))))
示例10: test_decode
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_decode(self):
headers = {u'fen\xeatre': u'\xbfqu\xe9 tal?, s\xfc\xdf'}
frameBytes = str(StompFrame(command=StompSpec.DISCONNECT, headers=headers, version=StompSpec.VERSION_1_1))
parser = StompParser(version=StompSpec.VERSION_1_1)
parser.add(frameBytes)
frame = parser.get()
self.assertEquals(frame.headers, headers)
parser = StompParser(version=StompSpec.VERSION_1_0)
self.assertRaises(UnicodeDecodeError, parser.add, frameBytes)
示例11: test_invalid_command
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [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))
示例12: main
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [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()
示例13: test_no_newline
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_no_newline(self):
headers = {'x': 'y'}
body = b'testing 1 2 3'
frameBytes = binaryType(StompFrame(StompSpec.MESSAGE, headers, body))
self.assertTrue(frameBytes.endswith(b'\x00'))
parser = StompParser()
parser.add(frameBytes)
frame = parser.get()
self.assertEqual(StompSpec.MESSAGE, frame.command)
self.assertEqual(headers, frame.headers)
self.assertEqual(body, frame.body)
self.assertEqual(parser.get(), None)
示例14: test_no_newline
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_no_newline(self):
headers = {'x': 'y'}
body = 'testing 1 2 3'
frameBytes = str(StompFrame(StompSpec.MESSAGE, headers, body))
self.assertTrue(frameBytes.endswith('\x00'))
parser = StompParser()
parser.add(self._generate_bytes(frameBytes))
frame = parser.get()
self.assertEquals(StompSpec.MESSAGE, frame.command)
self.assertEquals(headers, frame.headers)
self.assertEquals(body, frame.body)
self.assertEquals(parser.get(), None)
示例15: test_binary_body
# 需要导入模块: from stompest.protocol import StompParser [as 别名]
# 或者: from stompest.protocol.StompParser import add [as 别名]
def test_binary_body(self):
body = binascii.a2b_hex('f0000a09')
headers = {'content-length': str(len(body))}
frameBytes = str(StompFrame(StompSpec.MESSAGE, headers, body))
self.assertTrue(frameBytes.endswith('\x00'))
parser = StompParser()
parser.add(frameBytes)
frame = parser.get()
self.assertEquals(StompSpec.MESSAGE, frame.command)
self.assertEquals(headers, frame.headers)
self.assertEquals(body, frame.body)
self.assertEquals(parser.get(), None)