Mercurial > genshi > mirror
comparison genshi/template/loader.py @ 699:cfe3b4f02d77 trunk
Fix for caching in template loader for templates included by templates loaded from an absolute path. Closes #193. Thanks to Waldemar Kornewald for the test case.
author | cmlenz |
---|---|
date | Thu, 27 Mar 2008 14:49:06 +0000 |
parents | 408ab81767c7 |
children | fc6d9d2a3527 |
comparison
equal
deleted
inserted
replaced
698:408ab81767c7 | 699:cfe3b4f02d77 |
---|---|
164 if cls is None: | 164 if cls is None: |
165 cls = self.default_class | 165 cls = self.default_class |
166 if relative_to and not os.path.isabs(relative_to): | 166 if relative_to and not os.path.isabs(relative_to): |
167 filename = os.path.join(os.path.dirname(relative_to), filename) | 167 filename = os.path.join(os.path.dirname(relative_to), filename) |
168 filename = os.path.normpath(filename) | 168 filename = os.path.normpath(filename) |
169 cachekey = filename | |
169 | 170 |
170 self._lock.acquire() | 171 self._lock.acquire() |
171 try: | 172 try: |
172 # First check the cache to avoid reparsing the same file | 173 # First check the cache to avoid reparsing the same file |
173 try: | 174 try: |
174 tmpl = self._cache[filename] | 175 tmpl = self._cache[cachekey] |
175 if not self.auto_reload: | 176 if not self.auto_reload: |
176 return tmpl | 177 return tmpl |
177 mtime = self._mtime[filename] | 178 mtime = self._mtime[cachekey] |
178 if mtime and mtime == os.path.getmtime(tmpl.filepath): | 179 if mtime and mtime == os.path.getmtime(tmpl.filepath): |
179 return tmpl | 180 return tmpl |
180 except KeyError, OSError: | 181 except KeyError, OSError: |
181 pass | 182 pass |
182 | 183 |
219 dirname = '' | 220 dirname = '' |
220 tmpl = self.instantiate(cls, fileobj, dirname, | 221 tmpl = self.instantiate(cls, fileobj, dirname, |
221 filename, encoding=encoding) | 222 filename, encoding=encoding) |
222 if self.callback: | 223 if self.callback: |
223 self.callback(tmpl) | 224 self.callback(tmpl) |
224 self._cache[filename] = tmpl | 225 self._cache[cachekey] = tmpl |
225 self._mtime[filename] = mtime | 226 self._mtime[cachekey] = mtime |
226 finally: | 227 finally: |
227 if hasattr(fileobj, 'close'): | 228 if hasattr(fileobj, 'close'): |
228 fileobj.close() | 229 fileobj.close() |
229 return tmpl | 230 return tmpl |
230 | 231 |