]> git.sesse.net Git - xml-template/commitdiff
Add Python 3 support.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Aug 2017 22:09:35 +0000 (00:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 17 Aug 2017 22:09:35 +0000 (00:09 +0200)
Patch by Kristian Klette.

13 files changed:
python/attribute-empty.py
python/attribute.py
python/attribute2.py
python/attribute3.py
python/clone.py
python/include.py
python/namespace.py
python/namespace2.py
python/passthru.py
python/simple.py
python/structure.py
python/xmltemplate.py
tests/test.sh

index fed55b5f6513e0fa498749c1491f38738bf4cf66..99a8cbc3b22fae303bb5ef8eda8866ab2500fb69 100644 (file)
@@ -5,4 +5,4 @@ doc = xmltemplate.process_file("../xml/clone.xml", {
        "color": "blue",
        "#things": []
 });
-print doc.toxml()
+print(doc.toxml())
index 19d60769a24776c137b55fe4111af36f494edc2a..450e09704ddc01b3b6520f850470e3bd0bfcb0b8 100644 (file)
@@ -10,4 +10,4 @@ doc = xmltemplate.process_file("../xml/clone.xml", {
                { "li": "Warm, woolen mittens",  "li/class": "even" }
        ]
 })
-print doc.toxml()
+print(doc.toxml())
index 4f25464b6e17932e62a426deda6cc783cfeb394c..deb2f432551ee2befba12deb8985159cbf4a4350 100644 (file)
@@ -10,4 +10,4 @@ doc = xmltemplate.process_file("../xml/clone.xml", {
                { "li": "Warm, woolen mittens"},
        ], "odd", "even")
 });
-print doc.toxml()
+print(doc.toxml())
index 9c6ffbf50b3372fbd18ae957fe2f8a1461903722..c420d940bd026e7344f941f7aec569e4cf6ed6fe 100644 (file)
@@ -11,4 +11,4 @@ doc = xmltemplate.process_file("../xml/clone.xml", {
                { "li": "Warm, woolen mittens"},
        ], "odd", "even")
 });
-print doc.toxml()
+print(doc.toxml())
index 134cdb596df48ac614a1ee2c49ade111e042fb59..694b1b59b6787e8ea8028fd0105ecebf250dd6ca 100644 (file)
@@ -10,4 +10,4 @@ doc = xmltemplate.process_file("../xml/clone.xml", {
                { 'li': 'Warm, woolen mittens' }
        ]
 })
-print doc.toxml()
+print(doc.toxml())
index 0c87fba879a750765b67c040baefc98dd41930e9..3bab9f3bdc7d3dcfbf7a10aaa488c2334e663555 100644 (file)
@@ -9,4 +9,4 @@ master = xmltemplate.process_file("../xml/master.xml", {
        "h1": "Nice heading here",
        "contents": doc
 });
-print master.toxml()
+print(master.toxml())
index 22165785bec082caf6e11fecff7d9a27463f9513..2e19d7f7c748d4782a0ae9c06bce23f6c2cf5d77 100644 (file)
@@ -8,4 +8,4 @@ doc = xmltemplate.process_file("../xml/namespace.xml", {
        'tagname': 'foo',
        '#moretest': 'bar'
 })
-print doc.toxml()
+print(doc.toxml())
index 5df48c5bc94f3e26d6e815bc593ab111ab3da6d3..3c0d0c3052c777b80f7623b9fa4de9964bc703a8 100644 (file)
@@ -5,4 +5,4 @@ doc = xmltemplate.process_file("../xml/namespace2.xml", {
        'title': 'Namespace tests',
        '#hello': 'Replaced.'
 })
-print doc.toxml()
+print(doc.toxml())
index 1d7dd81eb93c9faa74add0a13e561f347e25cf3e..bd701d7b87a3e686b7373c9c13d9b993c1f6b2a9 100644 (file)
@@ -2,4 +2,4 @@
 import xmltemplate
 
 doc = xmltemplate.process_file("../xml/passthru.xml", {})
-print doc.toxml()
+print(doc.toxml())
index 7c78ed03696f5b4c72d58673ea8a269df369aa5f..8df3e08a161f4858a067ff8c2fbdb1c26cf8f3dc 100644 (file)
@@ -5,4 +5,4 @@ doc = xmltemplate.process_file("../xml/simple.xml", {
        'title': 'A very basic example',
        '#hello': 'Hello world!'
 })
-print doc.toxml()
+print(doc.toxml())
index 519ec6ffc6fed73001956df3b1c90de75cdb1ee3..3d72ee655e6320670a5f43fcdcb196d3c04d185e 100644 (file)
@@ -8,4 +8,4 @@ doc = xmltemplate.process_file("../xml/structure.xml", {
                { '#inner': 'Three' },
        ]
 })
-print doc.toxml()
+print(doc.toxml())
index 182b8e4a3712953d48a572d4183791ef4c3946ea..434868703e1d014c36525b0feaab72ae087dea7f 100644 (file)
@@ -1,14 +1,21 @@
 #! /usr/bin/python
 import re
+import sys
 import xml.dom.minidom
 
+if sys.version_info[0] > 2:
+    string = str
+else:
+    string = basestring
+
+
 def process_file(filename, obj, clean = True):
        doc = xml.dom.minidom.parse(filename)
        process(doc, obj, clean)
        return doc
 
 def process(node, obj, clean = True):
-       if isinstance(obj, basestring):                 # overwrite
+       if isinstance(obj, string):                     # overwrite
                while not node.firstChild is None:
                        node.removeChild(node.firstChild)
                doc = _get_document_element(node)
index cb118beb4e3288f1cbea0f6ef4d2ae51e7e6329f..1b66e17498ad17243d196a41a99c155e8ca81e0e 100755 (executable)
@@ -4,7 +4,7 @@ if [ -z "$TESTS" ]; then
        TESTS="passthru simple clone include attribute attribute2 attribute3 attribute-empty namespace namespace2 structure"
 fi
 if [ -z "$LANGUAGES" ]; then
-       LANGUAGES="perl perl-sax php4 php5 python ruby c++11"
+       LANGUAGES="perl perl-sax php4 php5 python python3 ruby c++11"
 fi
 
 for L in $LANGUAGES; do
@@ -28,7 +28,10 @@ for L in $LANGUAGES; do
                        ( cd ../c++11 && make -s && cd ../php5-swig && make -s && sudo cp XML_Template_SWIG.so /usr/lib/php5/20090626+lfs ) && php5-cgi -q ../php5-swig/$T.php > $TEMPFILE
                fi
                if [ "$L" = "python" ]; then
-                       python ../python/$T.py > $TEMPFILE
+                       python2 ../python/$T.py > $TEMPFILE
+               fi
+               if [ "$L" = "python3" ]; then
+                       python3 ../python/$T.py > $TEMPFILE
                fi
                if [ "$L" = "ruby" ]; then
                        ruby -I../ruby ../ruby/$T.rb > $TEMPFILE