當前位置: 首頁>>代碼示例>>Python>>正文


Python Provider.ipv4_private方法代碼示例

本文整理匯總了Python中faker.providers.misc.Provider.ipv4_private方法的典型用法代碼示例。如果您正苦於以下問題:Python Provider.ipv4_private方法的具體用法?Python Provider.ipv4_private怎麽用?Python Provider.ipv4_private使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在faker.providers.misc.Provider的用法示例。


在下文中一共展示了Provider.ipv4_private方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ipv4_private

# 需要導入模塊: from faker.providers.misc import Provider [as 別名]
# 或者: from faker.providers.misc.Provider import ipv4_private [as 別名]
    def test_ipv4_private(self):
        from faker.providers.internet import Provider
        provider = Provider(self.generator)

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

        for _ in range(99):
            address = provider.ipv4_private(network=True)
            address = six.text_type(address)
            assert len(address) >= 9
            assert len(address) <= 18
            assert ip_network(address)[0].is_private
            assert (
                re.compile(r'^(\d{1,3}\.){3}\d{1,3}/\d{1,2}$').search(address))
開發者ID:joke2k,項目名稱:faker,代碼行數:23,代碼來源:test_factory.py

示例2: test_ipv4_private_class_c

# 需要導入模塊: from faker.providers.misc import Provider [as 別名]
# 或者: from faker.providers.misc.Provider import ipv4_private [as 別名]
    def test_ipv4_private_class_c(self):
        from faker.providers.internet import Provider, _IPv4Constants
        provider = Provider(self.generator)

        class_network = _IPv4Constants._network_classes['c']
        class_min = class_network.network_address
        class_max = class_network.broadcast_address

        for _ in range(99):
            address = provider.ipv4_private(address_class='c')
            address = six.text_type(address)
            assert len(address) >= 7
            assert len(address) <= 15
            assert ip_address(address).is_private
            assert ip_address(address) >= class_min
            assert ip_address(address) <= class_max
開發者ID:joke2k,項目名稱:faker,代碼行數:18,代碼來源:test_factory.py


注:本文中的faker.providers.misc.Provider.ipv4_private方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。