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

afa at codespeak.net afa at codespeak.net
Tue Oct 19 19:23:16 CEST 2010


Author: afa
Date: Tue Oct 19 19:23:15 2010
New Revision: 78097

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:
bytearray.delslice, bytearray.append


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 19:23:15 2010
@@ -356,6 +356,11 @@
 # __________________________________________________________
 # Mutability methods
 
+def list_append__Bytearray_ANY(space, w_bytearray, w_item):
+    from pypy.objspace.std.bytearraytype import getbytevalue
+    w_bytearray.data.append(getbytevalue(space, w_item))
+    return space.w_None
+
 def list_extend__Bytearray_Bytearray(space, w_bytearray, w_other):
     w_bytearray.data += w_other.data
     return space.w_None
@@ -364,6 +369,12 @@
     w_bytearray.data += [c for c in space.str_w(w_other)]
     return space.w_None
 
+def delslice__Bytearray_ANY_ANY(space, w_bytearray, w_start, w_stop):
+    length = len(w_bytearray.data)
+    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
+    if start == stop:
+        return
+    del w_bytearray.data[start:stop]
 
 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 19:23:15 2010
@@ -15,9 +15,9 @@
     str_join, str_split, str_rsplit, str_partition, str_rpartition,
     str_splitlines)
 from pypy.objspace.std.listtype import (
-    list_extend)
+    list_append, list_extend)
 
-def _getbytevalue(space, w_value):
+def getbytevalue(space, w_value):
     if space.isinstance_w(w_value, space.w_str):
         string = space.str_w(w_value)
         if len(string) != 1:
@@ -72,7 +72,7 @@
             if not e.match(space, space.w_StopIteration):
                 raise
             break
-        value = _getbytevalue(space, w_item)
+        value = getbytevalue(space, w_item)
         data.append(value)
 
     return new_bytearray(space, w_bytearraytype, data)

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 19:23:15 2010
@@ -137,8 +137,21 @@
         check(b.partition(b'ss'), (b'mi', b'ss', b'issippi'))
         check(b.rpartition(b'ss'), (b'missi', b'ss', b'ippi'))
 
+    def test_append(self):
+        b = bytearray('abc')
+        b.append('d')
+        b.append(ord('e'))
+        assert b == 'abcde'
+
     def test_extend(self):
         b = bytearray('abc')
         b.extend(bytearray('def'))
         b.extend('ghi')
         assert b == 'abcdefghi'
+
+    def test_delslice(self):
+        b = bytearray('abcdefghi')
+        del b[5:8]
+        assert b == 'abcdei'
+        del b[:3]
+        assert b == 'dei'



More information about the Pypy-commit mailing list