[Zope3-checkins] SVN: Zope3/branches/3.2/ Teach zope.app.file.image.getImageInfo about Windows BMP files.

Marius Gedminas marius at pov.lt
Thu Jun 14 09:57:47 EDT 2007


Log message for revision 76698:
  Teach zope.app.file.image.getImageInfo about Windows BMP files.
  
  Merged revision 76693 from trunk with
  
    svn merge -r 76692:76693 svn://svn.zope.org/repos/main/zope.app.file/trunk/src/zope/app/file
  
  

Changed:
  U   Zope3/branches/3.2/doc/CHANGES.txt
  U   Zope3/branches/3.2/src/zope/app/file/image.py
  U   Zope3/branches/3.2/src/zope/app/file/tests/test_image.py
  U   Zope3/branches/3.2/zopeskel/etc/overrides.zcml

-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt	2007-06-14 13:52:54 UTC (rev 76697)
+++ Zope3/branches/3.2/doc/CHANGES.txt	2007-06-14 13:57:46 UTC (rev 76698)
@@ -10,6 +10,8 @@
 
     Bug fixes
 
+      - zope.app.file.image couldn't recognize Windows BMP files.
+
       - Ensured that 'zope.interface.ImplementedBy' is picklable
         (fixes obscure ZClass test bug in Zope 2.9).
 

Modified: Zope3/branches/3.2/src/zope/app/file/image.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/file/image.py	2007-06-14 13:52:54 UTC (rev 76697)
+++ Zope3/branches/3.2/src/zope/app/file/image.py	2007-06-14 13:57:46 UTC (rev 76698)
@@ -153,4 +153,11 @@
         except ValueError:
             pass
 
+    # handle BMPs
+    elif (size >= 30) and data.startswith('BM'):
+        kind = struct.unpack("<H", data[14:16])[0]
+        if kind == 40: # Windows 3.x bitmap
+            content_type = 'image/x-ms-bmp'
+            width, height = struct.unpack("<LL", data[18:26])
+
     return content_type, width, height

Modified: Zope3/branches/3.2/src/zope/app/file/tests/test_image.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/file/tests/test_image.py	2007-06-14 13:52:54 UTC (rev 76697)
+++ Zope3/branches/3.2/src/zope/app/file/tests/test_image.py	2007-06-14 13:57:46 UTC (rev 76698)
@@ -160,6 +160,18 @@
         from zope.app.file.image import getImageInfo
         t, w, h = getImageInfo("\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00\xff\xdb\x00C")
 
+    def test_getImageInfo_bmp(self):
+        from zope.app.file.image import getImageInfo
+        t, w, h = getImageInfo('BMl\x05\x00\x00\x00\x00\x00\x006\x04\x00\x00('
+                               '\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00\x00'
+                               '\x01\x00\x08\x00\x01\x00\x00\x006\x01\x00\x00'
+                               '\x12\x0b\x00\x00\x12\x0b\x00\x00\x00\x01\x00'
+                               '... and so on ...')
+        self.assertEqual(t, "image/x-ms-bmp")
+        self.assertEqual(w, 16)
+        self.assertEqual(h, 16)
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestImage),

Modified: Zope3/branches/3.2/zopeskel/etc/overrides.zcml
===================================================================
--- Zope3/branches/3.2/zopeskel/etc/overrides.zcml	2007-06-14 13:52:54 UTC (rev 76697)
+++ Zope3/branches/3.2/zopeskel/etc/overrides.zcml	2007-06-14 13:57:46 UTC (rev 76698)
@@ -6,4 +6,10 @@
   <!-- For example, define a different default skin -->
   <!-- <browser:defaultSkin name="" /> -->
 
+  <ivija:reportgenDaemon
+      outdir="reports"
+      pdfdir="pdfs"
+      />
+
+
 </configure>



More information about the Zope3-Checkins mailing list