[Erp5-report] r23644 - in /erp5/trunk/products: ERP5/Document/Image.py ERP5OOo/OOoTemplate.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Sep 16 19:21:45 CEST 2008


Author: jm
Date: Tue Sep 16 19:21:45 2008
New Revision: 23644

URL: http://svn.erp5.org?rev=23644&view=rev
Log:
* Accept single quotes for attributes in <office:include> and <office:include_img>.
* Use mimetypes.guess_extension to get the extension from the content_type.
* Recognize BMP files in Image documents.

Modified:
    erp5/trunk/products/ERP5/Document/Image.py
    erp5/trunk/products/ERP5OOo/OOoTemplate.py

Modified: erp5/trunk/products/ERP5/Document/Image.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Image.py?rev=23644&r1=23643&r2=23644&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Image.py (original)
+++ erp5/trunk/products/ERP5/Document/Image.py Tue Sep 16 19:21:45 2008
@@ -31,6 +31,7 @@
 
 import os
 import string
+import struct
 import sys
 import time
 import subprocess
@@ -118,10 +119,16 @@
       TODO:
       - use image magick or PIL
     """
+    self.size = len(self.data)
     content_type, width, height = getImageInfo(self.data)
+    if not content_type:
+      if self.size >= 30 and self.data[:2] == 'BM':
+        header = struct.unpack('<III', self.data[14:26])
+        if header[0] >= 12:
+          content_type = 'image/x-bmp'
+          width, height = header[1:]
     self.height = height
     self.width = width
-    self.size = len(self.data)
     self._setContentType(content_type)
 
   

Modified: erp5/trunk/products/ERP5OOo/OOoTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/OOoTemplate.py?rev=23644&r1=23643&r2=23644&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/OOoTemplate.py (original)
+++ erp5/trunk/products/ERP5OOo/OOoTemplate.py Tue Sep 16 19:21:45 2008
@@ -27,6 +27,7 @@
 ##############################################################################
 
 from types import StringType
+from mimetypes import guess_extension
 from zLOG import LOG
 from zLOG import PROBLEM
 from OFS.Image import File
@@ -242,7 +243,7 @@
 
   def renderIncludes(self, here, text, sub_document=None):
     attached_files_dict = {}
-    arguments_re = re.compile('(\S+?)\s*=\s*"(.*?)"\s*',re.DOTALL)
+    arguments_re = re.compile('''(\S+?)\s*=\s*('|")(.*?)\\2\s*''',re.DOTALL)
     def getLengthInfos( opts_dict, opts_names ):
       ret = []
       for opt_name in opts_names:
@@ -257,9 +258,8 @@
       return ret
 
     def replaceIncludes(match):
-      tag_string = match.group(1)
       # Build a dictionary with tag parameters
-      options_dict = dict(arguments_re.findall(tag_string))
+      options_dict = dict((x[0], x[2]) for x in arguments_re.findall(match.group(1)))
       # Find the page template based on the path and remove path from dict
       document = self._resolvePath(options_dict['path'].encode())
       document_text = ZopePageTemplate.pt_render(document) # extra_context is missing
@@ -339,7 +339,7 @@
 
     def replaceIncludesImg(match):
       options_dict = { 'text:anchor-type': 'paragraph' }
-      options_dict.update(arguments_re.findall(match.group(1)))
+      options_dict.update((x[0], x[2]) for x in arguments_re.findall(match.group(1)))
       for old_name, name, default in (('x', 'svg:x', '0cm'),
                                       ('y', 'svg:y', '0cm'),
                                       ('style', 'draw:style-name', 'fr1')):
@@ -372,9 +372,6 @@
         picture_type = picture.content_type
         if not is_standard_filetype:
           picture_type = picture_type()
-
-      if '/' not in picture_type:
-        picture_type = 'image/' + picture_type
 
       w, h, maxwidth, maxheight = getLengthInfos(options_dict,
                                   ('width', 'height', 'maxwidth', 'maxheight'))
@@ -407,7 +404,8 @@
         w = h * aspect_ratio
 
       actual_idx = self.document_counter.next()
-      pic_name = 'Pictures/picture%d.%s' % (actual_idx, picture_type.split('/')[-1])
+      pic_name = 'Pictures/picture%d%s' \
+                 % (actual_idx, guess_extension(picture_type) or '')
 
       # XXX: Pictures directory not managed (seems facultative)
       #  <manifest:file-entry manifest:media-type="" manifest:full-path="ObjBFE4F50D/Pictures/"/>




More information about the Erp5-report mailing list