<commit_before># Mrs
# Copyright 2008 <NAME> <<EMAIL>>
#
# This file is part of Mrs.
#
# Mrs is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Mrs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Mrs.  If not, see <http://www.gnu.org/licenses/>.

import threading, SimpleXMLRPCServer

# TODO: listen over SSL.  See
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786

# TODO: Switch to Twisted(?). Note that the current implementation uses a
# synchronous server.  We'll probably want to change that at some point.  Look
# at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/526625 and
# http://www.rexx.com/~dkuhlman/twisted_patterns.html#the-xml-rpc-pattern

# TODO: check for basic HTTP authentication?

def new_server(functions, port, host=None):
    """Return an RPC server for incoming RPC requests.

    Note that functions is an "instance" to be given to SimpleXMLRPCServer.
    """
    if host is None:
        # (Using socket.INADDR_ANY doesn't seem to work)
        host = ''
    server = SimpleXMLRPCServer.SimpleXMLRPCServer((host, port),
            requestHandler=MrsXMLRPCRequestHandler, logRequests=False)
    #server.register_introspection_functions()
    server.register_instance(functions)

    return server

class RPCThread(threading.Thread):
    """Thread for listening for incoming RPC requests.
    
    Listen on port 8000 for slaves to connect:
    server = RPCServer(functions, 8000)
    server.start()

    Note that functions is an "instance" to be given to SimpleXMLRPCServer.
    """
    def __init__(self, functions, port, **kwds):
        threading.Thread.__init__(self, **kwds)
        # Die when all other non-daemon threads have exited:
        self.setDaemon(True)
        self.server = new_server(functions, port)<commit_msg>added start_xmlrpc<commit_after># Mrs
# Copyright 2008 <NAME> <<EMAIL>>
#
# This file is part of Mrs.
#
# Mrs is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Mrs is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Mrs.  If not, see <http://www.gnu.org/licenses/>.

from twisted.internet import reactor
import threading, SimpleXMLRPCServer

# TODO: listen over SSL.  See
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496786

# TODO: Switch to Twisted(?). Note that the current implementation uses a
# synchronous server.  We'll probably want to change that at some point.  Look
# at: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/526625 and
# http://www.rexx.com/~dkuhlman/twisted_patterns.html#the-xml-rpc-pattern

# TODO: check for basic HTTP authentication?

def start_xmlrpc(resource, port):
    """Start an RPC server for incoming RPC requests (Twisted version)

    Returns a twisted.internet IPv4Address (which has attributes host,
    port, and type).

    Note that resource is an "instance" to be given to SimpleXMLRPCServer.
    The Twisted reactor must be started before you make this call.
    """
    from twisted.web import server
    from twist import reactor_call

    site = server.Site(resource)
    tcpport = reactor_call(reactor.listenTCP, port, site)
    address = tcpport.getHost()
    return address


def new_server(resource, port, host=None):
    """Return an RPC server for incoming RPC requests.

    Note that resource is an "instance" to be given to SimpleXMLRPCServer.
    """
    if host is None:
        # (Using socket.INADDR_ANY doesn't seem to work)
        host = ''
    server = SimpleXMLRPCServer.SimpleXMLRPCServer((host, port),
            requestHandler=MrsXMLRPCRequestHandler, logRequests=False)
    #server.register_introspection_functions()
    server.register_instance(resource)

    return server

class RPCThread(threading.Thread):
    """Thread for listening for incoming RPC requests (xmlrpclib version)
    
    Listen on port 8000 for slaves to connect:
    server = RPCServer(functions, 8000)
    server.start()

    Note that functions is an "instance" to be given to SimpleXMLRPCServer.
    """
    def __init__(self, functions, port, **kwds):
        threading.Thread.__init__(self, **kwds)
        # Die when all other non-daemon threads have exited:
        self.setDaemon(True)
        self.server = new_server(functions, port)
{'fraction_non_alphanumeric': 0.08362573099415205, 'fraction_numerical': 0.009941520467836258, 'mean_word_length': 3.703024747937672, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 5}, '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': '2660923', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1431, 'n_words': 564}