Some checks failed
tamq-ci / test (push) Failing after 6s
Assistant: codex Assistant-Model: gpt-5.6-sol Assistant-Session: 01a03397-4d51-7fd1-8ff2-946eb22ea2bc
29 lines
847 B
Python
29 lines
847 B
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from dataclasses import dataclass
|
|
|
|
ADDRESS = re.compile(r"^To:([a-z0-9][a-z0-9._-]*):[ \t]*(.+)$")
|
|
COMMAND = re.compile(r"^Cmd:[ \t]*(\S(?:.*\S)?)?[ \t]*$")
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class RoutedMessage:
|
|
target_repo: str
|
|
body: str
|
|
|
|
|
|
def parse_address_line(line: str) -> RoutedMessage | None:
|
|
"""Parse one complete direct-address line; ordinary input returns None."""
|
|
match = ADDRESS.match(line.rstrip("\r\n"))
|
|
if not match:
|
|
return None
|
|
return RoutedMessage(target_repo=match.group(1), body=match.group(2))
|
|
|
|
|
|
def parse_command_line(line: str) -> str | None:
|
|
"""Return an operator command body; worker output must never call this."""
|
|
match = COMMAND.match(line.rstrip("\r\n"))
|
|
if not match or not match.group(1):
|
|
return None
|
|
return match.group(1)
|