cadrumo.core.redaction.tax_identity_admission module

Host-composed admission gate for tax identities found by redaction.

Redaction scans wide and admits narrowly: a span shaped like a Spanish NIF/CIF or a prefixed NIF-IVA is only hashed when it really is one, because the same shapes cover ordinary operator output (SE-2026-000412, F-2026-0142, the groups of a printed IBAN). Deciding that needs the Spanish control-character tables and the dated per-Member-State NIF-IVA formats, which are published registry authority this core module cannot import.

The process host binds the authority-backed gate. Without one – or when the bound gate reports that its authority is unavailable – redaction admits on lexical shape alone, which over-redacts ordinary output rather than letting a real identity through.

class TaxIdentityAdmission(*args, **kwargs)[source]

Bases: Protocol

Decide whether a normalised span is a real tax identity.

Each method returns None when its authority cannot be consulted, so the caller applies its own fail-safe instead of treating absence as refusal.

admits_spanish_identity(normalised)[source]

Return whether normalised is a valid Spanish NIF, NIE, or CIF.

Return type:

bool | None

Parameters:

normalised (str)

admits_nif_iva(normalised)[source]

Return whether normalised matches its Member State’s NIF-IVA format.

Return type:

bool | None

Parameters:

normalised (str)

bind_tax_identity_admission(admission)[source]

Publish admission process-wide for the scope, restoring the previous gate after.

None suspends the gate for the scope, leaving redaction on its fallback.

Process-wide rather than context-local: log records are redacted on worker threads and fresh event-loop contexts that never inherit a context variable.

Return type:

Generator[TaxIdentityAdmission | None]

Parameters:

admission (TaxIdentityAdmission | None)

tax_identity_admission()[source]

Return the host-bound admission gate, or None when none is bound.

Return type:

TaxIdentityAdmission | None