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

import os
import pkgutil

from mako.lookup import TemplateLookup
from mako.template import Template


class DottedTemplateLookup(TemplateLookup):
    def __init__(self, pkg):
        self.dfltpkg = pkg

    def adjust_uri(self, uri, relto):
        return uri

    def get_template(self, name):
        div = name.rfind('.')

        # Break apart name into a package and base file name
        if div >= 0:
            pkg = name[:div]
            basename = name[div + 1:]
        else:
            pkg = self.dfltpkg
            basename = name

        # Attempt to load the template
        try:
            tpl = pkgutil.get_data(pkg, basename + '.mako')
            return Template(tpl, lookup=self)
        except IOError:
            raise RuntimeError('Template "{}" not found'.format(name))<commit_msg>Enhance the dotted name lookup functionality.<commit_after> # -*- coding: utf-8 -*-

import os
import pkgutil

from mako.lookup import TemplateLookup
from mako.template import Template


class DottedTemplateLookup(TemplateLookup):
    def __init__(self, pkg):
        self.dfltpkg = pkg

    def adjust_uri(self, uri, relto):
        return uri

    def get_template(self, name):
        div = name.rfind('.')

        # Break apart name into a package and base file name
        if div >= 0:
            pkg = name[:div]
            basename = name[div + 1:]
        else:
            pkg = self.dfltpkg
            basename = name

        # Attempt to load the template
        src = pkgutil.get_data(pkg, basename + '.mako')
        if not src:
            raise RuntimeError('Template "{}" not found'.format(name))

        return Template(src, lookup=self)
{'fraction_non_alphanumeric': 0.09673659673659674, 'fraction_numerical': 0.0034965034965034965, 'mean_word_length': 2.1105072463768115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2799148', 'n_tokens_mistral': 511, 'n_tokens_neox': 479, 'n_words': 154}