| 16 | self._prefix = prefix or [] |
| 17 | |
| 18 | def update(self, files): |
| 19 | for file in files: |
| 20 | with open(file, encoding="utf-8-sig") as f: |
| 21 | lines = f.readlines() |
| 22 | |
| 23 | # An interpreter only honours `#!` on the first line, so the notice goes after it. |
| 24 | shebang = lines[:1] if lines and lines[0].startswith("#!") else [] |
| 25 | lines = lines[len(shebang) :] |
| 26 | |
| 27 | index = -1 |
| 28 | for i, line in enumerate(lines): |
| 29 | if line.startswith(self._comment_characters) or self.valid_copyright_notice_line(line, index, file): |
| 30 | index += 1 |
| 31 | else: |
| 32 | break |
| 33 | |
| 34 | if index == -1: |
| 35 | self.write_update_notice(file, lines, shebang) |
| 36 | else: |
| 37 | current = "".join(lines[: index + 1]) |
| 38 | if current != self.copyright_notice(file): |
| 39 | self.write_update_notice(file, lines[index + 1 :], shebang) |
| 40 | |
| 41 | def valid_copyright_notice_line(self, line, index, file): |
| 42 | return index + 1 < len(self.copyright_notice_lines(file)) and line.startswith( |