diff options
author | Aron Xu <aron@debian.org> | 2014-07-09 04:01:07 +0800 |
---|---|---|
committer | Aron Xu <aron@debian.org> | 2014-07-09 04:01:07 +0800 |
commit | 7042e17490515a990a45aa7237d11bc49ab0eaf0 (patch) | |
tree | 62b661911406394bbeaca8951d660bb6d8aac0de /python/tests | |
parent | 2c8fe012ef1ff6e0613480dd182dec099aa9636e (diff) | |
download | libxml2-7042e17490515a990a45aa7237d11bc49ab0eaf0.tar.gz |
Imported Upstream version 2.8.0+dfsg1
Diffstat (limited to 'python/tests')
49 files changed, 488 insertions, 726 deletions
diff --git a/python/tests/Makefile.am b/python/tests/Makefile.am index 95ebead..52c89fc 100644 --- a/python/tests/Makefile.am +++ b/python/tests/Makefile.am @@ -19,7 +19,6 @@ PYTESTS= \ xpath.py \ outbuf.py \ inbuf.py \ - input_callback.py \ resolver.py \ regexp.py \ reader.py \ @@ -56,11 +55,8 @@ XMLS= \ invalid.xml \ test.dtd -CLEANFILES = core tmp.xml *.pyc - if WITH_PYTHON tests: $(PYTESTS) - @for f in $(XMLS) ; do test -f $$f || $(LN_S) $(srcdir)/$$f . ; done @echo "## running Python regression tests" -@(PYTHONPATH="..:../.libs:$(srcdir)/..:$$PYTHONPATH" ; \ export PYTHONPATH; \ @@ -73,3 +69,6 @@ tests: $(PYTESTS) else tests: endif + +clean: + rm -f *.pyc core diff --git a/python/tests/Makefile.in b/python/tests/Makefile.in index 132538f..a2aaf89 100644 --- a/python/tests/Makefile.in +++ b/python/tests/Makefile.in @@ -1,9 +1,9 @@ -# Makefile.in generated by automake 1.11.6 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software -# Foundation, Inc. +# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, +# Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -16,23 +16,6 @@ @SET_MAKE@ VPATH = @srcdir@ -am__make_dryrun = \ - { \ - am__dry=no; \ - case $$MAKEFLAGS in \ - *\\[\ \ ]*) \ - echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ - | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ - *) \ - for am__flg in $$MAKEFLAGS; do \ - case $$am__flg in \ - *=*|--*) ;; \ - *n*) am__dry=yes; break;; \ - esac; \ - done;; \ - esac; \ - test $$am__dry = yes; \ - } pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ @@ -65,19 +48,14 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = -AM_V_GEN = $(am__v_GEN_@AM_V@) -am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) am__v_GEN_0 = @echo " GEN " $@; -AM_V_at = $(am__v_at_@AM_V@) -am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) am__v_at_0 = @ SOURCES = DIST_SOURCES = -am__can_run_installinfo = \ - case $$AM_UPDATE_INFO_DIR in \ - n|no|NO) false;; \ - *) (install-info --version) >/dev/null 2>&1;; \ - esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -99,12 +77,6 @@ am__nobase_list = $(am__nobase_strip_setup); \ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__uninstall_files_from_dir = { \ - test -z "$$files" \ - || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ - || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ - $(am__cd) "$$dir" && rm -f $$files; }; \ - } am__installdirs = "$(DESTDIR)$(exampledir)" DATA = $(dist_example_DATA) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -112,6 +84,7 @@ ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AR = @AR@ +AS = @AS@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ @@ -148,7 +121,6 @@ HTML_DIR = @HTML_DIR@ HTML_OBJ = @HTML_OBJ@ HTTP_OBJ = @HTTP_OBJ@ ICONV_LIBS = @ICONV_LIBS@ -ICU_LIBS = @ICU_LIBS@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -204,6 +176,7 @@ RANLIB = @RANLIB@ RDL_LIBS = @RDL_LIBS@ READER_TEST = @READER_TEST@ RELDATE = @RELDATE@ +RM = @RM@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ @@ -228,6 +201,7 @@ TEST_VTIME = @TEST_VTIME@ TEST_XINCLUDE = @TEST_XINCLUDE@ TEST_XPATH = @TEST_XPATH@ TEST_XPTR = @TEST_XPTR@ +THREADS_W32 = @THREADS_W32@ THREAD_CFLAGS = @THREAD_CFLAGS@ THREAD_LIBS = @THREAD_LIBS@ VERSION = @VERSION@ @@ -260,7 +234,6 @@ WITH_SAX1 = @WITH_SAX1@ WITH_SCHEMAS = @WITH_SCHEMAS@ WITH_SCHEMATRON = @WITH_SCHEMATRON@ WITH_THREADS = @WITH_THREADS@ -WITH_THREAD_ALLOC = @WITH_THREAD_ALLOC@ WITH_TREE = @WITH_TREE@ WITH_TRIO = @WITH_TRIO@ WITH_VALID = @WITH_VALID@ @@ -354,7 +327,6 @@ PYTESTS = \ xpath.py \ outbuf.py \ inbuf.py \ - input_callback.py \ resolver.py \ regexp.py \ reader.py \ @@ -391,7 +363,6 @@ XMLS = \ invalid.xml \ test.dtd -CLEANFILES = core tmp.xml *.pyc all: all-am .SUFFIXES: @@ -433,11 +404,8 @@ clean-libtool: -rm -rf .libs _libs install-dist_exampleDATA: $(dist_example_DATA) @$(NORMAL_INSTALL) + test -z "$(exampledir)" || $(MKDIR_P) "$(DESTDIR)$(exampledir)" @list='$(dist_example_DATA)'; test -n "$(exampledir)" || list=; \ - if test -n "$$list"; then \ - echo " $(MKDIR_P) '$(DESTDIR)$(exampledir)'"; \ - $(MKDIR_P) "$(DESTDIR)$(exampledir)" || exit 1; \ - fi; \ for p in $$list; do \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; \ @@ -451,7 +419,9 @@ uninstall-dist_exampleDATA: @$(NORMAL_UNINSTALL) @list='$(dist_example_DATA)'; test -n "$(exampledir)" || list=; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ - dir='$(DESTDIR)$(exampledir)'; $(am__uninstall_files_from_dir) + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(exampledir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(exampledir)" && rm -f $$files tags: TAGS TAGS: @@ -506,19 +476,13 @@ install-am: all-am installcheck: installcheck-am install-strip: - if test -z '$(STRIP)'; then \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - install; \ - else \ - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ - fi + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -527,8 +491,6 @@ distclean-generic: maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am @@ -609,7 +571,6 @@ uninstall-am: uninstall-dist_exampleDATA @WITH_PYTHON_TRUE@tests: $(PYTESTS) -@WITH_PYTHON_TRUE@ @for f in $(XMLS) ; do test -f $$f || $(LN_S) $(srcdir)/$$f . ; done @WITH_PYTHON_TRUE@ @echo "## running Python regression tests" @WITH_PYTHON_TRUE@ -@(PYTHONPATH="..:../.libs:$(srcdir)/..:$$PYTHONPATH" ; \ @WITH_PYTHON_TRUE@ export PYTHONPATH; \ @@ -621,6 +582,9 @@ uninstall-am: uninstall-dist_exampleDATA @WITH_PYTHON_TRUE@ echo "-- $$test" ; echo "$$log" ; fi ; done) @WITH_PYTHON_FALSE@tests: +clean: + rm -f *.pyc core + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/python/tests/attribs.py b/python/tests/attribs.py index 99132c2..9331a27 100755 --- a/python/tests/attribs.py +++ b/python/tests/attribs.py @@ -20,7 +20,7 @@ doc = libxml2.parseDoc( elem = doc.getRootElement() attr = elem.hasNsProp('attr', 'http://abc.org') if attr == None or attr.serialize()[:-1] != """<!ATTLIST test abc:attr CDATA #FIXED "def">""": - print("Failed to find defaulted attribute abc:attr") + print "Failed to find defaulted attribute abc:attr" sys.exit(1) doc.freeDoc() @@ -28,7 +28,7 @@ doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/build.py b/python/tests/build.py index b2d3f78..bfc776c 100755 --- a/python/tests/build.py +++ b/python/tests/build.py @@ -23,29 +23,29 @@ doc = libxml2.parseFile("tmp.xml") comment = doc.children if comment.type != "comment" or \ comment.content != "This is a generated document": - print("error rereading comment") + print "error rereading comment" sys.exit(1) pi = comment.next if pi.type != "pi" or pi.name != "test" or pi.content != "PI content": - print("error rereading PI") + print "error rereading PI" sys.exit(1) root = pi.next if root.name != "doc": - print("error rereading root") + print "error rereading root" sys.exit(1) ns = root.ns() if ns.name != "my" or ns.content != "http://example.com/doc": - print("error rereading namespace") + print "error rereading namespace" sys.exit(1) elem = root.children if elem.name != "foo": - print("error rereading elem") + print "error rereading elem" sys.exit(1) if elem.getBase(None) != "http://example.com/imgs": - print("error rereading base") + print "error rereading base" sys.exit(1) if elem.prop("img") != "image.gif": - print("error rereading property") + print "error rereading property" sys.exit(1) doc.freeDoc() @@ -53,7 +53,7 @@ doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/compareNodes.py b/python/tests/compareNodes.py index ca5a5a2..ec04323 100755 --- a/python/tests/compareNodes.py +++ b/python/tests/compareNodes.py @@ -17,25 +17,25 @@ foonode2 = root.children # Now check that [in]equality tests work ok if not ( foonode1 == foonode2 ): - print("Error comparing nodes with ==, nodes should be equal but are unequal") + print "Error comparing nodes with ==, nodes should be equal but are unequal" sys.exit(1) if not ( foonode1 != root ): - print("Error comparing nodes with ==, nodes should not be equal but are equal") + print "Error comparing nodes with ==, nodes should not be equal but are equal" sys.exit(1) if not ( foonode1 != root ): - print("Error comparing nodes with !=, nodes should not be equal but are equal") + print "Error comparing nodes with !=, nodes should not be equal but are equal" if ( foonode1 != foonode2 ): - print("Error comparing nodes with !=, nodes should be equal but are unequal") + print "Error comparing nodes with !=, nodes should be equal but are unequal" # Next check that the hash function for the objects also works ok if not (hash(foonode1) == hash(foonode2)): - print("Error hash values for two equal nodes are different") + print "Error hash values for two equal nodes are different" sys.exit(1) if not (hash(foonode1) != hash(root)): - print("Error hash values for two unequal nodes are not different") + print "Error hash values for two unequal nodes are not different" sys.exit(1) if hash(foonode1) == hash(root): - print("Error hash values for two unequal nodes are equal") + print "Error hash values for two unequal nodes are equal" sys.exit(1) # Basic tests successful @@ -44,7 +44,7 @@ doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/ctxterror.py b/python/tests/ctxterror.py index 416e384..f2a897a 100755 --- a/python/tests/ctxterror.py +++ b/python/tests/ctxterror.py @@ -23,7 +23,7 @@ s = """<x xmlns="foo"></y>""" parserCtxt = libxml2.createPushParser(None,"",0,"test.xml") parserCtxt.setErrorHandler(callback, "-->") if parserCtxt.getErrorHandler() != (callback,"-->"): - print("getErrorHandler failed") + print "getErrorHandler failed" sys.exit(1) parserCtxt.parseChunk(s,len(s),1) doc = parserCtxt.doc() @@ -31,9 +31,9 @@ doc.freeDoc() parserCtxt = None if err != expect: - print("error") - print("received %s" %(err)) - print("expected %s" %(expect)) + print "error" + print "received %s" %(err) + print "expected %s" %(expect) sys.exit(1) i = 10000 @@ -50,7 +50,7 @@ while i > 0: # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/cutnpaste.py b/python/tests/cutnpaste.py index 7787246..0f9665a 100755 --- a/python/tests/cutnpaste.py +++ b/python/tests/cutnpaste.py @@ -35,14 +35,14 @@ source.freeDoc() # check the resulting tree str = dest.serialize() if str != """<root xmlns:foobar="http://example.org/bar" xmlns:default="http://example.org/include" xmlns:foo="http://example.org/foo"><default:fragment><foo:elem bar="tricky"/></default:fragment></root>""": - print("reconciliateNs() failed") + print "reconciliateNs() failed" sys.exit(1) target.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/dtdvalid.py b/python/tests/dtdvalid.py index d4049b8..2011f2c 100755 --- a/python/tests/dtdvalid.py +++ b/python/tests/dtdvalid.py @@ -14,7 +14,7 @@ ctxt = libxml2.newValidCtxt() doc = libxml2.parseDoc(instance) ret = doc.validateDtd(ctxt, dtd) if ret != 1: - print("error doing DTD validation") + print "error doing DTD validation" sys.exit(1) doc.freeDoc() @@ -25,8 +25,8 @@ del ctxt # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/error.py b/python/tests/error.py index 530c2ee..da6d0c1 100755 --- a/python/tests/error.py +++ b/python/tests/error.py @@ -24,13 +24,13 @@ except libxml2.parserError: got_exc = 1 if got_exc == 0: - print("Failed to get a parser exception") + print "Failed to get a parser exception" sys.exit(1) if err != expect: - print("error") - print("received %s" %(err)) - print("expected %s" %(expect)) + print "error" + print "received %s" %(err) + print "expected %s" %(expect) sys.exit(1) i = 10000 @@ -45,7 +45,7 @@ while i > 0: # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/inbuf.py b/python/tests/inbuf.py index 0c16674..a7cc7a6 100755 --- a/python/tests/inbuf.py +++ b/python/tests/inbuf.py @@ -1,19 +1,14 @@ #!/usr/bin/python -u import sys import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO +import StringIO # Memory debug specific libxml2.debugMemory(1) i = 0 while i < 5000: - f = str_io("foobar") + f = StringIO.StringIO("foobar") buf = libxml2.inputBuffer(f) i = i + 1 @@ -23,8 +18,8 @@ del buf # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/indexes.py b/python/tests/indexes.py index e41a0d9..8d7a7fc 100755 --- a/python/tests/indexes.py +++ b/python/tests/indexes.py @@ -20,16 +20,16 @@ class callback: def startDocument(self): global ctxt if ctxt.byteConsumed() != self.startd: - print("document start at wrong index: %d expecting %d\n" % ( - ctxt.byteConsumed(), self.startd)) + print "document start at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), self.startd) sys.exit(1) def endDocument(self): global ctxt expect = self.ende + self.delta * (self.count - 1) + self.endd if ctxt.byteConsumed() != expect: - print("document end at wrong index: %d expecting %d\n" % ( - ctxt.byteConsumed(), expect)) + print "document end at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect) sys.exit(1) def startElement(self, tag, attrs): @@ -37,8 +37,8 @@ class callback: if tag == "bar1": expect = self.starte + self.delta * self.count if ctxt.byteConsumed() != expect: - print("element start at wrong index: %d expecting %d\n" % ( - ctxt.byteConsumed(), expect)) + print "element start at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect) sys.exit(1) @@ -47,8 +47,8 @@ class callback: if tag == "bar1": expect = self.ende + self.delta * self.count if ctxt.byteConsumed() != expect: - print("element end at wrong index: %d expecting %d\n" % ( - ctxt.byteConsumed(), expect)) + print "element end at wrong index: %d expecting %d\n" % ( + ctxt.byteConsumed(), expect) sys.exit(1) self.count = self.count + 1 @@ -107,7 +107,7 @@ ctxt=None # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/input_callback.py b/python/tests/input_callback.py deleted file mode 100755 index 495ab62..0000000 --- a/python/tests/input_callback.py +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/python -u -# -# This tests custom input callbacks -# -import sys -import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO - -# We implement a new scheme, py://strings/ that will reference this dictionary -pystrings = { - 'catalogs/catalog.xml' : -'''<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd"> -<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> - <rewriteSystem systemIdStartString="http://example.com/dtds/" rewritePrefix="../dtds/"/> -</catalog>''', - - 'xml/sample.xml' : -'''<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE root SYSTEM "http://example.com/dtds/sample.dtd"> -<root>&sample.entity;</root>''', - - 'dtds/sample.dtd' : -''' -<!ELEMENT root (#PCDATA)> -<!ENTITY sample.entity "replacement text">''' -} - -prefix = "py://strings/" -startURL = prefix + "xml/sample.xml" -catURL = prefix + "catalogs/catalog.xml" - -def my_input_cb(URI): - if not(URI.startswith(prefix)): - return None - path = URI[len(prefix):] - if path not in pystrings: - return None - return str_io(pystrings[path]) - - -def run_test(desc, docpath, catalog, exp_status="verified", exp_err=[], test_callback=None, - root_name="root", root_content="replacement text"): - opts = libxml2.XML_PARSE_DTDLOAD | libxml2.XML_PARSE_NONET | libxml2.XML_PARSE_COMPACT - actual_err = [] - - def my_global_error_cb(ctx, msg): - actual_err.append((-1, msg)) - def my_ctx_error_cb(arg, msg, severity, reserved): - actual_err.append((severity, msg)) - - libxml2.registerErrorHandler(my_global_error_cb, None) - try: - parser = libxml2.createURLParserCtxt(docpath, opts) - parser.setErrorHandler(my_ctx_error_cb, None) - if catalog is not None: - parser.addLocalCatalog(catalog) - if test_callback is not None: - test_callback() - parser.parseDocument() - doc = parser.doc() - actual_status = "loaded" - e = doc.getRootElement() - if e.name == root_name and e.content == root_content: - actual_status = "verified" - doc.freeDoc() - except libxml2.parserError: - actual_status = "not loaded" - - if actual_status != exp_status: - print("Test '%s' failed: expect status '%s', actual '%s'" % (desc, exp_status, actual_status)) - sys.exit(1) - elif actual_err != exp_err: - print("Test '%s' failed" % desc) - print("Expect errors:") - for s,m in exp_err: print(" [%2d] '%s'" % (s,m)) - print("Actual errors:") - for s,m in actual_err: print(" [%2d] '%s'" % (s,m)) - sys.exit(1) - - -# Check that we cannot read custom schema without custom callback -run_test(desc="Loading entity without custom callback", - docpath=startURL, catalog=None, - exp_status="not loaded", exp_err=[ - (-1, "I/O "), - (-1, "warning : "), - (-1, "failed to load external entity \"py://strings/xml/sample.xml\"\n") - ]) - -# Register handler and try to load the same entity -libxml2.registerInputCallback(my_input_cb) -run_test(desc="Loading entity with custom callback", - docpath=startURL, catalog=None, - exp_status="loaded", exp_err=[ - (-1, "Attempt to load network entity http://example.com/dtds/sample.dtd"), - ( 4, "Entity 'sample.entity' not defined\n") - ]) - -# Register a catalog (also accessible via pystr://) and retry -run_test(desc="Loading entity with custom callback and catalog", - docpath=startURL, catalog=catURL) - -# Unregister custom callback when parser is already created -run_test(desc="Loading entity and unregistering callback", - docpath=startURL, catalog=catURL, - test_callback=lambda: libxml2.popInputCallbacks(), - exp_status="loaded", exp_err=[ - ( 3, "failed to load external entity \"py://strings/dtds/sample.dtd\"\n"), - ( 4, "Entity 'sample.entity' not defined\n") - ]) - -# Try to load the document again -run_test(desc="Retry loading document after unregistering callback", - docpath=startURL, catalog=catURL, - exp_status="not loaded", exp_err=[ - (-1, "I/O "), - (-1, "warning : "), - (-1, "failed to load external entity \"py://strings/xml/sample.xml\"\n") - ]) - -# But should be able to read standard I/O yet... -run_test(desc="Loading using standard i/o after unregistering callback", - docpath="tst.xml", catalog=None, - root_name='doc', root_content='bar') - -# Now pop ALL input callbacks, should fail to load even standard I/O -try: - while True: - libxml2.popInputCallbacks() -except IndexError: - pass - -run_test(desc="Loading using standard i/o after unregistering all callbacks", - docpath="tst.xml", catalog=None, - exp_status="not loaded", exp_err=[ - (-1, "I/O "), - (-1, "warning : "), - (-1, "failed to load external entity \"tst.xml\"\n") - ]) - -print("OK") -sys.exit(0); diff --git a/python/tests/nsdel.py b/python/tests/nsdel.py index 079399a..c06ded3 100755 --- a/python/tests/nsdel.py +++ b/python/tests/nsdel.py @@ -19,7 +19,7 @@ def checkNamespaceDefs(node, count): nsList = list(namespaceDefs(node)) #print nsList if len(nsList) != count : - raise Exception("Error: saw %d namespace declarations. Expected %d" % (len(nsList), count)) + raise Exception, "Error: saw %d namespace declarations. Expected %d" % (len(nsList), count) # Memory debug specific libxml2.debugMemory(1) @@ -56,7 +56,7 @@ doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/outbuf.py b/python/tests/outbuf.py index 62761cc..09cd9b5 100755 --- a/python/tests/outbuf.py +++ b/python/tests/outbuf.py @@ -1,22 +1,17 @@ #!/usr/bin/python -u import sys import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO +import StringIO def testSimpleBufferWrites(): - f = str_io() + f = StringIO.StringIO() buf = libxml2.createOutputBuffer(f, "ISO-8859-1") buf.write(3, "foo") buf.writeString("bar") buf.close() - + if f.getvalue() != "foobar": - print("Failed to save to StringIO") + print "Failed to save to StringIO" sys.exit(1) def testSaveDocToBuffer(): @@ -28,15 +23,15 @@ def testSaveDocToBuffer(): <?xml version="1.0" encoding="UTF-8"?> <foo>Hello</foo> ''' - f = str_io() + f = StringIO.StringIO() buf = libxml2.createOutputBuffer(f, 'UTF-8') doc = libxml2.parseDoc(input) doc.saveFileTo(buf, 'UTF-8') doc.freeDoc() if f.getvalue() != expected: - print('xmlDoc.saveFileTo() call failed.') - print(' got: %s' % repr(f.getvalue())) - print('expected: %s' % repr(expected)) + print 'xmlDoc.saveFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) sys.exit(1) def testSaveFormattedDocToBuffer(): @@ -54,13 +49,13 @@ def testSaveFormattedDocToBuffer(): ''') doc = libxml2.parseDoc(input) for i in (0, 1): - f = str_io() + f = StringIO.StringIO() buf = libxml2.createOutputBuffer(f, 'UTF-8') doc.saveFormatFileTo(buf, 'UTF-8', i) if f.getvalue() != expected[i]: - print('xmlDoc.saveFormatFileTo() call failed.') - print(' got: %s' % repr(f.getvalue())) - print('expected: %s' % repr(expected[i])) + print 'xmlDoc.saveFormatFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected[i]) sys.exit(1) doc.freeDoc() @@ -74,22 +69,22 @@ def testSaveIntoOutputBuffer(): <?xml version="1.0" encoding="UTF-8"?> <foo>Hello</foo> ''' - f = str_io() + f = StringIO.StringIO() doc = libxml2.parseDoc(input) buf = libxml2.createOutputBuffer(f, 'UTF-8') buf.saveFileTo(doc, 'UTF-8') if f.getvalue() != expected: - print('outputBuffer.saveFileTo() call failed.') - print(' got: %s' % repr(f.getvalue())) - print('expected: %s' % repr(expected)) + print 'outputBuffer.saveFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) sys.exit(1) - f = str_io() + f = StringIO.StringIO() buf = libxml2.createOutputBuffer(f, 'UTF-8') buf.saveFormatFileTo(doc, 'UTF-8', 1) if f.getvalue() != expected: - print('outputBuffer.saveFormatFileTo() call failed.') - print(' got: %s' % repr(f.getvalue())) - print('expected: %s' % repr(expected)) + print 'outputBuffer.saveFormatFileTo() call failed.' + print ' got: %s' % repr(f.getvalue()) + print 'expected: %s' % repr(expected) sys.exit(1) doc.freeDoc() @@ -104,7 +99,7 @@ if __name__ == '__main__': libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/push.py b/python/tests/push.py index 0edd61d..5b60a16 100755 --- a/python/tests/push.py +++ b/python/tests/push.py @@ -10,11 +10,11 @@ ctxt.parseChunk("/>", 2, 1) doc = ctxt.doc() ctxt=None if doc.name != "test.xml": - print("document name error") + print "document name error" sys.exit(1) root = doc.children if root.name != "foo": - print("root element name error") + print "root element name error" sys.exit(1) doc.freeDoc() i = 10000 @@ -29,7 +29,7 @@ ctxt=None # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/pushSAX.py b/python/tests/pushSAX.py index 48f6e82..1c1e786 100755 --- a/python/tests/pushSAX.py +++ b/python/tests/pushSAX.py @@ -51,14 +51,14 @@ ctxt=None reference = "startDocument:startElement foo {'url': 'tst'}:characters: bar:endElement foo:endDocument:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/pushSAXhtml.py b/python/tests/pushSAXhtml.py index 159d308..e6e89d9 100755 --- a/python/tests/pushSAXhtml.py +++ b/python/tests/pushSAXhtml.py @@ -52,14 +52,14 @@ ctxt=None reference = """startDocument:startElement html None:startElement body None:startElement foo {'url': 'tst'}:error: Tag foo invalid :characters: bar:endElement foo:endElement body:endElement html:endDocument:""" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader.py b/python/tests/reader.py index 173ce66..6c37762 100755 --- a/python/tests/reader.py +++ b/python/tests/reader.py @@ -4,96 +4,91 @@ # this tests the basic APIs of the XmlTextReader interface # import libxml2 +import StringIO import sys -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO # Memory debug specific libxml2.debugMemory(1) -f = str_io("""<a><b b1="b1"/><c>content of c</c></a>""") +f = StringIO.StringIO("""<a><b b1="b1"/><c>content of c</c></a>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test1") ret = reader.Read() if ret != 1: - print("test1: Error reading to first element") + print "test1: Error reading to first element" sys.exit(1) if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 1 or reader.HasAttributes() != 0: - print("test1: Error reading the first element") + print "test1: Error reading the first element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test1: Error reading to second element") + print "test1: Error reading to second element" sys.exit(1) if reader.Name() != "b" or reader.IsEmptyElement() != 1 or \ reader.NodeType() != 1 or reader.HasAttributes() != 1: - print("test1: Error reading the second element") + print "test1: Error reading the second element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test1: Error reading to third element") + print "test1: Error reading to third element" sys.exit(1) if reader.Name() != "c" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 1 or reader.HasAttributes() != 0: - print("test1: Error reading the third element") + print "test1: Error reading the third element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test1: Error reading to text node") + print "test1: Error reading to text node" sys.exit(1) if reader.Name() != "#text" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 3 or reader.HasAttributes() != 0 or \ reader.Value() != "content of c": - print("test1: Error reading the text node") + print "test1: Error reading the text node" sys.exit(1) ret = reader.Read() if ret != 1: - print("test1: Error reading to end of third element") + print "test1: Error reading to end of third element" sys.exit(1) if reader.Name() != "c" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 15 or reader.HasAttributes() != 0: - print("test1: Error reading the end of third element") + print "test1: Error reading the end of third element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test1: Error reading to end of first element") + print "test1: Error reading to end of first element" sys.exit(1) if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 15 or reader.HasAttributes() != 0: - print("test1: Error reading the end of first element") + print "test1: Error reading the end of first element" sys.exit(1) ret = reader.Read() if ret != 0: - print("test1: Error reading to end of document") + print "test1: Error reading to end of document" sys.exit(1) # # example from the XmlTextReader docs # -f = str_io("""<test xmlns:dt="urn:datatypes" dt:type="int"/>""") +f = StringIO.StringIO("""<test xmlns:dt="urn:datatypes" dt:type="int"/>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test2") ret = reader.Read() if ret != 1: - print("Error reading test element") + print "Error reading test element" sys.exit(1) if reader.GetAttributeNo(0) != "urn:datatypes" or \ reader.GetAttributeNo(1) != "int" or \ reader.GetAttributeNs("type", "urn:datatypes") != "int" or \ reader.GetAttribute("dt:type") != "int": - print("error reading test attributes") + print "error reading test attributes" sys.exit(1) # # example from the XmlTextReader docs # -f = str_io("""<root xmlns:a="urn:456"> +f = StringIO.StringIO("""<root xmlns:a="urn:456"> <item> <ref href="a:b"/> </item> @@ -105,203 +100,203 @@ ret = reader.Read() while ret == 1: if reader.Name() == "ref": if reader.LookupNamespace("a") != "urn:456": - print("error resolving namespace prefix") + print "error resolving namespace prefix" sys.exit(1) break ret = reader.Read() if ret != 1: - print("Error finding the ref element") + print "Error finding the ref element" sys.exit(1) # # Home made example for the various attribute access functions # -f = str_io("""<testattr xmlns="urn:1" xmlns:a="urn:2" b="b" a:b="a:b"/>""") +f = StringIO.StringIO("""<testattr xmlns="urn:1" xmlns:a="urn:2" b="b" a:b="a:b"/>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test4") ret = reader.Read() if ret != 1: - print("Error reading the testattr element") + print "Error reading the testattr element" sys.exit(1) # # Attribute exploration by index # if reader.MoveToAttributeNo(0) != 1: - print("Failed moveToAttribute(0)") + print "Failed moveToAttribute(0)" sys.exit(1) if reader.Value() != "urn:1": - print("Failed to read attribute(0)") + print "Failed to read attribute(0)" sys.exit(1) if reader.Name() != "xmlns": - print("Failed to read attribute(0) name") + print "Failed to read attribute(0) name" sys.exit(1) if reader.MoveToAttributeNo(1) != 1: - print("Failed moveToAttribute(1)") + print "Failed moveToAttribute(1)" sys.exit(1) if reader.Value() != "urn:2": - print("Failed to read attribute(1)") + print "Failed to read attribute(1)" sys.exit(1) if reader.Name() != "xmlns:a": - print("Failed to read attribute(1) name") + print "Failed to read attribute(1) name" sys.exit(1) if reader.MoveToAttributeNo(2) != 1: - print("Failed moveToAttribute(2)") + print "Failed moveToAttribute(2)" sys.exit(1) if reader.Value() != "b": - print("Failed to read attribute(2)") + print "Failed to read attribute(2)" sys.exit(1) if reader.Name() != "b": - print("Failed to read attribute(2) name") + print "Failed to read attribute(2) name" sys.exit(1) if reader.MoveToAttributeNo(3) != 1: - print("Failed moveToAttribute(3)") + print "Failed moveToAttribute(3)" sys.exit(1) if reader.Value() != "a:b": - print("Failed to read attribute(3)") + print "Failed to read attribute(3)" sys.exit(1) if reader.Name() != "a:b": - print("Failed to read attribute(3) name") + print "Failed to read attribute(3) name" sys.exit(1) # # Attribute exploration by name # if reader.MoveToAttribute("xmlns") != 1: - print("Failed moveToAttribute('xmlns')") + print "Failed moveToAttribute('xmlns')" sys.exit(1) if reader.Value() != "urn:1": - print("Failed to read attribute('xmlns')") + print "Failed to read attribute('xmlns')" sys.exit(1) if reader.MoveToAttribute("xmlns:a") != 1: - print("Failed moveToAttribute('xmlns')") + print "Failed moveToAttribute('xmlns')" sys.exit(1) if reader.Value() != "urn:2": - print("Failed to read attribute('xmlns:a')") + print "Failed to read attribute('xmlns:a')" sys.exit(1) if reader.MoveToAttribute("b") != 1: - print("Failed moveToAttribute('b')") + print "Failed moveToAttribute('b')" sys.exit(1) if reader.Value() != "b": - print("Failed to read attribute('b')") + print "Failed to read attribute('b')" sys.exit(1) if reader.MoveToAttribute("a:b") != 1: - print("Failed moveToAttribute('a:b')") + print "Failed moveToAttribute('a:b')" sys.exit(1) if reader.Value() != "a:b": - print("Failed to read attribute('a:b')") + print "Failed to read attribute('a:b')" sys.exit(1) if reader.MoveToAttributeNs("b", "urn:2") != 1: - print("Failed moveToAttribute('b', 'urn:2')") + print "Failed moveToAttribute('b', 'urn:2')" sys.exit(1) if reader.Value() != "a:b": - print("Failed to read attribute('b', 'urn:2')") + print "Failed to read attribute('b', 'urn:2')" sys.exit(1) # # Go back and read in sequence # if reader.MoveToElement() != 1: - print("Failed to move back to element") + print "Failed to move back to element" sys.exit(1) if reader.MoveToFirstAttribute() != 1: - print("Failed to move to first attribute") + print "Failed to move to first attribute" sys.exit(1) if reader.Value() != "urn:1": - print("Failed to read attribute(0)") + print "Failed to read attribute(0)" sys.exit(1) if reader.Name() != "xmlns": - print("Failed to read attribute(0) name") + print "Failed to read attribute(0) name" sys.exit(1) if reader.MoveToNextAttribute() != 1: - print("Failed to move to next attribute") + print "Failed to move to next attribute" sys.exit(1) if reader.Value() != "urn:2": - print("Failed to read attribute(1)") + print "Failed to read attribute(1)" sys.exit(1) if reader.Name() != "xmlns:a": - print("Failed to read attribute(1) name") + print "Failed to read attribute(1) name" sys.exit(1) if reader.MoveToNextAttribute() != 1: - print("Failed to move to next attribute") + print "Failed to move to next attribute" sys.exit(1) if reader.Value() != "b": - print("Failed to read attribute(2)") + print "Failed to read attribute(2)" sys.exit(1) if reader.Name() != "b": - print("Failed to read attribute(2) name") + print "Failed to read attribute(2) name" sys.exit(1) if reader.MoveToNextAttribute() != 1: - print("Failed to move to next attribute") + print "Failed to move to next attribute" sys.exit(1) if reader.Value() != "a:b": - print("Failed to read attribute(3)") + print "Failed to read attribute(3)" sys.exit(1) if reader.Name() != "a:b": - print("Failed to read attribute(3) name") + print "Failed to read attribute(3) name" sys.exit(1) if reader.MoveToNextAttribute() != 0: - print("Failed to detect last attribute") + print "Failed to detect last attribute" sys.exit(1) # # a couple of tests for namespace nodes # -f = str_io("""<a xmlns="http://example.com/foo"/>""") +f = StringIO.StringIO("""<a xmlns="http://example.com/foo"/>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test6") ret = reader.Read() if ret != 1: - print("test6: failed to Read()") + print "test6: failed to Read()" sys.exit(1) ret = reader.MoveToFirstAttribute() if ret != 1: - print("test6: failed to MoveToFirstAttribute()") + print "test6: failed to MoveToFirstAttribute()" sys.exit(1) if reader.NamespaceUri() != "http://www.w3.org/2000/xmlns/" or \ reader.LocalName() != "xmlns" or reader.Name() != "xmlns" or \ reader.Value() != "http://example.com/foo" or reader.NodeType() != 2: - print("test6: failed to read the namespace node") + print "test6: failed to read the namespace node" sys.exit(1) -f = str_io("""<a xmlns:prefix="http://example.com/foo"/>""") +f = StringIO.StringIO("""<a xmlns:prefix="http://example.com/foo"/>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test7") ret = reader.Read() if ret != 1: - print("test7: failed to Read()") + print "test7: failed to Read()" sys.exit(1) ret = reader.MoveToFirstAttribute() if ret != 1: - print("test7: failed to MoveToFirstAttribute()") + print "test7: failed to MoveToFirstAttribute()" sys.exit(1) if reader.NamespaceUri() != "http://www.w3.org/2000/xmlns/" or \ reader.LocalName() != "prefix" or reader.Name() != "xmlns:prefix" or \ reader.Value() != "http://example.com/foo" or reader.NodeType() != 2: - print("test7: failed to read the namespace node") + print "test7: failed to read the namespace node" sys.exit(1) # # Test for a limit case: # -f = str_io("""<a/>""") +f = StringIO.StringIO("""<a/>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test8") ret = reader.Read() if ret != 1: - print("test8: failed to read the node") + print "test8: failed to read the node" sys.exit(1) if reader.Name() != "a" or reader.IsEmptyElement() != 1: - print("test8: failed to analyze the node") + print "test8: failed to analyze the node" sys.exit(1) ret = reader.Read() if ret != 0: - print("test8: failed to detect the EOF") + print "test8: failed to detect the EOF" sys.exit(1) # # Another test provided by Stéphane Bidoul and checked with C# # def tst_reader(s): - f = str_io(s) + f = StringIO.StringIO(s) input = libxml2.inputBuffer(f) reader = input.newTextReader("tst") res = "" @@ -327,8 +322,8 @@ expect="""1 (a) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test5 failed") - print(res) + print "test5 failed" + print res sys.exit(1) doc="""<test><b/><c/></test>""" @@ -339,8 +334,8 @@ expect="""1 (test) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test9 failed") - print(res) + print "test9 failed" + print res sys.exit(1) doc="""<a><b>bbb</b><c>ccc</c></a>""" @@ -355,8 +350,8 @@ expect="""1 (a) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test10 failed") - print(res) + print "test10 failed" + print res sys.exit(1) doc="""<test a="a"/>""" @@ -365,8 +360,8 @@ expect="""1 (test) [None] 1 0 """ res = tst_reader(doc) if res != expect: - print("test11 failed") - print(res) + print "test11 failed" + print res sys.exit(1) doc="""<test><a>aaa</a><b/></test>""" @@ -379,8 +374,8 @@ expect="""1 (test) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test12 failed") - print(res) + print "test12 failed" + print res sys.exit(1) doc="""<test><p></p></test>""" @@ -391,8 +386,8 @@ expect="""1 (test) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test13 failed") - print(res) + print "test13 failed" + print res sys.exit(1) doc="""<p></p>""" @@ -401,8 +396,8 @@ expect="""1 (p) [None] 0 0 """ res = tst_reader(doc) if res != expect: - print("test14 failed") - print(res) + print "test14 failed" + print res sys.exit(1) # @@ -426,8 +421,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx """ res = tst_reader(doc) if res != expect: - print("test15 failed") - print(res) + print "test15 failed" + print res sys.exit(1) # @@ -440,7 +435,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader2.py b/python/tests/reader2.py index 8570575..ea890ec 100755 --- a/python/tests/reader2.py +++ b/python/tests/reader2.py @@ -5,13 +5,8 @@ import sys import glob import string +import StringIO import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO # Memory debug specific libxml2.debugMemory(1) @@ -35,11 +30,7 @@ libxml2.registerErrorHandler(callback, "") valid_files = glob.glob("../../test/valid/*.x*") valid_files.sort() for file in valid_files: - if file.find("t8") != -1: - continue - if file == "../../test/valid/rss.xml": - continue - if file == "../../test/valid/xlink.xml": + if string.find(file, "t8") != -1: continue reader = libxml2.newTextReaderFilename(file) #print "%s:" % (file) @@ -48,11 +39,11 @@ for file in valid_files: while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing and validating %s" % (file)) + print "Error parsing and validating %s" % (file) #sys.exit(1) if err != expect: - print(err) + print err # # another separate test based on Stephane Bidoul one @@ -88,7 +79,7 @@ expect="""10,test res="" err="" -input = libxml2.inputBuffer(str_io(s)) +input = libxml2.inputBuffer(StringIO.StringIO(s)) reader = input.newTextReader("test2") reader.SetParserProp(libxml2.PARSER_LOADDTD,1) reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1) @@ -98,12 +89,12 @@ while reader.Read() == 1: res = res + "%s,%s\n" % (reader.NodeType(),reader.Name()) if res != expect: - print("test2 failed: unexpected output") - print(res) + print "test2 failed: unexpected output" + print res sys.exit(1) if err != "": - print("test2 failed: validation error found") - print(err) + print "test2 failed: validation error found" + print err sys.exit(1) # @@ -133,12 +124,12 @@ res="" def myResolver(URL, ID, ctxt): if URL == "tst.ent": - return(str_io(tst_ent)) + return(StringIO.StringIO(tst_ent)) return None libxml2.setEntityLoader(myResolver) -input = libxml2.inputBuffer(str_io(s)) +input = libxml2.inputBuffer(StringIO.StringIO(s)) reader = input.newTextReader("test3") reader.SetParserProp(libxml2.PARSER_LOADDTD,1) reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1) @@ -148,12 +139,12 @@ while reader.Read() == 1: res = res + "%s %s\n" % (reader.NodeType(),reader.Name()) if res != expect: - print("test3 failed: unexpected output") - print(res) + print "test3 failed: unexpected output" + print res sys.exit(1) if err != "": - print("test3 failed: validation error found") - print(err) + print "test3 failed: validation error found" + print err sys.exit(1) # @@ -192,7 +183,7 @@ expect="""10 test 0 res="" err="" -input = libxml2.inputBuffer(str_io(s)) +input = libxml2.inputBuffer(StringIO.StringIO(s)) reader = input.newTextReader("test4") reader.SetParserProp(libxml2.PARSER_LOADDTD,1) reader.SetParserProp(libxml2.PARSER_DEFAULTATTRS,1) @@ -202,12 +193,12 @@ while reader.Read() == 1: res = res + "%s %s %d\n" % (reader.NodeType(),reader.Name(),reader.Depth()) if res != expect: - print("test4 failed: unexpected output") - print(res) + print "test4 failed: unexpected output" + print res sys.exit(1) if err != "": - print("test4 failed: validation error found") - print(err) + print "test4 failed: validation error found" + print err sys.exit(1) # @@ -237,18 +228,18 @@ expect="""10 test 0 res="" err="" -input = libxml2.inputBuffer(str_io(s)) +input = libxml2.inputBuffer(StringIO.StringIO(s)) reader = input.newTextReader("test5") reader.SetParserProp(libxml2.PARSER_VALIDATE,1) while reader.Read() == 1: res = res + "%s %s %d\n" % (reader.NodeType(),reader.Name(),reader.Depth()) if res != expect: - print("test5 failed: unexpected output") - print(res) + print "test5 failed: unexpected output" + print res if err != "": - print("test5 failed: validation error found") - print(err) + print "test5 failed: validation error found" + print err # # cleanup @@ -259,7 +250,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader3.py b/python/tests/reader3.py index 4302b6c..2458c89 100755 --- a/python/tests/reader3.py +++ b/python/tests/reader3.py @@ -3,13 +3,8 @@ # this tests the entities substitutions with the XmlTextReader interface # import sys +import StringIO import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO docstr="""<?xml version='1.0'?> <!DOCTYPE doc [ @@ -23,90 +18,90 @@ libxml2.debugMemory(1) # # First test, normal don't substitute entities. # -f = str_io(docstr) +f = StringIO.StringIO(docstr) input = libxml2.inputBuffer(f) reader = input.newTextReader("test_noent") ret = reader.Read() if ret != 1: - print("Error reading to root") + print "Error reading to root" sys.exit(1) if reader.Name() == "doc" or reader.NodeType() == 10: ret = reader.Read() if ret != 1: - print("Error reading to root") + print "Error reading to root" sys.exit(1) if reader.Name() != "doc" or reader.NodeType() != 1: - print("test_normal: Error reading the root element") + print "test_normal: Error reading the root element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_normal: Error reading to the entity") + print "test_normal: Error reading to the entity" sys.exit(1) if reader.Name() != "tst" or reader.NodeType() != 5: - print("test_normal: Error reading the entity") + print "test_normal: Error reading the entity" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_normal: Error reading to the end of root") + print "test_normal: Error reading to the end of root" sys.exit(1) if reader.Name() != "doc" or reader.NodeType() != 15: - print("test_normal: Error reading the end of the root element") + print "test_normal: Error reading the end of the root element" sys.exit(1) ret = reader.Read() if ret != 0: - print("test_normal: Error detecting the end") + print "test_normal: Error detecting the end" sys.exit(1) # # Second test, completely substitute the entities. # -f = str_io(docstr) +f = StringIO.StringIO(docstr) input = libxml2.inputBuffer(f) reader = input.newTextReader("test_noent") reader.SetParserProp(libxml2.PARSER_SUBST_ENTITIES, 1) ret = reader.Read() if ret != 1: - print("Error reading to root") + print "Error reading to root" sys.exit(1) if reader.Name() == "doc" or reader.NodeType() == 10: ret = reader.Read() if ret != 1: - print("Error reading to root") + print "Error reading to root" sys.exit(1) if reader.Name() != "doc" or reader.NodeType() != 1: - print("test_noent: Error reading the root element") + print "test_noent: Error reading the root element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_noent: Error reading to the entity content") + print "test_noent: Error reading to the entity content" sys.exit(1) if reader.Name() != "p" or reader.NodeType() != 1: - print("test_noent: Error reading the p element from entity") + print "test_noent: Error reading the p element from entity" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_noent: Error reading to the text node") + print "test_noent: Error reading to the text node" sys.exit(1) if reader.NodeType() != 3 or reader.Value() != "test": - print("test_noent: Error reading the text node") + print "test_noent: Error reading the text node" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_noent: Error reading to the end of p element") + print "test_noent: Error reading to the end of p element" sys.exit(1) if reader.Name() != "p" or reader.NodeType() != 15: - print("test_noent: Error reading the end of the p element") + print "test_noent: Error reading the end of the p element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_noent: Error reading to the end of root") + print "test_noent: Error reading to the end of root" sys.exit(1) if reader.Name() != "doc" or reader.NodeType() != 15: - print("test_noent: Error reading the end of the root element") + print "test_noent: Error reading the end of the root element" sys.exit(1) ret = reader.Read() if ret != 0: - print("test_noent: Error detecting the end") + print "test_noent: Error detecting the end" sys.exit(1) # @@ -127,12 +122,12 @@ simplestruct2_ent="""<descr/>""" def myResolver(URL, ID, ctxt): if URL == "simplestruct2.ent": - return(str_io(simplestruct2_ent)) + return(StringIO.StringIO(simplestruct2_ent)) return None libxml2.setEntityLoader(myResolver) -input = libxml2.inputBuffer(str_io(s)) +input = libxml2.inputBuffer(StringIO.StringIO(s)) reader = input.newTextReader("test3") reader.SetParserProp(libxml2.PARSER_SUBST_ENTITIES,1) while reader.Read() == 1: @@ -140,8 +135,8 @@ while reader.Read() == 1: reader.Depth(),reader.IsEmptyElement()) if res != expect: - print("test3 failed: unexpected output") - print(res) + print "test3 failed: unexpected output" + print res sys.exit(1) # @@ -154,7 +149,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader4.py b/python/tests/reader4.py index 0bb3e3f..0824929 100755 --- a/python/tests/reader4.py +++ b/python/tests/reader4.py @@ -3,19 +3,14 @@ # this tests the basic APIs of the XmlTextReader interface # import libxml2 +import StringIO import sys -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO # Memory debug specific libxml2.debugMemory(1) def tst_reader(s): - f = str_io(s) + f = StringIO.StringIO(s) input = libxml2.inputBuffer(f) reader = input.newTextReader("tst") res = "" @@ -37,14 +32,14 @@ expect="""1 (test) [None] 0 res = tst_reader("""<test><b/><c/></test>""") if res != expect: - print("Did not get the expected error message:") - print(res) + print "Did not get the expected error message:" + print res sys.exit(1) # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader5.py b/python/tests/reader5.py index 82d0dae..fcbad61 100755 --- a/python/tests/reader5.py +++ b/python/tests/reader5.py @@ -4,6 +4,7 @@ # this extract the Dragon bibliography entries from the XML specification # import libxml2 +import StringIO import sys # Memory debug specific @@ -14,11 +15,11 @@ Ravi Sethi, and Jeffrey D. Ullman. <emph>Compilers: Principles, Techniques, and Tools</emph>. Reading: Addison-Wesley, 1986, rpt. corr. 1988.</bibl>""" -f = open('../../test/valid/REC-xml-19980210.xml', 'rb') +f = open('../../test/valid/REC-xml-19980210.xml') input = libxml2.inputBuffer(f) reader = input.newTextReader("REC") res="" -while reader.Read() > 0: +while reader.Read(): while reader.Name() == 'bibl': node = reader.Expand() # expand the subtree if node.xpathEval("@id = 'Aho'"): # use XPath on it @@ -27,9 +28,9 @@ while reader.Read() > 0: break; if res != expect: - print("Error: didn't get the expected output") - print("got '%s'" % (res)) - print("expected '%s'" % (expect)) + print "Error: didn't get the expected output" + print "got '%s'" % (res) + print "expected '%s'" % (expect) # @@ -41,7 +42,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader6.py b/python/tests/reader6.py index ef33b18..7a34601 100755 --- a/python/tests/reader6.py +++ b/python/tests/reader6.py @@ -3,13 +3,8 @@ # this tests the entities substitutions with the XmlTextReader interface # import sys +import StringIO import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO schema="""<element name="foo" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> @@ -46,7 +41,7 @@ docstr="""<foo> <item>100</item> </foo>""" -f = str_io(docstr) +f = StringIO.StringIO(docstr) input = libxml2.inputBuffer(f) reader = input.newTextReader("correct") reader.RelaxNGSetSchema(rngs) @@ -55,11 +50,11 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document") + print "Error parsing the document" sys.exit(1) if reader.IsValid() != 1: - print("Document failed to validate") + print "Document failed to validate" sys.exit(1) # @@ -89,7 +84,7 @@ def callback(ctx, str): err = err + "%s" % (str) libxml2.registerErrorHandler(callback, "") -f = str_io(docstr) +f = StringIO.StringIO(docstr) input = libxml2.inputBuffer(f) reader = input.newTextReader("error") reader.RelaxNGSetSchema(rngs) @@ -98,16 +93,16 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document") + print "Error parsing the document" sys.exit(1) if reader.IsValid() != 0: - print("Document failed to detect the validation error") + print "Document failed to detect the validation error" sys.exit(1) if err != expect: - print("Did not get the expected error message:") - print(err) + print "Did not get the expected error message:" + print err sys.exit(1) # @@ -122,7 +117,7 @@ libxml2.relaxNGCleanupTypes() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader7.py b/python/tests/reader7.py index c88e370..35a426f 100755 --- a/python/tests/reader7.py +++ b/python/tests/reader7.py @@ -3,6 +3,7 @@ # this tests the entities substitutions with the XmlTextReader interface # import sys +import StringIO import libxml2 # Memory debug specific @@ -43,12 +44,12 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document test1") + print "Error parsing the document test1" sys.exit(1) if result != expect: - print("Unexpected result for test1") - print(result) + print "Unexpected result for test1" + print result sys.exit(1) # @@ -79,12 +80,12 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document test2") + print "Error parsing the document test2" sys.exit(1) if result != expect: - print("Unexpected result for test2") - print(result) + print "Unexpected result for test2" + print result sys.exit(1) # @@ -95,7 +96,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/reader8.py b/python/tests/reader8.py index de2dcd6..53b7f27 100755 --- a/python/tests/reader8.py +++ b/python/tests/reader8.py @@ -3,6 +3,7 @@ # this tests the entities substitutions with the XmlTextReader interface # import sys +import StringIO import libxml2 # Memory debug specific @@ -22,7 +23,7 @@ ret = reader.Read() ret = reader.Close() if ret != 0: - print("Error closing the document test1") + print "Error closing the document test1" sys.exit(1) del reader @@ -30,7 +31,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/readererr.py b/python/tests/readererr.py index c8ceba5..0dad36e 100755..100644 --- a/python/tests/readererr.py +++ b/python/tests/readererr.py @@ -3,13 +3,8 @@ # this tests the basic APIs of the XmlTextReader interface # import libxml2 +import StringIO import sys -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO # Memory debug specific libxml2.debugMemory(1) @@ -22,7 +17,7 @@ def myErrorHandler(arg,msg,severity,locator): global err err = err + "%s (%d) %s:%d:%s" % (arg,severity,locator.BaseURI(),locator.LineNumber(),msg) -f = str_io("""<a xmlns="foo"><b b1="b1"/><c>content of c</a>""") +f = StringIO.StringIO("""<a xmlns="foo"><b b1="b1"/><c>content of c</a>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test1") reader.SetErrorHandler(myErrorHandler,"-->") @@ -30,14 +25,14 @@ while reader.Read() == 1: pass if err != expect: - print("error") - print("received %s" %(err)) - print("expected %s" %(expect)) + print "error" + print "received %s" %(err) + print "expected %s" %(expect) sys.exit(1) reader.SetErrorHandler(None,None) if reader.GetErrorHandler() != (None,None): - print("GetErrorHandler failed") + print "GetErrorHandler failed" sys.exit(1) # @@ -50,7 +45,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/readernext.py b/python/tests/readernext.py index fcb9ae3..b01a49d 100755 --- a/python/tests/readernext.py +++ b/python/tests/readernext.py @@ -4,70 +4,65 @@ # this tests the next API of the XmlTextReader interface # import libxml2 +import StringIO import sys -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO # Memory debug specific libxml2.debugMemory(1) -f = str_io("""<a><b><c /></b><d>content of d</d></a>""") +f = StringIO.StringIO("""<a><b><c /></b><d>content of d</d></a>""") input = libxml2.inputBuffer(f) reader = input.newTextReader("test_next") ret = reader.Read() if ret != 1: - print("test_next: Error reading to first element") + print "test_next: Error reading to first element" sys.exit(1) if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 1 or reader.HasAttributes() != 0: - print("test_next: Error reading the first element") + print "test_next: Error reading the first element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_next: Error reading to second element") + print "test_next: Error reading to second element" sys.exit(1) if reader.Name() != "b" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 1 or reader.HasAttributes() != 0: - print("test_next: Error reading the second element") + print "test_next: Error reading the second element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_next: Error reading to third element") + print "test_next: Error reading to third element" sys.exit(1) if reader.Name() != "c" or reader.NodeType() != 1 or \ reader.HasAttributes() != 0: - print("test_next: Error reading the third element") + print "test_next: Error reading the third element" sys.exit(1) ret = reader.Read() if ret != 1: - print("test_next: Error reading to end of third element") + print "test_next: Error reading to end of third element" sys.exit(1) if reader.Name() != "b" or reader.NodeType() != 15: - print("test_next: Error reading to end of second element") + print "test_next: Error reading to end of second element" sys.exit(1) ret = reader.Next() if ret != 1: - print("test_next: Error moving to third element") + print "test_next: Error moving to third element" sys.exit(1) if reader.Name() != "d" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 1 or reader.HasAttributes() != 0: - print("test_next: Error reading third element") + print "test_next: Error reading third element" sys.exit(1) ret = reader.Next() if ret != 1: - print("test_next: Error reading to end of first element") + print "test_next: Error reading to end of first element" sys.exit(1) if reader.Name() != "a" or reader.IsEmptyElement() != 0 or \ reader.NodeType() != 15 or reader.HasAttributes() != 0: - print("test_next: Error reading the end of first element") + print "test_next: Error reading the end of first element" sys.exit(1) ret = reader.Read() if ret != 0: - print("test_next: Error reading to end of document") + print "test_next: Error reading to end of document" sys.exit(1) # @@ -80,7 +75,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/regexp.py b/python/tests/regexp.py index a03e459..4c05502 100755..100644 --- a/python/tests/regexp.py +++ b/python/tests/regexp.py @@ -6,19 +6,19 @@ libxml2.debugMemory(1) re = libxml2.regexpCompile("a|b") if re.regexpExec("a") != 1: - print("error checking 'a'") + print "error checking 'a'" sys.exit(1) if re.regexpExec("b") != 1: - print("error checking 'b'") + print "error checking 'b'" sys.exit(1) if re.regexpExec("ab") != 0: - print("error checking 'ab'") + print "error checking 'ab'" sys.exit(1) if re.regexpExec("") != 0: - print("error checking 'ab'") + print "error checking 'ab'" sys.exit(1) if re.regexpIsDeterminist() != 1: - print("error checking determinism") + print "error checking determinism" sys.exit(1) del re @@ -26,7 +26,7 @@ del re # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/relaxng.py b/python/tests/relaxng.py index fa3d327..2c83635 100755 --- a/python/tests/relaxng.py +++ b/python/tests/relaxng.py @@ -29,7 +29,7 @@ ctxt = rngs.relaxNGNewValidCtxt() doc = libxml2.parseDoc(instance) ret = doc.relaxNGValidateDoc(ctxt) if ret != 0: - print("error doing RelaxNG validation") + print "error doing RelaxNG validation" sys.exit(1) doc.freeDoc() @@ -41,8 +41,8 @@ libxml2.relaxNGCleanupTypes() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/resolver.py b/python/tests/resolver.py index 6f21f52..9f4a478 100755 --- a/python/tests/resolver.py +++ b/python/tests/resolver.py @@ -1,25 +1,20 @@ #!/usr/bin/python -u import sys import libxml2 -try: - import StringIO - str_io = StringIO.StringIO -except: - import io - str_io = io.StringIO +import StringIO # Memory debug specific libxml2.debugMemory(1) def myResolver(URL, ID, ctxt): - return(str_io("<foo/>")) + return(StringIO.StringIO("<foo/>")) libxml2.setEntityLoader(myResolver) doc = libxml2.parseFile("doesnotexist.xml") root = doc.children if root.name != "foo": - print("root element name error") + print "root element name error" sys.exit(1) doc.freeDoc() @@ -28,7 +23,7 @@ while i < 5000: doc = libxml2.parseFile("doesnotexist.xml") root = doc.children if root.name != "foo": - print("root element name error") + print "root element name error" sys.exit(1) doc.freeDoc() i = i + 1 @@ -37,8 +32,8 @@ while i < 5000: # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/schema.py b/python/tests/schema.py index 8089272..bfa8423 100755 --- a/python/tests/schema.py +++ b/python/tests/schema.py @@ -33,7 +33,7 @@ ctxt_valid = ctxt_schema.schemaNewValidCtxt() doc = libxml2.parseDoc(instance) ret = doc.schemaValidateDoc(ctxt_valid) if ret != 0: - print("error doing schema validation") + print "error doing schema validation" sys.exit(1) doc.freeDoc() @@ -45,8 +45,8 @@ libxml2.schemaCleanupTypes() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/serialize.py b/python/tests/serialize.py index 80b901a..91753e7 100755 --- a/python/tests/serialize.py +++ b/python/tests/serialize.py @@ -13,13 +13,13 @@ str = doc.serialize() if str != """<?xml version="1.0"?> <root><foo>hello</foo></root> """: - print("error serializing XML document 1") + print "error serializing XML document 1" sys.exit(1) str = doc.serialize("iso-8859-1") if str != """<?xml version="1.0" encoding="iso-8859-1"?> <root><foo>hello</foo></root> """: - print("error serializing XML document 2") + print "error serializing XML document 2" sys.exit(1) str = doc.serialize(format=1) if str != """<?xml version="1.0"?> @@ -27,7 +27,7 @@ if str != """<?xml version="1.0"?> <foo>hello</foo> </root> """: - print("error serializing XML document 3") + print "error serializing XML document 3" sys.exit(1) str = doc.serialize("iso-8859-1", 1) if str != """<?xml version="1.0" encoding="iso-8859-1"?> @@ -35,7 +35,7 @@ if str != """<?xml version="1.0" encoding="iso-8859-1"?> <foo>hello</foo> </root> """: - print("error serializing XML document 4") + print "error serializing XML document 4" sys.exit(1) # @@ -44,23 +44,23 @@ if str != """<?xml version="1.0" encoding="iso-8859-1"?> root = doc.getRootElement() str = root.serialize() if str != """<root><foo>hello</foo></root>""": - print("error serializing XML root 1") + print "error serializing XML root 1" sys.exit(1) str = root.serialize("iso-8859-1") if str != """<root><foo>hello</foo></root>""": - print("error serializing XML root 2") + print "error serializing XML root 2" sys.exit(1) str = root.serialize(format=1) if str != """<root> <foo>hello</foo> </root>""": - print("error serializing XML root 3") + print "error serializing XML root 3" sys.exit(1) str = root.serialize("iso-8859-1", 1) if str != """<root> <foo>hello</foo> </root>""": - print("error serializing XML root 4") + print "error serializing XML root 4" sys.exit(1) doc.freeDoc() @@ -72,13 +72,13 @@ str = doc.serialize() if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head><title>Hello</title></head><body><p>hello</p></body></html> """: - print("error serializing HTML document 1") + print "error serializing HTML document 1" sys.exit(1) str = doc.serialize("ISO-8859-1") if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Hello</title></head><body><p>hello</p></body></html> """: - print("error serializing HTML document 2") + print "error serializing HTML document 2" sys.exit(1) str = doc.serialize(format=1) if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> @@ -90,7 +90,7 @@ if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http <body><p>hello</p></body> </html> """: - print("error serializing HTML document 3") + print "error serializing HTML document 3" sys.exit(1) str = doc.serialize("iso-8859-1", 1) if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> @@ -102,7 +102,7 @@ if str != """<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http <body><p>hello</p></body> </html> """: - print("error serializing HTML document 4") + print "error serializing HTML document 4" sys.exit(1) # @@ -112,11 +112,11 @@ doc.htmlSetMetaEncoding(None) root = doc.getRootElement() str = root.serialize() if str != """<html><head><title>Hello</title></head><body><p>hello</p></body></html>""": - print("error serializing HTML root 1") + print "error serializing HTML root 1" sys.exit(1) str = root.serialize("ISO-8859-1") if str != """<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Hello</title></head><body><p>hello</p></body></html>""": - print("error serializing HTML root 2") + print "error serializing HTML root 2" sys.exit(1) str = root.serialize(format=1) if str != """<html> @@ -126,7 +126,7 @@ if str != """<html> </head> <body><p>hello</p></body> </html>""": - print("error serializing HTML root 3") + print "error serializing HTML root 3" sys.exit(1) str = root.serialize("iso-8859-1", 1) if str != """<html> @@ -136,7 +136,7 @@ if str != """<html> </head> <body><p>hello</p></body> </html>""": - print("error serializing HTML root 4") + print "error serializing HTML root 4" sys.exit(1) doc.freeDoc() @@ -144,7 +144,7 @@ doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/sync.py b/python/tests/sync.py index 9d565db..2141875 100755 --- a/python/tests/sync.py +++ b/python/tests/sync.py @@ -50,8 +50,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 None:endElement bar2:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -62,8 +62,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 None:endElement bar2:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -74,8 +74,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 None:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -86,8 +86,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:endElement bar2:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -98,8 +98,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -110,8 +110,8 @@ ctxt=None reference = "startDocument:startElement foo None:startElement bar2 {'a': '1', 'b': '2'}:endElement bar2:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) log="" @@ -122,14 +122,14 @@ ctxt=None reference = "startDocument:startElement foo None:" if log != reference: - print("Error got: %s" % log) - print("Exprected: %s" % reference) + print "Error got: %s" % log + print "Exprected: %s" % reference sys.exit(1) # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/thread2.py b/python/tests/thread2.py index 2749eb0..c8ac5ed 100755 --- a/python/tests/thread2.py +++ b/python/tests/thread2.py @@ -1,9 +1,6 @@ #!/usr/bin/python -u import string, sys, time -try: - from _thread import get_ident -except: - from thread import get_ident +import thread from threading import Thread, Lock import libxml2 @@ -34,8 +31,8 @@ def test(expectedLineNumbersDefault): # check a per thread-global if expectedLineNumbersDefault != getLineNumbersDefault(): failed = 1 - print("FAILED to obtain correct value for " \ - "lineNumbersDefault in thread %d" % get_ident()) + print "FAILED to obtain correct value for " \ + "lineNumbersDefault in thread %d" % thread.get_ident() # check ther global error handler # (which is NOT per-thread in the python bindings) try: @@ -54,7 +51,7 @@ libxml2.lineNumbersDefault(1) test(1) ec = len(eh.errors) if ec == 0: - print("FAILED: should have obtained errors") + print "FAILED: should have obtained errors" sys.exit(1) ts = [] @@ -68,7 +65,7 @@ for t in ts: t.join() if len(eh.errors) != ec+THREADS_COUNT*ec: - print("FAILED: did not obtain the correct number of errors") + print "FAILED: did not obtain the correct number of errors" sys.exit(1) # set lineNumbersDefault for future new threads @@ -83,17 +80,17 @@ for t in ts: t.join() if len(eh.errors) != ec+THREADS_COUNT*ec*2: - print("FAILED: did not obtain the correct number of errors") + print "FAILED: did not obtain the correct number of errors" sys.exit(1) if failed: - print("FAILED") + print "FAILED" sys.exit(1) # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/tst.py b/python/tests/tst.py index 57a7318..9540cda 100755 --- a/python/tests/tst.py +++ b/python/tests/tst.py @@ -7,22 +7,22 @@ libxml2.debugMemory(1) doc = libxml2.parseFile("tst.xml") if doc.name != "tst.xml": - print("doc.name failed") + print "doc.name failed" sys.exit(1) root = doc.children if root.name != "doc": - print("root.name failed") + print "root.name failed" sys.exit(1) child = root.children if child.name != "foo": - print("child.name failed") + print "child.name failed" sys.exit(1) doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/tstLastError.py b/python/tests/tstLastError.py index d5f9be7..d26e82c 100755 --- a/python/tests/tstLastError.py +++ b/python/tests/tstLastError.py @@ -17,8 +17,8 @@ class TestCase(unittest.TestCase): if libxml2.debugMemory(1) != 0: libxml2.dumpMemory() self.fail("Memory leak %d bytes" % (libxml2.debugMemory(1),)) - else: - print("OK") + else: + print "OK" def failUnlessXmlError(self,f,args,exc,domain,code,message,level,file,line): """Run function f, with arguments args and expect an exception exc; @@ -27,19 +27,19 @@ class TestCase(unittest.TestCase): # disable the default error handler libxml2.registerErrorHandler(None,None) try: - f(*args) + apply(f,args) except exc: e = libxml2.lastError() if e is None: self.fail("lastError not set") if 0: - print("domain = ",e.domain()) - print("code = ",e.code()) - print("message =",repr(e.message())) - print("level =",e.level()) - print("file =",e.file()) - print("line =",e.line()) - print() + print "domain = ",e.domain() + print "code = ",e.code() + print "message =",repr(e.message()) + print "level =",e.level() + print "file =",e.file() + print "line =",e.line() + print self.failUnlessEqual(domain,e.domain()) self.failUnlessEqual(code,e.code()) self.failUnlessEqual(message,e.message()) diff --git a/python/tests/tstURI.py b/python/tests/tstURI.py index e4d58af..58b7ad8 100755 --- a/python/tests/tstURI.py +++ b/python/tests/tstURI.py @@ -7,35 +7,35 @@ libxml2.debugMemory(1) uri = libxml2.parseURI("http://example.org:8088/foo/bar?query=simple#fragid") if uri.scheme() != 'http': - print("Error parsing URI: wrong scheme") + print "Error parsing URI: wrong scheme" sys.exit(1) if uri.server() != 'example.org': - print("Error parsing URI: wrong server") + print "Error parsing URI: wrong server" sys.exit(1) if uri.port() != 8088: - print("Error parsing URI: wrong port") + print "Error parsing URI: wrong port" sys.exit(1) if uri.path() != '/foo/bar': - print("Error parsing URI: wrong path") + print "Error parsing URI: wrong path" sys.exit(1) if uri.query() != 'query=simple': - print("Error parsing URI: wrong query") + print "Error parsing URI: wrong query" sys.exit(1) if uri.fragment() != 'fragid': - print("Error parsing URI: wrong query") + print "Error parsing URI: wrong query" sys.exit(1) uri.setScheme("https") uri.setPort(223) uri.setFragment(None) result=uri.saveUri() if result != "https://example.org:223/foo/bar?query=simple": - print("Error modifying or saving the URI") + print "Error modifying or saving the URI" uri = None # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/tstmem.py b/python/tests/tstmem.py index 6b34cf3..553096d 100755 --- a/python/tests/tstmem.py +++ b/python/tests/tstmem.py @@ -19,7 +19,7 @@ libxml2mod.xmlSetValidErrors(ctxt._o, error, error) doc = libxml2.parseDoc(instance) ret = doc.validateDtd(ctxt, dtd) if ret != 1: - print("error doing DTD validation") + print "error doing DTD validation" sys.exit(1) doc.freeDoc() @@ -30,7 +30,7 @@ del ctxt # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/tstxpath.py b/python/tests/tstxpath.py index 0ba5a6d..e47c34d 100755 --- a/python/tests/tstxpath.py +++ b/python/tests/tstxpath.py @@ -25,10 +25,10 @@ doc = libxml2.parseFile("tst.xml") ctxt = doc.xpathNewContext() res = ctxt.xpathEval("//*") if len(res) != 2: - print("xpath query: wrong node set size") + print "xpath query: wrong node set size" sys.exit(1) if res[0].name != "doc" or res[1].name != "foo": - print("xpath query: wrong node set value") + print "xpath query: wrong node set value" sys.exit(1) libxml2.registerXPathFunction(ctxt._o, "foo", None, foo) libxml2.registerXPathFunction(ctxt._o, "bar", None, bar) @@ -36,28 +36,28 @@ i = 10000 while i > 0: res = ctxt.xpathEval("foo(1)") if res != 2: - print("xpath extension failure") + print "xpath extension failure" sys.exit(1) i = i - 1 i = 10000 while i > 0: res = ctxt.xpathEval("bar(1)") if res != "3": - print("xpath extension failure got %s expecting '3'") + print "xpath extension failure got %s expecting '3'" sys.exit(1) i = i - 1 doc.freeDoc() ctxt.xpathFreeContext() if called != "foo": - print("xpath function: failed to access the context") - print("xpath function: %s" % (called)) + print "xpath function: failed to access the context" + print "xpath function: %s" % (called) sys.exit(1) #memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/validDTD.py b/python/tests/validDTD.py index 4b03b8e..1222f9f 100755 --- a/python/tests/validDTD.py +++ b/python/tests/validDTD.py @@ -11,7 +11,7 @@ class ErrorHandler: def handler(self, msg, data): if data != ARG: - raise Exception("Error handler did not receive correct argument") + raise Exception, "Error handler did not receive correct argument" self.errors.append(msg) @@ -34,7 +34,7 @@ ctxt.setValidityErrorHandler(e.handler, e.handler, ARG) doc = libxml2.parseDoc(valid) ret = doc.validateDtd(ctxt, dtd) if ret != 1 or e.errors: - print("error doing DTD validation") + print "error doing DTD validation" sys.exit(1) doc.freeDoc() @@ -42,7 +42,7 @@ doc.freeDoc() doc = libxml2.parseDoc(invalid) ret = doc.validateDtd(ctxt, dtd) if ret != 0 or not e.errors: - print("Error: document supposed to be invalid") + print "Error: document supposed to be invalid" doc.freeDoc() dtd.freeDtd() @@ -52,8 +52,8 @@ del ctxt # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/validRNG.py b/python/tests/validRNG.py index 57f13a4..7022efe 100755 --- a/python/tests/validRNG.py +++ b/python/tests/validRNG.py @@ -11,7 +11,7 @@ class ErrorHandler: def handler(self, msg, data): if data != ARG: - raise Exception("Error handler did not receive correct argument") + raise Exception, "Error handler did not receive correct argument" self.errors.append(msg) # Memory debug specific @@ -49,7 +49,7 @@ ctxt.setValidityErrorHandler(e.handler, e.handler, ARG) doc = libxml2.parseDoc(valid) ret = doc.relaxNGValidateDoc(ctxt) if ret != 0 or e.errors: - print("error doing RelaxNG validation") + print "error doing RelaxNG validation" sys.exit(1) doc.freeDoc() @@ -57,7 +57,7 @@ doc.freeDoc() doc = libxml2.parseDoc(invalid) ret = doc.relaxNGValidateDoc(ctxt) if ret == 0 or not e.errors: - print("Error: document supposed to be RelaxNG invalid") + print "Error: document supposed to be RelaxNG invalid" sys.exit(1) doc.freeDoc() @@ -69,8 +69,8 @@ libxml2.relaxNGCleanupTypes() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/validSchemas.py b/python/tests/validSchemas.py index cc543f3..d4d62b2 100755 --- a/python/tests/validSchemas.py +++ b/python/tests/validSchemas.py @@ -11,7 +11,7 @@ class ErrorHandler: def handler(self, msg, data): if data != ARG: - raise Exception("Error handler did not receive correct argument") + raise Exception, "Error handler did not receive correct argument" self.errors.append(msg) # Memory debug specific @@ -56,7 +56,7 @@ ctxt_valid.setValidityErrorHandler(e.handler, e.handler, ARG) doc = libxml2.parseDoc(valid) ret = doc.schemaValidateDoc(ctxt_valid) if ret != 0 or e.errors: - print("error doing schema validation") + print "error doing schema validation" sys.exit(1) doc.freeDoc() @@ -64,7 +64,7 @@ doc.freeDoc() doc = libxml2.parseDoc(invalid) ret = doc.schemaValidateDoc(ctxt_valid) if ret == 0 or not e.errors: - print("Error: document supposer to be schema invalid") + print "Error: document supposer to be schema invalid" sys.exit(1) doc.freeDoc() @@ -76,8 +76,8 @@ libxml2.schemaCleanupTypes() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/validate.py b/python/tests/validate.py index 16c0386..0dc86f4 100755 --- a/python/tests/validate.py +++ b/python/tests/validate.py @@ -12,14 +12,14 @@ doc = ctxt.doc() valid = ctxt.isValid() if doc.name != "valid.xml": - print("doc.name failed") + print "doc.name failed" sys.exit(1) root = doc.children if root.name != "doc": - print("root.name failed") + print "root.name failed" sys.exit(1) if valid != 1: - print("validity chec failed") + print "validity chec failed" sys.exit(1) doc.freeDoc() @@ -32,7 +32,7 @@ while i > 0: valid = ctxt.isValid() doc.freeDoc() if valid != 1: - print("validity check failed") + print "validity check failed" sys.exit(1) i = i - 1 @@ -48,14 +48,14 @@ ctxt.parseDocument() doc = ctxt.doc() valid = ctxt.isValid() if doc.name != "invalid.xml": - print("doc.name failed") + print "doc.name failed" sys.exit(1) root = doc.children if root.name != "doc": - print("root.name failed") + print "root.name failed" sys.exit(1) if valid != 0: - print("validity chec failed") + print "validity chec failed" sys.exit(1) doc.freeDoc() @@ -68,7 +68,7 @@ while i > 0: valid = ctxt.isValid() doc.freeDoc() if valid != 0: - print("validity check failed") + print "validity check failed" sys.exit(1) i = i - 1 del ctxt @@ -76,7 +76,7 @@ del ctxt # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/walker.py b/python/tests/walker.py index 47f0557..3b5a62a 100755 --- a/python/tests/walker.py +++ b/python/tests/walker.py @@ -3,6 +3,7 @@ # this tests the entities substitutions with the XmlTextReader interface # import sys +import StringIO import libxml2 # Memory debug specific @@ -44,12 +45,12 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document test1") + print "Error parsing the document test1" sys.exit(1) if result != expect: - print("Unexpected result for test1") - print(result) + print "Unexpected result for test1" + print result sys.exit(1) doc.freeDoc() @@ -84,12 +85,12 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document test2") + print "Error parsing the document test2" sys.exit(1) if result != expect: - print("Unexpected result for test2") - print(result) + print "Unexpected result for test2" + print result sys.exit(1) doc.freeDoc() @@ -122,12 +123,12 @@ while ret == 1: ret = reader.Read() if ret != 0: - print("Error parsing the document test3") + print "Error parsing the document test3" sys.exit(1) if result != expect: - print("Unexpected result for test3") - print(result) + print "Unexpected result for test3" + print result sys.exit(1) # @@ -138,7 +139,7 @@ del reader # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/xpath.py b/python/tests/xpath.py index 72e6c9d..2e036e1 100755 --- a/python/tests/xpath.py +++ b/python/tests/xpath.py @@ -11,24 +11,24 @@ libxml2.debugMemory(1) doc = libxml2.parseFile("tst.xml") if doc.name != "tst.xml": - print("doc.name error") + print "doc.name error" sys.exit(1); ctxt = doc.xpathNewContext() res = ctxt.xpathEval("//*") if len(res) != 2: - print("xpath query: wrong node set size") + print "xpath query: wrong node set size" sys.exit(1) if res[0].name != "doc" or res[1].name != "foo": - print("xpath query: wrong node set value") + print "xpath query: wrong node set value" sys.exit(1) ctxt.setContextNode(res[0]) res = ctxt.xpathEval("foo") if len(res) != 1: - print("xpath query: wrong node set size") + print "xpath query: wrong node set size" sys.exit(1) if res[0].name != "foo": - print("xpath query: wrong node set value") + print "xpath query: wrong node set value" sys.exit(1) doc.freeDoc() ctxt.xpathFreeContext() @@ -45,7 +45,7 @@ del ctxt # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/xpathext.py b/python/tests/xpathext.py index b83d283..4769626 100755 --- a/python/tests/xpathext.py +++ b/python/tests/xpathext.py @@ -15,10 +15,10 @@ doc = libxml2.parseFile("tst.xml") ctxt = doc.xpathNewContext() res = ctxt.xpathEval("//*") if len(res) != 2: - print("xpath query: wrong node set size") + print "xpath query: wrong node set size" sys.exit(1) if res[0].name != "doc" or res[1].name != "foo": - print("xpath query: wrong node set value") + print "xpath query: wrong node set value" sys.exit(1) libxml2.registerXPathFunction(ctxt._o, "foo", None, foo) @@ -27,14 +27,14 @@ i = 10000 while i > 0: res = ctxt.xpathEval("foo(1)") if res != 2: - print("xpath extension failure") + print "xpath extension failure" sys.exit(1) i = i - 1 i = 10000 while i > 0: res = ctxt.xpathEval("bar(1)") if res != "3": - print("xpath extension failure got %s expecting '3'") + print "xpath extension failure got %s expecting '3'" sys.exit(1) i = i - 1 doc.freeDoc() @@ -43,7 +43,7 @@ ctxt.xpathFreeContext() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/xpathleak.py b/python/tests/xpathleak.py index 33ab61c..39f49e3 100755..100644 --- a/python/tests/xpathleak.py +++ b/python/tests/xpathleak.py @@ -42,24 +42,24 @@ badexprs = ( for expr in badexprs: try: ctxt.xpathEval(expr) - except libxml2.xpathError: + except libxml2.xpathError, e: pass else: - print("Unexpectedly legal expression:", expr) + print "Unexpectedly legal expression:", expr ctxt.xpathFreeContext() doc.freeDoc() if err != expect: - print("error") - print("received %s" %(err)) - print("expected %s" %(expect)) + print "error" + print "received %s" %(err) + print "expected %s" %(expect) sys.exit(1) libxml2.cleanupParser() leakedbytes = libxml2.debugMemory(True) if leakedbytes == 0: - print("OK") + print "OK" else: - print("Memory leak", leakedbytes, "bytes") + print "Memory leak", leakedbytes, "bytes" # drop file to .memdump file in cwd, but won't work if not compiled in libxml2.dumpMemory() diff --git a/python/tests/xpathns.py b/python/tests/xpathns.py index 379535e..e67e550 100755 --- a/python/tests/xpathns.py +++ b/python/tests/xpathns.py @@ -14,8 +14,8 @@ for n in d.xpathEval("//namespace::*"): d.freeDoc() if res != expect: - print("test5 failed: unexpected output") - print(res) + print "test5 failed: unexpected output" + print res del res del d del n @@ -23,7 +23,7 @@ del n libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() diff --git a/python/tests/xpathret.py b/python/tests/xpathret.py index 11c8b32..2b5576a 100755 --- a/python/tests/xpathret.py +++ b/python/tests/xpathret.py @@ -27,21 +27,21 @@ ctxt = doc.xpathNewContext() libxml2.registerXPathFunction(ctxt._o, "foo", None, foo) res = ctxt.xpathEval("foo('hello')") if type(res) != type([]): - print("Failed to return a nodeset") + print "Failed to return a nodeset" sys.exit(1) if len(res) != 1: - print("Unexpected nodeset size") + print "Unexpected nodeset size" sys.exit(1) node = res[0] if node.name != 'p': - print("Unexpected nodeset element result") + print "Unexpected nodeset element result" sys.exit(1) node = node.children if node.type != 'text': - print("Unexpected nodeset element children type") + print "Unexpected nodeset element children type" sys.exit(1) if node.content != 'hello': - print("Unexpected nodeset element children content") + print "Unexpected nodeset element children content" sys.exit(1) doc.freeDoc() @@ -51,7 +51,7 @@ ctxt.xpathFreeContext() #memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: - print("OK") + print "OK" else: - print("Memory leak %d bytes" % (libxml2.debugMemory(1))) + print "Memory leak %d bytes" % (libxml2.debugMemory(1)) libxml2.dumpMemory() |