[pypy-commit] pypy py3k: UnicodeDecodeError accepts also bytearray
antocuni
noreply at buildbot.pypy.org
Fri Sep 14 11:19:20 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r57339:5bf1634cab2c
Date: 2012-09-12 17:38 +0200
http://bitbucket.org/pypy/pypy/changeset/5bf1634cab2c/
Log: UnicodeDecodeError accepts also bytearray
diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -677,14 +677,18 @@
def descr_init(self, space, w_encoding, w_object, w_start, w_end, w_reason):
# typechecking
+ if space.isinstance_w(w_object, space.w_bytearray):
+ w_bytes = space.wrapbytes(space.bufferstr_w(w_object))
+ else:
+ w_bytes = w_object
space.str_w(w_encoding)
- space.bytes_w(w_object)
+ space.bytes_w(w_bytes)
space.int_w(w_start)
space.int_w(w_end)
space.str_w(w_reason)
# assign attributes
self.w_encoding = w_encoding
- self.w_object = w_object
+ self.w_object = w_bytes
self.w_start = w_start
self.w_end = w_end
self.w_reason = w_reason
diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -126,19 +126,21 @@
assert str(e) == 'àèì'
def test_unicode_decode_error(self):
- ud = UnicodeDecodeError("x", b"y", 1, 5, "bah")
- assert ud.encoding == 'x'
- assert ud.object == b'y'
- assert ud.start == 1
- assert ud.end == 5
- assert ud.reason == 'bah'
- assert ud.args == ('x', b'y', 1, 5, 'bah')
- assert ud.message == ''
- ud.object = b'z9'
- assert ud.object == b'z9'
- assert str(ud) == "'x' codec can't decode bytes in position 1-4: bah"
- ud.end = 2
- assert str(ud) == "'x' codec can't decode byte 0x39 in position 1: bah"
+ for mybytes in (b'y', bytearray(b'y')):
+ ud = UnicodeDecodeError("x", mybytes, 1, 5, "bah")
+ assert ud.encoding == 'x'
+ assert ud.object == b'y'
+ assert type(ud.object) is bytes
+ assert ud.start == 1
+ assert ud.end == 5
+ assert ud.reason == 'bah'
+ assert ud.args == ('x', b'y', 1, 5, 'bah')
+ assert type(ud.args[1]) is type(mybytes)
+ ud.object = b'z9'
+ assert ud.object == b'z9'
+ assert str(ud) == "'x' codec can't decode bytes in position 1-4: bah"
+ ud.end = 2
+ assert str(ud) == "'x' codec can't decode byte 0x39 in position 1: bah"
def test_unicode_encode_error(self):
ue = UnicodeEncodeError("x", "y", 1, 5, "bah")
More information about the pypy-commit
mailing list