From 69afca435b271b42a341730802467bacf88fa444 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 19 Mar 2026 12:00:33 +1100 Subject: Remove unnecessary readlines and make FindCredits same as SciTE. --- scripts/CheckMentioned.py | 4 ++-- scripts/Face.py | 4 ++-- scripts/FileGenerator.py | 6 +++--- scripts/GenerateCharacterCategory.py | 4 ++-- scripts/ScintillaData.py | 21 +++++++++++---------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/scripts/CheckMentioned.py b/scripts/CheckMentioned.py index 1e5f6c393..b6d52293e 100644 --- a/scripts/CheckMentioned.py +++ b/scripts/CheckMentioned.py @@ -35,13 +35,13 @@ def depunctuate(s): symbols = {} with open(incFileName, "rt") as incFile: - for line in incFile.readlines(): + for line in incFile: if line.startswith("#define"): identifier = line.split()[1] symbols[identifier] = 0 with open(docFileName, "rt") as docFile: - for line in docFile.readlines(): + for line in docFile: for word in depunctuate(line).split(): if word in symbols.keys(): symbols[word] = 1 diff --git a/scripts/Face.py b/scripts/Face.py index 9814115f0..0278f5ac2 100644 --- a/scripts/Face.py +++ b/scripts/Face.py @@ -2,7 +2,7 @@ # Face.py - module for reading and parsing Scintilla.iface file # Implemented 2000 by Neil Hodgson neilh@scintilla.org # Released to the public domain. -# Requires Python 2.7 or later +# Requires Python 3.6 or later def sanitiseLine(line): line = line.rstrip('\n') @@ -72,7 +72,7 @@ class Face: currentComment = [] currentCommentFinished = 0 file = open(name) - for line in file.readlines(): + for line in file: line = sanitiseLine(line) if line: if line[0] == "#": diff --git a/scripts/FileGenerator.py b/scripts/FileGenerator.py index f798e1d6b..f596e9cbe 100644 --- a/scripts/FileGenerator.py +++ b/scripts/FileGenerator.py @@ -4,7 +4,7 @@ # Generate or regenerate source files based on comments in those files. # May be modified in-place or a template may be generated into a complete file. -# Requires Python 2.7 or later +# Requires Python 3.6 or later # The files are copied to a string apart from sections between a # ++Autogenerated comment and a --Autogenerated comment which is # generated by the CopyWithInsertion function. After the whole string is @@ -143,7 +143,7 @@ def UpdateLineInPlistFile(path, key, value): lines = [] keyCurrent = "" with codecs.open(path, "rb", "utf-8") as f: - for line in f.readlines(): + for line in f: ls = line.strip() if ls.startswith(""): keyCurrent = ls.replace("", "").replace("", "") @@ -160,7 +160,7 @@ def UpdateLineInFile(path, linePrefix, lineReplace): lines = [] updated = False with codecs.open(path, "r", "utf-8") as f: - for line in f.readlines(): + for line in f: line = line.rstrip() if not updated and line.startswith(linePrefix): lines.append(lineReplace) diff --git a/scripts/GenerateCharacterCategory.py b/scripts/GenerateCharacterCategory.py index 806dea2fe..1080cceed 100644 --- a/scripts/GenerateCharacterCategory.py +++ b/scripts/GenerateCharacterCategory.py @@ -2,7 +2,7 @@ # Script to generate scintilla/src/CharacterCategoryMap.cxx and lexilla/lexlib/CharacterCategory.cxx # from Python's Unicode data # Should be run rarely when a Python with a new version of Unicode data is available. -# Requires Python 3.3 or later +# Requires Python 3.6 or later # Should not be run with old versions of Python. import pathlib, platform, sys, unicodedata @@ -11,7 +11,7 @@ from FileGenerator import Regenerate def findCategories(filename): with filename.open(encoding="UTF-8") as infile: - lines = [x.strip() for x in infile.readlines() if "\tcc" in x] + lines = [x.strip() for x in infile if "\tcc" in x] values = "".join(lines).replace(" ","").split(",") print("Categrories:", values) return [v[2:] for v in values] diff --git a/scripts/ScintillaData.py b/scripts/ScintillaData.py index 55534306b..d57898e5e 100644 --- a/scripts/ScintillaData.py +++ b/scripts/ScintillaData.py @@ -25,19 +25,20 @@ import datetime, pathlib, sys def FindCredits(historyFile, removeLinks=True): + """ Return a list of contributors in a history file. """ credits = [] stage = 0 with historyFile.open(encoding="utf-8") as f: - for line in f.readlines(): - line = line.strip() - if stage == 0 and line == "": + for line in f: + s = line.strip() + if stage == 0 and s == "
": stage = 1 - elif stage == 1 and line == "
": + elif stage == 1 and s == "": stage = 2 - if stage == 1 and line.startswith(""): - credit = line[4:-5] - if removeLinks and ""): + credit = s[4:-5] + if removeLinks and "") name = end.split("<")[0] url = urlplus[1:-1] @@ -57,14 +58,14 @@ class ScintillaData: self.versionCommad = self.versionDotted.replace(".", ", ") + ', 0' with (scintillaRoot / "doc" / "index.html").open() as f: - self.dateModified = [d for d in f.readlines() if "Date.Modified" in d]\ + self.dateModified = [d for d in f if "Date.Modified" in d]\ [0].split('\"')[3] # 20130602 # index.html, SciTE.html dtModified = datetime.datetime.strptime(self.dateModified, "%Y%m%d") self.yearModified = self.dateModified[0:4] monthModified = dtModified.strftime("%B") - dayModified = "%d" % dtModified.day + dayModified = f"{dtModified.day}" self.mdyModified = monthModified + " " + dayModified + " " + self.yearModified # May 22 2013 # index.html, SciTE.html -- cgit v1.2.3