Skip to content

Commit 3d4f391

Browse files
committed
files.py utf-8 encoding
Force utf-8 when writing/reading framework files
1 parent 763ec9e commit 3d4f391

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

python/helpers/files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
import re
55

6-
def read_file(relative_path, backup_dirs=None, **kwargs):
6+
def read_file(relative_path, backup_dirs=None, encoding="utf-8", **kwargs):
77
if backup_dirs is None:
88
backup_dirs = []
99

1010
# Try to get the absolute path for the file from the original directory or backup directories
1111
absolute_path = find_file_in_dirs(relative_path, backup_dirs)
1212

1313
# Read the file content
14-
with open(absolute_path) as f:
14+
with open(absolute_path, 'r', encoding=encoding) as f:
1515
content = remove_code_fences(f.read())
1616

1717
# Replace placeholders with values from kwargs
@@ -63,10 +63,10 @@ def find_file_in_dirs(file_path, backup_dirs):
6363
def remove_code_fences(text):
6464
return re.sub(r'~~~\w*\n|~~~', '', text)
6565

66-
def write_file(relative_path:str, content:str):
66+
def write_file(relative_path:str, content:str, encoding:str="utf-8"):
6767
abs_path = get_abs_path(relative_path)
6868
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
69-
with open(abs_path, 'w') as f:
69+
with open(abs_path, 'w', encoding=encoding) as f:
7070
f.write(content)
7171

7272
def delete_file(relative_path:str):

0 commit comments

Comments
 (0)