[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP/tests - testHTTPCharsets.py:1.2 testHTTP.py:1.5

Stephan Richter srichter@cbu.edu
Fri, 14 Jun 2002 12:50:52 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP/tests
In directory cvs.zope.org:/tmp/cvs-serv18258/lib/python/Zope/Publisher/HTTP/tests

Modified Files:
	testHTTP.py 
Added Files:
	testHTTPCharsets.py 
Log Message:
Finished Zope 3 Unicode support. Zope 3 should now be able to handle all 
unicode formats. Note that ebcoding and decoding unicode strings is based
on the parameters we get from the browser in HTTP_ACCEPT_CHARSET.

All "text strings" (strings that represent human language text) internally 
in Zope 3 should be unicode strings from now on! I have not checked all of 
Zope 3, so if you see a non-unicode text string somewhere, please convert
it simply by putting 'u' before the string literal.

Note that binary data, such as images are not to be encoded. 

The encoding happens on the HTTPRequest/HTTPResponse abstraction level. 
That means that currenty FTP does not profit from this new code; however
FTP is always data anyhow.


=== Zope3/lib/python/Zope/Publisher/HTTP/tests/testHTTPCharsets.py 1.1 => 1.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# 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
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""Retrieval of HTTP character set information.
+
+$Id$
+"""
+import unittest, sys
+
+from Zope.Publisher.HTTP.HTTPCharsets import HTTPCharsets
+
+
+class HTTPCharsetTest(unittest.TestCase):
+
+    def testGetPreferredCharset(self):
+        request = {'HTTP_ACCEPT_CHARSET':
+                   'ISO-8859-1, UTF-8;q=0.66, UTF-16;q=0.33'}
+
+        http_charsets = HTTPCharsets(request)
+
+        self.assertEqual(list(http_charsets.getPreferredCharsets()),
+                         ['UTF-8', 'ISO-8859-1', 'UTF-16'])
+
+
+def test_suite():
+    loader=unittest.TestLoader()
+    return loader.loadTestsFromTestCase(HTTPCharsetTest)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/lib/python/Zope/Publisher/HTTP/tests/testHTTP.py 1.4 => 1.5 ===
         'GATEWAY_INTERFACE':  'TestFooInterface/1.0',
         'HTTP_OFF_THE_WALL':  "Spam 'n eggs",
+        'HTTP_ACCEPT_CHARSET': 'ISO-8859-1, UTF-8;q=0.66, UTF-16;q=0.33', 
     }
     
     def setUp(self):