本文整理汇总了Python中DocXMLRPCServer.DocXMLRPCServer.register_function方法的典型用法代码示例。如果您正苦于以下问题:Python DocXMLRPCServer.register_function方法的具体用法?Python DocXMLRPCServer.register_function怎么用?Python DocXMLRPCServer.register_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocXMLRPCServer.DocXMLRPCServer
的用法示例。
在下文中一共展示了DocXMLRPCServer.register_function方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def make_server():
serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
try:
# Add some documentation
serv.set_server_title("DocXMLRPCServer Test Documentation")
serv.set_server_name("DocXMLRPCServer Test Docs")
serv.set_server_documentation(
"This is an XML-RPC server's documentation, but the server "
"can be used by POSTing to /RPC2. Try self.add, too.")
# Create and register classes and functions
class TestClass(object):
def test_method(self, arg):
"""Test method's docs. This method truly does very little."""
self.arg = arg
serv.register_introspection_functions()
serv.register_instance(TestClass())
def add(x, y):
"""Add two instances together. This follows PEP008, but has nothing
to do with RFC1952. Case should matter: pEp008 and rFC1952. Things
that start with http and ftp should be auto-linked, too:
http://google.com.
"""
return x + y
serv.register_function(add)
serv.register_function(lambda x, y: x-y)
return serv
except:
serv.server_close()
raise
示例2: APIService
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
class APIService ( threading.Thread ):
@trace
def __init__(self, pid, passive, active, background, debug, port, hostname) :
super(APIService, self).__init__()
self._stop = threading.Event()
self.pid = pid
self.abort = False
self.aborted = False
self.port = port
self.hostname = hostname
self.api = API(pid, passive, active, background, port, debug)
cbdebug("Initializing API Service on " + hostname + ":" + str(port))
if debug is None :
self.server = AsyncDocXMLRPCServer((self.hostname, int(self.port)), allow_none = True)
else :
self.server = DocXMLRPCServer((self.hostname, int(self.port)), allow_none = True)
self.server.abort = False
self.server.aborted = False
self.server.set_server_title("API Service (xmlrpc)")
self.server.set_server_name("API Service (xmlrpc)")
#self.server.register_introspection_functions()
self.api.signatures = {}
for methodtuple in inspect.getmembers(self.api, predicate=inspect.ismethod) :
name = methodtuple[0]
if name in ["__init__", "success", "error", "migrate" ] :
continue
func = getattr(self.api, name)
argspec = inspect.getargspec(func)
spec = argspec[0]
defaults = [] if argspec[3] is None else argspec[3]
num_spec = len(spec)
num_defaults = len(defaults)
diff = num_spec - num_defaults
named = diff - 1
doc = "Usage: "
for x in range(1, diff) :
doc += spec[x] + ", "
for x in range(diff, num_spec) :
doc += spec[x] + " = " + str(defaults[x - diff]) + ", "
doc = doc[:-2]
self.api.signatures[name] = {"args" : spec[1:], "named" : named }
self.server.register_function(unwrap_kwargs(func, doc), name)
# self.server.register_instance(self.api)
cbdebug("API Service started")
@trace
def run(self):
cbdebug("API Service waiting for requests...")
self.server.serve_forever()
cbdebug("API Service shutting down...")
@trace
def stop (self) :
cbdebug("Calling API Service shutdown....")
self._stop.set()
self.server.shutdown()
示例3: testserver
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
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())
server.register_introspection_functions()
server.register_function(int)
server.register_function(list.sort)
示例4: run
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def run( s ):
server = DocXMLRPCServer( (s.host_name, s.port_number),
logRequests=0 )
server.register_function( s.notify )
server.register_function( s.subscribe )
server.register_function( s.unsubscribe )
server.register_function( s.unsubscribe_all )
server.register_function( s.get_logs )
print time.asctime(), "Event Server Starts - %s:%s" % (s.host_name,
s.port_number)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
server.close() # might work..?
print time.asctime(), "Event Server Stops - %s:%s" % (s.host_name,
s.port_number)
示例5: server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def server(evt, numrequests):
serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
try:
global PORT
PORT = serv.socket.getsockname()[1]
# Add some documentation
serv.set_server_title("DocXMLRPCServer Test Documentation")
serv.set_server_name("DocXMLRPCServer Test Docs")
serv.set_server_documentation(
"""This is an XML-RPC server's documentation, but the server can be used by
POSTing to /RPC2. Try self.add, too."""
)
# Create and register classes and functions
class TestClass(object):
def test_method(self, arg):
"""Test method's docs. This method truly does very little."""
self.arg = arg
serv.register_introspection_functions()
serv.register_instance(TestClass())
def add(x, y):
"""Add two instances together. This follows PEP008, but has nothing
to do with RFC1952. Case should matter: pEp008 and rFC1952. Things
that start with http and ftp should be auto-linked, too:
http://google.com.
"""
return x + y
serv.register_function(add)
serv.register_function(lambda x, y: x - y)
while numrequests > 0:
serv.handle_request()
numrequests -= 1
except socket.timeout:
pass
finally:
serv.server_close()
PORT = None
evt.set()
示例6: run_xmlrpc_server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def run_xmlrpc_server():
'''Run an XMLRPC server that publishes the translate_stacktrace function.'''
from DocXMLRPCServer import DocXMLRPCServer as XMLRPCServer
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s')
with open(PIDFILE, 'w') as pidfile:
pidfile.write('%s' % os.getpid())
try:
# Create server
server = XMLRPCServer(LISTEN_ADDR)
server.register_function(translate_stacktrace)
# Run the server's main loop
try:
server.serve_forever()
except KeyboardInterrupt:
pass
finally:
os.remove(PIDFILE)
示例7: DocXMLRPCServer
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
from DocXMLRPCServer import DocXMLRPCServer
import time
# Create server
server = DocXMLRPCServer(("localhost", 8000))
# Register a function
def echo(message):
"Accepts a message parameter and returns it unchanged."
return message
# New functions for lab exercise
def time():
"Returns the current time"
return time.asctime()
server.register_function(echo)
server.register_function(time)
# Run the server's main loop
server.serve_forever()
# DocXMLRPCServer classes automatically create and serve documentation to
# browsers, visit http://localhost:8000/ to see it.
示例8: sumAndDifference
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
#!/usr/bin/python
from DocXMLRPCServer import DocXMLRPCServer
def sumAndDifference(x,y):
"""This method returns sum and difference of arguments
as struct with two fields: 'sum' and 'difference'"""
return {'sum':x+y,'difference':x-y}
server = DocXMLRPCServer(("localhost", 5777))
server.register_function(sumAndDifference,"sample.sumAndDifference")
server.register_introspection_functions()
server.register_multicall_functions()
server.serve_forever()
示例9: run
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def run( s ):
server = DocXMLRPCServer( (s.host_name, s.port_number),
logRequests=0 )
server.register_function( s.notify )
server.register_function( s.create_user )
server.register_function( s.delete_user )
server.register_function( s.email_pw )
server.register_function( s.change_pw )
server.register_function( s.create_namespace )
server.register_function( s.delete_namespace )
server.register_function( s.set )
server.register_function( s.unset )
server.register_function( s.get_description_url )
server.register_introspection_functions()
print time.asctime(), "Local Names Store Server Starts - %s:%s" % (s.host_name,
s.port_number)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
print time.asctime(), "Local Names Store Server Stops - %s:%s" % (s.host_name,
s.port_number)
示例10: msg
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
##############
# XMLRPC msg #
############################
def msg(msg): #
return bot.sendMsg(msg)#
############################
####################
# Start Bot Thread #
##################################################
thread.start_new_thread(bot.Listen,('DevBot-1',))#
##################################################
#######################
# Setup XMLRPC Server #
########################################################################
query = "SELECT address,port FROM devbot WHERE LOWER(name) = 'DevBot' \
LIMIT 1" #
svrnfo = db.query(query) #
try: #
svrnfo = svrnfo[0] #
except: #
print "No instance found!" #
sys.exit(1) #
server = DocXMLRPCServer(svrnfo, logRequests=0) #
server.set_server_name("DevBot") #
server.register_function(msg) #
while not bot.terminateFlag: #
server.handle_request() #
########################################################################
示例11: dict
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
q = q.filter(fias_db.Addrobj.formalname.ilike(name_like))
if q.count() > return_limit:
return "Too big list"
else:
res = []
for one in q.all():
ao = melt.fias_AO(one, session=session)
one_ = dict(formalname=one.formalname,
shortname=one.shortname,
aolevel=one.aolevel,
code=one.code,
okato=str(one.okato) if one.okato else '',
postalcode=str(one.postalcode) if one.postalcode else '',
name=ao.name,
fullname=ao.fullname,
aoguid=str(one.aoguid)
)
res.append(one_)
return res
if __name__ == "__main__":
from DocXMLRPCServer import DocXMLRPCServer
serv = DocXMLRPCServer(("127.0.0.1", 8080), allow_none=True)
serv.register_function(GetAreas)
serv.register_function(GetAreaProperty)
serv.register_function(GetBuildings)
serv.register_function(GetBuildingProperties)
serv.register_introspection_functions()
serv.serve_forever()
示例12: SimpleXMLRPCServer
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
from SimpleXMLRPCServer import SimpleXMLRPCServer
from DocXMLRPCServer import DocXMLRPCServer
# Create server
#server = SimpleXMLRPCServer(("localhost", 8000))
server = DocXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
# Register pow() function; this will use the value of
# pow.__name__ as the name, which is just 'pow'.
server.register_function(pow)
# Register a function under a different name
def adder_function(x,y):
return x + y
server.register_function(adder_function, 'add')
# Register an instance; all the methods of the instance are
# published as XML-RPC methods (in this case, just 'div').
class MyFuncs:
def div(self, x, y):
return x // y
server.register_instance(MyFuncs())
def msg(user):
return '<h1>haha%s</h1>'%user
server.register_function(msg)
# Run the server's main loop
示例13: time
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_function [as 别名]
def time():
"Returns the datetime.datetime.now() to the client. That's all."
return datetime.datetime.now()
def add(numbers):
"Returns the sum of two numbers, separated by a '+' delimiter."
numbers = numbers.split('+')
print numbers
number1 = int(numbers[0])
print number1
number2 = int(numbers[1])
print number2
return number1 + number2
def google_utc_time():
google_utc = json.load("http://json-time.appspot.com/time.json")
print google_utc.dumps()
return google_utc.datetime
server.register_function(echo)
server.register_function(add)
server.register_function(time)
server.register_function(google_utc_time)
# Run the server's main loop
server.serve_forever()
# DocXMLRPCServer classes automatically create and serve documentation to
# browsers, visit http://localhost:8000/ to see it.