[Zope-Checkins] SVN: Zope/branches/2.9/lib/python/ZPublisher/ more
tests and fixes
Andreas Jung
andreas at andreas-jung.com
Wed Dec 21 10:12:01 EST 2005
Log message for revision 40956:
more tests and fixes
Changed:
U Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
U Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py
-=-
Modified: Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py 2005-12-21 15:09:16 UTC (rev 40955)
+++ Zope/branches/2.9/lib/python/ZPublisher/HTTPResponse.py 2005-12-21 15:12:00 UTC (rev 40956)
@@ -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/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py
===================================================================
--- Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py 2005-12-21 15:09:16 UTC (rev 40955)
+++ Zope/branches/2.9/lib/python/ZPublisher/tests/testHTTPResponse.py 2005-12-21 15:12:00 UTC (rev 40956)
@@ -1,3 +1,5 @@
+# -*- coding: iso-8859-15 -*-
+
import unittest
class HTTPResponseTests(unittest.TestCase):
@@ -74,7 +76,28 @@
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_CharsetApplicationHeaderUnicode(self):
+ response = self._makeOne(body=unicode('ärger', 'iso-8859-15'), headers={'content-type': 'application/foo'})
+ self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=iso-8859-15')
+ self.assertEqual(response.body, 'ärger')
+
+ def test_CharsetApplicationHeader1Unicode(self):
+ response = self._makeOne(body=unicode('ärger', 'iso-8859-15'), headers={'content-type': 'application/foo; charset=utf-8'})
+ self.assertEqual(response.headers.get('content-type'), 'application/foo; charset=utf-8')
+ self.assertEqual(response.body, unicode('ärger', 'iso-8859-15').encode('utf-8'))
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(HTTPResponseTests, 'test'))
More information about the Zope-Checkins
mailing list