Пример #1
0
 def render(self, context):
     try:
         return self.template_obj.render_unicode(**context_to_dict(context))
     except MakoException, me:
         if hasattr(me, 'source'):
             raise MakoExceptionWrapper(me, self.origin)
         else:
             raise me
Пример #2
0
def context_to_dict(ctxt):
    res = {}
    for d in reversed(ctxt.dicts):
        # sometimes contexts will be nested
        if isinstance(d, Context):
            res.update(context_to_dict(d))
        else:
            res.update(d)
    return res
Пример #3
0
def render_nemo_template(mako_template, context, def_name):
    try:
        template_obj = mako_template.template_obj

        if def_name is not None:
            template_obj = mako_template.template_obj.get_def(def_name)

        return template_obj.render_unicode(**context_to_dict(context))
    except MakoException, me:
        if hasattr(me, 'source'):
            raise MakoExceptionWrapper(me, mako_template.origin)
        else:
            raise me