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