def receive(self, frame): print('>>> frame received in database') sender = frame.get('from') action = frame.get('action') body = frame.get('body') word = body.get('word') if action == Routes.Db.add_meanings: print('>>> an add meanings action requested!') meanings = body.get('meanings') self.__add_meanings(word, meanings) elif action == Routes.Db.add_word: print('>>> an add word action requested!') meanings = body.get('meanings') self.__add_word(word, meanings) elif action == Routes.Db.get_meanings: print('>>> a get meaning action requested!') body['meaning'] = self.__get_meaning(word) frame = build_frame(self.__class__, sender, Routes.Db.get_meanings, body) self.__router.forward(frame) elif action == Routes.Db.search: print('>>> a search action requested!') results = self.__search(word) body = {'word': word, 'results': results} frame = build_frame(self.__class__, sender, Routes.Db.search, body) self.__router.forward(frame) else: # this should never happen print('><>< unrecognized action in Db')
def search(self, word): body = {'word': word} frame = build_frame(self.__class__, DataBase, Routes.Db.search, body) self.__router.forward(frame)
def get_meanings(self, word): body = {'word': word} frame = build_frame(self.__class__, DataBase, Routes.Db.get_meanings, body) self.__router.forward(frame)
def add_meanings(self, word, meanings): assert type(meanings) is list, 'meanings must be a list!' body = {'word': word, 'meanings': meanings} frame = build_frame(self.__class__, DataBase, Routes.Db.add_meanings, body) self.__router.forward(frame)