[Checkins] SVN: z3c.pt/trunk/ In debug mode the actual source code
for file templates is written out to a <filename>.source file,
to make it easier to inspect it.
Hanno Schlichting
plone at hannosch.info
Sat Jun 14 12:42:23 EDT 2008
Log message for revision 87393:
In debug mode the actual source code for file templates is written out to a <filename>.source file, to make it easier to inspect it.
Make debug mode setting explicit in a config.py. Currently it is bound to Python's __debug__, which is False when run with -O and otherwise True.
Changed:
U z3c.pt/trunk/docs/HISTORY.txt
_U z3c.pt/trunk/src/z3c/
_U z3c.pt/trunk/src/z3c/pt/
A z3c.pt/trunk/src/z3c/pt/config.py
U z3c.pt/trunk/src/z3c/pt/template.py
_U z3c.pt/trunk/src/z3c/pt/tests/
-=-
Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt 2008-06-14 13:38:57 UTC (rev 87392)
+++ z3c.pt/trunk/docs/HISTORY.txt 2008-06-14 16:42:21 UTC (rev 87393)
@@ -4,6 +4,12 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- In debug mode the actual source code for file templates is written out to
+ a <filename>.source file, to make it easier to inspect it.
+
+- Make debug mode setting explicit in a config.py. Currently it is bound to
+ Python's __debug__, which is False when run with -O and otherwise True.
+
- Use a simplified UnicodeWrite clause for the result of _translate calls,
as the result value is guaranteed to be Unicode.
Property changes on: z3c.pt/trunk/src/z3c
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
Property changes on: z3c.pt/trunk/src/z3c/pt
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
Added: z3c.pt/trunk/src/z3c/pt/config.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/config.py (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/config.py 2008-06-14 16:42:21 UTC (rev 87393)
@@ -0,0 +1 @@
+DEBUG_MODE = __debug__
Property changes on: z3c.pt/trunk/src/z3c/pt/config.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.pt/trunk/src/z3c/pt/template.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/template.py 2008-06-14 13:38:57 UTC (rev 87392)
+++ z3c.pt/trunk/src/z3c/pt/template.py 2008-06-14 16:42:21 UTC (rev 87393)
@@ -3,30 +3,38 @@
import codegen
import traceback
+from z3c.pt import config
+
class BaseTemplate(object):
registry = {}
default_expression = 'python'
def __init__(self, body, default_expression=None):
self.body = body
- self.signature = hash(body)
+ self.signature = hash(body)
+ self.source = ''
if default_expression:
self.default_expression = default_expression
-
+
@property
def translate(self):
return NotImplementedError("Must be implemented by subclass.")
+ def source_write(self):
+ # Hook for writing out the source code to the file system
+ return
+
def cook(self, params):
generator = self.translate(
self.body, params=params, default_expression=self.default_expression)
source, _globals = generator()
-
+
suite = codegen.Suite(source)
-
+
self.source = source
+ self.source_write()
self.annotations = generator.stream.annotations
_globals.update(suite._globals)
@@ -103,6 +111,18 @@
filename = property(_get_filename, _set_filename)
+ @property
+ def source_filename(self):
+ return "%s.source" % self.filename
+
+ def source_write(self):
+ if self.source_filename and config.DEBUG_MODE:
+ try:
+ fs = open(self.source_filename, 'w')
+ fs.write(self.source)
+ finally:
+ fs.close()
+
def render(self, **kwargs):
if self._cook_check():
self.body = open(self.filename, 'r').read()
@@ -110,9 +130,9 @@
self._v_last_read = self.mtime()
return BaseTemplate.render(self, **kwargs)
-
+
def _cook_check(self):
- if self._v_last_read and not __debug__:
+ if self._v_last_read and not config.DEBUG_MODE:
return
if self.mtime() == self._v_last_read:
@@ -123,7 +143,7 @@
def mtime(self):
try:
return os.path.getmtime(self.filename)
- except OSError:
+ except (IOError, OSError):
return 0
def __repr__(self):
Property changes on: z3c.pt/trunk/src/z3c/pt/tests
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
More information about the Checkins
mailing list