Hi,

Andreas Ames wrote:

> next trial.  I hope I've got it straight now.

Not quite so (although this may only be nitpicking ;-).

fs_env = environ

should have read

fs_env = environ.copy()

obviously.  See attachment.


cheers,

andreas



--- lib.orig/python/ZPublisher/HTTPRequest.py	2004-08-18 16:37:18.000000000 +0200
+++ lib/python/ZPublisher/HTTPRequest.py	2004-08-20 13:07:25.000000000 +0200
@@ -60,6 +60,37 @@
 class NestedLoopExit( Exception ):
     pass
 
+FILELIST_ENV_ENTRY = 'request.filestorage.filelist'
+
+class ZFieldStorage(cgi.FieldStorage):
+    """\
+    Tame the FieldStorage.
+
+    This class overrides the stock implementation to add all file
+    objects, generated while parsing a request, to a list.  This list
+    is given by the caller.
+
+    Unfortunately cgi.FieldStorage is not generic enough, to adapt the
+    list of constructor parameters, by just deriving from it.  Thus
+    the list is specified within the environ dict, given to the
+    constructor.  This is ugly and could be fixed by a simple patch
+    against cgi.FieldStorage.
+    """
+
+    def __init__(self, fp=None, headers=None, outerboundary="",
+                 environ=os.environ, keep_blank_values=0, strict_parsing=0):
+        self._filelist = environ.get(FILELIST_ENV_ENTRY, [])
+        cgi.FieldStorage.__init__(self, fp, headers, outerboundary,
+                                  environ, keep_blank_values,
+                                  strict_parsing)
+
+    def make_file(self, binary=None):
+        import tempfile
+        res = tempfile.TemporaryFile("w+b")
+        self._filelist.append(res)
+        return res
+
+    
 class HTTPRequest(BaseRequest):
     """\
     Model HTTP request data.
@@ -125,10 +156,15 @@
 
     def retry(self):
         self.retry_count=self.retry_count+1
-        self.stdin.seek(0)
+        if not self._fs:                # not really needed
+            raise ValueError, "Retrying on partially initialized request is not supported.  Call processInputs()."
+        for f in self._fs_filelist:
+            f.seek(0)
         r=self.__class__(stdin=self.stdin,
                          environ=self._orig_env,
-                         response=self.response.retry()
+                         response=self.response.retry(),
+                         fs = self._fs,
+                         flist = self._fs_filelist
                          )
         r.retry_count=self.retry_count
         return r
@@ -138,6 +174,8 @@
         # removing tempfiles.
         self.stdin = None
         self._file = None
+        self._fs = None
+        self._fs_filelist = None
         self.form.clear()
         # we want to clear the lazy dict here because BaseRequests don't have
         # one.  Without this, there's the possibility of memory leaking
@@ -237,7 +275,7 @@
         """
         return self._client_addr
 
-    def __init__(self, stdin, environ, response, clean=0):
+    def __init__(self, stdin, environ, response, clean=0, fs=None, flist=None):
         self._orig_env=environ
         # Avoid the overhead of scrubbing the environment in the
         # case of request cloning for traversal purposes. If the
@@ -261,7 +299,11 @@
         self.steps=[]
         self._steps=[]
         self._lazies={}
-
+        self._fs = fs
+        if flist is None:
+            self._fs_filelist = []
+        else:
+            self._fs_filelist = flist
 
         if environ.has_key('REMOTE_ADDR'):
             self._client_addr = environ['REMOTE_ADDR']
@@ -382,23 +424,26 @@
         taintedform=self.taintedform
 
         meth=None
-        fs=FieldStorage(fp=fp,environ=environ,keep_blank_values=1)
-        if not hasattr(fs,'list') or fs.list is None:
+        if not self._fs:
+            fs_env = environ.copy()
+            fs_env[FILELIST_ENV_ENTRY] = self._fs_filelist
+            self._fs=ZFieldStorage(fp=fp,environ=fs_env,keep_blank_values=1)
+        if not hasattr(self._fs,'list') or self._fs.list is None:
             # Hm, maybe it's an XML-RPC
-            if (fs.headers.has_key('content-type') and
-                fs.headers['content-type'] == 'text/xml' and
+            if (self._fs.headers.has_key('content-type') and
+                self._fs.headers['content-type'] == 'text/xml' and
                 method == 'POST'):
                 # Ye haaa, XML-RPC!
                 global xmlrpc
                 if xmlrpc is None: import xmlrpc
-                meth, self.args = xmlrpc.parse_input(fs.value)
+                meth, self.args = xmlrpc.parse_input(self._fs.value)
                 response=xmlrpc.response(response)
                 other['RESPONSE']=self.response=response
                 self.maybe_webdav_client = 0
             else:
-                self._file=fs.file
+                self._file=self._fs.file
         else:
-            fslist=fs.list
+            fslist=self._fs.list
             tuple_items={}
             lt=type([])
             CGI_name=isCGI_NAME
_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope )

Reply via email to