1
2
3
4
5 import pkg_resources
6
7 available_engines = dict([ (entry_point.name, entry_point.load())
8 for entry_point in pkg_resources.
9 iter_entry_points('python.templating.engines') ])
10
12
13 - def __init__(self, extra_vars_func=None, engine_opts=None):
14 self.extra_vars_func = extra_vars_func
15 self.engine_opts = engine_opts
16 self.engines = {}
17
19 if not ':' in path:
20 dotted_path = path
21 engine_name = default_engine
22 else:
23 engine_name, dotted_path = path.split(':', 1)
24 engine = self._get_engine(engine_name)
25 return engine, dotted_path
26
28 engine, dotted_path = self.get_engine_and_path(path)
29 result = engine.render(
30 data, format=format, fragment=fragment, template=dotted_path)
31 return result
32
34 engine = self.engines.get(engine_name)
35 if not engine:
36 Engine = available_engines.get(engine_name, None)
37 if not Engine:
38 msg = 'No engine for "%s" found. Please install it.'
39 raise TemplateEngineMissing(msg % (engine_name,))
40 self.engines[engine_name] = \
41 engine = Engine(self.extra_vars_func, self.engine_opts)
42 return engine
43
46