• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python protocol.StompParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中stompest.protocol.StompParser的典型用法代码示例。如果您正苦于以下问题:Python StompParser类的具体用法?Python StompParser怎么用?Python StompParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StompParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
开发者ID:nikipore,项目名称:stompest,代码行数:8,代码来源:parser_test.py


示例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)
开发者ID:IngoScholtes,项目名称:stompest,代码行数:8,代码来源:parser_test.py


示例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())
开发者ID:nikipore,项目名称:stompest,代码行数:9,代码来源:parser_test.py


示例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')
开发者ID:nikipore,项目名称:stompest,代码行数:10,代码来源:parser_test.py


示例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))
开发者ID:nikipore,项目名称:stompest,代码行数:11,代码来源:parser_test.py


示例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'))))
开发者ID:IngoScholtes,项目名称:stompest,代码行数:11,代码来源:parser_test.py


示例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)
开发者ID:IngoScholtes,项目名称:stompest,代码行数:11,代码来源:parser_test.py


示例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())
开发者ID:nikipore,项目名称:stompest,代码行数:11,代码来源:parser_test.py


示例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)
开发者ID:nikipore,项目名称:stompest,代码行数:12,代码来源:parser_test.py


示例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)
开发者ID:IngoScholtes,项目名称:stompest,代码行数:12,代码来源:parser_test.py


示例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)
开发者ID:nikipore,项目名称:stompest,代码行数:13,代码来源:parser_test.py


示例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)
开发者ID:IngoScholtes,项目名称:stompest,代码行数:13,代码来源:parser_test.py


示例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')
开发者ID:nikipore,项目名称:stompest,代码行数:13,代码来源:parser_test.py


示例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
开发者ID:nikipore,项目名称:stompest,代码行数:51,代码来源:broker_simulator.py


示例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())
开发者ID:nikipore,项目名称:stompest,代码行数:13,代码来源:parser_test.py


示例16: __init__

 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
     }
开发者ID:nikipore,项目名称:stompest,代码行数:11,代码来源:broker_simulator.py


示例17: __init__

 def __init__(self, url, playerStrategy):
     super(BlackjackClient, self).__init__(url)
     self.tokens = {}
     self.strategy = playerStrategy
     self.parser = StompParser(StompSpec.VERSION_1_1)
     self.session = StompSession(StompSpec.VERSION_1_1)
     self.connect()
     while self.session.state != 'connected':
         time.sleep(.1)
     self.__subscribe_to_queues()
     self.send_stomp('/app/register', json.dumps({'name': self.strategy.get_name()}))
开发者ID:rajagopal067,项目名称:PythonBlackjackClient,代码行数:11,代码来源:blackjack_client.py


示例18: test_add_throws_FrameError_on_invalid_command

    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())
开发者ID:nikipore,项目名称:stompest,代码行数:8,代码来源:parser_test.py


示例19: test_strip_line_delimiter

    def test_strip_line_delimiter(self):
        queue = '/queue/test'
        frame = commands.send(queue)
        frameWithStripLineDelimiter = commands.send(queue + '\r')
        for (version, stripLineDelimiter) in [
            (StompSpec.VERSION_1_0, False),
            (StompSpec.VERSION_1_1, False),
            (StompSpec.VERSION_1_2, True)
        ]:
            parser = StompParser(version)
            parser.add(binaryType(frameWithStripLineDelimiter))
            self.assertEqual(parser.get(), frame if stripLineDelimiter else frameWithStripLineDelimiter)

        frameWithCarriageReturn = commands.send(queue + '\r', version=StompSpec.VERSION_1_2)
        parser = StompParser(StompSpec.VERSION_1_2)
        parser.add(binaryType(frameWithCarriageReturn))
        self.assertEqual(parser.get().headers[StompSpec.DESTINATION_HEADER], queue + '\r')
开发者ID:nikipore,项目名称:stompest,代码行数:17,代码来源:parser_test.py


示例20: test_frames_with_heart_beats_succeeds

 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())
开发者ID:nikipore,项目名称:stompest,代码行数:10,代码来源:parser_test.py



注:本文中的stompest.protocol.StompParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sync.Stomp类代码示例发布时间:2022-05-27
下一篇:
Python stompest.Stomp类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap