going-flying.com gemini git repository
536f5e1ff49f4730eddf9a9774f902aba0d8f602 - Matthew Ernisse - 1614384892
move vfdsay over to using my gmicgi module
diff --git a/cgi-bin/gmicgi/__init__.py b/cgi-bin/gmicgi/__init__.py index d9a5b25..c96d06c 100755 --- a/cgi-bin/gmicgi/__init__.py +++ b/cgi-bin/gmicgi/__init__.py @@ -43,6 +43,8 @@ class GeminiCGI(object): 10: ('10', ''), 20: ('20', ''), 30: ('30', ''), + 42: ('42', 'CGI ERROR'), + 43: ('43', 'PROXY ERROR'), 50: ('50', 'PERMANENT FAILURE'), 51: ('51', 'NOT FOUND'), 59: ('59', 'BAD REQUEST'), @@ -69,6 +71,14 @@ class GeminiCGI(object): return cls(50) @classmethod + def ProxyFail(cls): + return cls(43) + + @classmethod + def CGIFail(cls): + return cls(42) + + @classmethod def Input(cls, meta): return cls(10, meta) diff --git a/cgi-bin/vfdsay.py b/cgi-bin/vfdsay.py index a4d9635..2a62a32 100755 --- a/cgi-bin/vfdsay.py +++ b/cgi-bin/vfdsay.py @@ -34,6 +34,8 @@ import sys from urllib.parse import unquote +import gmicgi + def unicodeCheck(ch): ''' The Noritake Itron VFD connected to the other end of all of this nonsense has the 'katakana character font', which means @@ -45,20 +47,20 @@ def unicodeCheck(ch): if __name__ == '__main__': - qs = os.environ.get('QUERY_STRING') - if not qs: - print('10 What would you like to say (24 chars max)?\r\n') + cgi = gmicgi.GeminiCGI() + if not cgi.query_string: + cgi.Response.Input('What would you like to say (24 chars max)') sys.exit(0) try: qs = unquote(qs).strip() - list(map(unicodeCheck, qs)) + list(map(unicodeCheck, cgi.query_string)) except Exception as e: - print(f'50 {e} in input\r\n') + cgi.Response.Fail() sys.exit(0) - if len(qs) > 24: - print('50 Maximum line length is 24 characters.\r\n') + if len(cgi.query_string) > 24: + cgi.Response.Fail() sys.exit(0) try: @@ -67,11 +69,12 @@ if __name__ == '__main__': params={'msg': qs} ) resp.raise_for_status() + except Exception as e: - print(f'43 Error connecting to VFD: {e}\r\n') + cgi.Response.ProxyFail() sys.exit(0) - print("20 text/gemini\r\n") + cgi.Response.Ok() print(f'''``` [0m ┌───────────────────┐