| 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(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 18 |
{ |
| 19 |
PyObject *return_value = NULL; |
| 20 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 21 |
|
| 22 |
#define NUM_KEYWORDS 4 |
| 23 |
static struct { |
| 24 |
PyGC_Head _this_is_not_used; |
| 25 |
PyObject_VAR_HEAD |
| 26 |
Py_hash_t ob_hash; |
| 27 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 28 |
} _kwtuple = { |
| 29 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 30 |
.ob_hash = -1, |
| 31 |
.ob_item = { &_Py_ID(value), &_Py_ID(expression), &_Py_ID(conversion), &_Py_ID(format_spec), }, |
| 32 |
}; |
| 33 |
#undef NUM_KEYWORDS |
| 34 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 35 |
|
| 36 |
#else // !Py_BUILD_CORE |
| 37 |
# define KWTUPLE NULL |
| 38 |
#endif // !Py_BUILD_CORE |
| 39 |
|
| 40 |
static const char * const _keywords[] = {"value", "expression", "conversion", "format_spec", NULL}; |
| 41 |
static _PyArg_Parser _parser = { |
| 42 |
.keywords = _keywords, |
| 43 |
.fname = "Interpolation", |
| 44 |
.kwtuple = KWTUPLE, |
| 45 |
}; |
| 46 |
#undef KWTUPLE |
| 47 |
PyObject *argsbuf[4]; |
| 48 |
PyObject * const *fastargs; |
| 49 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 50 |
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1; |
| 51 |
PyObject *value; |
| 52 |
PyObject *expression = &_Py_STR(empty); |
| 53 |
PyObject *conversion = Py_None; |
| 54 |
PyObject *format_spec = &_Py_STR(empty); |
| 55 |
|
| 56 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
| 57 |
/*minpos*/ 1, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 58 |
if (!fastargs) { |
| 59 |
goto exit; |
| 60 |
} |
| 61 |
value = fastargs[0]; |
| 62 |
if (!noptargs) { |
| 63 |
goto skip_optional_pos; |
| 64 |
} |
| 65 |
if (fastargs[1]) { |
| 66 |
if (!PyUnicode_Check(fastargs[1])) { |
| 67 |
_PyArg_BadArgument("Interpolation", "argument 'expression'", "str", fastargs[1]); |
| 68 |
goto exit; |
| 69 |
} |
| 70 |
expression = fastargs[1]; |
| 71 |
if (!--noptargs) { |
| 72 |
goto skip_optional_pos; |
| 73 |
} |
| 74 |
} |
| 75 |
if (fastargs[2]) { |
| 76 |
if (!_conversion_converter(fastargs[2], &conversion)) { |
| 77 |
goto exit; |
| 78 |
} |
| 79 |
if (!--noptargs) { |
| 80 |
goto skip_optional_pos; |
| 81 |
} |
| 82 |
} |
| 83 |
if (!PyUnicode_Check(fastargs[3])) { |
| 84 |
_PyArg_BadArgument("Interpolation", "argument 'format_spec'", "str", fastargs[3]); |
| 85 |
goto exit; |
| 86 |
} |
| 87 |
format_spec = fastargs[3]; |
| 88 |
skip_optional_pos: |
| 89 |
return_value = interpolation_new_impl(type, value, expression, conversion, format_spec); |
| 90 |
|
| 91 |
exit: |
| 92 |
return return_value; |
| 93 |
} |
| 94 |
/*[clinic end generated code: output=2391391e2d7708c0 input=a9049054013a1b77]*/ |