summaryrefslogtreecommitdiff
path: root/gemini.py
diff options
context:
space:
mode:
Diffstat (limited to 'gemini.py')
-rw-r--r--gemini.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/gemini.py b/gemini.py
index 275eab9..7bedda5 100644
--- a/gemini.py
+++ b/gemini.py
@@ -24,6 +24,9 @@ def gem2html(gem: dict) -> str:
parser = fsm.Parser(gem['body'].split('\n'), body)
parser.parse()
params['body'] = body.getvalue()
+ elif gem['status'][0] == '1':
+ template = string.Template(open('input_template.html').read())
+ params['meta'] = gem['meta']
else:
template = string.Template(open('error_template.html').read())
if gem['status'] == '00':
@@ -63,6 +66,29 @@ def get(url: str, follow_redirects: bool = True) -> dict:
return response
+def hack_url(url: str) -> str:
+ """
+ An ugly hack to reformat input queries the way gemini wants them:
+ ?<query>
+ Rather than the default way an html get form renders them:
+ ?<inputname>=<query>
+ I don't think this ever *should* break but I guess it *could*.
+ """
+ url_parts = urllib.parse.urlsplit(url)
+ query = urllib.parse.parse_qs(url_parts.query)
+ if len(query) == 1 and '__client_internal_input' in query and len(query['__client_internal_input']) == 1:
+ query = str(query['__client_internal_input'][0])
+ url = urllib.parse.urlunsplit((
+ url_parts.scheme,
+ url_parts.netloc,
+ url_parts.path,
+ query,
+ url_parts.fragment,
+ ))
+ url_parts = urllib.parse.urlsplit(url)
+ return url
+
+
def _parse_meta(meta: str) -> dict:
mime, _, params_text = meta.lower().strip().partition(';')
params = {}