Coverage Report

Created: 2026-02-26 06:53

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