<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import collections
import socket
import sys
import uuid

from tornado.httpserver import HTTPServer
from tornado.netutil import bind_sockets
from tornado.web import Application, RequestHandler

from project.plugins.provider import ProviderConfigContext

from project.internal.plugin_html import cleanup_and_scope_form, html_tag


class UIServerEvent(object):
    pass


class UIServerDoneEvent(UIServerEvent):
    def __init__(self, result):
        super(UIServerDoneEvent, self).__init__()
        self.result = result

# future: use actual template system
_entity_table = {"&": "&amp;", "<": "&lt;", ">": "&gt;", "'": "&#39;", '"': "&quot;"}


def _html_escape(text):
    for key, value in _entity_table.items():
        text = text.replace(key, value)
    return text


class PrepareViewHandler(RequestHandler):
    def __init__(self, application, *args, **kwargs):
        # Note: application is stored as self.application
        super(PrepareViewHandler, self).__init__(application, *args, **kwargs)

    def _outer_page(self, content):
        return """
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Project setup</title>
  </head>
  <body>
    %s
  </body>
</html><commit_msg>Fix html escape function in ui_server<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function

import collections
import socket
import sys
import uuid

from tornado.httpserver import HTTPServer
from tornado.netutil import bind_sockets
from tornado.web import Application, RequestHandler

from project.plugins.provider import ProviderConfigContext

from project.internal.plugin_html import cleanup_and_scope_form, html_tag


class UIServerEvent(object):
    pass


class UIServerDoneEvent(UIServerEvent):
    def __init__(self, result):
        super(UIServerDoneEvent, self).__init__()
        self.result = result

# future: use actual template system
# it's important to replace & before the later ones
_entity_table = [ ("&", "&amp;"), ("<", "&lt;"), (">", "&gt;"), ("'", "&#39;"), ('"', "&quot;") ]


def _html_escape(text):
    for (key, value) in _entity_table:
        text = text.replace(key, value)
    return text


class PrepareViewHandler(RequestHandler):
    def __init__(self, application, *args, **kwargs):
        # Note: application is stored as self.application
        super(PrepareViewHandler, self).__init__(application, *args, **kwargs)

    def _outer_page(self, content):
        return """
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Project setup</title>
  </head>
  <body>
    %s
  </body>
</html>
{'fraction_non_alphanumeric': 0.12915129151291513, 'fraction_numerical': 0.002952029520295203, 'mean_word_length': 4.264077669902913, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 25, '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': '2859700', 'n_tokens_mistral': 852, 'n_tokens_neox': 818, 'n_words': 228}