diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2022-04-27 23:25:37 +0300 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2022-04-27 23:25:37 +0300 |
commit | cafde67c026809ed73cec9eae6deb0f4921cb0d0 (patch) | |
tree | c9ca0d7fe5e8442815d6584d4537c4d4e141c8d6 /core/views/expo.py | |
parent | 362aedc2ac449bf8a76970877938bf03483c8db0 (diff) | |
download | troggle-cafde67c026809ed73cec9eae6deb0f4921cb0d0.tar.gz troggle-cafde67c026809ed73cec9eae6deb0f4921cb0d0.tar.bz2 troggle-cafde67c026809ed73cec9eae6deb0f4921cb0d0.zip |
ISO-8859-1 fallback 1
Diffstat (limited to 'core/views/expo.py')
-rw-r--r-- | core/views/expo.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/core/views/expo.py b/core/views/expo.py index 1fd01e5..3c092bb 100644 --- a/core/views/expo.py +++ b/core/views/expo.py @@ -130,13 +130,18 @@ def expowebpage(request, expowebpath, path): html = o.read() except: try: - with open(os.path.normpath(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("\\t","\t") - html = html.replace("\\'","\'") + with open(os.path.normpath(expowebpath / path), "r", encoding='iso-8859-1') as o: + html = o.read() + html = str(o.read()).replace("<h1>","<h1>ISO-8859-1 characters here - ") except: - return HttpResponse(default_head + '<h3>UTF-8 Parsing Failure:<br>Page could not be parsed using UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please edit this <var>:expoweb:</var> page to replace dubious umlauts and £ symbols with correct HTML entities e.g. <em>&pound;;</em>. </body' ) + try: + with open(os.path.normpath(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("\\t","\t") + html = html.replace("\\'","\'") + except: + return HttpResponse(default_head + '<h3>UTF-8 Parsing Failure:<br>Page could not be parsed using UTF-8:<br>failure detected in expowebpage in views.expo.py</h3> Please edit this <var>:expoweb:</var> page to replace dubious umlauts and £ symbols with correct HTML entities e.g. <em>&pound;;</em>. </body' ) m = re.search(r'(.*)<\s*head([^>]*)>(.*)<\s*/head\s*>(.*)<\s*body([^>]*)>(.*)<\s*/body\s*>(.*)', html, re.DOTALL + re.IGNORECASE) if m: |