<commit_before>#!/usr/bin/env python

import logging
import time

import tornado.ioloop
import tornado.web

from concurrent.futures import ThreadPoolExecutor
from tornado import gen
from tornado.concurrent import run_on_executor

from get_certificate import get_certificate_expiry

HOSTNAME_REGEX = '[a-zA-Z0-9.]+'  # ish...


class CertExpiryHandler(tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(max_workers=2)

    @gen.coroutine
    @tornado.web.addslash
    def get(self, hostname, port='443'):
        port = int(port) if port else 443

        expiry_date = yield self._blocking_get_cert_expiry(hostname, port)
        self.write(str(expiry_date))

    @run_on_executor
    def _blocking_get_cert_expiry(self, hostname, port):
        return get_certificate_expiry(hostname, port)


class TestSleepHandler(tornado.web.RequestHandler):
    # See https://gist.github.com/methane/2185380

    executor = ThreadPoolExecutor(max_workers=2)

    @gen.coroutine
    @tornado.web.addslash<commit_msg>Include hyphens and dashes in hostname regex<commit_after>#!/usr/bin/env python

import logging
import time

import tornado.ioloop
import tornado.web

from concurrent.futures import ThreadPoolExecutor
from tornado import gen
from tornado.concurrent import run_on_executor

from get_certificate import get_certificate_expiry

HOSTNAME_REGEX = '[a-zA-Z0-9.\-_]+'  # ish...


class CertExpiryHandler(tornado.web.RequestHandler):
    executor = ThreadPoolExecutor(max_workers=2)

    @gen.coroutine
    @tornado.web.addslash
    def get(self, hostname, port='443'):
        port = int(port) if port else 443

        expiry_date = yield self._blocking_get_cert_expiry(hostname, port)
        self.write(str(expiry_date))

    @run_on_executor
    def _blocking_get_cert_expiry(self, hostname, port):
        return get_certificate_expiry(hostname, port)


class TestSleepHandler(tornado.web.RequestHandler):
    # See https://gist.github.com/methane/2185380

    executor = ThreadPoolExecutor(max_workers=2)

    @gen.coroutine
    @tornado.web.addslash
{'fraction_non_alphanumeric': 0.09011627906976744, 'fraction_numerical': 0.016472868217054265, 'mean_word_length': 4.281329923273657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '1381391', 'n_tokens_mistral': 738, 'n_tokens_neox': 681, 'n_words': 137}