1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Index: genshi/template.py
===================================================================
--- genshi/template.py  (revision 346)
+++ genshi/template.py  (working copy)
@@ -1314,9 +1314,10 @@
             directly
         @param cls: the class of the template object to instantiate
         """
+        filepath = filename
         if relative_to:
-            filename = os.path.join(os.path.dirname(relative_to), filename)
-        filename = os.path.normpath(filename)
+            filepath = os.path.join(os.path.dirname(relative_to), filepath)
+        filepath = os.path.normpath(filepath)
 
         self._lock.acquire()
         try:
@@ -1331,23 +1332,26 @@
 
             # Bypass the search path if the filename is absolute
             search_path = self.search_path
+            filedir = os.path.dirname(filepath)
             if os.path.isabs(filename):
-                search_path = [os.path.dirname(filename)]
+                search_path = [filedir]
+            elif filedir not in search_path:
+                search_path.append(filedir)
 
             if not search_path:
                 raise TemplateError('Search path for templates not configured')
 
             for dirname in search_path:
-                filepath = os.path.join(dirname, filename)
+                path = os.path.join(dirname, filepath)
                 try:
-                    fileobj = open(filepath, 'U')
+                    fileobj = open(path, 'U')
                     try:
                         tmpl = cls(fileobj, basedir=dirname, filename=filename,
                                    loader=self)
                     finally:
                         fileobj.close()
                     self._cache[filename] = tmpl
-                    self._mtime[filename] = os.path.getmtime(filepath)
+                    self._mtime[filename] = os.path.getmtime(path)
                     return tmpl
                 except IOError:
                     continue