File: in.diff

package info (click to toggle)
cdiff 1.0-1.1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 472 kB
  • sloc: python: 1,256; sh: 74; makefile: 52
file content (53 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# HG changeset patch
# User Dan Kenigsberg <danken@redhat.com>
# Date 1317492169 -10800
# Node ID a9a87f0e7c509ec6768379c08a0cf56f43d71b4a
# Parent  b0ef6a5a6dccab0089d287bf6b9bcb8132bdbd0d
xml.dom.minidom toprettyxml: omit whitespace for Text nodes

http://bugs.python.org/issue4147

This patch was very lightly tested, but I think it is nicer than the former one,
as Text.writexml() should better know not to wrap its data with whitespace.
Ever.

diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/test/test_minidom.py
--- a/Lib/test/test_minidom.py	Fri Sep 30 08:46:25 2011 +0300
+++ b/Lib/test/test_minidom.py	Sat Oct 01 21:02:49 2011 +0300
@@ -467,6 +467,13 @@
         dom.unlink()
         self.confirm(domstr == str.replace("\n", "\r\n"))
 
+    def testPrettyTextNode(self):
+        str = '<A>B</A>'
+        dom = parseString(str)
+        dom2 = parseString(dom.toprettyxml())
+        self.confirm(dom.childNodes[0].childNodes[0].toxml()==
+                     dom2.childNodes[0].childNodes[0].toxml())
+
     def testProcessingInstruction(self):
         dom = parseString('<e><?mypi \t\n data \t\n ?></e>')
         pi = dom.documentElement.firstChild
diff -r b0ef6a5a6dcc -r a9a87f0e7c50 Lib/xml/dom/minidom.py
--- a/Lib/xml/dom/minidom.py	Fri Sep 30 08:46:25 2011 +0300
+++ b/Lib/xml/dom/minidom.py	Sat Oct 01 21:02:49 2011 +0300
@@ -836,7 +836,9 @@
             _write_data(writer, attrs[a_name].value)
             writer.write("\"")
         if self.childNodes:
-            writer.write(">%s"%(newl))
+            writer.write(">")
+            if self.childNodes[0].nodeType != Node.TEXT_NODE:
+                writer.write(newl)
             for node in self.childNodes:
                 node.writexml(writer,indent+addindent,addindent,newl)
             writer.write("%s</%s>%s" % (indent,self.tagName,newl))
@@ -1061,7 +1063,7 @@
         return newText
 
     def writexml(self, writer, indent="", addindent="", newl=""):
-        _write_data(writer, "%s%s%s"%(indent, self.data, newl))
+        _write_data(writer, self.data)
 
     # DOM Level 3 (WD 9 April 2002)