def render(self, request): """ :type request: bouser.web.request.BouserRequest :param request: :return: """ self.web.crossdomain(request, allow_credentials=True) main, sub = request.get_content_type() if not main: main, sub = 'application', 'json' content = request.content.getvalue() if sub in ('msgpack', 'application/x-msgpack'): data = load(content) elif sub == 'json': data = json.loads(content, 'utf-8') else: request.setResponseCode(400, 'Unknown Content Type') return '' message = Message.from_json(data) self.simargl.message_received(self, message) request.setHeader('content-type', 'application/json; charset=utf-8') return as_json({'success': True})
def startService(self): try: with open('tokens.msgpack', 'rb') as f: self.tokens = msgpack_helpers.load(f.read()) except (IOError, OSError, msgpack.UnpackException, msgpack.UnpackValueError): pass self.expired_cleaner = LoopingCall(self._clean_expired) self.expired_cleaner.start(self.clean_period) Service.startService(self)
def processData(self, buf): if self.mode == 'negotiation': message = json.loads(buf) self.mode = message['mode'] self._flush_q() return elif self.mode == 'json': data = json.loads(buf) elif self.mode == 'msgpack': data = msgpack_helpers.load(buf) else: return message = Message.from_json(data) self.factory.notify(message)