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>
# so just open the file as a byte stream. We only need to search
# for a pattern that should be the same regardless of encoding,
# so that should be good enough.
- fd = open(filename, "rb")
-
- lineno = 1
- for line in fd:
- if b"Copyright" in line:
- return True
- lineno += 1
- if lineno > 50:
- return False
+ with open(filename, "rb") as fd:
+ for lineno, line in enumerate(fd, start=1):
+ if b"Copyright" in line:
+ return True
+ if lineno > MAX_LINES:
+ break
return False