<commit_before>import uuid

from twisted.internet.defer import inlineCallbacks
from twisted.python import log
from twisted.web import http
from twisted.web.resource import Resource
from vumi.transports.base import Transport


class HttpHealthResource(Resource):
    isLeaf = True

    def __init__(self):
        Resource.__init__(self)

    def render_GET(self, request):
        request.setResponseCode(http.OK)
        return "OK"


class HttpResource(Resource):
    isLeaf = True

    def __init__(self, transport):
        self.transport = transport
        Resource.__init__(self)

    def render(self, request, http_action=None):
        log.msg("HttpResource HTTP Action: %s" % (request,))
        request.setHeader("content-type", "text/plain")
        uu = uuid.uuid4().get_hex()
        self.transport.handle_raw_inbound_message(uu, request)
        return '{"message_id": "%s"}' % (uu)


class HttpTransport(Transport):
    """
    Strictly for internal testing only
    this has NO SECURITY!

    Configuration Values
    --------------------
    web_path : str
        The path relative to the host where this listens
    web_port : int
        The port this listens on
    transport_name : str
        The name this transport instance will use to create it's queues
    """

    @inlineCallbacks
    def setup_transport(self):

        # start receipt web resource
        self.web_resource = yield self.start_web_resources(
            [
                (HttpResource(self), self.config['web_path']),
                (HttpHealthResource(), 'health'),
            ],
            self.config['web_port'])

    @inlineCallbacks
    def teardown_transport(self):
        yield self.web_resource.loseConnection()

    def handle_outbound_message(self, message):
        log.msg("HttpApiTransport consuming %s" % (message))

    def handle_raw_inbound_message(self, message_id, request):
        content = str(request.args.get('content', [None])[0])
        to_addr = str(request.args.get('to_addr', [None])[0])<commit_msg>Convert web_port to int to allow it to be set via --set-option (which always sends in strings).<commit_after>import uuid

from twisted.internet.defer import inlineCallbacks
from twisted.python import log
from twisted.web import http
from twisted.web.resource import Resource
from vumi.transports.base import Transport


class HttpHealthResource(Resource):
    isLeaf = True

    def __init__(self):
        Resource.__init__(self)

    def render_GET(self, request):
        request.setResponseCode(http.OK)
        return "OK"


class HttpResource(Resource):
    isLeaf = True

    def __init__(self, transport):
        self.transport = transport
        Resource.__init__(self)

    def render(self, request, http_action=None):
        log.msg("HttpResource HTTP Action: %s" % (request,))
        request.setHeader("content-type", "text/plain")
        uu = uuid.uuid4().get_hex()
        self.transport.handle_raw_inbound_message(uu, request)
        return '{"message_id": "%s"}' % (uu)


class HttpTransport(Transport):
    """
    Strictly for internal testing only
    this has NO SECURITY!

    Configuration Values
    --------------------
    web_path : str
        The path relative to the host where this listens
    web_port : int
        The port this listens on
    transport_name : str
        The name this transport instance will use to create it's queues
    """

    @inlineCallbacks
    def setup_transport(self):

        # start receipt web resource
        self.web_resource = yield self.start_web_resources(
            [
                (HttpResource(self), self.config['web_path']),
                (HttpHealthResource(), 'health'),
            ],
            int(self.config['web_port']))

    @inlineCallbacks
    def teardown_transport(self):
        yield self.web_resource.loseConnection()

    def handle_outbound_message(self, message):
        log.msg("HttpApiTransport consuming %s" % (message))

    def handle_raw_inbound_message(self, message_id, request):
        content = str(request.args.get('content', [None])[0])
        to_addr = str(request.args.get('to_addr', [None])[0])
{'fraction_non_alphanumeric': 0.10835540573079701, 'fraction_numerical': 0.0014447387430772936, 'mean_word_length': 2.800548947849954, 'pattern_counts': {'":': 2, '<': 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': '3922430', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1147, 'n_words': 305}