[Zope3-checkins] SVN: Zope3/branches/Zope-3.1/src/zope/app/file/browser/file.py use proper content-type parsing when checking for a charset declaration

Fred L. Drake, Jr. fdrake at gmail.com
Mon Aug 1 11:00:06 EDT 2005


Log message for revision 37621:
  use proper content-type parsing when checking for a charset declaration
  (backported from trunk revision 37589)
  

Changed:
  U   Zope3/branches/Zope-3.1/src/zope/app/file/browser/file.py

-=-
Modified: Zope3/branches/Zope-3.1/src/zope/app/file/browser/file.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/file/browser/file.py	2005-08-01 14:57:31 UTC (rev 37620)
+++ Zope3/branches/Zope-3.1/src/zope/app/file/browser/file.py	2005-08-01 15:00:06 UTC (rev 37621)
@@ -20,6 +20,7 @@
 
 import zope.event
 
+from zope.publisher import contenttype
 from zope.schema import Text
 from zope.app import content_types
 from zope.app.event import objectevent
@@ -391,6 +392,8 @@
         'ASCII'
 
     """
-    if 'charset=' not in content_type:
-        return 'ASCII'
-    return content_type.split('charset=')[1]
+    if content_type and content_type.strip():
+        major, minor, params = contenttype.parse(content_type)
+        return params.get("charset", "ASCII")
+    else:
+        return "ASCII"



More information about the Zope3-Checkins mailing list