raise ValueError( "Could not import address {0!r}.".format( address ) )
return
+ #------------------------------------------------------
+ def as_str( self ):
+ '''Returns a string with an usable display of the address
+ @return: The address as string
+ @rtype: str
+ '''
+
+ if self.address is None:
+ return None
+
+ def format_byte( byte ):
+ return "{0:02x}".format( byte )
+
+ return_value = '<undef>'
+ if self.type == 'guid':
+ return_value = '0x'
+ for byte in self.address:
+ return_value += "{0:02x}".format( byte )
+ elif self.type == 'mac':
+ return_value = ':'.join( map( format_byte, self.address ) )
+
+ return return_value
+
+ #------------------------------------------------------
+ def as_ipv6hostpart( self ):
+ '''Returns a string with an usable 64-bit host part of an IPv6 address
+ @return: The host part as string
+ @rtype: str
+ '''
+
+ if self.address is None:
+ return None
+
+ pp = pprint.PrettyPrinter( indent = 4, depth = 6, width = 120 )
+
+ return_value = '<undef>'
+ byte_list = []
+ for byte in self.address:
+ byte_list.append( byte )
+ if self.type == 'mac':
+ byte_list.insert( 3, 254 )
+ byte_list.insert( 3, 255 )
+
+ if self.verbose >= 2:
+ self.logger.debug( "Bytelist to display: {0!r}.".format( pp.pformat( byte_list ) ) )
+
+ first_byte = byte_list[0]
+ seventh_bit = ( first_byte & 2 ) >> 1
+ eighth_bit = ( first_byte & 1 )
+ if seventh_bit == 0:
+ seventh_bit = 1
+ else:
+ seventh_bit = 0
+ if self.verbose >= 3:
+ self.logger.debug( "Seventh bit: {0!r}.".format( seventh_bit ) )
+ first_byte &= 252
+ first_byte += ( seventh_bit << 1 ) + eighth_bit
+ if self.verbose >= 3:
+ self.logger.debug( "First byte: {0!r}.".format( first_byte ) )
+ byte_list[0] = first_byte
+
+ nibble_list = []
+ nibble_list.append( ( byte_list[0] << 8 ) + byte_list[1] )
+ nibble_list.append( ( byte_list[2] << 8 ) + byte_list[3] )
+ nibble_list.append( ( byte_list[4] << 8 ) + byte_list[5] )
+ nibble_list.append( ( byte_list[6] << 8 ) + byte_list[7] )
+ if self.verbose >= 2:
+ self.logger.debug( "Nibblelist to display: {0!r}.".format( pp.pformat( nibble_list ) ) )
+
+ def format_nibble( nibble ):
+ return "{0:x}".format( nibble )
+
+ return ':'.join( map( format_nibble, nibble_list ) )
+
+ #------------------------------------------------------
+
# vim: fileencoding=utf-8 filetype=python ts=4 expandtab