import os import tempfile from pathlib import Path import yaml def write_temp_spec(payload: dict) -> Path: handle, filename = tempfile.mkstemp(prefix="l4d2-spec-", suffix=".yaml") path = Path(filename) with os.fdopen(handle, "w", encoding="utf-8") as file_obj: file_obj.write(yaml.safe_dump(payload, sort_keys=False)) return path