def do_POST(self, client): try: body = client.rfile.read(int(client.headers['Content-Length'])) task = json.loads(body.decode('utf-8')) print('\n\nReceive: %s\n' % tools.stringify(task)) taskQueue.put(task) tools.normalResponse(client, "success") except Exception as e: tools.normalResponse(client, "failed")
def message_received(self, client, msg): try: if client.status == self.ESTABLISHED: task = json.loads(msg.decode('utf-8')) taskQueue.put(task) client.task = task print('\n\nReceive: %s\n' % tools.stringify(task)) if task['type'] == 'stream': client.status = self.IN_TRANSIT task['close'] = lambda: self.close(client) task['dataQueue'] = queue.Queue(dataCacheSize) for i in range(dataCacheSize): task['dataQueue'].put(None) elif client.status == self.IN_TRANSIT: desc, chunk = msg.split(b'\r\n', 1) data = json.loads(desc.decode('utf-8')) data['chunk'] = chunk client.task['dataQueue'].put(data) self.send_message(client, 'success') except: self.send_message(client, 'failed')
def printWithoutData(self, task): copyTask = {key: task[key] for key in task} if copyTask.get('data'): copyTask['data'] = '...' print('\n\nReceive: %s\n' % tools.stringify(copyTask))
def downloadLoop(): while True: task = taskQueue.get() print('Handle: %s' % tools.stringify(task)) taskDispatcher.dispatch(**task)