[pypy-commit] pypy py3k: Fixes in pyexpat module
amauryfa
noreply at buildbot.pypy.org
Sun Dec 18 19:34:22 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r50665:924692e049ba
Date: 2011-12-18 16:14 +0100
http://bitbucket.org/pypy/pypy/changeset/924692e049ba/
Log: Fixes in pyexpat module
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
@@ -606,11 +606,15 @@
# Parse methods
- @unwrap_spec(data=str, isfinal=bool)
- def Parse(self, space, data, isfinal=False):
+ @unwrap_spec(isfinal=bool)
+ def Parse(self, space, w_data, isfinal=False):
"""Parse(data[, isfinal])
Parse XML data. `isfinal' should be true at end of input."""
+ if space.isinstance_w(w_data, space.w_bytes):
+ data = space.bytes_w(w_data)
+ else:
+ data = space.str_w(w_data)
res = XML_Parse(self.itself, data, len(data), isfinal)
if self._exc_info:
e = self._exc_info
@@ -779,7 +783,7 @@
Return a new XML parser object."""
if space.is_w(w_encoding, space.w_None):
encoding = None
- elif space.is_true(space.isinstance(w_encoding, space.w_str)):
+ elif space.is_true(space.isinstance(w_encoding, space.w_unicode)):
encoding = space.str_w(w_encoding)
else:
type_name = space.type(w_encoding).getname(space)
@@ -790,7 +794,7 @@
if space.is_w(w_namespace_separator, space.w_None):
namespace_separator = 0
- elif space.is_true(space.isinstance(w_namespace_separator, space.w_str)):
+ elif space.is_true(space.isinstance(w_namespace_separator, space.w_unicode)):
separator = space.str_w(w_namespace_separator)
if len(separator) == 0:
namespace_separator = 0
@@ -839,5 +843,5 @@
def ErrorString(space, code):
"""ErrorString(errno) -> string
Returns string error for given number."""
- return space.wrapbytes(rffi.charp2str(XML_ErrorString(code)))
+ return space.wrap(rffi.charp2str(XML_ErrorString(code)))
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
@@ -42,7 +42,7 @@
import pyexpat
for encoding_arg in (None, 'utf-8', 'iso-8859-1'):
for namespace_arg in (None, '{'):
- print encoding_arg, namespace_arg
+ print(encoding_arg, namespace_arg)
p = pyexpat.ParserCreate(encoding_arg, namespace_arg)
data = []
p.CharacterDataHandler = lambda s: data.append(s)
@@ -83,7 +83,7 @@
def test_encoding_xml(self):
# use one of the few encodings built-in in expat
- xml = "<?xml version='1.0' encoding='iso-8859-1'?><s>caf\xe9</s>"
+ xml = b"<?xml version='1.0' encoding='iso-8859-1'?><s>caf\xe9</s>"
import pyexpat
p = pyexpat.ParserCreate()
def gotText(text):
@@ -93,7 +93,7 @@
p.Parse(xml)
def test_explicit_encoding(self):
- xml = "<?xml version='1.0'?><s>caf\xe9</s>"
+ xml = b"<?xml version='1.0'?><s>caf\xe9</s>"
import pyexpat
p = pyexpat.ParserCreate(encoding='iso-8859-1')
def gotText(text):
@@ -103,7 +103,7 @@
def test_python_encoding(self):
# This name is not knonwn by expat
- xml = "<?xml version='1.0' encoding='latin1'?><s>caf\xe9</s>"
+ xml = b"<?xml version='1.0' encoding='latin1'?><s>caf\xe9</s>"
import pyexpat
p = pyexpat.ParserCreate()
def gotText(text):
@@ -112,7 +112,7 @@
p.Parse(xml)
def test_decode_error(self):
- xml = '<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>'
+ xml = b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>'
import pyexpat
p = pyexpat.ParserCreate()
def f(*args): pass
More information about the pypy-commit
mailing list