[CMF-checkins] CVS: Products/CMFCore - FSPageTemplate.py:1.27

Jens Vagelpohl jens at dataflake.org
Fri Sep 3 13:58:25 EDT 2004


Update of /cvs-repository/Products/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv32614/CMFCore

Modified Files:
	FSPageTemplate.py 
Log Message:
- FSPageTemplate: Refine the XML content type detection so that
  addtional data such as encoding is preserved
  (http://www.zope.org/Collectors/CMF/228)


=== Products/CMFCore/FSPageTemplate.py 1.26 => 1.27 ===
--- Products/CMFCore/FSPageTemplate.py:1.26	Thu Aug 12 11:07:39 2004
+++ Products/CMFCore/FSPageTemplate.py	Fri Sep  3 13:57:50 2004
@@ -34,7 +34,7 @@
 from utils import _setCacheHeaders
 from utils import expandpath
 
-xml_detect_re = re.compile('^\s*<\?xml\s+')
+xml_detect_re = re.compile('^\s*<\?xml\s+(?:[^>]*?encoding=["\']([^"\'>]+))?')
 _marker = []  # Create a new marker object.
 
 
@@ -84,14 +84,13 @@
         finally:
             file.close()
         if reparse:
-            if xml_detect_re.match(data):
+            xml_info = xml_detect_re.match(data)
+            if xml_info:
                 # Smells like xml
-                self.content_type = 'text/xml'
-            else:
-                try:
-                    del self.content_type
-                except (AttributeError, KeyError):
-                    pass
+                # set "content_type" from the XML declaration
+                encoding = xml_info.group(1) or 'utf-8'
+                self.content_type = 'text/xml; charset=%s' % encoding
+
             self.write(data)
 
     security.declarePrivate('read')



More information about the CMF-checkins mailing list