in.diff 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # HG changeset patch
  2. # User Dan Kenigsberg <danken@redhat.com>
  3. # Date 1317492169 -10800
  4. # Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a
  5. # Parent b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d
  6. xml.dom.minidom toprettyxml: omit whitespace for Text nodes
  7. http://bugs.python.org/issue4147
  8. This patch was very lightly tested, but I think it is nicer than the former one,
  9. as Text.writexml() should better know not to wrap its data with whitespace.
  10. Ever.
  11. diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py
  12. --- a/Lib/test/test_minidom.py Fri Sep 30 08:46:25 2011 +0300
  13. +++ b/Lib/test/test_minidom.py Sat Oct 01 21:02:49 2011 +0300
  14. @@ -467,6 +467,13 @@
  15. dom.unlink()
  16. self.confirm(domstr == str.replace("\n", "\r\n"))
  17. + def testPrettyTextNode(self):
  18. + str = '<A>B</A>'
  19. + dom = parseString(str)
  20. + dom2 = parseString(dom.toprettyxml())
  21. + self.confirm(dom.childNodes[0].childNodes[0].toxml()==
  22. + dom2.childNodes[0].childNodes[0].toxml())
  23. +
  24. def testProcessingInstruction(self):
  25. dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
  26. pi = dom.documentElement.firstChild
  27. diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py
  28. --- a/Lib/xml/dom/minidom.py Fri Sep 30 08:46:25 2011 +0300
  29. +++ b/Lib/xml/dom/minidom.py Sat Oct 01 21:02:49 2011 +0300
  30. @@ -836,7 +836,9 @@
  31. _write_data(writer, attrs[a_name].value)
  32. writer.write("\"")
  33. if self.childNodes:
  34. - writer.write(">%s"%(newl))
  35. + writer.write(">")
  36. + if self.childNodes[0].nodeType != Node.TEXT_NODE:
  37. + writer.write(newl)
  38. for node in self.childNodes:
  39. node.writexml(writer,indent+addindent,addindent,newl)
  40. writer.write("%s</%s>%s" % (indent,self.tagName,newl))
  41. @@ -1061,7 +1063,7 @@
  42. return newText
  43. def writexml(self, writer, indent="", addindent="", newl=""):
  44. - _write_data(writer, "%s%s%s"%(indent, self.data, newl))
  45. + _write_data(writer, self.data)
  46. # DOM Level 3 (WD 9 April 2002)