Skip to content

Commit 337734f

Browse files
author
Steve Canny
committed
oxml: extract nsdecls() to docx.oxml.ns
1 parent 5ec3ac1 commit 337734f

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

docx/oxml/ns.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ def nsuri(self):
7070
'http://foo/bar' in nsmap.
7171
"""
7272
return self._ns_uri
73+
74+
75+
def nsdecls(*prefixes):
76+
"""
77+
Return a string containing a namespace declaration for each of the
78+
namespace prefix strings, e.g. 'p', 'ct', passed as *prefixes*.
79+
"""
80+
return ' '.join(['xmlns:%s="%s"' % (pfx, nsmap[pfx]) for pfx in prefixes])

docx/oxml/shared.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@
2020
# ===========================================================================
2121

2222

23-
def nsdecls(*prefixes):
24-
return ' '.join(['xmlns:%s="%s"' % (pfx, nsmap[pfx]) for pfx in prefixes])
25-
26-
2723
def nspfxmap(*nspfxs):
2824
"""
2925
Return a dict containing the subset namespace prefix mappings specified by

docx/oxml/text.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
(CT_R).
66
"""
77

8-
from docx.enum.text import WD_UNDERLINE
9-
from docx.oxml.parts.numbering import CT_NumPr
10-
from docx.oxml.shared import (
11-
CT_String, nsdecls, OxmlBaseElement, OxmlElement, oxml_fromstring, qn
8+
from ..enum.text import WD_UNDERLINE
9+
from .ns import nsdecls
10+
from .parts.numbering import CT_NumPr
11+
from .shared import (
12+
CT_String, OxmlBaseElement, OxmlElement, oxml_fromstring, qn
1213
)
1314

1415

tests/unitdata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
from __future__ import absolute_import, print_function, unicode_literals
88

9-
from docx.oxml.shared import nsdecls, oxml_fromstring
9+
from docx.oxml.ns import nsdecls
10+
from docx.oxml.shared import oxml_fromstring
1011

1112

1213
class BaseBuilder(object):

0 commit comments

Comments
 (0)