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

mfoord commits-noreply at bitbucket.org
Tue Jan 18 18:46:56 CET 2011


Author: Michael Foord <michael at voidspace.org.uk>
Branch: bytearray
Changeset: r40894:6d05ae471b60
Date: 2011-01-18 18:47 +0100
http://bitbucket.org/pypy/pypy/changeset/6d05ae471b60/

Log:	(mfoord) bytearray.reverse

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
@@ -287,6 +287,9 @@
     except ValueError:
         raise OperationError(space.w_ValueError, space.wrap(
             "value not found in bytearray"))
+
+def bytearray_reverse__Bytearray(space, w_bytearray):
+    w_bytearray.data.reverse()
     return space.w_None
 
 # These methods could just delegate to the string implementation,

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
@@ -223,6 +223,10 @@
         b.remove(Indexable())
         assert b == ''
 
+    def test_reverse(self):
+        b = bytearray('hello')
+        b.reverse()
+        assert b == bytearray('olleh')
 
     def test_delitem(self):
         b = bytearray('abc')

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
@@ -33,6 +33,10 @@
                     doc="B.remove(int) -> None\n\n"
                     "Remove the first occurance of a value in B.")
 
+bytearray_reverse  = SMM('reverse', 1,
+                    doc="B.reverse() -> None\n\n"
+                    "Reverse the order of the values in B in place.")
+
 def getbytevalue(space, w_value):
     if space.isinstance_w(w_value, space.w_str):
         string = space.str_w(w_value)


More information about the Pypy-commit mailing list