Skip to content

Commit 67ae998

Browse files
committed
cleanup
1 parent 3cf0802 commit 67ae998

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

docx/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
# register custom Part classes with opc package reader
99

1010
from docx.opc.constants import CONTENT_TYPE as CT, RELATIONSHIP_TYPE as RT
11-
from docx.opc.part import PartFactory, XmlPart
11+
from docx.opc.part import PartFactory
1212
from docx.opc.parts.coreprops import CorePropertiesPart
1313

1414
from docx.parts.document import DocumentPart
15+
from docx.parts.header import HeaderPart, FooterPart
1516
from docx.parts.image import ImagePart
1617
from docx.parts.numbering import NumberingPart
1718
from docx.parts.styles import StylesPart
@@ -28,8 +29,8 @@ def part_class_selector(content_type, reltype):
2829
PartFactory.part_type_for[CT.WML_DOCUMENT_MAIN] = DocumentPart
2930
PartFactory.part_type_for[CT.WML_NUMBERING] = NumberingPart
3031
PartFactory.part_type_for[CT.WML_STYLES] = StylesPart
31-
PartFactory.part_type_for[CT.WML_HEADER] = XmlPart
32-
PartFactory.part_type_for[CT.WML_FOOTER] = XmlPart
32+
PartFactory.part_type_for[CT.WML_HEADER] = HeaderPart
33+
PartFactory.part_type_for[CT.WML_FOOTER] = FooterPart
3334

3435
del (
3536
CT, CorePropertiesPart, DocumentPart, NumberingPart, PartFactory,

docx/oxml/section.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
from .xmlchemy import BaseOxmlElement, OptionalAttribute, ZeroOrOne
1414

1515

16-
class CT_HeaderReference(BaseOxmlElement):
17-
"""
18-
``<w:headerReference>``, the element for the header reference
19-
"""
20-
21-
2216
class CT_PageMar(BaseOxmlElement):
2317
"""
2418
``<w:pgMar>`` element, defining page margins.

docx/parts/header.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77

88

99
class HeaderPart(XmlPart):
10-
# COPYPASTA FROM DOCUMENT PART BELOW THIS POINT
11-
# TODO ABSTRACT?
12-
13-
# @lazyproperty
14-
# def inline_shapes(self):
15-
# """
16-
# The |InlineShapes| instance containing the inline shapes in the
17-
# document.
18-
# """
19-
# return InlineShapes(self._element.body, self)
10+
@property
11+
def _styles_part(self):
12+
"""
13+
Instance of |StylesPart| for this document. Creates an empty styles
14+
part if one is not present.
15+
"""
16+
# HACK
17+
# one styles to rule them all, maybe this is the way it's supposed to be?
18+
document = self.package.main_document_part
19+
try:
20+
return document.part_related_by(RT.STYLES)
21+
except KeyError:
22+
styles_part = StylesPart.default(self.package)
23+
document.relate_to(styles_part, RT.STYLES)
24+
return styles_part
2025

26+
# MOSTLY COPYPASTA FROM DOCUMENT PART BELOW THIS POINT
27+
# TODO ABSTRACT?
2128
@property
2229
def next_id(self):
2330
"""
@@ -90,23 +97,7 @@ def styles(self):
9097
"""
9198
return self._styles_part.styles
9299

93-
@property
94-
def _styles_part(self):
95-
"""
96-
Instance of |StylesPart| for this document. Creates an empty styles
97-
part if one is not present.
98-
"""
99-
# HACK
100-
# one styles to rule them all
101-
document = self.package.main_document_part
102-
try:
103-
return document.part_related_by(RT.STYLES)
104-
except KeyError:
105-
styles_part = StylesPart.default(self.package)
106-
document.relate_to(styles_part, RT.STYLES)
107-
return styles_part
108-
109100

110101
class FooterPart(HeaderPart):
111-
# identical to HeaderPart for now
102+
# identical to HeaderPart, ABSTRACT
112103
pass

0 commit comments

Comments
 (0)