JSON-RPC Calculator

The code for this example is located in the examples.calculator.manage module.

This is a a JSON-RPC server with some simple functions. To run the server type:

python manage.py

Open a new shell and launch python and type:

>>> from pulsar.apps import rpc
>>> p = rpc.JsonProxy('http://localhost:8060')
>>> p.ping()
'pong'
>>> p.functions_list()
[[...
>>> p.calc.add(3,4)
7.0

Implementation

The calculator rpc functions are implemented by the Calculator handler, while the Root handler exposes utility methods from the PulsarServerCommands handler.

class examples.calculator.manage.Calculator(subhandlers=None, title=None, documentation=None)[source]

A JSONRPC handler which implements few simple remote methods.

rpc_add(request, a, b)[source]

Add two numbers

rpc_divide(*args, **kwargs)

Divide two numbers.

This method illustrate how to use the rpc_method() decorator.

rpc_multiply(request, a, b)[source]

Multiply two numbers

rpc_randompaths(*args, **kwargs)

Lists of random walks.

rpc_subtract(request, a, b)[source]

Subtract two numbers

class examples.calculator.manage.Root(subhandlers=None, title=None, documentation=None)[source]

Add two rpc methods for testing to the PulsarServerCommands handler.

rpc_dodgy_method(request)[source]

This method will fails because the return object is not json serializable.

class examples.calculator.manage.Site[source]

WSGI handler for the RPC server

setup(environ)[source]

Called once to setup the list of wsgi middleware.