[Checkins] SVN: Zope/trunk/lib/python/Products/PageTemplates/ removed content-type restrictions (text/html, text/xml only)

Andreas Jung andreas at andreas-jung.com
Thu Jan 11 12:13:15 EST 2007


Log message for revision 71927:
  removed content-type restrictions (text/html, text/xml only)
  

Changed:
  U   Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
  U   Zope/trunk/lib/python/Products/PageTemplates/utils.py

-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2007-01-11 17:12:29 UTC (rev 71926)
+++ Zope/trunk/lib/python/Products/PageTemplates/ZopePageTemplate.py	2007-01-11 17:13:14 UTC (rev 71927)
@@ -126,7 +126,7 @@
         encoding = None
         output_encoding = None
 
-        if content_type == 'text/xml':
+        if content_type in ('text/xml',):
 
             if is_unicode:
                 encoding = None
@@ -136,7 +136,7 @@
                 output_encoding = 'utf-8'
             
 
-        elif content_type == 'text/html':
+        elif content_type in ('text/html',) :
 
             charset = charsetFromMetaEquiv(text)
 
@@ -156,7 +156,10 @@
                     output_encoding = 'iso-8859-15'
 
         else:
-            raise ValueError('Unsupported content-type %s' % content_type)
+            utext, encoding = convertToUnicode(text, 
+                                               content_type, 
+                                               preferred_encodings)
+            output_encoding = encoding
 
         # for content updated through WebDAV, FTP 
         if not keep_output_encoding:
@@ -228,8 +231,8 @@
             text = file.read()
 
         content_type = guess_type(filename, text)   
-        if not content_type in ('text/html', 'text/xml'):
-            raise ValueError('Unsupported mimetype: %s' % content_type)
+#        if not content_type in ('text/html', 'text/xml'):
+#            raise ValueError('Unsupported mimetype: %s' % content_type)
 
         self.pt_edit(text, content_type)
         return self.pt_editForm(manage_tabs_message='Saved changes')

Modified: Zope/trunk/lib/python/Products/PageTemplates/utils.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/utils.py	2007-01-11 17:12:29 UTC (rev 71926)
+++ Zope/trunk/lib/python/Products/PageTemplates/utils.py	2007-01-11 17:13:14 UTC (rev 71927)
@@ -70,20 +70,19 @@
     elif content_type.startswith('text/html'):
 
         encoding = charsetFromMetaEquiv(source)
+        if encoding:
+            return unicode(source, encoding), encoding  
 
-        # Try to detect the encoding by converting it unicode without raising
-        # exceptions. There are some smarter Python-based sniffer methods
-        # available however we have to check their licenses first before
-        # including them into the Zope 2 core
+    # Try to detect the encoding by converting it unicode without raising
+    # exceptions. There are some smarter Python-based sniffer methods
+    # available however we have to check their licenses first before
+    # including them into the Zope 2 core
 
-        if not encoding:
-            for enc in preferred_encodings:
-                try:
-                    return unicode(source, enc), enc
-                except UnicodeDecodeError:
-                    continue
+    for enc in preferred_encodings:
+        try:
+            return unicode(source, enc), enc
+        except UnicodeDecodeError:
+                continue
 
-        raise TypeError('Could not auto-detect encoding')
+    return unicode(source), None
 
-    else:
-        raise ValueError('Unsupported content-type: %s' % content_type) 



More information about the Checkins mailing list