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

afa at codespeak.net afa at codespeak.net
Tue Oct 19 18:25:38 CEST 2010


Author: afa
Date: Tue Oct 19 18:25:37 2010
New Revision: 78095

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py
Log:
Fix bytearray->str conversion


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 18:25:37 2010
@@ -104,7 +104,7 @@
 
 # bytearray-to-string delegation
 def delegate_Bytearray2String(space, w_bytearray):
-    return W_StringObject(''.join(w_bytearray.data))
+    return str__Bytearray(space, w_bytearray)
 
 def String2Bytearray(space, w_str):
     data = [c for c in space.str_w(w_str)]
@@ -188,6 +188,9 @@
 
     return space.wrap(buf.build())
 
+def str__Bytearray(space, w_bytearray):
+    return W_StringObject(''.join(w_bytearray.data))
+
 def _convert_idx_params(space, w_self, w_start, w_stop):
     start = slicetype._Eval_SliceIndex(space, w_start)
     stop = slicetype._Eval_SliceIndex(space, w_stop)

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 18:25:37 2010
@@ -27,6 +27,11 @@
         assert repr(bytearray('test')) == "bytearray(b'test')"
         assert repr(bytearray("d'oh")) == r"bytearray(b'd\'oh')"
 
+    def test_str(self):
+        assert str(bytearray()) == ""
+        assert str(bytearray('test')) == "test"
+        assert str(bytearray("d'oh")) == "d'oh"
+
     def test_getitem(self):
         b = bytearray('test')
         assert b[0] == ord('t')



More information about the Pypy-commit mailing list