#NEWLINE# def __init__( self , addr , version = None , flags = 0 ) : #NEWLINE# #INDENT# '\n        Constructor.\n\n        :param addr: an IPv4 or IPv6 address which may be represented in an\n            accepted string format, as an unsigned integer or as another\n            IPAddress object (copy construction).\n\n        :param version: (optional) optimizes version detection if specified\n            and distinguishes between IPv4 and IPv6 for addresses with an\n            equivalent integer value.\n\n        :param flags: (optional) decides which rules are applied to the\n            interpretation of the addr value. Supported constants are\n            INET_PTON and ZEROFILL. See the netaddr.core docs for further\n            details.\n\n        ' #NEWLINE# super ( IPAddress , self ) . __init__ ( ) #NEWLINE# if isinstance ( addr , BaseIP ) : #NEWLINE# #INDENT# if ( ( version is not None ) and ( version != addr . _module . version ) ) : #NEWLINE# #INDENT# raise ValueError ( 'cannot switch IP versions using copy constructor!' ) #NEWLINE# #UNINDENT# self . _value = addr . _value #NEWLINE# self . _module = addr . _module #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( version is not None ) : #NEWLINE# #INDENT# if ( version == 4 ) : #NEWLINE# #INDENT# self . _module = _ipv4 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( version == 6 ) : #NEWLINE# #INDENT# self . _module = _ipv6 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( '%r is an invalid IP version!' % version ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( _is_str ( addr ) and ( '/' in addr ) ) : #NEWLINE# #INDENT# raise ValueError ( ( '%s() does not support netmasks or subnet prefixes! See documentation for details.' % self . __class__ . __name__ ) ) #NEWLINE# #UNINDENT# if ( self . _module is None ) : #NEWLINE# #INDENT# if isinstance ( addr , _int_type ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( 0 <= int ( addr ) <= _ipv4 . max_int ) : #NEWLINE# #INDENT# self . _value = int ( addr ) #NEWLINE# self . _module = _ipv4 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( _ipv4 . max_int < int ( addr ) <= _ipv6 . max_int ) : #NEWLINE# #INDENT# self . _value = int ( addr ) #NEWLINE# self . _module = _ipv6 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except ValueError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for module in ( _ipv4 , _ipv6 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . _value = module . str_to_int ( self , flags ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _module = module #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( self . _module is None ) : #NEWLINE# #INDENT# raise AddrFormatError ( ( 'failed to detect a valid IP address from %r' % addr ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if _is_str ( addr ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# self . _value = self . _module . str_to_int ( addr , flags ) #NEWLINE# #UNINDENT# except AddrFormatError : #NEWLINE# #INDENT# raise AddrFormatError ( ( 'base address %r is not IPv%d' % ( addr , self . _module . version ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( 0 <= int ( addr ) <= self . _module . max_int ) : #NEWLINE# #INDENT# self . _value = int ( addr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise AddrFormatError ( ( 'bad address format: %r' % addr ) )