Exemplo n.º 1
0
 def test_copy(self):
     # create a non-trivial context with some dummy
     # frames, match templates and py:choice stacks.
     orig_ctxt = Context(a=5, b=6)
     orig_ctxt.push({'c': 7})
     orig_ctxt._match_templates.append(object())
     orig_ctxt._choice_stack.append(object())
     ctxt = orig_ctxt.copy()
     self.assertNotEqual(id(orig_ctxt), id(ctxt))
     self.assertEqual(repr(orig_ctxt), repr(ctxt))
     self.assertEqual(orig_ctxt._match_templates, ctxt._match_templates)
     self.assertEqual(orig_ctxt._choice_stack, ctxt._choice_stack)
Exemplo n.º 2
0
 def test_copy(self):
     # create a non-trivial context with some dummy
     # frames, match templates and py:choice stacks.
     orig_ctxt = Context(a=5, b=6)
     orig_ctxt.push({'c': 7})
     orig_ctxt._match_templates.append(object())
     orig_ctxt._choice_stack.append(object())
     ctxt = orig_ctxt.copy()
     self.assertNotEqual(id(orig_ctxt), id(ctxt))
     self.assertEqual(repr(orig_ctxt), repr(ctxt))
     self.assertEqual(orig_ctxt._match_templates, ctxt._match_templates)
     self.assertEqual(orig_ctxt._choice_stack, ctxt._choice_stack)
 def render(self, context=None, request=None):
     genshi_context = GenshiContext()
     genshi_context['static'] = staticfiles_storage.url
     genshi_context['url'] = reverse
     if request is not None:
         genshi_context['request'] = request
         genshi_context['csrf_input'] = csrf_input_lazy(request)
         genshi_context['csrf_token'] = csrf_token_lazy(request)
     if context is not None:
         genshi_context.push(context)
     stream = self.template.generate(genshi_context)
     template_render.send(self, genshi_context=genshi_context)
     # this might raise a genshi.template.eval.UndefinedError (derived from
     # genshi.template.base.TemplateRuntimeError)
     return stream.render(self.serialization, doctype=self.doctype)