<commit_before># -*- coding: utf-8 -*-
#
# Copyright (C) 2006 Edgewall Software
# Copyright (C) 2006 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://markup.edgewall.org/wiki/License.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://markup.edgewall.org/log/.

"""Basic support for the template engine plugin API used by TurboGears and
CherryPy/Buffet.
"""

from pkg_resources import resource_filename

from markup.core import Attrs, Stream, QName
from markup.eval import Undefined
from markup.input import HTML, XML
from markup.template import Context, Template, TemplateLoader

def ET(element):
    """Converts the given ElementTree element to a markup stream."""
    tag_name = element.tag
    if tag_name.startswith('{'):
        tag_name = tag_name[1:]
    tag_name = QName(tag_name)
    attrib = Attrs(element.items())

    yield (Stream.START, (tag_name, attrib), (None, -1, -1))
    if element.text:
        yield Stream.TEXT, element.text, (None, -1, -1)
    for child in element.getchildren():
        for item in et_to_stream(child):
            yield item
    yield Stream.END, tag_name, (None, -1, -1)
    if element.tail:
        yield Stream.TEXT, element.tail, (None, -1, -1)


class TemplateEnginePlugin(object):
    """Implementation of the plugin API."""

    def __init__(self, extra_vars_func=None, options=None):
        if options is None:
            options = {}
        # TODO get loader_args from the options dict

        self.loader = TemplateLoader(auto_reload=True)
        self.options = options
        self.get_extra_vars = extra_vars_func

    def load_template(self, templatename):
        """Find a template specified in python 'dot' notation."""
        divider = templatename.rfind('.')
        if divider >= 0:
            package = templatename[:divider]
            basename = templatename[divider + 1:] + '.html'
            templatename = resource_filename(package, basename)<commit_msg>Fix refactoring leftover from [242]. Closes #40.<commit_after># -*- coding: utf-8 -*-
#
# Copyright (C) 2006 Edgewall Software
# Copyright (C) 2006 <NAME>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://markup.edgewall.org/wiki/License.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://markup.edgewall.org/log/.

"""Basic support for the template engine plugin API used by TurboGears and
CherryPy/Buffet.
"""

from pkg_resources import resource_filename

from markup.core import Attrs, Stream, QName
from markup.eval import Undefined
from markup.input import HTML, XML
from markup.template import Context, Template, TemplateLoader

def ET(element):
    """Converts the given ElementTree element to a markup stream."""
    tag_name = element.tag
    if tag_name.startswith('{'):
        tag_name = tag_name[1:]
    tag_name = QName(tag_name)
    attrib = Attrs(element.items())

    yield (Stream.START, (tag_name, attrib), (None, -1, -1))
    if element.text:
        yield Stream.TEXT, element.text, (None, -1, -1)
    for child in element.getchildren():
        for item in ET(child):
            yield item
    yield Stream.END, tag_name, (None, -1, -1)
    if element.tail:
        yield Stream.TEXT, element.tail, (None, -1, -1)


class TemplateEnginePlugin(object):
    """Implementation of the plugin API."""

    def __init__(self, extra_vars_func=None, options=None):
        if options is None:
            options = {}
        # TODO get loader_args from the options dict

        self.loader = TemplateLoader(auto_reload=True)
        self.options = options
        self.get_extra_vars = extra_vars_func

    def load_template(self, templatename):
        """Find a template specified in python 'dot' notation."""
        divider = templatename.rfind('.')
        if divider >= 0:
            package = templatename[:divider]
            basename = templatename[divider + 1:] + '.html'
            templatename = resource_filename(package, basename)
{'fraction_non_alphanumeric': 0.10304396843291995, 'fraction_numerical': 0.010146561443066516, 'mean_word_length': 3.19678334910123, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6766757', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1264, 'n_words': 441}