MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / __getitem__

Method __getitem__

docx/scripts/document.py:680–711  ·  view source on GitHub ↗

Get or create a DocxXMLEditor for the specified XML file. Enables lazy-loaded editors with bracket notation: node = doc["word/document.xml"].get_node(tag="w:p", line_number=42) Args: xml_path: Relative path to XML file (e.g., "word/document.xml", "w

(self, xml_path: str)

Source from the content-addressed store, hash-verified

678 self._add_author_to_people(author)
679
680 def __getitem__(self, xml_path: str) -> DocxXMLEditor:
681 """
682 Get or create a DocxXMLEditor for the specified XML file.
683
684 Enables lazy-loaded editors with bracket notation:
685 node = doc["word/document.xml"].get_node(tag="w:p", line_number=42)
686
687 Args:
688 xml_path: Relative path to XML file (e.g., "word/document.xml", "word/comments.xml")
689
690 Returns:
691 DocxXMLEditor instance for the specified file
692
693 Raises:
694 ValueError: If the file does not exist
695
696 Example:
697 # Get node from document.xml
698 node = doc["word/document.xml"].get_node(tag="w:del", attrs={"w:id": "1"})
699
700 # Get node from comments.xml
701 comment = doc["word/comments.xml"].get_node(tag="w:comment", attrs={"w:id": "0"})
702 """
703 if xml_path not in self._editors:
704 file_path = self.unpacked_path / xml_path
705 if not file_path.exists():
706 raise ValueError(f"XML file not found: {xml_path}")
707 # Use DocxXMLEditor with RSID, author, and initials for all editors
708 self._editors[xml_path] = DocxXMLEditor(
709 file_path, rsid=self.rsid, author=self.author, initials=self.initials
710 )
711 return self._editors[xml_path]
712
713 def add_comment(self, start, end, text: str) -> int:
714 """

Callers

nothing calls this directly

Calls 1

DocxXMLEditorClass · 0.85

Tested by

no test coverage detected