<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import BaseHTTPServer, SocketServer
import select
import random
import re
import urllib
import httphandlers as handlers
import rapidsms
from rapidsms.backends.base import BackendBase

class HttpServer (BaseHTTPServer.HTTPServer, SocketServer.ThreadingMixIn):
       
    def handle_request (self, timeout=1.0):
        # don't block on handle_request
        reads, writes, errors = (self,), (), ()
        reads, writes, errors = select.select(reads, writes, errors, timeout)
        if reads:
            BaseHTTPServer.HTTPServer.handle_request(self)

class Backend(BackendBase):
    
    def configure(self, host="localhost", port=8080, handler="HttpHandler", **kwargs):
        
        #module_name = "httphandlers"
        #module = __import__(module_name, {}, {}, [''])
        component_class = getattr(handlers, handler)
        
        self.server = HttpServer((host, int(port)), component_class)
        self.type = "HTTP"
        # set this backend in the server instance so it 
        # can callback when a message is received
        self.server.backend = self
        
    def run (self):
        while self.running:
            msg = self.next_message()
            if msg:
                if handlers.msg_store.has_key(msg.connection.identity):
                        handlers.msg_store[msg.connection.identity].append(msg.text)
                else:
                        handlers.msg_store[msg.connection.identity] = []
                        handlers.msg_store[msg.connection.identity].append(msg.text)
            self.server.handle_request()<commit_msg>fix the http backend -- outgoing was still busted<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

import BaseHTTPServer, SocketServer
import select
import random
import re
import urllib
import httphandlers as handlers
import rapidsms
from rapidsms.backends.base import BackendBase

class HttpServer (BaseHTTPServer.HTTPServer, SocketServer.ThreadingMixIn):
       
    def handle_request (self, timeout=1.0):
        # don't block on handle_request
        reads, writes, errors = (self,), (), ()
        reads, writes, errors = select.select(reads, writes, errors, timeout)
        if reads:
            BaseHTTPServer.HTTPServer.handle_request(self)

class Backend(BackendBase):
    
    def configure(self, host="localhost", port=8080, handler="HttpHandler", **kwargs):
        
        #module_name = "httphandlers"
        #module = __import__(module_name, {}, {}, [''])
        component_class = getattr(handlers, handler)
        
        self.handler = component_class
        self.server = HttpServer((host, int(port)), component_class)
        self.type = "HTTP"
        # set this backend in the server instance so it 
        # can callback when a message is received
        self.server.backend = self
        # also set it in the handler class so we can callback
        self.handler.backend = self

        # set the slug based on the handler, so we can have multiple
        # http backends
        self._slug = "http_%s" % handler
        
        
    def run (self):
        while self.running:
            msg = self.next_message()
            if msg:
                if handlers.msg_store.has_key(msg.connection.identity):
                        handlers.msg_store[msg.connection.identity].append(msg.text)
                else:
                        handlers.msg_store[msg.connection.identity] = []
                        handlers.msg_store[msg.connection.identity].append(msg.text)
            self.server.handle_request()

    def send(self, message):
        self.handler.outgoing(message)
{'fraction_non_alphanumeric': 0.09636264929424539, 'fraction_numerical': 0.004885993485342019, 'mean_word_length': 2.3963133640552994, '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': '6861441', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1014, 'n_words': 262}