cpython/Tools/wasm/emscripten/web_example/server.py
Savannah Ostrowski a15aeec29e
Some checks are pending
Tests / (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
GH-139590: Run ruff format on pre-commit for Tools/wasm (#139591)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-10-08 02:25:06 +00:00

46 lines
1 KiB
Python
Executable file

#!/usr/bin/env python
import argparse
from http import server
parser = argparse.ArgumentParser(
description="Start a local webserver with a Python terminal."
)
parser.add_argument(
"--port",
type=int,
default=8000,
help="port for the http server to listen on",
)
parser.add_argument(
"--bind",
type=str,
default="127.0.0.1",
help="Bind address (empty for all)",
)
class MyHTTPRequestHandler(server.SimpleHTTPRequestHandler):
def end_headers(self) -> None:
self.send_my_headers()
super().end_headers()
def send_my_headers(self) -> None:
self.send_header("Cross-Origin-Opener-Policy", "same-origin")
self.send_header("Cross-Origin-Embedder-Policy", "require-corp")
def main() -> None:
args = parser.parse_args()
if not args.bind:
args.bind = None
server.test( # type: ignore[attr-defined]
HandlerClass=MyHTTPRequestHandler,
protocol="HTTP/1.1",
port=args.port,
bind=args.bind,
)
if __name__ == "__main__":
main()