"""The mother class."""
+ __slots__ = ()
+
@property
def exploded(self):
"""Return the longhand version of the IP address as a string."""
used by single IP addresses.
"""
+ __slots__ = ()
+
def __int__(self):
return self._ip
"""
+ __slots__ = ()
+ _version = 4
# Equivalent to 255.255.255.255 or 32 bits of 1's.
_ALL_ONES = (2**IPV4LENGTH) - 1
_DECIMAL_DIGITS = frozenset('0123456789')
# when constructed (see _make_netmask()).
_netmask_cache = {}
- def __init__(self, address):
- self._version = 4
-
def _explode_shorthand_ip_string(self):
return str(self)
"""Represent and manipulate single IPv4 Addresses."""
+ __slots__ = ('_ip', '__weakref__')
+
def __init__(self, address):
"""
AddressValueError: If ipaddress isn't a valid IPv4 address.
"""
- _BaseV4.__init__(self, address)
-
# Efficient constructor from integer.
if isinstance(address, int):
self._check_int_address(address)
supplied.
"""
-
- _BaseV4.__init__(self, address)
_BaseNetwork.__init__(self, address)
# Constructing from a packed address or integer
"""
+ __slots__ = ()
+ _version = 6
_ALL_ONES = (2**IPV6LENGTH) - 1
_HEXTET_COUNT = 8
_HEX_DIGITS = frozenset('0123456789ABCDEFabcdef')
# when constructed (see _make_netmask()).
_netmask_cache = {}
- def __init__(self, address):
- self._version = 6
-
@classmethod
def _make_netmask(cls, arg):
"""Make a (netmask, prefix_len) tuple from the given argument.
"""Represent and manipulate single IPv6 Addresses."""
+ __slots__ = ('_ip', '__weakref__')
+
def __init__(self, address):
"""Instantiate a new IPv6 address object.
AddressValueError: If address isn't a valid IPv6 address.
"""
- _BaseV6.__init__(self, address)
-
# Efficient constructor from integer.
if isinstance(address, int):
self._check_int_address(address)
supplied.
"""
- _BaseV6.__init__(self, address)
_BaseNetwork.__init__(self, address)
# Efficient constructor from integer or packed address
import operator
import pickle
import ipaddress
+import weakref
class BaseTestCase(unittest.TestCase):
def test_pickle(self):
self.pickle_test('192.0.2.1')
+ def test_weakref(self):
+ weakref.ref(self.factory('192.0.2.1'))
+
class AddressTestCase_v6(BaseTestCase, CommonTestMixin_v6):
factory = ipaddress.IPv6Address
def test_pickle(self):
self.pickle_test('2001:db8::')
+ def test_weakref(self):
+ weakref.ref(self.factory('2001:db8::'))
+
class NetmaskTestMixin_v4(CommonTestMixin_v4):
"""Input validation on interfaces and networks is very similar"""