[Checkins] SVN: z3c.pt/trunk/ Simplified the _escape function
handling by pulling in the str call into the function.
Corrected the bigtable hotshot test to only benchmark rendering.
Hanno Schlichting
plone at hannosch.info
Fri Jul 18 03:34:27 EDT 2008
Log message for revision 88468:
Simplified the _escape function handling by pulling in the str call into the function. Corrected the bigtable hotshot test to only benchmark rendering.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/benchmark/benchmark/bigtable.py
U z3c.pt/trunk/src/z3c/pt/clauses.py
U z3c.pt/trunk/src/z3c/pt/generation.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-07-17 22:23:07 UTC (rev 88467)
+++ z3c.pt/trunk/CHANGES.txt 2008-07-18 07:34:25 UTC (rev 88468)
@@ -4,6 +4,9 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Simplified the _escape function handling by pulling in the str call into the
+ function. Corrected the bigtable hotshot test to only benchmark rendering.
+
- Replaced the cgi.escape function by an optimized local version, we go up
to 11x for path and 16x for Python expressions :) In the bigtable benchmark
the enhancement is more noticable - we are the same speed as spitfire -O1
Modified: z3c.pt/trunk/benchmark/benchmark/bigtable.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/bigtable.py 2008-07-17 22:23:07 UTC (rev 88467)
+++ z3c.pt/trunk/benchmark/benchmark/bigtable.py 2008-07-18 07:34:25 UTC (rev 88468)
@@ -51,10 +51,7 @@
tests = ['test_z3c']
for test in tests:
- if which:
- setup = 'from __main__ import setup, %s; setup()' % test
- else:
- setup = 'from __main__ import setup, %s; setup(); %s()' % (test, test)
+ setup = 'from __main__ import setup, %s; setup(); %s()' % (test, test)
t = timeit.Timer(setup=setup,
stmt='%s()' % test)
@@ -73,7 +70,9 @@
which = True
import hotshot, hotshot.stats
prof = hotshot.Profile("template.prof")
- benchtime = prof.runcall(run, which, number=1)
+ setup()
+ test_z3c()
+ benchtime = prof.runcall(test_z3c)
stats = hotshot.stats.load("template.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py 2008-07-17 22:23:07 UTC (rev 88467)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py 2008-07-18 07:34:25 UTC (rev 88468)
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
-from utils import unicode_required_flag
from cgi import escape
-import types
+from z3c.pt import types
+from z3c.pt.generation import _escape
+from z3c.pt.utils import unicode_required_flag
class Assign(object):
"""
@@ -305,7 +306,6 @@
>>> from z3c.pt.generation import CodeIO
>>> from z3c.pt.testing import pyexp
>>> from StringIO import StringIO
- >>> from cgi import escape as _escape
Unlimited scope:
@@ -427,9 +427,9 @@
class Tag(object):
"""
>>> from z3c.pt.generation import CodeIO
+ >>> from z3c.pt.generation import _escape
>>> from z3c.pt.testing import pyexp
>>> from StringIO import StringIO
- >>> from cgi import escape as _escape
Dynamic attribute:
@@ -504,18 +504,18 @@
if unicode_required_flag:
stream.write("if isinstance(%s, unicode):" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(%s,1)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(%s,1,0)+'\"')" %
(attribute, temp))
stream.outdent()
stream.write("elif %s is not None:" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(str(%s),1)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(%s,1)+'\"')" %
(attribute, temp))
stream.outdent()
else:
stream.write("if %s is not None:" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(str(%s),1)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(%s,1)+'\"')" %
(attribute, temp))
stream.outdent()
@@ -646,9 +646,9 @@
class Write(object):
"""
>>> from z3c.pt.generation import CodeIO
+ >>> from z3c.pt.generation import _escape
>>> from z3c.pt.testing import pyexp
>>> from StringIO import StringIO
- >>> from cgi import escape as _escape
Basic write:
@@ -712,7 +712,7 @@
if self.structure:
stream.write("_write(str(_urf))")
else:
- stream.write("_write(_escape(str(_urf)))")
+ stream.write("_write(_escape(_urf))")
stream.outdent()
else:
stream.write("if _urf is not None:")
@@ -720,7 +720,7 @@
if self.structure:
stream.write("_write(str(_urf))")
else:
- stream.write("_write(_escape(str(_urf)))")
+ stream.write("_write(_escape(_urf))")
stream.outdent()
def end(self, stream):
Modified: z3c.pt/trunk/src/z3c/pt/generation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-17 22:23:07 UTC (rev 88467)
+++ z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-18 07:34:25 UTC (rev 88468)
@@ -3,7 +3,6 @@
from zope.i18n import translate
from zope.i18nmessageid import Message
-import cgi
import StringIO
import expressions
@@ -46,8 +45,10 @@
return target_language
return negotiate(context)
-def _escape(s, quote=0):
+def _escape(s, quote=0, string=1):
"""Replace special characters '&', '<' and '>' by SGML entities."""
+ if string:
+ s = str(s)
if '&' in s:
s = s.replace("&", "&") # Must be done first!
if '<' in s:
More information about the Checkins
mailing list