def _ZeroPad(addr_string):
  chunks = addr_string.split(":")
  total_length = len(chunks)
  if total_length > 8:
    raise socket.error("Too many address chunks in %s, expected 8" %
                       addr_string)

  double_colon = False
  addr_array = []
  for chunk in chunks:
    if chunk:
      chunk_len = len(chunk)
      if chunk_len > 4:
        raise socket.error("Chunk must be length 4: %s" % addr_string)
      if chunk_len != 4:
        # Pad out with 0's until we have 4 digits
        chunk = "0" * (4 - chunk_len) + chunk
      addr_array.append(chunk)
    else:
      if double_colon:
        raise socket.error("More than one double colon in %s" % addr_string)
      else:
        double_colon = True
        # Add zeros for the compressed chunks
        addr_array.extend(["0000"] * (8 - total_length + 1))

  if len(addr_array) != 8:
    raise socket.error("Bad address length, expected 8 chunks: %s" % addr_array)

  return "".join(addr_array)
Pad out zeros in each address chunk as necessary.
dataset/ETHPy150Open google/grr/grr/lib/ipv6_utils.py/_ZeroPad