diff -r 1d7472b015f0 Lib/collections/__init__.py --- a/Lib/collections/__init__.py Sun Feb 26 18:09:50 2012 +0100 +++ b/Lib/collections/__init__.py Sun Feb 26 20:28:46 2012 +0100 @@ -1061,8 +1061,8 @@ return self.__class__(self.data.encode(encoding, errors)) return self.__class__(self.data.encode(encoding)) return self.__class__(self.data.encode()) - def endswith(self, suffix, start=0, end=_sys.maxsize): - return self.data.endswith(suffix, start, end) + def endswith(self, sub, start=0, end=_sys.maxsize): + return self.data.endswith(sub, start, end) def expandtabs(self, tabsize=8): return self.__class__(self.data.expandtabs(tabsize)) def find(self, sub, start=0, end=_sys.maxsize): @@ -1113,8 +1113,8 @@ def rsplit(self, sep=None, maxsplit=-1): return self.data.rsplit(sep, maxsplit) def splitlines(self, keepends=False): return self.data.splitlines(keepends) - def startswith(self, prefix, start=0, end=_sys.maxsize): - return self.data.startswith(prefix, start, end) + def startswith(self, sub, start=0, end=_sys.maxsize): + return self.data.startswith(sub, start, end) def strip(self, chars=None): return self.__class__(self.data.strip(chars)) def swapcase(self): return self.__class__(self.data.swapcase()) def title(self): return self.__class__(self.data.title()) diff -r 1d7472b015f0 Lib/test/string_tests.py --- a/Lib/test/string_tests.py Sun Feb 26 18:09:50 2012 +0100 +++ b/Lib/test/string_tests.py Sun Feb 26 20:28:46 2012 +0100 @@ -45,7 +45,7 @@ return tuple([self.fixtype(x) for x in obj]) elif isinstance(obj, dict): return dict([ - (self.fixtype(key), self.fixtype(value)) + (key, self.fixtype(value)) for (key, value) in obj.items() ]) else: @@ -75,14 +75,15 @@ realresult = getattr(obj, methodname)(*args) self.assertIsNot(obj, realresult) - # check that obj.method(*args) raises exc - def checkraises(self, exc, obj, methodname, *args): + # check that obj.method(*args, **kwargs) raises exc + def checkraises(self, exc, obj, methodname, *args, **kwargs): obj = self.fixtype(obj) args = self.fixtype(args) + kwargs = self.fixtype(kwargs) self.assertRaises( exc, getattr(obj, methodname), - *args + *args, **kwargs ) # call obj.method(*args) without any checks @@ -93,40 +94,67 @@ def test_count(self): self.checkequal(3, 'aaa', 'count', 'a') + self.checkequal(3, 'aaa', 'count', sub='a') + self.checkequal(0, 'aaa', 'count', 'b') + self.checkequal(0, 'aaa', 'count', sub='b') + self.checkequal(3, 'aaa', 'count', 'a') + self.checkequal(3, 'aaa', 'count', sub='a') self.checkequal(0, 'aaa', 'count', 'b') self.checkequal(3, 'aaa', 'count', 'a') + self.checkequal(3, 'aaa', 'count', sub='a') self.checkequal(0, 'aaa', 'count', 'b') - self.checkequal(3, 'aaa', 'count', 'a') + self.checkequal(0, 'aaa', 'count', sub='b') self.checkequal(0, 'aaa', 'count', 'b') - self.checkequal(0, 'aaa', 'count', 'b') + self.checkequal(0, 'aaa', 'count', sub='b') self.checkequal(2, 'aaa', 'count', 'a', 1) + self.checkequal(2, 'aaa', 'count', 'a', start=1) self.checkequal(0, 'aaa', 'count', 'a', 10) + self.checkequal(0, 'aaa', 'count', 'a', start=10) self.checkequal(1, 'aaa', 'count', 'a', -1) + self.checkequal(1, 'aaa', 'count', 'a', start=-1) self.checkequal(3, 'aaa', 'count', 'a', -10) + self.checkequal(3, 'aaa', 'count', 'a', start=-10) self.checkequal(1, 'aaa', 'count', 'a', 0, 1) + self.checkequal(1, 'aaa', 'count', 'a', start=0, end=1) self.checkequal(3, 'aaa', 'count', 'a', 0, 10) + self.checkequal(3, 'aaa', 'count', 'a', start=0, end=10) self.checkequal(2, 'aaa', 'count', 'a', 0, -1) + self.checkequal(2, 'aaa', 'count', 'a', start=0, end=-1) self.checkequal(0, 'aaa', 'count', 'a', 0, -10) + self.checkequal(0, 'aaa', 'count', sub='a', start=0, end=-10) self.checkequal(3, 'aaa', 'count', '', 1) + self.checkequal(3, 'aaa', 'count', '', start=1) self.checkequal(1, 'aaa', 'count', '', 3) + self.checkequal(1, 'aaa', 'count', '', start=3) self.checkequal(0, 'aaa', 'count', '', 10) + self.checkequal(0, 'aaa', 'count', sub='', start=10) self.checkequal(2, 'aaa', 'count', '', -1) + self.checkequal(2, 'aaa', 'count', sub='', start=-1) self.checkequal(4, 'aaa', 'count', '', -10) + self.checkequal(4, 'aaa', 'count', sub='', start=-10) self.checkequal(1, '', 'count', '') + self.checkequal(1, '', 'count', sub='') self.checkequal(0, '', 'count', '', 1, 1) + self.checkequal(0, '', 'count', sub='', start=1, end=1) self.checkequal(0, '', 'count', '', sys.maxsize, 0) + self.checkequal(0, '', 'count', sub='', start=sys.maxsize, end=0) self.checkequal(0, '', 'count', 'xx') + self.checkequal(0, '', 'count', sub='xx') self.checkequal(0, '', 'count', 'xx', 1, 1) + self.checkequal(0, '', 'count', sub='xx', start=1, end=1) self.checkequal(0, '', 'count', 'xx', sys.maxsize, 0) + self.checkequal(0, '', 'count', sub='xx', start=sys.maxsize, end=0) self.checkraises(TypeError, 'hello', 'count') if self.contains_bytes: self.checkequal(0, 'hello', 'count', 42) + self.checkequal(0, 'hello', 'count', sub=42) else: self.checkraises(TypeError, 'hello', 'count', 42) + self.checkraises(TypeError, 'hello', 'count', sub=42) # For a variety of combinations, # verify that str.count() matches an equivalent function @@ -157,37 +185,58 @@ def test_find(self): self.checkequal(0, 'abcdefghiabc', 'find', 'abc') + self.checkequal(0, 'abcdefghiabc', 'find', sub='abc') self.checkequal(9, 'abcdefghiabc', 'find', 'abc', 1) + self.checkequal(9, 'abcdefghiabc', 'find', sub='abc', start=1) self.checkequal(-1, 'abcdefghiabc', 'find', 'def', 4) + self.checkequal(-1, 'abcdefghiabc', 'find', sub='def', start=4) self.checkequal(0, 'abc', 'find', '', 0) + self.checkequal(0, 'abc', 'find', sub='', start=0) self.checkequal(3, 'abc', 'find', '', 3) + self.checkequal(3, 'abc', 'find', sub='', start=3) self.checkequal(-1, 'abc', 'find', '', 4) + self.checkequal(-1, 'abc', 'find', sub='', start=4) # to check the ability to pass None as defaults self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a') + self.checkequal( 2, 'rrarrrrrrrrra', 'find', sub='a') self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4) + self.checkequal(12, 'rrarrrrrrrrra', 'find', sub='a', start=4) self.checkequal(-1, 'rrarrrrrrrrra', 'find', 'a', 4, 6) + self.checkequal(-1, 'rrarrrrrrrrra', 'find', sub='a', start=4, end=6) self.checkequal(12, 'rrarrrrrrrrra', 'find', 'a', 4, None) + self.checkequal(12, 'rrarrrrrrrrra', 'find', sub='a', start=4, end=None) self.checkequal( 2, 'rrarrrrrrrrra', 'find', 'a', None, 6) + self.checkequal( 2, 'rrarrrrrrrrra', 'find', sub='a', start=None, end=6) self.checkraises(TypeError, 'hello', 'find') if self.contains_bytes: self.checkequal(-1, 'hello', 'find', 42) + self.checkequal(-1, 'hello', 'find', sub=42) else: self.checkraises(TypeError, 'hello', 'find', 42) + self.checkraises(TypeError, 'hello', 'find', sub=42) self.checkequal(0, '', 'find', '') + self.checkequal(0, '', 'find', sub='') self.checkequal(-1, '', 'find', '', 1, 1) + self.checkequal(-1, '', 'find', sub='', start=1, end=1) self.checkequal(-1, '', 'find', '', sys.maxsize, 0) + self.checkequal(-1, '', 'find', sub='', start=sys.maxsize, end=0) self.checkequal(-1, '', 'find', 'xx') + self.checkequal(-1, '', 'find', sub='xx') self.checkequal(-1, '', 'find', 'xx', 1, 1) + self.checkequal(-1, '', 'find', sub='xx', start=1, end=1) self.checkequal(-1, '', 'find', 'xx', sys.maxsize, 0) + self.checkequal(-1, '', 'find', sub='xx', start=sys.maxsize, end=0) # issue 7458 self.checkequal(-1, 'ab', 'find', 'xxx', sys.maxsize + 1, 0) + self.checkequal(-1, 'ab', 'find', sub='xxx', start=sys.maxsize + 1, + end=0) # For a variety of combinations, # verify that str.find() matches __contains__ @@ -214,27 +263,42 @@ def test_rfind(self): self.checkequal(9, 'abcdefghiabc', 'rfind', 'abc') + self.checkequal(9, 'abcdefghiabc', 'rfind', sub='abc') self.checkequal(12, 'abcdefghiabc', 'rfind', '') + self.checkequal(12, 'abcdefghiabc', 'rfind', sub='') self.checkequal(0, 'abcdefghiabc', 'rfind', 'abcd') + self.checkequal(0, 'abcdefghiabc', 'rfind', sub='abcd') self.checkequal(-1, 'abcdefghiabc', 'rfind', 'abcz') + self.checkequal(-1, 'abcdefghiabc', 'rfind', sub='abcz') self.checkequal(3, 'abc', 'rfind', '', 0) + self.checkequal(3, 'abc', 'rfind', sub='', start=0) self.checkequal(3, 'abc', 'rfind', '', 3) + self.checkequal(3, 'abc', 'rfind', sub='', start=3) self.checkequal(-1, 'abc', 'rfind', '', 4) + self.checkequal(-1, 'abc', 'rfind', sub='', start=4) # to check the ability to pass None as defaults self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a') + self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a') self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4) + self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a', start=4) self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', 'a', 4, 6) + self.checkequal(-1, 'rrarrrrrrrrra', 'rfind', sub='a', start=4, end=6) self.checkequal(12, 'rrarrrrrrrrra', 'rfind', 'a', 4, None) - self.checkequal( 2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6) + self.checkequal(12, 'rrarrrrrrrrra', 'rfind', sub='a', start=4, + end=None) + self.checkequal(2, 'rrarrrrrrrrra', 'rfind', 'a', None, 6) + self.checkequal(2, 'rrarrrrrrrrra', 'rfind', sub='a', start=None, end=6) self.checkraises(TypeError, 'hello', 'rfind') if self.contains_bytes: self.checkequal(-1, 'hello', 'rfind', 42) + self.checkequal(-1, 'hello', 'rfind', sub=42) else: self.checkraises(TypeError, 'hello', 'rfind', 42) + self.checkraises(TypeError, 'hello', 'rfind', sub=42) # For a variety of combinations, # verify that str.rfind() matches __contains__ @@ -264,54 +328,93 @@ def test_index(self): self.checkequal(0, 'abcdefghiabc', 'index', '') + self.checkequal(0, 'abcdefghiabc', 'index', sub='') self.checkequal(3, 'abcdefghiabc', 'index', 'def') + self.checkequal(3, 'abcdefghiabc', 'index', sub='def') self.checkequal(0, 'abcdefghiabc', 'index', 'abc') + self.checkequal(0, 'abcdefghiabc', 'index', sub='abc') self.checkequal(9, 'abcdefghiabc', 'index', 'abc', 1) + self.checkequal(9, 'abcdefghiabc', 'index', sub='abc', start=1) self.checkraises(ValueError, 'abcdefghiabc', 'index', 'hib') + self.checkraises(ValueError, 'abcdefghiabc', 'index', sub='hib') self.checkraises(ValueError, 'abcdefghiab', 'index', 'abc', 1) + self.checkraises(ValueError, 'abcdefghiab', 'index', sub='abc', start=1) self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', 8) + self.checkraises(ValueError, 'abcdefghi', 'index', sub='ghi', start=8) self.checkraises(ValueError, 'abcdefghi', 'index', 'ghi', -1) + self.checkraises(ValueError, 'abcdefghi', 'index', sub='ghi', start=-1) # to check the ability to pass None as defaults - self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a') + self.checkequal(2, 'rrarrrrrrrrra', 'index', 'a') + self.checkequal(2, 'rrarrrrrrrrra', 'index', sub='a') self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4) + self.checkequal(12, 'rrarrrrrrrrra', 'index', sub='a', start=4) self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', 'a', 4, 6) + self.checkraises(ValueError, 'rrarrrrrrrrra', 'index', sub='a', start=4, + end=6) self.checkequal(12, 'rrarrrrrrrrra', 'index', 'a', 4, None) - self.checkequal( 2, 'rrarrrrrrrrra', 'index', 'a', None, 6) + self.checkequal(12, 'rrarrrrrrrrra', 'index', sub='a', start=4, + end=None) + self.checkequal(2, 'rrarrrrrrrrra', 'index', sub='a', start=None, + end=6) self.checkraises(TypeError, 'hello', 'index') if self.contains_bytes: self.checkraises(ValueError, 'hello', 'index', 42) + self.checkraises(ValueError, 'hello', 'index', sub=42) else: self.checkraises(TypeError, 'hello', 'index', 42) + self.checkraises(TypeError, 'hello', 'index', sub=42) def test_rindex(self): self.checkequal(12, 'abcdefghiabc', 'rindex', '') + self.checkequal(12, 'abcdefghiabc', 'rindex', sub='') self.checkequal(3, 'abcdefghiabc', 'rindex', 'def') + self.checkequal(3, 'abcdefghiabc', 'rindex', sub='def') self.checkequal(9, 'abcdefghiabc', 'rindex', 'abc') + self.checkequal(9, 'abcdefghiabc', 'rindex', sub='abc') self.checkequal(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1) + self.checkequal(0, 'abcdefghiabc', 'rindex', sub='abc', start=0, + end=-1) self.checkraises(ValueError, 'abcdefghiabc', 'rindex', 'hib') + self.checkraises(ValueError, 'abcdefghiabc', 'rindex', sub='hib') self.checkraises(ValueError, 'defghiabc', 'rindex', 'def', 1) + self.checkraises(ValueError, 'defghiabc', 'rindex', sub='def', start=1) self.checkraises(ValueError, 'defghiabc', 'rindex', 'abc', 0, -1) + self.checkraises(ValueError, 'defghiabc', 'rindex', sub='abc', start=0, + end=-1) self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, 8) - self.checkraises(ValueError, 'abcdefghi', 'rindex', 'ghi', 0, -1) + self.checkraises(ValueError, 'abcdefghi', 'rindex', sub='ghi', start=0, + end=8) + self.checkraises(ValueError, 'abcdefghi', 'rindex', sub='ghi', start=0, + end=-1) # to check the ability to pass None as defaults self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a') + self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a') self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4) + self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a', start=4) self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', 'a', 4, 6) + self.checkraises(ValueError, 'rrarrrrrrrrra', 'rindex', sub='a', + start=4, end=6) self.checkequal(12, 'rrarrrrrrrrra', 'rindex', 'a', 4, None) - self.checkequal( 2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6) + self.checkequal(12, 'rrarrrrrrrrra', 'rindex', sub='a', start=4, + end=None) + self.checkequal(2, 'rrarrrrrrrrra', 'rindex', 'a', None, 6) + self.checkequal(2, 'rrarrrrrrrrra', 'rindex', sub='a', start=None, + end=6) self.checkraises(TypeError, 'hello', 'rindex') if self.contains_bytes: self.checkraises(ValueError, 'hello', 'rindex', 42) + self.checkraises(ValueError, 'hello', 'rindex', sub=42) else: self.checkraises(TypeError, 'hello', 'rindex', 42) + self.checkraises(TypeError, 'hello', 'rindex', sub=42) def test_lower(self): self.checkequal('hello', 'HeLLo', 'lower') @@ -969,97 +1072,197 @@ def test_startswith(self): self.checkequal(True, 'hello', 'startswith', 'he') + self.checkequal(True, 'hello', 'startswith', sub='he') self.checkequal(True, 'hello', 'startswith', 'hello') + self.checkequal(True, 'hello', 'startswith', sub='hello') self.checkequal(False, 'hello', 'startswith', 'hello world') + self.checkequal(False, 'hello', 'startswith', sub='hello world') self.checkequal(True, 'hello', 'startswith', '') + self.checkequal(True, 'hello', 'startswith', sub='') self.checkequal(False, 'hello', 'startswith', 'ello') + self.checkequal(False, 'hello', 'startswith', sub='ello') self.checkequal(True, 'hello', 'startswith', 'ello', 1) + self.checkequal(True, 'hello', 'startswith', sub='ello', start=1) self.checkequal(True, 'hello', 'startswith', 'o', 4) + self.checkequal(True, 'hello', 'startswith', sub='o', start=4) self.checkequal(False, 'hello', 'startswith', 'o', 5) + self.checkequal(False, 'hello', 'startswith', sub='o', start=5) self.checkequal(True, 'hello', 'startswith', '', 5) + self.checkequal(True, 'hello', 'startswith', sub='', start=5) self.checkequal(False, 'hello', 'startswith', 'lo', 6) + self.checkequal(False, 'hello', 'startswith', sub='lo', start=6) self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3) + self.checkequal(True, 'helloworld', 'startswith', sub='lowo', start=3) self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7) - self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6) + self.checkequal(True, 'helloworld', 'startswith', sub='lowo', start=3, + end=7) + self.checkequal(False, 'helloworld', 'startswith', sub='lowo', start=3, + end=6) # test negative indices self.checkequal(True, 'hello', 'startswith', 'he', 0, -1) + self.checkequal(True, 'hello', 'startswith', sub='he', start=0, end=-1) self.checkequal(True, 'hello', 'startswith', 'he', -53, -1) + self.checkequal(True, 'hello', 'startswith', sub='he', start=-53, + end=-1) self.checkequal(False, 'hello', 'startswith', 'hello', 0, -1) + self.checkequal(False, 'hello', 'startswith', sub='hello', start=0, + end=-1) self.checkequal(False, 'hello', 'startswith', 'hello world', -1, -10) + self.checkequal(False, 'hello', 'startswith', sub='hello world', + start=-1, end=-10) self.checkequal(False, 'hello', 'startswith', 'ello', -5) + self.checkequal(False, 'hello', 'startswith', sub='ello', start=-5) self.checkequal(True, 'hello', 'startswith', 'ello', -4) + self.checkequal(True, 'hello', 'startswith', sub='ello', start=-4) self.checkequal(False, 'hello', 'startswith', 'o', -2) + self.checkequal(False, 'hello', 'startswith', sub='o', start=-2) self.checkequal(True, 'hello', 'startswith', 'o', -1) + self.checkequal(True, 'hello', 'startswith', sub='o', start=-1) self.checkequal(True, 'hello', 'startswith', '', -3, -3) + self.checkequal(True, 'hello', 'startswith', sub='', start=-3, end=-3) self.checkequal(False, 'hello', 'startswith', 'lo', -9) + self.checkequal(False, 'hello', 'startswith', sub='lo', start=-9) self.checkraises(TypeError, 'hello', 'startswith') self.checkraises(TypeError, 'hello', 'startswith', 42) + self.checkraises(TypeError, 'hello', 'startswith', sub=42) # test tuple arguments self.checkequal(True, 'hello', 'startswith', ('he', 'ha')) + self.checkequal(True, 'hello', 'startswith', sub=('he', 'ha')) self.checkequal(False, 'hello', 'startswith', ('lo', 'llo')) + self.checkequal(False, 'hello', 'startswith', sub=('lo', 'llo')) self.checkequal(True, 'hello', 'startswith', ('hellox', 'hello')) + self.checkequal(True, 'hello', 'startswith', sub=('hellox', 'hello')) self.checkequal(False, 'hello', 'startswith', ()) + self.checkequal(False, 'hello', 'startswith', sub=()) self.checkequal(True, 'helloworld', 'startswith', ('hellowo', 'rld', 'lowo'), 3) + self.checkequal(True, 'helloworld', 'startswith', + sub=('hellowo', 'rld', 'lowo'), start=3) self.checkequal(False, 'helloworld', 'startswith', ('hellowo', 'ello', 'rld'), 3) + self.checkequal(False, 'helloworld', 'startswith', + sub=('hellowo', 'ello', 'rld'), start=3) self.checkequal(True, 'hello', 'startswith', ('lo', 'he'), 0, -1) + self.checkequal(True, 'hello', 'startswith', sub=('lo', 'he'), start=0, + end=-1) self.checkequal(False, 'hello', 'startswith', ('he', 'hel'), 0, 1) + self.checkequal(False, 'hello', 'startswith', sub=('he', 'hel'), + start=0, end=1) self.checkequal(True, 'hello', 'startswith', ('he', 'hel'), 0, 2) + self.checkequal(True, 'hello', 'startswith', sub=('he', 'hel'), + start=0, end=2) self.checkraises(TypeError, 'hello', 'startswith', (42,)) + self.checkraises(TypeError, 'hello', 'startswith', sub=(42,)) def test_endswith(self): self.checkequal(True, 'hello', 'endswith', 'lo') + self.checkequal(True, 'hello', 'endswith', sub='lo') self.checkequal(False, 'hello', 'endswith', 'he') + self.checkequal(False, 'hello', 'endswith', sub='he') self.checkequal(True, 'hello', 'endswith', '') + self.checkequal(True, 'hello', 'endswith', sub='') self.checkequal(False, 'hello', 'endswith', 'hello world') + self.checkequal(False, 'hello', 'endswith', sub='hello world') self.checkequal(False, 'helloworld', 'endswith', 'worl') + self.checkequal(False, 'helloworld', 'endswith', sub='worl') self.checkequal(True, 'helloworld', 'endswith', 'worl', 3, 9) + self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=3, + end=9) self.checkequal(True, 'helloworld', 'endswith', 'world', 3, 12) + self.checkequal(True, 'helloworld', 'endswith', sub='world', start=3, + end=12) self.checkequal(True, 'helloworld', 'endswith', 'lowo', 1, 7) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=1, + end=7) self.checkequal(True, 'helloworld', 'endswith', 'lowo', 2, 7) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=2, + end=7) self.checkequal(True, 'helloworld', 'endswith', 'lowo', 3, 7) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=3, + end=7) self.checkequal(False, 'helloworld', 'endswith', 'lowo', 4, 7) + self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=4, + end=7) self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8) + self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=3, + end=8) self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1) + self.checkequal(False, 'ab', 'endswith', sub='ab', start=0, end=1) self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0) + self.checkequal(False, 'ab', 'endswith', sub='ab', start=0, end=0) # test negative indices self.checkequal(True, 'hello', 'endswith', 'lo', -2) + self.checkequal(True, 'hello', 'endswith', sub='lo', start=-2) self.checkequal(False, 'hello', 'endswith', 'he', -2) + self.checkequal(False, 'hello', 'endswith', sub='he', start=-2) self.checkequal(True, 'hello', 'endswith', '', -3, -3) + self.checkequal(True, 'hello', 'endswith', sub='', start=-3, end=-3) self.checkequal(False, 'hello', 'endswith', 'hello world', -10, -2) + self.checkequal(False, 'hello', 'endswith', sub='hello world', + start=-10, end=-2) self.checkequal(False, 'helloworld', 'endswith', 'worl', -6) + self.checkequal(False, 'helloworld', 'endswith', sub='worl', start=-6) self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, -1) + self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=-5, + end=-1) self.checkequal(True, 'helloworld', 'endswith', 'worl', -5, 9) + self.checkequal(True, 'helloworld', 'endswith', sub='worl', start=-5, + end=9) self.checkequal(True, 'helloworld', 'endswith', 'world', -7, 12) + self.checkequal(True, 'helloworld', 'endswith', sub='world', start=-7, + end=12) self.checkequal(True, 'helloworld', 'endswith', 'lowo', -99, -3) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-99, + end=-3) self.checkequal(True, 'helloworld', 'endswith', 'lowo', -8, -3) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-8, + end=-3) self.checkequal(True, 'helloworld', 'endswith', 'lowo', -7, -3) + self.checkequal(True, 'helloworld', 'endswith', sub='lowo', start=-7, + end=-3) self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, -4) + self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=3, + end=-4) self.checkequal(False, 'helloworld', 'endswith', 'lowo', -8, -2) + self.checkequal(False, 'helloworld', 'endswith', sub='lowo', start=-8, + end=-2) self.checkraises(TypeError, 'hello', 'endswith') self.checkraises(TypeError, 'hello', 'endswith', 42) + self.checkraises(TypeError, 'hello', 'endswith', sub=42) # test tuple arguments self.checkequal(False, 'hello', 'endswith', ('he', 'ha')) + self.checkequal(False, 'hello', 'endswith', sub=('he', 'ha')) self.checkequal(True, 'hello', 'endswith', ('lo', 'llo')) + self.checkequal(True, 'hello', 'endswith', sub=('lo', 'llo')) self.checkequal(True, 'hello', 'endswith', ('hellox', 'hello')) + self.checkequal(True, 'hello', 'endswith', sub=('hellox', 'hello')) self.checkequal(False, 'hello', 'endswith', ()) + self.checkequal(False, 'hello', 'endswith', sub=()) self.checkequal(True, 'helloworld', 'endswith', ('hellowo', 'rld', 'lowo'), 3) + self.checkequal(True, 'helloworld', 'endswith', + sub=('hellowo','rld', 'lowo'), start=3) self.checkequal(False, 'helloworld', 'endswith', ('hellowo', 'ello', 'rld'), 3, -1) + self.checkequal(False, 'helloworld', 'endswith', + sub=('hellowo', 'ello','rld'), start=3, end=-1) self.checkequal(True, 'hello', 'endswith', ('hell', 'ell'), 0, -1) - self.checkequal(False, 'hello', 'endswith', ('he', 'hel'), 0, 1) - self.checkequal(True, 'hello', 'endswith', ('he', 'hell'), 0, 4) + self.checkequal(True, 'hello', 'endswith', sub=('hell', 'ell'), start=0, + end=-1) + self.checkequal(False, 'hello', 'endswith', sub=('he', 'hel'), start=0, + end=1) + self.checkequal(True, 'hello', 'endswith', sub=('he', 'hell'), start=0, + end=4) self.checkraises(TypeError, 'hello', 'endswith', (42,)) + self.checkraises(TypeError, 'hello', 'endswith', sub=(42,)) def test___contains__(self): self.checkequal(True, '', '__contains__', '') diff -r 1d7472b015f0 Lib/test/test_userstring.py --- a/Lib/test/test_userstring.py Sun Feb 26 18:09:50 2012 +0100 +++ b/Lib/test/test_userstring.py Sun Feb 26 20:28:46 2012 +0100 @@ -27,13 +27,14 @@ realresult ) - def checkraises(self, exc, object, methodname, *args): + def checkraises(self, exc, object, methodname, *args, **kwargs): object = self.fixtype(object) # we don't fix the arguments, because UserString can't cope with it self.assertRaises( exc, getattr(object, methodname), - *args + *args, + **kwargs ) def checkcall(self, object, methodname, *args): diff -r 1d7472b015f0 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Sun Feb 26 18:09:50 2012 +0100 +++ b/Objects/bytearrayobject.c Sun Feb 26 20:28:46 2012 +0100 @@ -1068,7 +1068,8 @@ } Py_LOCAL_INLINE(Py_ssize_t) -bytearray_find_internal(PyByteArrayObject *self, PyObject *args, int dir) +bytearray_find_internal(PyByteArrayObject *self, PyObject *args, PyObject *kwds, + int dir) { PyObject *subobj; char byte; @@ -1079,7 +1080,8 @@ Py_ssize_t res; if (!stringlib_parse_args_finds_byte("find/rfind/index/rindex", - args, &subobj, &byte, &start, &end)) + args, kwds, &subobj, &byte, &start, + &end)) return -2; if (subobj) { @@ -1119,9 +1121,9 @@ Return -1 on failure."); static PyObject * -bytearray_find(PyByteArrayObject *self, PyObject *args) +bytearray_find(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytearray_find_internal(self, args, +1); + Py_ssize_t result = bytearray_find_internal(self, args, kwds, +1); if (result == -2) return NULL; return PyLong_FromSsize_t(result); @@ -1135,7 +1137,7 @@ as in slice notation."); static PyObject * -bytearray_count(PyByteArrayObject *self, PyObject *args) +bytearray_count(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *sub_obj; const char *str = PyByteArray_AS_STRING(self), *sub; @@ -1146,7 +1148,7 @@ Py_buffer vsub; PyObject *count_obj; - if (!stringlib_parse_args_finds_byte("count", args, &sub_obj, &byte, + if (!stringlib_parse_args_finds_byte("count", args, kwds, &sub_obj, &byte, &start, &end)) return NULL; @@ -1205,9 +1207,9 @@ Like B.find() but raise ValueError when the subsection is not found."); static PyObject * -bytearray_index(PyByteArrayObject *self, PyObject *args) +bytearray_index(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytearray_find_internal(self, args, +1); + Py_ssize_t result = bytearray_find_internal(self, args, kwds, +1); if (result == -2) return NULL; if (result == -1) { @@ -1229,9 +1231,9 @@ Return -1 on failure."); static PyObject * -bytearray_rfind(PyByteArrayObject *self, PyObject *args) +bytearray_rfind(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytearray_find_internal(self, args, -1); + Py_ssize_t result = bytearray_find_internal(self, args, kwds, -1); if (result == -2) return NULL; return PyLong_FromSsize_t(result); @@ -1244,9 +1246,9 @@ Like B.rfind() but raise ValueError when the subsection is not found."); static PyObject * -bytearray_rindex(PyByteArrayObject *self, PyObject *args) +bytearray_rindex(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytearray_find_internal(self, args, -1); + Py_ssize_t result = bytearray_find_internal(self, args, kwds, -1); if (result == -2) return NULL; if (result == -1) { @@ -1334,14 +1336,15 @@ prefix can also be a tuple of bytes to try."); static PyObject * -bytearray_startswith(PyByteArrayObject *self, PyObject *args) +bytearray_startswith(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *subobj; int result; - if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("startswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -1377,14 +1380,15 @@ suffix can also be a tuple of bytes to try."); static PyObject * -bytearray_endswith(PyByteArrayObject *self, PyObject *args) +bytearray_endswith(PyByteArrayObject *self, PyObject *args, PyObject *kwds) { Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *subobj; int result; - if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("endswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -2833,16 +2837,16 @@ {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, clear__doc__}, {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, copy__doc__}, - {"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__}, + {"count", (PyCFunction)bytearray_count, METH_VARARGS | METH_KEYWORDS, count__doc__}, {"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc}, - {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__}, + {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS | METH_KEYWORDS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS, expandtabs__doc__}, {"extend", (PyCFunction)bytearray_extend, METH_O, extend__doc__}, - {"find", (PyCFunction)bytearray_find, METH_VARARGS, find__doc__}, + {"find", (PyCFunction)bytearray_find, METH_VARARGS | METH_KEYWORDS, find__doc__}, {"fromhex", (PyCFunction)bytearray_fromhex, METH_VARARGS|METH_CLASS, fromhex_doc}, - {"index", (PyCFunction)bytearray_index, METH_VARARGS, index__doc__}, + {"index", (PyCFunction)bytearray_index, METH_VARARGS | METH_KEYWORDS, index__doc__}, {"insert", (PyCFunction)bytearray_insert, METH_VARARGS, insert__doc__}, {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, @@ -2869,8 +2873,8 @@ {"remove", (PyCFunction)bytearray_remove, METH_O, remove__doc__}, {"replace", (PyCFunction)bytearray_replace, METH_VARARGS, replace__doc__}, {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, reverse__doc__}, - {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, rfind__doc__}, - {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, rindex__doc__}, + {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS | METH_KEYWORDS, rfind__doc__}, + {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS | METH_KEYWORDS, rindex__doc__}, {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, rpartition__doc__}, {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__}, @@ -2878,7 +2882,7 @@ {"split", (PyCFunction)bytearray_split, METH_VARARGS | METH_KEYWORDS, split__doc__}, {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, - {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS , + {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS | METH_KEYWORDS, startswith__doc__}, {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, strip__doc__}, {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, diff -r 1d7472b015f0 Objects/bytesobject.c --- a/Objects/bytesobject.c Sun Feb 26 18:09:50 2012 +0100 +++ b/Objects/bytesobject.c Sun Feb 26 20:28:46 2012 +0100 @@ -1220,7 +1220,8 @@ } Py_LOCAL_INLINE(Py_ssize_t) -bytes_find_internal(PyBytesObject *self, PyObject *args, int dir) +bytes_find_internal(PyBytesObject *self, PyObject *args, PyObject *kwds, + int dir) { PyObject *subobj; char byte; @@ -1231,7 +1232,8 @@ Py_ssize_t res; if (!stringlib_parse_args_finds_byte("find/rfind/index/rindex", - args, &subobj, &byte, &start, &end)) + args, kwds, &subobj, &byte, &start, + &end)) return -2; if (subobj) { @@ -1272,9 +1274,9 @@ Return -1 on failure."); static PyObject * -bytes_find(PyBytesObject *self, PyObject *args) +bytes_find(PyBytesObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytes_find_internal(self, args, +1); + Py_ssize_t result = bytes_find_internal(self, args, kwds, +1); if (result == -2) return NULL; return PyLong_FromSsize_t(result); @@ -1287,9 +1289,9 @@ Like B.find() but raise ValueError when the substring is not found."); static PyObject * -bytes_index(PyBytesObject *self, PyObject *args) +bytes_index(PyBytesObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytes_find_internal(self, args, +1); + Py_ssize_t result = bytes_find_internal(self, args, kwds, +1); if (result == -2) return NULL; if (result == -1) { @@ -1311,9 +1313,9 @@ Return -1 on failure."); static PyObject * -bytes_rfind(PyBytesObject *self, PyObject *args) +bytes_rfind(PyBytesObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytes_find_internal(self, args, -1); + Py_ssize_t result = bytes_find_internal(self, args, kwds, -1); if (result == -2) return NULL; return PyLong_FromSsize_t(result); @@ -1326,9 +1328,9 @@ Like B.rfind() but raise ValueError when the substring is not found."); static PyObject * -bytes_rindex(PyBytesObject *self, PyObject *args) +bytes_rindex(PyBytesObject *self, PyObject *args, PyObject *kwds) { - Py_ssize_t result = bytes_find_internal(self, args, -1); + Py_ssize_t result = bytes_find_internal(self, args, kwds, -1); if (result == -2) return NULL; if (result == -1) { @@ -1479,7 +1481,7 @@ as in slice notation."); static PyObject * -bytes_count(PyBytesObject *self, PyObject *args) +bytes_count(PyBytesObject *self, PyObject *args, PyObject *kwds) { PyObject *sub_obj; const char *str = PyBytes_AS_STRING(self), *sub; @@ -1490,7 +1492,7 @@ Py_buffer vsub; PyObject *count_obj; - if (!stringlib_parse_args_finds_byte("count", args, &sub_obj, &byte, + if (!stringlib_parse_args_finds_byte("count", args, kwds, &sub_obj, &byte, &start, &end)) return NULL; @@ -2212,14 +2214,15 @@ prefix can also be a tuple of bytes to try."); static PyObject * -bytes_startswith(PyBytesObject *self, PyObject *args) +bytes_startswith(PyBytesObject *self, PyObject *args, PyObject *kwds) { Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *subobj; int result; - if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("startswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -2256,14 +2259,15 @@ suffix can also be a tuple of bytes to try."); static PyObject * -bytes_endswith(PyBytesObject *self, PyObject *args) +bytes_endswith(PyBytesObject *self, PyObject *args, PyObject *kwds) { Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *subobj; int result; - if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("endswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -2437,16 +2441,16 @@ {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, - {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__}, + {"count", (PyCFunction)bytes_count, METH_VARARGS | METH_KEYWORDS, count__doc__}, {"decode", (PyCFunction)bytes_decode, METH_VARARGS | METH_KEYWORDS, decode__doc__}, - {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, + {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS | METH_KEYWORDS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS, expandtabs__doc__}, - {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__}, + {"find", (PyCFunction)bytes_find, METH_VARARGS | METH_KEYWORDS, find__doc__}, {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS, fromhex_doc}, - {"index", (PyCFunction)bytes_index, METH_VARARGS, index__doc__}, + {"index", (PyCFunction)bytes_index, METH_VARARGS | METH_KEYWORDS, index__doc__}, {"isalnum", (PyCFunction)stringlib_isalnum, METH_NOARGS, _Py_isalnum__doc__}, {"isalpha", (PyCFunction)stringlib_isalpha, METH_NOARGS, @@ -2469,8 +2473,8 @@ _Py_maketrans__doc__}, {"partition", (PyCFunction)bytes_partition, METH_O, partition__doc__}, {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__}, - {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__}, - {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__}, + {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS | METH_KEYWORDS, rfind__doc__}, + {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS | METH_KEYWORDS, rindex__doc__}, {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, {"rpartition", (PyCFunction)bytes_rpartition, METH_O, rpartition__doc__}, @@ -2479,7 +2483,7 @@ {"split", (PyCFunction)bytes_split, METH_VARARGS | METH_KEYWORDS, split__doc__}, {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, - {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS, + {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS | METH_KEYWORDS, startswith__doc__}, {"strip", (PyCFunction)bytes_strip, METH_VARARGS, strip__doc__}, {"swapcase", (PyCFunction)stringlib_swapcase, METH_NOARGS, diff -r 1d7472b015f0 Objects/stringlib/find.h --- a/Objects/stringlib/find.h Sun Feb 26 18:09:50 2012 +0100 +++ b/Objects/stringlib/find.h Sun Feb 26 20:28:46 2012 +0100 @@ -103,8 +103,8 @@ Py_LOCAL_INLINE(int) STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args, - PyObject **subobj, - Py_ssize_t *start, Py_ssize_t *end) + PyObject *kwds, PyObject **subobj, + Py_ssize_t *start, Py_ssize_t *end) { PyObject *tmp_subobj; Py_ssize_t tmp_start = 0; @@ -112,11 +112,13 @@ PyObject *obj_start=Py_None, *obj_end=Py_None; char format[FORMAT_BUFFER_SIZE] = "O|OO:"; size_t len = strlen(format); + static char *kwlist[] = {"sub", "start", "end", 0}; strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1); format[FORMAT_BUFFER_SIZE - 1] = '\0'; - if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, format, kwlist, &tmp_subobj, + &obj_start, &obj_end)) return 0; /* To support None in "start" and "end" arguments, meaning @@ -151,12 +153,12 @@ Py_LOCAL_INLINE(int) STRINGLIB(parse_args_finds_unicode)(const char * function_name, PyObject *args, - PyObject **substring, - Py_ssize_t *start, Py_ssize_t *end) + PyObject *kwds, PyObject **substring, + Py_ssize_t *start, Py_ssize_t *end) { PyObject *tmp_substring; - if(STRINGLIB(parse_args_finds)(function_name, args, &tmp_substring, + if(STRINGLIB(parse_args_finds)(function_name, args, kwds, &tmp_substring, start, end)) { tmp_substring = PyUnicode_FromObject(tmp_substring); if (!tmp_substring) @@ -181,14 +183,14 @@ Py_LOCAL_INLINE(int) STRINGLIB(parse_args_finds_byte)(const char *function_name, PyObject *args, - PyObject **subobj, char *byte, + PyObject *kwds, PyObject **subobj, char *byte, Py_ssize_t *start, Py_ssize_t *end) { PyObject *tmp_subobj; Py_ssize_t ival; PyObject *err; - if(!STRINGLIB(parse_args_finds)(function_name, args, &tmp_subobj, + if(!STRINGLIB(parse_args_finds)(function_name, args, kwds, &tmp_subobj, start, end)) return 0; diff -r 1d7472b015f0 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Sun Feb 26 18:09:50 2012 +0100 +++ b/Objects/unicodeobject.c Sun Feb 26 20:28:46 2012 +0100 @@ -11080,7 +11080,7 @@ interpreted as in slice notation."); static PyObject * -unicode_count(PyObject *self, PyObject *args) +unicode_count(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *substring; Py_ssize_t start = 0; @@ -11090,7 +11090,7 @@ void *buf1, *buf2; Py_ssize_t len1, len2, iresult; - if (!stringlib_parse_args_finds_unicode("count", args, &substring, + if (!stringlib_parse_args_finds_unicode("count", args, kwds, &substring, &start, &end)) return NULL; @@ -11271,14 +11271,14 @@ Return -1 on failure."); static PyObject * -unicode_find(PyObject *self, PyObject *args) +unicode_find(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *substring; Py_ssize_t start; Py_ssize_t end; Py_ssize_t result; - if (!stringlib_parse_args_finds_unicode("find", args, &substring, + if (!stringlib_parse_args_finds_unicode("find", args, kwds, &substring, &start, &end)) return NULL; @@ -11372,14 +11372,14 @@ Like S.find() but raise ValueError when the substring is not found."); static PyObject * -unicode_index(PyObject *self, PyObject *args) +unicode_index(PyObject *self, PyObject *args, PyObject *kwds) { Py_ssize_t result; PyObject *substring; Py_ssize_t start; Py_ssize_t end; - if (!stringlib_parse_args_finds_unicode("index", args, &substring, + if (!stringlib_parse_args_finds_unicode("index", args, kwds, &substring, &start, &end)) return NULL; @@ -12388,14 +12388,14 @@ Return -1 on failure."); static PyObject * -unicode_rfind(PyObject *self, PyObject *args) +unicode_rfind(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *substring; Py_ssize_t start; Py_ssize_t end; Py_ssize_t result; - if (!stringlib_parse_args_finds_unicode("rfind", args, &substring, + if (!stringlib_parse_args_finds_unicode("rfind", args, kwds, &substring, &start, &end)) return NULL; @@ -12420,14 +12420,14 @@ Like S.rfind() but raise ValueError when the substring is not found."); static PyObject * -unicode_rindex(PyObject *self, PyObject *args) +unicode_rindex(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *substring; Py_ssize_t start; Py_ssize_t end; Py_ssize_t result; - if (!stringlib_parse_args_finds_unicode("rindex", args, &substring, + if (!stringlib_parse_args_finds_unicode("rindex", args, kwds, &substring, &start, &end)) return NULL; @@ -13004,8 +13004,7 @@ prefix can also be a tuple of strings to try."); static PyObject * -unicode_startswith(PyObject *self, - PyObject *args) +unicode_startswith(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *subobj; PyObject *substring; @@ -13013,7 +13012,8 @@ Py_ssize_t end = PY_SSIZE_T_MAX; int result; - if (!stringlib_parse_args_finds("startswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("startswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -13052,8 +13052,7 @@ suffix can also be a tuple of strings to try."); static PyObject * -unicode_endswith(PyObject *self, - PyObject *args) +unicode_endswith(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *subobj; PyObject *substring; @@ -13061,7 +13060,8 @@ Py_ssize_t end = PY_SSIZE_T_MAX; int result; - if (!stringlib_parse_args_finds("endswith", args, &subobj, &start, &end)) + if (!stringlib_parse_args_finds("endswith", args, kwds, &subobj, &start, + &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; @@ -13178,16 +13178,16 @@ {"casefold", (PyCFunction) unicode_casefold, METH_NOARGS, casefold__doc__}, {"title", (PyCFunction) unicode_title, METH_NOARGS, title__doc__}, {"center", (PyCFunction) unicode_center, METH_VARARGS, center__doc__}, - {"count", (PyCFunction) unicode_count, METH_VARARGS, count__doc__}, + {"count", (PyCFunction) unicode_count, METH_VARARGS | METH_KEYWORDS, count__doc__}, {"expandtabs", (PyCFunction) unicode_expandtabs, METH_VARARGS, expandtabs__doc__}, - {"find", (PyCFunction) unicode_find, METH_VARARGS, find__doc__}, + {"find", (PyCFunction) unicode_find, METH_VARARGS | METH_KEYWORDS, find__doc__}, {"partition", (PyCFunction) unicode_partition, METH_O, partition__doc__}, - {"index", (PyCFunction) unicode_index, METH_VARARGS, index__doc__}, + {"index", (PyCFunction) unicode_index, METH_VARARGS | METH_KEYWORDS, index__doc__}, {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__}, {"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__}, {"lstrip", (PyCFunction) unicode_lstrip, METH_VARARGS, lstrip__doc__}, - {"rfind", (PyCFunction) unicode_rfind, METH_VARARGS, rfind__doc__}, - {"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__}, + {"rfind", (PyCFunction) unicode_rfind, METH_VARARGS | METH_KEYWORDS, rfind__doc__}, + {"rindex", (PyCFunction) unicode_rindex, METH_VARARGS | METH_KEYWORDS, rindex__doc__}, {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__}, {"rstrip", (PyCFunction) unicode_rstrip, METH_VARARGS, rstrip__doc__}, {"rpartition", (PyCFunction) unicode_rpartition, METH_O, rpartition__doc__}, @@ -13196,8 +13196,8 @@ {"swapcase", (PyCFunction) unicode_swapcase, METH_NOARGS, swapcase__doc__}, {"translate", (PyCFunction) unicode_translate, METH_O, translate__doc__}, {"upper", (PyCFunction) unicode_upper, METH_NOARGS, upper__doc__}, - {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__}, - {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__}, + {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS | METH_KEYWORDS, startswith__doc__}, + {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS | METH_KEYWORDS, endswith__doc__}, {"islower", (PyCFunction) unicode_islower, METH_NOARGS, islower__doc__}, {"isupper", (PyCFunction) unicode_isupper, METH_NOARGS, isupper__doc__}, {"istitle", (PyCFunction) unicode_istitle, METH_NOARGS, istitle__doc__},