Exemple #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)
Exemple #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)
Exemple #4
0
 def create_query(self, search):
     #generate a string with the single parameter - search, using template defined as processAppendQueryTemplate
     q = processAppendQueryTemplate.generate(
         Context(search=search)).render()
     #print the query
     #print q
     return q
Exemple #5
0
    def test_import_in_def(self):
        suite = Suite("""def fun():
    from itertools import repeat
    return repeat(1, 3)
""")
        data = Context()
        suite.execute(data)
        assert 'repeat' not in data
        self.assertEqual([1, 1, 1], list(data['fun']()))
Exemple #6
0
    def test_import_in_def(self):
        suite = Suite("""def fun():
    from itertools import ifilter
    return ifilter(None, range(3))
""")
        data = Context()
        suite.execute(data)
        assert 'ifilter' not in data
        self.assertEqual([1, 2], list(data['fun']()))
    def _render_aeroo(self, template, data, output_format):
        """Generate the aeroo report binary from the template.

        :param template: the Libreoffice template to use
        :param data: the data used for rendering the report
        :param output_format: the output format
        :return: the report's binary data
        """
        # The first given record is
        template_io = BytesIO()
        template_io.write(template)
        serializer = OOSerializer(template_io)

        report_context = GenshiContext(**data)
        report_context.update(self._get_aeroo_extra_functions())
        report_context['t'] = AerooNamespace()

        output = Template(source=template_io, serializer=serializer)\
            .generate(report_context).render().getvalue()

        if self.aeroo_in_format != output_format:
            output = self._convert_aeroo_report(output, output_format)

        return output
Exemple #8
0
 def test_import_star(self):
     suite = Suite("from itertools import *")
     data = Context()
     suite.execute(data)
     assert 'ifilter' in data
Exemple #9
0
 def create_query(self, search):
     q = downstreamQueryTemplate.generate(Context(search=search)).render()
     return q
Exemple #10
0
 def create_query(self, search):
     q = processAppendQueryTemplate.generate(
         Context(search=search)).render()
     return q