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

afa at codespeak.net afa at codespeak.net
Wed Sep 29 13:06:09 CEST 2010


Author: afa
Date: Wed Sep 29 13:06:08 2010
New Revision: 77465

Modified:
   pypy/branch/fast-forward/pypy/objspace/std/bytearrayobject.py
   pypy/branch/fast-forward/pypy/objspace/std/test/test_bytes.py
Log:
Implement comparison between bytearray and str


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	Wed Sep 29 13:06:08 2010
@@ -6,6 +6,7 @@
 from pypy.rlib.rarithmetic import intmask
 from pypy.rlib.rstring import StringBuilder
 from pypy.objspace.std.intobject import W_IntObject
+from pypy.objspace.std.stringobject import W_StringObject
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std import slicetype
 from pypy.interpreter import gateway
@@ -100,6 +101,16 @@
             return space.w_False
     return space.w_True
 
+def eq__Bytearray_String(space, w_bytearray1, w_string2):
+    data1 = w_bytearray1.data
+    data2 = w_string2._value
+    if len(data1) != len(data2):
+        return space.w_False
+    for i in range(len(data1)):
+        if data1[i] != data2[i]:
+            return space.w_False
+    return space.w_True
+
 def _min(a, b):
     if a < b:
         return a

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	Wed Sep 29 13:06:08 2010
@@ -41,3 +41,10 @@
         assert bytearray('hello') < bytearray('world')
         assert bytearray('world') > bytearray('hello')
 
+    def test_compare_str(self):
+        assert bytearray('hello') == 'hello'
+        assert 'hello' == bytearray('hello')
+        # unicode is always different
+        assert bytearray('hello') != u'hello'
+        assert u'hello' != bytearray('hello')
+



More information about the Pypy-commit mailing list