[pypy-svn] r51360 - in pypy/dist/pypy/rlib: . test

fijal at codespeak.net fijal at codespeak.net
Sat Feb 9 17:26:34 CET 2008


Author: fijal
Date: Sat Feb  9 17:26:29 2008
New Revision: 51360

Modified:
   pypy/dist/pypy/rlib/rbuffer.py
   pypy/dist/pypy/rlib/test/test_rbuffer.py
Log:
getslice


Modified: pypy/dist/pypy/rlib/rbuffer.py
==============================================================================
--- pypy/dist/pypy/rlib/rbuffer.py	(original)
+++ pypy/dist/pypy/rlib/rbuffer.py	Sat Feb  9 17:26:29 2008
@@ -27,6 +27,9 @@
             raise IndexError(item)
         return self.ll_buffer[item]
 
+    def getslice(self, start, end):
+        return "".join([self.getitem(item) for item in range(start, end)])
+
     def setitem(self, item, value):
         if item >= self.size or item < 0:
             raise IndexError(item)

Modified: pypy/dist/pypy/rlib/test/test_rbuffer.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_rbuffer.py	(original)
+++ pypy/dist/pypy/rlib/test/test_rbuffer.py	Sat Feb  9 17:26:29 2008
@@ -21,3 +21,11 @@
         buf2 = RBuffer(7, buf.address() + 2)
         assert buf2.getitem(0) == '\x03'
         buf.free()
+
+    def test_getslice(self):
+        buf = RBuffer(10)
+        buf.setitem(0, '\x01')
+        buf.setitem(1, '\x02')
+        buf.setitem(2, '\x03')
+        assert buf.getslice(0, 3) == '\x01\x02\x03'
+        buf.free()



More information about the Pypy-commit mailing list