42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
# Private conformance peer: author APIs only; no framing or lifecycle code.
|
|
import pathlib
|
|
import sys
|
|
import threading
|
|
|
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[3] / "sdk/python"))
|
|
from cthulhu_tentacle import Command, present, serve
|
|
|
|
started = threading.Event()
|
|
|
|
|
|
def echo(cancelled, arguments):
|
|
return arguments
|
|
|
|
|
|
def fail(cancelled, arguments):
|
|
raise RuntimeError("private handler details")
|
|
|
|
|
|
def large(cancelled, arguments):
|
|
return "x" * 65536
|
|
|
|
|
|
def wait(cancelled, arguments):
|
|
started.set()
|
|
cancelled.wait()
|
|
pathlib.Path(sys.argv[1]).write_text("cancelled")
|
|
|
|
|
|
def has_started(cancelled, arguments):
|
|
return started.wait(2)
|
|
|
|
|
|
commands = [Command("echo", "Echo", "", echo), Command("fail", "Fail", "", fail),
|
|
Command("large", "Large", "", large), Command("wait", "Wait", "", wait),
|
|
Command("started", "Started", "", has_started)]
|
|
if pathlib.Path(sys.argv[1]).name == "presentation":
|
|
commands.append(Command("present", "Present", "",
|
|
lambda cancelled, arguments: present(speech="Hello, é猫😀é", braille="Display é猫😀é", uninterruptible=True),
|
|
presentation=True))
|
|
serve(commands)
|