def receiveFrame(self): self._checkConnected() parser = StompFrameLineParser() while (not parser.isDone()): parser.processLine(self.sfile.readline()[:-1]) return parser.getMessage()
def parseFrame(self, message): from stompest.parser import StompFrameLineParser parser = StompFrameLineParser() for line in message.split('\n')[:-1]: parser.processLine(line) self.assertTrue(parser.isDone()) return parser.getMessage()
def test_frame_without_header_or_body_succeeds(self): cmd = stomper.disconnect() lines = cmd.split('\n')[:-1] parser = StompFrameLineParser() for line in lines: parser.processLine(line) msg = parser.getMessage() self.assertEqual(msg, {'cmd': 'DISCONNECT', 'headers': {}, 'body': ''})
def test_frameParse_succeeds(self): frame = stomper.Frame() frame.cmd = 'SEND' frame.headers = {'foo': 'bar', 'hello ': 'there-world with space ', 'empty-value':'', '':'empty-header'} frame.headers['destination'] = '/queue/blah' frame.body = 'some stuff\nand more' cmd = frame.pack() lines = cmd.split('\n')[:-1] parser = StompFrameLineParser() self.assertFalse(parser.isDone()) for line in lines: self.assertFalse(parser.isDone()) parser.processLine(line) self.assertTrue(parser.isDone()) msg = parser.getMessage() self.assertEqual(msg, {'cmd': 'SEND', 'headers': {'foo': 'bar', 'hello ': 'there-world with space ', 'empty-value':'', '':'empty-header', 'destination': '/queue/blah'}, 'body': 'some stuff\nand more'})
def test_getMessage_returns_None_if_not_done(self): parser = StompFrameLineParser() self.assertEqual(None, parser.getMessage()) parser.processLine('CONNECT') self.assertEqual(None, parser.getMessage())