gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

ec4971b0cb8f8632e1427e99bf9c65eca4fb13fd - Matthew Ernisse - 1612579228

a little more helpful

view tree

view raw

diff --git a/cgi-bin/converter b/cgi-bin/converter
index ebd06e1..1c2f007 100755
--- a/cgi-bin/converter
+++ b/cgi-bin/converter
@@ -65,8 +65,8 @@ class GeminiCGI(object):
 			return cls(20, meta)
 
 		@classmethod
-		def Fail(cls, meta=None):
-			return cls(50, meta)
+		def Fail(cls):
+			return cls(50)
 
 		@classmethod
 		def NotFound(cls):
@@ -94,7 +94,10 @@ def display_main_menu(cgi):
 	response.print_header()
 	print('''# Matt's Gemini Toolbox.
 
-## Display a number in Binary, Decimal and Hexadecimal.
+## Number base converters
+
+Display a number in binary, decimal and hexadecimal.  If your input cannot be recognized, the script will return a permanent failure.
+
 => bin	Binary Input
 => dec	Decimal Input
 => hex	Hexadecimal Input
@@ -117,9 +120,11 @@ def pretty_binary(i):
 	return j + ' ' + ' '.join(out)
 
 
-def result_table(input, b, d, h):
+def result_table(cgi, input, b, d, h):
 	''' Pretty print a table'''
 	global BACK_LINK
+	response = cgi.Response.Ok('text/gemini')
+	response.print_header()
 
 	output  = '```\n'
 	output += f'# Input\n{input}\n\n'
@@ -168,13 +173,11 @@ if __name__ == '__main__':
 				b = pretty_binary(d)
 				h = f'{d:02X}'
 			except Exception:
-				response = cgi.Response.Fail('Invalid input')
+				response = cgi.Response.Fail()
 				response.print_header()
 				sys.exit()
 
-			response = cgi.Response.Ok('text/gemini')
-			response.print_header()
-			result_table(s, b, d, h)
+			result_table(cgi, s, b, d, h)
 	
 		elif cgi.path_info == 'dec':
 			s = cgi.query_string
@@ -184,13 +187,11 @@ if __name__ == '__main__':
 				b = pretty_binary(d)
 				h = f'{d:02X}'
 			except Exception:
-				response = cgi.Response.Fail('Invalid input')
+				response = cgi.Response.Fail()
 				response.print_header()
 				sys.exit()
 
-			response = cgi.Response.Ok('text/gemini')
-			response.print_header()
-			result_table(s, b, d, h)
+			result_table(cgi, s, b, d, h)
 	
 		elif cgi.path_info == 'hex':
 			s = cgi.query_string
@@ -200,13 +201,11 @@ if __name__ == '__main__':
 				b = pretty_binary(d)
 				h = f'{d:02X}'
 			except Exception:
-				response = cgi.Response.Fail('Invalid input')
+				response = cgi.Response.Fail()
 				response.print_header()
 				sys.exit()
 
-			response = cgi.Response.Ok('text/gemini')
-			response.print_header()
-			result_table(s, b, d, h)
+			result_table(cgi, s, b, d, h)
 
 		else:
 			response = cgi.Response.NotFound()