<commit_before>import time
import tornado.ioloop
import tornado.web
import os

from .config import config, dirname
from .tools import show
from .web_handlers import stream_control, stream_stats, info, mobile_stream

STATIC_PATH = os.path.join(os.path.dirname(dirname), 'www', '')


class Server(object):
    host = config.get('local', 'addr')
    port = config.getint('local', 'port')

    application = tornado.web.Application([
        (r'/control/(.*?)/(' + stream_control.options + r')/?(\d*)',
         stream_control.StreamControlHandler),
        (r'/stats/([^/]*)/?(.*)', stream_stats.StreamStatsHandler),
        (r'/info/(' + info.options + r')/?(.*)', info.InfoHandler),
        (r'/mobile/location', mobile_stream.MobileStreamLocation),
        (r'/(.*)', tornado.web.StaticFileHandler, {'path': STATIC_PATH})
    ])

    tcp_retry = 10  # seconds
    daemon_threads = True

    def start(self):
        while True:
            try:
                self.application.listen(self.port, self.host)
            except IOError:
                show('Waiting TCP port to be used.')
                time.sleep(self.tcp_retry)
            else:
                show('Listening at {0.host}:{0.port} (http)'.format(self))
                break
        return self

    def stop(self):
        pass<commit_msg>Preparing to enable external Tornado handlers<commit_after>import time
import tornado.ioloop
import tornado.web
import os

from .config import config, dirname
from .tools import show
from .web_handlers import stream_control, stream_stats, info, mobile_stream

STATIC_PATH = os.path.join(os.path.dirname(dirname), 'www', '')


def build_application():
    controllers = [
        (r'/control/(.*?)/(' + stream_control.options + r')/?(\d*)',
         stream_control.StreamControlHandler),
        (r'/stats/([^/]*)/?(.*)', stream_stats.StreamStatsHandler),
        (r'/info/(' + info.options + r')/?(.*)', info.InfoHandler),
        (r'/mobile/location', mobile_stream.MobileStreamLocation),
    ]

    for name in config.get_list('web', 'external_handlers'):
        print('>>>', name)
        #controllers.append('todo: add here!')

    controllers.append(
        (r'/(.*)', tornado.web.StaticFileHandler, {'path': STATIC_PATH})
    )
    return tornado.web.Application(controllers)


class Server(object):
    host = config.get('local', 'addr')
    port = config.getint('local', 'port')
    tcp_retry = 10  # seconds
    daemon_threads = True
    application = build_application()

    def start(self):
        while True:
            try:
                self.application.listen(self.port, self.host)
            except IOError:
                show('Waiting TCP port to be used.')
                time.sleep(self.tcp_retry)
            else:
                show('Listening at {0.host}:{0.port} (http)'.format(self))
                break
        return self

    def stop(self):
        pass
{'fraction_non_alphanumeric': 0.14860681114551083, 'fraction_numerical': 0.0027519779841761265, 'mean_word_length': 2.546341463414634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3244521', 'n_tokens_mistral': 905, 'n_tokens_neox': 857, 'n_words': 190}