Python 7.0pl5 Electronic Accessory User Manual


 
Remote Access
118
self.cancelTimer("idle")
self.destroyReferences()
return 0
Using the "netrpc" module to access the service, a client might be coded as follows. In this case a
separate cursor is created in relation to the queries made about each table in the database.
import netrpc
url = "http://localhost:8000/database"
service = netrpc.RemoteService(url)
tables = service.execute("show tables")
timout = 30
for entry in tables:
table = entry[0]
print "table: " + table
name = service.cursor(30)
print "cursor: " + url + "/" + name
cursor = netrpc.RemoteService(url+"/"+name)
cursor.execute("select * from "+table)
desc = cursor.description()
print "desc: " + str(desc)
data = cursor.fetchall()
print "data: " + str(data)
cursor.close()
In general, giving open access to a database in this way may not be advisable, especially over the In-
ternet. Such a mechanism might be restricted to a corporate intranet. Alternatively, custom interfaces
should be layered on top of the database providing interfaces based on functional requirements.
The XML-RPC Gateway
If the Python NET-RPC client implementation can’t be used because of the need to use a different lan-
guage for the client, you might instead consider using the XML-RPC protocol. Clients for the XML-
RPC protocol are available in many different languages, many of which are listed at "http://www.xm-
lrpc.com". The only change to your server application will be to instantiate an instance of the XML-
RPC gateway instead of the NET-RPC gateway.
import netsvc
import netsvc.xmlrpc
dispatcher = netsvc.Dispatcher()
dispatcher.monitor(signal.SIGINT)
validator = Validator()