示例#1
0
    def test_encoding(self):
        key = u'fen\xeatre'
        value = u'\xbfqu\xe9 tal?, s\xfc\xdf'
        command = StompSpec.DISCONNECT
        message = {
            'command': command,
            'headers': {
                key: value
            },
            'version': StompSpec.VERSION_1_1
        }
        frame = StompFrame(**message)
        self.assertEquals(message['headers'], frame.headers)
        self.assertEquals(dict(frame), message)

        self.assertEquals(eval(repr(frame)), frame)
        frame.version = StompSpec.VERSION_1_1
        self.assertEquals(eval(repr(frame)), frame)
        self.assertEquals(
            str(frame),
            codecs.lookup('utf-8').encode(command + u'\n' + key + u':' +
                                          value + u'\n\n\x00')[0])

        otherFrame = StompFrame(**message)
        self.assertEquals(frame, otherFrame)

        frame.version = StompSpec.VERSION_1_0
        self.assertRaises(UnicodeEncodeError, frame.__str__)
示例#2
0
    def test_encoding(self):
        key = b'fen\xc3\xaatre'.decode('utf-8')
        value = b'\xc2\xbfqu\xc3\xa9 tal?'.decode('utf-8')
        command = StompSpec.DISCONNECT
        message = {
            'command': command,
            'headers': {
                key: value
            },
            'version': StompSpec.VERSION_1_1
        }
        frame = StompFrame(**message)
        self.assertEqual(message['headers'], frame.headers)
        self.assertEqual(dict(frame), message)

        self.assertEqual(eval(repr(frame)), frame)
        frame.version = StompSpec.VERSION_1_1
        self.assertEqual(eval(repr(frame)), frame)
        expectedResult = (command + '\n' + key + ':' + value +
                          '\n\n\x00').encode('utf-8')
        self.assertEqual(binaryType(frame), expectedResult)

        otherFrame = StompFrame(**message)
        self.assertEqual(frame, otherFrame)

        frame.version = StompSpec.VERSION_1_0
        self.assertRaises(UnicodeEncodeError, binaryType, frame)
示例#3
0
    def test_encoding(self):
        key = 'fen\xeatre'
        value = '\xbfqu\xe9 tal?, s\xfc\xdf'
        command = StompSpec.DISCONNECT
        message = {'command': command, 'headers': {key: value}, 'version': StompSpec.VERSION_1_1}
        frame = StompFrame(**message)
        self.assertEquals(message['headers'], frame.headers)
        self.assertEquals(dict(frame), message)

        self.assertEquals(eval(repr(frame)), frame)
        frame.version = StompSpec.VERSION_1_1
        self.assertEquals(eval(repr(frame)), frame)
        self.assertEquals(str(frame), codecs.lookup('utf-8').encode(command + '\n' + key + ':' + value + '\n\n\x00')[0])

        otherFrame = StompFrame(**message)
        self.assertEquals(frame, otherFrame)

        frame.version = StompSpec.VERSION_1_0
        self.assertRaises(UnicodeEncodeError, frame.__str__)
示例#4
0
    def test_unescape(self):
        frameBytes = """%s
\\n\\\\:\\c\t\\n

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT,
                           headers={'\n\\': ':\t\n'},
                           version=StompSpec.VERSION_1_1)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s
\\n\\\\:\\c\t\\r

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT,
                           headers={'\n\\': ':\t\r'},
                           version=StompSpec.VERSION_1_2)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s
\\n\\\\:\\c\t\r

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT,
                           headers={'\n\\': ':\t\r'},
                           version=StompSpec.VERSION_1_1)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s

\\::\t\r


\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT,
                           headers={'\n\\': ':\t\r\n'},
                           version=StompSpec.VERSION_1_0)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s

\\::\t\r


\x00""" % StompSpec.CONNECT

        frame = StompFrame(command=StompSpec.CONNECT,
                           headers={'\n\\': ':\t\r\n'})
        for version in StompSpec.VERSIONS:
            frame.version = version
            self.assertEquals(str(frame), frameBytes)
示例#5
0
    def test_encoding(self):
        key = b'fen\xc3\xaatre'.decode('utf-8')
        value = b'\xc2\xbfqu\xc3\xa9 tal?'.decode('utf-8')
        command = StompSpec.DISCONNECT
        message = {'command': command, 'headers': {key: value}, 'version': StompSpec.VERSION_1_1}
        frame = StompFrame(**message)
        self.assertEqual(message['headers'], frame.headers)
        self.assertEqual(dict(frame), message)

        self.assertEqual(eval(repr(frame)), frame)
        frame.version = StompSpec.VERSION_1_1
        self.assertEqual(eval(repr(frame)), frame)
        expectedResult = (command + '\n' + key + ':' + value + '\n\n\x00').encode('utf-8')
        self.assertEqual(binaryType(frame), expectedResult)

        otherFrame = StompFrame(**message)
        self.assertEqual(frame, otherFrame)

        frame.version = StompSpec.VERSION_1_0
        self.assertRaises(UnicodeEncodeError, binaryType, frame)
示例#6
0
    def test_unescape(self):
        frameBytes = """%s
\\n\\\\:\\c\t\\n

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT, headers={'\n\\': ':\t\n'}, version=StompSpec.VERSION_1_1)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s
\\n\\\\:\\c\t\\r

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT, headers={'\n\\': ':\t\r'}, version=StompSpec.VERSION_1_2)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s
\\n\\\\:\\c\t\r

\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT, headers={'\n\\': ':\t\r'}, version=StompSpec.VERSION_1_1)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s

\\::\t\r


\x00""" % StompSpec.DISCONNECT

        frame = StompFrame(command=StompSpec.DISCONNECT, headers={'\n\\': ':\t\r\n'}, version=StompSpec.VERSION_1_0)
        self.assertEquals(str(frame), frameBytes)

        frameBytes = """%s

\\::\t\r


\x00""" % StompSpec.CONNECT

        frame = StompFrame(command=StompSpec.CONNECT, headers={'\n\\': ':\t\r\n'})
        for version in StompSpec.VERSIONS:
            frame.version = version
            self.assertEquals(str(frame), frameBytes)