本文整理汇总了Python中DocXMLRPCServer.DocXMLRPCServer.register_instance方法的典型用法代码示例。如果您正苦于以下问题:Python DocXMLRPCServer.register_instance方法的具体用法?Python DocXMLRPCServer.register_instance怎么用?Python DocXMLRPCServer.register_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DocXMLRPCServer.DocXMLRPCServer
的用法示例。
在下文中一共展示了DocXMLRPCServer.register_instance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
class XMLRPCServer:
def __init__(self, host, port, logic):
"""Initialise XMLRPC"""
#Create XMLRPC server with functions from XMLRPCInterface class below
self.rpcserver = DocXMLRPCServer((host, port), logRequests=0)
self.rpcserver.register_instance(XMLRPCInterface(logic))
self.port = port
#Set up documentation interface properties
self.rpcserver.set_server_title("Truemix XMLRPC API")
self.rpcserver.set_server_name("Truemix XMLRPC API Documentation")
self.rpcserver.set_server_documentation(
"Truemix is a radio automation system with a server/client"
" organisation. This XMLRPC API allows you to write your own"
" applications that connect with the Truemix backend server."
)
def start_serving(self):
try:
#Advertise the service with avahi and dbus
bus = dbus.SystemBus()
server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
g = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
g.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0), "Truemix Server", "_truemix-xmlrpc._tcp", "", "", dbus.UInt16(self.port), "")
g.Commit()
except dbus.exceptions.DBusException:
#Unable to advertise server
pass
#Start the xmlrpc server
self.rpcserver.serve_forever()
示例2: make_server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [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
示例3: testserver
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [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: start
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
def start():
"""
Start the XML-RPC server, and print out the port number that it is
listening on.
"""
server = XMLRPCServer(("127.0.0.1", 0), JPushyXMLRPCRequestHandler)
# print out the port number
print server.socket.getsockname()[1]
sys.stdout.flush()
server.allow_none = True
server.register_introspection_functions()
server.register_instance(JPushyFunctions())
server.serve_forever()
示例5: start
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
def start( address, scheduler, debug=False ):
global count
if debug:
s = DocXMLRPCServer( address, allow_none=True )
s.register_introspection_functions()
else:
s = SimpleXMLRPCServer( address, allow_none=True )
handler = RPCHandler( scheduler )
s.register_multicall_functions()
s.register_instance( handler )
s.thread = threading.Thread( name="RPC", target=s.serve_forever )
s.thread.daemon = True
s.thread.start()
logging.info( "rpc interface started" )
return s, s.thread, handler
示例6: server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [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()
示例7: APIService
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [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)
cbdebug("Initializing API Service on port " + str(self.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.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()
示例8: Server
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
#.........这里部分代码省略.........
logging.warn('No port specified, using 9001')
else:
try:
self._port = int(config.get('server', 'port'))
except:
raise RuntimeError('Server port must be an integer')
for section in config.sections():
if not section == 'server':
logging.debug('Found a client: %s' % section)
if not config.has_option(section, 'artifacts'):
raise RuntimeError('Client sections require an artifacts option')
artifacts_string = config.get(section, 'artifacts')
artifacts = {}
if artifacts_string == '':
raise RuntimeError('Artifacts list cannot be empty')
for artifact in artifacts_string.split(','):
logging.debug('Found an artifact: %s' % artifact)
file_based = True
filename = ''
backup_command = ''
restore_command = ''
cleanup = False
versions = 1
interval = '1h'
if config.has_option(section, artifact + '_filename'):
filename = config.get(section, artifact + '_filename')
else:
raise RuntimeError("Artifacts must have at least a file specified. Error in client '%s'" % section)
if config.has_option(section, artifact + '_backup_command'):
file_based = False
backup_command = config.get(section, artifact + '_backup_command')
if config.has_option(section, artifact + '_restore_command'):
restore_command = config.get(section, artifact + '_restore_command')
else:
raise RuntimeError("A backup command was specified without a restore command. A restore command is required in client '%s', artifact '%s'" % (section, artifact))
if config.has_option(section, artifact + '_cleanup'):
tmp = config.get(section, artifact + '_cleanup')
if tmp.lower() == 'true':
cleanup = True
elif tmp.lower() == 'false':
cleanup = False
else:
raise RuntimeError("Invalid option for cleanup in client '%s', artifact '%s'" % (section, artifact))
if config.has_option(section, artifact + '_versions'):
try:
versions = int(config.get(section, artifact + '_versions'))
except:
raise RuntimeError("Version option must be an integer in client '%s', artifact '%s'" % (section, artifact))
if config.has_option(section, artifact + '_interval'):
interval = config.get(section, artifact + '_interval')
regex = "^(\d+w ?)?(\d+d ?)?(\d+h ?)?(\d+m ?)?(\d+s ?)?$"
if not re.search(regex, interval):
raise RuntimeError("Interval option must in valid timedelta format. e.g. 1w2d3h4m. In client '%s', artifact '%s'" % (section, artifact))
artifacts[artifact] = {
'file_based': file_based,
'filename': filename,
'backup_command': backup_command,
'restore_command': restore_command,
'cleanup': cleanup,
'versions': versions,
'interval': interval
}
self._clients[section] = artifacts
if not len(self._clients) > 0:
raise RuntimeError('No clients specified')
self._server = None
def _add_arguments(self):
self._parser.add_argument('config_file', metavar='CONFIGFILE')
def run(self):
logging.debug('Starting XMLRPC server')
self._server = DocXMLRPCServer(('0.0.0.0', self._port), logRequests=False)
self._server.register_instance(_XMLRPCServer(self._clients, self._backup_location))
self._server.serve_forever()
def stop(self):
logging.debug('Stopping XMLRPC Server')
if self._server != None:
self._server.shutdown()
示例9: opendb
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
(hwinfot,meth) = xmlrpclib.loads(hwinfostr)
hwinfo = hwinfot[0]
# Append date before inserting
hwinfo.update({'Date': datetime.datetime.now()})
try:
conn = opendb()
except:
return False
else:
add_record(conn, hwinfo)
conn.close()
return True
def gethwinfo(self):
"""Return the entire HW database"""
return xmlrpclib.dumps((getdb(),))
if __name__ == '__main__':
import os.path
import time
if not os.path.isfile(DBFILE):
createdb(DBFILE)
from DocXMLRPCServer import DocXMLRPCServer
server = DocXMLRPCServer(("", 8000), logRequests=0)
server.register_introspection_functions()
server.register_instance(HwInfoServer())
print time.asctime(), 'Application Starting.'
server.serve_forever()
print time.asctime(), 'Application Finishing.'
示例10: SimpleXMLRPCServer
# 需要导入模块: from DocXMLRPCServer import DocXMLRPCServer [as 别名]
# 或者: from DocXMLRPCServer.DocXMLRPCServer import register_instance [as 别名]
# 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
server.serve_forever()