def post(self,session_id): session = self.get_session(session_id) data = self.request.body.decode('utf-8') if data.startswith('data='): data = data[5:] data = json.loads(data) session.raw_message(data) self.set_header('Content-Type', 'text/plain; charset=UTF-8') self.finish()
def post(self, server_id,session_id): session = self._session = self.get_session(session_id) if session.is_closed(): self.set_status(401) return data = self.request.body if not data: self.write("Payload expected.") self.set_status(500) return list = json.loads(data) for message in list: session.raw_message(message) self.set_status(204) self.set_header('Content-Type', 'text/plain; charset=UTF-8')
def post(self, session_id): session = self.get_session(session_id) data = self.request.body if not data.startswith("d="): raise HTTPError(403, "Incorrect jsonp format!") data = urllib.unquote_plus(data[2:]).decode("utf-8") if data.startswith('"'): data = json.loads(data) session.raw_message(data) self.set_header("Content-Type", "text/plain; charset=UTF-8") self.finish()
def on_message(self,message): self._session.raw_message(json.loads(message))
def _parse_message(self,message): parts = message.split(':', 3) if len(parts) == 3: msg_type, msg_id, msg_endpoint = parts msg_data = None else: msg_type, msg_id, msg_endpoint, msg_data = parts if msg_type == '1': if not msg_endpoint: self.on_open_connection(self._connection) return conn = self.get_sub_connection(msg_endpoint) if conn: raise exception.Error("Subroute allready opened!") parsed = urlparse.urlparse(msg_endpoint) cl = self._sub_routes.get(parsed.path) if not cl: raise exception.SubRouteNotFound(msg_endpoint) conn = cl(self,msg_endpoint,self._connection,**self._kwargs) args = urlparse.parse_qs(parsed.query,keep_blank_values=1) info = connection.Info(self._client_info.ip,args,self._client_info.cookies) yield gen.listen(conn.on_handshake(info),conn.exception_callback) self._sub_connections[msg_endpoint] = conn self.on_open_connection(conn) return elif msg_type == '2': self._missed_heartbeats = 0 return if msg_endpoint: conn = self.get_sub_connection(msg_endpoint) if not conn: raise exception.SubRouteNotFound(msg_endpoint) else: conn = self._connection if msg_type == '0': self.close(conn) return if msg_type == '4': # JSON message. Unserialize and change message type msg_data = json.loads(msg_data) msg_type = '3' if msg_type == '3': result = yield gen.listen(conn.on_message(msg_data),conn.exception_callback) if msg_id: self.send_ack(conn, msg_id, result) elif msg_type == '5': if not msg_data: raise exception.MessageFormatUnexpected event = json.loads(msg_data) if 'args' not in event: event['args'] = [] result = yield gen.listen(conn.on_event(event['name'],event['args']),conn.exception_callback) if msg_id: if msg_id.endswith('+'): msg_id = msg_id[:-1] self.send_ack(conn,msg_id,result) pass elif msg_type == '6': args = [] parts = msg_data.split('+',1) if len(parts) is 2: msg_id, msg_data = parts else: msg_id, msg_data = parts[0], None if msg_data: args = json.loads(msg_data) self.final_ack(conn, msg_id, args) pass elif msg_type == '7': #error pass else: raise exception.MessageFormatUnexpected(message)