2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

removed rest of endocings

This commit is contained in:
Martin Green 2022-06-22 09:10:56 +01:00
parent ea880915b0
commit 4d8125a2fd

View File

@ -121,19 +121,19 @@ def expofilesdir(request, dirpath, filepath):
def expowebpage(request, expowebpath, path):
'''Adds menus and serves an HTML page
'''
if not os.path.isfile(os.path.normpath(expowebpath / path).encode(sysdefaultencoding)):
if not os.path.isfile(expowebpath / path):
# Should not get here if the path has suffix "_edit"
print(f' - 404 error in expowebpage() {path}')
return render(request, 'pagenotfound.html', {'path': path}, status="404")
try:
with open(os.path.normpath(expowebpath / path).encode(sysdefaultencoding), "r", encoding='utf-8') as o:
with open(expowebpath / path, "r", encoding='utf-8') as o:
html = o.read()
except:
# exception raised on debian with python 3.9.2 but not on WSL Ubuntu with python 3.9.5
# because debian was assuming default text encoding was 'ascii'. Now specified explicitly so should be OK
try:
with open(os.path.normpath(expowebpath / path).encode(sysdefaultencoding), "rb") as o:
with open(expowebpath / path, "rb") as o:
html = str(o.read()).replace("<h1>","<h1>BAD NON-UTF-8 characters here - ")
html = html.replace("\\n","\n")
html = html.replace("\\r","")
@ -156,7 +156,7 @@ def expowebpage(request, expowebpath, path):
if m:
editable = False
else:
editable = os.access(os.path.normpath(expowebpath / path).encode(sysdefaultencoding), os.W_OK) # are file permissions writeable?
editable = os.access(expowebpath / path, os.W_OK) # are file permissions writeable?
has_menu = False
menumatch = re.match(r'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)