Source code for cadrumo.application.modelo._registry_resources
"""Registry-backed work-unit guards shared by modelo application actions.Modelo application services access the packaged registry through onegeneration-pinned indexed operation. This module owns work-unit revision andperiod guards.The revision and period guards are create-work-unit checks: they reject userinput that names a modelo revision or filing period the committed registry doesnot declare, before a work unit records a law-determined registry identity.See Also: :mod:`cadrumo.core.resources`: Owns the packaged resource registry and bundled-path resolution. :class:`cadrumo.domain.calculations.registry.authority.PinnedAuthorityOperation`: Loads and validates modelo definitions, then serves registry snapshots. :mod:`cadrumo.application.modelo._registry_helpers`: Owns import/amendment registry checks."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfrom...core.periodimportPeriodfrom...domain.calculations.registry.idsimportRevisionIdfrom...domain.modelos.errorsimportModeloErrorifTYPE_CHECKING:from...domain.calculations.registry.authorityimportPinnedAuthorityOperation
[docs]defreject_unknown_revision(*,modelo:str,revision_id:RevisionId,operation:PinnedAuthorityOperation,)->None:"""Refuse a work-unit create that names an undeclared revision id. The central :class:`ValidatedRegistryAuthority` first resolves the modelo definition. If the modelo exists but ``revision_id`` is absent from its revision map, this raises :class:`ModeloError` with the available revision ids. """from...domain.calculations.registry.errorsimportRegistrySnapshotErrortry:revisions=operation.modelo_directory(modelo).revisionsexcept(RegistrySnapshotError,ValueError)asexc:raiseModeloError(str(exc))fromexcifany(revision.id==revision_idforrevisioninrevisions):returnavailable=", ".join(sorted(str(revision.id)forrevisioninrevisions))raiseModeloError(f"revision_id {revision_id!r} is not declared on modelo {modelo!r}. Available revisions: {available}",)
[docs]defreject_unknown_period_for_revision(*,modelo:str,revision_id:RevisionId,period:Period,operation:PinnedAuthorityOperation,)->None:"""Refuse a work-unit create whose :class:`Period` is absent from the revision schedules. The guard inspects the named revision's filing schedules and compares the caller's ``period.registry_token`` to the declared period tokens. A revision with no declared schedule is accepted here; a missing revision is also left alone because :func:`reject_unknown_revision` owns that refusal. """from...domain.calculations.registry.errorsimportRegistrySnapshotErrorfrom...domain.calculations.registry.period_selector_matchimportselector_period_matches_requesttry:revision=operation.revision(modelo,str(revision_id))except(RegistrySnapshotError,ValueError)asexc:raiseModeloError(str(exc))fromexcdeclared:set[str]=set()forscheduleinrevision.filing_schedules:declared.update(schedule.periods)ifnotdeclaredorany(selector_period_matches_request(token,period.registry_token)fortokenindeclared):returnavailable=", ".join(sorted(declared))raiseModeloError(f"period {period.registry_token!r} is not declared on modelo {modelo!r} "f"revision {revision_id!r}. Available periods: {available}",)