summaryrefslogtreecommitdiffstats
path: root/Lib/ipaddress.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-06-17 06:33:00 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-06-17 06:33:00 (GMT)
commitd972265df81bce483e6cad87d1cf4254f508e5c0 (patch)
treea386d7f25251cd554b1d4ec0c5fc817cce1f8a55 /Lib/ipaddress.py
parent5b0dac12b81f4af01506fb61184515147bee7a09 (diff)
downloadcpython-d972265df81bce483e6cad87d1cf4254f508e5c0.zip
cpython-d972265df81bce483e6cad87d1cf4254f508e5c0.tar.gz
cpython-d972265df81bce483e6cad87d1cf4254f508e5c0.tar.bz2
Improve an internal ipaddress test, add a comment explaining why treating networks as containers of interfaces rather than addresses would prove confusing
Diffstat (limited to 'Lib/ipaddress.py')
-rw-r--r--Lib/ipaddress.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/Lib/ipaddress.py b/Lib/ipaddress.py
index abbdcf8..05ea453 100644
--- a/Lib/ipaddress.py
+++ b/Lib/ipaddress.py
@@ -416,6 +416,11 @@ class _IPAddressBase:
"""Return the shorthand version of the IP address as a string."""
return str(self)
+ @property
+ def version(self):
+ msg = '%200s has no version specified' % (type(self),)
+ raise NotImplementedError(msg)
+
def _ip_int_from_prefix(self, prefixlen=None):
"""Turn the prefix length netmask into a int for comparison.
@@ -555,10 +560,6 @@ class _BaseAddress(_IPAddressBase):
def _get_address_key(self):
return (self._version, self)
- @property
- def version(self):
- raise NotImplementedError('BaseIP has no version')
-
class _BaseNetwork(_IPAddressBase):
@@ -727,12 +728,12 @@ class _BaseNetwork(_IPAddressBase):
return int(self.broadcast_address) - int(self.network_address) + 1
@property
- def version(self):
- raise NotImplementedError('BaseNet has no version')
-
- @property
def _address_class(self):
- raise NotImplementedError('BaseNet has no associated address class')
+ # Returning bare address objects (rather than interfaces) allows for
+ # more consistent behaviour across the network address, broadcast
+ # address and individual host addresses.
+ msg = '%200s has no associated address class' % (type(self),)
+ raise NotImplementedError(msg)
@property
def prefixlen(self):
@@ -1333,7 +1334,6 @@ class IPv4Network(_BaseV4, _BaseNetwork):
"""
# Class to use when creating address objects
- # TODO (ncoghlan): Investigate using IPv4Interface instead
_address_class = IPv4Address
def __init__(self, address, strict=True):
@@ -1945,7 +1945,6 @@ class IPv6Network(_BaseV6, _BaseNetwork):
"""
# Class to use when creating address objects
- # TODO (ncoghlan): Investigate using IPv6Interface instead
_address_class = IPv6Address
def __init__(self, address, strict=True):