<commit_before># -*- coding: utf-8 -*-

from . import sitecfg
from mako.lookup import TemplateLookup
from mako import exceptions


class TemplateEngine:
    def __init__(self, siteconfig: sitecfg.SiteConfig):
        params = {
            'directories':      siteconfig.TEMPLATE_DIR,
            'module_directory': siteconfig.TEMPLATE_CACHE_DIR,
            # 'input_encoding':   'utf-8',
            # 'output_encoding':   'utf-8',
            # 'encoding_errors':  'replace',
            'strict_undefined': True
        }
        self._lookup = TemplateLookup(**params)
        self._args = dict()
        self._headers_sent = False

    def assign(self, vname, vvalue):
        self._args[vname] = vvalue

    def unassign(self, vname):
        if vname in self._args:
            self._args.pop(vname)

    def render(self, tname):
        tmpl = self._lookup.get_template(tname)
        return tmpl.render(**self._args)
        # return tmpl.render_unicode(**self._args)

    def output(self, tname):
        if not self._headers_sent:
            print('Content-Type: text/html')
            print()
            self._headers_sent = True
        # MAKO exceptions handler
        try:
            rendered = self.render(tname)
            print(rendered)  # python IO encoding mut be set to utf-8 (see ../index.py header for details)
            # print(os.environ)
            # print(locale.getpreferredencoding())
            # print(type(rendered))
            # print(rendered[0:1370])
            # part = rendered[1371:1374]
            # if 'LANG' in os.environ:
            #    print(os.environ['LANG'])
            # if 'LC_ALL' in os.environ:
            #    print(os.environ['LC_ALL'])
        except exceptions.MakoException:
            print(exceptions.html_error_template().render())
<commit_msg>add method to clear all assignments<commit_after># -*- coding: utf-8 -*-

from . import sitecfg
from mako.lookup import TemplateLookup
from mako import exceptions


class TemplateEngine:
    def __init__(self, siteconfig: sitecfg.SiteConfig):
        params = {
            'directories':      siteconfig.TEMPLATE_DIR,
            'module_directory': siteconfig.TEMPLATE_CACHE_DIR,
            # 'input_encoding':   'utf-8',
            # 'output_encoding':   'utf-8',
            # 'encoding_errors':  'replace',
            'strict_undefined': True
        }
        self._lookup = TemplateLookup(**params)
        self._args = dict()
        self._headers_sent = False

    def assign(self, vname, vvalue):
        self._args[vname] = vvalue

    def unassign(self, vname):
        if vname in self._args:
            self._args.pop(vname)

    def unassign_all(self):
        self._args = dict()

    def render(self, tname):
        tmpl = self._lookup.get_template(tname)
        return tmpl.render(**self._args)
        # return tmpl.render_unicode(**self._args)

    def output(self, tname):
        if not self._headers_sent:
            print('Content-Type: text/html')
            print()
            self._headers_sent = True
        # MAKO exceptions handler
        try:
            rendered = self.render(tname)
            print(rendered)  # python IO encoding mut be set to utf-8 (see ../index.py header for details)
            # print(os.environ)
            # print(locale.getpreferredencoding())
            # print(type(rendered))
            # print(rendered[0:1370])
            # part = rendered[1371:1374]
            # if 'LANG' in os.environ:
            #    print(os.environ['LANG'])
            # if 'LC_ALL' in os.environ:
            #    print(os.environ['LC_ALL'])
        except exceptions.MakoException:
            print(exceptions.html_error_template().render())

{'fraction_non_alphanumeric': 0.11032863849765258, 'fraction_numerical': 0.008868022952529996, 'mean_word_length': 1.853422619047619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4007986', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1072, 'n_words': 233}