changeset 1012:882a8e99e0e8

removed form param from most setup_args* methods, fixed missing cgi import for WSGI
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 23 Jul 2006 18:37:17 +0200
parents 58f5af49cd03
children 289254f32ab2
files MoinMoin/request/CGI.py MoinMoin/request/CLI.py MoinMoin/request/FCGI.py MoinMoin/request/MODPYTHON.py MoinMoin/request/STANDALONE.py MoinMoin/request/TWISTED.py MoinMoin/request/WSGI.py MoinMoin/request/__init__.py
diffstat 8 files changed, 31 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/request/CGI.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/CGI.py	Sun Jul 23 18:37:17 2006 +0200
@@ -7,7 +7,7 @@
                 2003-2006 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
-import sys, os
+import sys, os, cgi
 
 from MoinMoin import config
 from MoinMoin.request import RequestBase
@@ -29,6 +29,11 @@
         except Exception, err:
             self.fail(err)
 
+    def _setup_args_from_cgi_form(self):
+        """ Override to create cgi form """
+        form = cgi.FieldStorage()
+        return RequestBase._setup_args_from_cgi_form(self, form)
+
     def open_logs(self):
         # create log file for catching stderr output
         if not self.opened_logs:
--- a/MoinMoin/request/CLI.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/CLI.py	Sun Jul 23 18:37:17 2006 +0200
@@ -30,6 +30,12 @@
         self.cfg.caching_formats = [] # don't spoil the cache
         self.initTheme() # usually request.run() does this, but we don't use it
 
+    def _setup_args_from_cgi_form(self):
+        """ Override to create cli form """
+        #form = cgi.FieldStorage()
+        #return RequestBase._setup_args_from_cgi_form(self, form)
+        return {}
+
     def read(self, n=None):
         """ Read from input stream. """
         if n is None:
--- a/MoinMoin/request/FCGI.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/FCGI.py	Sun Jul 23 18:37:17 2006 +0200
@@ -32,11 +32,9 @@
         except Exception, err:
             self.fail(err)
 
-    def _setup_args_from_cgi_form(self, form=None):
+    def _setup_args_from_cgi_form(self):
         """ Override to use FastCGI form """
-        if form is None:
-            form = self.fcgform
-        return RequestBase._setup_args_from_cgi_form(self, form)
+        return RequestBase._setup_args_from_cgi_form(self, self.fcgform)
 
     def read(self, n=None):
         """ Read from input stream. """
--- a/MoinMoin/request/MODPYTHON.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/MODPYTHON.py	Sun Jul 23 18:37:17 2006 +0200
@@ -76,15 +76,14 @@
 
         RequestBase.fixURI(self, env)
 
-    def _setup_args_from_cgi_form(self, form=None):
+    def _setup_args_from_cgi_form(self):
         """ Override to use mod_python.util.FieldStorage 
         
-        Its little different from cgi.FieldStorage, so we need to
+        It's little different from cgi.FieldStorage, so we need to
         duplicate the conversion code.
         """
         from mod_python import util
-        if form is None:
-            form = util.FieldStorage(self.mpyreq)
+        form = util.FieldStorage(self.mpyreq)
 
         args = {}
         for key in form.keys():
--- a/MoinMoin/request/STANDALONE.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/STANDALONE.py	Sun Jul 23 18:37:17 2006 +0200
@@ -54,7 +54,7 @@
         except Exception, err:
             self.fail(err)
 
-    def _setup_args_from_cgi_form(self, form=None):
+    def _setup_args_from_cgi_form(self):
         """ Override to create standalone form """
         form = cgi.FieldStorage(self.rfile, headers=self.headers, environ={'REQUEST_METHOD': 'POST'})
         return RequestBase._setup_args_from_cgi_form(self, form)
--- a/MoinMoin/request/TWISTED.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/TWISTED.py	Sun Jul 23 18:37:17 2006 +0200
@@ -64,7 +64,7 @@
             return self.finish()
         RequestBase.run(self)
 
-    def setup_args(self, form=None):
+    def setup_args(self):
         """ Return args dict 
         
         Twisted already parsed args, including __filename__ hacking,
--- a/MoinMoin/request/WSGI.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/WSGI.py	Sun Jul 23 18:37:17 2006 +0200
@@ -6,7 +6,7 @@
                 2003-2006 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
-import sys, os
+import sys, os, cgi
 
 from MoinMoin import config
 from MoinMoin.request import RequestBase
@@ -30,12 +30,11 @@
         except Exception, err:
             self.fail(err)
 
-    def setup_args(self, form=None):
+    def setup_args(self):
         # TODO: does this include query_string args for POST requests?
         # see also how CGI works now
-        if form is None:
-            form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1)
-        return self._setup_args_from_cgi_form(form)
+        form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1)
+        return RequestBase._setup_args_from_cgi_form(self, form)
 
     def read(self, n=None):
         if n is None:
--- a/MoinMoin/request/__init__.py	Sat Jul 22 17:49:17 2006 +0200
+++ b/MoinMoin/request/__init__.py	Sun Jul 23 18:37:17 2006 +0200
@@ -887,40 +887,33 @@
                     break
         return forbidden
 
-    def setup_args(self, form=None):
+    def setup_args(self):
         """ Return args dict 
         First, we parse the query string (usually this is used in GET methods,
         but TwikiDraw uses ?action=AttachFile&do=savedrawing plus posted stuff).
         Second, we update what we got in first step by the stuff we get from
         the form (or by a POST). We invoke _setup_args_from_cgi_form to handle
         possible file uploads.
-        
-        Warning: calling with a form might fail, depending on the type of the
-        request! Only the request knows which kind of form it can handle.
-        
-        TODO: The form argument should be removed in 1.5.
         """
         args = cgi.parse_qs(self.query_string, keep_blank_values=1)
         args = self.decodeArgs(args)
-        # if we have form data (e.g. in a POST), those override the stuff we already have:
-        if form is not None or self.request_method == 'POST':
-            postargs = self._setup_args_from_cgi_form(form)
+        # if we have form data (in a POST), those override the stuff we already have:
+        if self.request_method == 'POST':
+            postargs = self._setup_args_from_cgi_form()
             args.update(postargs)
         return args
 
     def _setup_args_from_cgi_form(self, form=None):
         """ Return args dict from a FieldStorage
-        
-        Create the args from a standard cgi.FieldStorage or from given form.
-        Each key contain a list of values.
+
+        Create the args from a given form. Each key contain a list of values.
+        This method usually gets overridden in classes derived from this - it
+        is their task to call this method with an appropriate form parameter.
 
         @param form: a cgi.FieldStorage
         @rtype: dict
         @return: dict with form keys, each contains a list of values
         """
-        if form is None:
-            form = cgi.FieldStorage()
-
         args = {}
         for key in form:
             values = form[key]