<commit_before>import os
import json
import falcon
import jinja2
import mimetypes


class TemplateRenderer(object):

    def __init__(self, templates_path):
        self.tpl_path = templates_path

    def render(self, tpl_name, *args, **kwargs):
        template = self._load_template(tpl_name)
        return template.render(*args, **kwargs)

    def _load_template(self, tpl):

        curr_dir = os.path.dirname(os.path.abspath(__file__))

        path, filename = os.path.split(tpl)

        templates_directory = os.path.join(curr_dir, self.tpl_path)

        return jinja2.Environment(
            loader=jinja2.FileSystemLoader(
                os.path.join(path, templates_directory)
            )
        ).get_template(filename)


class StaticSinkAdapter(object):

    def __init__(self, static_path):
        self.static_path = static_path

    def __call__(self, req, resp, filepath):
        resp.content_type = mimetypes.guess_type(filepath)[0]
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        file_path = os.path.join(
            os.path.join(curr_dir, self.static_path),
            filepath
        )
        if not os.path.exists(file_path):
            raise falcon.HTTPNotFound()
        else:
            resp.stream = open(file_path, 'rb')
            resp.stream_len = os.path.getsize(file_path)


class SwaggerUiResource(object):

    def __init__(self, templates_folder, default_context):
        self.templates = TemplateRenderer(templates_folder)
        self.context = default_context

    def on_get(self, req, resp):<commit_msg>Use Response.set_stream() instead of deprecated stream_len<commit_after>import os
import json
import falcon
import jinja2
import mimetypes


class TemplateRenderer(object):

    def __init__(self, templates_path):
        self.tpl_path = templates_path

    def render(self, tpl_name, *args, **kwargs):
        template = self._load_template(tpl_name)
        return template.render(*args, **kwargs)

    def _load_template(self, tpl):

        curr_dir = os.path.dirname(os.path.abspath(__file__))

        path, filename = os.path.split(tpl)

        templates_directory = os.path.join(curr_dir, self.tpl_path)

        return jinja2.Environment(
            loader=jinja2.FileSystemLoader(
                os.path.join(path, templates_directory)
            )
        ).get_template(filename)


class StaticSinkAdapter(object):

    def __init__(self, static_path):
        self.static_path = static_path

    def __call__(self, req, resp, filepath):
        resp.content_type = mimetypes.guess_type(filepath)[0]
        curr_dir = os.path.dirname(os.path.abspath(__file__))
        file_path = os.path.join(
            os.path.join(curr_dir, self.static_path),
            filepath
        )
        if not os.path.exists(file_path):
            raise falcon.HTTPNotFound()
        else:
            stream = open(file_path, 'rb')
            stream_len = os.path.getsize(file_path)
            resp.set_stream(stream, stream_len)


class SwaggerUiResource(object):

    def __init__(self, templates_folder, default_context):
        self.templates = TemplateRenderer(templates_folder)
        self.context = default_context

    def on_get(self, req, resp):
{'fraction_non_alphanumeric': 0.09836571076164045, 'fraction_numerical': 0.002466851680542707, 'mean_word_length': 2.7459584295612007, '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': '4203074', 'n_tokens_mistral': 1006, 'n_tokens_neox': 976, 'n_words': 186}