File
Blob: samples/repl-server-python/worker.py
| 1 | import code |
| 2 | import sys |
| 3 | from io import StringIO |
| 4 | |
| 5 | from js import Response |
| 6 | from workers import WorkerEntrypoint |
| 7 | |
| 8 | sys.stdout = StringIO() |
| 9 | |
| 10 | ii = code.InteractiveInterpreter() |
| 11 | |
| 12 | |
| 13 | class Default(WorkerEntrypoint): |
| 14 | async def fetch(self, request): |
| 15 | cmd = (await request.json()).cmd |
| 16 | |
| 17 | ii.runsource(cmd) |
| 18 | |
| 19 | res = sys.stdout.getvalue() |
| 20 | sys.stdout = StringIO() |
| 21 | |
| 22 | return Response.new(res) |