XMLRPCServlet

XML-RPC servlet base class

Written by Geoffrey Talvola

See Examples/XMLRPCExample.py for sample usage.

class XMLRPCServlet.XMLRPCServlet

Bases: RPCServlet

XMLRPCServlet is a base class for XML-RPC servlets.

See Examples/XMLRPCExample.py for sample usage.

For more Pythonic convenience at the cost of language independence, see PickleRPCServlet.

__init__()

Subclasses must invoke super.

allow_none = True
awake(transaction)

Begin transaction.

call(methodName, *args, **keywords)

Call custom method.

Subclasses may override this class for custom handling of methods.

canBeReused()

Returns whether a single servlet instance can be reused.

The default is True, but subclasses con override to return False. Keep in mind that performance may seriously be degraded if instances can’t be reused. Also, there’s no known good reasons not to reuse an instance. Remember the awake() and sleep() methods are invoked for every transaction. But just in case, your servlet can refuse to be reused.

canBeThreaded()

Return whether the servlet can be multithreaded.

This value should not change during the lifetime of the object. The default implementation returns False. Note: This is not currently used.

close()
exposedMethods()

Get exposed methods.

Subclasses should return a list of methods that will be exposed through XML-RPC.

static handleException(transaction)

Handle exception.

If ReportRPCExceptionsInWebware is set to True, then flush the response (because we don’t want the standard HTML traceback to be appended to the response) and then handle the exception in the standard Webware way. This means logging it to the console, storing it in the error log, sending error email, etc. depending on the settings.

lastModified(_trans)

Get time of last modification.

Return this object’s Last-Modified time (as a float), or None (meaning don’t know or not applicable).

log(message)

Log a message.

This can be invoked to print messages concerning the servlet. This is often used by self to relay important information back to developers.

name()

Return the name which is simple the name of the class.

Subclasses should not override this method. It is used for logging and debugging.

static notImplemented(trans)
open()
respond(transaction)

Respond to a request.

Invokes the appropriate respondToSomething() method depending on the type of request (e.g., GET, POST, PUT, …).

respondToHead(trans)

Respond to a HEAD request.

A correct but inefficient implementation.

respondToPost(transaction)

Respond to a Post request.

This is similar to the xmlrpcserver.py example from the xmlrpc library distribution, only it’s been adapted to work within a Webware servlet.

resultForException(e, trans)

Get text for exception.

Given an unhandled exception, returns the string that should be sent back in the RPC response as controlled by the RPCExceptionReturn setting.

runMethodForTransaction(transaction, method, *args, **kw)
static runTransaction(transaction)
static sendOK(contentType, contents, trans, contentEncoding=None)

Send a 200 OK response with the given contents.

serverSidePath(path=None)

Return the filesystem path of the page on the server.

setFactory(factory)
sleep(transaction)

End transaction.

transaction()

Get the corresponding transaction.

Most uses of RPC will not need this.