[Checkins] SVN: Zope/branches/2.9-with-ZODB3.8/ - backported feature to support named temporary files

Christian Theune ct at gocept.com
Fri Mar 9 16:27:51 EST 2007


Log message for revision 73132:
   - backported feature to support named temporary files
  

Changed:
  U   Zope/branches/2.9-with-ZODB3.8/doc/CHANGES.txt
  U   Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/HTTPRequest.py
  U   Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/tests/testHTTPRequest.py

-=-
Modified: Zope/branches/2.9-with-ZODB3.8/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9-with-ZODB3.8/doc/CHANGES.txt	2007-03-09 21:00:06 UTC (rev 73131)
+++ Zope/branches/2.9-with-ZODB3.8/doc/CHANGES.txt	2007-03-09 21:27:51 UTC (rev 73132)
@@ -4,6 +4,10 @@
   Change information for previous versions of Zope can be found in the
   file HISTORY.txt.
 
+  Blob-support branch
+
+      - Backported feature from Zope 2.11 to support named temporary files.
+
   Zope 2.9.7 (unreleased)
 
    Bugs fixed

Modified: Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/HTTPRequest.py	2007-03-09 21:00:06 UTC (rev 73131)
+++ Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/HTTPRequest.py	2007-03-09 21:27:51 UTC (rev 73132)
@@ -13,7 +13,7 @@
 
 __version__='$Revision: 1.96 $'[11:-2]
 
-import re, sys, os, time, random, codecs
+import re, sys, os, time, random, codecs, tempfile
 from types import StringType, UnicodeType
 from BaseRequest import BaseRequest, quote
 from HTTPResponse import HTTPResponse
@@ -383,7 +383,7 @@
         taintedform=self.taintedform
 
         meth=None
-        fs=FieldStorage(fp=fp,environ=environ,keep_blank_values=1)
+        fs=ZopeFieldStorage(fp=fp,environ=environ,keep_blank_values=1)
         if not hasattr(fs,'list') or fs.list is None:
             # Hm, maybe it's an XML-RPC
             if (fs.headers.has_key('content-type') and
@@ -1395,7 +1395,11 @@
         except: pass
     return dict
 
+class ZopeFieldStorage(FieldStorage):
 
+    def make_file(self, binary=None):
+        return tempfile.NamedTemporaryFile("w+b")
+
 class FileUpload:
     '''\
     File upload objects
@@ -1420,7 +1424,7 @@
         else: methods= ['close', 'fileno', 'flush', 'isatty',
                         'read', 'readline', 'readlines', 'seek',
                         'tell', 'truncate', 'write', 'writelines',
-                        '__iter__','next'] # see Collector 1837
+                        '__iter__','next', 'name'] # see Collector 1837
 
         d=self.__dict__
         for m in methods:

Modified: Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/tests/testHTTPRequest.py	2007-03-09 21:00:06 UTC (rev 73131)
+++ Zope/branches/2.9-with-ZODB3.8/lib/python/ZPublisher/tests/testHTTPRequest.py	2007-03-09 21:27:51 UTC (rev 73132)
@@ -1,6 +1,15 @@
 import unittest
 from urllib import quote_plus
 
+TEST_LARGEFILE_DATA = '''
+--12345
+Content-Disposition: form-data; name="file"; filename="file"
+Content-Type: application/octet-stream
+
+test %s
+
+''' % ('test' * 1000)
+
 class AuthCredentialsTestsa( unittest.TestCase ):
 
     def _getTargetClass(self):
@@ -684,6 +693,17 @@
         req.close()
         self.assertEqual(start_count, sys.getrefcount(s))  # The test
 
+    def testFileName(self):
+        # checks fileupload object supports the filename
+        from StringIO import StringIO
+        s = StringIO(TEST_LARGEFILE_DATA)
+        env = TEST_ENVIRON.copy()
+        from ZPublisher.HTTPRequest import HTTPRequest
+        req = HTTPRequest(s, env, None)
+        req.processInputs()
+        f = req.form.get('file')
+        self.assert_(f.name)
+
     def testFileIterator(self):
         # checks fileupload object supports the iterator protocol
         # collector entry 1837



More information about the Checkins mailing list