changeset 268:eb0a369ebef6 trunk

Use absolute template path in exceptions, so that the corresponding code can be shown in tracebacks.
author cmlenz
date Mon, 25 Sep 2006 13:27:29 +0000
parents 8165d6e3b703
children 63bdd030c49f
files genshi/template.py
diffstat 1 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/genshi/template.py
+++ b/genshi/template.py
@@ -31,9 +31,9 @@
 from genshi.input import XMLParser
 from genshi.path import Path
 
-__all__ = ['BadDirectiveError', 'TemplateError', 'TemplateSyntaxError',
-           'TemplateNotFound', 'MarkupTemplate', 'TextTemplate',
-           'TemplateLoader']
+__all__ = ['BadDirectiveError', 'MarkupTemplate', 'Template', 'TemplateError',
+           'TemplateSyntaxError', 'TemplateNotFound', 'TemplateLoader',
+           'TextTemplate']
 
 
 class TemplateError(Exception):
@@ -384,6 +384,7 @@
 
         # Store the function reference in the bottom context frame so that it
         # doesn't get popped off before processing the template has finished
+        # FIXME: this makes context data mutable as a side-effect
         ctxt.frames[-1][self.name] = function
 
         return []
@@ -433,8 +434,7 @@
             ctxt.pop()
 
     def __repr__(self):
-        return '<%s "%s in %s">' % (self.__class__.__name__,
-                                    ', '.join(self.targets), self.expr.source)
+        return '<%s>' % self.__class__.__name__
 
 
 class IfDirective(Directive):
@@ -726,9 +726,7 @@
         ctxt.pop()
 
     def __repr__(self):
-        return '<%s "%s">' % (self.__class__.__name__,
-                              '; '.join(['%s = %s' % (name, expr.source)
-                                         for name, expr in self.vars]))
+        return '<%s>' % (self.__class__.__name__)
 
 
 class TemplateMeta(type):
@@ -764,7 +762,7 @@
         if basedir and filename:
             self.filepath = os.path.join(basedir, filename)
         else:
-            self.filepath = None
+            self.filepath = filename
 
         self.filters = [self._flatten, self._eval]
 
@@ -994,7 +992,7 @@
                     if cls is None:
                         raise BadDirectiveError(tag.localname, pos[0], pos[1])
                     value = attrib.get(getattr(cls, 'ATTRIBUTE', None), '')
-                    directives.append(cls(value, *pos))
+                    directives.append(cls(value, self.filepath, pos[1], pos[2]))
                     strip = True
 
                 new_attrib = []
@@ -1004,10 +1002,12 @@
                         if cls is None:
                             raise BadDirectiveError(name.localname, pos[0],
                                                     pos[1])
-                        directives.append(cls(value, *pos))
+                        directives.append(cls(value, self.filepath, pos[1],
+                                              pos[2]))
                     else:
                         if value:
-                            value = list(self._interpolate(value, *pos))
+                            value = list(self._interpolate(value, self.filepath,
+                                                           pos[1], pos[2]))
                             if len(value) == 1 and value[0][0] is TEXT:
                                 value = value[0][1]
                         else:
@@ -1038,7 +1038,8 @@
                                               pos)]
 
             elif kind is TEXT:
-                for kind, data, pos in self._interpolate(data, *pos):
+                for kind, data, pos in self._interpolate(data, self.filepath,
+                                                         pos[1], pos[2]):
                     stream.append((kind, data, pos))
 
             elif kind is COMMENT:
Copyright (C) 2012-2017 Edgewall Software