Skip to content
handlers.py 832 B
Newer Older
Antoine Millet's avatar
Antoine Millet committed
#!/usr/bin/env python
#coding:utf8

class RpcHandler(object):    
    '''
    Basic RPC functions handler.
Antoine Millet's avatar
Antoine Millet committed

    Derive this call in your handler and define some methods. All the defined
    methods (including privates) are available to your peer.
Antoine Millet's avatar
Antoine Millet committed
    '''

    def __getitem__(self, name):
        if hasattr(self, name):
            return getattr(self, name)
        else:
            raise KeyError(name)

Antoine Millet's avatar
Antoine Millet committed
#
Antoine Millet's avatar
Antoine Millet committed
# Decorators:
Antoine Millet's avatar
Antoine Millet committed
#
Antoine Millet's avatar
Antoine Millet committed

def threadless(func):
    '''
    Function handler decorator -- don't spawn a new thread when function is
    called.
    '''
    
    func.__threaded__ = False
    return func

def pure(func):
    '''
    Function handler decorator -- the function is a pure fonction, caller will
Antoine Millet's avatar
Antoine Millet committed
    not pass :class:`RpcConnection` object as first call parameters.
Antoine Millet's avatar
Antoine Millet committed
    '''
    
    func.__pure__ = True
    return func