diff -r e14e70e1a390 Lib/collections/__init__.py --- a/Lib/collections/__init__.py Tue Sep 20 04:04:33 2011 +0200 +++ b/Lib/collections/__init__.py Tue Sep 20 16:32:13 2011 +0100 @@ -1045,7 +1045,7 @@ return self.data.split(sep, maxsplit) def rsplit(self, sep=None, maxsplit=-1): return self.data.rsplit(sep, maxsplit) - def splitlines(self, keepends=0): return self.data.splitlines(keepends) + 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 strip(self, chars=None): return self.__class__(self.data.strip(chars)) diff -r e14e70e1a390 Lib/test/buffer_tests.py --- a/Lib/test/buffer_tests.py Tue Sep 20 04:04:33 2011 +0200 +++ b/Lib/test/buffer_tests.py Tue Sep 20 16:32:13 2011 +0100 @@ -200,7 +200,13 @@ self.marshal(b'abc\ndef\r\nghi\n\r').splitlines()) self.assertEqual([b'', b'abc', b'def', b'ghi', b''], self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines()) + self.assertEqual([b'', b'abc', b'def', b'ghi', b''], + self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(False)) self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], - self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(1)) + self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(True)) + self.assertEqual([b'', b'abc', b'def', b'ghi', b''], + self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=False)) + self.assertEqual([b'\n', b'abc\n', b'def\r\n', b'ghi\n', b'\r'], + self.marshal(b'\nabc\ndef\r\nghi\n\r').splitlines(keepends=True)) self.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42) diff -r e14e70e1a390 Lib/test/string_tests.py --- a/Lib/test/string_tests.py Tue Sep 20 04:04:33 2011 +0200 +++ b/Lib/test/string_tests.py Tue Sep 20 16:32:13 2011 +0100 @@ -47,11 +47,12 @@ return obj # check that obj.method(*args) returns result - def checkequal(self, result, obj, methodname, *args): + def checkequal(self, result, obj, methodname, *args, **kwargs): result = self.fixtype(result) obj = self.fixtype(obj) args = self.fixtype(args) - realresult = getattr(obj, methodname)(*args) + kwargs = self.fixtype(kwargs) + realresult = getattr(obj, methodname)(*args, **kwargs) self.assertEqual( result, realresult @@ -908,7 +909,14 @@ self.checkequal(['abc', 'def', 'ghi'], "abc\ndef\r\nghi\n", 'splitlines') self.checkequal(['abc', 'def', 'ghi', ''], "abc\ndef\r\nghi\n\r", 'splitlines') self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", 'splitlines') - self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], "\nabc\ndef\r\nghi\n\r", 'splitlines', 1) + self.checkequal(['', 'abc', 'def', 'ghi', ''], + "\nabc\ndef\r\nghi\n\r", 'splitlines', False) + self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], + "\nabc\ndef\r\nghi\n\r", 'splitlines', True) + self.checkequal(['', 'abc', 'def', 'ghi', ''], "\nabc\ndef\r\nghi\n\r", + 'splitlines', keepends=False) + self.checkequal(['\n', 'abc\n', 'def\r\n', 'ghi\n', '\r'], + "\nabc\ndef\r\nghi\n\r", 'splitlines', keepends=True) self.checkraises(TypeError, 'abc', 'splitlines', 42, 42) diff -r e14e70e1a390 Lib/test/test_userstring.py --- a/Lib/test/test_userstring.py Tue Sep 20 04:04:33 2011 +0200 +++ b/Lib/test/test_userstring.py Tue Sep 20 16:32:13 2011 +0100 @@ -17,11 +17,11 @@ # Overwrite the three testing methods, because UserString # can't cope with arguments propagated to UserString # (and we don't test with subclasses) - def checkequal(self, result, object, methodname, *args): + def checkequal(self, result, object, methodname, *args, **kwargs): result = self.fixtype(result) object = self.fixtype(object) # we don't fix the arguments, because UserString can't cope with it - realresult = getattr(object, methodname)(*args) + realresult = getattr(object, methodname)(*args, **kwargs) self.assertEqual( result, realresult diff -r e14e70e1a390 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Tue Sep 20 04:04:33 2011 +0200 +++ b/Objects/bytearrayobject.c Tue Sep 20 16:32:13 2011 +0100 @@ -2608,11 +2608,13 @@ is given and true."); static PyObject* -bytearray_splitlines(PyObject *self, PyObject *args) +bytearray_splitlines(PyObject *self, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"keepends", 0}; int keepends = 0; - if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines", + kwlist, &keepends)) return NULL; return stringlib_splitlines( @@ -2801,8 +2803,8 @@ {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS, rsplit__doc__}, {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__}, {"split", (PyCFunction)bytearray_split, METH_VARARGS, split__doc__}, - {"splitlines", (PyCFunction)bytearray_splitlines, METH_VARARGS, - splitlines__doc__}, + {"splitlines", (PyCFunction)bytearray_splitlines, + METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, {"startswith", (PyCFunction)bytearray_startswith, METH_VARARGS , startswith__doc__}, {"strip", (PyCFunction)bytearray_strip, METH_VARARGS, strip__doc__}, diff -r e14e70e1a390 Objects/bytesobject.c --- a/Objects/bytesobject.c Tue Sep 20 04:04:33 2011 +0200 +++ b/Objects/bytesobject.c Tue Sep 20 16:32:13 2011 +0100 @@ -2312,11 +2312,13 @@ is given and true."); static PyObject* -bytes_splitlines(PyObject *self, PyObject *args) +bytes_splitlines(PyObject *self, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"keepends", 0}; int keepends = 0; - if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines", + kwlist, &keepends)) return NULL; return stringlib_splitlines( @@ -2458,7 +2460,7 @@ {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__}, {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__}, {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__}, - {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS, + {"splitlines", (PyCFunction)bytes_splitlines, METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, {"startswith", (PyCFunction)bytes_startswith, METH_VARARGS, startswith__doc__}, diff -r e14e70e1a390 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Tue Sep 20 04:04:33 2011 +0200 +++ b/Objects/unicodeobject.c Tue Sep 20 16:32:13 2011 +0100 @@ -8881,11 +8881,13 @@ is given and true."); static PyObject* -unicode_splitlines(PyUnicodeObject *self, PyObject *args) -{ +unicode_splitlines(PyUnicodeObject *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"keepends", 0}; int keepends = 0; - if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:splitlines", + kwlist, &keepends)) return NULL; return PyUnicode_Splitlines((PyObject *)self, keepends); @@ -9273,7 +9275,7 @@ {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__}, {"rstrip", (PyCFunction) unicode_rstrip, METH_VARARGS, rstrip__doc__}, {"rpartition", (PyCFunction) unicode_rpartition, METH_O, rpartition__doc__}, - {"splitlines", (PyCFunction) unicode_splitlines, METH_VARARGS, splitlines__doc__}, + {"splitlines", (PyCFunction) unicode_splitlines, METH_VARARGS | METH_KEYWORDS, splitlines__doc__}, {"strip", (PyCFunction) unicode_strip, METH_VARARGS, strip__doc__}, {"swapcase", (PyCFunction) unicode_swapcase, METH_NOARGS, swapcase__doc__}, {"translate", (PyCFunction) unicode_translate, METH_O, translate__doc__},