Permalink
Browse files

Cleaned up and updated for z3 templates only. Tested with Plone 4.3 only

  • Loading branch information...
1 parent 009a8a8 commit 16ae46164a89e95ae49eb01d82b5638c056a0977 @naro naro committed Jan 30, 2014
Showing with 21 additions and 59 deletions.
  1. +8 −15 Products/PTProfiler/ProfilerPatch.py
  2. +13 −44 Products/PTProfiler/__init__.py
@@ -20,7 +20,7 @@ def __patched_call__(self, econtext):
"""The patched method for expressions
"""
global enabled
-
+
name = self._patching_class._get_name(econtext)
if enabled and name and not name.find(os.path.dirname(__file__)) > -1:
expr = self._patching_class._get_expr(self)
@@ -56,14 +56,6 @@ def _get_name(self, econtext):
def _get_expr(self, obj):
if self._type == 'python':
- return 'python: %s' % obj.expr
- else:
- return '%s: %s' % (self._type, obj._s)
-
-class ExprProfilerPatchZ3(ExprProfilerPatch):
-
- def _get_expr(self, obj):
- if self._type == 'python':
return 'python: %s' % obj.text
else:
return '%s: %s' % (self._type, obj._s)
@@ -73,22 +65,23 @@ def _get_expr(self, obj):
# PageTemplates
#-----------------------------------------------------------------------------
-def __patched_render__(self, source=0, extra_context={}):
+def __patched_render__(self, namespace, source=False, sourceAnnotations=False, showtal=False):
global enabled
-
+
name = self._patching_class._get_name(self)
# don't profile if profiling is disabled and don't profile our own pts
if enabled and not name.find(os.path.dirname(__file__)) > -1:
starttime = time.clock()
try:
- ret = self._patching_class._org_method(self, source, extra_context)
+ ret = self._patching_class._org_method(self, namespace, source, sourceAnnotations, showtal)
finally:
profile_container.pt_hit(name, time.clock() - starttime)
else:
- ret = self._patching_class._org_method(self, source, extra_context)
+ ret = self._patching_class._org_method(self, namespace, source, sourceAnnotations, showtal)
return ret
+
class PTProfilerPatch:
"""A class to hook into PageTemplates
"""
@@ -99,7 +92,7 @@ def __init__(self, class_to_patch):
log('patch Page Templates pt_render')
def _get_name(self, object):
- return (getattr(object, '_filepath', None) or
- getattr(object, 'filename', None) or
+ return (getattr(object, '_filepath', None) or
+ getattr(object, 'filename', None) or
getattr(object, 'id'))
@@ -10,27 +10,14 @@
"""
# import the profiling machinery and monkeypatch the objects
-from ProfilerPatch import ExprProfilerPatch, PTProfilerPatch
-from ProfilerPatch import ExprProfilerPatchZ3
+from ProfilerPatch import PTProfilerPatch
+from ProfilerPatch import ExprProfilerPatch
from ProfilerPatch import log
-from Products.PageTemplates.PageTemplate import PageTemplate
-from Products.PageTemplates.ZRPythonExpr import PythonExpr
-try:
- from zope.tales.expressions import PathExpr, StringExpr
-except ImportError:
- from Products.PageTemplates.Expressions import PathExpr, StringExpr
-
-try:
- from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
- from zope.pagetemplate.pagetemplate import PageTemplate as PageTemplateZ3
-
- from zope.tales.pythonexpr import PythonExpr as PythonExprZ3
- from zope.tales.expressions import PathExpr as PathExprZ3
- from zope.tales.expressions import StringExpr as StringExprZ3
- HAS_Z3TEMPLATES = True
-except ImportError:
- HAS_Z3TEMPLATES = False
+from zope.pagetemplate.pagetemplate import PageTemplate
+from zope.tales.pythonexpr import PythonExpr
+from zope.tales.expressions import PathExpr
+from zope.tales.expressions import StringExpr
import PTProfilerViewer
@@ -42,28 +29,10 @@ def initialize(context):
icon='www/PTP.gif',
)
- pt = PageTemplate()
- if isinstance(pt, PageTemplateZ3):
- TEMPLATES_ARE_Z3 = True
- else:
- TEMPLATES_ARE_Z3 = False
- if HAS_Z3TEMPLATES:
- if TEMPLATES_ARE_Z3:
- log('Patching page templates...')
- PTProfilerPatch(PageTemplate)
- else:
- log('Patching Five page templates...')
- PTProfilerPatch(ZopeTwoPageTemplateFile)
- log('Patching Z3 TALES engine...')
- ExprProfilerPatchZ3('python', PythonExprZ3)
- ExprProfilerPatchZ3('path', PathExprZ3)
- ExprProfilerPatchZ3('string', StringExprZ3)
- log('Patched')
- if (not HAS_Z3TEMPLATES) or (not TEMPLATES_ARE_Z3):
- log('Patching page templates...')
- PTProfilerPatch(PageTemplate)
- log('Patching Z2 TALES engine...')
- ExprProfilerPatch('python', PythonExpr)
- ExprProfilerPatch('path', PathExpr)
- ExprProfilerPatch('string', StringExpr)
- log('Patched')
+ log('Patching page templates...')
+ PTProfilerPatch(PageTemplate)
+ log('Patching Z3 TALES engine...')
+ ExprProfilerPatch('python', PythonExpr)
+ ExprProfilerPatch('path', PathExpr)
+ ExprProfilerPatch('string', StringExpr)
+ log('Patched')

0 comments on commit 16ae461

Please sign in to comment.