summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Singleton <matt@xcolour.net>2022-01-14 18:56:56 -0600
committerMatt Singleton <matt@xcolour.net>2022-01-16 13:04:41 -0600
commit17921744313bcffeb65f9cd9fb387364691a39db (patch)
tree3e69a2d4118caf68dc9d3f619e9c68756928ab57
parenta0fabfae06df0ff4ef9ad1277a9565aaea551ff6 (diff)
HACK: assume all content is utf8
-rw-r--r--gemini.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/gemini.py b/gemini.py
index cbc2eca..b940bb7 100644
--- a/gemini.py
+++ b/gemini.py
@@ -13,12 +13,13 @@ def htmlescape(text: str) -> str:
def gem2html(gem: str) -> str:
html = io.StringIO()
- html.write('<html>\n<head>\n<style type="text/css">\n')
- html.write(open('style.css').read())
+ html.write('<!DOCTYPE html>\n<html lang="en">\n<html>\n<head>\n<meta charset="utf-8"/>\n<style type="text/css">\n')
+ html.write(open('style.css', encoding='utf8').read())
html.write('</style>\n</head>\n<body>\n<div id="root">')
parser = fsm.Parser(gem.split('\n'), html)
parser.parse()
html.write('</div>\n</body>\n</html>')
+ print(html.getvalue())
return html.getvalue()
@@ -76,7 +77,12 @@ def _get(url: str) -> dict:
ssock.sendall('{url}\r\n'.format(url=url).encode('utf8'))
fp = ssock.makefile(mode='rb')
header = fp.readline(1027)
- status, meta = header.decode('utf8').split(None, 1)
+ parts = header.decode('utf8').split(None, 1)
+ status = parts[0]
+ if len(parts) == 1:
+ meta = ''
+ else:
+ meta = parts[1]
if status[0] != '2':
return {
'status': status,