chiark / gitweb /
cgi.py: Export request method from `cgiparse'.
[chopwood] / cgi.py
diff --git a/cgi.py b/cgi.py
index d66bfc6a6b106b4b55c4626aa40d6073be8ec41b..1aa2917950ad99350c143c70bf6486119eccc338 100644 (file)
--- a/cgi.py
+++ b/cgi.py
@@ -311,6 +311,7 @@ def cgi_errors(hook = None):
 ### CGI input.
 
 ## Lots of global variables to be filled in by `cgiparse'.
+METHOD = None
 COOKIE = {}
 SPECIAL = {}
 PARAM = []
@@ -377,20 +378,20 @@ def cgiparse():
         True if the client connection is carried over SSL or TLS.
   """
 
-  global SSLP
+  global METHOD, SSLP
 
   def getenv(var):
     try: return ENV[var]
     except KeyError: raise U.ExpectedError, (500, "No `%s' supplied" % var)
 
   ## Yes, we want the request method.
-  method = getenv('REQUEST_METHOD')
+  METHOD = getenv('REQUEST_METHOD')
 
   ## Acquire the query string.
-  if method == 'GET':
+  if METHOD == 'GET':
     q = getenv('QUERY_STRING')
 
-  elif method == 'POST':
+  elif METHOD == 'POST':
 
     ## We must read the query string from stdin.
     n = getenv('CONTENT_LENGTH')
@@ -404,7 +405,7 @@ def cgiparse():
       raise U.ExpectedError, (500, "Failed to read correct length")
 
   else:
-    raise U.ExpectedError, (500, "Unexpected request method `%s'" % method)
+    raise U.ExpectedError, (500, "Unexpected request method `%s'" % METHOD)
 
   ## Populate the `SPECIAL', `PARAM' and `PARAMDICT' tables.
   seen = set()