Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r64490:f093a2c55499
Date: 2013-05-22 15:16 -0700
http://bitbucket.org/pypy/pypy/changeset/f093a2c55499/

Log:    fix tuple handling

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
@@ -725,35 +725,33 @@
                                                w_end, True)
     return space.newbool(stringendswith(u_self, w_suffix._value, start, end))
 
-def str_endswith__String_ANY_ANY_ANY(space, w_self, w_suffixes, w_start, 
w_end):
-    if not space.isinstance_w(w_suffixes, space.w_tuple):
-        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):
-        suffix = space.bufferstr_w(w_suffix)
+def str_endswith__String_ANY_ANY_ANY(space, w_self, w_suffix, w_start, w_end):
+    u_self, start, end = _convert_idx_params(space, w_self, w_start, w_end,
+                                             True)
+    if not space.isinstance_w(w_suffix, space.w_tuple):
+        suffix = _suffix_to_str(space, w_suffix, 'endswith')
+        return space.newbool(stringendswith(u_self, suffix, start, end))
+
+    for w_item in space.fixedview(w_suffix):
+        suffix = space.bufferstr_w(w_item)
         if stringendswith(u_self, suffix, start, end):
             return space.w_True
     return space.w_False
 
-def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefix, w_start, 
w_end):
-    (u_self, start, end) = _convert_idx_params(space, w_self, w_start,
-                                               w_end, True)
-    return space.newbool(stringstartswith(
-            u_self, _suffix_to_str(space, w_prefix, 'startswith'), start, end))
-
 def str_startswith__String_String_ANY_ANY(space, w_self, w_prefix, w_start, 
w_end):
     (u_self, start, end) = _convert_idx_params(space, w_self, w_start,
                                                w_end, True)
     return space.newbool(stringstartswith(u_self, w_prefix._value, start, end))
 
-def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefixes, w_start, 
w_end):
-    if not space.isinstance_w(w_prefixes, space.w_tuple):
-        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):
-        prefix = space.bufferstr_w(w_prefix)
+def str_startswith__String_ANY_ANY_ANY(space, w_self, w_prefix, w_start, 
w_end):
+    u_self, start, end = _convert_idx_params(space, w_self, w_start, w_end,
+                                             True)
+    if not space.isinstance_w(w_prefix, space.w_tuple):
+        prefix = _suffix_to_str(space, w_prefix, 'startswith')
+        return space.newbool(stringstartswith(u_self, prefix, start, end))
+
+    for w_item in space.fixedview(w_prefix):
+        prefix = space.bufferstr_w(w_item)
         if stringstartswith(u_self, prefix, start, end):
             return space.w_True
     return space.w_False
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
@@ -453,22 +453,11 @@
             space, len(self), w_start, w_end, upper_bound)
     return (self, start, end)
 
-def unicode_endswith__Unicode_ANY_ANY_ANY(space, w_self, w_substr, w_start, 
w_end):
-    typename = space.type(w_substr).getname(space)
-    msg = "endswith first arg must be str or a tuple of str, not %s" % typename
-    raise OperationError(space.w_TypeError, space.wrap(msg))
-
 def unicode_endswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, 
w_start, w_end):
     self, start, end = _convert_idx_params(space, w_self,
                                                    w_start, w_end, True)
     return space.newbool(stringendswith(self, w_substr._value, start, end))
 
-def unicode_startswith__Unicode_ANY_ANY_ANY(space, w_self, w_substr, w_start, 
w_end):
-    typename = space.type(w_substr).getname(space)
-    msg = ("startswith first arg must be str or a tuple of str, not %s" %
-           typename)
-    raise OperationError(space.w_TypeError, space.wrap(msg))
-
 def unicode_startswith__Unicode_Unicode_ANY_ANY(space, w_self, w_substr, 
w_start, w_end):
     self, start, end = _convert_idx_params(space, w_self, w_start, w_end, True)
     # XXX this stuff can be waaay better for ootypebased backends if
@@ -479,7 +468,11 @@
 def unicode_startswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_prefixes,
                                               w_start, w_end):
     if not space.isinstance_w(w_prefixes, space.w_tuple):
-        raise FailedToImplement
+        typename = space.type(w_prefixes).getname(space)
+        msg = ("startswith first arg must be str or a tuple of str, not %s" %
+               typename)
+        raise OperationError(space.w_TypeError, space.wrap(msg))
+
     unistr, start, end = _convert_idx_params(space, w_unistr,
                                              w_start, w_end, True)
     for w_prefix in space.fixedview(w_prefixes):
@@ -491,7 +484,10 @@
 def unicode_endswith__Unicode_ANY_ANY_ANY(space, w_unistr, w_suffixes,
                                             w_start, w_end):
     if not space.isinstance_w(w_suffixes, space.w_tuple):
-        raise FailedToImplement
+        typename = space.type(w_suffixes).getname(space)
+        msg = "endswith first arg must be str or a tuple of str, not %s" % 
typename
+        raise OperationError(space.w_TypeError, space.wrap(msg))
+
     unistr, start, end = _convert_idx_params(space, w_unistr,
                                              w_start, w_end, True)
     for w_suffix in space.fixedview(w_suffixes):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to