[Zope-Checkins] SVN: Zope/branches/2.9/ For content-type HTTP
headers starting with 'text/' or 'application/'
Andreas Jung
andreas at andreas-jung.com
Tue Dec 20 01:18:02 EST 2005
Log message for revision 40891:
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/branches/2.9/doc/CHANGES.txt
U Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
-=-
Modified: Zope/branches/2.9/doc/CHANGES.txt
===================================================================
--- Zope/branches/2.9/doc/CHANGES.txt 2005-12-20 06:16:14 UTC (rev 40890)
+++ Zope/branches/2.9/doc/CHANGES.txt 2005-12-20 06:18:01 UTC (rev 40891)
@@ -27,6 +27,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/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py 2005-12-20 06:16:14 UTC (rev 40890)
+++ Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py 2005-12-20 06:18:01 UTC (rev 40891)
@@ -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