[Zope3-checkins] SVN: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/mimefield.py Use the standard Field __init__. Inheriting from Bytes does show an upload

Janko Hauser jhauser at zscout.de
Sun Jan 16 14:59:10 EST 2005


Log message for revision 28850:
  Use the standard Field __init__. Inheriting from Bytes does show an upload 
  field if used in a schema.
  

Changed:
  U   Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/mimefield.py

-=-
Modified: Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/mimefield.py
===================================================================
--- Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/mimefield.py	2005-01-16 18:12:14 UTC (rev 28849)
+++ Zope3/branches/jhauser-filefieldwidget/src/zope/app/file/mimefield.py	2005-01-16 19:59:10 UTC (rev 28850)
@@ -13,7 +13,7 @@
 ##############################################################################
 """File content component
 
-$Id: $
+$Id:$
 """
 __docformat__ = 'restructuredtext'
 
@@ -21,10 +21,10 @@
 from transaction import get_transaction
 from zope.interface import implements
 
-from zope.schema.interfaces import IBytesLine
+from zope.schema.interfaces import IBytes
 from zope.schema._bootstrapfields import Field
 from zope.schema._bootstrapfields import TextLine
-from zope.schema._field import BytesLine
+from zope.schema._field import Bytes
 from zope.app.file.file import File
 
 from zope.i18nmessageid import MessageIDFactory
@@ -35,7 +35,7 @@
 #
 # The basic schema interface
 #
-class IMime(IBytesLine):
+class IMime(IBytes):
     u"""Fields which hold data characterized by a mime type.
 
     The data is stored memory effecient.
@@ -56,10 +56,9 @@
     filename = TextLine(title=_(u"Filename"),
                         description=_(u"The Filename of the uploaded file"),
                         required=False)
-
     
- # The field implementation                       
-class FileData(BytesLine, File):
+# The field implementation                       
+class FileData(Bytes, File):
     """A field implementation for uploaded files. 
 
     Let's test the constructor:
@@ -147,29 +146,29 @@
     Last, but not least, verify the interface:
 
     >>> from zope.interface.verify import verifyClass
-    >>> IFile.implementedBy(File)
+    >>> IFile.implementedBy(FileData)
     True
-    >>> verifyClass(IFile, File)
+    >>> verifyClass(IFile, FileData)
     True
     """
 
     implements(IFileData, IFile)
 
-    def __init__(self, data='', contentType=''):
-        self.data = data
-        # instead of mimeType we use contentType as it is mandated by IFile
-        self.contentType = contentType
-        self.filename = self._extractFilename(data)
-
     def _setdata(self, data):
         File._setdata(data)
+        print 'setting data', type(data)
         self.filename = self._extractFilename(data)
+        self.contentType = self._extractContentType(data)
 
+    def _extractContentType(self, data):
+        u"""Extract the content type for the given data"""
+        return 'application/octet-stream'
+    
     def _extractFilename(self, data):
         # if it is a fileupload object
         if hasattr(data,'filename'):
             fid = data.filename
-            # prepare from ospath filenames from explorer.
+            # some browsers include the full pathname
             fid=fid[max(fid.rfind('/'),
                         fid.rfind('\\'),
                         fid.rfind(':')



More information about the Zope3-Checkins mailing list