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())
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')
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')
def test_strip_line_delimiter(self): queue = '/queue/test' frame = commands.send(queue) rawFrameReplaced = str(commands.send(queue)).replace('\n', '\r\n') for (version, replace) in [(StompSpec.VERSION_1_0, False), (StompSpec.VERSION_1_1, False), (StompSpec.VERSION_1_2, True)]: if replace: parser = StompParser(version) parser.add(rawFrameReplaced) self.assertEquals(parser.get(), frame) else: self.assertRaises(StompFrameError, StompParser(version).add, rawFrameReplaced) textWithCarriageReturn = 'there\rfolks' frame = commands.send(queue, headers={'hi': textWithCarriageReturn}) parser = StompParser(StompSpec.VERSION_1_2) parser.add(str(frame)) self.assertEquals(parser.get().headers['hi'], textWithCarriageReturn)
def test_strip_line_delimiter(self): queue = '/queue/test' frame = commands.send(queue) rawFrameReplaced = str(commands.send(queue)).replace('\n', '\r\n') for (version, replace) in [ (StompSpec.VERSION_1_0, False), (StompSpec.VERSION_1_1, False), (StompSpec.VERSION_1_2, True) ]: if replace: parser = StompParser(version) parser.add(rawFrameReplaced) self.assertEquals(parser.get(), frame) else: self.assertRaises(StompFrameError, StompParser(version).add, rawFrameReplaced) textWithCarriageReturn = 'there\rfolks' frame = commands.send(queue, headers={'hi': textWithCarriageReturn}) parser = StompParser(StompSpec.VERSION_1_2) parser.add(str(frame)) self.assertEquals(parser.get().headers['hi'], textWithCarriageReturn)
def send(self, destination, body='', headers=None, receipt=None): """send(destination, body='', headers=None, receipt=None) Send a **SEND** frame. """ self.sendFrame(commands.send(destination, body, headers, receipt))