[pypy-svn] r78091 - in pypy/branch/fast-forward/pypy/objspace/std: . test

afa at codespeak.net afa at codespeak.net
Tue Oct 19 17:30:25 CEST 2010


Author: afa
Date: Tue Oct 19 17:30:23 2010
New Revision: 78091

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py
   pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py
Log:
Implement bytearray.extend


Modified: pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py	Tue Oct 19 17:30:23 2010
@@ -350,5 +350,17 @@
         String2Bytearray(space, w_b),
         String2Bytearray(space, w_c)])
 
+# __________________________________________________________
+# Mutability methods
+
+def list_extend__Bytearray_Bytearray(space, w_bytearray, w_other):
+    w_bytearray.data += w_other.data
+    return space.w_None
+
+def list_extend__Bytearray_ANY(space, w_bytearray, w_other):
+    w_bytearray.data += [c for c in space.str_w(w_other)]
+    return space.w_None
+
+
 from pypy.objspace.std import bytearraytype
 register_all(vars(), bytearraytype)

Modified: pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py	Tue Oct 19 17:30:23 2010
@@ -14,6 +14,8 @@
     str_ljust, str_rjust, str_center, str_zfill,
     str_join, str_split, str_rsplit, str_partition, str_rpartition,
     str_splitlines)
+from pypy.objspace.std.listtype import (
+    list_extend)
 
 def _getbytevalue(space, w_value):
     if space.isinstance_w(w_value, space.w_str):

Modified: pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py
==============================================================================
--- pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py	(original)
+++ pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py	Tue Oct 19 17:30:23 2010
@@ -131,3 +131,9 @@
 
         check(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
         check(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
+
+    def test_extend(self):
+        b = bytearray('abc')
+        b.extend(bytearray('def'))
+        b.extend('ghi')
+        assert b == 'abcdefghi'



More information about the Pypy-commit mailing list