def f(status, results=None): if (results is None): envelope.addElement("body", content=pp.render_json({"status": status, "debug": debug})) else: msg = dict(results) msg.update({"status": status, "debug": debug}) envelope.addElement("body", content=pp.render_json(msg)) self.send(envelope)
def write(self, chunk, cache=300): self._write_debug(chunk) cc = self.get_argument("callback", "") bdy = pp.render_json(chunk) self.set_header("Cache-Control", "public, max-age=%d" % cache) if (re.match(r"^[a-zA-Z_][a-zA-Z0-9_]*$", cc)): self.set_status(200) self.set_header("Content-Type", "text/javascript; charset=utf-8") bdy = u"%s(%s);" % (cc, bdy) else: self.set_header("Content-Type", "application/json") super(RestHandler, self).write(bdy)
def handle_select(self, request, sender, cc): try: if ((request["select"]["regex"] == "leela.xmpp") and (request["select"]["proc"] == "*")): data0 = yield self.redis.hgetall("leela.xmpp") tmp = [] for (key, data1) in data0.iteritems(): data = parser.parse_json(data1) sql = pp.render_select(data["request"]["select"]["proc"], data["request"]["select"]["regex"]) if (data["sender"] == sender.userhost()): tmp.append({"key": key, "cmd": sql }) cc(200, {"results": tmp}) else: hcode = hashlib.sha512() hcode.update(sender.userhost()) hcode.update(request["select"]["proc"]) hcode.update(request["select"]["regex"]) key = hcode.hexdigest() self.redis.hsetnx("leela.xmpp", key, pp.render_json({"request": request, "sender": sender.userhost()})) except: logger.exception() cc(500, {"reason": "internal server error"})
def serialize_data(e, epoch): timestamp = (e.year(), e.month(), e.day(), e.hour(), e.minute(), e.second()) k = serialize_key(*timestamp, epoch=epoch) v = pp.render_json(e.value()) return((k, v))
def serialize_data(e, epoch): timestamp = (e.year(), e.month(), e.day(), e.hour(), e.minute(), e.second()) k = serialize_key(*timestamp, epoch=epoch) v = pp.render_json(e.value()) return ((k, v))