From fc3e4ef0d8f12520e40aaceb4fa405e0c6985133 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 13 Nov 2023 17:39:17 +0300 Subject: [PATCH] Chore: Explicitly open text files in text mode --- Robots/bkmk_rforking.py | 2 +- Storage/bkmk_stflad.py | 6 +++--- bkmk2db.py | 2 +- check_dups.py | 2 +- db2bkmk.py | 2 +- parse_html/bkmk_parse_html.py | 2 +- set-title-list.py | 2 +- sort_db.py | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Robots/bkmk_rforking.py b/Robots/bkmk_rforking.py index 136440c..117bf31 100644 --- a/Robots/bkmk_rforking.py +++ b/Robots/bkmk_rforking.py @@ -24,7 +24,7 @@ from bkmk_objects import Robot # This is to catch 'close failed: [Errno 9] Bad file descriptor' message # from os.close() in Subprocess.die() and errors from the subprocess. -sys.stderr = open("err.log", 'a') +sys.stderr = open("err.log", 'at') check_subp = None subp_pipe = None diff --git a/Storage/bkmk_stflad.py b/Storage/bkmk_stflad.py index a15d605..7a29b83 100644 --- a/Storage/bkmk_stflad.py +++ b/Storage/bkmk_stflad.py @@ -25,7 +25,7 @@ class storage_flad(Walker): def root_folder(self, f): header = f.header.replace(".", ".\n") header = header.replace("<", "\n<", 3)[1:] - header_file = open("header", 'w') + header_file = open("header", 'wt') header_file.write(header + "\n") header_file.write('

%s

\n\n' % f.name) if f.comment: header_file.write('
%s\n' % f.comment) @@ -61,7 +61,7 @@ Charset: %s self.outfile.write("\nLevel: %s\nRuler: YES\n" % (level+1)) def store(self, root_folder): - self.outfile = open(self.filename, 'w') + self.outfile = open(self.filename, 'wt') root_folder.walk_depth(self) self.outfile.close() @@ -83,7 +83,7 @@ Charset: %s self.folder_stack = [root_folder] self.current_folder = root_folder - header_file = open("header", 'r') + header_file = open("header", 'rt') header = header_file.read() header_file.close() diff --git a/bkmk2db.py b/bkmk2db.py index 5a96d7f..629668d 100755 --- a/bkmk2db.py +++ b/bkmk2db.py @@ -76,7 +76,7 @@ def run(): else: dos_add = 0 # UNIX' and Mac's len() counts CR or LF correct - infile = open(filename, 'r') + infile = open(filename, 'rt') parser = BkmkParser() line_no = 0 diff --git a/check_dups.py b/check_dups.py index 25c2936..df79df8 100755 --- a/check_dups.py +++ b/check_dups.py @@ -52,7 +52,7 @@ def run(): sys.exit(1) if log_filename: - log_file = open(log_filename, 'w') + log_file = open(log_filename, 'wt') from storage import storage storage = storage() diff --git a/db2bkmk.py b/db2bkmk.py index 4e50101..7d1d9aa 100755 --- a/db2bkmk.py +++ b/db2bkmk.py @@ -97,7 +97,7 @@ def run(): root_folder.walk_depth(Transl(transl_d)) - outfile = open(output_filename, 'w', encoding='utf-8') + outfile = open(output_filename, 'wt', encoding='utf-8') root_folder.walk_depth(writer(outfile, prune)) outfile.close() diff --git a/parse_html/bkmk_parse_html.py b/parse_html/bkmk_parse_html.py index ddfad27..85aeb88 100644 --- a/parse_html/bkmk_parse_html.py +++ b/parse_html/bkmk_parse_html.py @@ -226,7 +226,7 @@ def parse_html(html_text, charset=None, log=None): def parse_filename(filename, charset=None, log=None): - fp = open(filename, 'r') + fp = open(filename, 'rt') try: parser = parse_html(fp.read(), charset=charset, log=log) finally: diff --git a/set-title-list.py b/set-title-list.py index 4644a81..be0684c 100755 --- a/set-title-list.py +++ b/set-title-list.py @@ -42,7 +42,7 @@ def run(): URL = None title = None - title_list_file = open(args[0], 'r') + title_list_file = open(args[0], 'rt') for line in title_list_file: line = line[:-1] # strip trailing newline if URL is None: diff --git a/sort_db.py b/sort_db.py index bcd3a8e..4dd117e 100755 --- a/sort_db.py +++ b/sort_db.py @@ -99,7 +99,7 @@ def run(): sys.stdout.write("Writing %s: " % output_filename) sys.stdout.flush() - outfile = open(output_filename, 'w', encoding='utf-8') + outfile = open(output_filename, 'wt', encoding='utf-8') writer = writer(outfile) writer.root_folder(root_folder) walk_linear(linear, writer) -- 2.39.5