2021-08-24 13:50:05 -03:00
|
|
|
/*[clinic input]
|
|
|
|
preserve
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
2022-08-11 18:25:49 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2023-08-31 18:42:34 -03:00
|
|
|
# include "pycore_gc.h" // PyGC_Head
|
|
|
|
# include "pycore_runtime.h" // _Py_ID()
|
2022-08-11 18:25:49 -03:00
|
|
|
#endif
|
2023-10-17 09:30:31 -03:00
|
|
|
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2021-08-24 13:50:05 -03:00
|
|
|
static PyObject *
|
2023-05-30 18:43:34 -03:00
|
|
|
tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
|
|
|
|
int extra_tokens, const char *encoding);
|
2021-08-24 13:50:05 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|
|
|
{
|
|
|
|
PyObject *return_value = NULL;
|
2022-08-13 07:09:40 -03:00
|
|
|
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2023-05-20 21:03:02 -03:00
|
|
|
#define NUM_KEYWORDS 2
|
2022-08-11 18:25:49 -03:00
|
|
|
static struct {
|
|
|
|
PyGC_Head _this_is_not_used;
|
|
|
|
PyObject_VAR_HEAD
|
|
|
|
PyObject *ob_item[NUM_KEYWORDS];
|
|
|
|
} _kwtuple = {
|
|
|
|
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
|
2023-05-30 18:43:34 -03:00
|
|
|
.ob_item = { &_Py_ID(extra_tokens), &_Py_ID(encoding), },
|
2022-08-11 18:25:49 -03:00
|
|
|
};
|
|
|
|
#undef NUM_KEYWORDS
|
2022-08-13 07:09:40 -03:00
|
|
|
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
|
|
|
|
|
|
|
|
#else // !Py_BUILD_CORE
|
|
|
|
# define KWTUPLE NULL
|
|
|
|
#endif // !Py_BUILD_CORE
|
2022-08-11 18:25:49 -03:00
|
|
|
|
2023-05-30 18:43:34 -03:00
|
|
|
static const char * const _keywords[] = {"", "extra_tokens", "encoding", NULL};
|
2022-08-11 18:25:49 -03:00
|
|
|
static _PyArg_Parser _parser = {
|
|
|
|
.keywords = _keywords,
|
|
|
|
.fname = "tokenizeriter",
|
|
|
|
.kwtuple = KWTUPLE,
|
|
|
|
};
|
|
|
|
#undef KWTUPLE
|
2023-05-30 18:43:34 -03:00
|
|
|
PyObject *argsbuf[3];
|
2021-08-24 13:50:05 -03:00
|
|
|
PyObject * const *fastargs;
|
|
|
|
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
|
2023-05-30 18:43:34 -03:00
|
|
|
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
|
|
|
|
PyObject *readline;
|
2023-05-20 21:03:02 -03:00
|
|
|
int extra_tokens;
|
2023-05-30 18:43:34 -03:00
|
|
|
const char *encoding = NULL;
|
2021-08-24 13:50:05 -03:00
|
|
|
|
2023-05-20 21:03:02 -03:00
|
|
|
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 1, argsbuf);
|
2021-08-24 13:50:05 -03:00
|
|
|
if (!fastargs) {
|
|
|
|
goto exit;
|
|
|
|
}
|
2023-05-30 18:43:34 -03:00
|
|
|
readline = fastargs[0];
|
|
|
|
extra_tokens = PyObject_IsTrue(fastargs[1]);
|
|
|
|
if (extra_tokens < 0) {
|
2021-08-24 13:50:05 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-05-30 18:43:34 -03:00
|
|
|
if (!noptargs) {
|
|
|
|
goto skip_optional_kwonly;
|
|
|
|
}
|
|
|
|
if (!PyUnicode_Check(fastargs[2])) {
|
|
|
|
_PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]);
|
2021-08-24 13:50:05 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-11-01 12:34:42 -03:00
|
|
|
encoding = PyUnicode_AsUTF8(fastargs[2]);
|
2023-05-30 18:43:34 -03:00
|
|
|
if (encoding == NULL) {
|
2021-08-24 13:50:05 -03:00
|
|
|
goto exit;
|
|
|
|
}
|
2023-05-30 18:43:34 -03:00
|
|
|
skip_optional_kwonly:
|
|
|
|
return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding);
|
2021-08-24 13:50:05 -03:00
|
|
|
|
|
|
|
exit:
|
|
|
|
return return_value;
|
|
|
|
}
|
2023-11-01 12:34:42 -03:00
|
|
|
/*[clinic end generated code: output=92cb8176149f0924 input=a9049054013a1b77]*/
|