Skip to content

Commit b0ddc5a

Browse files
author
Steve Canny
committed
oxml: add CT_Body.sectPr
Remove now-dead CT_Body._sentinel_sectPr.
1 parent f4e6257 commit b0ddc5a

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

docx/oxml/parts/document.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<w:document>.
66
"""
77

8-
from ..ns import qn
98
from ..table import CT_Tbl
109
from ..xmlchemy import BaseOxmlElement, ZeroOrOne, ZeroOrMore
1110

@@ -32,6 +31,7 @@ class CT_Body(BaseOxmlElement):
3231
"""
3332
p = ZeroOrMore('w:p', successors=('w:sectPr',))
3433
tbl = ZeroOrMore('w:tbl', successors=('w:sectPr',))
34+
sectPr = ZeroOrOne('w:sectPr', successors=())
3535

3636
def add_section_break(self):
3737
"""
@@ -57,7 +57,7 @@ def clear_content(self):
5757
Remove all content child elements from this <w:body> element. Leave
5858
the <w:sectPr> element if it is present.
5959
"""
60-
if self._sentinel_sectPr is not None:
60+
if self.sectPr is not None:
6161
content_elms = self[:-1]
6262
else:
6363
content_elms = self[:]
@@ -69,25 +69,9 @@ def _append_blocklevelelt(self, block_level_elt):
6969
Return *block_level_elt* after appending it to end of
7070
EG_BlockLevelElts sequence.
7171
"""
72-
sentinel_sectPr = self._sentinel_sectPr
73-
if sentinel_sectPr is not None:
74-
sentinel_sectPr.addprevious(block_level_elt)
72+
sectPr = self.sectPr
73+
if sectPr is not None:
74+
sectPr.addprevious(block_level_elt)
7575
else:
7676
self.append(block_level_elt)
7777
return block_level_elt
78-
79-
@property
80-
def _sentinel_sectPr(self):
81-
"""
82-
Return ``<w:sectPr>`` element appearing as last child, or None if not
83-
found. Note that the ``<w:sectPr>`` element can also occur earlier in
84-
the body; here we're only interested in one occuring as the last
85-
child.
86-
"""
87-
if len(self) == 0:
88-
sentinel_sectPr = None
89-
elif self[-1].tag != qn('w:sectPr'):
90-
sentinel_sectPr = None
91-
else:
92-
sentinel_sectPr = self[-1]
93-
return sentinel_sectPr

0 commit comments

Comments
 (0)