backend.py: Make FlatFileRecord._format include the trailing newline.
[chopwood] / cgi.py
diff --git a/cgi.py b/cgi.py
index 6006062..69b9038 100644 (file)
--- a/cgi.py
+++ b/cgi.py
@@ -419,7 +419,8 @@ def cgiparse():
     else:
       PARAM.append((k, v))
       if k in seen:
-        del PARAMDICT[k]
+        try: del PARAMDICT[k]
+        except KeyError: pass
       else:
         PARAMDICT[k] = v
         seen.add(k)
@@ -453,6 +454,11 @@ class Subcommand (SC.Subcommand):
   CGI parameters.
   """
 
+  def __init__(me, name, contexts, desc, func,
+               methods = ['GET', 'POST'], *args, **kw):
+    super(Subcommand, me).__init__(name, contexts, desc, func, *args, **kw)
+    me.methods = set(methods)
+
   def cgi(me, param, path):
     """
     Invoke the subcommand given a collection of CGI parameters.
@@ -484,6 +490,12 @@ class Subcommand (SC.Subcommand):
     want = {}
     kw = {}
 
+    ## Check the request method against the permitted list.
+    meth = METHOD
+    if meth == 'HEAD': meth = 'GET'
+    if meth not in me.methods:
+      raise U.ExpectedError, (500, "Unexpected request method `%s'" % METHOD)
+
     def set_value(k, v):
       """Set a simple value: we shouldn't see multiple values."""
       if k in kw: