diff -r 967f368b7f75 Objects/bytearrayobject.c --- a/Objects/bytearrayobject.c Sun Jan 19 00:38:36 2014 +0200 +++ b/Objects/bytearrayobject.c Tue Jan 21 01:13:17 2014 +0200 @@ -2825,14 +2825,13 @@ {"append", (PyCFunction)bytearray_append, METH_O, append__doc__}, {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, - {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, + STRINGLIB_CENTER_METHODDEF {"clear", (PyCFunction)bytearray_clear, METH_NOARGS, clear__doc__}, {"copy", (PyCFunction)bytearray_copy, METH_NOARGS, copy__doc__}, {"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__}, {"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc}, {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__}, - {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS, - expandtabs__doc__}, + STRINGLIB_EXPANDTABS_METHODDEF {"extend", (PyCFunction)bytearray_extend, METH_O, extend__doc__}, {"find", (PyCFunction)bytearray_find, METH_VARARGS, find__doc__}, {"fromhex", (PyCFunction)bytearray_fromhex, METH_VARARGS|METH_CLASS, @@ -2854,7 +2853,7 @@ {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, {"join", (PyCFunction)bytearray_join, METH_O, join_doc}, - {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__}, + STRINGLIB_LJUST_METHODDEF {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, {"lstrip", (PyCFunction)bytearray_lstrip, METH_VARARGS, lstrip__doc__}, {"maketrans", (PyCFunction)bytearray_maketrans, METH_VARARGS|METH_STATIC, @@ -2866,7 +2865,7 @@ {"reverse", (PyCFunction)bytearray_reverse, METH_NOARGS, reverse__doc__}, {"rfind", (PyCFunction)bytearray_rfind, METH_VARARGS, rfind__doc__}, {"rindex", (PyCFunction)bytearray_rindex, METH_VARARGS, rindex__doc__}, - {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, + STRINGLIB_RJUST_METHODDEF {"rpartition", (PyCFunction)bytearray_rpartition, METH_O, rpartition__doc__}, {"rsplit", (PyCFunction)bytearray_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__}, {"rstrip", (PyCFunction)bytearray_rstrip, METH_VARARGS, rstrip__doc__}, @@ -2882,7 +2881,7 @@ {"translate", (PyCFunction)bytearray_translate, METH_VARARGS, translate__doc__}, {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, - {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__}, + STRINGLIB_ZFILL_METHODDEF {NULL} }; diff -r 967f368b7f75 Objects/bytesobject.c --- a/Objects/bytesobject.c Sun Jan 19 00:38:36 2014 +0200 +++ b/Objects/bytesobject.c Tue Jan 21 01:13:17 2014 +0200 @@ -2397,13 +2397,12 @@ {"__getnewargs__", (PyCFunction)bytes_getnewargs, METH_NOARGS}, {"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS, _Py_capitalize__doc__}, - {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, + STRINGLIB_CENTER_METHODDEF {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__}, {"decode", (PyCFunction)bytes_decode, METH_VARARGS | METH_KEYWORDS, decode__doc__}, {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__}, - {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS | METH_KEYWORDS, - expandtabs__doc__}, + STRINGLIB_EXPANDTABS_METHODDEF {"find", (PyCFunction)bytes_find, METH_VARARGS, find__doc__}, {"fromhex", (PyCFunction)bytes_fromhex, METH_VARARGS|METH_CLASS, fromhex_doc}, @@ -2423,7 +2422,7 @@ {"isupper", (PyCFunction)stringlib_isupper, METH_NOARGS, _Py_isupper__doc__}, {"join", (PyCFunction)bytes_join, METH_O, join__doc__}, - {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, ljust__doc__}, + STRINGLIB_LJUST_METHODDEF {"lower", (PyCFunction)stringlib_lower, METH_NOARGS, _Py_lower__doc__}, {"lstrip", (PyCFunction)bytes_lstrip, METH_VARARGS, lstrip__doc__}, {"maketrans", (PyCFunction)bytes_maketrans, METH_VARARGS|METH_STATIC, @@ -2432,7 +2431,7 @@ {"replace", (PyCFunction)bytes_replace, METH_VARARGS, replace__doc__}, {"rfind", (PyCFunction)bytes_rfind, METH_VARARGS, rfind__doc__}, {"rindex", (PyCFunction)bytes_rindex, METH_VARARGS, rindex__doc__}, - {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, rjust__doc__}, + STRINGLIB_RJUST_METHODDEF {"rpartition", (PyCFunction)bytes_rpartition, METH_O, rpartition__doc__}, {"rsplit", (PyCFunction)bytes_rsplit, METH_VARARGS | METH_KEYWORDS, rsplit__doc__}, @@ -2449,7 +2448,7 @@ {"translate", (PyCFunction)bytes_translate, METH_VARARGS, translate__doc__}, {"upper", (PyCFunction)stringlib_upper, METH_NOARGS, _Py_upper__doc__}, - {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, zfill__doc__}, + STRINGLIB_ZFILL_METHODDEF {"__sizeof__", (PyCFunction)bytes_sizeof, METH_NOARGS, sizeof__doc__}, {NULL, NULL} /* sentinel */ diff -r 967f368b7f75 Objects/stringlib/transmogrify.h --- a/Objects/stringlib/transmogrify.h Sun Jan 19 00:38:36 2014 +0200 +++ b/Objects/stringlib/transmogrify.h Tue Jan 21 01:13:17 2014 +0200 @@ -4,25 +4,58 @@ /* the more complicated methods. parts of these should be pulled out into the shared code in bytes_methods.c to cut down on duplicate code bloat. */ -PyDoc_STRVAR(expandtabs__doc__, -"B.expandtabs(tabsize=8) -> copy of B\n\ -\n\ -Return a copy of B where all tab characters are expanded using spaces.\n\ -If tabsize is not given, a tab size of 8 characters is assumed."); +/*[clinic input] +class B +[clinic start generated code]*/ +/*[clinic end generated code: checksum=da39a3ee5e6b4b0d3255bfef95601890afd80709]*/ -static PyObject* -stringlib_expandtabs(PyObject *self, PyObject *args, PyObject *kwds) +/*[clinic input] +B.expandtabs as stringlib_expandtabs + + tabsize: int = 8 + +Return a copy where all tab characters are expanded using spaces. + +If tabsize is not given, a tab size of 8 characters is assumed. +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_expandtabs__doc__, +"expandtabs(tabsize=8)\n" +"Return a copy where all tab characters are expanded using spaces.\n" +"\n" +"If tabsize is not given, a tab size of 8 characters is assumed."); + +#define STRINGLIB_EXPANDTABS_METHODDEF \ + {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS|METH_KEYWORDS, stringlib_expandtabs__doc__}, + +static PyObject * +stringlib_expandtabs_impl(PyObject *self, int tabsize); + +static PyObject * +stringlib_expandtabs(PyObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"tabsize", NULL}; + int tabsize = 8; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "|i:expandtabs", _keywords, + &tabsize)) + goto exit; + return_value = stringlib_expandtabs_impl(self, tabsize); + +exit: + return return_value; +} + +static PyObject * +stringlib_expandtabs_impl(PyObject *self, int tabsize) +/*[clinic end generated code: checksum=3d651d40c2ceac014766ddbb1fdbaf5266672bbb]*/ { const char *e, *p; char *q; size_t i, j; PyObject *u; - static char *kwlist[] = {"tabsize", 0}; - int tabsize = 8; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:expandtabs", - kwlist, &tabsize)) - return NULL; /* First pass: determine size of output string */ i = j = 0; @@ -120,21 +153,51 @@ return u; } -PyDoc_STRVAR(ljust__doc__, -"B.ljust(width[, fillchar]) -> copy of B\n" +/*[clinic input] +B.ljust as stringlib_ljust + + width: Py_ssize_t + fillchar: char(c_default="' '", py_default="b' '") = ' ' + / + +Return a left-justified string of length width. + +Padding is done using the specified fill character (default is a space). +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_ljust__doc__, +"ljust(width, fillchar=b\' \')\n" +"Return a left-justified string of length width.\n" "\n" -"Return B left justified in a string of length width. Padding is\n" -"done using the specified fill character (default is a space)."); +"Padding is done using the specified fill character (default is a space)."); + +#define STRINGLIB_LJUST_METHODDEF \ + {"ljust", (PyCFunction)stringlib_ljust, METH_VARARGS, stringlib_ljust__doc__}, + +static PyObject * +stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar); static PyObject * stringlib_ljust(PyObject *self, PyObject *args) { + PyObject *return_value = NULL; Py_ssize_t width; char fillchar = ' '; - if (!PyArg_ParseTuple(args, "n|c:ljust", &width, &fillchar)) - return NULL; + if (!PyArg_ParseTuple(args, + "n|c:ljust", + &width, &fillchar)) + goto exit; + return_value = stringlib_ljust_impl(self, width, fillchar); +exit: + return return_value; +} + +static PyObject * +stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: checksum=b0c5f9af52331f2c7278a4dbc8dfa16c664e98e8]*/ +{ if (STRINGLIB_LEN(self) >= width && STRINGLIB_CHECK_EXACT(self)) { #if STRINGLIB_MUTABLE /* We're defined as returning a copy; If the object is mutable @@ -149,22 +212,51 @@ return pad(self, 0, width - STRINGLIB_LEN(self), fillchar); } +/*[clinic input] +B.rjust as stringlib_rjust -PyDoc_STRVAR(rjust__doc__, -"B.rjust(width[, fillchar]) -> copy of B\n" + width: Py_ssize_t + fillchar: char(c_default="' '", py_default="b' '") = ' ' + / + +Return a right-justified string of length width. + +Padding is done using the specified fill character (default is a space). +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_rjust__doc__, +"rjust(width, fillchar=b\' \')\n" +"Return a right-justified string of length width.\n" "\n" -"Return B right justified in a string of length width. Padding is\n" -"done using the specified fill character (default is a space)"); +"Padding is done using the specified fill character (default is a space)."); + +#define STRINGLIB_RJUST_METHODDEF \ + {"rjust", (PyCFunction)stringlib_rjust, METH_VARARGS, stringlib_rjust__doc__}, + +static PyObject * +stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar); static PyObject * stringlib_rjust(PyObject *self, PyObject *args) { + PyObject *return_value = NULL; Py_ssize_t width; char fillchar = ' '; - if (!PyArg_ParseTuple(args, "n|c:rjust", &width, &fillchar)) - return NULL; + if (!PyArg_ParseTuple(args, + "n|c:rjust", + &width, &fillchar)) + goto exit; + return_value = stringlib_rjust_impl(self, width, fillchar); +exit: + return return_value; +} + +static PyObject * +stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: checksum=18ff32c71a37a5bdb1eddac584ff864ad4e1be17]*/ +{ if (STRINGLIB_LEN(self) >= width && STRINGLIB_CHECK_EXACT(self)) { #if STRINGLIB_MUTABLE /* We're defined as returning a copy; If the object is mutable @@ -179,22 +271,52 @@ return pad(self, width - STRINGLIB_LEN(self), 0, fillchar); } +/*[clinic input] +B.center as stringlib_center -PyDoc_STRVAR(center__doc__, -"B.center(width[, fillchar]) -> copy of B\n" + width: Py_ssize_t + fillchar: char(c_default="' '", py_default="b' '") = ' ' + / + +Return a centered string of length width. + +Padding is done using the specified fill character (default is a space). +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_center__doc__, +"center(width, fillchar=b\' \')\n" +"Return a centered string of length width.\n" "\n" -"Return B centered in a string of length width. Padding is\n" -"done using the specified fill character (default is a space)."); +"Padding is done using the specified fill character (default is a space)."); + +#define STRINGLIB_CENTER_METHODDEF \ + {"center", (PyCFunction)stringlib_center, METH_VARARGS, stringlib_center__doc__}, + +static PyObject * +stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar); static PyObject * stringlib_center(PyObject *self, PyObject *args) { - Py_ssize_t marg, left; + PyObject *return_value = NULL; Py_ssize_t width; char fillchar = ' '; - if (!PyArg_ParseTuple(args, "n|c:center", &width, &fillchar)) - return NULL; + if (!PyArg_ParseTuple(args, + "n|c:center", + &width, &fillchar)) + goto exit; + return_value = stringlib_center_impl(self, width, fillchar); + +exit: + return return_value; +} + +static PyObject * +stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar) +/*[clinic end generated code: checksum=681c08ac05f140085f0fbbe08289444629de158f]*/ +{ + Py_ssize_t marg, left; if (STRINGLIB_LEN(self) >= width && STRINGLIB_CHECK_EXACT(self)) { #if STRINGLIB_MUTABLE @@ -213,22 +335,52 @@ return pad(self, left, marg - left, fillchar); } -PyDoc_STRVAR(zfill__doc__, -"B.zfill(width) -> copy of B\n" +/*[clinic input] +B.zfill as stringlib_zfill + + width: Py_ssize_t + / + +Pad a numeric string with zeros on the left, to fill a field of the given width. + +The original string is never truncated. +[clinic start generated code]*/ + +PyDoc_STRVAR(stringlib_zfill__doc__, +"zfill(width)\n" +"Pad a numeric string with zeros on the left, to fill a field of the given width.\n" "\n" -"Pad a numeric string B with zeros on the left, to fill a field\n" -"of the specified width. B is never truncated."); +"The original string is never truncated."); + +#define STRINGLIB_ZFILL_METHODDEF \ + {"zfill", (PyCFunction)stringlib_zfill, METH_VARARGS, stringlib_zfill__doc__}, + +static PyObject * +stringlib_zfill_impl(PyObject *self, Py_ssize_t width); static PyObject * stringlib_zfill(PyObject *self, PyObject *args) { + PyObject *return_value = NULL; + Py_ssize_t width; + + if (!PyArg_ParseTuple(args, + "n:zfill", + &width)) + goto exit; + return_value = stringlib_zfill_impl(self, width); + +exit: + return return_value; +} + +static PyObject * +stringlib_zfill_impl(PyObject *self, Py_ssize_t width) +/*[clinic end generated code: checksum=ab4b4f727ae444586aa3ecbcf3d3be16c4e70863]*/ +{ Py_ssize_t fill; PyObject *s; char *p; - Py_ssize_t width; - - if (!PyArg_ParseTuple(args, "n:zfill", &width)) - return NULL; if (STRINGLIB_LEN(self) >= width) { if (STRINGLIB_CHECK_EXACT(self)) {