Skip to content

Commit f64f87b

Browse files
author
Steve Canny
committed
oxml: extract nsmap to docx.oxml.ns
1 parent fc965c2 commit f64f87b

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

docx/oxml/ns.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# encoding: utf-8
2+
3+
"""
4+
Namespace-related objects.
5+
"""
6+
7+
from __future__ import absolute_import, print_function, unicode_literals
8+
9+
10+
nsmap = {
11+
'a': ('http://schemas.openxmlformats.org/drawingml/2006/main'),
12+
'c': ('http://schemas.openxmlformats.org/drawingml/2006/chart'),
13+
'dgm': ('http://schemas.openxmlformats.org/drawingml/2006/diagram'),
14+
'pic': ('http://schemas.openxmlformats.org/drawingml/2006/picture'),
15+
'r': ('http://schemas.openxmlformats.org/officeDocument/2006/relations'
16+
'hips'),
17+
'w': ('http://schemas.openxmlformats.org/wordprocessingml/2006/main'),
18+
'wp': ('http://schemas.openxmlformats.org/drawingml/2006/wordprocessing'
19+
'Drawing'),
20+
'xml': ('http://www.w3.org/XML/1998/namespace')
21+
}

docx/oxml/parts/numbering.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
Custom element classes related to the numbering part
55
"""
66

7-
from docx.oxml.shared import (
8-
CT_DecimalNumber, nsmap, OxmlBaseElement, OxmlElement, qn
9-
)
7+
from ..shared import CT_DecimalNumber, OxmlBaseElement, OxmlElement, qn
8+
from ..ns import nsmap
109

1110

1211
class CT_Num(OxmlBaseElement):

docx/oxml/parts/styles.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
Custom element classes related to the styles part
55
"""
66

7-
from docx.oxml.shared import nsmap, OxmlBaseElement, qn
7+
from ..shared import OxmlBaseElement, qn
8+
from ..ns import nsmap
89

910

1011
class CT_Style(OxmlBaseElement):

docx/oxml/shape.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
Custom element classes for shape-related elements like ``<w:inline>``
55
"""
66

7-
from docx.oxml.shared import (
8-
nsmap, nspfxmap, OxmlBaseElement, OxmlElement, qn
9-
)
10-
from docx.shared import Emu
7+
from .shared import nspfxmap, OxmlBaseElement, OxmlElement, qn
8+
from ..shared import Emu
9+
from .ns import nsmap
1110

1211

1312
class CT_Blip(OxmlBaseElement):

docx/oxml/shared.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,9 @@
99
import re
1010

1111
from .exceptions import ValidationError
12+
from .ns import nsmap
1213

1314

14-
nsmap = {
15-
'a': ('http://schemas.openxmlformats.org/drawingml/2006/main'),
16-
'c': ('http://schemas.openxmlformats.org/drawingml/2006/chart'),
17-
'dgm': ('http://schemas.openxmlformats.org/drawingml/2006/diagram'),
18-
'pic': ('http://schemas.openxmlformats.org/drawingml/2006/picture'),
19-
'r': ('http://schemas.openxmlformats.org/officeDocument/2006/relations'
20-
'hips'),
21-
'w': ('http://schemas.openxmlformats.org/wordprocessingml/2006/main'),
22-
'wp': ('http://schemas.openxmlformats.org/drawingml/2006/wordprocessing'
23-
'Drawing'),
24-
'xml': ('http://www.w3.org/XML/1998/namespace')
25-
}
26-
2715
# configure XML parser
2816
element_class_lookup = etree.ElementNamespaceClassLookup()
2917
oxml_parser = etree.XMLParser(remove_blank_text=True)

docx/parts/document.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
from ..opc.constants import RELATIONSHIP_TYPE as RT
1212
from ..opc.oxml import serialize_part_xml
1313
from ..opc.package import Part
14-
from ..oxml.shared import nsmap, oxml_fromstring
14+
from ..oxml.ns import nsmap
15+
from ..oxml.shared import oxml_fromstring
1516
from ..shape import InlineShape
1617
from ..shared import lazyproperty, Parented
1718
from ..table import Table

docx/shape.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
absolute_import, division, print_function, unicode_literals
1010
)
1111

12-
from docx.enum.shape import WD_INLINE_SHAPE
13-
from docx.oxml.shape import CT_Inline, CT_Picture
14-
from docx.oxml.shared import nsmap
12+
from .enum.shape import WD_INLINE_SHAPE
13+
from .oxml.shape import CT_Inline, CT_Picture
14+
from .oxml.ns import nsmap
1515

1616

1717
class InlineShape(object):

0 commit comments

Comments
 (0)