MCPcopy Index your code
hub / github.com/RustPython/RustPython / __init__

Method __init__

Lib/ipaddress.py:1498–1548  ·  view source on GitHub ↗

Instantiate a new IPv4 network object. Args: address: A string or integer representing the IP [& network]. '192.0.2.0/24' '192.0.2.0/255.255.255.0' '192.0.2.0/0.0.0.255' are all functionally the same in IPv4. Similarly,

(self, address, strict=True)

Source from the content-addressed store, hash-verified

1496 _address_class = IPv4Address
1497
1498 def __init__(self, address, strict=True):
1499 """Instantiate a new IPv4 network object.
1500
1501 Args:
1502 address: A string or integer representing the IP [& network].
1503 '192.0.2.0/24'
1504 '192.0.2.0/255.255.255.0'
1505 '192.0.2.0/0.0.0.255'
1506 are all functionally the same in IPv4. Similarly,
1507 '192.0.2.1'
1508 '192.0.2.1/255.255.255.255'
1509 '192.0.2.1/32'
1510 are also functionally equivalent. That is to say, failing to
1511 provide a subnetmask will create an object with a mask of /32.
1512
1513 If the mask (portion after the / in the argument) is given in
1514 dotted quad form, it is treated as a netmask if it starts with a
1515 non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
1516 starts with a zero field (e.g. 0.255.255.255 == /8), with the
1517 single exception of an all-zero mask which is treated as a
1518 netmask == /0. If no mask is given, a default of /32 is used.
1519
1520 Additionally, an integer can be passed, so
1521 IPv4Network('192.0.2.1') == IPv4Network(3221225985)
1522 or, more generally
1523 IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
1524 IPv4Interface('192.0.2.1')
1525
1526 Raises:
1527 AddressValueError: If ipaddress isn't a valid IPv4 address.
1528 NetmaskValueError: If the netmask isn't valid for
1529 an IPv4 address.
1530 ValueError: If strict is True and a network address is not
1531 supplied.
1532 """
1533 addr, mask = self._split_addr_prefix(address)
1534
1535 self.network_address = IPv4Address(addr)
1536 self.netmask, self._prefixlen = self._make_netmask(mask)
1537 packed = int(self.network_address)
1538 if packed & int(self.netmask) != packed:
1539 if strict:
1540 raise ValueError('%s has host bits set' % self)
1541 else:
1542 self.network_address = IPv4Address(packed &
1543 int(self.netmask))
1544
1545 if self._prefixlen == (self.max_prefixlen - 1):
1546 self.hosts = self.__iter__
1547 elif self._prefixlen == (self.max_prefixlen):
1548 self.hosts = lambda: iter((IPv4Address(addr),))
1549
1550 @property
1551 @functools.lru_cache()

Callers

nothing calls this directly

Calls 4

IPv4AddressClass · 0.85
iterFunction · 0.85
_split_addr_prefixMethod · 0.80
_make_netmaskMethod · 0.45

Tested by

no test coverage detected