当前位置: 首页>>代码示例>>Python>>正文


Python serialization.AMQPWriter类代码示例

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


在下文中一共展示了AMQPWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_table_multi

    def test_table_multi(self):
        val = {
            'foo': 7,
            'bar': Decimal('123345.1234'),
            'baz': 'this is some random string I typed',
            'ubaz': u'And something in unicode',
            'dday_aniv': datetime(1994, 6, 6),
            'more': {
                'abc': -123,
                'def': 'hello world',
                'now': datetime(2007, 11, 11, 21, 14, 31),
                'qty': Decimal('-123.45'),
                'blank': {},
                'extra': {
                    'deeper': 'more strings',
                    'nums': -12345678,
                },
            }
        }

        w = AMQPWriter()
        w.write_table(val)
        s = w.getvalue()

        r = AMQPReader(s)
        self.assertEqual(r.read_table(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:26,代码来源:test_serialization.py

示例2: test_shortstr_unicode

    def test_shortstr_unicode(self):
        w = AMQPWriter()
        w.write_shortstr(u'hello')
        s = w.getvalue()
        self.assertEqualBinary(s, '\x05hello')

        r = AMQPReader(s)
        self.assertEqual(r.read_shortstr(), u'hello')
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:8,代码来源:test_serialization.py

示例3: test_empty_longstr

    def test_empty_longstr(self):
        w = AMQPWriter()
        w.write_longstr('')
        s = w.getvalue()

        self.assertEqualBinary(s, '\x00\x00\x00\x00')

        r = AMQPReader(s)
        self.assertEqual(r.read_longstr(), '')
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:9,代码来源:test_serialization.py

示例4: test_longlong

    def test_longlong(self):
        for i in range(256):
            val = randint(0, (2 ** 64) - 1)
            w = AMQPWriter()
            w.write_longlong(val)
            s = w.getvalue()

            r = AMQPReader(s)
            self.assertEqual(r.read_longlong(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:9,代码来源:test_serialization.py

示例5: test_short

    def test_short(self):
        for i in range(256):
            val = randint(0, 65535)
            w = AMQPWriter()
            w.write_short(val)
            s = w.getvalue()

            r = AMQPReader(s)
            self.assertEqual(r.read_short(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:9,代码来源:test_serialization.py

示例6: test_octet

    def test_octet(self):
        for val in range(256):
            w = AMQPWriter()
            w.write_octet(val)
            s = w.getvalue()
            self.assertEqualBinary(s, chr(val))

            r = AMQPReader(s)
            self.assertEqual(r.read_octet(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:9,代码来源:test_serialization.py

示例7: test_single_bit

    def test_single_bit(self):
        for val, check in [(True, '\x01'), (False, '\x00')]:
            w = AMQPWriter()
            w.write_bit(val)
            s = w.getvalue()

            self.assertEqualBinary(s, check)

            r = AMQPReader(s)
            self.assertEqual(r.read_bit(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:10,代码来源:test_serialization.py

示例8: test_table_empty

    def test_table_empty(self):
        val = {}
        w = AMQPWriter()
        w.write_table(val)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x00\x00\x00\x00')

        r = AMQPReader(s)
        self.assertEqual(r.read_table(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:10,代码来源:test_serialization.py

示例9: test_longstr_unicode

    def test_longstr_unicode(self):
        val = u'a' * 512
        w = AMQPWriter()
        w.write_longstr(val)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x00\x00\x02\x00' + ('a' * 512))

        r = AMQPReader(s)
        self.assertEqual(r.read_longstr(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:10,代码来源:test_serialization.py

示例10: test_array_from_tuple

    def test_array_from_tuple(self):
        val = (1, 'foo')
        w = AMQPWriter()
        w.write_array(val)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x00\x00\x00\x0DI\x00\x00\x00\x01S\x00\x00\x00\x03foo')

        r = AMQPReader(s)
        self.assertEqual(r.read_array(), list(val))
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:10,代码来源:test_serialization.py

示例11: test_table

    def test_table(self):
        val = {'foo': 7}
        w = AMQPWriter()
        w.write_table(val)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x00\x00\x00\x09\x03fooI\x00\x00\x00\x07')

        r = AMQPReader(s)
        self.assertEqual(r.read_table(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:10,代码来源:test_serialization.py

示例12: test_array_from_list

    def test_array_from_list(self):
        val = [1, 'foo', None]
        w = AMQPWriter()
        w.write_array(val)
        s = w.getvalue()

        self.assertEqualBinary(
            s, '\x00\x00\x00\x0EI\x00\x00\x00\x01S\x00\x00\x00\x03fooV',
        )

        r = AMQPReader(s)
        self.assertEqual(r.read_array(), val)
开发者ID:1st1,项目名称:py-amqp,代码行数:12,代码来源:test_serialization.py

示例13: test_table_with_array

    def test_table_with_array(self):
        val = {
            'foo': 7,
            'bar': Decimal('123345.1234'),
            'baz': 'this is some random string I typed',
            'blist': [1,2,3],
            'nlist': [1, [2,3,4]],
            'ndictl': {'nfoo': 8, 'nblist': [5,6,7] }
        }

        w = AMQPWriter()
        w.write_table(val)
        s = w.getvalue()

        r = AMQPReader(s)
        self.assertEqual(r.read_table(), val)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:16,代码来源:test_serialization.py

示例14: test_multiple_bits2

    def test_multiple_bits2(self):
        """
        Check bits mixed with non-bits
        """
        w = AMQPWriter()
        w.write_bit(True)
        w.write_bit(True)
        w.write_bit(False)
        w.write_octet(10)
        w.write_bit(True)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x03\x0a\x01')

        r = AMQPReader(s)
        self.assertEqual(r.read_bit(), True)
        self.assertEqual(r.read_bit(), True)
        self.assertEqual(r.read_bit(), False)
        self.assertEqual(r.read_octet(), 10)
        self.assertEqual(r.read_bit(), True)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:20,代码来源:test_serialization.py

示例15: test_multiple_bits

    def test_multiple_bits(self):
        w = AMQPWriter()
        w.write_bit(True)
        w.write_bit(True)
        w.write_bit(False)
        w.write_bit(True)
        s = w.getvalue()

        self.assertEqualBinary(s, '\x0b')

        r = AMQPReader(s)
        self.assertEqual(r.read_bit(), True)
        self.assertEqual(r.read_bit(), True)
        self.assertEqual(r.read_bit(), False)
        self.assertEqual(r.read_bit(), True)
开发者ID:UCSB-CS-RACELab,项目名称:CloudRunner,代码行数:15,代码来源:test_serialization.py


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