def __init__(self, address, strict=True):

        """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.0.2/0.0.0.255'
              are all functionally the same in IPv4. Similarly,
              '192.0.2.1'
              '192.0.2.1/255.255.255.255'
              '192.0.2.1/32'
              are also functionaly equivalent. That is to say, failing to
              provide a subnetmask will create an object with a mask of /32.

              If the mask (portion after the / in the argument) is given in
              dotted quad form, it is treated as a netmask if it starts with a
              non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
              starts with a zero field (e.g. 0.255.255.255 == /8), with the
              single exception of an all-zero mask which is treated as a
              netmask == /0. If no mask is given, a default of /32 is used.

              Additionally, an integer can be passed, so
              IPv4Network('192.0.2.1') == IPv4Network(3221225985)
              or, more generally
              IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
                IPv4Interface('192.0.2.1')

        Raises:
            AddressValueError: If ipaddress isn't a valid IPv4 address.
            NetmaskValueError: If the netmask isn't valid for
              an IPv4 address.
            ValueError: If strict is True and a network address is not
              supplied.

        """

        _BaseV4.__init__(self, address)
        _BaseNetwork.__init__(self, address)

        # Constructing from a packed address
        if isinstance(address, bytes):
            self.network_address = IPv4Address(address)
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv4Address(self._ALL_ONES)
            #fixme: address/network test here
            return

        # Efficient constructor from integer.
        if isinstance(address, _compat_int_types):
            self.network_address = IPv4Address(address)
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv4Address(self._ALL_ONES)
            #fixme: address/network test here.
            return

        # Assume input argument to be string or any object representation
        # which converts into a formatted IP prefix string.
        addr = _split_optional_netmask(address)
        self.network_address = IPv4Address(self._ip_int_from_string(addr[0]))

        if len(addr) == 2:
            mask = addr[1].split('.')

            if len(mask) == 4:
                # We have dotted decimal netmask.
                if self._is_valid_netmask(addr[1]):
                    self.netmask = IPv4Address(self._ip_int_from_string(
                                               addr[1]))
                elif self._is_hostmask(addr[1]):
                    self.netmask = IPv4Address(
                        self._ip_int_from_string(addr[1]) ^ self._ALL_ONES)
                else:
                    raise NetmaskValueError('%r is not a valid netmask'
                                            % addr[1])

                self._prefixlen = self._prefix_from_ip_int(int(self.netmask))
            else:
                # We have a netmask in prefix length form.
                if not self._is_valid_netmask(addr[1]):
                    raise NetmaskValueError('%r is not a valid netmask'
                                            % addr[1])
                self._prefixlen = int(addr[1])
                self.netmask = IPv4Address(self._ip_int_from_prefix(
                    self._prefixlen))
        else:
            self._prefixlen = self._max_prefixlen
            self.netmask = IPv4Address(self._ip_int_from_prefix(
                self._prefixlen))

        if strict:
            if (IPv4Address(int(self.network_address) & int(self.netmask)) !=
                    self.network_address):
                raise ValueError('%s has host bits set' % self)
        self.network_address = IPv4Address(int(self.network_address) &
                                           int(self.netmask))

        if self._prefixlen == (self._max_prefixlen - 1):
            self.hosts = self.__iter__
def __init__ ( self , address , strict = True ) : _BaseV4 . __init__ ( self , address ) _BaseNetwork . __init__ ( self , address ) if isinstance ( address , bytes ) : self . network_address = IPv4Address ( address ) self . _prefixlen = self . _max_prefixlen self . netmask = IPv4Address ( self . _ALL_ONES ) return if isinstance ( address , _compat_int_types ) : self . network_address = IPv4Address ( address ) self . _prefixlen = self . _max_prefixlen self . netmask = IPv4Address ( self . _ALL_ONES ) return addr = _split_optional_netmask ( address ) self . network_address = IPv4Address ( self . _ip_int_from_string ( addr [ 0 ] ) ) if len ( addr ) == 2 : mask = addr [ 1 ] . split ( '.' ) if len ( mask ) == 4 : if self . _is_valid_netmask ( addr [ 1 ] ) : self . netmask = IPv4Address ( self . _ip_int_from_string ( addr [ 1 ] ) ) elif self . _is_hostmask ( addr [ 1 ] ) : self . netmask = IPv4Address ( self . _ip_int_from_string ( addr [ 1 ] ) ^ self . _ALL_ONES ) else : raise NetmaskValueError ( '%r is not a valid netmask' % addr [ 1 ] ) self . _prefixlen = self . _prefix_from_ip_int ( int ( self . netmask ) ) else : if not self . _is_valid_netmask ( addr [ 1 ] ) : raise NetmaskValueError ( '%r is not a valid netmask' % addr [ 1 ] ) self . _prefixlen = int ( addr [ 1 ] ) self . netmask = IPv4Address ( self . _ip_int_from_prefix ( self . _prefixlen ) ) else : self . _prefixlen = self . _max_prefixlen self . netmask = IPv4Address ( self . _ip_int_from_prefix ( self . _prefixlen ) ) if strict : if ( IPv4Address ( int ( self . network_address ) & int ( self . netmask ) ) != self . network_address ) : raise ValueError ( '%s has host bits set' % self ) self . network_address = IPv4Address ( int ( self . network_address ) & int ( self . netmask ) ) if self . _prefixlen == ( self . _max_prefixlen - 1 ) : self . hosts = self . __iter__
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.0.2/0.0.0.255'
              are all functionally the same in IPv4. Similarly,
              '192.0.2.1'
              '192.0.2.1/255.255.255.255'
              '192.0.2.1/32'
              are also functionaly equivalent. That is to say, failing to
              provide a subnetmask will create an object with a mask of /32.

              If the mask (portion after the / in the argument) is given in
              dotted quad form, it is treated as a netmask if it starts with a
              non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it
              starts with a zero field (e.g. 0.255.255.255 == /8), with the
              single exception of an all-zero mask which is treated as a
              netmask == /0. If no mask is given, a default of /32 is used.

              Additionally, an integer can be passed, so
              IPv4Network('192.0.2.1') == IPv4Network(3221225985)
              or, more generally
              IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==
                IPv4Interface('192.0.2.1')

        Raises:
            AddressValueError: If ipaddress isn't a valid IPv4 address.
            NetmaskValueError: If the netmask isn't valid for
              an IPv4 address.
            ValueError: If strict is True and a network address is not
              supplied.