Handle#

class scikitplot.cleanprompt.Handle(vault, policy, entries=())[source]#

Everything needed to decode a reply. Holds the removed values.

Parameters:
vaultVault

Label-to-value mapping.

policyRedactionPolicy

The policy that produced the labels; supplies the placeholder grammar.

entriestuple of Entry

Ordered record of what was replaced, used to seed a following turn.

Parameters:

Notes

User notes. Treat a handle like a password: keep it on the machine that created it and let it go out of scope when you are done. Printing or logging it discloses nothing — its representation reports counts, not values.

Developer notes. Deliberately not a plain tuple with the safe text. Keeping the safe half and the unsafe half in different objects means a caller who serializes “the result” cannot accidentally serialize the secrets, which is the mistake the upstream web tier made by putting the mapping in a cookie.

clear()[source]#

Drop every value this handle holds.

Return type:

None

entries: tuple[Entry, ...] = ()#
export()[source]#

Return a JSON-safe document containing the values.

Returns:
dict

{"grammar": ..., "policy": ..., "entries": {label: value}}.

Raises:
PolicyError

If the vault has been cleared.

Return type:

dict[str, Any]

Notes

User notes. This is the deliberate, named way to move a handle across a process boundary — a web request, a queue, a subprocess. It contains the removed values in clear text. Nothing in this submodule calls it implicitly.

property labels: tuple[str, ...]#

Every placeholder issued. Labels are not secrets.

Type:

Tuple of str

classmethod load(document, policy=None)[source]#

Rebuild a handle from export output.

Parameters:
documentmapping

The exported document.

policyRedactionPolicy, optional

Policy to decode under. Defaults to DEFAULT_POLICY.

Returns:
Handle

A handle with no entry history, which is enough to decode but not to seed a following turn.

Raises:
PolicyError

If the document is malformed, or its grammar does not match policy.

Parameters:
Return type:

Handle

policy: RedactionPolicy[source]#
vault: Vault[source]#