[Zope3-checkins] SVN: Zope3/trunk/ - zope.pagetemplate.pagetemplatefile introspects the html http-equiv

Christian Zagrodnick cz at gocept.com
Wed Mar 7 05:44:04 EST 2007


Log message for revision 73025:
  - zope.pagetemplate.pagetemplatefile introspects the html http-equiv
    header to guess the content encoding. This did not work for XHTML
    content.
  
  - zope.app.publisher.browser.pagetemplateresource sets the Content-Type
    header like the other page templates do it.
  
  
  This basically fixes page templates in resource directories having a byte order
  mark. Those were delivered as text/plain.
  
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/publication/httpfactory.txt
  U   Zope3/trunk/src/zope/app/publisher/browser/pagetemplateresource.py
  U   Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py
  U   Zope3/trunk/src/zope/pagetemplate/pagetemplatefile.py
  U   Zope3/trunk/src/zope/pagetemplate/tests/test_htmltests.py
  U   Zope3/trunk/src/zope/pagetemplate/tests/test_ptfile.py
  U   Zope3/trunk/src/zope/testbrowser/README.txt

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/doc/CHANGES.txt	2007-03-07 10:44:01 UTC (rev 73025)
@@ -189,6 +189,13 @@
 
     Bug fixes
 
+      - zope.pagetemplate.pagetemplatefile introspects the html http-equiv
+        header to guess the content encoding. This did not work for XHTML
+        content.
+
+      - zope.app.publisher.browser.pagetemplateresource sets the Content-Type
+        header like the other page templates do it.
+
       - Fixed zope.app.cache.ram.RAMCache which ignored the
         cleanupInterval.
         

Modified: Zope3/trunk/src/zope/app/publication/httpfactory.txt
===================================================================
--- Zope3/trunk/src/zope/app/publication/httpfactory.txt	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/app/publication/httpfactory.txt	2007-03-07 10:44:01 UTC (rev 73025)
@@ -14,14 +14,14 @@
   ... GET / HTTP/1.1
   ... """)
   HTTP/1.1 200 Ok
-  Content-Length: 4402
+  Content-Length: 4322
   Content-Type: text/html;charset=utf-8
   ...
   >>> print http(r"""
   ... POST / HTTP/1.1
   ... """)
   HTTP/1.1 200 Ok
-  Content-Length: 4402
+  Content-Length: 4322
   Content-Type: text/html;charset=utf-8
   ...
   >>> print http(r"""

Modified: Zope3/trunk/src/zope/app/publisher/browser/pagetemplateresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/pagetemplateresource.py	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/app/publisher/browser/pagetemplateresource.py	2007-03-07 10:44:01 UTC (rev 73025)
@@ -39,6 +39,9 @@
 
     def __call__(self):
         pt = self.context
+        response = self.request.response
+        if not response.getHeader("Content-Type"):
+            response.setHeader("Content-Type", pt.content_type)
         return pt(self.request)
 
 class PageTemplateResourceFactory(object):

Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_pagetemplateresource.py	2007-03-07 10:44:01 UTC (rev 73025)
@@ -30,12 +30,15 @@
      PageTemplateResourceFactory
 import zope.app.publisher.browser.tests as p
 
+
 test_directory = os.path.dirname(p.__file__)
 
+
 checker = NamesChecker(
     ('__call__', 'request', 'publishTraverse')
     )
 
+
 class Test(PlacelessSetup, TestCase):
 
     def setUp(self):
@@ -56,10 +59,14 @@
         request = TestRequest(test_data=test_data)
         factory = PageTemplateResourceFactory(path, checker, 'testresource.pt')
         resource = factory(request)
-        self.assert_(resource(), test_data)        
+        self.assert_(resource(), test_data)
+        self.assertEquals('text/html',
+                          request.response.getHeader('Content-Type'))
 
+
 def test_suite():
     return makeSuite(Test)
 
+
 if __name__=='__main__':
     main(defaultTest='test_suite')

Modified: Zope3/trunk/src/zope/pagetemplate/pagetemplatefile.py
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/pagetemplatefile.py	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/pagetemplate/pagetemplatefile.py	2007-03-07 10:44:01 UTC (rev 73025)
@@ -31,7 +31,7 @@
 
 meta_pattern = re.compile(
     r'\s*<meta\s+http-equiv=["\']?Content-Type["\']?'
-    r'\s+content=["\']?([^;]+);\s*charset=([^"\']+)["\']?\s*>\s*',
+    r'\s+content=["\']?([^;]+);\s*charset=([^"\']+)["\']?\s*/?\s*>\s*',
     re.IGNORECASE)
 
 def package_home(gdict):

Modified: Zope3/trunk/src/zope/pagetemplate/tests/test_htmltests.py
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/tests/test_htmltests.py	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/pagetemplate/tests/test_htmltests.py	2007-03-07 10:44:01 UTC (rev 73025)
@@ -135,6 +135,7 @@
         out = t(msg=msg)
         util.check_html(expect, out)
 
+
 def test_suite():
     return unittest.makeSuite(HTMLTests)
 

Modified: Zope3/trunk/src/zope/pagetemplate/tests/test_ptfile.py
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/tests/test_ptfile.py	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/pagetemplate/tests/test_ptfile.py	2007-03-07 10:44:01 UTC (rev 73025)
@@ -165,7 +165,23 @@
             u"\u0422\u0435\u0441\u0442"
             u"</title></head></html>\n")
 
+    def test_xhtml(self):
+        pt = self.get_pt(
+            "<html><head><title>"
+            # 'Test' in russian (windows-1251)
+            "\xd2\xe5\xf1\xf2"
+            '</title><meta http-equiv="Content-Type"'
+            ' content="text/html; charset=windows-1251"/>'
+            "</head></html>")
+        rendered = pt()
+        self.failUnless(isinstance(rendered, unicode))
+        self.failUnlessEqual(rendered,
+            u"<html><head><title>"
+            u"\u0422\u0435\u0441\u0442"
+            u"</title></head></html>\n")
 
+
+
 def test_suite():
     return unittest.makeSuite(TypeSniffingTestCase)
 

Modified: Zope3/trunk/src/zope/testbrowser/README.txt
===================================================================
--- Zope3/trunk/src/zope/testbrowser/README.txt	2007-03-06 23:54:42 UTC (rev 73024)
+++ Zope3/trunk/src/zope/testbrowser/README.txt	2007-03-07 10:44:01 UTC (rev 73025)
@@ -140,7 +140,6 @@
     Status: 200 Ok
     Content-Length: ...
     Content-Type: text/html;charset=utf-8
-    X-Content-Type-Warning: guessed from content
     X-Powered-By: Zope (www.zope.org), Python (www.python.org)
 
 Or as a mapping:



More information about the Zope3-Checkins mailing list