Skip to content
21 changes: 15 additions & 6 deletions packtools/sps/models/accessibility_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano trocar except por except Exception dá igual. Qual é a motivação para ignorar a exceção? Faz sentido ignorar todas as exceções? Faz sentido ignorar algumas exceções? É esta avaliação que tem que ser feita. E coloque comentário a motivação.

return None

def _get_xml_string(self):
Expand All @@ -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
Expand All @@ -68,7 +68,7 @@ def alt_text(self):
"alt_text_content_type": content_type,
"alt_text_xml": xml
}
except:
except Exception:
return None

@property
Expand All @@ -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 <long-desc> existem como filhos diretos."""
try:
return len(self.node.findall("long-desc"))
except (AttributeError, TypeError):
return 0

@property
def parent_info(self):
"""
Expand All @@ -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,
Expand Down Expand Up @@ -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 {})
Expand Down
Loading