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


Python forms.GenericIPAddressField类代码示例

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


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

示例1: test_generic_ipaddress_as_ipv4_only

 def test_generic_ipaddress_as_ipv4_only(self):
     f = GenericIPAddressField(protocol="IPv4")
     self.assertFormErrors(["This field is required."], f.clean, "")
     self.assertFormErrors(["This field is required."], f.clean, None)
     self.assertEqual(f.clean(" 127.0.0.1 "), "127.0.0.1")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "foo")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "127.0.0.")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "1.2.3.4.5")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "256.125.1.5")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "fe80::223:6cff:fe8a:2e8a")
     self.assertFormErrors(["Enter a valid IPv4 address."], f.clean, "2a02::223:6cff:fe8a:2e8a")
开发者ID:aplanas,项目名称:django,代码行数:11,代码来源:test_extra.py

示例2: test_generic_ipaddress_as_ipv4_only

 def test_generic_ipaddress_as_ipv4_only(self):
     f = GenericIPAddressField(protocol="IPv4")
     self.assertFormErrors(['This field is required.'], f.clean, '')
     self.assertFormErrors(['This field is required.'], f.clean, None)
     self.assertEqual(f.clean(' 127.0.0.1 '), '127.0.0.1')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, 'foo')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '127.0.0.')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, 'fe80::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '2a02::223:6cff:fe8a:2e8a')
开发者ID:AvaniLodaya,项目名称:django,代码行数:11,代码来源:test_extra.py

示例3: test_generic_ipaddress_as_generic_not_required

 def test_generic_ipaddress_as_generic_not_required(self):
     f = GenericIPAddressField(required=False)
     self.assertEqual(f.clean(''), '')
     self.assertEqual(f.clean(None), '')
     self.assertEqual(f.clean('127.0.0.1'), '127.0.0.1')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, 'foo')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '127.0.0.')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '1.2.3.4.5')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '256.125.1.5')
     self.assertEqual(f.clean(' fe80::223:6cff:fe8a:2e8a '), 'fe80::223:6cff:fe8a:2e8a')
     self.assertEqual(f.clean(' 2a02::223:6cff:fe8a:2e8a '), '2a02::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '12345:2:3:4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3::4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, 'foo::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3:4:5:6:7:8')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1:2')
开发者ID:AvaniLodaya,项目名称:django,代码行数:16,代码来源:test_extra.py

示例4: test_generic_ipaddress_as_ipv6_only

 def test_generic_ipaddress_as_ipv6_only(self):
     f = GenericIPAddressField(protocol="IPv6")
     self.assertFormErrors(['This field is required.'], f.clean, '')
     self.assertFormErrors(['This field is required.'], f.clean, None)
     self.assertFormErrors(['Enter a valid IPv6 address.'], f.clean, '127.0.0.1')
     self.assertFormErrors(['Enter a valid IPv6 address.'], f.clean, 'foo')
     self.assertFormErrors(['Enter a valid IPv6 address.'], f.clean, '127.0.0.')
     self.assertFormErrors(['Enter a valid IPv6 address.'], f.clean, '1.2.3.4.5')
     self.assertFormErrors(['Enter a valid IPv6 address.'], f.clean, '256.125.1.5')
     self.assertEqual(f.clean(' fe80::223:6cff:fe8a:2e8a '), 'fe80::223:6cff:fe8a:2e8a')
     self.assertEqual(f.clean(' 2a02::223:6cff:fe8a:2e8a '), '2a02::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '12345:2:3:4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3::4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, 'foo::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3:4:5:6:7:8')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1:2')
开发者ID:AvaniLodaya,项目名称:django,代码行数:16,代码来源:test_extra.py

示例5: test_generic_ipaddress_as_generic_not_required

 def test_generic_ipaddress_as_generic_not_required(self):
     f = GenericIPAddressField(required=False)
     self.assertEqual(f.clean(""), "")
     self.assertEqual(f.clean(None), "")
     self.assertEqual(f.clean("127.0.0.1"), "127.0.0.1")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "foo")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "127.0.0.")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "1.2.3.4.5")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "256.125.1.5")
     self.assertEqual(f.clean(" fe80::223:6cff:fe8a:2e8a "), "fe80::223:6cff:fe8a:2e8a")
     self.assertEqual(f.clean(" 2a02::223:6cff:fe8a:2e8a "), "2a02::223:6cff:fe8a:2e8a")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "12345:2:3:4")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1::2:3::4")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "foo::223:6cff:fe8a:2e8a")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1::2:3:4:5:6:7:8")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1:2")
开发者ID:aplanas,项目名称:django,代码行数:16,代码来源:test_extra.py

示例6: test_generic_ipaddress_as_generic

 def test_generic_ipaddress_as_generic(self):
     # The edge cases of the IPv6 validation code are not deeply tested
     # here, they are covered in the tests for django.utils.ipv6
     f = GenericIPAddressField()
     self.assertFormErrors(['This field is required.'], f.clean, '')
     self.assertFormErrors(['This field is required.'], f.clean, None)
     self.assertEqual(f.clean(' 127.0.0.1 '), '127.0.0.1')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, 'foo')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '127.0.0.')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '1.2.3.4.5')
     self.assertFormErrors(['Enter a valid IPv4 or IPv6 address.'], f.clean, '256.125.1.5')
     self.assertEqual(f.clean(' fe80::223:6cff:fe8a:2e8a '), 'fe80::223:6cff:fe8a:2e8a')
     self.assertEqual(f.clean(' 2a02::223:6cff:fe8a:2e8a '), '2a02::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '12345:2:3:4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3::4')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, 'foo::223:6cff:fe8a:2e8a')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1::2:3:4:5:6:7:8')
     self.assertFormErrors(['This is not a valid IPv6 address.'], f.clean, '1:2')
开发者ID:AvaniLodaya,项目名称:django,代码行数:18,代码来源:test_extra.py

示例7: test_generic_ipaddress_as_generic

 def test_generic_ipaddress_as_generic(self):
     # The edge cases of the IPv6 validation code are not deeply tested
     # here, they are covered in the tests for django.utils.ipv6
     f = GenericIPAddressField()
     self.assertFormErrors(["This field is required."], f.clean, "")
     self.assertFormErrors(["This field is required."], f.clean, None)
     self.assertEqual(f.clean(" 127.0.0.1 "), "127.0.0.1")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "foo")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "127.0.0.")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "1.2.3.4.5")
     self.assertFormErrors(["Enter a valid IPv4 or IPv6 address."], f.clean, "256.125.1.5")
     self.assertEqual(f.clean(" fe80::223:6cff:fe8a:2e8a "), "fe80::223:6cff:fe8a:2e8a")
     self.assertEqual(f.clean(" 2a02::223:6cff:fe8a:2e8a "), "2a02::223:6cff:fe8a:2e8a")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "12345:2:3:4")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1::2:3::4")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "foo::223:6cff:fe8a:2e8a")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1::2:3:4:5:6:7:8")
     self.assertFormErrors(["This is not a valid IPv6 address."], f.clean, "1:2")
开发者ID:aplanas,项目名称:django,代码行数:18,代码来源:test_extra.py

示例8: test_generic_ipaddress_normalization

    def test_generic_ipaddress_normalization(self):
        # Test the normalising code
        f = GenericIPAddressField()
        self.assertEqual(f.clean(' ::ffff:0a0a:0a0a  '), '::ffff:10.10.10.10')
        self.assertEqual(f.clean(' ::ffff:10.10.10.10  '), '::ffff:10.10.10.10')
        self.assertEqual(f.clean(' 2001:000:a:0000:0:fe:fe:beef  '), '2001:0:a::fe:fe:beef')
        self.assertEqual(f.clean(' 2001::a:0000:0:fe:fe:beef  '), '2001:0:a::fe:fe:beef')

        f = GenericIPAddressField(unpack_ipv4=True)
        self.assertEqual(f.clean(' ::ffff:0a0a:0a0a'), '10.10.10.10')
开发者ID:AvaniLodaya,项目名称:django,代码行数:10,代码来源:test_extra.py

示例9: test_generic_ipaddress_as_ipv6_only

 def test_generic_ipaddress_as_ipv6_only(self):
     f = GenericIPAddressField(protocol="IPv6")
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean('')
     with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
         f.clean(None)
     with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv6 address.'"):
         f.clean('127.0.0.1')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv6 address.'"):
         f.clean('foo')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv6 address.'"):
         f.clean('127.0.0.')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv6 address.'"):
         f.clean('1.2.3.4.5')
     with self.assertRaisesMessage(ValidationError, "'Enter a valid IPv6 address.'"):
         f.clean('256.125.1.5')
     self.assertEqual(f.clean(' fe80::223:6cff:fe8a:2e8a '), 'fe80::223:6cff:fe8a:2e8a')
     self.assertEqual(f.clean(' 2a02::223:6cff:fe8a:2e8a '), '2a02::223:6cff:fe8a:2e8a')
     with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
         f.clean('12345:2:3:4')
     with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
         f.clean('1::2:3::4')
     with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
         f.clean('foo::223:6cff:fe8a:2e8a')
     with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
         f.clean('1::2:3:4:5:6:7:8')
     with self.assertRaisesMessage(ValidationError, "'This is not a valid IPv6 address.'"):
         f.clean('1:2')
开发者ID:2015E8007361074,项目名称:django,代码行数:28,代码来源:test_genericipaddressfield.py


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