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


Python Provider.ipv4_public方法代码示例

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


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

示例1: test_ipv4_public

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import ipv4_public [as 别名]
    def test_ipv4_public(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            address = provider.ipv4_public()
            address = six.text_type(address)
            assert len(address) >= 7
            assert len(address) <= 15
            assert not ip_address(address).is_private, address
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}$').search(address))

        for _ in range(99):
            address = provider.ipv4_public(network=True)
            address = six.text_type(address)
            assert len(address) >= 9
            assert len(address) <= 18
            # Hack around ipaddress module
            # As 192.0.0.0 is net addr of many 192.0.0.0/* nets
            # ipaddress considers them as private
            if ip_network(address).network_address != ip_address('192.0.0.0'):
                assert not ip_network(address)[0].is_private, address
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$').search(address))
开发者ID:joke2k,项目名称:faker,代码行数:27,代码来源:test_factory.py

示例2: test_ipv4_public_class_c

# 需要导入模块: from faker.providers.misc import Provider [as 别名]
# 或者: from faker.providers.misc.Provider import ipv4_public [as 别名]
    def test_ipv4_public_class_c(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

        for _ in range(99):
            address = provider.ipv4_public(address_class='c')
            address = six.text_type(address)
            assert len(address) >= 7
            assert len(address) <= 15
            assert not ip_address(address).is_private, address
开发者ID:joke2k,项目名称:faker,代码行数:12,代码来源:test_factory.py


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