Coverage Report

Created: 2026-03-08 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Python/clinic/Python-tokenize.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
#  include "pycore_gc.h"          // PyGC_Head
7
#  include "pycore_runtime.h"     // _Py_ID()
8
#endif
9
#include "pycore_modsupport.h"    // _PyArg_UnpackKeywords()
10
11
static PyObject *
12
tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
13
                       int extra_tokens, const char *encoding);
14
15
static PyObject *
16
tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
17
20
{
18
20
    PyObject *return_value = NULL;
19
20
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
20
21
20
    #define NUM_KEYWORDS 2
22
20
    static struct {
23
20
        PyGC_Head _this_is_not_used;
24
20
        PyObject_VAR_HEAD
25
20
        Py_hash_t ob_hash;
26
20
        PyObject *ob_item[NUM_KEYWORDS];
27
20
    } _kwtuple = {
28
20
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
29
20
        .ob_hash = -1,
30
20
        .ob_item = { &_Py_ID(extra_tokens), &_Py_ID(encoding), },
31
20
    };
32
20
    #undef NUM_KEYWORDS
33
20
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
34
35
    #else  // !Py_BUILD_CORE
36
    #  define KWTUPLE NULL
37
    #endif  // !Py_BUILD_CORE
38
39
20
    static const char * const _keywords[] = {"", "extra_tokens", "encoding", NULL};
40
20
    static _PyArg_Parser _parser = {
41
20
        .keywords = _keywords,
42
20
        .fname = "tokenizeriter",
43
20
        .kwtuple = KWTUPLE,
44
20
    };
45
20
    #undef KWTUPLE
46
20
    PyObject *argsbuf[3];
47
20
    PyObject * const *fastargs;
48
20
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
49
20
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
50
20
    PyObject *readline;
51
20
    int extra_tokens;
52
20
    const char *encoding = NULL;
53
54
20
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
55
20
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 1, /*varpos*/ 0, argsbuf);
56
20
    if (!fastargs) {
57
0
        goto exit;
58
0
    }
59
20
    readline = fastargs[0];
60
20
    extra_tokens = PyObject_IsTrue(fastargs[1]);
61
20
    if (extra_tokens < 0) {
62
0
        goto exit;
63
0
    }
64
20
    if (!noptargs) {
65
16
        goto skip_optional_kwonly;
66
16
    }
67
4
    if (!PyUnicode_Check(fastargs[2])) {
68
0
        _PyArg_BadArgument("tokenizeriter", "argument 'encoding'", "str", fastargs[2]);
69
0
        goto exit;
70
0
    }
71
4
    Py_ssize_t encoding_length;
72
4
    encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
73
4
    if (encoding == NULL) {
74
0
        goto exit;
75
0
    }
76
4
    if (strlen(encoding) != (size_t)encoding_length) {
77
0
        PyErr_SetString(PyExc_ValueError, "embedded null character");
78
0
        goto exit;
79
0
    }
80
20
skip_optional_kwonly:
81
20
    return_value = tokenizeriter_new_impl(type, readline, extra_tokens, encoding);
82
83
20
exit:
84
20
    return return_value;
85
20
}
86
/*[clinic end generated code: output=4c448f34d9c835c0 input=a9049054013a1b77]*/