Index: genshi/template/loader.py
===================================================================
--- genshi/template/loader.py	(revision 1185)
+++ genshi/template/loader.py	(working copy)
@@ -173,15 +173,8 @@
         """
         if cls is None:
             cls = self.default_class
-        search_path = self.search_path
 
-        # Make the filename relative to the template file its being loaded
-        # from, but only if that file is specified as a relative path, or no
-        # search path has been set up
-        if relative_to and (not search_path or not os.path.isabs(relative_to)):
-            filename = os.path.join(os.path.dirname(relative_to), filename)
-
-        filename = os.path.normpath(filename)
+        filename, search_path = self._resolve_paths(filename, relative_to)
         cachekey = filename
 
         self._lock.acquire()
@@ -197,28 +190,11 @@
             except (KeyError, OSError):
                 pass
 
-            isabs = False
+            isabs = os.path.isabs(filename)
 
-            if os.path.isabs(filename):
-                # Bypass the search path if the requested filename is absolute
-                search_path = [os.path.dirname(filename)]
-                isabs = True
-
-            elif relative_to and os.path.isabs(relative_to):
-                # Make sure that the directory containing the including
-                # template is on the search path
-                dirname = os.path.dirname(relative_to)
-                if dirname not in search_path:
-                    search_path = list(search_path) + [dirname]
-                isabs = True
-
-            elif not search_path:
-                # Uh oh, don't know where to look for the template
-                raise TemplateError('Search path for templates not configured')
-
             for loadfunc in search_path:
                 if isinstance(loadfunc, basestring):
-                    loadfunc = directory(loadfunc)
+                    loadfunc = self.directory(loadfunc)
                 try:
                     filepath, filename, fileobj, uptodate = loadfunc(filename)
                 except IOError:
@@ -248,6 +224,41 @@
         finally:
             self._lock.release()
 
+    def _resolve_paths(self, filename, relative_to):
+        """Return a normalized filename and list of search paths.
+
+        :param filename: path of the template file to load
+        :param relative_to: the filename of the template from which the new
+                            template is being loaded, or ``None`` if the
+                            template is being loaded directly
+        :return: a normalized *filename* and sequence of appropriate search
+                 paths
+        """
+        search_path = self.search_path
+
+        # Make the filename relative to the template file its being loaded
+        # from, but only if that file is specified as a relative path, or no
+        # search path has been set up
+        if relative_to and (not search_path or not os.path.isabs(relative_to)):
+            filename = os.path.join(os.path.dirname(relative_to), filename)
+
+        filename = os.path.normpath(filename)
+
+        if os.path.isabs(filename):
+            # Bypass the search path if the requested filename is absolute
+            search_path = [os.path.dirname(filename)]
+        elif relative_to and os.path.isabs(relative_to):
+            # Make sure that the directory containing the including
+            # template is on the search path
+            dirname = os.path.dirname(relative_to)
+            if dirname not in search_path:
+                search_path = list(search_path) + [dirname]
+        elif not search_path:
+            # Uh oh, don't know where to look for the template
+            raise TemplateError('Search path for templates not configured')
+
+        return filename, search_path
+
     def _instantiate(self, cls, fileobj, filepath, filename, encoding=None):
         """Instantiate and return the `Template` object based on the given
         class and parameters.
