File tree Expand file tree Collapse file tree 7 files changed +27
-24
lines changed
Expand file tree Collapse file tree 7 files changed +27
-24
lines changed Original file line number Diff line number Diff line change 99
1010from lxml import etree
1111
12- from .ns import nsmap
12+ from .ns import NamespacePrefixedTag , nsmap
1313
1414
1515# configure XML parser
@@ -40,6 +40,21 @@ def register_custom_element_class(tag, cls):
4040 namespace [tagroot ] = cls
4141
4242
43+ def OxmlElement (nsptag_str , attrs = None , nsmap = None ):
44+ """
45+ Return a 'loose' lxml element having the tag specified by *nsptag_str*.
46+ *nsptag_str* must contain the standard namespace prefix, e.g. 'a:tbl'.
47+ The resulting element is an instance of the custom element class for this
48+ tag name if one is defined. A dictionary of attribute values may be
49+ provided as *attrs*; they are set if present.
50+ """
51+ nsptag = NamespacePrefixedTag (nsptag_str )
52+ _nsmap = nsptag .nsmap if nsmap is None else nsmap
53+ return oxml_parser .makeelement (
54+ nsptag .clark_name , attrib = attrs , nsmap = _nsmap
55+ )
56+
57+
4358# ===========================================================================
4459# custom element class mappings
4560# ===========================================================================
Original file line number Diff line number Diff line change 44Custom element classes related to the numbering part
55"""
66
7- from ..shared import CT_DecimalNumber , OxmlBaseElement , OxmlElement
7+ from .. import OxmlElement
8+ from ..shared import CT_DecimalNumber , OxmlBaseElement
89from ..ns import nsmap , qn
910
1011
Original file line number Diff line number Diff line change 44Custom element classes for shape-related elements like ``<w:inline>``
55"""
66
7- from .shared import OxmlBaseElement , OxmlElement
7+ from . import OxmlElement
8+ from .shared import OxmlBaseElement
89from ..shared import Emu
910from .ns import nsmap , nspfxmap , qn
1011
Original file line number Diff line number Diff line change 1010
1111import re
1212
13- from . import oxml_parser
13+ from . import OxmlElement
1414from .exceptions import ValidationError
15- from .ns import NamespacePrefixedTag , qn
15+ from .ns import qn
1616
1717
1818# ===========================================================================
1919# utility functions
2020# ===========================================================================
2121
2222
23- def OxmlElement (nsptag_str , attrs = None , nsmap = None ):
24- """
25- Return a 'loose' lxml element having the tag specified by *nsptag_str*.
26- *nsptag_str* must contain the standard namespace prefix, e.g. 'a:tbl'.
27- The resulting element is an instance of the custom element class for this
28- tag name if one is defined. A dictionary of attribute values may be
29- provided as *attrs*; they are set if present.
30- """
31- nsptag = NamespacePrefixedTag (nsptag_str )
32- _nsmap = nsptag .nsmap if nsmap is None else nsmap
33- return oxml_parser .makeelement (
34- nsptag .clark_name , attrib = attrs , nsmap = _nsmap
35- )
36-
37-
3823def serialize_for_reading (element ):
3924 """
4025 Serialize *element* to human-readable XML suitable for tests. No XML
Original file line number Diff line number Diff line change 66
77from __future__ import absolute_import , print_function , unicode_literals
88
9+ from . import OxmlElement
910from .exceptions import ValidationError
1011from .ns import qn
11- from .shared import CT_String , OxmlBaseElement , OxmlElement
12+ from .shared import CT_String , OxmlBaseElement
1213from .text import CT_P
1314
1415
Original file line number Diff line number Diff line change 55(CT_R).
66"""
77
8- from . import parse_xml
8+ from . import parse_xml , OxmlElement
99from ..enum .text import WD_UNDERLINE
1010from .ns import nsdecls , qn
1111from .parts .numbering import CT_NumPr
12- from .shared import CT_String , OxmlBaseElement , OxmlElement
12+ from .shared import CT_String , OxmlBaseElement
1313
1414
1515class CT_Br (OxmlBaseElement ):
Original file line number Diff line number Diff line change @@ -110,6 +110,6 @@ def image_partname(n):
110110 return PackURI ('/word/media/image%d.%s' % (n , ext ))
111111 used_numbers = [image_part .partname .idx for image_part in self ]
112112 for n in range (1 , len (self )+ 1 ):
113- if not n in used_numbers :
113+ if n not in used_numbers :
114114 return image_partname (n )
115115 return image_partname (len (self )+ 1 )
You can’t perform that action at this time.
0 commit comments