Source code for cadrumo.application.modelo.calculation_repository
"""Explicit lifetime binding for Modelo calculation-revision persistence."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.modelos.protocolsimportCalculationRevisionCatalogueRepositoryProtocol
[docs]classCalculationRevisionCatalogueRepositoryFactory(Protocol):"""Construct the calculation-revision repository port for one bucket."""def__call__(self,*,bucket_id:str)->CalculationRevisionCatalogueRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_calculation_revision_catalogue_repository_factory(factory:CalculationRevisionCatalogueRepositoryFactory,)->Generator[CalculationRevisionCatalogueRepositoryFactory]:"""Bind one outward-composed calculation-revision repository factory."""token=_BOUND_CALCULATION_REVISION_CATALOGUE_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_CALCULATION_REVISION_CATALOGUE_REPOSITORY_FACTORY.reset(token)
[docs]defcalculation_revision_catalogue_repository(*,bucket_id:str,)->CalculationRevisionCatalogueRepositoryProtocol:"""Resolve the explicitly composed calculation repository for ``bucket_id``."""try:factory=_BOUND_CALCULATION_REVISION_CATALOGUE_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("calculation-revision catalogue persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)