Skip to content

Commit 9c0544a

Browse files
committed
add v1 HeaderPart
1 parent 4b37134 commit 9c0544a

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
_scratch/
77
Session.vim
88
/.tox/
9+
tags

docx/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from docx.parts.image import ImagePart
1616
from docx.parts.numbering import NumberingPart
1717
from docx.parts.styles import StylesPart
18+
from docx.parts.header import HeaderPart
1819

1920

2021
def part_class_selector(content_type, reltype):
@@ -28,6 +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
32+
PartFactory.part_type_for[CT.WML_HEADER] = HeaderPart
33+
# PartFactory.part_type_for[CT.WML_FOOTER] = FooterPart
3134

3235
del (
3336
CT, CorePropertiesPart, DocumentPart, NumberingPart, PartFactory,

docx/parts/header.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from ..opc.part import XmlPart
2+
3+
4+
class HeaderPart(XmlPart):
5+
pass

tests/test_header.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# import pytest
2+
from unitutil.file import absjoin, test_file_dir
3+
from docx.api import Document
4+
from docx.opc.constants import CONTENT_TYPE as CT
5+
from docx.parts.header import HeaderPart
6+
7+
8+
dir_pkg_path = absjoin(test_file_dir, 'expanded_docx')
9+
10+
11+
class DescribeHeader(object):
12+
def it_loads_header_as_header_part(self):
13+
document = Document(dir_pkg_path)
14+
for rel_id, part in document.part.related_parts.items():
15+
if part.content_type == CT.WML_HEADER:
16+
assert isinstance(part, HeaderPart)

0 commit comments

Comments
 (0)