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
def _dispatch(self, method, params): try: return CGIXMLRPCRequestHandler._dispatch(self, method, params) except Exception, e: # print server error on stderr (which should go to the apache # logfile so we can more easily debug the problem) import traceback traceback.print_exc() raise e
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()
def __init__(self): CGIXMLRPCRequestHandler.__init__(self) XMLRPCDocGenerator.__init__(self)
def server(): from SimpleXMLRPCServer import CGIXMLRPCRequestHandler handler = CGIXMLRPCRequestHandler() handler.register_function(pow) handler.register_function(lambda x,y: x+y, 'add') handler.register_introspection_functions() handler.register_instance(MyFuncs()) handler.handle_request()
def __init__(self, methods): CGIXMLRPCRequestHandler.__init__(self) self.methods = methods
def get_month_total(session_key, month): if is_user_auth(session_key): query = db.Query(MonthTally) query.filter('month_str =', month) results = query.fetch(1000) t0_total = 0 t1_total = 0 for item in results: if item.type_id == 0: t0_total += item.count if item.type_id == 1: t1_total += item.count return [t0_total, t1_total] #------------------------------------------------- handler = CGIXMLRPCRequestHandler() handler.register_introspection_functions() handler.register_function(user_login) handler.register_function(get_last_tallies) handler.register_function(get_tallies) handler.register_function(add_tally) handler.register_function(save_tally) handler.register_function(del_tally) handler.register_function(get_stat_report) handler.register_function(get_month_total) handler.handle_request()
#!/usr/bin/env python import os import sys def getDirectory(): try: return os.environ['PCD_DIR'] except: return None def setPath(pcdDir): paths = [ pcdDir, pcdDir + '/vendor', pcdDir + '/modules' ] for item in paths: sys.path.append(item) pcdDir = getDirectory() if pcdDir == None: print "Error - Environment variable PCD_DIR not set. Exiting..." sys.exit(1) setPath(pcdDir) import webservice from SimpleXMLRPCServer import CGIXMLRPCRequestHandler from webservice import WebService handler = CGIXMLRPCRequestHandler(allow_none=True, encoding=False) handler.register_instance(WebService(pcdDir)) handler.handle_request()
from xmlrpclib import ServerProxy servName=socket.gethostname() (servPort,servPid,servComm)=eval(open("mabsCommandServer.portno").read()) server=ServerProxy("http://%s:%d/"%(servName,servPort)) def nextFasta(clientID): try: filen=server.nextFasta(clientID) print >> errstrm, "Serving",filen,"to",os.environ["REMOTE_HOST"],"(",clientID,") at", time.asctime() errstrm.flush() return filen except Exception,e: print >> errstrm,e if e[0]==111 and os.system("/bin/ps -no-headers %d >/dev/null"%(servPid)) != 0: print >> errstrm, "Looks like server has died. Trying to start it." os.system("python2.2 %s 2>/dev/null >/dev/null </dev/null &"%(servComm)) return "xTryAgain" handler = CGIXMLRPCRequestHandler() handler.register_function(nextFasta) handler.handle_request() except Exception,e: print >> errstrm,e
"""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()
def main(): handler = CGIXMLRPCRequestHandler() handler.register_function(compare_word_selection_submissions, 'relevant_words.quality_oracle') handler.register_introspection_functions() handler.handle_request()
def serverMethodSignatures(server): """List all methods as well as signatures""" methods = CGIXMLRPCRequestHandler.system_listMethods(server) methods_and_signatures = [(method, server.system_methodSignature(method)) \ for method in methods] return methods_and_signatures
# print(os.getpid()) return pow(x,y) def hex(self,x): # self.lock.acquire() self.callstats['hex'] += 1 # time.sleep(1) # self.lock.release() return "%x" % x def sortlist(self,l): l = list(l) l.sort() return l handler = CGIXMLRPCRequestHandler() handler.register_instance(Math()) handler.register_introspection_functions() handler.register_function(int) handler.register_function(list.sort) handler.handle_request() def testserver(): class ThreadingServer(ThreadingMixIn,DocXMLRPCServer): pass server = DocXMLRPCServer(('localhost',8888),DocXMLRPCRequestHandler,allow_none=True) server.set_server_title("Chapter 18 document") server.set_server_name("chapter") server.set_server_documentation("""welcome""") server.register_instance(Math())