code: def check_header(filename, is_newly_created=False):
    
    try:
      with open(filename, 'r') as pyfile:
        buf = ""
        for lineno in range(1,7):
          line = pyfile.readline()
          # Skip shebang line
          if lineno == 1 and line.startswith('#!'):
            line = pyfile.readline()
          # Check if the copyright year can be parsed as within the current century, or the current
          # year if it is a new file.
          if line.startswith("# Copyright"):
            year = line[12:16]
            if is_newly_created:
              if not year == _current_year:
                raise HeaderCheckFailure('{}: copyright year must be {} (was {})'
                                         .format(filename, _current_year, year))
            else:
              if not _current_century_regex.match(year):
                raise HeaderCheckFailure(
                  "{}: copyright year must match '{}' (was {}): current year is {}"
                  .format(filename, _current_century_regex.pattern, year, _current_year))
            line = "# Copyright YYYY" + line[16:]
          buf += line
        if buf != EXPECTED_HEADER:
          raise HeaderCheckFailure('{}: failed to parse header at all'
                                   .format(filename))
    except IOError as e:
      raise HeaderCheckFailure('{}: error while reading input ({})'
                               .format(filename, str(e)))
docs: Raises `HeaderCheckFailure` if the header doesn't match.