def _RemoveV4Ending(addr_string):
 match = V4_ENDING.match(addr_string)
 if match:
  ipv4_addr = '.'.join(match.groups()[1:])
  try:
   socket.inet_aton(ipv4_addr)
  except (socket.error, ValueError):
   raise socket.error(('Illegal IPv4 extension: %s' % addr_string))
  if (int(match.group(2)) == 0):
   raise socket.error("IPv4 can't start with 0")
  return ('%s:%04x:%04x' % (match.group('v6'), ((int(match.group(2)) * 256) + int(match.group(3))), ((int(match.group(4)) * 256) + int(match.group(5)))))
 return addr_string

def _RemoveV4Ending ( addr_string ) : match = V4_ENDING . match ( addr_string ) if match : ipv4_addr = '.' . join ( match . groups ( ) [ 1 : ] ) try : socket . inet_aton ( ipv4_addr ) except ( socket . error , ValueError ) : raise socket . error ( ( 'Illegal IPv4 extension: %s' % addr_string ) ) if ( int ( match . group ( 2 ) ) == 0 ) : raise socket . error ( "IPv4 can't start with 0" ) return ( '%s:%04x:%04x' % ( match . group ( 'v6' ) , ( ( int ( match . group ( 2 ) ) * 256 ) + int ( match . group ( 3 ) ) ) , ( ( int ( match . group ( 4 ) ) * 256 ) + int ( match . group ( 5 ) ) ) ) ) return addr_string
replace v4 endings with v6 equivalents .