summaryrefslogtreecommitdiff
path: root/Modules/clinic/binascii.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-14 10:32:22 +0200
committerGitHub <noreply@github.com>2019-03-14 10:32:22 +0200
commit3191391515824fa7f3c573d807f1034c6a28fab3 (patch)
treeff8213b07b206de4df88dc352ee957ce68f0f2de /Modules/clinic/binascii.c.h
parent2c0d3f454705bb5ccf5f6189f3cf77bbae4f056b (diff)
downloadcpython-git-3191391515824fa7f3c573d807f1034c6a28fab3.tar.gz
bpo-36127: Argument Clinic: inline parsing code for keyword parameters. (GH-12058)
Diffstat (limited to 'Modules/clinic/binascii.c.h')
-rw-r--r--Modules/clinic/binascii.c.h138
1 files changed, 125 insertions, 13 deletions
diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h
index 3295833e87..4043d89d97 100644
--- a/Modules/clinic/binascii.c.h
+++ b/Modules/clinic/binascii.c.h
@@ -50,14 +50,36 @@ binascii_b2a_uu(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"", "backtick", NULL};
- static _PyArg_Parser _parser = {"y*|$i:b2a_uu", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "b2a_uu", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer data = {NULL, NULL};
int backtick = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &data, &backtick)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
goto exit;
}
+ if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&data, 'C')) {
+ _PyArg_BadArgument("b2a_uu", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ backtick = _PyLong_AsInt(args[1]);
+ if (backtick == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+skip_optional_kwonly:
return_value = binascii_b2a_uu_impl(module, &data, backtick);
exit:
@@ -117,14 +139,36 @@ binascii_b2a_base64(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"", "newline", NULL};
- static _PyArg_Parser _parser = {"y*|$i:b2a_base64", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "b2a_base64", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer data = {NULL, NULL};
int newline = 1;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &data, &newline)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&data, 'C')) {
+ _PyArg_BadArgument("b2a_base64", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_kwonly;
+ }
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ newline = _PyLong_AsInt(args[1]);
+ if (newline == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional_kwonly:
return_value = binascii_b2a_base64_impl(module, &data, newline);
exit:
@@ -548,14 +592,32 @@ binascii_a2b_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"data", "header", NULL};
- static _PyArg_Parser _parser = {"O&|i:a2b_qp", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "a2b_qp", 0};
+ PyObject *argsbuf[2];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer data = {NULL, NULL};
int header = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- ascii_buffer_converter, &data, &header)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!ascii_buffer_converter(args[0], &data)) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ header = _PyLong_AsInt(args[1]);
+ if (header == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional_pos:
return_value = binascii_a2b_qp_impl(module, &data, header);
exit:
@@ -588,16 +650,66 @@ binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"data", "quotetabs", "istext", "header", NULL};
- static _PyArg_Parser _parser = {"y*|iii:b2a_qp", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "b2a_qp", 0};
+ PyObject *argsbuf[4];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Py_buffer data = {NULL, NULL};
int quotetabs = 0;
int istext = 1;
int header = 0;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &data, &quotetabs, &istext, &header)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 4, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
+ goto exit;
+ }
+ if (!PyBuffer_IsContiguous(&data, 'C')) {
+ _PyArg_BadArgument("b2a_qp", 1, "contiguous buffer", args[0]);
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[1]) {
+ if (PyFloat_Check(args[1])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ quotetabs = _PyLong_AsInt(args[1]);
+ if (quotetabs == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (args[2]) {
+ if (PyFloat_Check(args[2])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ istext = _PyLong_AsInt(args[2]);
+ if (istext == -1 && PyErr_Occurred()) {
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (PyFloat_Check(args[3])) {
+ PyErr_SetString(PyExc_TypeError,
+ "integer argument expected, got float" );
+ goto exit;
+ }
+ header = _PyLong_AsInt(args[3]);
+ if (header == -1 && PyErr_Occurred()) {
goto exit;
}
+skip_optional_pos:
return_value = binascii_b2a_qp_impl(module, &data, quotetabs, istext, header);
exit:
@@ -608,4 +720,4 @@ exit:
return return_value;
}
-/*[clinic end generated code: output=7210a01a718da4a0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a4a38e162605aca2 input=a9049054013a1b77]*/