[pypy-svn] pypy bytearray: (mfoord) bytearray.splitlines

mfoord commits-noreply at bitbucket.org
Fri Jan 21 12:47:00 CET 2011


Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r41123:4fa6b9e56399
Date: 2011-01-21 12:41 +0100
http://bitbucket.org/pypy/pypy/changeset/4fa6b9e56399/

Log:	(mfoord) bytearray.splitlines

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
@@ -531,6 +531,12 @@
     w_res = stringobject.str_expandtabs__String_ANY(space, w_str, w_tabsize)
     return String2Bytearray(space, w_res)
 
+def str_splitlines__Bytearray_ANY(space, w_bytearray, w_keepends):
+    w_str = str__Bytearray(space, w_bytearray)
+    w_result = stringobject.str_splitlines__String_ANY(space, w_str, w_keepends)
+    return space.newlist([new_bytearray(space, space.w_bytearray, space.str_w(entry))
+                          for entry in space.unpackiterable(w_result)])
+
 def str_split__Bytearray_ANY_ANY(space, w_bytearray, w_by, w_maxsplit=-1):
     w_str = str__Bytearray(space, w_bytearray)
     if not space.is_w(w_by, space.w_None):

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
@@ -79,6 +79,15 @@
         assert bytearray('ll') in bytearray('hello')
         assert memoryview('ll') in bytearray('hello')
 
+    def test_splitlines(self):
+        b = bytearray('1234')
+        assert b.splitlines()[0] == b
+        assert b.splitlines()[0] is not b
+
+        assert len(bytearray('foo\nbar').splitlines()) == 2
+        for item in bytearray('foo\nbar').splitlines():
+            assert isinstance(item, bytearray)
+
     def test_ord(self):
         b = bytearray('\0A\x7f\x80\xff')
         assert ([ord(b[i:i+1]) for i in range(len(b))] ==


More information about the Pypy-commit mailing list