Source code for cadrumo.application.modelo.reconciliation_parsing
"""Neutral parser boundary for modelo reconciliation evidence.Application reconciliation consumes parsed filing observations. Inbound adaptersown PDF extraction and bind one parser implementation at the executable host."""from__future__importannotationsfromcollections.abcimportGenerator,SequencefromcontextlibimportcontextmanagerfromcontextvarsimportContextVarfrompathlibimportPathfromtypingimportTYPE_CHECKING,Protocolfrom...core.errors.hierarchyimportInternalInvariantErrorifTYPE_CHECKING:from...core.periodimportPeriodfrom...domain.calculations.registry.schemaimportRegistrySnapshotfrom...domain.justificante.schemaimportJustificante
[docs]classReconciliationCasillaObservation(Protocol):"""The numeric-or-text casilla facts reconciliation reads from a PDF."""@propertydefcasilla_id(self)->str:"""Return the canonical casilla identifier."""...@propertydefprinted_value(self)->object:"""Return the parsed printed value, if any."""...@propertydefsource_page(self)->int:"""Return the one-based page carrying the observation."""...@propertydefextraction_confidence(self)->float:"""Return the parser's bounded extraction confidence."""...
[docs]classReconciliationDeclaracionObservation(Protocol):"""Minimal filed-declaración observation consumed by reconciliation."""@propertydefmodelo(self)->str:"""Return the observed modelo code."""...@propertydefperiod(self)->Period:"""Return the observed filing period."""...@propertydefejercicio(self)->str:"""Return the printed filing year."""...@propertydeftax_id(self)->str:"""Return the printed taxpayer identifier."""...@propertydefvalues(self)->Sequence[ReconciliationCasillaObservation]:"""Return the parsed casilla observations."""...@propertydefextraction_profile_id(self)->str:"""Return the registry extraction-profile identifier."""...@propertydefextraction_profile_provisional(self)->bool:"""Return whether the selected extraction profile is provisional."""...
[docs]classReconciliationEvidenceParserPort(Protocol):"""Inbound parsing capabilities required by reconciliation."""
[docs]defparse_justificante(self,source:Path)->Justificante:"""Parse one local justificante PDF."""...
[docs]defparse_justificante_bytes(self,source:bytes)->Justificante:"""Parse one in-memory justificante PDF."""...
[docs]defparse_declaracion(self,source:Path,*,modelo:str,filing_year:int,period:str,)->ReconciliationDeclaracionObservation:"""Parse one local declaración PDF against its addressed work unit."""...
[docs]defparse_declaracion_bytes(self,source:bytes,*,modelo:str,filing_year:int,period:str,registry_snapshot:RegistrySnapshot,)->ReconciliationDeclaracionObservation:"""Parse decrypted declaration bytes against a validated snapshot. Core types: :class:`~cadrumo.domain.calculations.registry.schema.RegistrySnapshot`. """...
[docs]@contextmanagerdefbind_reconciliation_evidence_parser(parser:ReconciliationEvidenceParserPort,)->Generator[ReconciliationEvidenceParserPort]:"""Bind the inbound parser implementation for one host lifetime."""token=_BOUND_RECONCILIATION_EVIDENCE_PARSER.set(parser)try:yieldparserfinally:_BOUND_RECONCILIATION_EVIDENCE_PARSER.reset(token)
[docs]defreconciliation_evidence_parser()->ReconciliationEvidenceParserPort:"""Resolve the explicitly composed reconciliation parser."""try:return_BOUND_RECONCILIATION_EVIDENCE_PARSER.get()exceptLookupErroraserror:raiseInternalInvariantError("reconciliation evidence parsing has not been composed")fromerror