<commit_before>import logging
import logging.config
import re
from asyncio import get_event_loop, Queue
from collections import deque, defaultdict
from functools import partial
from inspect import isawaitable, stack, getmodulename
from traceback import format_exc
from urllib.parse import urlencode, urlunparse

from mach9.config import Config, LOGGING
from mach9.exceptions import ServerError, URLBuildError
from mach9.handlers import ErrorHandler
from mach9.log import log as _log
from mach9.log import log as _netlog
from mach9.response import HTTPResponse, StreamHTTPResponse, WebsocketResponse
from mach9.router import Router
from mach9.request import Request
from mach9.static import register as static_register
from mach9.testing import Mach9TestClient
from mach9.views import CompositionView
from mach9.server import Server


class Mach9:

    def __init__(self, name=None, router=None, error_handler=None,
                 load_env=True, request_class=None, debug=None,
                 log=None, netlog=None,
                 log_config=LOGGING,
                 get_current_time=None, composition_view=None,
                 stream_http_response_class=None,
                 websocket_response_class=None):

        self.log = log or _log

        if log_config:
            logging.config.dictConfig(log_config)
        # Only set up a default log handler if the
        # end-user application didn't set anything up.
        if (log_config and not logging.root.handlers
                and self.log.level == logging.NOTSET):
            formatter = logging.Formatter(
                '%(asctime)s: %(levelname)s: %(message)s')
            handler = logging.StreamHandler()
            handler.setFormatter(formatter)
            self.log.addHandler(handler)
            self.log.setLevel(logging.INFO)

        # Get name from previous stack frame
        if name is None:
            frame_records = stack()[1]
            name = getmodulename(frame_records[1])

        _composition_view = composition_view or CompositionView

        self.config = config = Config(load_env=load_env)
        self.request_max_size = config.REQUEST_MAX_SIZE
        self.request_timeout = config.REQUEST_TIMEOUT
        self.keep_alive = config.KEEP_ALIVE
        self.name = name
        self.websocket_channels = {}
        self.composition_view_class = _composition_view
        self.router = router or Router(_composition_view)
        self.request_class = request_class or Request
        self.error_handler = error_handler or ErrorHandler(self.log)
        self.debug = debug
        self.error_handler.debug = debug
        self.log_config = log_config
        self.request_middleware = deque()
        self.response_middleware = deque()
        self.blueprints = {}
        self._blueprint_order = []
        self.stream_http_response_class = (
            stream_http_response_class or StreamHTTPResponse)
        self.websocket_response_class = (
            websocket_response_class or WebsocketResponse)
        self.sock = None<commit_msg>Remove get_current_time() in app.py (#60)<commit_after>import logging
import logging.config
import re
from asyncio import get_event_loop, Queue
from collections import deque, defaultdict
from functools import partial
from inspect import isawaitable, stack, getmodulename
from traceback import format_exc
from urllib.parse import urlencode, urlunparse

from mach9.config import Config, LOGGING
from mach9.exceptions import ServerError, URLBuildError
from mach9.handlers import ErrorHandler
from mach9.log import log as _log
from mach9.log import log as _netlog
from mach9.response import HTTPResponse, StreamHTTPResponse, WebsocketResponse
from mach9.router import Router
from mach9.request import Request
from mach9.static import register as static_register
from mach9.testing import Mach9TestClient
from mach9.views import CompositionView
from mach9.server import Server


class Mach9:

    def __init__(self, name=None, router=None, error_handler=None,
                 load_env=True, request_class=None, debug=None,
                 log=None, netlog=None, log_config=LOGGING,
                 composition_view_class=None,
                 stream_http_response_class=None,
                 websocket_response_class=None):

        self.log = log or _log

        if log_config:
            logging.config.dictConfig(log_config)
        # Only set up a default log handler if the
        # end-user application didn't set anything up.
        if (log_config and not logging.root.handlers
                and self.log.level == logging.NOTSET):
            formatter = logging.Formatter(
                '%(asctime)s: %(levelname)s: %(message)s')
            handler = logging.StreamHandler()
            handler.setFormatter(formatter)
            self.log.addHandler(handler)
            self.log.setLevel(logging.INFO)

        # Get name from previous stack frame
        if name is None:
            frame_records = stack()[1]
            name = getmodulename(frame_records[1])

        _composition_view_class = composition_view_class or CompositionView

        self.config = config = Config(load_env=load_env)
        self.request_max_size = config.REQUEST_MAX_SIZE
        self.request_timeout = config.REQUEST_TIMEOUT
        self.keep_alive = config.KEEP_ALIVE
        self.name = name
        self.websocket_channels = {}
        self.composition_view_class = _composition_view_class
        self.router = router or Router(_composition_view_class)
        self.request_class = request_class or Request
        self.error_handler = error_handler or ErrorHandler(self.log)
        self.debug = debug
        self.error_handler.debug = debug
        self.log_config = log_config
        self.request_middleware = deque()
        self.response_middleware = deque()
        self.blueprints = {}
        self._blueprint_order = []
        self.stream_http_response_class = (
            stream_http_response_class or StreamHTTPResponse)
        self.websocket_response_class = (
            websocket_response_class or WebsocketResponse)
        self.sock = None
{'fraction_non_alphanumeric': 0.06311314584695879, 'fraction_numerical': 0.005559189012426423, 'mean_word_length': 2.8568726355611602, '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': '706106', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1636, 'n_words': 434}