Esempio n. 1
0
def xmlrpc_handler(request):
    """
  <Purpose>
    Sends XML-RPC requests to the PublicFunctions dispatcher. Displays a
    helpful page if viewed in a web browser.

  <Arguments>
    request:
      A Django HTTP request.

  <Exceptions>
    None.

  <Side Effects>
    The called XML-RPC functions may have side effects.

  <Returns>
    A Django HTTP response.
  """

    if request.method == 'GET':
        response = render_to_response('xmlrpc-info.html',
                                      context_instance=RequestContext(request))

    elif request.method == 'POST':
        # Not all languages have the notion of "None".
        xmlrpc_handler = CGIXMLRPCRequestHandler(allow_none=False,
                                                 encoding=None)
        xmlrpc_handler.register_instance(PublicFunctions())

        response = HttpResponse(mimetype='application/xml')
        response.write(xmlrpc_handler._marshaled_dispatch(request.body))

    return response
Esempio n. 2
0
def main():
        # Configure logging.
        logging.config.fileConfig(ini_conf_path)

    	# Get a logger.
    	global log
    	log = logging.getLogger('tbxsos-xmlrpc')

        # Get master configuration.
        global master_config
        master_config = get_master_config()

        # Get KCD external configuration.
        global kcd_external_conf
        kcd_external_conf = get_kcd_external_conf_object(master_config=master_config)

        # Tell kctl lib to commit changes.
        kparams_set("commit", True)

        # Get an CGI XMLRPC server.
        server = CGIXMLRPCRequestHandler() #allow_none=1)
        # Get an XMLRPC server.
        #server = SimpleXMLRPCServer(("localhost", 8000))

        # Make the API public.
        #server.register_introspection_functions()

        # Register all functions from the KPSApi class.
        server.register_instance(KPSApi())

        # Handle CGI request.
        server.handle_request()
Esempio n. 3
0
        """Returns the number of seconds the class has been
        instantiated."""
        return time.time() - self.starttime

    def failure(self):
        """Causes a RuntimeError to be raised."""
        raise RuntimeError, "This function always raises an error."

class Math(Stats):
    def __init__(self):
        self.callstats = {'pow': 0, 'hex': 0}
        self.starttime = time.time()
        
    def pow(self, x, y):
        """Returns x raised to the yth power; that is, x ^ y.
        
        x and y may be integers or floating-point values."""
        self.callstats['pow'] += 1    
        return pow(x, y)

    def hex(self, x):
        """Returns a string holding a hexadecimal representation of
        the integer x."""
        self.callstats['hex'] += 1    
        return "%x" % x

handler = CGIXMLRPCRequestHandler()
handler.register_instance(Math())
handler.register_introspection_functions()
handler.handle_request()