From: Oleg Broytman Date: Tue, 21 Nov 2023 18:46:42 +0000 (+0300) Subject: Fix(Py3): Always open text storage files in UTF-8 X-Git-Tag: 5.0.0~3 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=64b2e0c0275c1487574614bbfb0ca1ef50fae1df;p=bookmarks_db.git Fix(Py3): Always open text storage files in UTF-8 --- diff --git a/Storage/bkmk_stflad.py b/Storage/bkmk_stflad.py index 7a29b83..81a4e6d 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", 'wt') + header_file = open("header", 'wt', encoding='utf-8') 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, 'wt') + self.outfile = open(self.filename, 'wt', encoding='utf-8') 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", 'rt') + header_file = open("header", 'rt', encoding='utf-8') header = header_file.read() header_file.close() diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 9f7fed7..1d32fdc 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -91,13 +91,13 @@ class storage_json(Walker): def store(self, root_folder): root_folder.walk_depth(self) - outfile = open(self.filename, 'wt') + outfile = open(self.filename, 'wt', encoding='utf-8') json.dump(self.dict, outfile) outfile.close() del self.dict def load(self): - infile = open(self.filename, 'rt') + infile = open(self.filename, 'rt', encoding='utf-8') bkmk_s = infile.read() infile.close() diff --git a/Storage/debug-json/pprint-json.py b/Storage/debug-json/pprint-json.py index b90f9f0..6b9d280 100755 --- a/Storage/debug-json/pprint-json.py +++ b/Storage/debug-json/pprint-json.py @@ -4,7 +4,7 @@ import sys import json from pprint import pprint -infile = open(sys.argv[1], 'rt') +infile = open(sys.argv[1], 'rt', encoding='utf-8') bkmk_s = infile.read() infile.close()