[pypy-svn] pypy fast-forward: Forbid unicode in byetarray.extend() and BytesIO.write()

amauryfa commits-noreply at bitbucket.org
Fri Jan 7 17:56:08 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: fast-forward
Changeset: r40463:140879acbc80
Date: 2011-01-07 15:15 +0100
http://bitbucket.org/pypy/pypy/changeset/140879acbc80/

Log:	Forbid unicode in byetarray.extend() and BytesIO.write()

diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -4,6 +4,10 @@
     def setup_class(cls):
         cls.space = gettestobjspace(usemodules=['_io'])
 
+    def test_init(self):
+        import _io
+        raises(TypeError, _io.BytesIO, u"12345")
+
     def test_capabilities(self):
         import _io
         f = _io.BytesIO()

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
@@ -157,6 +157,8 @@
         b.extend(buffer('jkl'))
         assert b == 'abcdefghijkl'
 
+        raises(TypeError, b.extend, u"unicode")
+
     def test_delslice(self):
         b = bytearray('abcdefghi')
         del b[5:8]

diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -76,6 +76,9 @@
     @unwrap_spec('self', ObjSpace, W_Root)
     def write_w(self, space, w_data):
         self._check_closed(space)
+        if space.isinstance_w(w_data, space.w_unicode):
+            raise OperationError(space.w_TypeError, space.wrap(
+                "bytes string of buffer expected"))
         buf = space.buffer_w(w_data)
         length = buf.getlength()
         if length <= 0:

diff --git a/pypy/objspace/std/bytearrayobject.py b/pypy/objspace/std/bytearrayobject.py
--- a/pypy/objspace/std/bytearrayobject.py
+++ b/pypy/objspace/std/bytearrayobject.py
@@ -365,6 +365,9 @@
     w_bytearray.data += w_other.data
 
 def list_extend__Bytearray_ANY(space, w_bytearray, w_other):
+    if space.isinstance_w(w_other, space.w_unicode):
+        raise OperationError(space.w_TypeError, space.wrap(
+            "bytes string of buffer expected"))
     w_bytearray.data += [c for c in space.bufferstr_w(w_other)]
 
 def inplace_add__Bytearray_Bytearray(space, w_bytearray1, w_bytearray2):


More information about the Pypy-commit mailing list