cpython: 0b2660384d4e (original) (raw)

Mercurial > cpython

changeset 72462:0b2660384d4e

Issue #13012: Allow 'keepends' to be passed as a keyword argument in str.splitlines, bytes.splitlines and bytearray.splitlines. [#13012]

Mark Dickinson mdickinson@enthought.com
date Sat, 24 Sep 2011 09:14:39 +0100
parents 18eec56bcf29
children ac79caff7d6d
files Lib/test/buffer_tests.py Lib/test/string_tests.py Lib/test/test_userstring.py Misc/NEWS Objects/bytearrayobject.c Objects/bytesobject.c Objects/unicodeobject.c
diffstat 7 files changed, 41 insertions(+), 17 deletions(-)[+] [-] Lib/test/buffer_tests.py 8 Lib/test/string_tests.py 14 Lib/test/test_userstring.py 4 Misc/NEWS 4 Objects/bytearrayobject.c 10 Objects/bytesobject.c 8 Objects/unicodeobject.c 10

line wrap: on

line diff

--- a/Lib/test/buffer_tests.py +++ b/Lib/test/buffer_tests.py @@ -200,7 +200,13 @@ class MixinBytesBufferCommonTests(object 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.assertRaises(TypeError, self.marshal(b'abc').splitlines, 42, 42)

--- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -47,11 +47,12 @@ class BaseTest(unittest.TestCase): return obj # check that obj.method(*args) returns result

@@ -908,7 +909,14 @@ class MixinStrUnicodeUserStringTest: 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.checkraises(TypeError, 'abc', 'splitlines', 42, 42)

--- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -17,11 +17,11 @@ class UserStringTest( # Overwrite the three testing methods, because UserString # can't cope with arguments propagated to UserString # (and we don't test with subclasses)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #13012: The 'keepends' parameter to str.splitlines may now be passed

--- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2608,11 +2608,13 @@ Line breaks are not included in the resu is given and true."); static PyObject* -bytearray_splitlines(PyObject *self, PyObject *args) +bytearray_splitlines(PyObject *self, PyObject *args, PyObject *kwds) {

return stringlib_splitlines( @@ -2801,8 +2803,8 @@ bytearray_methods[] = { {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS, rsplit__doc__}, {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__}, {"split", (PyCFunction)bytearray_split, METH_VARARGS, split__doc__},

--- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2312,11 +2312,13 @@ Line breaks are not included in the resu is given and true."); static PyObject* -bytes_splitlines(PyObject *self, PyObject *args) +bytes_splitlines(PyObject *self, PyObject *args, PyObject *kwds) {

return stringlib_splitlines( @@ -2458,7 +2460,7 @@ bytes_methods[] = { {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS, rsplit__doc__}, {"rstrip", (PyCFunction)bytes_rstrip, METH_VARARGS, rstrip__doc__}, {"split", (PyCFunction)bytes_split, METH_VARARGS, split__doc__},

--- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8881,11 +8881,13 @@ Line breaks are not included in the resu is given and true."); static PyObject* -unicode_splitlines(PyUnicodeObject *self, PyObject *args) -{ +unicode_splitlines(PyUnicodeObject *self, PyObject *args, PyObject *kwds) +{

return PyUnicode_Splitlines((PyObject *)self, keepends); @@ -9273,7 +9275,7 @@ static PyMethodDef unicode_methods[] = { {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__}, {"rstrip", (PyCFunction) unicode_rstrip, METH_VARARGS, rstrip__doc__}, {"rpartition", (PyCFunction) unicode_rpartition, METH_O, rpartition__doc__},