本文整理汇总了Python中stompest.protocol.StompParser类的典型用法代码示例。如果您正苦于以下问题:Python StompParser类的具体用法?Python StompParser怎么用?Python StompParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StompParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_frames_with_optional_newlines_succeeds
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())
示例2: test_frames_with_optional_newlines_succeeds
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)
示例3: test_dont_unescape_bad_characters
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())
示例4: test_keep_first_of_repeated_headers
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')
示例5: test_invalid_command
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))
示例6: test_invalid_command
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'))))
示例7: test_decode
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)
示例8: test_frame_parse_succeeds
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_no_newline
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)
示例10: test_no_newline
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)
示例11: test_decode
def test_decode(self):
key = b'fen\xc3\xaatre'.decode('utf-8')
value = b'\xc2\xbfqu\xc3\xa9 tal?'.decode('utf-8')
headers = {key: value}
frameBytes = binaryType(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.assertEqual(frame.headers, headers)
parser = StompParser(version=StompSpec.VERSION_1_0)
self.assertRaises(UnicodeDecodeError, parser.add, frameBytes)
示例12: test_binary_body
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)
示例13: test_duplicate_headers
def test_duplicate_headers(self):
command = StompSpec.SEND
rawFrame = '%s\nfoo:bar1\nfoo:bar2\n\nsome stuff\nand more\x00' % (command,)
parser = StompParser()
parser.add(rawFrame.encode())
parsedFrame = parser.get()
self.assertIsNone(parser.get())
self.assertEqual(parsedFrame.command, command)
self.assertEqual(parsedFrame.headers, {'foo': 'bar1'})
self.assertEqual(parsedFrame.rawHeaders, [('foo', 'bar1'), ('foo', 'bar2')])
self.assertEqual(parsedFrame.body, b'some stuff\nand more')
示例14: BlackHoleStompServer
class BlackHoleStompServer(Protocol):
delimiter = StompSpec.FRAME_DELIMITER
def __init__(self):
self.log = logging.getLogger(LOG_CATEGORY)
self._parser = StompParser()
self.commandMap = {
StompSpec.CONNECT: self.handleConnect,
StompSpec.DISCONNECT: self.handleDisconnect,
StompSpec.SEND: self.handleSend,
StompSpec.SUBSCRIBE: self.handleSubscribe,
StompSpec.ACK: self.handleAck,
StompSpec.NACK: self.handleNack
}
def connectionMade(self):
self.log.debug('Connection made')
def connectionLost(self, reason):
self.log.debug('Connection lost: %s' % reason)
def dataReceived(self, data):
self._parser.add(data)
for frame in iter(self._parser.get, self._parser.SENTINEL):
try:
self.log.debug('Received %s' % frame.info())
except KeyError:
raise StompFrameError('Unknown STOMP command: %s' % repr(frame))
self.commandMap[frame.command](frame)
def getFrame(self, command, headers, body):
return binaryType(StompFrame(command, headers, body, version=self._parser.version))
def handleConnect(self, frame):
pass
def handleDisconnect(self, frame):
pass
def handleSend(self, frame):
pass
def handleSubscribe(self, frame):
pass
def handleAck(self, frame):
pass
def handleNack(self, frame):
pass
示例15: test_reset_succeeds
def test_reset_succeeds(self):
frame = StompFrame(
command=StompSpec.SEND,
headers={'foo': 'bar', 'hello ': 'there-world with space ', 'empty-value':'', '':'empty-header', StompSpec.DESTINATION_HEADER: '/queue/blah'},
body=b'some stuff\nand more'
)
parser = StompParser()
parser.add(binaryType(frame))
parser.reset()
self.assertIsNone(parser.get())
parser.add(binaryType(frame)[:20])
self.assertIsNone(parser.get())