def _RemoveV4Ending(addr_string):
  """Replace v4 endings with v6 equivalents."""

  match = V4_ENDING.match(addr_string)
  if match:
    ipv4_addr = ".".join(match.groups()[1:])
    try:
      socket.inet_aton(ipv4_addr)
    except (socket.error, __HOLE__):
      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
dataset/ETHPy150Open google/grr/grr/lib/ipv6_utils.py/_RemoveV4Ending