Module bjsonrpc.handlers

class bjsonrpc.handlers.BaseHandler(connection, *args, **kwargs)

Base Class to publish remote methods. It is instantiated by Connection.

Example:

class MyHandler(bjson.handlers.BaseHandler):
    def _setup(self):
        # Initailize here.
        self.c = 0
        
    def echo(self,text): 
        print text
        self.c += 1
        
    def getcount(self): return c

Other members:

public_methods_pattern
RegEx string that returns True if the method name is suitable for publishing. Defaults to r’^[a-z]w+$’
nonpublic_methods
List of string containing names that shouldn’t be published (even if they are in the format required by the RegEx). Defaults to [“close”,”_factory”,”add_method”,”get_method”]
_setup(*args, **kwargs)

Empty method to ease inheritance. Overload it with your needs, it will be called after __init__.

_shutdown()

Internal method called when the handler is going to be destroyed. You should add cleanup code here. Remember to call the parent function.

classmethod _factory(*args, **kwargs)

New in bjsonrpc v0.2.1

Classmethod aimed to create flavoured instances of BaseHandler. When you create a new connection you may want to give the constructor a set of specific arguments. Use this classmethod to do that:

conn = bjsonrpc.connect(handler_factory=MyHandler._factory(“my flavoured one”))

Later, whenever the class is instantiated, the BaseHandler.setup method will receive the arguments passed to factory.

The original idea for this feature is from Paul Pietkiewicz (pawel.pietkiewicz (at) gmail.com)

add_method(*args, **kwargs)

Porcelain for publishing methods into the handler. Is used by the constructor itself to publish all non-private functions.

get_method(name)

Porcelain for resolving method objects from their names. Used by connections to get the apropiate method object.

close()

Cleans some variables before the object is freed. close is called manually from connection whenever a handler is going to be deleted.

class bjsonrpc.handlers.NullHandler(connection, *args, **kwargs)

Null version of BaseHandler which has nothing in it. Use this when you don’t want to publish any function.

Previous topic

Module bjsonrpc.request

Next topic

Module bjsonrpc.proxies

This Page