#NEWLINE# def __init__( self , address , strict = True ) : #NEWLINE# #INDENT# "Instantiate a new IPv4 network object.\n\n        Args:\n            address: A string or integer representing the IP [& network].\n              '192.0.2.0/24'\n              '192.0.2.0/255.255.255.0'\n              '192.0.0.2/0.0.0.255'\n              are all functionally the same in IPv4. Similarly,\n              '192.0.2.1'\n              '192.0.2.1/255.255.255.255'\n              '192.0.2.1/32'\n              are also functionaly equivalent. That is to say, failing to\n              provide a subnetmask will create an object with a mask of /32.\n\n              If the mask (portion after the / in the argument) is given in\n              dotted quad form, it is treated as a netmask if it starts with a\n              non-zero field (e.g. /255.0.0.0 == /8) and as a hostmask if it\n              starts with a zero field (e.g. 0.255.255.255 == /8), with the\n              single exception of an all-zero mask which is treated as a\n              netmask == /0. If no mask is given, a default of /32 is used.\n\n              Additionally, an integer can be passed, so\n              IPv4Network('192.0.2.1') == IPv4Network(3221225985)\n              or, more generally\n              IPv4Interface(int(IPv4Interface('192.0.2.1'))) ==\n                IPv4Interface('192.0.2.1')\n\n        Raises:\n            AddressValueError: If ipaddress isn't a valid IPv4 address.\n            NetmaskValueError: If the netmask isn't valid for\n              an IPv4 address.\n            ValueError: If strict is True and a network address is not\n              supplied.\n\n        " #NEWLINE# _BaseV4 . __init__ ( self , address ) #NEWLINE# _BaseNetwork . __init__ ( self , address ) #NEWLINE# if isinstance ( address , bytes ) : #NEWLINE# #INDENT# self . network_address = IPv4Address ( address ) #NEWLINE# self . _prefixlen = self . _max_prefixlen #NEWLINE# self . netmask = IPv4Address ( self . _ALL_ONES ) #NEWLINE# return #NEWLINE# #UNINDENT# if isinstance ( address , int ) : #NEWLINE# #INDENT# self . network_address = IPv4Address ( address ) #NEWLINE# self . _prefixlen = self . _max_prefixlen #NEWLINE# self . netmask = IPv4Address ( self . _ALL_ONES ) #NEWLINE# return #NEWLINE# #UNINDENT# addr = _split_optional_netmask ( address ) #NEWLINE# self . network_address = IPv4Address ( self . _ip_int_from_string ( addr [ 0 ] ) ) #NEWLINE# if ( len ( addr ) == 2 ) : #NEWLINE# #INDENT# mask = addr [ 1 ] . split ( '.' ) #NEWLINE# if ( len ( mask ) == 4 ) : #NEWLINE# #INDENT# if self . _is_valid_netmask ( addr [ 1 ] ) : #NEWLINE# #INDENT# self . netmask = IPv4Address ( self . _ip_int_from_string ( addr [ 1 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if self . _is_hostmask ( addr [ 1 ] ) : #NEWLINE# #INDENT# self . netmask = IPv4Address ( ( self . _ip_int_from_string ( addr [ 1 ] ) ^ self . _ALL_ONES ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise NetmaskValueError ( ( '%r is not a valid netmask' % addr [ 1 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . _prefixlen = self . _prefix_from_ip_int ( int ( self . netmask ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not self . _is_valid_netmask ( addr [ 1 ] ) ) : #NEWLINE# #INDENT# raise NetmaskValueError ( ( '%r is not a valid netmask' % addr [ 1 ] ) ) #NEWLINE# #UNINDENT# self . _prefixlen = int ( addr [ 1 ] ) #NEWLINE# self . netmask = IPv4Address ( self . _ip_int_from_prefix ( addr . _prefixlen ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . _prefixlen = self . _max_prefixlen #NEWLINE# self . netmask = IPv4Address ( self . _ip_int_from_prefix ( self . _prefixlen ) ) #NEWLINE# #UNINDENT# if strict : #NEWLINE# #INDENT# if ( IPv4Address ( ( int ( self . network_address ) & int ( self . netmask ) ) ) != self . network_address ) : #NEWLINE# #INDENT# raise ValueError ( ( '%s has host bits set' % self ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . network_address = IPv4Address ( ( int ( self . network_address ) & int ( self . netmask ) ) ) #NEWLINE# if ( self . _prefixlen == ( self . _max_prefixlen - 1 ) ) : #NEWLINE# #INDENT# self . hosts = self . __iter__