[Zope-Checkins] SVN: Zope/trunk/ - For content-type HTTP headers starting with 'text/' or 'application/'

Andreas Jung andreas at andreas-jung.com
Tue Dec 20 01:16:16 EST 2005


Log message for revision 40890:
    - For content-type HTTP headers starting with 'text/' or 'application/'
      the 'charset' field is automatically if not specified by the
      application. The 'charset' is determined by the content-type header
      specified by the application (if available) or from the
      zpublisher_default_encoding value as configured in etc/zope.conf
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/ZPublisher/HTTPResponse.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-12-19 23:03:14 UTC (rev 40889)
+++ Zope/trunk/doc/CHANGES.txt	2005-12-20 06:16:14 UTC (rev 40890)
@@ -124,6 +124,12 @@
 
     Bugs Fixed
 
+      - For content-type HTTP headers starting with 'text/' or 'application/'
+        the 'charset' field is automatically if not specified by the
+        application. The 'charset' is determined by the content-type header
+        specified by the application (if available) or from the
+        zpublisher_default_encoding value as configured in etc/zope.conf
+
       - Collector #1976: FTP STOR command would load the file being
         uploaded in memory. Changed to use a TemporaryFile.
 

Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2005-12-19 23:03:14 UTC (rev 40889)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2005-12-20 06:16:14 UTC (rev 40890)
@@ -1,9 +1,9 @@
 #############################################################################
 #
-# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@@ -336,9 +336,9 @@
         if not self.headers.has_key('content-type'):
             isHTML = self.isHTML(self.body)
             if isHTML:
-                c = 'text/html'
+                c = 'text/html; charset=%s' % default_encoding
             else:
-                c = 'text/plain'
+                c = 'text/plain; charset=%s' % default_encoding
             self.setHeader('content-type', c)
 
         # Some browsers interpret certain characters in Latin 1 as html
@@ -440,11 +440,18 @@
                                               r')(?:(?:\s*;)|\Z)',
                                               re.IGNORECASE)):
         # Encode the Unicode data as requested
+
         if self.headers.has_key('content-type'):
             match = charset_re.match(self.headers['content-type'])
             if match:
                 encoding = match.group(1)
                 return body.encode(encoding)
+            else:
+
+                ct = self.headers['content-type']
+                if ct.startswith('text/') or ct.startswith('application/'):
+                    self.headers['content-type'] = '%s; charset=%s' % (ct, default_encoding)
+
         # Use the default character encoding
         return body.encode(default_encoding,'replace')
 



More information about the Zope-Checkins mailing list