[Zope3-checkins] SVN: Zope3/trunk/ Added ++debug++ traversal adapter that allows you to specify a comma separated

Marius Gedminas marius at pov.lt
Fri Jun 11 13:39:08 EDT 2004


Log message for revision 25358:
Added ++debug++ traversal adapter that allows you to specify a comma separated
list of debugging flags that will be enabled in request.debug.  Currently there
is only one flag, 'source', that enables ZPT source annotations.




-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/doc/CHANGES.txt	2004-06-11 17:39:08 UTC (rev 25358)
@@ -10,6 +10,15 @@
 
     New features
 
+      - Added ++debug++ traversal adapter that allows you to turn on debugging
+        flags in request.debug.  Currently there is only one flag named
+        "source" that adds HTML comments to rendered page templates showing
+        where each code snippet came from.  Try
+
+          http://localhost:8080/++debug++source/@@contents.html
+
+        and view the source of the resulting page.
+
     Bug fixes
 
       - Fixed bug in TypeRegistry for

Modified: Zope3/trunk/src/zope/app/pagetemplate/tests/test_binding.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/tests/test_binding.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/pagetemplate/tests/test_binding.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -36,7 +36,8 @@
         ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
 
     def test_binding(self):
-        comp = PTComponent(Content())
+        from zope.publisher.browser import TestRequest
+        comp = PTComponent(Content(), TestRequest())
         self.assertEqual(comp.index(), "42\n")
         self.assertEqual(comp.nothing(), "\n")
         self.assertEqual(comp.default(), "<span>42</span>\n")

Modified: Zope3/trunk/src/zope/app/pagetemplate/tests/test_simpleviewclass.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/tests/test_simpleviewclass.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/pagetemplate/tests/test_simpleviewclass.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -23,9 +23,11 @@
 
     def test_simple(self):
         from zope.app.pagetemplate.tests.simpletestview import SimpleTestView
+        from zope.publisher.browser import TestRequest
 
         ob = data()
-        view = SimpleTestView(ob, None)
+        request = TestRequest()
+        view = SimpleTestView(ob, request)
         macro = view['test']
         out = view()
         self.assertEqual(out,
@@ -36,6 +38,7 @@
 
     def test_WBases(self):
         from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+        from zope.publisher.browser import TestRequest
 
         class C: pass
 
@@ -44,7 +47,8 @@
         self.failUnless(issubclass(SimpleTestView, C))
 
         ob = data()
-        view = SimpleTestView(ob, None)
+        request = TestRequest()
+        view = SimpleTestView(ob, request)
         macro = view['test']
         out = view()
         self.assertEqual(out,

Modified: Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -45,7 +45,8 @@
         namespace = self.pt_getContext(
             request=instance.request,
             instance=instance, args=args, options=keywords)
-        return self.pt_render(namespace)
+        return self.pt_render(namespace,
+                    sourceAnnotations=instance.request.debug.sourceAnnotations)
 
     def __get__(self, instance, type=None):
         return BoundPageTemplate(self, instance)

Modified: Zope3/trunk/src/zope/app/traversing/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/traversing/configure.zcml	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/traversing/configure.zcml	2004-06-11 17:39:08 UTC (rev 25358)
@@ -97,4 +97,10 @@
     factory="zope.app.traversing.namespace.vh" 
     />
 
+<view
+    name="debug" type="*"
+    provides="zope.app.traversing.interfaces.ITraversable" for="*"
+    factory="zope.app.traversing.namespace.debug" 
+    />
+
 </configure>

Modified: Zope3/trunk/src/zope/app/traversing/namespace.py
===================================================================
--- Zope3/trunk/src/zope/app/traversing/namespace.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/traversing/namespace.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -425,10 +425,49 @@
              no adapter
 
            Cleanup:
-    
+
              >>> tearDown()
            """
         try:
             return component.getAdapter(self.context, IPathAdapter, name=name)
         except:
             raise NotFoundError(self.context, name)
+
+
+class debug(view):
+
+    def traverse(self, name, ignored):
+        """Debug traversal adapter
+
+           This adapter allows debugging flags to be set in the request.
+           See IDebugFlags.
+
+           Demonstration:
+
+             >>> from zope.publisher.browser import TestRequest
+             >>> request = TestRequest()
+             >>> ob = object()
+             >>> adapter = debug(ob, request)
+             >>> request.debug.sourceAnnotations
+             False
+             >>> adapter.traverse('source', ()) is ob
+             True
+             >>> request.debug.sourceAnnotations
+             True
+             >>> adapter.traverse('source,source', ()) is ob
+             True
+             >>> try:
+             ...     adapter.traverse('badflag', ())
+             ... except ValueError:
+             ...     print 'unknown debugging flag'
+             unknown debugging flag
+
+        """
+        request = self.request
+        for flag in name.split(','):
+            if flag == 'source':
+                request.debug.sourceAnnotations = True
+            else:
+                raise ValueError("Unknown debug flag: %s" % flag)
+        return self.context
+

Modified: Zope3/trunk/src/zope/app/workflow/stateful/xmlimportexport.py
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/xmlimportexport.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/app/workflow/stateful/xmlimportexport.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -159,12 +159,13 @@
     template = ViewPageTemplateFile('xmlexport_template.pt')
 
     def __init__(self, context):
-        self.context = context    
+        self.context = context
 
     def doExport(self):
         # Unfortunately, the template expects its parent to have an attribute
         # called request.
-        self.request = None
+        from zope.publisher.browser import TestRequest
+        self.request = TestRequest()
         return self.template()
 
     def getDublinCore(self, obj):

Modified: Zope3/trunk/src/zope/pagetemplate/pagetemplate.py
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/pagetemplate.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/pagetemplate/pagetemplate.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -51,7 +51,7 @@
         engine.  This method is free to use the keyword arguments it
         receives.
 
-    pt_render(namespace, source=0)
+    pt_render(namespace, source=False, sourceAnnotations=False)
         Responsible the TAL interpreter to perform the rendering.  The
         namespace argument is a mapping which defines the top-level
         namespaces passed to the TALES expression engine.
@@ -99,7 +99,7 @@
     def pt_getEngine(self):
         return Engine
 
-    def pt_render(self, namespace, source=False):
+    def pt_render(self, namespace, source=False, sourceAnnotations=False):
         """Render this Page Template"""
         self._cook_check()
         __traceback_supplement__ = (PageTemplateTracebackSupplement,
@@ -110,7 +110,8 @@
         output = StringIO(u'')
         context = self.pt_getEngineContext(namespace)
         TALInterpreter(self._v_program, self._v_macros,
-                       context, output, tal=not source, strictinsert=0)()
+                       context, output, tal=not source, strictinsert=0,
+                       sourceAnnotations=sourceAnnotations)()
         return output.getvalue()
 
     def pt_errors(self, namespace):

Modified: Zope3/trunk/src/zope/pagetemplate/readme.txt
===================================================================
--- Zope3/trunk/src/zope/pagetemplate/readme.txt	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/pagetemplate/readme.txt	2004-06-11 17:39:08 UTC (rev 25358)
@@ -46,7 +46,7 @@
         engine.  This method is free to use the keyword arguments it
         receives.
 
-    pt_render(namespace, source=0)
+    pt_render(namespace, source=False, sourceAnnotations=False)
         Responsible the TAL interpreter to perform the rendering.  The
         namespace argument is a mapping which defines the top-level
         namespaces passed to the TALES expression engine.

Modified: Zope3/trunk/src/zope/publisher/base.py
===================================================================
--- Zope3/trunk/src/zope/publisher/base.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/publisher/base.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -27,7 +27,7 @@
 
 from zope.publisher.interfaces import IPublication
 from zope.publisher.interfaces import NotFound, DebugError, Unauthorized
-from zope.publisher.interfaces import IRequest, IResponse
+from zope.publisher.interfaces import IRequest, IResponse, IDebugFlags
 from zope.publisher.publish import mapply
 
 _marker = object()
@@ -152,6 +152,15 @@
 class RequestEnvironment(RequestDataMapper):
     _mapname = '_environ'
 
+
+class DebugFlags(object):
+    """Debugging flags."""
+
+    implements(IDebugFlags)
+
+    sourceAnnotations = False
+
+
 class BaseRequest(object):
     """Represents a publishing request.
 
@@ -181,6 +190,7 @@
         '_presentation_skin', # View skin
         '_principal',        # request principal, set by publication
         'interaction',       # interaction, set by interaction
+        'debug',             # debug flags
         )
 
     environment = RequestDataProperty(RequestEnvironment)
@@ -202,6 +212,7 @@
         self._body_instream = body_instream
         self._held = ()
         self._principal = None
+        self.debug = DebugFlags()
         self.interaction = None
 
     def setPrincipal(self, principal):

Modified: Zope3/trunk/src/zope/publisher/interfaces/__init__.py
===================================================================
--- Zope3/trunk/src/zope/publisher/interfaces/__init__.py	2004-06-11 16:37:06 UTC (rev 25357)
+++ Zope3/trunk/src/zope/publisher/interfaces/__init__.py	2004-06-11 17:39:08 UTC (rev 25358)
@@ -386,6 +386,12 @@
         """
 
 
+class IDebugFlags(Interface):
+    """Features that support debugging."""
+
+    sourceAnnotations = Attribute("""Enable ZPT source annotations""")
+
+
 class IApplicationRequest(IEnumerableMapping):
     """Features that support application logic
     """
@@ -398,6 +404,8 @@
 
     bodyFile = Attribute("""The body of the request as a file""")
 
+    debug = Attribute("""Debug flags (see IDebugFlags).""")
+
     def __getitem__(key):
         """Return request data
 




More information about the Zope3-Checkins mailing list