WebKit.PickleRPCServlet | index /usr/local/share/webware/WebKit/PickleRPCServlet.py

`Dict-RPC servlets.`

Modules
`` |  |
sys | traceback | zlib |

Classes
`` |  | MiscUtils.PickleRPC.SafeUnpickler(__builtin__.object) PickleRPCServlet(WebKit.RPCServlet.RPCServlet, MiscUtils.PickleRPC.SafeUnpickler) WebKit.RPCServlet.RPCServlet(WebKit.HTTPServlet.HTTPServlet) PickleRPCServlet(WebKit.RPCServlet.RPCServlet, MiscUtils.PickleRPC.SafeUnpickler)
class PickleRPCServlet(WebKit.RPCServlet.RPCServlet, MiscUtils.PickleRPC.SafeUnpickler)
`` | `PickleRPCServlet is a base class for Dict-RPC servlets. The "Pickle" refers to Python's pickle module. This class is similar to XMLRPCServlet. By using Python pickles you get their convenience (assuming the client is Pythonic), but lose language independence. Some of us don't mind that last one. ;-) Conveniences over XML-RPC include the use of all of the following: * Any pickle-able Python type (datetime for example) * Python instances (aka objects) * None * Longs that are outside the 32-bit int boundaries * Keyword arguments Pickles should also be faster than XML, especially now that we support binary pickling and compression. To make your own PickleRPCServlet, create a subclass and implement a method which is then named in exposedMethods(): from WebKit.PickleRPCServlet import PickleRPCServlet class Math(PickleRPCServlet): def multiply(self, x, y): return x * y def exposedMethods(self): return ['multiply'] To make a PickleRPC call from another Python program, do this: from MiscUtils.PickleRPC import Server server = Server('http://localhost/WebKit.cgi/Context/Math') print server.multiply(3, 4) # 12 print server.multiply('-', 10) # ---------- If a request error is raised by the server, then MiscUtils.PickleRPC.RequestError is raised. If an unhandled exception is raised by the server, or the server response is malformed, then MiscUtils.PickleRPC.ResponseError (or one of its subclasses) is raised. Tip: If you want callers of the RPC servlets to be able to introspect what methods are available, then include 'exposedMethods' in exposedMethods(). If you wanted the actual response dictionary for some reason: print server._request('multiply', 3, 4) # {'value': 12, 'timeReceived': ...} In which case, an exception is not purposefully raised if the dictionary contains one. Instead, examine the dictionary. For the dictionary formats and more information see the docs for MiscUtils.PickleRPC.`
| Method resolution order: PickleRPCServlet WebKit.RPCServlet.RPCServlet WebKit.HTTPServlet.HTTPServlet WebKit.Servlet.Servlet MiscUtils.PickleRPC.SafeUnpickler __builtin__.object Methods defined here: respondToPost(self, trans) sendResponse(self, trans, response) `Timestamp the response dict and send it.` Static methods defined here: useBinaryPickle() `Determine whether binary pickling format shall be used. When this returns True, the highest available binary pickling format will be used. Override this to return False to use the less-efficient text pickling format.` Methods inherited from WebKit.RPCServlet.RPCServlet: awake(self, transaction) `Begin transaction.` call(self, methodName, *args, **keywords) `Call custom method. Subclasses may override this class for custom handling of methods.` resultForException(self, 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.` sleep(self, transaction) `End transaction.` transaction(self) `Get the corresponding transaction. Most uses of RPC will not need this.` Static methods inherited from WebKit.RPCServlet.RPCServlet: exposedMethods() `Get exposed methods. Subclasses should return a list of methods that will be exposed through XML-RPC.` handleException(transaction) `Handle exception. If ReportRPCExceptionsInWebKit 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 WebKit way. This means logging it to the console, storing it in the error log, sending error email, etc. depending on the settings.` sendOK(contentType, contents, trans, contentEncoding=None) `Send a 200 OK response with the given contents.` Methods inherited from WebKit.HTTPServlet.HTTPServlet: __init__(self) respond(self, trans) `Respond to a request. Invokes the appropriate respondToSomething() method depending on the type of request (e.g., GET, POST, PUT, ...).` respondToHead(self, trans) `Respond to a HEAD request. A correct but inefficient implementation.` Static methods inherited from WebKit.HTTPServlet.HTTPServlet: 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).` notImplemented(trans) Methods inherited from WebKit.Servlet.Servlet: close(self) log(self, 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(self) `Return the name which is simple the name of the class. Subclasses should *not* override this method. It is used for logging and debugging.` open(self) runMethodForTransaction(self, trans, method, *args, **kw) serverSidePath(self, path=None) `Return the filesystem path of the page on the server.` setFactory(self, factory) Static methods inherited from WebKit.Servlet.Servlet: 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.` runTransaction(trans) Data descriptors inherited from WebKit.Servlet.Servlet: __dict__ `dictionary for instance variables (if defined)` __weakref__ `list of weak references to the object (if defined)` Methods inherited from MiscUtils.PickleRPC.SafeUnpickler: allowedGlobals(self) `Allowed class names. Must return a list of (moduleName, klassName) tuples for all classes that you want to allow to be unpickled. Example: return [('datetime', 'date')] allows datetime.date instances to be unpickled.` findGlobal(self, module, klass) `Find class name.` load(self, file) `Unpickle a file.` loads(self, str) `Unpickle a string.`

Functions
`` |  | 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.` time(...) `time() -> floating point number Return the current time in seconds since the Epoch. Fractions of a second may be present if the system clock provides them.`