How to use the chameleon.PageTemplate function in Chameleon

To help you get started, we’ve selected a few Chameleon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github castlecms / castle.cms / castle / cms / transformer.py View on Github external
@adapter(IPubEnd)
def requestEnd(event):
    req = event.request
    try:
        period = time.time() - req.environ['__started__']
    except Exception:
        period = 0

    if period > 5.0:
        logger.warn('SLOW REQUEST(%i): %s' % (int(period), req.ACTUAL_URL))

    log_request(req)


_impersonator_template = PageTemplate("""
<div id="impersonator">
  <a class="stop" href="${stop_url}"><span class="glyphicon glyphicon-remove"></span></a>
  <span>This is what the website looks like to:
    <span class="anonymous">
        <span class="glyphicon glyphicon-globe"></span> Public
    </span>
    <span class="anonymous">
      <span class="glyphicon glyphicon-user"></span> ${user_name}
  </span>
</span></div>"""  # noqa
)


class TransformInpersonatorOutput(object):
    implements(ITransform)
github toscawidgets / tw2.core / tw2 / core / templating.py View on Github external
from .jinja_util import htmlbools
        env = jinja2.environment.Environment(autoescape=True)
        env.filters['htmlbools'] = htmlbools
        tmpl = env.from_string(src, template_class=jinja2.Template)
        tmpl.filename = filename
        return lambda kwargs: Markup(tmpl.render(**kwargs))

    elif engine_name == 'kajiki':
        import kajiki
        tmpl = kajiki.XMLTemplate(six.u(src), filename=filename,
                                  cdata_scripts=False)
        return lambda kwargs: Markup(tmpl(kwargs).render())

    elif engine_name == 'chameleon':
        import chameleon
        tmpl = chameleon.PageTemplate(src, filename=filename)
        return lambda kwargs: Markup(tmpl.render(**kwargs).strip())

    raise NotImplementedError("Unhandled engine")
github kmu-bigdata / serverless-faas-workbench / aws / cpu-memory / chameleon / lambda_function.py View on Github external
def lambda_handler(event, context):
    num_of_rows = event['num_of_rows']
    num_of_cols = event['num_of_cols']

    start = time()
    tmpl = PageTemplate(BIGTABLE_ZPT)

    data = {}
    for i in range(num_of_cols):
        data[str(i)] = i

    table = [data for x in range(num_of_rows)]
    options = {'table': table}

    data = tmpl.render(options=options)
    latency = time() - start

    result = json.dumps({'latency': latency, 'data': data})
    return result
github malthe / chameleon / benchmarks / bm_chameleon.py View on Github external
def test_mako(count):
    template = PageTemplate(CONTENT_TEMPLATE)
    base = PageTemplate(BASE_TEMPLATE)
    page = PageTemplate(PAGE_TEMPLATE)

    table = [range(150) for i in range(150)]
    paragraphs = range(50)
    title = 'Hello world!'

    times = []
    for i in range(count):
        t0 = time.time()
        data = template.render(
            table=table, paragraphs=paragraphs,
            lorem=LOREM_IPSUM, title=title,
            img_count=50,
            base=base,
            page=page,
github sayanarijit / htmldoom / benchmark / general.py View on Github external
def chameleon(n):
    return PageTemplate(chameltmpl)(n=n)
github malthe / chameleon / benchmarks / bm_chameleon.py View on Github external
def test_mako(count):
    template = PageTemplate(CONTENT_TEMPLATE)
    base = PageTemplate(BASE_TEMPLATE)
    page = PageTemplate(PAGE_TEMPLATE)

    table = [range(150) for i in range(150)]
    paragraphs = range(50)
    title = 'Hello world!'

    times = []
    for i in range(count):
        t0 = time.time()
        data = template.render(
            table=table, paragraphs=paragraphs,
            lorem=LOREM_IPSUM, title=title,
            img_count=50,
            base=base,
            page=page,
            )
        t1 = time.time()