Esempio n. 1
0
    def add_loader(self, module):
        """
        Register a Jinja2 package loader for the given module.

        Args:
            module (str):
                Module name to register.
        """
        if not aiohttp_jinja2:
            raise immp.HookError("Loaders require Jinja2 and aiohttp_jinja2")
        self._loader.mapping[module] = PackageLoader(module)
Esempio n. 2
0
 def channels(self):
     try:
         return {
             key: {
                 self.host.channels[label]: setting
                 for label, setting in mapping.items()
             }
             for key, mapping in self.config.items()
         }
     except KeyError as e:
         raise immp.HookError("No channel named '{}'".format(e.args[0]))
Esempio n. 3
0
    def _jinja(self, fn, path):
        @wraps(fn)
        async def inner(request):
            env = dict(self.env)
            env["request"] = request
            env.update(await fn(request))
            return env

        if not aiohttp_jinja2:
            raise immp.HookError(
                "Templating requires Jinja2 and aiohttp_jinja2")
        outer = aiohttp_jinja2.template("{}/{}".format(self.module, path))
        return outer(inner)