[Zope-Checkins] SVN: Zope/trunk/lib/python/ZPublisher/ fixes + more tests (Stefan Holek)

Andreas Jung andreas at andreas-jung.com
Wed Dec 21 10:03:13 EST 2005


Log message for revision 40954:
  fixes + more tests (Stefan Holek)
  

Changed:
  U   Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
  U   Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py

-=-
Modified: Zope/trunk/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2005-12-21 15:01:15 UTC (rev 40953)
+++ Zope/trunk/lib/python/ZPublisher/HTTPResponse.py	2005-12-21 15:03:12 UTC (rev 40954)
@@ -333,13 +333,18 @@
                 self.body = body
 
 
+        isHTML = self.isHTML(self.body)
         if not self.headers.has_key('content-type'):
-            isHTML = self.isHTML(self.body)
             if isHTML:
                 c = 'text/html; charset=%s' % default_encoding
             else:
                 c = 'text/plain; charset=%s' % default_encoding
             self.setHeader('content-type', c)
+        else:
+            c = self.headers['content-type']
+            if not 'charset=' in  c:
+                c = '%s; charset=%s' % (c, default_encoding)                
+                self.setHeader('content-type', c)
 
         # Some browsers interpret certain characters in Latin 1 as html
         # special characters. These cannot be removed by html_quote,

Modified: Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py	2005-12-21 15:01:15 UTC (rev 40953)
+++ Zope/trunk/lib/python/ZPublisher/tests/testHTTPResponse.py	2005-12-21 15:03:12 UTC (rev 40954)
@@ -74,7 +74,18 @@
         response.appendHeader('XXX', 'foo')
         self.assertEqual(response.headers.get('xxx'), 'bar,\n\tfoo')
 
+    def test_CharsetNoHeader(self):
+        response = self._makeOne(body='foo')
+        self.assertEqual(response.headers.get('content-type'), 'text/plain; charset=iso-8859-15')
 
+    def test_CharsetTextHeader(self):
+        response = self._makeOne(body='foo', headers={'content-type': 'text/plain'})
+        self.assertEqual(response.headers.get('content-type'), 'text/plain; charset=iso-8859-15')
+
+    def test_CharsetApplicationHeader(self):
+        response = self._makeOne(body='foo', headers={'content-type': 'application/foo'})
+        self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=iso-8859-15')
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(HTTPResponseTests, 'test'))



More information about the Zope-Checkins mailing list