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


Python amp.Unicode方法代码示例

本文整理汇总了Python中twisted.protocols.amp.Unicode方法的典型用法代码示例。如果您正苦于以下问题:Python amp.Unicode方法的具体用法?Python amp.Unicode怎么用?Python amp.Unicode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.protocols.amp的用法示例。


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

示例1: test_compression_is_worth_it

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Unicode [as 别名]
def test_compression_is_worth_it(self):
        argument = arguments.CompressedAmpList(
            [("ip", amp.Unicode()), ("mac", amp.Unicode())]
        )
        # Create 3500 leases. We can get up to ~3750 and still satisfy the
        # post-conditions, but the randomness means we can't be sure about
        # test stability that close to the limit.
        leases = [
            {
                "ip": factory.make_ipv4_address(),
                "mac": factory.make_mac_address(),
            }
            for _ in range(3500)
        ]
        encoded_compressed = argument.toStringProto(leases, proto=None)
        encoded_uncompressed = zlib.decompress(encoded_compressed)
        # The encoded leases compress to less than half the size of the
        # uncompressed leases, and under the AMP message limit of 64k.
        self.expectThat(
            len(encoded_compressed), LessThan(len(encoded_uncompressed) / 2)
        )
        self.expectThat(len(encoded_compressed), LessThan(2 ** 16)) 
开发者ID:maas,项目名称:maas,代码行数:24,代码来源:test_arguments.py

示例2: test_serializeUnicodeKeyRaises

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Unicode [as 别名]
def test_serializeUnicodeKeyRaises(self):
        """
        Verify that TypeError is raised when trying to serialize Unicode keys.
        """
        a = amp.AmpBox(**{u'key': 'value'})
        self.assertRaises(TypeError, a.serialize) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:test_amp.py

示例3: test_serializeUnicodeValueRaises

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Unicode [as 别名]
def test_serializeUnicodeValueRaises(self):
        """
        Verify that TypeError is raised when trying to serialize Unicode
        values.
        """
        a = amp.AmpBox(key=u'value')
        self.assertRaises(TypeError, a.serialize) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_amp.py

示例4: test_round_trip

# 需要导入模块: from twisted.protocols import amp [as 别名]
# 或者: from twisted.protocols.amp import Unicode [as 别名]
def test_round_trip(self):
        argument = arguments.AmpList([(b"thing", amp.Unicode())])
        example = [{"thing": factory.make_name("thing")}]
        encoded = argument.toStringProto(example, proto=None)
        self.assertThat(encoded, IsInstance(bytes))
        decoded = argument.fromStringProto(encoded, proto=None)
        self.assertEqual(example, decoded) 
开发者ID:maas,项目名称:maas,代码行数:9,代码来源:test_arguments.py


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