| 595 | sys.stdout.write("[gui] " + fmt % args + "\n") |
| 596 | |
| 597 | |
| 598 | def _is_loopback_host(host: str) -> bool: |
| 599 | """Whether binding to host keeps the server reachable only from this machine.""" |
| 600 | candidate = str(host or "").strip().strip("[]").lower() |
| 601 | if candidate in {"localhost", ""}: |
| 602 | return True |
| 603 | try: |
| 604 | return ipaddress.ip_address(candidate).is_loopback |
| 605 | except ValueError: |
| 606 | # A hostname we cannot classify offline; treat as non-loopback so the |
| 607 | # explicit opt-in below is required rather than assumed safe. |
| 608 | return False |
| 609 | |
| 610 | |
| 611 | def run_server( |
| 612 | host: str = "127.0.0.1", |