MiscUtils.PickleRPC (version 1) | index /usr/local/share/webware/MiscUtils/PickleRPC.py |
PickleRPC.py
PickleRPC provides a Server object for connection to Pickle-RPC servers
for the purpose of making requests and receiving the responses.
>>> from MiscUtils.PickleRPC import Server
>>> server = Server('http://localhost/cgi-bin/WebKit.cgi/Examples/PickleRPCExample')
>>> server.multiply(10,20)
200
>>> server.add(10,20)
30
See also: Server, Webkit.PickleRPCServlet, WebKit.Examples.PickleRPCExample
UNDER THE HOOD
Requests look like this:
{
'version': 1, # default
'action': 'call', # default
'methodName': 'NAME',
'args': (A, B, ...), # default = (,)
'keywords': {'A': A, 'B': B, ...} # default = {}
}
Only 'methodName' is required since that is the only key without a
default value.
Responses look like this:
{
'timeReceived': N,
'timeReponded': M,
'value': V,
'exception': E,
'requestError': E,
}
TimeReceived is the time the initial request was received.
TimeResponded is the time at which the response was finished, as
close to transmission as possible. The times are expressed as
number of seconds since the Epoch, e.g., time.time().
Value is whatever the method happened to return.
Exception may be 'occurred' to indicate that an exception
occurred, the specific exception, such as "KeyError: foo" or the
entire traceback (as a string), at the discretion of the server.
It will always be a non-empty string if it is present.
RequestError is an exception such as "Missing method
in request." (with no traceback) that indicates a problem with the
actual request received by the Pickle-RPC server.
Value, exception and requestError are all exclusive to each other.
SECURITY
Pickle RPC uses the SafeUnpickler class (in this module) to
prevent unpickling of unauthorized classes. By default, it
doesn't allow _any_ classes to be unpickled. You can override
allowedGlobals() or findGlobal() in a subclass as needed to
allow specific class instances to be unpickled.
Note that both Transport in this module and PickleRPCServlet in
WebKit are derived from SafeUnpickler.
CREDIT
The implementation of this module was taken directly from Python 2.2's
xmlrpclib and then transformed from XML-orientation to Pickle-orientation.
The zlib compression was adapted from code by Skip Montanaro that I found
here: http://manatee.mojam.com/~skip/python/
Modules | ||||||
|
Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Functions | ||
Data | ||
__version__ = 1 |