Source code for cadrumo.adapters.inbound.notificacion.document_reader
"""Adapter that reads a fetched notification document in memory."""from__future__importannotationsfrom....application.live.notification_portsimportNotificationDocumentProtocolfrom....core.time.clockimporttoday_madridfrom....domain.notifications.sancionimportSancionLiquidacionfrom..pdf.page_text_extractionimportextract_pages_text_from_bytesfrom.errorsimportNotificacionParseError,SancionParseErrorfrom.sancionimportparse_sancion_document
[docs]classNotificationDocumentReader:"""Extract and parse one fetched notification document without storage."""
[docs]defread(self,document:NotificationDocumentProtocol,)->tuple[SancionLiquidacion|None,str|None]:"""Return the complete reading, or an explicit refusal reason."""try:pages=extract_pages_text_from_bytes(document.pdf_bytes,error_class=NotificacionParseError,pdf_label="an AEAT notification document",source_label="the fetched notification PDF",)exceptNotificacionParseErrorasexc:returnNone,f"{type(exc).__name__}: {exc}"[:512]try:return(parse_sancion_document("\n".join(pages),certificado_id=str(document.certificado_id),document_sha256=document.pdf_sha256,effective_date=today_madrid(),),None,)exceptSancionParseErrorasexc:returnNone,f"{type(exc).__name__}: {exc}"[:512]