[CMF-checkins] SVN: CMF/trunk/CMFDefault/ - CMFDefault.Image and
CMFDefault.File: When calling the constructor,
Jens Vagelpohl
jens at dataflake.org
Sat Aug 13 16:37:52 EDT 2005
Log message for revision 37922:
- 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/trunk/CMFDefault/File.py
U CMF/trunk/CMFDefault/Image.py
U CMF/trunk/CMFDefault/tests/test_Image.py
-=-
Modified: CMF/trunk/CMFDefault/File.py
===================================================================
--- CMF/trunk/CMFDefault/File.py 2005-08-13 20:36:17 UTC (rev 37921)
+++ CMF/trunk/CMFDefault/File.py 2005-08-13 20:37:52 UTC (rev 37922)
@@ -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/trunk/CMFDefault/Image.py
===================================================================
--- CMF/trunk/CMFDefault/Image.py 2005-08-13 20:36:17 UTC (rev 37921)
+++ CMF/trunk/CMFDefault/Image.py 2005-08-13 20:37:52 UTC (rev 37922)
@@ -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/trunk/CMFDefault/tests/test_Image.py
===================================================================
--- CMF/trunk/CMFDefault/tests/test_Image.py 2005-08-13 20:36:17 UTC (rev 37921)
+++ CMF/trunk/CMFDefault/tests/test_Image.py 2005-08-13 20:37:52 UTC (rev 37922)
@@ -81,7 +81,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