Qooxdoo-specific CherryPy-based JSON RPC-server
Project description
Overview
Python RPC-server for a Qooxdoo application. Implemented on top of Cherrypy. Supports file upload and download. Controller code example:
import cherrypy
import qxcpjsonrpc as rpc
class Service:
@cherrypy.expose
def index(self, *args, **kwargs):
return rpc.JsonRpcServer().run()
Service code example:
import qxcpjsonrpc as rpc
class Test(rpc.JsonRpcService):
@rpc.public
def add(self, x, y):
return x + y
Qooxdoo code example:
var rpc = new qx.io.remote.Rpc();
rpc.setServiceName("Test");
rpc.setUrl("http://127.0.0.1:8080/service");
rpc.addListener("completed", function(event)
{
console.log(event.getData());
});
rpc.callAsyncListeners(this, "add", 5, 7);
Serialization
Serialization is provided by json package. However it doesn’t work out-of-the-box for some practically important types.
No special deserialization but json.loads is performed. Additional parsing is indended to be in user code.
Date
Dates are serialized to UTC ISO 8601 strings, close to what Javascript JSON.stringify(new Date()) produces. datetime.datetime objects look like 2012-03-17T19:09:12.217000Z, datetime.date like 2012-03-17T00:00:00Z.
As far as I know, there’s no reliable and cross-browser way to parse ISO 8601 strings using Javascript Date object. The following code can help (usually I put it to Date.fromISOString, as a counterpart to Date.prototype.toISOString), which converts ISO 8601 to cross-browser representation 2011/10/09 07:06:05 +0000 and passes it to Date constructor.
function fromISOString(value)
{
if(!value)
{
return null;
}
return new Date(value
.split(".")[0]
.split("Z")[0]
.split("-").join("/")
.replace("T", " ")
+ " +0000"
);
}
For dealing with ISO 8601 strings in service user code there’s a helper, which can be used as follows. Note that datetime.datetime objects it produces are timezone-aware. Timezone is UTC.
import qxcpjsonrpc as rpc
rpc.fromJsonDate('2012-03-17T19:09:12.217Z')
Decimal
Serialized as strings.
Examples
For examples look in test suite. More examples could be found in this project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for QooxdooCherrypyJsonRpc-0.3.0.zip
Algorithm | Hash digest | |
---|---|---|
SHA256 | a71d4b82bfb87ff7a113ca2df838c9478378a07e6051a47237b9f9fe969934c1 |
|
MD5 | ae7e41ef13b9f5b11520b74edae5d0c8 |
|
BLAKE2b-256 | 0fd2c13f7c27346eca0da2df67d7babfa472bbf16c251f485c834ea0b693a9dc |