def EvaluatePrefix(prefix, path_regex):
  if path_regex.match(prefix):
    # The prefix is a match for this regex. We assume regex is sane enough
    # that all extentions of prefix will also match.
    return "MATCH"

  path_regex_string = path_regex.pattern
  if not path_regex_string.startswith(KNOWN_PATH_REGEX_PREFIX):
    # We don't know how to analyze this regex. Assume that extensions of prefix
    # might match the regex.
    logging.warning("Unrecognized regex format, being pessimistic: %s",
                    path_regex_string)
    return "POSSIBLE"

  literal_prefix = _LiteralPrefix(path_regex_string[len(
      KNOWN_PATH_REGEX_PREFIX):])
  if literal_prefix.startswith(prefix):
    # There are extensions of prefix which match regex.
    return "POSSIBLE"

  if prefix.startswith(literal_prefix):
    # It is possible that some extension of prefix will match
    # regex.
    return "POSSIBLE"

  # There is a character in the literal prefix which does not match
  # the corresponding character in prefix. Therefore no match is possible.
  return "NO_MATCH"
Estimate if subjects beginning with prefix might match path_regex.
dataset/ETHPy150Open google/grr/grr/lib/data_stores/common.py/EvaluatePrefix