changeset 22:2483fe549959 trunk

Fix for the template engine plugin: the search path is now ignored if the requested template path is absolute.
author cmlenz
date Tue, 20 Jun 2006 15:10:24 +0000
parents b4d17897d053
children d88358f719fa
files examples/includes/run.py markup/template.py
diffstat 2 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/examples/includes/run.py
+++ b/examples/includes/run.py
@@ -29,9 +29,9 @@
         timing.start()
         list(tmpl.generate(Context(**data)))
         timing.finish()
+        times.append(timing.milli())
         sys.stdout.write('.')
         sys.stdout.flush()
-        times.append(timing.milli())
     print
 
     print ' --> render stage: %dms (avg), %dms (min), %dms (max)' % (
--- a/markup/template.py
+++ b/markup/template.py
@@ -49,7 +49,6 @@
 
 from markup.core import Attributes, Namespace, Stream, StreamEventKind
 from markup.eval import Expression
-from markup.filters import IncludeFilter
 from markup.input import HTML, XMLParser, XML
 from markup.path import Path
 
@@ -873,14 +872,19 @@
     def load(self, filename, relative_to=None):
         """Load the template with the given name.
         
-        This method searches the search path trying to locate a template
-        matching the given name. If no such template is found, a
-        `TemplateNotFound` exception is raised. Otherwise, a `Template` object
-        representing the requested template is returned.
+        If the `filename` parameter is relative, this method searches the search
+        path trying to locate a template matching the given name. If the file
+        name is an absolute path, the search path is not bypassed.
         
-        Template searches are cached to avoid having to parse the same template
-        file more than once. Thus, subsequent calls of this method with the
-        same template file name will return the same `Template` object.
+        If requested template is not found, a `TemplateNotFound` exception is
+        raised. Otherwise, a `Template` object is returned that represents the
+        parsed template.
+        
+        Template instances are cached to avoid having to parse the same
+        template file more than once. Thus, subsequent calls of this method
+        with the same template file name will return the same `Template`
+        object (unless the `auto_reload` option is enabled and the file was
+        changed since the last parse.)
         
         If the `relative_to` parameter is provided, the `filename` is
         interpreted as being relative to that path.
@@ -893,6 +897,8 @@
         if relative_to:
             filename = posixpath.join(posixpath.dirname(relative_to), filename)
         filename = os.path.normpath(filename)
+
+        # First check the cache to avoid reparsing the same file
         try:
             tmpl = self._cache[filename]
             if not self.auto_reload or \
@@ -900,11 +906,18 @@
                 return tmpl
         except KeyError:
             pass
-        for dirname in self.search_path:
+
+        # Bypass the search path if the filename is absolute
+        search_path = self.search_path
+        if os.path.isabs(filename):
+            search_path = [os.path.dirname(filename)]
+
+        for dirname in search_path:
             filepath = os.path.join(dirname, filename)
             try:
                 fileobj = file(filepath, 'rt')
                 try:
+                    from markup.filters import IncludeFilter
                     tmpl = Template(fileobj, basedir=dirname, filename=filename)
                     tmpl.filters.append(IncludeFilter(self))
                 finally:
Copyright (C) 2012-2017 Edgewall Software