gemini.git

going-flying.com gemini git repository

summary

tree

log

refs

2cb9b4f8272ed5edd9f8158263f0a9edb3759f06 - Matthew Ernisse - 1614713150

documentation++

view tree

view raw

diff --git a/cgi-bin/gmicgi/__init__.py b/cgi-bin/gmicgi/__init__.py
index 8909d3f..a28f896 100755
--- a/cgi-bin/gmicgi/__init__.py
+++ b/cgi-bin/gmicgi/__init__.py
@@ -32,9 +32,10 @@ from urllib.parse import parse_qs, quote, unquote, urlparse
 
 
 class GeminiCGI(object):
-	'''A convenience class to handle CGI under Molly Brown.
-	Contains a Response class to make it easy to not forget the
-	nuances of the Gemini header line.
+	'''A class to make writing CGI scripts for Molly Brown a little
+	bit easier.  Contains some decorators, a simple (optional) route
+	engine and a Response class that aims to make it easy to not forget
+	the nuances of the Gemini header line.
 	'''
 
 	class Response(object):
@@ -110,9 +111,22 @@ class GeminiCGI(object):
 			return cls(30, meta)
 
 	def __init__(self):
-		''' Setup an instance of the GeminiCGI processor, which will
-		process the PATH_INFO and QUERY_STRING environment variables.
-
+		''' Setup an instance of the GeminiCGI processor.  This will
+		provide several ways to look at the PATH_INFO and QUERY_STRING
+		environment variables.
+
+		Properties:
+			- client_cert - Hash of the client certificate
+			- path_info - String containing the contents of the
+				URL path part AFTER the script name.
+			- script_path - Filesystem location of the script.
+			- query_string - Raw query string from the request.
+			- query_dequoted - The query string run through
+				urlunquote.
+			- query_parsed - The query string run through
+				parse_qs.  This will be a mapping of
+				key/values if the query string is formatted
+				that way (eg: q=foo would return {'q': 'foo'}).
 		'''
 		self.client_cert = os.environ.get('TLS_CLIENT_HASH', '')
 		self.path_info = os.environ.get('PATH_INFO', '')
@@ -128,7 +142,7 @@ class GeminiCGI(object):
 			self.query_parsed = parse_qs(self.query_string)
 
 	def certificate_required(self, f):
-		''' Return a 60 if a client certificate isn't presented. '''
+		''' Decorator to require a certificate from the client.'''
 		def decorator():
 			if not self.client_cert:
 				return self.Response.NeedCert()
@@ -160,7 +174,15 @@ class GeminiCGI(object):
 		return decorator
 
 	def run(self):
-		''' Run the route engine.'''
+		''' Run the route engine.  Note multiple functions may
+		exist for a given route, they will be called in order they
+		are discovered.  If no route matches then this function will
+		call the cgi.Response.NotFound function to send the proper
+		response to the client.  If you wish to do your own route
+		processing, either do it first or do not use this method.
+
+		You can access the routes property directly if you need to.
+		'''
 		if self.path_info in self.routes.keys():
 			for func in self.routes[self.path_info]:
 				func()