diff options
Diffstat (limited to 'deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py')
-rw-r--r-- | deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py index 5de848158d..0a945322b4 100644 --- a/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +++ b/deps/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py @@ -14,56 +14,52 @@ import xml.dom.minidom def _Replacement_write_data(writer, data, is_attrib=False): - """Writes datachars to writer.""" - data = data.replace("&", "&").replace("<", "<") - data = data.replace("\"", """).replace(">", ">") - if is_attrib: - data = data.replace( - "\r", "
").replace( - "\n", "
").replace( - "\t", "	") - writer.write(data) + """Writes datachars to writer.""" + data = data.replace("&", "&").replace("<", "<") + data = data.replace('"', """).replace(">", ">") + if is_attrib: + data = data.replace("\r", "
").replace("\n", "
").replace("\t", "	") + writer.write(data) def _Replacement_writexml(self, writer, indent="", addindent="", newl=""): - # indent = current indentation - # addindent = indentation to add to higher levels - # newl = newline string - writer.write(indent+"<" + self.tagName) + # indent = current indentation + # addindent = indentation to add to higher levels + # newl = newline string + writer.write(indent + "<" + self.tagName) - attrs = self._get_attributes() - a_names = attrs.keys() - a_names.sort() + attrs = self._get_attributes() + a_names = sorted(attrs.keys()) - for a_name in a_names: - writer.write(" %s=\"" % a_name) - _Replacement_write_data(writer, attrs[a_name].value, is_attrib=True) - writer.write("\"") - if self.childNodes: - writer.write(">%s" % newl) - for node in self.childNodes: - node.writexml(writer, indent + addindent, addindent, newl) - writer.write("%s</%s>%s" % (indent, self.tagName, newl)) - else: - writer.write("/>%s" % newl) + for a_name in a_names: + writer.write(' %s="' % a_name) + _Replacement_write_data(writer, attrs[a_name].value, is_attrib=True) + writer.write('"') + if self.childNodes: + writer.write(">%s" % newl) + for node in self.childNodes: + node.writexml(writer, indent + addindent, addindent, newl) + writer.write("%s</%s>%s" % (indent, self.tagName, newl)) + else: + writer.write("/>%s" % newl) class XmlFix(object): - """Object to manage temporary patching of xml.dom.minidom.""" + """Object to manage temporary patching of xml.dom.minidom.""" - def __init__(self): - # Preserve current xml.dom.minidom functions. - self.write_data = xml.dom.minidom._write_data - self.writexml = xml.dom.minidom.Element.writexml - # Inject replacement versions of a function and a method. - xml.dom.minidom._write_data = _Replacement_write_data - xml.dom.minidom.Element.writexml = _Replacement_writexml + def __init__(self): + # Preserve current xml.dom.minidom functions. + self.write_data = xml.dom.minidom._write_data + self.writexml = xml.dom.minidom.Element.writexml + # Inject replacement versions of a function and a method. + xml.dom.minidom._write_data = _Replacement_write_data + xml.dom.minidom.Element.writexml = _Replacement_writexml - def Cleanup(self): - if self.write_data: - xml.dom.minidom._write_data = self.write_data - xml.dom.minidom.Element.writexml = self.writexml - self.write_data = None + def Cleanup(self): + if self.write_data: + xml.dom.minidom._write_data = self.write_data + xml.dom.minidom.Element.writexml = self.writexml + self.write_data = None - def __del__(self): - self.Cleanup() + def __del__(self): + self.Cleanup() |