[pypy-svn] pypy default: (mfoord, holger) recognize unicode/errors arg for bytearray constructor

hpk42 commits-noreply at bitbucket.org
Mon Jan 17 19:45:46 CET 2011


Author: holger krekel <holger at merlinux.eu>
Branch: 
Changeset: r40816:93d6145b7245
Date: 2011-01-17 19:44 +0100
http://bitbucket.org/pypy/pypy/changeset/93d6145b7245/

Log:	(mfoord, holger) recognize unicode/errors arg for bytearray
	constructor

diff --git a/pypy/objspace/std/test/test_bytes.py b/pypy/objspace/std/test/test_bytes.py
--- a/pypy/objspace/std/test/test_bytes.py
+++ b/pypy/objspace/std/test/test_bytes.py
@@ -22,6 +22,11 @@
             assert b == data.encode(encoding)
         raises(TypeError, bytearray, 9, 'utf8')
 
+    def test_encoding_with_ignore_errors(self):
+        data = u"H\u1234"
+        b = bytearray(data, "latin1", errors="ignore")
+        assert b == "H"
+
     def test_len(self):
         b = bytearray('test')
         assert len(b) == 4

diff --git a/pypy/objspace/std/bytearraytype.py b/pypy/objspace/std/bytearraytype.py
--- a/pypy/objspace/std/bytearraytype.py
+++ b/pypy/objspace/std/bytearraytype.py
@@ -47,7 +47,7 @@
         from pypy.objspace.std.unicodetype import (
             _get_encoding_and_errors, encode_object
         )
-        encoding, errors = _get_encoding_and_errors(space, w_encoding, space.w_None)
+        encoding, errors = _get_encoding_and_errors(space, w_encoding, w_errors)
 
         # if w_source is an integer this correctly raises a TypeError
         # the CPython error message is: "encoding or errors without a string argument"


More information about the Pypy-commit mailing list