<commit_before>import datetime
import json
import logging
import time

from mlabns.db import model
from mlabns.util import fqdn_rewrite
from mlabns.util import lookup_query
from mlabns.util import message
from mlabns.util import resolver
from mlabns.util import util

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


def _create_tool_url(fqdn, http_port):
    """Create an HTTP URL for a tool.

    Args:
        fqdn: A tool FQDN (already processed by fqdn_rewrite).
        http_port: The HTTP port number part of the URL.

    Returns:
        A constructed tool HTTP URL with protocol and http port.
    """
    # Use str() to ensure we return a non-unicode string
    return str('http://%s:%s' % (fqdn, http_port))


class LookupHandler(webapp.RequestHandler):
    """Routes GET requests to the appropriate SliverTools."""

    def post(self):
        """Not implemented."""
        return util.send_not_found(self)

    def get(self):
        """Handles an HTTP GET request.

        The URL must be in the following format:
        'http://mlab-ns.appspot.com/tool-name?query_string',
        where tool-name is one of the tools running on M-Lab.
        For more information about the URL and the supported arguments
        in the query string, see the design doc at http://goo.gl/48S22.
        """
        # Check right away whether we should redirect this request.
        url = util.try_redirect_url(self.request, datetime.datetime.now())
        if url:
            return self.send_redirect_url(url)

        query = lookup_query.LookupQuery()<commit_msg>Imports util.redirect module and calls try_redirect_url from that import (#173)<commit_after>import datetime
import json
import logging
import time

from mlabns.db import model
from mlabns.util import fqdn_rewrite
from mlabns.util import lookup_query
from mlabns.util import message
from mlabns.util import redirect
from mlabns.util import resolver
from mlabns.util import util

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template


def _create_tool_url(fqdn, http_port):
    """Create an HTTP URL for a tool.

    Args:
        fqdn: A tool FQDN (already processed by fqdn_rewrite).
        http_port: The HTTP port number part of the URL.

    Returns:
        A constructed tool HTTP URL with protocol and http port.
    """
    # Use str() to ensure we return a non-unicode string
    return str('http://%s:%s' % (fqdn, http_port))


class LookupHandler(webapp.RequestHandler):
    """Routes GET requests to the appropriate SliverTools."""

    def post(self):
        """Not implemented."""
        return util.send_not_found(self)

    def get(self):
        """Handles an HTTP GET request.

        The URL must be in the following format:
        'http://mlab-ns.appspot.com/tool-name?query_string',
        where tool-name is one of the tools running on M-Lab.
        For more information about the URL and the supported arguments
        in the query string, see the design doc at http://goo.gl/48S22.
        """
        # Check right away whether we should redirect this request.
        url = redirect.try_redirect_url(self.request, datetime.datetime.now())
        if url:
            return self.send_redirect_url(url)

        query = lookup_query.LookupQuery()
{'fraction_non_alphanumeric': 0.07905019537120529, 'fraction_numerical': 0.0033062819356777877, 'mean_word_length': 2.9808612440191387, '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': '4418537', 'n_tokens_mistral': 971, 'n_tokens_neox': 940, 'n_words': 354}