def file_passes()

in hack/verify_boilerplate.py [0:0]


def file_passes(filename, refs, regexs):  # pylint: disable=too-many-locals
    try:
        # Pass the encoding parameter to avoid ascii decode error for some
        # platform.
        with open(filename, 'r', encoding='utf-8') as fp:
            file_data = fp.read()
    except IOError:
        return False

    if not file_data:
        return True  # Nothing to copyright in this empty file.

    basename = os.path.basename(filename)
    extension = file_extension(filename)
    if extension != "":
        ref = refs[extension]
    else:
        ref = refs[basename]

    ref = ref.copy()

    # remove build tags from the top of Go files
    if extension == "go":
        con = regexs["go_build_constraints"]
        (file_data, found) = con.subn("", file_data, 1)

    # remove shebang from the top of shell files
    if extension in ("sh", "py"):
        she = regexs["shebang"]
        (file_data, found) = she.subn("", file_data, 1)

    data = file_data.splitlines()

    # if our test file is smaller than the reference it surely fails!
    if len(ref) > len(data):
        return False

    # trim our file to the same number of lines as the reference file
    data = data[:len(ref)]

    # check if we encounter a 'YEAR' placeholder if the file is generated
    if is_generated(file_data):
        for i, line in enumerate(data):
            if "Copyright YEAR" in line:
                return False
        return True

    year = regexs["year"]
    for datum in data:
        if year.search(datum):
            return False

    # Replace all occurrences of the regex "2017|2016|2015|2014" with "YEAR"
    when = regexs["date"]
    for idx, datum in enumerate(data):
        (data[idx], found) = when.subn('YEAR', datum)
        if found != 0:
            break

    # if we don't match the reference at this point, fail
    if ref != data:
        return False

    return True