[pypy-svn] r77459 - pypy/branch/fast-forward/pypy/objspace/std

afa at codespeak.net afa at codespeak.net
Tue Sep 28 19:02:56 CEST 2010


Author: afa
Date: Tue Sep 28 19:02:55 2010
New Revision: 77459

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py
   pypy/branch/fast-forward/pypy/objspace/std/bytearraytype.py
Log:
Translation fixes


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 Sep 28 19:02:55 2010
@@ -49,7 +49,8 @@
     length = len(data)
     start, stop, step, slicelength = w_slice.indices4(space, length)
     assert slicelength >= 0
-    return W_BytearrayObject(data[start:stop:step])
+    newdata = [data[start + i*step] for i in range(slicelength)]
+    return W_BytearrayObject(newdata)
 
 def getslice__Bytearray_ANY_ANY(space, w_bytearray, w_start, w_stop):
     length = len(w_bytearray.data)
@@ -159,20 +160,19 @@
 
     return space.wrap(buf.build())
 
-def getnewargs__Bytearray(space, w_bytearray):
-    return space.newbytearray([W_BytearrayObject(w_bytearray.wrappeditems)])
-
-def bytearray_count__Bytearray_ANY(space, w_bytearray, w_obj):
+def bytearray_count__Bytearray_Int(space, w_bytearray, w_char):
+    char = w_char.intval
     count = 0
-    for w_item in w_bytearray.wrappeditems:
-        if space.eq_w(w_item, w_obj):
+    for c in w_bytearray.data:
+        if ord(c) == char:
             count += 1
     return space.wrap(count)
 
-def bytearray_index__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_obj, w_start, w_stop):
+def bytearray_index__Bytearray_Int_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop):
+    char = w_char.intval
     start = slicetype._Eval_SliceIndex(space, w_start)
     stop = slicetype._Eval_SliceIndex(space, w_stop)
-    length = len(w_bytearray.wrappeditems)
+    length = len(w_bytearray.data)
     if start < 0:
         start += length
         if start < 0:
@@ -182,8 +182,8 @@
         if stop < 0:
             stop = 0
     for i in range(start, min(stop, length)):
-        w_item = w_bytearray.wrappeditems[i]
-        if space.eq_w(w_item, w_obj):
+        c = w_bytearray.data[i]
+        if ord(c) == char:
             return space.wrap(i)
     raise OperationError(space.w_ValueError,
                          space.wrap("bytearray.index(x): x not in bytearray"))

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 Sep 28 19:02:55 2010
@@ -20,10 +20,7 @@
 def descr__new__(space, w_bytearraytype,
                  w_source='', w_encoding=None, w_errors=None):
     from pypy.objspace.std.bytearrayobject import W_BytearrayObject
-    if w_source is None:
-        data = []
-    else:
-        data = space.str_w(w_source)
+    data = [c for c in space.str_w(w_source)]
     w_obj = space.allocate_instance(W_BytearrayObject, w_bytearraytype)
     W_BytearrayObject.__init__(w_obj, data)
     return w_obj



More information about the Pypy-commit mailing list