async def helper(self, sid, request): try: result = None logger.info("REQUEST\nfunc_name: {}\nrequest: {}\n".format( name, request )) product = await func(self, sid, request) logger.info("REQUEST\nfunc_name: {}\nproduct: {}\nrequest: {}\n".format( name, product, request )) if not is_error(product): try: validate(instance=product, schema=bres.schema[name]) result = dumps(product, cls=DictEncoder) except ValidationError: logger.info("VALIDATION ERROR\nfunc_name: {}\nReturn response: {}\nReturn schema: {}\n".format( name, product, name )) result = make_error(Errors.SERVER_ERR) else: logger.info("INPUT ERROR\nfunc_name: {}\nReturn response: {}".format( name, product )) result = product except Exception as e: # catch generic exceptions logger.info("GENERIC ERROR\nfunc_name: {}\nrequest: {}\nexception: {}\n".format( name, request, e )) result = make_error(Errors.SERVER_ERR) logger.info("RESULT\n{}\n".format(result)) return result
def helper(self, **kwargs): board_id = kwargs["board_id"] if self.gm.boards.find_one({"short_id": board_id}): return func(self, **kwargs) else: return make_error(Errors.DNE_BOARD, error_meta={"board_id": board_id})
async def on_create(sid, request): """ :return: :ref:`bres_created-label` :errors: BAD_RESPONSE """ product = gm.board_manager.create() if not is_error(product): try: validate(instance=product, schema=bres.created) serialized = dumps(product, cls=DictEncoder) except ValidationError: serialized = make_error(Errors.BAD_RESPONSE) else: serialized = make_error(product) return serialized
async def helper(self, sid, request): try: session = await self.get_session(sid) discussion_id = session["discussion_id"] user_id = session["user_id"] except Exception: return make_error(Errors.INVALID_USER_SESSION) return await func(self, sid, request)
async def helper(self, sid, request): try: result = None logger.info("REQUEST (sid: {})\nfunc_name: {}\nrequest: {}\n".format( sid, name, request )) product = await func(self, sid, request) logger.info("func_name: {}\nproduct: {}\nrequest: {}\n".format( name, product, request )) if not is_error(product): try: validate(instance=product, schema=dres.schema[name]) result = dumps(product, cls=DictEncoder) if emit: # send result to others in room session = await self.get_session(sid) logger.info("Emitting (sid: {}) with {}".format(sid, session)) if "board_id" in session and "discussion_id" in session: board_id = session["board_id"] discussion_id = session["discussion_id"] logger.info("Emitting to {}/{}.".format(board_id, discussion_id)) await self.emit( name, result, room=get_room(board_id, discussion_id), skip_sid=sid ) except ValidationError: logger.info("Return response: {}\nReturn schema: {}".format( product, name )) result = make_error(Errors.SERVER_ERR) else: logger.info("INPUT ERROR\nfunc_name: {}\nReturn response: {}".format( name, product )) result = product except Exception as e: # catch generic exceptions logger.info("func_name: {}\nrequest: {}\nexception: {}\n".format( name, request, e )) result = make_error(Errors.SERVER_ERR) return result
def helper(self, **kwargs): board_id = kwargs["board_id"] link_id = kwargs["link_id"] if self.gm.links.find_one({ "short_id": link_id, "board_id": board_id }): return func(self, **kwargs) else: return make_error(Errors.DNE_LINK, error_meta={"link_id": link_id})
def helper(self, **kwargs): board_id = kwargs["board_id"] user_id = kwargs["user_id"] if self.gm.users.find_one({ "short_id": user_id, "board_id": board_id }): return func(self, **kwargs) else: return make_error(Errors.DNE_USER, error_meta={"user_id": user_id})
def helper(self, **kwargs): board_id = kwargs["board_id"] discussion_id = kwargs["discussion_id"] if self.gm.discussions.find_one({ "short_id": discussion_id, "board_id": board_id }): return func(self, **kwargs) else: return make_error(Errors.DNE_DISCUSSION, error_meta={"discussion_id": discussion_id})
def helper(self, **kwargs): board_id = kwargs["board_id"] for p in Checker.unit_input: if p in kwargs: unit_id = kwargs[p] if self.gm.units.find_one({ "short_id": unit_id, "board_id": board_id }): return func(self, **kwargs) else: return make_error(Errors.DNE_UNIT, error_meta={"unit_id": unit_id})
def add_focused(self, board_id, discussion_id, unit_id): unit = self.gm.units.find_one({"short_id": unit_id, "board_id": board_id}) if unit["chat"] is True: return make_error(Errors.NOT_BOARD, error_meta={"unit_id": unit_id} ) discussion = self.gm.discussions.find_one({"short_id": discussion_id, "board_id": board_id}) if unit["short_id"] not in discussion["focused"]: self.gm.discussions.update_one( {"short_id" : discussion_id, "board_id": board_id}, {"$addToSet": {"focused": unit_id}} ) return {"unit": self.gm._get_basic_unit(board_id, unit_id)} else: return {}
def add_pinned(self, board_id, discussion_id, unit_id, user_id): unit = self.gm.units.find_one({"short_id": unit_id, "board_id": board_id}) if unit["chat"] is False: return make_error(Errors.NOT_CHAT, error_meta={"unit_id": unit_id} ) discussion = self.gm.discussions.find_one({"short_id": discussion_id, "board_id": board_id}) if unit["short_id"] not in discussion["pinned"]: self.gm.discussions.update_one( {"short_id" : discussion_id, "board_id": board_id}, {"$addToSet": {"pinned": unit_id}} ) message = "pinned \"{}\"".format(unit["pith"]) notice_unit = self.gm.create_notice_unit(board_id, discussion_id, message, user_id) return { "unit": self.gm._get_chat_unit(board_id, unit_id), "notice_unit": self.gm._get_chat_unit(board_id, notice_unit.short_id) } else: return {}
async def helper(self, sid, request): try: validate(instance=request, schema=breq.schema[name]) return await func(self, sid, request) except ValidationError: return make_error(Errors.BAD_REQUEST)
async def helper(self, sid, request): try: result = None product = await func(self, sid, request) logger.info("func_name: {}\nproduct: {}\nrequest: {}\n".format( name, product, request )) if is_error(product): result = make_error(product, info={ "func_name": name, "result": result, "request": request }) else: ret_res, emits_res = product bad_response = False if ret is not None: try: validate(instance=ret_res, schema=dres.schema[ret]) result = ret_res except ValidationError: logger.info("Return response: {}\nReturn schema: {}".format(ret_res, ret)) bad_response = True if emits is not None: assert(emits_res is not None) for r, e in zip(emits_res, emits): try: validate(instance=r, schema=dres.schema[e]) except ValidationError: logger.info("Emit response: {}\nEmit schema: {}".format(r, e)) bad_response = True if bad_response: # we cannot send off emits result = make_error(Errors.BAD_RESPONSE) else: # we can send off emits shared = {} if emits is not None: assert(emits_res is not None) for r, e in zip(emits_res, emits): shared[e] = r if result is None: result = {} # set emitted data to return result["shared"] = shared result = dumps(result, cls=DictEncoder) # default returns # every function except maybe leave should have a discussion id session = await self.get_session(sid) # send to everyone else if "discussion_id" in session: discussion_id = session["discussion_id"] emit_shared = dumps(shared, cls=DictEncoder) await self.emit(name, emit_shared, room=discussion_id, skip_sid=sid) return result except Exception as e: logger.info("func_name: {}\nrequest: {}\nexception: {}\n".format( name, request, e ))