summaryrefslogtreecommitdiffstats
path: root/Objects/stringlib
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/stringlib')
-rw-r--r--Objects/stringlib/clinic/transmogrify.h.h104
1 files changed, 97 insertions, 7 deletions
diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h
index 7b7fd58..15c43af 100644
--- a/Objects/stringlib/clinic/transmogrify.h.h
+++ b/Objects/stringlib/clinic/transmogrify.h.h
@@ -55,10 +55,40 @@ stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
char fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|c:ljust",
- &width, &fillchar)) {
+ if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {
goto exit;
}
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {
+ fillchar = PyBytes_AS_STRING(args[1])[0];
+ }
+ else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {
+ fillchar = PyByteArray_AS_STRING(args[1])[0];
+ }
+ else {
+ _PyArg_BadArgument("ljust", 2, "a byte string of length 1", args[1]);
+ goto exit;
+ }
+skip_optional:
return_value = stringlib_ljust_impl(self, width, fillchar);
exit:
@@ -86,10 +116,40 @@ stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
char fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|c:rjust",
- &width, &fillchar)) {
+ if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {
+ goto exit;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {
+ fillchar = PyBytes_AS_STRING(args[1])[0];
+ }
+ else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {
+ fillchar = PyByteArray_AS_STRING(args[1])[0];
+ }
+ else {
+ _PyArg_BadArgument("rjust", 2, "a byte string of length 1", args[1]);
goto exit;
}
+skip_optional:
return_value = stringlib_rjust_impl(self, width, fillchar);
exit:
@@ -117,10 +177,40 @@ stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
Py_ssize_t width;
char fillchar = ' ';
- if (!_PyArg_ParseStack(args, nargs, "n|c:center",
- &width, &fillchar)) {
+ if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {
+ goto exit;
+ }
+ if (PyFloat_Check(args[0])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ {
+ Py_ssize_t ival = -1;
+ PyObject *iobj = PyNumber_Index(args[0]);
+ if (iobj != NULL) {
+ ival = PyLong_AsSsize_t(iobj);
+ Py_DECREF(iobj);
+ }
+ if (ival == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ width = ival;
+ }
+ if (nargs < 2) {
+ goto skip_optional;
+ }
+ if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {
+ fillchar = PyBytes_AS_STRING(args[1])[0];
+ }
+ else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {
+ fillchar = PyByteArray_AS_STRING(args[1])[0];
+ }
+ else {
+ _PyArg_BadArgument("center", 2, "a byte string of length 1", args[1]);
goto exit;
}
+skip_optional:
return_value = stringlib_center_impl(self, width, fillchar);
exit:
@@ -169,4 +259,4 @@ stringlib_zfill(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=bf2ef501639e1190 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=787248a980f6a00e input=a9049054013a1b77]*/