<commit_before>#!/usr/bin/env python

import argparse
import re
import os
import os.path
import sys

EXCLUDED_PREFIXES = ("./generated/", "./thirdparty/", "./build", "./.git/",
                     "./bazel-")
SUFFIXES = (".cc", ".h", "BUILD")

# Files in these paths can make reference to protobuf stuff directly
GOOGLE_PROTOBUF_WHITELIST = ('ci/prebuilt', 'source/common/protobuf')

CLANG_FORMAT_PATH = os.getenv("CLANG_FORMAT", "clang-format-5.0")
BUILDIFIER_PATH = os.getenv("BUILDIFIER", "/usr/lib/go/bin/buildifier")
ENVOY_BUILD_FIXER_PATH = os.path.join(
    os.path.dirname(os.path.abspath(sys.argv[0])), "envoy_build_fixer.py")
HEADER_ORDER_PATH = os.path.join(
    os.path.dirname(os.path.abspath(sys.argv[0])), "header_order.py")

found_error = False


def printError(error):
  global found_error
  found_error = True
  print "ERROR: %s" % (error)


def checkNamespace(file_path):
  with open(file_path) as f:
    text = f.read()
    if not re.search('^\s*namespace\s+Envoy\s*{', text, re.MULTILINE) and \
       not re.search('NOLINT\(namespace-envoy\)', text, re.MULTILINE):
      printError("Unable to find Envoy namespace or NOLINT(namespace-envoy) for file: %s" % file_path)
      return False
  return True


# To avoid breaking the Lyft import, we just check for path inclusion here.
def whitelistedForProtobufDeps(file_path):
  return len(
      [path_segment in file_path
       for path_segment in GOOGLE_PROTOBUF_WHITELIST]) > 0

def checkProtobufExternalDepsBuild(file_path):
  if whitelistedForProtobufDeps(file_path):
    return True
  with open(file_path) as f:
    if re.search('"protobuf"', f.read(), re.MULTILINE):
      printError(
          "%s has unexpected direct external dependency on protobuf, use "
          "//source/common/protobuf instead." % file_path)
      return False
    return True


def checkProtobufExternalDeps(file_path):
  if whitelistedForProtobufDeps(file_path):
    return True
  with open(file_path) as f:
    text = f.read()
    if re.search('"google/protobuf', text, re.MULTILINE) or re.search(
        "google::protobuf", text, re.MULTILINE):
      printError(
          "%s has unexpected direct external dependency on protobuf, use "
          "//source/common/protobuf instead." % file_path)
      return False
    return True


def checkFilePath(file_path):
  if os.path.basename(file_path) == "BUILD":<commit_msg>fix format: fix white list (#1242)<commit_after>#!/usr/bin/env python

import argparse
import re
import os
import os.path
import sys

EXCLUDED_PREFIXES = ("./generated/", "./thirdparty/", "./build", "./.git/",
                     "./bazel-")
SUFFIXES = (".cc", ".h", "BUILD")

# Files in these paths can make reference to protobuf stuff directly
GOOGLE_PROTOBUF_WHITELIST = ('ci/prebuilt', 'source/common/protobuf')

CLANG_FORMAT_PATH = os.getenv("CLANG_FORMAT", "clang-format-5.0")
BUILDIFIER_PATH = os.getenv("BUILDIFIER", "/usr/lib/go/bin/buildifier")
ENVOY_BUILD_FIXER_PATH = os.path.join(
    os.path.dirname(os.path.abspath(sys.argv[0])), "envoy_build_fixer.py")
HEADER_ORDER_PATH = os.path.join(
    os.path.dirname(os.path.abspath(sys.argv[0])), "header_order.py")

found_error = False


def printError(error):
  global found_error
  found_error = True
  print "ERROR: %s" % (error)


def checkNamespace(file_path):
  with open(file_path) as f:
    text = f.read()
    if not re.search('^\s*namespace\s+Envoy\s*{', text, re.MULTILINE) and \
       not re.search('NOLINT\(namespace-envoy\)', text, re.MULTILINE):
      printError("Unable to find Envoy namespace or NOLINT(namespace-envoy) for file: %s" % file_path)
      return False
  return True


# To avoid breaking the Lyft import, we just check for path inclusion here.
def whitelistedForProtobufDeps(file_path):
  return any(path_segment in file_path for path_segment in GOOGLE_PROTOBUF_WHITELIST)

def checkProtobufExternalDepsBuild(file_path):
  if whitelistedForProtobufDeps(file_path):
    return True
  with open(file_path) as f:
    if re.search('"protobuf"', f.read(), re.MULTILINE):
      printError(
          "%s has unexpected direct external dependency on protobuf, use "
          "//source/common/protobuf instead." % file_path)
      return False
    return True


def checkProtobufExternalDeps(file_path):
  if whitelistedForProtobufDeps(file_path):
    return True
  with open(file_path) as f:
    text = f.read()
    if re.search('"google/protobuf', text, re.MULTILINE) or re.search(
        "google::protobuf", text, re.MULTILINE):
      printError(
          "%s has unexpected direct external dependency on protobuf, use "
          "//source/common/protobuf instead." % file_path)
      return False
    return True


def checkFilePath(file_path):
  if os.path.basename(file_path) == "BUILD":
{'fraction_non_alphanumeric': 0.12754780416053793, 'fraction_numerical': 0.0027316663164530363, 'mean_word_length': 3.741035856573705, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3180666', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1589, 'n_words': 390}