Source code for cadrumo.application.modelo.justificante_repository
"""Explicit lifetime binding for justificante persistence."""from__future__importannotationsfromcollections.abcimportGeneratorfromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfromtypingimportProtocolfrom...core.errors.hierarchyimportInternalInvariantErrorfrom...domain.justificante.protocolsimportJustificanteRepositoryProtocol
[docs]classJustificanteRepositoryFactory(Protocol):"""Construct the justificante repository port for one profile bucket."""def__call__(self,*,bucket_id:str)->JustificanteRepositoryProtocol:"""Return the repository bound to ``bucket_id``."""...
[docs]@contextmanagerdefbind_justificante_repository_factory(factory:JustificanteRepositoryFactory,)->Generator[JustificanteRepositoryFactory]:"""Bind one outward-composed justificante repository factory."""token=_BOUND_JUSTIFICANTE_REPOSITORY_FACTORY.set(factory)try:yieldfactoryfinally:_BOUND_JUSTIFICANTE_REPOSITORY_FACTORY.reset(token)
[docs]defjustificante_repository(*,bucket_id:str)->JustificanteRepositoryProtocol:"""Resolve the explicitly composed justificante repository for ``bucket_id``."""try:factory=_BOUND_JUSTIFICANTE_REPOSITORY_FACTORY.get()exceptLookupErroraserror:raiseInternalInvariantError("justificante persistence has not been composed")fromerrorreturnfactory(bucket_id=bucket_id)