Ticket #206: prefixed-virtual-path.diff
| File prefixed-virtual-path.diff, 2.4 KB (added by Waldemar Kornewald <wkornewald@…>, 16 years ago) |
|---|
-
genshi/template/tests/loader.py
290 290 file2 = open(os.path.join(dir2, 'tmpl1.html'), 'w') 291 291 try: 292 292 file2.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> 293 <xi:include href=" foo.html" /> from sub1293 <xi:include href="../foo.html" /> from sub1 294 294 </html>""") 295 295 finally: 296 296 file2.close() … … 300 300 file3 = open(os.path.join(dir3, 'tmpl2.html'), 'w') 301 301 try: 302 302 file3.write("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> 303 <xi:include href=" foo.html" /> from sub2303 <xi:include href="../foo.html" /> from sub2 304 304 </html>""") 305 305 finally: 306 306 file3.close() -
genshi/template/loader.py
296 296 request to the delegate. 297 297 298 298 >>> load = prefixed( 299 ... app1 = lambda filename: ('app1', filename ),300 ... app2 = lambda filename: ('app2', filename )299 ... app1 = lambda filename: ('app1', filename, None, None), 300 ... app2 = lambda filename: ('app2', filename, None, None) 301 301 ... ) 302 302 >>> print load('app1/foo.html') 303 ('app1', ' foo.html')303 ('app1', 'app1/foo.html', None, None) 304 304 >>> print load('app2/bar.html') 305 ('app2', ' bar.html')305 ('app2', 'app2/bar.html', None, None) 306 306 307 307 :param delegates: mapping of path prefixes to loader functions 308 308 :return: the loader function … … 313 313 if filename.startswith(prefix): 314 314 if isinstance(delegate, basestring): 315 315 delegate = TemplateLoader.directory(delegate) 316 return delegate(filename[len(prefix):].lstrip('/\\')) 316 path, _, fileobj, mtime = delegate( 317 filename[len(prefix):].lstrip('/\\')) 318 return path, filename, fileobj, mtime 317 319 raise TemplateNotFound(filename, delegates.keys()) 318 320 return _dispatch_by_prefix 319 321 prefixed = staticmethod(prefixed)
