| 1 | #!/usr/bin/env python3 |
| 2 | """Safety checks for opaque DrawingML fragments copied between PPTX parts.""" |
| 3 | |
| 4 | from __future__ import annotations |
| 5 | |
| 6 | from xml.etree import ElementTree as ET |
| 7 | |
| 8 | |
| 9 | RELATIONSHIPS_NS = ( |
| 10 | "http://schemas.openxmlformats.org/officeDocument/2006/relationships" |
| 11 | ) |
| 12 | _RELATIONSHIP_ATTRIBUTE_PREFIX = f"{{{RELATIONSHIPS_NS}}}" |
| 13 | |
| 14 | |
| 15 | def has_relationship_attributes(root: ET.Element) -> bool: |
| 16 | """Return whether a subtree contains any part-local relationship QName.""" |
| 17 | return any( |
| 18 | attribute.startswith(_RELATIONSHIP_ATTRIBUTE_PREFIX) |
| 19 | for element in root.iter() |
| 20 | for attribute in element.attrib |
| 21 | ) |
| 22 |