[pypy-svn] pypy default: pyexpat.error constructor should accept only one message;

amauryfa commits-noreply at bitbucket.org
Thu Feb 10 11:41:30 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r41766:9a6df5a28474
Date: 2011-02-10 10:22 +0100
http://bitbucket.org/pypy/pypy/changeset/9a6df5a28474/

Log:	pyexpat.error constructor should accept only one message; other
	attributes are set after the object is built. This fixes one test in
	test_xml_etree

diff --git a/lib-python/TODO b/lib-python/TODO
--- a/lib-python/TODO
+++ b/lib-python/TODO
@@ -16,6 +16,8 @@
 - remove code duplication: bit_length() and _count_bits() in rlib/rbigint.py,
   objspace/std/longobject.py and objspace/std/longtype.py.
 
+- missing module pyexpat.errors
+
 
 Medium tasks
 ------------

diff --git a/pypy/module/pyexpat/app_pyexpat.py b/pypy/module/pyexpat/app_pyexpat.py
--- a/pypy/module/pyexpat/app_pyexpat.py
+++ b/pypy/module/pyexpat/app_pyexpat.py
@@ -1,6 +1,2 @@
 class ExpatError(Exception):
-    def __init__(self, msg, code, lineno, colno):
-        Exception.__init__(self, msg)
-        self.code = code
-        self.lineno = lineno
-        self.colno = colno
+    pass

diff --git a/pypy/module/pyexpat/interp_pyexpat.py b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -583,10 +583,11 @@
         msg = "%s: line %d, column %d" % (err, lineno, colno)
         w_module = space.getbuiltinmodule('pyexpat')
         w_errorcls = space.getattr(w_module, space.wrap('error'))
-        w_error = space.call_function(
-            w_errorcls,
-            space.wrap(msg), space.wrap(code),
-            space.wrap(colno), space.wrap(lineno))
+        w_error = space.call_function(w_errorcls, space.wrap(msg))
+        space.setattr(w_error, space.wrap("code"), space.wrap(code))
+        space.setattr(w_error, space.wrap("offset"), space.wrap(colno))
+        space.setattr(w_error, space.wrap("lineno"), space.wrap(lineno))
+
         self.w_error = w_error
         return OperationError(w_errorcls, w_error)
 

diff --git a/pypy/module/pyexpat/test/test_parser.py b/pypy/module/pyexpat/test/test_parser.py
--- a/pypy/module/pyexpat/test/test_parser.py
+++ b/pypy/module/pyexpat/test/test_parser.py
@@ -14,7 +14,12 @@
         res = p.Parse("<xml></xml>")
         assert res == 1
 
-        raises(pyexpat.ExpatError, p.Parse, "3")
+        exc = raises(pyexpat.ExpatError, p.Parse, "3")
+        assert exc.value.lineno == 1
+        assert exc.value.offset == 11
+        assert exc.value.code == 9 # XML_ERROR_JUNK_AFTER_DOC_ELEMENT
+
+        pyexpat.ExpatError("error")
 
     def test_encoding(self):
         import pyexpat


More information about the Pypy-commit mailing list