Exemple #1
0
 def _sendMessageNow(self):
     if self.queue.empty() and self.iteratorQueue.empty():
         return
     self.corpus.call_running = True
     if not self.iteratorQueue.empty() and (
             self.queue.empty() or
         (self.last_query
          and self.last_query["method"] != "iterate_previous_query")):
         queue = self.iteratorQueue
     else:
         queue = self.queue
     self.deferred, method, args, kwargs = queue.get_nowait()
     if config["DEBUG"] and (method != "iterate_previous_query"
                             or config["DEBUG"] == 2):
         self.corpus.log("Traph client query: %s %s %s" %
                         (method, lightLogVar(args), lightLogVar(kwargs)))
     self.last_query = {"method": method, "args": args, "kwargs": kwargs}
     if method == "clear":
         self.corpus.log(
             "Dropping cleared traph queued queries: %s calls & %s iterative calls"
             % (self.queue.len(), self.iteratorQueue.len()))
         self.iteratorQueue.drop()
         self.queue.drop()
     self.start_query = time()
     self.sendLine(msgpack.packb(self.last_query))
Exemple #2
0
 def lineReceived(self, data):
     self.corpus.lastcall = time()
     try:
         msg = msgpack.unpackb(data)
         if config["DEBUG"]:
             exec_time = time() - self.start_query
             if exec_time > 1:
                 self.corpus.log(
                     "WARNING: query took a long time! (%ss) %s %s %s" %
                     (exec_time, self.last_query["method"],
                      lightLogVar(self.last_query["args"]),
                      lightLogVar(self.last_query["kwargs"])))
         if config["DEBUG"] == 2:
             self.corpus.log("Traph server answer: %s" % lightLogVar(msg))
         if "iterator" in msg:
             return self.reiterateMessage(self.deferred, msg["iterator"])
         self.deferred.callback(msg)
     except (msgpack.exceptions.ExtraData,
             msgpack.exceptions.UnpackValueError) as e:
         error = "%s: %s - Received badly formatted data of length %s in answer to %s %s %s" % (
             type(e), e, len(data), self.last_query["method"],
             lightLogVar(self.last_query["args"]),
             lightLogVar(self.last_query["kwargs"]))
         self.corpus.log(error, True)
         if self.deferred:
             self.deferred.errback(Exception(error))
     self.corpus.call_running = False
     self.deferred = None
     self._sendMessageNow()
Exemple #3
0
 def _cbRender(self, result, request, id, version):
     if self.debug == 2:
         request.content.seek(0, 0)
         content = request.content.read()
         if not content and request.method == 'GET' and 'request' in request.args:
             content = request.args['request'][0]
         parsed = jsonrpclib.loads(content)
         functionPath = parsed.get("method")
         try:
             txt = jsonrpclib.dumps(result, id=id, version=2.0)
         except TypeError:
             txt = result
         self.safe_log("%s: %s" % (functionPath, lightLogVar(txt, 1000)), "DEBUG - ANSWER")
     return JSONRPC._cbRender(self, result, request, id, version)
Exemple #4
0
 def lineReceived(self, data):
     self.corpus.lastcall = time()
     try:
         msg = msgpack.unpackb(data)
         if config["DEBUG"]:
             exec_time = time() - self.start_query
             if exec_time > 1:
                 self.corpus.log("WARNING: query took a long time! (%ss) %s %s %s" % (exec_time, self.last_query["method"], lightLogVar(self.last_query["args"]), lightLogVar(self.last_query["kwargs"])))
         if config["DEBUG"] == 2:
             self.corpus.log("Traph server answer: %s" % lightLogVar(msg))
         if "iterator" in msg:
             return self.reiterateMessage(self.deferred, msg["iterator"])
         self.deferred.callback(msg)
     except (msgpack.exceptions.ExtraData, msgpack.exceptions.UnpackValueError) as e:
         error = "%s: %s - Received badly formatted data of length %s in answer to %s %s %s" % (type(e), e, len(data), self.last_query["method"], lightLogVar(self.last_query["args"]), lightLogVar(self.last_query["kwargs"]))
         self.corpus.log(error, True)
         if self.deferred:
             self.deferred.errback(Exception(error))
     self.corpus.call_running = False
     self.deferred = None
     self._sendMessageNow()
Exemple #5
0
 def _sendMessageNow(self):
     if self.queue.empty() and self.iteratorQueue.empty():
         return
     self.corpus.call_running = True
     if not self.iteratorQueue.empty() and (
       self.queue.empty() or
       (self.last_query and self.last_query["method"] != "iterate_previous_query")
     ):
         queue = self.iteratorQueue
     else: queue = self.queue
     self.deferred, method, args, kwargs = queue.get_nowait()
     if config["DEBUG"] and (method != "iterate_previous_query" or config["DEBUG"] == 2):
         self.corpus.log("Traph client query: %s %s %s" % (method, lightLogVar(args), lightLogVar(kwargs)))
     self.last_query = {
       "method": method,
       "args": args,
       "kwargs": kwargs
     }
     if method == "clear":
         self.corpus.log("Dropping cleared traph queued queries: %s calls & %s iterative calls" % (self.queue.len(), self.iteratorQueue.len()))
         self.iteratorQueue.drop()
         self.queue.drop()
     self.start_query = time()
     self.sendLine(msgpack.packb(self.last_query))