[CMF-checkins] SVN: CMF/branches/1.5/C - CMFDefault.Image and CMFDefault.File: When calling the constructor,

Jens Vagelpohl jens at dataflake.org
Sat Aug 13 16:36:17 EDT 2005


Log message for revision 37921:
  - CMFDefault.Image and CMFDefault.File: When calling the constructor,
    any intelligent content type detection would be destroyed by the
    call to initialize Dublin Core values, which would overwrite the
    content_type. It is now preserved, if possible.
    (http://www.zope.org/Collectors/CMF/370) 
  

Changed:
  U   CMF/branches/1.5/CHANGES.txt
  U   CMF/branches/1.5/CMFDefault/File.py
  U   CMF/branches/1.5/CMFDefault/Image.py
  U   CMF/branches/1.5/CMFDefault/tests/test_Image.py

-=-
Modified: CMF/branches/1.5/CHANGES.txt
===================================================================
--- CMF/branches/1.5/CHANGES.txt	2005-08-13 19:33:23 UTC (rev 37920)
+++ CMF/branches/1.5/CHANGES.txt	2005-08-13 20:36:17 UTC (rev 37921)
@@ -1,4 +1,4 @@
-CMF 1.5.4-beta (unreleased)
+After CMF 1.5.3
 
   Bug Fixes
 
@@ -7,6 +7,12 @@
       checkIdAvailable() now make sure non-managers can't create objects with
       IDs already taken by Method Aliases of the current folder.
 
+    - CMFDefault.Image and CMFDefault.File: When calling the constructor,
+      any intelligent content type detection would be destroyed by the
+      call to initialize Dublin Core values, which would overwrite the
+      content_type. It is now preserved, if possible.
+      (http://www.zope.org/Collectors/CMF/370)
+
 CMF 1.5.3 (2005/08/07)
 
   Bugs fixed

Modified: CMF/branches/1.5/CMFDefault/File.py
===================================================================
--- CMF/branches/1.5/CMFDefault/File.py	2005-08-13 19:33:23 UTC (rev 37920)
+++ CMF/branches/1.5/CMFDefault/File.py	2005-08-13 20:36:17 UTC (rev 37921)
@@ -148,12 +148,20 @@
                 , contributors=()
                 , effective_date=None
                 , expiration_date=None
-                , format='text/html'
+                , format=None
                 , language='en-US'
                 , rights=''
                 ):
         OFS.Image.File.__init__( self, id, title, file
                                , content_type, precondition )
+
+        # If no file format has been passed in, rely on what OFS.Image.File
+        # detected. Unlike Images, which have code to try and pick the content
+        # type out of the binary data, File objects only provide the correct
+        # type if a "hint" in the form of a filename extension is given.
+        if format is None:
+            format = self.content_type 
+
         DefaultDublinCoreImpl.__init__( self, title, subject, description
                                , contributors, effective_date, expiration_date
                                , format, language, rights )

Modified: CMF/branches/1.5/CMFDefault/Image.py
===================================================================
--- CMF/branches/1.5/CMFDefault/Image.py	2005-08-13 19:33:23 UTC (rev 37920)
+++ CMF/branches/1.5/CMFDefault/Image.py	2005-08-13 20:36:17 UTC (rev 37921)
@@ -140,12 +140,18 @@
                 , contributors=()
                 , effective_date=None
                 , expiration_date=None
-                , format='image/png'
+                , format=None
                 , language='en-US'
                 , rights=''
                 ):
         OFS.Image.File.__init__( self, id, title, file
                                , content_type, precondition )
+
+        # If no file format has been passed in, rely on what OFS.Image.File
+        # detected.
+        if format is None:
+            format = self.content_type
+
         DefaultDublinCoreImpl.__init__( self, title, subject, description
                                , contributors, effective_date, expiration_date
                                , format, language, rights )

Modified: CMF/branches/1.5/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/branches/1.5/CMFDefault/tests/test_Image.py	2005-08-13 19:33:23 UTC (rev 37920)
+++ CMF/branches/1.5/CMFDefault/tests/test_Image.py	2005-08-13 20:36:17 UTC (rev 37921)
@@ -89,7 +89,28 @@
         self.assertEqual(image.Format(), 'image/gif')
         self.assertEqual(image.content_type, 'image/gif')
 
+    def test_ImageContentTypeUponConstruction(self):
+        # Test the content type after calling the constructor with the
+        # file object being passed in (http://www.zope.org/Collectors/CMF/370)
+        testfile = open(TEST_JPG, 'rb')
+        image = Image('testimage', file=testfile)
+        testfile.close()
+        self.assertEqual(image.Format(), 'image/jpeg')
+        self.assertEqual(image.content_type, 'image/jpeg')
 
+    def test_FileContentTypeUponConstruction(self):
+        # Test the content type after calling the constructor with the
+        # file object being passed in (http://www.zope.org/Collectors/CMF/370)
+        testfile = open(TEST_JPG, 'rb')
+        # Notice the cheat? File objects lack the extra intelligence that
+        # picks content types from the actual file data, so it needs to be
+        # helped along with a file extension...
+        file = File('testfile.jpg', file=testfile)
+        testfile.close()
+        self.assertEqual(file.Format(), 'image/jpeg')
+        self.assertEqual(file.content_type, 'image/jpeg')
+
+
 class TestImageCopyPaste(RequestTest):
 
     # Tests related to http://www.zope.org/Collectors/CMF/176



More information about the CMF-checkins mailing list