From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1521) id 968513857C72; Wed, 26 Oct 2022 10:11:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 968513857C72 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666779109; bh=Nt4+nzv86j4QU8pL4rr+Ta5BhW5nUEe7ocXb83F5/vo=; h=From:To:Subject:Date:From; b=hdENayI9h7+yWuctAIWm5063f/6tjb/8rMw3DRorkUxbtbv/CjLTvapK+phk9oZph Oohn33SrzXUenn2pJ7jv9DM20811e/BrGPy01HukdSaS98V9xL8W8td5sElaJn+fsk W3VP83fQaPZ/kJAX0TKUNfNzZyIpF0BlFJDFDXhQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Frysinger To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb: copyright: make file header scan a bit more pythonic X-Act-Checkin: binutils-gdb X-Git-Author: Mike Frysinger X-Git-Refname: refs/heads/master X-Git-Oldrev: e5fbca55b28b77eced290e4e681f1d5cd3dafe98 X-Git-Newrev: 99033a63c7ba0997ef737392eef15337d6783078 Message-Id: <20221026101149.968513857C72@sourceware.org> Date: Wed, 26 Oct 2022 10:11:49 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D99033a63c7ba= 0997ef737392eef15337d6783078 commit 99033a63c7ba0997ef737392eef15337d6783078 Author: Mike Frysinger Date: Sat Jan 1 13:08:20 2022 -0500 gdb: copyright: make file header scan a bit more pythonic =20 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. =20 Approved-By: Simon Marchi Diff: --- gdb/copyright.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/gdb/copyright.py b/gdb/copyright.py index 8d623e6f5c7..040fed18708 100755 --- a/gdb/copyright.py +++ b/gdb/copyright.py @@ -148,15 +148,12 @@ def may_have_copyright_notice(filename): # 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 =3D open(filename, "rb") - - lineno =3D 1 - for line in fd: - if b"Copyright" in line: - return True - lineno +=3D 1 - if lineno > 50: - return False + with open(filename, "rb") as fd: + for lineno, line in enumerate(fd, start=3D1): + if b"Copyright" in line: + return True + if lineno > MAX_LINES: + break return False