MCPcopy Index your code
hub / github.com/python-openxml/python-docx / CT_Numbering

Class CT_Numbering

src/docx/oxml/numbering.py:78–109  ·  view source on GitHub ↗

`` `` element, the root element of a numbering part, i.e. numbering.xml.

Source from the content-addressed store, hash-verified

76
77
78class CT_Numbering(BaseOxmlElement):
79 """``<w:numbering>`` element, the root element of a numbering part, i.e.
80 numbering.xml."""
81
82 num = ZeroOrMore("w:num", successors=("w:numIdMacAtCleanup",))
83
84 def add_num(self, abstractNum_id):
85 """Return a newly added CT_Num (<w:num>) element referencing the abstract
86 numbering definition identified by `abstractNum_id`."""
87 next_num_id = self._next_numId
88 num = CT_Num.new(next_num_id, abstractNum_id)
89 return self._insert_num(num)
90
91 def num_having_numId(self, numId):
92 """Return the ``<w:num>`` child element having ``numId`` attribute matching
93 `numId`."""
94 xpath = './w:num[@w:numId="%d"]' % numId
95 try:
96 return self.xpath(xpath)[0]
97 except IndexError:
98 raise KeyError("no <w:num> element with numId %d" % numId)
99
100 @property
101 def _next_numId(self):
102 """The first ``numId`` unused by a ``<w:num>`` element, starting at 1 and
103 filling any gaps in numbering between existing ``<w:num>`` elements."""
104 numId_strs = self.xpath("./w:num/@w:numId")
105 num_ids = [int(numId_str) for numId_str in numId_strs]
106 for num in range(1, len(num_ids) + 2):
107 if num not in num_ids:
108 break
109 return num

Callers

nothing calls this directly

Calls 1

ZeroOrMoreClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…