summaryrefslogtreecommitdiffstats
path: root/Modules/clinic/pyexpat.c.h
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-03-14 08:32:22 (GMT)
committerGitHub <noreply@github.com>2019-03-14 08:32:22 (GMT)
commit3191391515824fa7f3c573d807f1034c6a28fab3 (patch)
treeff8213b07b206de4df88dc352ee957ce68f0f2de /Modules/clinic/pyexpat.c.h
parent2c0d3f454705bb5ccf5f6189f3cf77bbae4f056b (diff)
downloadcpython-3191391515824fa7f3c573d807f1034c6a28fab3.zip
cpython-3191391515824fa7f3c573d807f1034c6a28fab3.tar.gz
cpython-3191391515824fa7f3c573d807f1034c6a28fab3.tar.bz2
bpo-36127: Argument Clinic: inline parsing code for keyword parameters. (GH-12058)
Diffstat (limited to 'Modules/clinic/pyexpat.c.h')
-rw-r--r--Modules/clinic/pyexpat.c.h61
1 files changed, 57 insertions, 4 deletions
diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h
index 3fe7b64..dfb27d5 100644
--- a/Modules/clinic/pyexpat.c.h
+++ b/Modules/clinic/pyexpat.c.h
@@ -297,15 +297,68 @@ pyexpat_ParserCreate(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
{
PyObject *return_value = NULL;
static const char * const _keywords[] = {"encoding", "namespace_separator", "intern", NULL};
- static _PyArg_Parser _parser = {"|zzO:ParserCreate", _keywords, 0};
+ static _PyArg_Parser _parser = {NULL, _keywords, "ParserCreate", 0};
+ PyObject *argsbuf[3];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
const char *encoding = NULL;
const char *namespace_separator = NULL;
PyObject *intern = NULL;
- if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
- &encoding, &namespace_separator, &intern)) {
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 3, 0, argsbuf);
+ if (!args) {
goto exit;
}
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ if (args[0]) {
+ if (args[0] == Py_None) {
+ encoding = NULL;
+ }
+ else if (PyUnicode_Check(args[0])) {
+ Py_ssize_t encoding_length;
+ encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
+ if (encoding == NULL) {
+ goto exit;
+ }
+ if (strlen(encoding) != (size_t)encoding_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("ParserCreate", 1, "str or None", args[0]);
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ if (args[1]) {
+ if (args[1] == Py_None) {
+ namespace_separator = NULL;
+ }
+ else if (PyUnicode_Check(args[1])) {
+ Py_ssize_t namespace_separator_length;
+ namespace_separator = PyUnicode_AsUTF8AndSize(args[1], &namespace_separator_length);
+ if (namespace_separator == NULL) {
+ goto exit;
+ }
+ if (strlen(namespace_separator) != (size_t)namespace_separator_length) {
+ PyErr_SetString(PyExc_ValueError, "embedded null character");
+ goto exit;
+ }
+ }
+ else {
+ _PyArg_BadArgument("ParserCreate", 2, "str or None", args[1]);
+ goto exit;
+ }
+ if (!--noptargs) {
+ goto skip_optional_pos;
+ }
+ }
+ intern = args[2];
+skip_optional_pos:
return_value = pyexpat_ParserCreate_impl(module, encoding, namespace_separator, intern);
exit:
@@ -348,4 +401,4 @@ exit:
#ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */
-/*[clinic end generated code: output=0f18b756d82b78a5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e48f37d326956bdd input=a9049054013a1b77]*/