Made it such that opening files for reading and writing when editing to use utf8 encoding

This commit is contained in:
Martin Green 2022-06-20 21:35:51 +01:00
parent 491fba7d64
commit a664e8ce8c

View File

@ -283,7 +283,7 @@ def editexpopage(request, path):
try:
filepath = Path(settings.EXPOWEB) / path
o = open(os.path.normpath(filepath).encode(sysdefaultencoding), "r")
html = o.read()
html = o.read(encoding="utf8")
autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|It is auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE)
if autogeneratedmatch:
return HttpResponse(autogeneratedmatch.group(1))
@ -331,7 +331,7 @@ def editexpopage(request, path):
# GIT see also core/models/cave.py writetrogglefile()
# GIT see also core/views/uploads.py dwgupload()
try:
with open(os.path.normpath(filepath).encode(sysdefaultencoding), "w") as f:
with open(os.path.normpath(filepath).encode(sysdefaultencoding), "w", encoding="utf8") as f:
print(f'WRITING{cwd}---{filename} ')
# as the wsgi process www-data, we have group write-access but are not owner, so cannot chmod.
# os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--