diff --git a/packtools/sps/models/accessibility_data.py b/packtools/sps/models/accessibility_data.py index 6f15fa016..1e21b1835 100644 --- a/packtools/sps/models/accessibility_data.py +++ b/packtools/sps/models/accessibility_data.py @@ -40,7 +40,7 @@ def __init__(self, node): def xref_sec_rid(self): try: return self.node.xpath('xref[@ref-type="sec"]')[0].get("rid") - except: + except Exception: return None def _get_xml_string(self): @@ -50,7 +50,7 @@ def _get_xml_string(self): xml_str = etree.tostring(self.node, encoding='unicode') # Limita a 200 caracteres para não sobrecarregar logs return xml_str[:200] + "..." if len(xml_str) > 200 else xml_str - except: + except Exception: return f"<{self.node.tag}...>" @property @@ -68,7 +68,7 @@ def alt_text(self): "alt_text_content_type": content_type, "alt_text_xml": xml } - except: + except Exception: return None @property @@ -87,9 +87,17 @@ def long_desc(self): "long_desc_content_type": content_type, "long_desc_xml": xml } - except: + except Exception: return None + @property + def long_desc_count(self): + """Conta quantos elementos existem como filhos diretos.""" + try: + return len(self.node.findall("long-desc")) + except (AttributeError, TypeError): + return 0 + @property def parent_info(self): """ @@ -98,8 +106,8 @@ def parent_info(self): """ parent = self.node.getparent() if parent is not None: - label = parent.findtext(".//label") - caption_title = parent.findtext(".//caption/title") + label = parent.findtext("./label") + caption_title = parent.findtext("./caption/title") return { "parent_tag": parent.tag, "parent_label": label, @@ -127,6 +135,7 @@ def data(self): "tag": self.node.tag, "xref_sec_rid": self.xref_sec_rid, "xml": self._get_xml_string(), # Para mensagens de erro mais claras + "long_desc_count": self.long_desc_count, } d.update(self.long_desc or {}) d.update(self.alt_text or {}) diff --git a/packtools/sps/validation/accessibility_data.py b/packtools/sps/validation/accessibility_data.py index 55bcdefc8..8dd0ed19a 100644 --- a/packtools/sps/validation/accessibility_data.py +++ b/packtools/sps/validation/accessibility_data.py @@ -26,10 +26,14 @@ def validate(self): Executes all defined validations. """ yield from self.validate_alt_text() - yield from self.validate_alt_text_media_restriction() # NOVA - yield from self.validate_alt_text_not_duplicate_label_caption() # NOVA - yield from self.validate_decorative_figure_alt_text() # NOVA + yield from self.validate_alt_text_media_restriction() + yield from self.validate_alt_text_not_duplicate_label_caption() + yield from self.validate_decorative_figure_alt_text() yield from self.validate_long_desc() + yield from self.validate_long_desc_media_restriction() + yield from self.validate_long_desc_not_duplicate_label_caption() + yield from self.validate_long_desc_occurrence() + yield from self.validate_long_desc_incompatible_with_null_alt() yield self.validate_transcript() yield self.validate_speaker_and_speech() yield self.validate_accessibility_data_structure() @@ -115,12 +119,12 @@ def validate_alt_text(self): def validate_alt_text_media_restriction(self): """ - NOVA VALIDAÇÃO: Valida que em e só ocorre para vídeo/áudio. + Validates that in and only occurs for video/audio. - Regra SPS 1.10: - "Em e o elemento só deverá ocorrer quando - o formato do objeto for vídeo ou áudio, tendo os seguintes atributos para - @mime-type e @mime-subtype: video/mp4, audio/mp3" + SPS 1.10 rule: + "In and , the element should only occur when + the object format is video or audio, with the following attributes for + @mime-type and @mime-subtype: video/mp4, audio/mp3" """ tag = self.data.get("tag") @@ -186,11 +190,11 @@ def validate_alt_text_media_restriction(self): def validate_alt_text_not_duplicate_label_caption(self): """ - NOVA VALIDAÇÃO: Valida que não copia o conteúdo de