aeat.application.wizard._prompter module

Prompter abstraction for the wizard runtime.

The Prompter protocol decouples “where does an answer come from” from “what does the wizard ask for”. The runtime calls prompter.ask(question, default=...) for every visible question and receives a canonical-token string in return. Two implementations ship: ScriptedPrompter for deterministic tests and structured flag-driven CLI invocations, and QuestionaryPrompter for live operator interaction. Both speak the same canonical-token contract.

exception WizardUnsupportedConsoleError(message=None, *, context=None, suggestion=None, translated_message=None)[source]

Bases: AeatError

Raised when the host terminal cannot host an interactive wizard.

Surfaces when prompt_toolkit rejects the active TTY (typically prompt_toolkit.output.win32.NoConsoleScreenBufferError under git-bash on Windows). The runtime catches this at the QuestionaryPrompter boundary and surfaces a translated operator-facing message rather than a Python traceback.

Parameters:
  • message (str | None)

  • context (Mapping[str, object] | None)

  • suggestion (str | None)

  • translated_message (str | None)

Return type:

None

code: ClassVar[ErrorCode]
exception WizardEditUnsupportedConsoleError(message=None, *, context=None, suggestion=None, translated_message=None)[source]

Bases: WizardUnsupportedConsoleError

No-console refusal raised specifically from the profile edit flow.

The base error’s recovery suggestion names profile create, which reads as a destructive replacement when an operator hit the no-console state via profile edit. This subclass carries its own registered error code so the trailing recovery suggestion names the non-interactive profile edit patch form instead.

Parameters:
  • message (str | None)

  • context (Mapping[str, object] | None)

  • suggestion (str | None)

  • translated_message (str | None)

Return type:

None

code: ClassVar[ErrorCode]
class Prompter(*args, **kwargs)[source]

Bases: Protocol

Capability protocol for collecting one answer from one question.

ask(question, *, default)[source]

Render question and return the operator’s canonical-token answer.

Return type:

str

Parameters:
class ScriptedPrompter(answers)[source]

Bases: object

Test-only prompter that pops canonical-token answers from a FIFO queue.

Tests construct a ScriptedPrompter with a deque of canonical tokens whose order matches the runtime’s expected question sequence. Each ask call pops the leftmost token; an empty deque raises WizardScriptUnderflowError. Calling close() after the runtime finishes raises WizardScriptOverflowError if any scripted token went unconsumed, surfacing test-fixture drift loudly without exposing token values in diagnostics.

Parameters:

answers (deque[str] | list[str] | tuple[str, ...])

property asked: tuple[str, ...]

Return the ids of the questions asked so far, in call order.

ask(question, *, default)[source]

Pop and return the next scripted canonical-token answer.

Parameters:
  • question (WizardQuestion) – The WizardQuestion being asked (used only in the underflow error message).

  • default (str | None) – Ignored; the scripted queue always supplies an explicit answer.

Raises:

WizardScriptUnderflowError – When the answer queue is empty.

Return type:

str

close()[source]

Assert every scripted answer was consumed.

Raises:

WizardScriptOverflowError – When the deque holds unconsumed canonical tokens at flow end. The exception context reports counts only because scripted tokens can contain secrets.

Return type:

None

class QuestionaryPrompter(*, input=None, output=None)[source]

Bases: object

Production prompter that dispatches each widget onto a questionary primitive.

The mapping is one-to-one: TEXTquestionary.text, SECRETquestionary.password, CONFIRMquestionary.confirm, SELECTquestionary.select, CHECKBOXquestionary.checkbox, PATHquestionary.path, INTEGERquestionary.text with a numeric validator. The class accepts an optional input / output pair so tests can drive it through prompt_toolkit.input.create_pipe_input().

Parameters:
  • input (Input | None)

  • output (Output | None)

prepare(flow)[source]

Verify prompt support and explain the setup flow before progress starts.

Return type:

None

Parameters:

flow (WizardFlow)

emit_progress(text)[source]

Emit a progress line (section header or question prefix).

Called by the runtime between question prompts so operators see their position in the flow. Routes through the structured logger so the message is handled by the configured logging pipeline and any registered secret-scrubbing filters.

Return type:

None

Parameters:

text (str)

ask(question, *, default)[source]

Render question interactively and return the canonical-token answer.

Dispatches to the appropriate questionary primitive based on question.widget and returns the operator’s response as a canonical-token string ("true"/"false" for CONFIRM, comma-separated tokens for CHECKBOX, raw text otherwise).

Parameters:
Raises:

WizardUnsupportedConsoleError – When the host terminal cannot host an interactive prompt (Windows no-console, non-TTY).

Return type:

str