Instantiate a new IPv6 Network object. Args: 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::'
(self, address, strict=True)
| 2292 | _address_class = IPv6Address |
| 2293 | |
| 2294 | def __init__(self, address, strict=True): |
| 2295 | """Instantiate a new IPv6 Network object. |
| 2296 | |
| 2297 | Args: |
| 2298 | address: A string or integer representing the IPv6 network or the |
| 2299 | IP and prefix/netmask. |
| 2300 | '2001:db8::/128' |
| 2301 | '2001:db8:0000:0000:0000:0000:0000:0000/128' |
| 2302 | '2001:db8::' |
| 2303 | are all functionally the same in IPv6. That is to say, |
| 2304 | failing to provide a subnetmask will create an object with |
| 2305 | a mask of /128. |
| 2306 | |
| 2307 | Additionally, an integer can be passed, so |
| 2308 | IPv6Network('2001:db8::') == |
| 2309 | IPv6Network(42540766411282592856903984951653826560) |
| 2310 | or, more generally |
| 2311 | IPv6Network(int(IPv6Network('2001:db8::'))) == |
| 2312 | IPv6Network('2001:db8::') |
| 2313 | |
| 2314 | strict: A boolean. If true, ensure that we have been passed |
| 2315 | A true network address, eg, 2001:db8::1000/124 and not an |
| 2316 | IP address on a network, eg, 2001:db8::1/124. |
| 2317 | |
| 2318 | Raises: |
| 2319 | AddressValueError: If address isn't a valid IPv6 address. |
| 2320 | NetmaskValueError: If the netmask isn't valid for |
| 2321 | an IPv6 address. |
| 2322 | ValueError: If strict was True and a network address was not |
| 2323 | supplied. |
| 2324 | """ |
| 2325 | addr, mask = self._split_addr_prefix(address) |
| 2326 | |
| 2327 | self.network_address = IPv6Address(addr) |
| 2328 | self.netmask, self._prefixlen = self._make_netmask(mask) |
| 2329 | packed = int(self.network_address) |
| 2330 | if packed & int(self.netmask) != packed: |
| 2331 | if strict: |
| 2332 | raise ValueError('%s has host bits set' % self) |
| 2333 | else: |
| 2334 | self.network_address = IPv6Address(packed & |
| 2335 | int(self.netmask)) |
| 2336 | |
| 2337 | if self._prefixlen == (self.max_prefixlen - 1): |
| 2338 | self.hosts = self.__iter__ |
| 2339 | elif self._prefixlen == self.max_prefixlen: |
| 2340 | self.hosts = lambda: iter((IPv6Address(addr),)) |
| 2341 | |
| 2342 | def hosts(self): |
| 2343 | """Generate Iterator over usable hosts in a network. |
nothing calls this directly
no test coverage detected