class ComandProccessor(object): COMANDNOTFOUND = json.dumps({'code': 'comand not found'}, separators=(',',':')) COMANDNOTVALID = json.dumps({'code': 'comand not valid'}, separators=(',',':')) ACCESSERROR = json.dumps({'code': 'access error'}, separators=(',',':')) INTERNALERROR = json.dumps({'code': 'internal error'}, separators=(',',':')) def __init__(self): self.modules = Modules() def getComand(self, comand): comandDict =json.loads(comand) return comandDict['comand'] def getToken(self, comand): comandDict = json.loads(comand) return comandDict['token'] def getModule(self, comand): comandDict = json.loads(comand) return comandDict['module'] def getData(self, comand): comandDict = json.loads(comand) return comandDict['data'] def comandIsValid(self, comand): try: comandDict = json.loads(comand) except: return False if not type(comandDict) is dict: return False if len(comandDict) != 4: return False else: if not 'comand' in comandDict: return False elif not 'token' in comandDict: return False elif not 'module' in comandDict: return False elif not 'data' in comandDict: return False else: return True def findHanlder(self, comand): cc = self.getComand(comand) module = self.getModule(comand) return self.modules.findComand(module, cc) def permissionAllow(self, comand , session): return True
def __init__(self): self.name = 'main' self.prompt_session = PromptSession( 'ST ≫ ', bottom_toolbar=bottom_toolbar, auto_suggest=AutoSuggestFromHistory(), enable_history_search=True, # rprompt=get_rprompt, style=rprompt_style ) self.contexts = [ Listeners(self.prompt_session), Sessions(self.prompt_session), Modules(self.prompt_session), Stagers(self.prompt_session) ] self.prompt_session.completer = WordCompleter([ctx.name for ctx in self.contexts] + ['exit'], ignore_case=True) self.prompt_session.contexts = self.contexts self.current_context = self
def __init__(self): self.name = 'main' self.completer = WordCompleter( ['listeners', 'sessions', 'modules', 'stagers', 'exit'], ignore_case=True) self.prompt_session = PromptSession( 'ST ≫ ', bottom_toolbar=bottom_toolbar, completer=self.completer, auto_suggest=AutoSuggestFromHistory() #rprompt=get_rprompt, #style=rprompt_style ) self.contexts = [ Listeners(self.prompt_session), Sessions(self.prompt_session), Modules(self.prompt_session), Stagers(self.prompt_session) ] self.current_context = self
def __init__(self): self.modules = Modules()