[pypy-commit] pypy remove-tuple-smm: Fix string methods that take tuples as arguments (eg. 'ab'.startswith(('a', 'b'))).

Manuel Jacob noreply at buildbot.pypy.org
Wed May 22 11:50:11 CEST 2013


Author: Manuel Jacob
Branch: remove-tuple-smm
Changeset: r64432:81de1c3de10f
Date: 2013-05-22 11:47 +0200
http://bitbucket.org/pypy/pypy/changeset/81de1c3de10f/

Log:	Fix string methods that take tuples as arguments (eg.
	'ab'.startswith(('a', 'b'))).

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
@@ -14,7 +14,7 @@
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std.stringobject import W_StringObject
-from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.tupleobject import W_AbstractTupleObject
 from pypy.objspace.std.unicodeobject import W_UnicodeObject
 from pypy.objspace.std.util import get_positive_index
 from rpython.rlib.rstring import StringBuilder
@@ -310,31 +310,30 @@
                                                          w_start, w_stop)
 
 def str_startswith__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_prefix, w_start, w_stop):
+    if isinstance(w_prefix, W_AbstractTupleObject):
+        w_str = str__Bytearray(space, w_bytearray)
+        w_prefix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
+                                   space.unpackiterable(w_prefix)])
+        return stringobject.str_startswith__String_ANY_ANY_ANY(space, w_str, w_prefix,
+                                                                  w_start, w_stop)
+
     w_prefix = space.wrap(space.bufferstr_new_w(w_prefix))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_startswith__String_String_ANY_ANY(space, w_str, w_prefix,
                                                               w_start, w_stop)
 
-def str_startswith__Bytearray_Tuple_ANY_ANY(space, w_bytearray, w_prefix, w_start, w_stop):
-    w_str = str__Bytearray(space, w_bytearray)
-    w_prefix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
-                               space.unpackiterable(w_prefix)])
-    return stringobject.str_startswith__String_Tuple_ANY_ANY(space, w_str, w_prefix,
-                                                              w_start, w_stop)
-
 def str_endswith__Bytearray_ANY_ANY_ANY(space, w_bytearray, w_suffix, w_start, w_stop):
+    if isinstance(w_suffix, W_AbstractTupleObject):
+        w_str = str__Bytearray(space, w_bytearray)
+        w_suffix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
+                                   space.unpackiterable(w_suffix)])
+        return stringobject.str_endswith__String_ANY_ANY_ANY(space, w_str, w_suffix,
+                                                                  w_start, w_stop)
     w_suffix = space.wrap(space.bufferstr_new_w(w_suffix))
     w_str = str__Bytearray(space, w_bytearray)
     return stringobject.str_endswith__String_String_ANY_ANY(space, w_str, w_suffix,
                                                               w_start, w_stop)
 
-def str_endswith__Bytearray_Tuple_ANY_ANY(space, w_bytearray, w_suffix, w_start, w_stop):
-    w_str = str__Bytearray(space, w_bytearray)
-    w_suffix = space.newtuple([space.wrap(space.bufferstr_new_w(w_entry)) for w_entry in
-                               space.unpackiterable(w_suffix)])
-    return stringobject.str_endswith__String_Tuple_ANY_ANY(space, w_str, w_suffix,
-                                                              w_start, w_stop)
-
 def str_join__Bytearray_ANY(space, w_self, w_list):
     list_w = space.listview(w_list)
     if not list_w:
diff --git a/pypy/objspace/std/stringobject.py b/pypy/objspace/std/stringobject.py
--- a/pypy/objspace/std/stringobject.py
+++ b/pypy/objspace/std/stringobject.py
@@ -12,7 +12,7 @@
 from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
 from pypy.objspace.std.stringtype import (
     joined2, sliced, stringendswith, stringstartswith, wrapchar, wrapstr)
-from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.tupleobject import W_AbstractTupleObject
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import (
     compute_hash, compute_unique_id, specialize)
@@ -684,7 +684,9 @@
                                                w_end, True)
     return space.newbool(stringendswith(u_self, w_suffix._value, start, end))
 
-def str_endswith__String_Tuple_ANY_ANY(space, w_self, w_suffixes, w_start, w_end):
+def str_endswith__String_ANY_ANY_ANY(space, w_self, w_suffixes, w_start, w_end):
+    if not isinstance(w_suffixes, W_AbstractTupleObject):
+        raise FailedToImplement
     (u_self, start, end) = _convert_idx_params(space, w_self, w_start,
                                                w_end, True)
     for w_suffix in space.fixedview(w_suffixes):
@@ -702,7 +704,9 @@
                                                w_end, True)
     return space.newbool(stringstartswith(u_self, w_prefix._value, start, end))
 
-def str_startswith__String_Tuple_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
+def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
+    if not isinstance(w_prefixes, W_AbstractTupleObject):
+        raise FailedToImplement
     (u_self, start, end) = _convert_idx_params(space, w_self,
                                                w_start, w_end, True)
     for w_prefix in space.fixedview(w_prefixes):
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -12,7 +12,7 @@
     W_StringObject, make_rsplit_with_delim)
 from pypy.objspace.std.stringtype import stringendswith, stringstartswith
 from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.tupleobject import W_AbstractTupleObject
 from rpython.rlib import jit
 from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib.objectmodel import (
@@ -501,8 +501,10 @@
     #     with additional parameters as rpython)
     return space.newbool(stringstartswith(self, w_substr._value, start, end))
 
-def unicode_startswith__Unicode_Tuple_ANY_ANY(space, w_unistr, w_prefixes,
+def unicode_startswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_prefixes,
                                               w_start, w_end):
+    if not isinstance(w_prefixes, W_AbstractTupleObject):
+        raise FailedToImplement
     unistr, start, end = _convert_idx_params(space, w_unistr,
                                              w_start, w_end, True)
     for w_prefix in space.fixedview(w_prefixes):
@@ -511,8 +513,10 @@
             return space.w_True
     return space.w_False
 
-def unicode_endswith__Unicode_Tuple_ANY_ANY(space, w_unistr, w_suffixes,
+def unicode_endswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_suffixes,
                                             w_start, w_end):
+    if not isinstance(w_suffixes, W_AbstractTupleObject):
+        raise FailedToImplement
     unistr, start, end = _convert_idx_params(space, w_unistr,
                                              w_start, w_end, True)
     for w_suffix in space.fixedview(w_suffixes):


More information about the pypy-commit mailing list