def send_error(self, e): send_to_server({ "id": self.id, "error": { "type": type(e).__name__, "message": "PDF generation failed: " + str(e) } })
def send_response(self, data): send_to_server({"id": self.id, "response": None, "objects": [{"type": ["DataMedia"], "path": ["response"], "id": "pdf", "mime-type": "application/pdf", "name": self.filename}]}) # Copied from _server.serialise() l = len(data) i = 0 n = 0 sent_once = False while i < l or not sent_once: chunk_len = min(l - i, 65536) send_to_server({'type': 'CHUNK_HEADER', 'requestId': self.id, 'mediaId': 'pdf', 'chunkIndex': n, 'lastChunk': (i + chunk_len == l)}, data[i:(i+chunk_len)]) i += chunk_len n += 1 sent_once = True
def send_exception(self, e): send_to_server({"id": self.id, "error": e})