equal
deleted
inserted
replaced
30 import datetime |
30 import datetime |
31 from types import * |
31 from types import * |
32 from xml.dom import minidom |
32 from xml.dom import minidom |
33 from xml.sax.saxutils import unescape |
33 from xml.sax.saxutils import unescape |
34 from collections import OrderedDict |
34 from collections import OrderedDict |
|
35 from builtins import str as text |
|
36 |
35 from six.moves import xrange |
37 from six.moves import xrange |
36 from lxml import etree |
38 from lxml import etree |
37 |
39 |
38 |
40 |
39 def CreateNode(name): |
41 def CreateNode(name): |
48 node._attrs[new_name] = node._attrs.pop(old_name) |
50 node._attrs[new_name] = node._attrs.pop(old_name) |
49 |
51 |
50 |
52 |
51 def NodeSetAttr(node, name, value): |
53 def NodeSetAttr(node, name, value): |
52 attr = minidom.Attr(name) |
54 attr = minidom.Attr(name) |
53 text = minidom.Text() |
55 txt = minidom.Text() |
54 text.data = value |
56 txt.data = value |
55 attr.childNodes[0] = text |
57 attr.childNodes[0] = txt |
56 node._attrs[name] = attr |
58 node._attrs[name] = attr |
57 |
59 |
58 |
60 |
59 # Regular expression models for checking all kind of |
61 # Regular expression models for checking all kind of |
60 # string values defined in XML standard |
62 # string values defined in XML standard |
136 @return: data extracted as string |
138 @return: data extracted as string |
137 """ |
139 """ |
138 if not extract: |
140 if not extract: |
139 return attr |
141 return attr |
140 if len(attr.childNodes) == 1: |
142 if len(attr.childNodes) == 1: |
141 return unicode(unescape(attr.childNodes[0].data)) |
143 return text(unescape(attr.childNodes[0].data)) |
142 else: |
144 else: |
143 # content is a CDATA |
145 # content is a CDATA |
144 text = u'' |
146 txt = u'' |
145 for node in attr.childNodes: |
147 for node in attr.childNodes: |
146 if not (node.nodeName == "#text" and node.data.strip() == u''): |
148 if not (node.nodeName == "#text" and node.data.strip() == u''): |
147 text += unicode(unescape(node.data)) |
149 txt += text(unescape(node.data)) |
148 return text |
150 return text |
149 |
151 |
150 |
152 |
151 def GetNormalizedString(attr, extract=True): |
153 def GetNormalizedString(attr, extract=True): |
152 """ |
154 """ |