If the version is not 4 or 6.
"""
- if not (isinstance(first, _BaseAddress) and isinstance(last, _BaseAddress)):
+ if (not (isinstance(first, _BaseAddress) and
+ isinstance(last, _BaseAddress))):
raise TypeError('first and last must be IP addresses, not networks')
if first.version != last.version:
raise TypeError("%s and %s are not of the same version" % (
if first > last:
raise ValueError('last IP address must be greater than first')
- networks = []
-
if first.version == 4:
ip = IPv4Network
elif first.version == 6:
prefix = _get_prefix_length(first_int, current, ip_bits)
net = ip('%s/%d' % (str(first), prefix))
yield net
- #networks.append(net)
if current == ip._ALL_ONES:
break
first_int = current + 1
return '%s(%r)' % (self.__class__.__name__, str(self))
def __str__(self):
- return '%s' % self._string_from_ip_int(self._ip)
+ return str(self._string_from_ip_int(self._ip))
def __hash__(self):
return hash(hex(int(self._ip)))
return not eq
def __str__(self):
- return '%s/%s' % (str(self.ip),
- str(self._prefixlen))
+ return '%s/%s' % (self.ip, self._prefixlen)
def __hash__(self):
return hash(int(self.network_address) ^ int(self.netmask))
if not (other.network_address >= self.network_address and
other.broadcast_address <= self.broadcast_address):
- raise ValueError('%s not contained in %s' % (str(other), str(self)))
-
+ raise ValueError('%s not contained in %s' % (other, self))
if other == self:
raise StopIteration
- ret_addrs = []
-
# Make sure we're comparing the network of other.
other = ip_network('%s/%s' % (str(other.network_address),
str(other.prefixlen)),
An IPv4 network object.
Raises:
- ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have a
- negative prefix length.
+ ValueError: If self.prefixlen - prefixlen_diff < 0. I.e., you have
+ a negative prefix length.
OR
If prefixlen_diff and new_prefix are both set or new_prefix is a
larger number than the current prefix (larger number means a
raise ValueError('cannot set prefixlen_diff and new_prefix')
prefixlen_diff = self._prefixlen - new_prefix
-
if self.prefixlen - prefixlen_diff < 0:
raise ValueError(
'current prefixlen is %d, cannot have a prefixlen_diff of %d' %
self.netmask = self.network.netmask
self.hostmask = self.network.hostmask
-
def __str__(self):
return '%s/%d' % (self._string_from_ip_int(self._ip),
self.network.prefixlen)
return True
return False
-
@property
def prefixlen(self):
return self._prefixlen
def with_netmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
self.netmask)
+
@property
def with_hostmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
if parts_skipped < 1:
raise AddressValueError(ip_str)
else:
- # Otherwise, allocate the entire address to parts_hi. The endpoints
- # could still be empty, but _parse_hextet() will check for that.
+ # Otherwise, allocate the entire address to parts_hi. The
+ # endpoints could still be empty, but _parse_hextet() will check
+ # for that.
if len(parts) != self._HEXTET_COUNT:
raise AddressValueError(ip_str)
parts_hi = len(parts)
The hextet as an integer.
Raises:
- ValueError: if the input isn't strictly a hex number from [0..FFFF].
+ ValueError: if the input isn't strictly a hex number from
+ [0..FFFF].
"""
# Whitelist the characters, since int() allows a lot of bizarre stuff.
return (self.network_address in private_network and
self.broadcast_address in private_network)
-
@property
def ipv4_mapped(self):
"""Return the IPv4 mapped address.
self._prefixlen = self.network._prefixlen
self.hostmask = self.network.hostmask
-
def __str__(self):
return '%s/%d' % (self._string_from_ip_int(self._ip),
self.network.prefixlen)
@property
def prefixlen(self):
return self._prefixlen
+
@property
def ip(self):
return IPv6Address(self._ip)
@property
def with_netmask(self):
return self.with_prefixlen
+
@property
def with_hostmask(self):
return '%s/%s' % (self._string_from_ip_int(self._ip),
"""Instantiate a new IPv6 Network object.
Args:
- address: A string or integer representing the IPv6 network or the IP
- and prefix/netmask.
+ address: A string or integer representing the IPv6 network or the
+ IP and prefix/netmask.
'2001:db8::/128'
'2001:db8:0000:0000:0000:0000:0000:0000/128'
'2001:db8::'
return False
return 0 <= prefixlen <= self._max_prefixlen
- @property
- def with_netmask(self):
- return self.with_prefixlen
-
@property
def with_prefixlen(self):
return '%s/%d' % (str(self.network_address), self._prefixlen)