/src/cpython/Objects/clinic/interpolationobject.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 | | interpolation_new_impl(PyTypeObject *type, PyObject *value, |
13 | | PyObject *expression, PyObject *conversion, |
14 | | PyObject *format_spec); |
15 | | |
16 | | static PyObject * |
17 | | interpolation_new_helper(PyTypeObject *type, PyObject *const *args, |
18 | | Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames) |
19 | 0 | { |
20 | 0 | PyObject *return_value = NULL; |
21 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
22 | |
|
23 | 0 | #define NUM_KEYWORDS 4 |
24 | 0 | static struct { |
25 | 0 | PyGC_Head _this_is_not_used; |
26 | 0 | PyObject_VAR_HEAD |
27 | 0 | Py_hash_t ob_hash; |
28 | 0 | PyObject *ob_item[NUM_KEYWORDS]; |
29 | 0 | } _kwtuple = { |
30 | 0 | .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
31 | 0 | .ob_hash = -1, |
32 | 0 | .ob_item = { &_Py_ID(value), &_Py_ID(expression), &_Py_ID(conversion), &_Py_ID(format_spec), }, |
33 | 0 | }; |
34 | 0 | #undef NUM_KEYWORDS |
35 | 0 | #define KWTUPLE (&_kwtuple.ob_base.ob_base) |
36 | |
|
37 | | #else // !Py_BUILD_CORE |
38 | | # define KWTUPLE NULL |
39 | | #endif // !Py_BUILD_CORE |
40 | |
|
41 | 0 | static const char * const _keywords[] = {"value", "expression", "conversion", "format_spec", NULL}; |
42 | 0 | static _PyArg_Parser _parser = { |
43 | 0 | .keywords = _keywords, |
44 | 0 | .fname = "Interpolation", |
45 | 0 | .kwtuple = KWTUPLE, |
46 | 0 | }; |
47 | 0 | #undef KWTUPLE |
48 | 0 | PyObject *argsbuf[4]; |
49 | 0 | PyObject * const *fastargs; |
50 | 0 | Py_ssize_t noptargs = nargs + nkw - 1; |
51 | 0 | PyObject *value; |
52 | 0 | PyObject *expression = &_Py_STR(empty); |
53 | 0 | PyObject *conversion = Py_None; |
54 | 0 | PyObject *format_spec = &_Py_STR(empty); |
55 | |
|
56 | 0 | fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser, |
57 | 0 | /*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
58 | 0 | if (!fastargs) { |
59 | 0 | goto exit; |
60 | 0 | } |
61 | 0 | value = fastargs[0]; |
62 | 0 | if (!noptargs) { |
63 | 0 | goto skip_optional_pos; |
64 | 0 | } |
65 | 0 | if (fastargs[1]) { |
66 | 0 | if (!PyUnicode_Check(fastargs[1])) { |
67 | 0 | _PyArg_BadArgument("Interpolation", "argument 'expression'", "str", fastargs[1]); |
68 | 0 | goto exit; |
69 | 0 | } |
70 | 0 | expression = fastargs[1]; |
71 | 0 | if (!--noptargs) { |
72 | 0 | goto skip_optional_pos; |
73 | 0 | } |
74 | 0 | } |
75 | 0 | if (fastargs[2]) { |
76 | 0 | if (!_conversion_converter(fastargs[2], &conversion)) { |
77 | 0 | goto exit; |
78 | 0 | } |
79 | 0 | if (!--noptargs) { |
80 | 0 | goto skip_optional_pos; |
81 | 0 | } |
82 | 0 | } |
83 | 0 | if (!PyUnicode_Check(fastargs[3])) { |
84 | 0 | _PyArg_BadArgument("Interpolation", "argument 'format_spec'", "str", fastargs[3]); |
85 | 0 | goto exit; |
86 | 0 | } |
87 | 0 | format_spec = fastargs[3]; |
88 | 0 | skip_optional_pos: |
89 | 0 | return_value = interpolation_new_impl(type, value, expression, conversion, format_spec); |
90 | |
|
91 | 0 | exit: |
92 | 0 | return return_value; |
93 | 0 | } |
94 | | |
95 | | static PyObject * |
96 | | interpolation_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
97 | 0 | { |
98 | 0 | return interpolation_new_helper(type, _PyTuple_CAST(args)->ob_item, |
99 | 0 | PyTuple_GET_SIZE(args), |
100 | 0 | kwargs ? PyDict_GET_SIZE(kwargs) : 0, |
101 | 0 | kwargs, NULL); |
102 | 0 | } |
103 | | |
104 | | static PyObject * |
105 | | interpolation_vectorcall(PyObject *type, PyObject *const *args, |
106 | | size_t nargsf, PyObject *kwnames) |
107 | 0 | { |
108 | 0 | PyObject *return_value = NULL; |
109 | 0 | Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); |
110 | 0 | PyObject *value; |
111 | 0 | PyObject *expression = &_Py_STR(empty); |
112 | 0 | PyObject *conversion = Py_None; |
113 | 0 | PyObject *format_spec = &_Py_STR(empty); |
114 | |
|
115 | 0 | assert(_PyType_CAST(type)->tp_new == interpolation_new); |
116 | | /* Make sure the type object is immutable: the generated |
117 | | * vectorcall doesn't deal e.g. with users reassigning __init__. */ |
118 | 0 | assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE)); |
119 | 0 | if (kwnames != NULL || nargs < 1 || nargs > 4) { |
120 | 0 | return interpolation_new_helper(_PyType_CAST(type), args, nargs, |
121 | 0 | kwnames ? PyTuple_GET_SIZE(kwnames) : 0, |
122 | 0 | NULL, kwnames); |
123 | 0 | } |
124 | 0 | value = args[0]; |
125 | 0 | if (nargs < 2) { |
126 | 0 | goto skip_optional; |
127 | 0 | } |
128 | 0 | if (!PyUnicode_Check(args[1])) { |
129 | 0 | _PyArg_BadArgument("Interpolation", "argument 'expression'", "str", args[1]); |
130 | 0 | goto exit; |
131 | 0 | } |
132 | 0 | expression = args[1]; |
133 | 0 | if (nargs < 3) { |
134 | 0 | goto skip_optional; |
135 | 0 | } |
136 | 0 | if (!_conversion_converter(args[2], &conversion)) { |
137 | 0 | goto exit; |
138 | 0 | } |
139 | 0 | if (nargs < 4) { |
140 | 0 | goto skip_optional; |
141 | 0 | } |
142 | 0 | if (!PyUnicode_Check(args[3])) { |
143 | 0 | _PyArg_BadArgument("Interpolation", "argument 'format_spec'", "str", args[3]); |
144 | 0 | goto exit; |
145 | 0 | } |
146 | 0 | format_spec = args[3]; |
147 | 0 | skip_optional: |
148 | 0 | return_value = interpolation_new_impl(_PyType_CAST(type), value, expression, conversion, format_spec); |
149 | |
|
150 | 0 | exit: |
151 | 0 | return return_value; |
152 | 0 | } |
153 | | /*[clinic end generated code: output=d07caaaa0e78ca15 input=a9049054013a1b77]*/ |