[z3-checkins] r46984 - z3/deliverance/trunk/deliverance

ltucker at codespeak.net ltucker at codespeak.net
Fri Sep 28 00:13:45 CEST 2007


Author: ltucker
Date: Fri Sep 28 00:13:43 2007
New Revision: 46984

Modified:
   z3/deliverance/trunk/deliverance/interpreter.py
   z3/deliverance/trunk/deliverance/test_wsgi.py
   z3/deliverance/trunk/deliverance/utils.py
   z3/deliverance/trunk/deliverance/wsgimiddleware.py
   z3/deliverance/trunk/deliverance/xslt.py
Log:
do not theme if x-deliverance-no-theme header is present or meta http-equiv tag is present, also tests

Modified: z3/deliverance/trunk/deliverance/interpreter.py
==============================================================================
--- z3/deliverance/trunk/deliverance/interpreter.py	(original)
+++ z3/deliverance/trunk/deliverance/interpreter.py	Fri Sep 28 00:13:43 2007
@@ -59,6 +59,9 @@
                 transformation represented by this class performed on the 
                 given content. 
         """
+        if self.shouldnt_theme(content):
+            return copy.deepcopy(content)
+
         result = copy.deepcopy(self.theme)
         input = self.aggregate(self.resolve_uri,self.rules,copy.deepcopy(content))
         self.apply_rules(self.rules, result, input)

Modified: z3/deliverance/trunk/deliverance/test_wsgi.py
==============================================================================
--- z3/deliverance/trunk/deliverance/test_wsgi.py	(original)
+++ z3/deliverance/trunk/deliverance/test_wsgi.py	Fri Sep 28 00:13:43 2007
@@ -4,6 +4,7 @@
 from paste.fixture import TestApp
 from paste.urlparser import StaticURLParser
 from paste.response import header_value
+from paste.wsgilib import intercept_output
 from deliverance.wsgimiddleware import DeliveranceMiddleware
 from formencode.doctest_xml_compare import xml_compare
 from deliverance.htmlserialize import tostring
@@ -21,6 +22,7 @@
 url_data = os.path.join(os.path.dirname(__file__), 'test-data', 'wsgiurl')
 aggregate_data = os.path.join(os.path.dirname(__file__), 'test-data', 'aggregate')
 aggregate2_data = os.path.join(os.path.dirname(__file__), 'test-data', 'aggregate2')
+ignore_data = os.path.join(os.path.dirname(__file__), 'test-data', 'ignore')
 
 static_app = StaticURLParser(static_data)
 tasktracker_app = StaticURLParser(tasktracker_data)
@@ -31,8 +33,7 @@
 url_app = StaticURLParser(url_data)
 aggregate_app = StaticURLParser(aggregate_data)
 aggregate2_app = StaticURLParser(aggregate2_data)
-
-
+ignore_app = StaticURLParser(ignore_data)
 
 def html_string_compare(astr, bstr):
     """
@@ -165,6 +166,43 @@
     res2 = app.get('/expected.html?notheme')
     html_string_compare(res.body, res2.body)
 
+def do_ignore(renderer_type, name): 
+    wsgi_app = DeliveranceMiddleware(ignore_app, 'theme.html', 'rules.xml', 
+                                     renderer_type)
+    
+    app = TestApp(wsgi_app)
+    res = app.get('/index.html')
+    res2 = app.get('/expected.html?notheme')
+    html_string_compare(res.body, res2.body)
+
+    res = app.get('/index2.html')
+    res2 = app.get('/expected2.html?notheme')
+    html_string_compare(res.body, res2.body)
+
+
+def do_ignore_header(renderer_type, name):     
+    class NoThemeHeaderApp:
+        def __init__(self, app): 
+            self.app = app
+
+        def __call__(self, environ, start_response): 
+            status, headers, body = intercept_output(environ, self.app)
+            headers.append(('x-deliverance-no-theme','1'))
+            start_response(status, headers)
+            return [body]
+
+    wsgi_app = DeliveranceMiddleware(NoThemeHeaderApp(ignore_app), 
+                                      'theme.html', 'rules.xml', 
+                                      renderer_type)
+    
+    app = TestApp(wsgi_app)
+
+    res = app.get('/index2.html')
+    res2 = app.get('/expected3.html?notheme')
+    html_string_compare(res.body, res2.body)
+    
+    
+
 def do_cache(renderer_type, name): 
     # XXX this should be busted up into multiple tests I spose 
 
@@ -274,15 +312,8 @@
     
 
 
-    
-
-    
-    
-    
-                                          
-
 RENDERER_TYPES = ['py', 'xslt']
-TEST_FUNCS = [ do_url, do_basic, do_text, do_tasktracker, do_xinclude, do_with_spaces, do_nycsr, do_necoro, do_guidesearch, do_ajax, do_aggregate, do_aggregate2, do_cache ] 
+TEST_FUNCS = [ do_url, do_basic, do_text, do_tasktracker, do_xinclude, do_with_spaces, do_nycsr, do_necoro, do_guidesearch, do_ajax, do_aggregate, do_aggregate2, do_cache, do_ignore, do_ignore_header ] 
 def test_all():
     for renderer_type in RENDERER_TYPES:
         for test_func in TEST_FUNCS: 

Modified: z3/deliverance/trunk/deliverance/utils.py
==============================================================================
--- z3/deliverance/trunk/deliverance/utils.py	(original)
+++ z3/deliverance/trunk/deliverance/utils.py	Fri Sep 28 00:13:43 2007
@@ -88,6 +88,13 @@
 
     REQUEST_CONTENT = "deliverance:request-content"
 
+    def shouldnt_theme(self, document):
+        if document is None:
+            return False
+
+        nt = document.xpath('//head/meta[@http-equiv="x-deliverance-no-theme"]')
+        return len(nt) != 0
+
     def get_theme_el(self,rule,theme):
         """
         get the element referred to by the "theme" attribute of the 

Modified: z3/deliverance/trunk/deliverance/wsgimiddleware.py
==============================================================================
--- z3/deliverance/trunk/deliverance/wsgimiddleware.py	(original)
+++ z3/deliverance/trunk/deliverance/wsgimiddleware.py	Fri Sep 28 00:13:43 2007
@@ -219,6 +219,11 @@
         specify a response from the wrapped middleware 
         which deliverance may need to theme. 
         """
+
+        dont_deliverate = header_value(headers, 'x-deliverance-no-theme')
+        if dont_deliverate:
+            return False
+
         type = header_value(headers, 'content-type')
         if type is None:
             return True # yerg, 304s can have no content-type 

Modified: z3/deliverance/trunk/deliverance/xslt.py
==============================================================================
--- z3/deliverance/trunk/deliverance/xslt.py	(original)
+++ z3/deliverance/trunk/deliverance/xslt.py	Fri Sep 28 00:13:43 2007
@@ -106,6 +106,8 @@
                 transformation represented by this class performed on the 
                 given content. 
         """
+        if self.shouldnt_theme(content):
+            return copy.deepcopy(content)
 
         #print "TRANSFORM: %s" % etree.tostring(self.xslt_wrapper)
         if content:


More information about the z3-checkins mailing list