[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser - BrowserRequest.py:1.1.4.7

Gary Poster garyposter@earthlink.net
Wed, 27 Mar 2002 21:12:11 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser
In directory cvs.zope.org:/tmp/cvs-serv24597/Browser

Modified Files:
      Tag: Zope-3x-branch
	BrowserRequest.py 
Log Message:
Added FileUpload class from Zope 2 so FileUploads could work



=== Zope3/lib/python/Zope/Publisher/Browser/BrowserRequest.py 1.1.4.6 => 1.1.4.7 ===
     ############################################################
 
+class FileUpload:
+    '''\
+    File upload objects
+
+    File upload objects are used to represent file-uploaded data.
+
+    File upload objects can be used just like files.
+
+    In addition, they have a 'headers' attribute that is a dictionary
+    containing the file-upload headers, and a 'filename' attribute
+    containing the name of the uploaded file.
+    '''
+
+    # Allow access to attributes such as headers and filename so
+    # that ZClass authors can use DTML to work with FileUploads.
+    __allow_access_to_unprotected_subobjects__=1
+
+    def __init__(self, aFieldStorage):
+
+        file=aFieldStorage.file
+        if hasattr(file, '__methods__'): methods=file.__methods__
+        else: methods= ['close', 'fileno', 'flush', 'isatty',
+                        'read', 'readline', 'readlines', 'seek',
+                        'tell', 'truncate', 'write', 'writelines']
+
+        d=self.__dict__
+        for m in methods:
+            if hasattr(file,m): d[m]=getattr(file,m)
+
+        self.headers=aFieldStorage.headers
+        self.filename=aFieldStorage.filename
+
+        # Add an assertion to the rfc822.Message object that implements
+        # self.headers so that managed code can access them.
+        try:    self.headers.__allow_access_to_unprotected_subobjects__ = 1
+        except: pass
+
 class RedirectingBrowserRequest(BrowserRequest):
     """Browser requests that redirect when the actual and effective URLs differ
     """