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
`` |  |
types | zlib |  |

Classes
`` |  | SafeUnpickler Transport SafeTransport Server exceptions.Exception(exceptions.BaseException) Error RequestError ResponseError InvalidContentTypeError ProtocolError(ResponseError, xmlrpclib.ProtocolError)
class Error(exceptions.Exception)
`` | `The abstract exception/error class for all PickleRPC errors.`
| Method resolution order: Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors defined here: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class InvalidContentTypeError(ResponseError)
`` |  | Method resolution order: InvalidContentTypeError ResponseError Error exceptions.Exception exceptions.BaseException __builtin__.object Methods defined here: __init__(self, headers, content) __repr__(self) __str__ = __repr__(self) Data descriptors inherited from Error: __weakref__ `list of weak references to the object (if defined)` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class ProtocolError(ResponseError, xmlrpclib.ProtocolError)
`` |  | Method resolution order: ProtocolError ResponseError Error xmlrpclib.ProtocolError xmlrpclib.Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors inherited from Error: __weakref__ `list of weak references to the object (if defined)` Methods inherited from xmlrpclib.ProtocolError: __init__(self, url, errcode, errmsg, headers) __repr__(self) Methods inherited from xmlrpclib.Error: __str__(self) Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class RequestError(Error)
`` | `These are errors originally raised by the server complaining about malformed requests.`
| Method resolution order: RequestError Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors inherited from Error: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class ResponseError(Error)
`` | `These are unhandled exceptions raised when the server was computing a response. These will indicate errors such as: * exception in the actual target method on the server * malformed responses * non "200 OK" status code responses`
| Method resolution order: ResponseError Error exceptions.Exception exceptions.BaseException __builtin__.object Data descriptors inherited from Error: __weakref__ `list of weak references to the object (if defined)` Methods inherited from exceptions.Exception: __init__(...) `x.__init__(...) initializes x; see x.__class__.__doc__ for signature` Data and other attributes inherited from exceptions.Exception: __new__ = <built-in method __new__ of type object at 0x8118bc0> `T.__new__(S, ...) -> a new object with type S, a subtype of T` Methods inherited from exceptions.BaseException: __delattr__(...) `x.__delattr__('name') <==> del x.name` __getattribute__(...) `x.__getattribute__('name') <==> x.name` __getitem__(...) `x.__getitem__(y) <==> x[y]` __getslice__(...) `x.__getslice__(i, j) <==> x[i:j] Use of negative indices is not supported.` __reduce__(...) __repr__(...) `x.__repr__() <==> repr(x)` __setattr__(...) `x.__setattr__('name', value) <==> x.name = value` __setstate__(...) __str__(...) `x.__str__() <==> str(x)` Data descriptors inherited from exceptions.BaseException: __dict__ args message `exception message`
class SafeTransport(Transport)
`` | `Handles an HTTPS transaction to a Pickle-RPC server.`
| Method resolution order: SafeTransport Transport SafeUnpickler Methods defined here: make_connection(self, host) send_host(self, connection, host) Methods inherited from Transport: parse_response(self, f) parse_response_gzip(self, f) request(self, host, handler, request_body, verbose=0, binary=0, compressed=0, acceptCompressedResponse=0) send_content(self, connection, request_body, binary=0, compressed=0, acceptCompressedResponse=0) send_request(self, connection, handler, request_body) send_user_agent(self, connection) Data and other attributes inherited from Transport: user_agent = 'PickleRPC/1 (by http://webware.sf.net/)' Methods inherited from SafeUnpickler: allowedGlobals(self) `Must return a list of (moduleName, klassName) tuples for all classes that you want to allow to be unpickled. Example: return [('mx.DateTime', '_DT')] allows mx.DateTime instances to be unpickled.` findGlobal(self, module, klass) load(self, file) loads(self, str)
class SafeUnpickler
`` | `For security reasons, we don't want to allow just anyone to unpickle anything. That can cause arbitrary code to be executed. So this SafeUnpickler base class is used to control what can be unpickled. By default it doesn't let you unpickle any class instances at all, but you can create subclass that overrides allowedGlobals(). Note that the PickleRPCServlet class in WebKit is derived from this class and uses its load() and loads() methods to do all unpickling.`
| Methods defined here: allowedGlobals(self) `Must return a list of (moduleName, klassName) tuples for all classes that you want to allow to be unpickled. Example: return [('mx.DateTime', '_DT')] allows mx.DateTime instances to be unpickled.` findGlobal(self, module, klass) load(self, file) loads(self, str)
class Server
`` | `uri [,options] -> a logical connection to an XML-RPC server uri is the connection point on the server, given as scheme://host/target. The standard implementation always supports the "http" scheme. If SSL socket support is available (Python 2.0), it also supports "https". If the target part and the slash preceding it are both omitted, "/PickleRPC" is assumed. See the module doc string for more information.`
| Methods defined here: __getattr__(self, name) __init__(self, uri, transport=None, verbose=0, binary=1, compressRequest=1, acceptCompressedResponse=1) __repr__(self) __str__ = __repr__(self)
ServerProxy = class Server
`` | `uri [,options] -> a logical connection to an XML-RPC server uri is the connection point on the server, given as scheme://host/target. The standard implementation always supports the "http" scheme. If SSL socket support is available (Python 2.0), it also supports "https". If the target part and the slash preceding it are both omitted, "/PickleRPC" is assumed. See the module doc string for more information.`
| Methods defined here: __getattr__(self, name) __init__(self, uri, transport=None, verbose=0, binary=1, compressRequest=1, acceptCompressedResponse=1) __repr__(self) __str__ = __repr__(self)
class Transport(SafeUnpickler)
`` | `Handles an HTTP transaction to a Pickle-RPC server.`
| Methods defined here: make_connection(self, host) parse_response(self, f) parse_response_gzip(self, f) request(self, host, handler, request_body, verbose=0, binary=0, compressed=0, acceptCompressedResponse=0) send_content(self, connection, request_body, binary=0, compressed=0, acceptCompressedResponse=0) send_host(self, connection, host) send_request(self, connection, handler, request_body) send_user_agent(self, connection) Data and other attributes defined here: user_agent = 'PickleRPC/1 (by http://webware.sf.net/)' Methods inherited from SafeUnpickler: allowedGlobals(self) `Must return a list of (moduleName, klassName) tuples for all classes that you want to allow to be unpickled. Example: return [('mx.DateTime', '_DT')] allows mx.DateTime instances to be unpickled.` findGlobal(self, module, klass) load(self, file) loads(self, str)

Functions
`` |  | StringIO(...) `StringIO([s]) -- Return a StringIO-like stream for reading or writing` Unpickler(...) `Unpickler(file) -- Create an unpickler.` dumps(...) `dumps(obj, protocol=0) -- Return a string containing an object in pickle format. See the Pickler docstring for the meaning of optional argument proto.`

Data
`` |  | __version__ = 1