I define a python xmlrpc server as follows (approximate example for the purpose of explaining things only):
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer(('localhost', 8000))
server.register_function(foo, "serial.send")
server.serve_forever()
Then I can use a xmlrpc client like the following
import xmlrpclib
device = xmlrpclib.ServerProxy("http://localhost:8000/RPC2")
device.serial.send(...)
Here I can check if device is an instance of xmlrpclib.ServerProxy with
isinstance(device, xmlrpclib.ServerProxy)
but what is device.serial? I want to check that device.serial belongs to an xmlrpc, and not, for instance, to serial, socket or something else.
Here is a concrete example of what I want to check:
def foo(x):
if isinstance(x, ...):
print("xmlrpc access")
else:
print("direct access")
foo(device.serial) # expected output: 'xmlrpc access'
foo(serial.Serial(..)) # expected output: 'direct access'
foo(socket.Socket(...)) # expected outcome: 'direct access'
If you are asking for arbitrary inspection of Python objects then use the ‘inspect’
module of Python:
http://www.ibm.com/developerworks/library/l-pyint/index.html
also checking
or
gives you access to the base classes.