diff options
author | David Moss <drkjam@gmail.com> | 2016-09-16 23:52:19 +0100 |
---|---|---|
committer | David Moss <drkjam@gmail.com> | 2016-09-16 23:52:19 +0100 |
commit | 593a01563d186cddd71e872a7134abcf9c426ce3 (patch) | |
tree | 2f1416a26b0be4bb880fd1f65a3736633ff5357e | |
parent | 212953fdc25cbdcbe36100b2de778b004d6d9b54 (diff) | |
parent | d3a0a763f9a7b4fd77d808de268c7baa11e6dee8 (diff) | |
download | netaddr-593a01563d186cddd71e872a7134abcf9c426ce3.tar.gz |
Merge branch 'nnathan-fix_netmask_bits' into rel-0.7.x
-rw-r--r-- | netaddr/ip/__init__.py | 5 | ||||
-rw-r--r-- | netaddr/tests/ip/test_ip_v4.py | 1 | ||||
-rw-r--r-- | netaddr/tests/ip/test_ip_v6.py | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py index ff716e5..8c52948 100644 --- a/netaddr/ip/__init__.py +++ b/netaddr/ip/__init__.py @@ -348,6 +348,11 @@ class IPAddress(BaseIP): if not self.is_netmask(): return self._module.width + # the '0' address (e.g. 0.0.0.0 or 0000::) is a valid netmask with + # no bits set. + if self._value == 0: + return 0 + i_val = self._value numbits = 0 diff --git a/netaddr/tests/ip/test_ip_v4.py b/netaddr/tests/ip/test_ip_v4.py index 85fcf6a..fe1ae38 100644 --- a/netaddr/tests/ip/test_ip_v4.py +++ b/netaddr/tests/ip/test_ip_v4.py @@ -403,6 +403,7 @@ def test_ipaddress_netmask_v4(): assert IPAddress('1.1.1.1').netmask_bits() == 32 assert IPAddress('255.255.255.254').netmask_bits() == 31 assert IPAddress('255.255.255.0').netmask_bits() == 24 + assert IPAddress('0.0.0.0').netmask_bits() == 0 def test_ipaddress_hex_format(): diff --git a/netaddr/tests/ip/test_ip_v6.py b/netaddr/tests/ip/test_ip_v6.py index fb19f19..e8fb2ad 100644 --- a/netaddr/tests/ip/test_ip_v6.py +++ b/netaddr/tests/ip/test_ip_v6.py @@ -84,7 +84,7 @@ def test_ipnetwork_constructor_v6(): def test_ipaddress_netmask_v6(): - assert IPAddress('::').netmask_bits() == 128 + assert IPAddress('::').netmask_bits() == 0 def test_objects_use_slots(): |