Merge "Patch writexml for non standard XML DOM implementations"

This commit is contained in:
Jenkins 2014-06-25 18:13:07 +00:00 committed by Gerrit Code Review
commit fe693157cc

View File

@ -22,6 +22,7 @@ import hashlib
import yaml
import json
import xml.etree.ElementTree as XML
import xml
from xml.dom import minidom
import jenkins
import re
@ -37,9 +38,9 @@ logger = logging.getLogger(__name__)
MAGIC_MANAGE_STRING = "<!-- Managed by Jenkins Job Builder -->"
# Python <= 2.7.3's minidom toprettyxml produces broken output by adding
# extraneous whitespace around data. This patches the broken implementation
# with one taken from Python > 2.7.3.
# Python 2.6's minidom toprettyxml produces broken output by adding extraneous
# whitespace around data. This patches the broken implementation with one taken
# from 2.7
def writexml(self, writer, indent="", addindent="", newl=""):
# indent = current indentation
# addindent = indentation to add to higher levels
@ -68,7 +69,9 @@ def writexml(self, writer, indent="", addindent="", newl=""):
else:
writer.write("/>%s" % (newl))
if sys.version_info[:3] <= (2, 7, 3):
# PyXML xml.__name__ is _xmlplus. Check that if we don't have the default
# system version of the minidom, then patch the writexml method
if sys.version_info[:3] < (2, 7, 0) or xml.__name__ != 'xml':
minidom.Element.writexml = writexml