<commit_before># -*- coding: utf-8 -*-
"""
    tipfy.ext.mako
    ~~~~~~~~~~~~~~

    Mako template engine extension.

    It requires the mako module to be added to the lib dir. Mako can be
    downloaded at http://www.makotemplates.org/

    :copyright: 2009 by tipfy.org.
    :license: BSD, see LICENSE.txt for more details.
"""
from os import path
from mako.template import Template
from mako.runtime import Context
from StringIO import StringIO

from tipfy import local, app, response


def render_template(filename, **context):
    """Renders a template."""
    template = Template(filename=path.join(app.config.templates_dir, filename))
    buf = StringIO()
    template.render_context(Context(buf, **context))
    return buf.getvalue()


def render_response(filename, **context):
    """Renders a template and returns a response object."""
    response.data = render_template(filename, **context)
    response.mimetype = 'text/html'
    return response<commit_msg>ext.mako now uses TemplateLookup. Thanks <NAME> for the fix.<commit_after># -*- coding: utf-8 -*-
"""
    tipfy.ext.mako
    ~~~~~~~~~~~~~~

    Mako template engine extension.

    It requires the mako module to be added to the lib dir. Mako can be
    downloaded at http://www.makotemplates.org/

    :copyright: 2009 by tipfy.org.
    :license: BSD, see LICENSE.txt for more details.
"""
from os import path
from mako.lookup import TemplateLookup
from mako.runtime import Context
from StringIO import StringIO

from tipfy import local, app, response

lookup = TemplateLookup(directories=[path.join(app.config.templates_dir)],
    output_encoding='utf-8', encoding_errors='replace')


def render_template(filename, **context):
    """Renders a template."""
    template = lookup.get_template(filename)
    buf = StringIO()
    template.render_context(Context(buf, **context))
    return buf.getvalue()


def render_response(filename, **context):
    """Renders a template and returns a response object."""
    response.data = render_template(filename, **context)
    response.mimetype = 'text/html'
    return response
{'fraction_non_alphanumeric': 0.12093690248565965, 'fraction_numerical': 0.005258126195028681, 'mean_word_length': 3.901639344262295, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3083562', 'n_tokens_mistral': 610, 'n_tokens_neox': 590, 'n_words': 194}