from sitz import tagger

from twisted.internet.defer import inlineCallbacks, succeed
from twisted.internet import reactor
from abbase import getDigit, log, getListIndex

consoleCommand, consoleMetaclass = tagger('commands')
class ConsoleClient(object):
    __ccname__ = 'console client'
    __metaclass__ = consoleMetaclass
    
    def __init__(self):        
        self.onClose = reactor.stop
        self.onOpen = self.initializeConsoleClient().addCallback(lambda _:log('console client initialized'))
        
    @consoleCommand('quit','exits program')
    @inlineCallbacks
    def quit(self):
        yield self.onClose()

    @consoleCommand('help','prints list of available commands')
    def help(self):
        return '\n'.join('%d:\t%s\t->\t%s' % (index, command[tagger.NAME], command[tagger.DESCRIPTION]) for index, command in enumerate(self.commands))
 
    @inlineCallbacks
    def inputLoop(self):
        commandIndex = yield getListIndex([command[tagger.NAME] for command in self.commands],'select command')
        try:
            response = yield self.commands[commandIndex][tagger.CALLABLE](self)
            response = str(response)
        except Exception, e:
Beispiel #2
0
from autobahn.websocket import listenWS
from autobahn.wamp import exportRpc, \
    WampServerFactory, \
    WampServerProtocol

from functools import partial

from sitz import tagger, SITZ_RPC_URI

from abbase import uriFromMessage
from abclient import getProtocol

PROPERTIES = 'PROPERTIES'

_command, wampmetaclass = tagger('commands')
def command(name,description='no description'):
    """
    decorator to expose decorated function as
    server command

    @param name: command identifier
    @param str: string    
    """
    def foo(bar):
        return exportRpc(name)(_command(name,description)(bar))
    return foo
    
class BaseWAMP(object):
    """
    base class for WAMP classes