@classmethod
  def IpInList(cls, key_name, ip):
    if not ip:
      return False  # lenient response

    # TODO(user): Once the underlying util.Ip* methods support ipv6
    # this method can go away. Until then, this stops all of the churn
    # and exits early.
    if ip.find(':') > -1:  # ipv6
      return False

    try:
      ip_blocks_str = cls.MemcacheWrappedGet(key_name, 'text_value')
      if not ip_blocks_str:
        return False
      ip_blocks = util.Deserialize(ip_blocks_str)
    except (util.DeserializeError, db.Error):
      logging.exception('IpInList(%s)', ip)
      return False  # lenient response

    # Note: The method below, parsing a serialized list of networks
    # expressed as strings, might seem silly. But the total time to
    # deserialize and translate the strings back into IP network/mask
    # integers is actually faster than storing them already split, e.g. a
    # list of 2 item lists (network,mask). Apparently JSON isn't as
    # efficient at parsing ints or nested lists.
    #
    # (pickle is 2X+ faster but not secure & deprecated inside util module)

    ip_int = ipcalc.IpToInt(ip)

    for ip_mask_str in ip_blocks:
      ip_mask = ipcalc.IpMaskToInts(ip_mask_str)
      if (ip_int & ip_mask[1]) == ip_mask[0]:
        return True

    return False
Check whether IP is in serialized IP/mask list in key_name.
dataset/ETHPy150Open google/simian/src/simian/mac/models/base.py/KeyValueCache.IpInList