summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2020-01-10 12:58:38 -0800
committerDavid Lord <davidism@gmail.com>2020-01-10 12:58:38 -0800
commite492255f270add52d051ef4f8e87899f40e57687 (patch)
tree5c32f9e526b2efae6d901bc4dd77655dbf8ab3b5 /examples
parent143667d95d73730415bb1281d1cd5e439b366fec (diff)
downloadjinja2-e492255f270add52d051ef4f8e87899f40e57687.tar.gz
remove old scripts and examples
Diffstat (limited to 'examples')
-rw-r--r--examples/bench.py499
-rw-r--r--examples/profile.py54
-rw-r--r--examples/rwbench/django/_form.html1
-rw-r--r--examples/rwbench/django/_input_field.html1
-rw-r--r--examples/rwbench/django/_textarea.html1
-rw-r--r--examples/rwbench/django/index.html29
-rw-r--r--examples/rwbench/django/layout.html29
-rw-r--r--examples/rwbench/djangoext.py126
-rw-r--r--examples/rwbench/genshi/helpers.html12
-rw-r--r--examples/rwbench/genshi/index.html41
-rw-r--r--examples/rwbench/genshi/layout.html30
-rw-r--r--examples/rwbench/jinja/helpers.html12
-rw-r--r--examples/rwbench/jinja/index.html29
-rw-r--r--examples/rwbench/jinja/layout.html29
-rw-r--r--examples/rwbench/mako/helpers.html11
-rw-r--r--examples/rwbench/mako/index.html31
-rw-r--r--examples/rwbench/mako/layout.html30
-rw-r--r--examples/rwbench/rwbench.py122
18 files changed, 0 insertions, 1087 deletions
diff --git a/examples/bench.py b/examples/bench.py
deleted file mode 100644
index e610718..0000000
--- a/examples/bench.py
+++ /dev/null
@@ -1,499 +0,0 @@
-"""\
- This benchmark compares some python templating engines with Jinja so
- that we get a picture of how fast Jinja is for a semi real world
- template. If a template engine is not installed the test is skipped.\
-"""
-import cgi
-import sys
-from timeit import Timer
-
-from jinja2 import Environment as JinjaEnvironment
-from jinja2._compat import text_type
-
-context = {
- "page_title": "mitsuhiko's benchmark",
- "table": [
- dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) for x in range(1000)
- ],
-}
-
-jinja_template = JinjaEnvironment(
- line_statement_prefix="%", variable_start_string="${", variable_end_string="}"
-).from_string(
- """\
-<!doctype html>
-<html>
- <head>
- <title>${page_title|e}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title|e}</h1>
- </div>
- <ul class="navigation">
- % for href, caption in [
- ('index.html', 'Index'),
- ('downloads.html', 'Downloads'),
- ('products.html', 'Products')
- ]
- <li><a href="${href|e}">${caption|e}</a></li>
- % endfor
- </ul>
- <div class="table">
- <table>
- % for row in table
- <tr>
- % for cell in row
- <td>${cell}</td>
- % endfor
- </tr>
- % endfor
- </table>
- </div>
- </body>
-</html>\
-"""
-)
-
-
-def test_jinja():
- jinja_template.render(context)
-
-
-try:
- from tornado.template import Template
-except ImportError:
- test_tornado = None
-else:
- tornado_template = Template(
- """\
-<!doctype html>
-<html>
- <head>
- <title>{{ page_title }}</title>
- </head>
- <body>
- <div class="header">
- <h1>{{ page_title }}</h1>
- </div>
- <ul class="navigation">
- {% for href, caption in [ \
- ('index.html', 'Index'), \
- ('downloads.html', 'Downloads'), \
- ('products.html', 'Products') \
- ] %}
- <li><a href="{{ href }}">{{ caption }}</a></li>
- {% end %}
- </ul>
- <div class="table">
- <table>
- {% for row in table %}
- <tr>
- {% for cell in row %}
- <td>{{ cell }}</td>
- {% end %}
- </tr>
- {% end %}
- </table>
- </div>
- </body>
-</html>\
-"""
- )
-
- def test_tornado():
- tornado_template.generate(**context)
-
-
-try:
- from django.conf import settings
-
- settings.configure()
- from django.template import Template as DjangoTemplate, Context as DjangoContext
-except ImportError:
- test_django = None
-else:
- django_template = DjangoTemplate(
- """\
-<!doctype html>
-<html>
- <head>
- <title>{{ page_title }}</title>
- </head>
- <body>
- <div class="header">
- <h1>{{ page_title }}</h1>
- </div>
- <ul class="navigation">
- {% for href, caption in navigation %}
- <li><a href="{{ href }}">{{ caption }}</a></li>
- {% endfor %}
- </ul>
- <div class="table">
- <table>
- {% for row in table %}
- <tr>
- {% for cell in row %}
- <td>{{ cell }}</td>
- {% endfor %}
- </tr>
- {% endfor %}
- </table>
- </div>
- </body>
-</html>\
-"""
- )
-
- def test_django():
- c = DjangoContext(context)
- c["navigation"] = [
- ("index.html", "Index"),
- ("downloads.html", "Downloads"),
- ("products.html", "Products"),
- ]
- django_template.render(c)
-
-
-try:
- from mako.template import Template as MakoTemplate
-except ImportError:
- test_mako = None
-else:
- mako_template = MakoTemplate(
- """\
-<!doctype html>
-<html>
- <head>
- <title>${page_title|h}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title|h}</h1>
- </div>
- <ul class="navigation">
- % for href, caption in [('index.html', 'Index'), ('downloads.html', 'Downloads'), \
-('products.html', 'Products')]:
- <li><a href="${href|h}">${caption|h}</a></li>
- % endfor
- </ul>
- <div class="table">
- <table>
- % for row in table:
- <tr>
- % for cell in row:
- <td>${cell}</td>
- % endfor
- </tr>
- % endfor
- </table>
- </div>
- </body>
-</html>\
-"""
- )
-
- def test_mako():
- mako_template.render(**context)
-
-
-try:
- from genshi.template import MarkupTemplate as GenshiTemplate
-except ImportError:
- test_genshi = None
-else:
- genshi_template = GenshiTemplate(
- """\
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">
- <head>
- <title>${page_title}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title}</h1>
- </div>
- <ul class="navigation">
- <li py:for="href, caption in [
- ('index.html', 'Index'),
- ('downloads.html', 'Downloads'),
- ('products.html', 'Products')]"><a href="${href}">${caption}</a></li>
- </ul>
- <div class="table">
- <table>
- <tr py:for="row in table">
- <td py:for="cell in row">${cell}</td>
- </tr>
- </table>
- </div>
- </body>
-</html>\
-"""
- )
-
- def test_genshi():
- genshi_template.generate(**context).render("html", strip_whitespace=False)
-
-
-try:
- from Cheetah.Template import Template as CheetahTemplate
-except ImportError:
- test_cheetah = None
-else:
- cheetah_template = CheetahTemplate(
- """\
-#import cgi
-<!doctype html>
-<html>
- <head>
- <title>$cgi.escape($page_title)</title>
- </head>
- <body>
- <div class="header">
- <h1>$cgi.escape($page_title)</h1>
- </div>
- <ul class="navigation">
- #for $href, $caption in [('index.html', 'Index'), ('downloads.html', 'Downloads'), \
-('products.html', 'Products')]:
- <li><a href="$cgi.escape($href)">$cgi.escape($caption)</a></li>
- #end for
- </ul>
- <div class="table">
- <table>
- #for $row in $table:
- <tr>
- #for $cell in $row:
- <td>$cell</td>
- #end for
- </tr>
- #end for
- </table>
- </div>
- </body>
-</html>\
-""",
- searchList=[dict(context)],
- )
-
- def test_cheetah():
- text_type(cheetah_template)
-
-
-try:
- import tenjin
-except ImportError:
- test_tenjin = None
-else:
- tenjin_template = tenjin.Template()
- tenjin_template.convert(
- """\
-<!doctype html>
-<html>
- <head>
- <title>${page_title}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title}</h1>
- </div>
- <ul class="navigation">
-<?py for href, caption in [('index.html', 'Index'), ('downloads.html', 'Downloads'), \
-('products.html', 'Products')]: ?>
- <li><a href="${href}">${caption}</a></li>
-<?py #end ?>
- </ul>
- <div class="table">
- <table>
-<?py for row in table: ?>
- <tr>
-<?py for cell in row: ?>
- <td>#{cell}</td>
-<?py #end ?>
- </tr>
-<?py #end ?>
- </table>
- </div>
- </body>
-</html>\
-"""
- )
-
- def test_tenjin():
- tenjin_template.render(context, locals())
-
-
-try:
- from spitfire.compiler import util as SpitfireTemplate
- from spitfire.compiler.analyzer import o2_options as spitfire_optimizer
-except ImportError:
- test_spitfire = None
-else:
- spitfire_template = SpitfireTemplate.load_template(
- """\
-<!doctype html>
-<html>
- <head>
- <title>$cgi.escape($page_title)</title>
- </head>
- <body>
- <div class="header">
- <h1>$cgi.escape($page_title)</h1>
- </div>
- <ul class="navigation">
- #for $href, $caption in [('index.html', 'Index'), ('downloads.html', 'Downloads'), \
-('products.html', 'Products')]
- <li><a href="$cgi.escape($href)">$cgi.escape($caption)</a></li>
- #end for
- </ul>
- <div class="table">
- <table>
- #for $row in $table
- <tr>
- #for $cell in $row
- <td>$cell</td>
- #end for
- </tr>
- #end for
- </table>
- </div>
- </body>
-</html>\
-""",
- "spitfire_tmpl",
- spitfire_optimizer,
- {"enable_filters": False},
- )
- spitfire_context = dict(context, **{"cgi": cgi})
-
- def test_spitfire():
- spitfire_template(search_list=[spitfire_context]).main()
-
-
-try:
- from chameleon.zpt.template import PageTemplate
-except ImportError:
- test_chameleon = None
-else:
- chameleon_template = PageTemplate(
- """\
-<html xmlns:tal="http://xml.zope.org/namespaces/tal">
- <head>
- <title tal:content="page_title">Page Title</title>
- </head>
- <body>
- <div class="header">
- <h1 tal:content="page_title">Page Title</h1>
- </div>
- <ul class="navigation">
- <li tal:repeat="item sections"><a tal:attributes="href item[0]" \
-tal:content="item[1]">caption</a></li>
- </ul>
- <div class="table">
- <table>
- <tr tal:repeat="row table">
- <td tal:repeat="cell row" tal:content="row[cell]">cell</td>
- </tr>
- </table>
- </div>
- </body>
-</html>\
-"""
- )
- chameleon_context = dict(context)
- chameleon_context["sections"] = [
- ("index.html", "Index"),
- ("downloads.html", "Downloads"),
- ("products.html", "Products"),
- ]
-
- def test_chameleon():
- chameleon_template.render(**chameleon_context)
-
-
-try:
- from chameleon.zpt.template import PageTemplate
- from chameleon.genshi import language
-except ImportError:
- test_chameleon_genshi = None
-else:
- chameleon_genshi_template = PageTemplate(
- """\
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">
- <head>
- <title>${page_title}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title}</h1>
- </div>
- <ul class="navigation">
- <li py:for="info in sections"><a href="${info[0]}">${info[1]}</a></li>
- </ul>
- <div class="table">
- <table>
- <tr py:for="row in table">
- <td py:for="cell in row">${row[cell]}</td>
- </tr>
- </table>
- </div>
- </body>
-</html>\
-""",
- parser=language.Parser(),
- )
- chameleon_genshi_context = dict(context)
- chameleon_genshi_context["sections"] = [
- ("index.html", "Index"),
- ("downloads.html", "Downloads"),
- ("products.html", "Products"),
- ]
-
- def test_chameleon_genshi():
- chameleon_genshi_template.render(**chameleon_genshi_context)
-
-
-sys.stdout.write(
- "\r"
- + "\n".join(
- (
- "=" * 80,
- "Template Engine BigTable Benchmark".center(80),
- "=" * 80,
- __doc__,
- "-" * 80,
- )
- )
- + "\n"
-)
-
-
-for test in (
- "jinja",
- "mako",
- "tornado",
- "tenjin",
- "spitfire",
- "django",
- "genshi",
- "cheetah",
- "chameleon",
- "chameleon_genshi",
-):
- if locals()["test_" + test] is None:
- sys.stdout.write(" %-20s*not installed*\n" % test)
- continue
- t = Timer(setup="from __main__ import test_%s as bench" % test, stmt="bench()")
- sys.stdout.write(" >> %-20s<running>" % test)
- sys.stdout.flush()
- sys.stdout.write("\r %-20s%.4f seconds\n" % (test, t.timeit(number=50) / 50))
-sys.stdout.write("-" * 80 + "\n")
-sys.stdout.write(
- """\
- WARNING: The results of this benchmark are useless to compare the
- performance of template engines and should not be taken seriously in any
- way. It's testing the performance of simple loops and has no real-world
- usefulnes. It only used to check if changes on the Jinja code affect
- performance in a good or bad way and how it roughly compares to others.
-"""
- + "=" * 80
- + "\n"
-)
diff --git a/examples/profile.py b/examples/profile.py
deleted file mode 100644
index b16d99f..0000000
--- a/examples/profile.py
+++ /dev/null
@@ -1,54 +0,0 @@
-from __future__ import print_function
-
-try:
- from cProfile import Profile
-except ImportError:
- from profile import Profile
-from pstats import Stats
-from jinja2 import Environment as JinjaEnvironment
-
-context = {
- "page_title": "mitsuhiko's benchmark",
- "table": [
- dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10) for x in range(1000)
- ],
-}
-
-source = """\
-% macro testmacro(x)
- <span>${x}</span>
-% endmacro
-<!doctype html>
-<html>
- <head>
- <title>${page_title|e}</title>
- </head>
- <body>
- <div class="header">
- <h1>${page_title|e}</h1>
- </div>
- <div class="table">
- <table>
- % for row in table
- <tr>
- % for cell in row
- <td>${testmacro(cell)}</td>
- % endfor
- </tr>
- % endfor
- </table>
- </div>
- </body>
-</html>\
-"""
-jinja_template = JinjaEnvironment(
- line_statement_prefix="%", variable_start_string="${", variable_end_string="}"
-).from_string(source)
-print(jinja_template.environment.compile(source, raw=True))
-
-
-p = Profile()
-p.runcall(lambda: jinja_template.render(context))
-stats = Stats(p)
-stats.sort_stats("time", "calls")
-stats.print_stats()
diff --git a/examples/rwbench/django/_form.html b/examples/rwbench/django/_form.html
deleted file mode 100644
index 9c4f710..0000000
--- a/examples/rwbench/django/_form.html
+++ /dev/null
@@ -1 +0,0 @@
-<form action="{{ action }}" method="{{ method }}">{{ body }}</form>
diff --git a/examples/rwbench/django/_input_field.html b/examples/rwbench/django/_input_field.html
deleted file mode 100644
index 290fdbd..0000000
--- a/examples/rwbench/django/_input_field.html
+++ /dev/null
@@ -1 +0,0 @@
-<input type="{{ type }}" value="{{ value }}" name="{{ name }}">
diff --git a/examples/rwbench/django/_textarea.html b/examples/rwbench/django/_textarea.html
deleted file mode 100644
index 7f10424..0000000
--- a/examples/rwbench/django/_textarea.html
+++ /dev/null
@@ -1 +0,0 @@
-<textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols }}">{{ value }}</textarea>
diff --git a/examples/rwbench/django/index.html b/examples/rwbench/django/index.html
deleted file mode 100644
index 6f620bb..0000000
--- a/examples/rwbench/django/index.html
+++ /dev/null
@@ -1,29 +0,0 @@
-{% extends "layout.html" %}
-{% block page_title %}Index Page{% endblock %}
-{% block body %}
- {% for article in articles %}
- {% if article.published %}
- <div class="article">
- <h2><a href="{{ article.href }}">{{ article.title }}</a></h2>
- <p class="meta">written by <a href="{{ article.user.href }}">{{ article.user.username }}</a> on {{ article.pub_date|dateformat }}</p>
- <div class="text">{{ article.body|safe }}</div>
- </div>
- {% endif %}
- {% endfor %}
- {% form %}
- <dl>
- <dt>Name</dt>
- <dd>{% input_field 'name' %}</dd>
- <dt>E-Mail</dt>
- <dd>{% input_field 'email' %}</dd>
- <dt>URL</dt>
- <dd>{% input_field 'url' %}</dd>
- <dt>Comment</dt>
- <dd>{% textarea 'comment' %}</dd>
- <dt>Captcha</dt>
- <dd>{% input_field 'captcha' %}</dd>
- </dl>
- {% input_field '' 'submit' 'Submit' %}
- {% input_field 'cancel' 'submit' 'Cancel' %}
- {% endform %}
-{% endblock %}
diff --git a/examples/rwbench/django/layout.html b/examples/rwbench/django/layout.html
deleted file mode 100644
index b75cbfb..0000000
--- a/examples/rwbench/django/layout.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
- <title>{% block page_title %}{% endblock %} | RealWorld Benchmark</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-</head>
-<body>
- <div class="contents">
- <div class="header">
- <h1>RealWorld Benchmark</h1>
- <blockquote><p>
- A less stupid benchmark for Mako and Jinja to get an impression how
- code changes affect runtime performance.
- </p></blockquote>
- </div>
- <ul class="navigation">
- {% for href, caption in page_navigation %}
- <li><a href="{{ href }}">{{ caption }}</a></li>
- {% endfor %}
- </ul>
- <div class="body">
- {% block body %}{% endblock %}
- </div>
- <div class="footer">
- &copy; Copyright 2008 by I don't know who.
- </div>
- </div>
-</body>
-</html>
diff --git a/examples/rwbench/djangoext.py b/examples/rwbench/djangoext.py
deleted file mode 100644
index 0052aef..0000000
--- a/examples/rwbench/djangoext.py
+++ /dev/null
@@ -1,126 +0,0 @@
-# -*- coding: utf-8 -*-
-from os.path import join
-
-from django import template as django_template_module
-from django.conf import settings
-from django.template import Context as DjangoContext
-from django.template import loader as django_loader
-from django.template import Node
-from django.template import TokenParser
-from django.template import Variable
-from rwbench import dateformat
-from rwbench import ROOT
-
-settings.configure(
- TEMPLATE_DIRS=(join(ROOT, "django"),),
- TEMPLATE_LOADERS=(
- (
- "django.template.loaders.cached.Loader",
- ("django.template.loaders.filesystem.Loader",),
- ),
- ),
-)
-
-# for django extensions. We monkey patch our extensions in so that
-# we don't have to initialize a more complex django setup.
-django_extensions = django_template_module.Library()
-django_template_module.builtins.append(django_extensions)
-
-django_extensions.filter(dateformat)
-
-
-def var_or_none(x):
- if x is not None:
- return Variable(x)
-
-
-# and more django extensions
-@django_extensions.tag
-def input_field(parser, token):
- p = TokenParser(token.contents)
- args = [p.value()]
- while p.more():
- args.append(p.value())
- return InputFieldNode(*args)
-
-
-@django_extensions.tag
-def textarea(parser, token):
- p = TokenParser(token.contents)
- args = [p.value()]
- while p.more():
- args.append(p.value())
- return TextareaNode(*args)
-
-
-@django_extensions.tag
-def form(parser, token):
- p = TokenParser(token.contents)
- args = []
- while p.more():
- args.append(p.value())
- body = parser.parse(("endform",))
- parser.delete_first_token()
- return FormNode(body, *args)
-
-
-class InputFieldNode(Node):
- def __init__(self, name, type=None, value=None):
- self.name = var_or_none(name)
- self.type = var_or_none(type)
- self.value = var_or_none(value)
-
- def render(self, context):
- name = self.name.resolve(context)
- type = "text"
- value = ""
- if self.type is not None:
- type = self.type.resolve(context)
- if self.value is not None:
- value = self.value.resolve(context)
- tmpl = django_loader.get_template("_input_field.html")
- return tmpl.render(DjangoContext({"name": name, "type": type, "value": value}))
-
-
-class TextareaNode(Node):
- def __init__(self, name, rows=None, cols=None, value=None):
- self.name = var_or_none(name)
- self.rows = var_or_none(rows)
- self.cols = var_or_none(cols)
- self.value = var_or_none(value)
-
- def render(self, context):
- name = self.name.resolve(context)
- rows = 10
- cols = 40
- value = ""
- if self.rows is not None:
- rows = int(self.rows.resolve(context))
- if self.cols is not None:
- cols = int(self.cols.resolve(context))
- if self.value is not None:
- value = self.value.resolve(context)
- tmpl = django_loader.get_template("_textarea.html")
- return tmpl.render(
- DjangoContext({"name": name, "rows": rows, "cols": cols, "value": value})
- )
-
-
-class FormNode(Node):
- def __init__(self, body, action=None, method=None):
- self.body = body
- self.action = action
- self.method = method
-
- def render(self, context):
- body = self.body.render(context)
- action = ""
- method = "post"
- if self.action is not None:
- action = self.action.resolve(context)
- if self.method is not None:
- method = self.method.resolve(context)
- tmpl = django_loader.get_template("_form.html")
- return tmpl.render(
- DjangoContext({"body": body, "action": action, "method": method})
- )
diff --git a/examples/rwbench/genshi/helpers.html b/examples/rwbench/genshi/helpers.html
deleted file mode 100644
index ecc6dc4..0000000
--- a/examples/rwbench/genshi/helpers.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<div xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/"
- py:strip="">
-
- <py:def function="input_field(name='', value='', type='text')">
- <input type="$type" value="$value" name="$name" />
- </py:def>
-
- <py:def function="textarea(name, value='', rows=10, cols=40)">
- <textarea name="$name" rows="$rows" cols="cols">$value</textarea>
- </py:def>
-
-</div>
diff --git a/examples/rwbench/genshi/index.html b/examples/rwbench/genshi/index.html
deleted file mode 100644
index 70f697d..0000000
--- a/examples/rwbench/genshi/index.html
+++ /dev/null
@@ -1,41 +0,0 @@
-<?python
- from rwbench import dateformat
-?>
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude"
- xmlns:py="http://genshi.edgewall.org/">
- <xi:include href="layout.html" />
- <xi:include href="helpers.html" />
- <head><title>Index Page</title></head>
- <body>
- <div class="article" py:for="article in articles">
- <py:if test="article.published">
- <h2><a href="${article.href}">${article.title}</a></h2>
- <p class="meta">written by <a href="${article.user.href}"
- >${article.user.username}</a> on ${dateformat(article.pub_date)}</p>
- <div class="text">${Markup(article.body)}</div>
- </py:if>
- </div>
- <!--
- For a fair and balanced comparison we would have to use a def here
- that wraps the form data but I don't know what would be the best
- Genshi equivalent for that. Quite frankly I doubt that this makes
- sense in Genshi anyways.
- -->
- <form action="" method="post">
- <dl>
- <dt>Name</dt>
- <dd>${input_field('name')}</dd>
- <dt>E-Mail</dt>
- <dd>${input_field('email')}</dd>
- <dt>URL</dt>
- <dd>${input_field('url')}</dd>
- <dt>Comment</dt>
- <dd>${textarea('comment')}</dd>
- <dt>Captcha</dt>
- <dd>${input_field('captcha')}</dd>
- </dl>
- ${input_field(type='submit', value='Submit')}
- ${input_field(name='cancel', type='submit', value='Cancel')}
- </form>
- </body>
-</html>
diff --git a/examples/rwbench/genshi/layout.html b/examples/rwbench/genshi/layout.html
deleted file mode 100644
index d56fffd..0000000
--- a/examples/rwbench/genshi/layout.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/" >
- <py:match path="head" once="true">
- <head>
- <title>${select('title/text()')} | RealWorld Benchmark</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
- </py:match>
- <py:match path="body" once="true">
- <body>
- <div class="contents">
- <div class="header">
- <h1>RealWorld Benchmark</h1>
- <blockquote><p>
- A less stupid benchmark for Mako and Jinja to get an impression how
- code changes affect runtime performance.
- </p></blockquote>
- </div>
- <ul class="navigation">
- <li py:for="href, caption in page_navigation"><a href="$href">$caption</a></li>
- </ul>
- <div class="body">
- ${select('*|text()')}
- </div>
- <div class="footer">
- &copy; Copyright 2008 by I don't know who.
- </div>
- </div>
- </body>
- </py:match>
-</html>
diff --git a/examples/rwbench/jinja/helpers.html b/examples/rwbench/jinja/helpers.html
deleted file mode 100644
index 89976aa..0000000
--- a/examples/rwbench/jinja/helpers.html
+++ /dev/null
@@ -1,12 +0,0 @@
-{% macro input_field(name, value='', type='text') -%}
- <input type="{{ type }}" value="{{ value|e }}" name="{{ name }}">
-{%- endmacro %}
-
-{% macro textarea(name, value='', rows=10, cols=40) -%}
- <textarea name="{{ name }}" rows="{{ rows }}" cols="{{ cols }}">{{
- value|e }}</textarea>
-{%- endmacro %}
-
-{% macro form(action='', method='post') -%}
- <form action="{{ action|e }}" method="{{ method }}">{{ caller() }}</form>
-{%- endmacro %}
diff --git a/examples/rwbench/jinja/index.html b/examples/rwbench/jinja/index.html
deleted file mode 100644
index b006d05..0000000
--- a/examples/rwbench/jinja/index.html
+++ /dev/null
@@ -1,29 +0,0 @@
-{% extends "layout.html" %}
-{% from "helpers.html" import input_field, textarea, form %}
-{% block page_title %}Index Page{% endblock %}
-{% block body %}
- {%- for article in articles if article.published %}
- <div class="article">
- <h2><a href="{{ article.href|e }}">{{ article.title|e }}</a></h2>
- <p class="meta">written by <a href="{{ article.user.href|e
- }}">{{ article.user.username|e }}</a> on {{ article.pub_date|dateformat }}</p>
- <div class="text">{{ article.body }}</div>
- </div>
- {%- endfor %}
- {%- call form() %}
- <dl>
- <dt>Name</dt>
- <dd>{{ input_field('name') }}</dd>
- <dt>E-Mail</dt>
- <dd>{{ input_field('email') }}</dd>
- <dt>URL</dt>
- <dd>{{ input_field('url') }}</dd>
- <dt>Comment</dt>
- <dd>{{ textarea('comment') }}</dd>
- <dt>Captcha</dt>
- <dd>{{ input_field('captcha') }}</dd>
- </dl>
- {{ input_field(type='submit', value='Submit') }}
- {{ input_field('cancel', type='submit', value='Cancel') }}
- {%- endcall %}
-{% endblock %}
diff --git a/examples/rwbench/jinja/layout.html b/examples/rwbench/jinja/layout.html
deleted file mode 100644
index 308ba9d..0000000
--- a/examples/rwbench/jinja/layout.html
+++ /dev/null
@@ -1,29 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
- <title>{% block page_title %}{% endblock %} | RealWorld Benchmark</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-</head>
-<body>
- <div class="contents">
- <div class="header">
- <h1>RealWorld Benchmark</h1>
- <blockquote><p>
- A less stupid benchmark for Mako and Jinja to get an impression how
- code changes affect runtime performance.
- </p></blockquote>
- </div>
- <ul class="navigation">
- {%- for href, caption in page_navigation %}
- <li><a href="{{ href|e }}">{{ caption }}</a></li>
- {%- endfor %}
- </ul>
- <div class="body">
- {% block body %}{% endblock %}
- </div>
- <div class="footer">
- &copy; Copyright 2008 by I don't know who.
- </div>
- </div>
-</body>
-</html>
diff --git a/examples/rwbench/mako/helpers.html b/examples/rwbench/mako/helpers.html
deleted file mode 100644
index a0290eb..0000000
--- a/examples/rwbench/mako/helpers.html
+++ /dev/null
@@ -1,11 +0,0 @@
-<%def name="input_field(name='', value='', type='text')">
- <input type="${type}" value="${value|h}" name="${name}">
-</%def>
-
-<%def name="textarea(name, value='', rows=10, cols=40)">
- <textarea name="${name}" rows="${rows}" cols="${cols}">${value|h}</textarea>
-</%def>
-
-<%def name="form(action='', method='post')">
- <form action="${action|h}" method="${method}">${caller.body()}</form>
-</%def>
diff --git a/examples/rwbench/mako/index.html b/examples/rwbench/mako/index.html
deleted file mode 100644
index c4c6303..0000000
--- a/examples/rwbench/mako/index.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<%!
- from rwbench import dateformat
-%>
-<%inherit file="layout.html" />
-<%namespace file="helpers.html" import="input_field, textarea, form" />
-<%def name="page_title()">Index Page</%def>
-% for article in articles:
- <% if not article.published: continue %>
-<div class="article">
- <h2><a href="${article.href|h}">${article.title|h}</a></h2>
- <p class="meta">written by <a href="${article.user.href|h
- }">${article.user.username|h}</a> on ${dateformat(article.pub_date)}</p>
- <div class="text">${article.body}</div>
-</div>
-% endfor
-<%call expr="form()">
- <dl>
- <dt>Name</dt>
- <dd>${input_field('name')}</dd>
- <dt>E-Mail</dt>
- <dd>${input_field('email')}</dd>
- <dt>URL</dt>
- <dd>${input_field('url')}</dd>
- <dt>Comment</dt>
- <dd>${textarea('comment')}</dd>
- <dt>Captcha</dt>
- <dd>${input_field('captcha')}</dd>
- </dl>
- ${input_field(type='submit', value='Submit')}
- ${input_field(name='cancel', type='submit', value='Cancel')}
-</%call>
diff --git a/examples/rwbench/mako/layout.html b/examples/rwbench/mako/layout.html
deleted file mode 100644
index 15e9282..0000000
--- a/examples/rwbench/mako/layout.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
-<html>
-<head>
- <title>${self.page_title()} | RealWorld Benchmark</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-</head>
-<body>
- <div class="contents">
- <div class="header">
- <h1>RealWorld Benchmark</h1>
- <blockquote><p>
- A less stupid benchmark for Mako and Jinja to get an impression how
- code changes affect runtime performance.
- </p></blockquote>
- </div>
- <ul class="navigation">
- % for href, caption in page_navigation:
- <li><a href="${href|h}">${caption}</a></li>
- % endfor
- </ul>
- <div class="body">
- ${self.body()}
- </div>
- <div class="footer">
- &copy; Copyright 2008 by I don't know who.
- </div>
- </div>
-</body>
-</html>
-<%def name="page_title()"></%def>
diff --git a/examples/rwbench/rwbench.py b/examples/rwbench/rwbench.py
deleted file mode 100644
index 957216a..0000000
--- a/examples/rwbench/rwbench.py
+++ /dev/null
@@ -1,122 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
- RealWorldish Benchmark
- ~~~~~~~~~~~~~~~~~~~~~~
-
- A more real-world benchmark of Jinja. Like the other benchmark in the
- Jinja repository this has no real-world usefulnes (despite the name).
- Just go away and ignore it. NOW!
-
- :copyright: (c) 2009 by the Jinja Team.
- :license: BSD.
-"""
-from __future__ import print_function
-
-import sys
-from datetime import datetime
-from os.path import abspath
-from os.path import dirname
-from os.path import join
-from pstats import Stats
-from random import choice
-from random import randrange
-from timeit import Timer
-
-from djangoext import django_loader
-from djangoext import DjangoContext
-from genshi.template import TemplateLoader as GenshiTemplateLoader
-from mako.lookup import TemplateLookup
-
-from jinja2 import Environment
-from jinja2 import FileSystemLoader
-from jinja2.utils import generate_lorem_ipsum
-
-try:
- from cProfile import Profile
-except ImportError:
- from profile import Profile
-
-ROOT = abspath(dirname(__file__))
-
-
-def dateformat(x):
- return x.strftime("%Y-%m-%d")
-
-
-jinja_env = Environment(loader=FileSystemLoader(join(ROOT, "jinja")))
-jinja_env.filters["dateformat"] = dateformat
-mako_lookup = TemplateLookup(directories=[join(ROOT, "mako")])
-genshi_loader = GenshiTemplateLoader([join(ROOT, "genshi")])
-
-
-class Article(object):
- def __init__(self, id):
- self.id = id
- self.href = "/article/%d" % self.id
- self.title = generate_lorem_ipsum(1, False, 5, 10)
- self.user = choice(users)
- self.body = generate_lorem_ipsum()
- self.pub_date = datetime.utcfromtimestamp(randrange(10 ** 9, 2 * 10 ** 9))
- self.published = True
-
-
-class User(object):
- def __init__(self, username):
- self.href = "/user/%s" % username
- self.username = username
-
-
-users = map(User, [u"John Doe", u"Jane Doe", u"Peter Somewhat"])
-articles = map(Article, range(20))
-navigation = [
- ("index", "Index"),
- ("about", "About"),
- ("foo?bar=1", "Foo with Bar"),
- ("foo?bar=2&s=x", "Foo with X"),
- ("blah", "Blub Blah"),
- ("hehe", "Haha"),
-] * 5
-
-context = dict(users=users, articles=articles, page_navigation=navigation)
-
-jinja_template = jinja_env.get_template("index.html")
-mako_template = mako_lookup.get_template("index.html")
-genshi_template = genshi_loader.load("index.html")
-
-
-def test_jinja():
- jinja_template.render(context)
-
-
-def test_mako():
- mako_template.render_unicode(**context)
-
-
-def test_django():
- # not cached because django is not thread safe and does
- # not cache by itself so it would be unfair to cache it here.
- django_template = django_loader.get_template("index.html")
- django_template.render(DjangoContext(context))
-
-
-def test_genshi():
- genshi_template.generate(**context).render("html", doctype="html")
-
-
-if __name__ == "__main__":
- sys.stdout.write("Realworldish Benchmark:\n")
- for test in "jinja", "mako", "django", "genshi":
- t = Timer(setup="from __main__ import test_%s as bench" % test, stmt="bench()")
- sys.stdout.write(" >> %-20s<running>" % test)
- sys.stdout.flush()
- sys.stdout.write(
- "\r %-20s%.4f seconds\n" % (test, t.timeit(number=200) / 200)
- )
-
- if "-p" in sys.argv:
- print("Jinja profile")
- p = Profile()
- p.runcall(test_jinja)
- stats = Stats(p)
- stats.sort_stats("time", "calls")
- stats.print_stats()