Révision | 99033a63c7ba0997ef737392eef15337d6783078 (tree) |
---|---|
l'heure | 2022-10-26 17:56:40 |
Auteur | Mike Frysinger <vapier@gent...> |
Commiter | Mike Frysinger |
gdb: copyright: make file header scan a bit more pythonic
Should be functionally the same, but uses more pythonic idioms to get
fewer lines of code, and to make sure to not leak open file handles.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
@@ -148,15 +148,12 @@ def may_have_copyright_notice(filename): | ||
148 | 148 | # so just open the file as a byte stream. We only need to search |
149 | 149 | # for a pattern that should be the same regardless of encoding, |
150 | 150 | # so that should be good enough. |
151 | - fd = open(filename, "rb") | |
152 | - | |
153 | - lineno = 1 | |
154 | - for line in fd: | |
155 | - if b"Copyright" in line: | |
156 | - return True | |
157 | - lineno += 1 | |
158 | - if lineno > 50: | |
159 | - return False | |
151 | + with open(filename, "rb") as fd: | |
152 | + for lineno, line in enumerate(fd, start=1): | |
153 | + if b"Copyright" in line: | |
154 | + return True | |
155 | + if lineno > MAX_LINES: | |
156 | + break | |
160 | 157 | return False |
161 | 158 | |
162 | 159 |