<commit_before>#!/usr/bin/python

import logging
import sys, os

from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.web import Application

sys.path.append("../")
from newebe.settings import TORNADO_PORT, DEBUG, COOKIE_KEY, \
                            PRIVATE_KEY, CERTIFICATE
from newebe.routes import routes


# Set logging configuration
FORMAT = '[%(levelname)s] %(asctime)s: %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)
logger = logging.getLogger(__name__)


class Newebe(Application):
    '''
    Main application that allows access to Newebe data via REST services.
    '''

    def __init__(self):
        settings = {
          "static_path": os.path.join(os.path.dirname(__file__), "static"),
          "cookie_secret": COOKIE_KEY,
          "login_url": "/login",
        }
        Application.__init__(self, routes, debug=DEBUG, **settings)


class NewebeIOLoop(IOLoop):
    '''
    Override of Tornado IO loop to avoid logging when async requests fail.    
    '''
    def handle_callback_exception(callback):
        pass


if __name__ == '__main__':

    '''
    Main function : it is here where tornado server is configured and launched 
    as a Newebe instance.
    '''

    # Application server setup
    logger = logging.getLogger("newebe")
    logger.info("Sets up application server.")
    tornado_app = Newebe()

    if not DEBUG:
        # Send log ouptut to a file.
        log_file = 'newebe.%s.log' % TORNADO_PORT
        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
        hdlr = logging.FileHandler(os.path.join("./", log_file))
        hdlr.setFormatter(formatter)
        logger.addHandler(hdlr)
        logger.setLevel(logging.INFO)

    try:
        # SSL mode only in production
        if not DEBUG:
            ssl_options = {
                "certfile": CERTIFICATE,
                "keyfile": PRIVATE_KEY,
            }
        else:
            ssl_options = None 

        # Server running.
        http_server = HTTPServer(tornado_app, xheaders=True,
                                 ssl_options = ssl_options)

        http_server.listen(TORNADO_PORT)
        logger.info("Starts Newebe on port %d." % TORNADO_PORT)
        ioloop = NewebeIOLoop.instance()
        ioloop.start()
<commit_msg>clean server launcher<commit_after>#!/usr/bin/python

import logging
import sys, os

from tornado.ioloop import IOLoop
from tornado.httpserver import HTTPServer
from tornado.web import Application

sys.path.append("../")
from newebe.routes import routes
from newebe.settings import TORNADO_PORT, DEBUG, COOKIE_KEY, \
                            PRIVATE_KEY, CERTIFICATE


# Set logging configuration
FORMAT = '[%(levelname)s] %(asctime)s: %(message)s'
logging.basicConfig(format=FORMAT, level=logging.INFO)
logger = logging.getLogger(__name__)


class Newebe(Application):
    '''
    Main application that allows access to Newebe data via REST services.
    '''

    def __init__(self):
        settings = {
          "static_path": os.path.join(os.path.dirname(__file__), "static"),
          "cookie_secret": COOKIE_KEY,
          "login_url": "/login",
        }
        Application.__init__(self, routes, debug=DEBUG, **settings)


class NewebeIOLoop(IOLoop):
    '''
    Override of Tornado IO loop to avoid logging when async requests fail.    
    '''
    def handle_callback_exception(callback):
        pass


if __name__ == '__main__':

    '''
    Main function : it is here where tornado server is configured and launched 
    as a Newebe instance.
    '''

    # Application server setup
    logger = logging.getLogger("newebe")
    logger.info("Sets up application server.")
    tornado_app = Newebe()

    if not DEBUG:
        # Send log ouptut to a file.
        log_file = 'newebe.%s.log' % TORNADO_PORT
        formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
        hdlr = logging.FileHandler(os.path.join("./", log_file))
        hdlr.setFormatter(formatter)
        logger.addHandler(hdlr)
        logger.setLevel(logging.INFO)

        # SSL mode only in production
        ssl_options = {
            "certfile": CERTIFICATE,
            "keyfile": PRIVATE_KEY,
        }
    else:
        ssl_options = None 

    try:
        # Server running.
        http_server = HTTPServer(tornado_app, xheaders=True,
                                 ssl_options = ssl_options)

        http_server.listen(TORNADO_PORT)
        logger.info("Starts Newebe on port %d." % TORNADO_PORT)
        ioloop = NewebeIOLoop.instance()
        ioloop.start()

{'fraction_non_alphanumeric': 0.10429314830875976, 'fraction_numerical': 0.0, 'mean_word_length': 2.5375766871165646, 'pattern_counts': {'":': 10, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1599088', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1387, 'n_words': 343}