(self)
| 41 | return |
| 42 | |
| 43 | def do_GET(self) -> bytes | None: |
| 44 | if self.path.endswith(PYARROW_WHEEL_PATH.name): |
| 45 | self.send_response(200) |
| 46 | self.send_header("Content-type", "application/x-zip") |
| 47 | self.end_headers() |
| 48 | with PYARROW_WHEEL_PATH.open(mode="rb") as wheel: |
| 49 | self.copyfile(wheel, self.wfile) |
| 50 | elif self.path.endswith("/test.html"): |
| 51 | body = b""" |
| 52 | <!doctype html> |
| 53 | <html> |
| 54 | <head> |
| 55 | <script> |
| 56 | window.python_done_callback = undefined; |
| 57 | window.python_logs = []; |
| 58 | function capturelogs(evt) { |
| 59 | if ('results' in evt.data) { |
| 60 | if (window.python_done_callback) { |
| 61 | let callback = window.python_done_callback; |
| 62 | window.python_done_callback = undefined; |
| 63 | callback({result:evt.data.results}); |
| 64 | } |
| 65 | } |
| 66 | if ('print' in evt.data) { |
| 67 | evt.data.print.forEach((x)=>{window.python_logs.push(x)}); |
| 68 | } |
| 69 | } |
| 70 | window.pyworker = new Worker("worker.js"); |
| 71 | window.pyworker.onmessage = capturelogs; |
| 72 | </script> |
| 73 | </head> |
| 74 | <body></body> |
| 75 | </html> |
| 76 | """ |
| 77 | self.send_response(200) |
| 78 | self.send_header("Content-type", "text/html") |
| 79 | self.send_header("Content-length", len(body)) |
| 80 | self.end_headers() |
| 81 | self.copyfile(BytesIO(body), self.wfile) |
| 82 | elif self.path.endswith("/worker.js"): |
| 83 | body = b""" |
| 84 | importScripts("./pyodide.js"); |
| 85 | onmessage = async function (e) { |
| 86 | const data = e.data; |
| 87 | if (!self.pyodide) { |
| 88 | self.pyodide = await loadPyodide(); |
| 89 | } |
| 90 | function do_print(arg) { |
| 91 | let databytes = Array.from(arg); |
| 92 | self.postMessage({print:databytes}); |
| 93 | return databytes.length; |
| 94 | } |
| 95 | self.pyodide.setStdout({write:do_print,isatty:data.isatty}); |
| 96 | self.pyodide.setStderr({write:do_print,isatty:data.isatty}); |
| 97 | |
| 98 | await self.pyodide.loadPackagesFromImports(data.python); |
| 99 | let results = await self.pyodide.runPythonAsync(data.python); |
| 100 | self.postMessage({results}); |
nothing calls this directly
no test coverage detected