From b8d3b32725371e74f2e79df0f83885e83d9ef778 Mon Sep 17 00:00:00 2001 From: Yini Xu <34967660+YiniXu9506@users.noreply.github.com> Date: Thu, 9 Sep 2021 14:50:39 +0800 Subject: [PATCH] chore: fix byte encode (#6428) --- scripts/check-conflicts.py | 6 +++--- scripts/check-control-char.py | 2 +- scripts/check-file-encoding.py | 2 +- scripts/check-manual-line-breaks.py | 2 +- scripts/check-tags.py | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/check-conflicts.py b/scripts/check-conflicts.py index 7d940ad4d9f0b..0f003e5f96597 100644 --- a/scripts/check-conflicts.py +++ b/scripts/check-conflicts.py @@ -42,7 +42,7 @@ single = [] lineNum = 0 if os.path.isfile(filename): - with open(filename,'r') as file: + with open(filename,'r', encoding='utf-8') as file: for line in file: lineNum += 1 if re.match(r'<{7}.*\n', line): @@ -57,7 +57,7 @@ flag = 0 else: continue - + if len(pos): mark = 1 @@ -65,7 +65,7 @@ for conflict in pos: if len(conflict) == 2: print("CONFLICTS: line " + str(conflict[0]) + " to line " + str(conflict[1]) + "\n") - + pos = [] if mark: diff --git a/scripts/check-control-char.py b/scripts/check-control-char.py index e17a721d8c74e..3bf7784c3b718 100644 --- a/scripts/check-control-char.py +++ b/scripts/check-control-char.py @@ -37,7 +37,7 @@ def check_control_char(filename): pos = [] flag = 0 - with open(filename,'r') as file: + with open(filename,'r', encoding='utf-8') as file: for line in file: lineNum += 1 diff --git a/scripts/check-file-encoding.py b/scripts/check-file-encoding.py index b207659cfc8be..2ad3127f249b4 100644 --- a/scripts/check-file-encoding.py +++ b/scripts/check-file-encoding.py @@ -35,7 +35,7 @@ def check_BOM(filename): BUFSIZE = 4096 BOMLEN = len(codecs.BOM_UTF8) - with open(filename, "r+b") as fp: + with open(filename, "r+b", encoding='utf-8') as fp: chunk = fp.read(BUFSIZE) if chunk.startswith(codecs.BOM_UTF8): i = 0 diff --git a/scripts/check-manual-line-breaks.py b/scripts/check-manual-line-breaks.py index 7102581ff37e2..771e1658f852b 100644 --- a/scripts/check-manual-line-breaks.py +++ b/scripts/check-manual-line-breaks.py @@ -40,7 +40,7 @@ def check_manual_break(filename): lineNum = 0 mark = 0 - with open(filename,'r') as file: + with open(filename,'r', encoding='utf-8') as file: for line in file: lineNum += 1 diff --git a/scripts/check-tags.py b/scripts/check-tags.py index 51eb14ff6920d..1b1f8f84fd7e2 100644 --- a/scripts/check-tags.py +++ b/scripts/check-tags.py @@ -107,7 +107,7 @@ def filter_frontmatter(content): if len(collect) >= 2: filter_point = collect[1] content = content[filter_point:] - + return content def filter_backticks(content, filename): @@ -140,7 +140,7 @@ def filter_backticks(content, filename): for filename in sys.argv[1:]: # print("Checking " + filename + "......\n") if os.path.isfile(filename): - file = open(filename, "r" ) + file = open(filename, "r", encoding='utf-8') content = file.read() file.close()