| 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 |
PyDoc_STRVAR(builtin___import____doc__, |
| 12 |
"__import__($module, /, name, globals=None, locals=None, fromlist=(),\n" |
| 13 |
" level=0)\n" |
| 14 |
"--\n" |
| 15 |
"\n" |
| 16 |
"Import a module.\n" |
| 17 |
"\n" |
| 18 |
"Because this function is meant for use by the Python\n" |
| 19 |
"interpreter and not for general use, it is better to use\n" |
| 20 |
"importlib.import_module() to programmatically import a module.\n" |
| 21 |
"\n" |
| 22 |
"The globals argument is only used to determine the context;\n" |
| 23 |
"they are not modified. The locals argument is unused. The fromlist\n" |
| 24 |
"should be a list of names to emulate ``from name import ...``, or an\n" |
| 25 |
"empty list to emulate ``import name``.\n" |
| 26 |
"When importing a module from a package, note that __import__(\'A.B\', ...)\n" |
| 27 |
"returns package A when fromlist is empty, but its submodule B when\n" |
| 28 |
"fromlist is not empty. The level argument is used to determine whether\n" |
| 29 |
"to perform absolute or relative imports: 0 is absolute, while a positive\n" |
| 30 |
"number is the number of parent directories to search relative to the\n" |
| 31 |
"current module."); |
| 32 |
|
| 33 |
#define BUILTIN___IMPORT___METHODDEF \ |
| 34 |
{"__import__", _PyCFunction_CAST(builtin___import__), METH_FASTCALL|METH_KEYWORDS, builtin___import____doc__}, |
| 35 |
|
| 36 |
static PyObject * |
| 37 |
builtin___import___impl(PyObject *module, PyObject *name, PyObject *globals, |
| 38 |
PyObject *locals, PyObject *fromlist, int level); |
| 39 |
|
| 40 |
static PyObject * |
| 41 |
builtin___import__(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 42 |
{ |
| 43 |
PyObject *return_value = NULL; |
| 44 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 45 |
|
| 46 |
#define NUM_KEYWORDS 5 |
| 47 |
static struct { |
| 48 |
PyGC_Head _this_is_not_used; |
| 49 |
PyObject_VAR_HEAD |
| 50 |
Py_hash_t ob_hash; |
| 51 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 52 |
} _kwtuple = { |
| 53 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 54 |
.ob_hash = -1, |
| 55 |
.ob_item = { &_Py_ID(name), &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(fromlist), &_Py_ID(level), }, |
| 56 |
}; |
| 57 |
#undef NUM_KEYWORDS |
| 58 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 59 |
|
| 60 |
#else // !Py_BUILD_CORE |
| 61 |
# define KWTUPLE NULL |
| 62 |
#endif // !Py_BUILD_CORE |
| 63 |
|
| 64 |
static const char * const _keywords[] = {"name", "globals", "locals", "fromlist", "level", NULL}; |
| 65 |
static _PyArg_Parser _parser = { |
| 66 |
.keywords = _keywords, |
| 67 |
.fname = "__import__", |
| 68 |
.kwtuple = KWTUPLE, |
| 69 |
}; |
| 70 |
#undef KWTUPLE |
| 71 |
PyObject *argsbuf[5]; |
| 72 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 73 |
PyObject *name; |
| 74 |
PyObject *globals = NULL; |
| 75 |
PyObject *locals = NULL; |
| 76 |
PyObject *fromlist = NULL; |
| 77 |
int level = 0; |
| 78 |
|
| 79 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 80 |
/*minpos*/ 1, /*maxpos*/ 5, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 81 |
if (!args) { |
| 82 |
goto exit; |
| 83 |
} |
| 84 |
name = args[0]; |
| 85 |
if (!noptargs) { |
| 86 |
goto skip_optional_pos; |
| 87 |
} |
| 88 |
if (args[1]) { |
| 89 |
globals = args[1]; |
| 90 |
if (!--noptargs) { |
| 91 |
goto skip_optional_pos; |
| 92 |
} |
| 93 |
} |
| 94 |
if (args[2]) { |
| 95 |
locals = args[2]; |
| 96 |
if (!--noptargs) { |
| 97 |
goto skip_optional_pos; |
| 98 |
} |
| 99 |
} |
| 100 |
if (args[3]) { |
| 101 |
fromlist = args[3]; |
| 102 |
if (!--noptargs) { |
| 103 |
goto skip_optional_pos; |
| 104 |
} |
| 105 |
} |
| 106 |
level = PyLong_AsInt(args[4]); |
| 107 |
if (level == -1 && PyErr_Occurred()) { |
| 108 |
goto exit; |
| 109 |
} |
| 110 |
skip_optional_pos: |
| 111 |
return_value = builtin___import___impl(module, name, globals, locals, fromlist, level); |
| 112 |
|
| 113 |
exit: |
| 114 |
return return_value; |
| 115 |
} |
| 116 |
|
| 117 |
PyDoc_STRVAR(builtin_abs__doc__, |
| 118 |
"abs($module, x, /)\n" |
| 119 |
"--\n" |
| 120 |
"\n" |
| 121 |
"Return the absolute value of the argument."); |
| 122 |
|
| 123 |
#define BUILTIN_ABS_METHODDEF \ |
| 124 |
{"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, |
| 125 |
|
| 126 |
PyDoc_STRVAR(builtin_all__doc__, |
| 127 |
"all($module, iterable, /)\n" |
| 128 |
"--\n" |
| 129 |
"\n" |
| 130 |
"Return True if bool(x) is True for all values x in the iterable.\n" |
| 131 |
"\n" |
| 132 |
"If the iterable is empty, return True."); |
| 133 |
|
| 134 |
#define BUILTIN_ALL_METHODDEF \ |
| 135 |
{"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, |
| 136 |
|
| 137 |
PyDoc_STRVAR(builtin_any__doc__, |
| 138 |
"any($module, iterable, /)\n" |
| 139 |
"--\n" |
| 140 |
"\n" |
| 141 |
"Return True if bool(x) is True for any x in the iterable.\n" |
| 142 |
"\n" |
| 143 |
"If the iterable is empty, return False."); |
| 144 |
|
| 145 |
#define BUILTIN_ANY_METHODDEF \ |
| 146 |
{"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, |
| 147 |
|
| 148 |
PyDoc_STRVAR(builtin_ascii__doc__, |
| 149 |
"ascii($module, obj, /)\n" |
| 150 |
"--\n" |
| 151 |
"\n" |
| 152 |
"Return an ASCII-only representation of an object.\n" |
| 153 |
"\n" |
| 154 |
"As repr(), return a string containing a printable representation of an\n" |
| 155 |
"object, but escape the non-ASCII characters in the string returned by\n" |
| 156 |
"repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" |
| 157 |
"to that returned by repr() in Python 2."); |
| 158 |
|
| 159 |
#define BUILTIN_ASCII_METHODDEF \ |
| 160 |
{"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, |
| 161 |
|
| 162 |
PyDoc_STRVAR(builtin_bin__doc__, |
| 163 |
"bin($module, number, /)\n" |
| 164 |
"--\n" |
| 165 |
"\n" |
| 166 |
"Return the binary representation of an integer.\n" |
| 167 |
"\n" |
| 168 |
" >>> bin(2796202)\n" |
| 169 |
" \'0b1010101010101010101010\'"); |
| 170 |
|
| 171 |
#define BUILTIN_BIN_METHODDEF \ |
| 172 |
{"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, |
| 173 |
|
| 174 |
PyDoc_STRVAR(builtin_callable__doc__, |
| 175 |
"callable($module, obj, /)\n" |
| 176 |
"--\n" |
| 177 |
"\n" |
| 178 |
"Return whether the object is callable (i.e., some kind of function).\n" |
| 179 |
"\n" |
| 180 |
"Note that classes are callable, as are instances of classes with a\n" |
| 181 |
"__call__() method."); |
| 182 |
|
| 183 |
#define BUILTIN_CALLABLE_METHODDEF \ |
| 184 |
{"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, |
| 185 |
|
| 186 |
PyDoc_STRVAR(builtin_format__doc__, |
| 187 |
"format($module, value, format_spec=\'\', /)\n" |
| 188 |
"--\n" |
| 189 |
"\n" |
| 190 |
"Return type(value).__format__(value, format_spec)\n" |
| 191 |
"\n" |
| 192 |
"Many built-in types implement format_spec according to the\n" |
| 193 |
"Format Specification Mini-language. See help(\'FORMATTING\').\n" |
| 194 |
"\n" |
| 195 |
"If type(value) does not supply a method named __format__\n" |
| 196 |
"and format_spec is empty, then str(value) is returned.\n" |
| 197 |
"See also help(\'SPECIALMETHODS\')."); |
| 198 |
|
| 199 |
#define BUILTIN_FORMAT_METHODDEF \ |
| 200 |
{"format", _PyCFunction_CAST(builtin_format), METH_FASTCALL, builtin_format__doc__}, |
| 201 |
|
| 202 |
static PyObject * |
| 203 |
builtin_format_impl(PyObject *module, PyObject *value, PyObject *format_spec); |
| 204 |
|
| 205 |
static PyObject * |
| 206 |
builtin_format(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 207 |
{ |
| 208 |
PyObject *return_value = NULL; |
| 209 |
PyObject *value; |
| 210 |
PyObject *format_spec = NULL; |
| 211 |
|
| 212 |
if (!_PyArg_CheckPositional("format", nargs, 1, 2)) { |
| 213 |
goto exit; |
| 214 |
} |
| 215 |
value = args[0]; |
| 216 |
if (nargs < 2) { |
| 217 |
goto skip_optional; |
| 218 |
} |
| 219 |
if (!PyUnicode_Check(args[1])) { |
| 220 |
_PyArg_BadArgument("format", "argument 2", "str", args[1]); |
| 221 |
goto exit; |
| 222 |
} |
| 223 |
format_spec = args[1]; |
| 224 |
skip_optional: |
| 225 |
return_value = builtin_format_impl(module, value, format_spec); |
| 226 |
|
| 227 |
exit: |
| 228 |
return return_value; |
| 229 |
} |
| 230 |
|
| 231 |
PyDoc_STRVAR(builtin_chr__doc__, |
| 232 |
"chr($module, i, /)\n" |
| 233 |
"--\n" |
| 234 |
"\n" |
| 235 |
"Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
| 236 |
|
| 237 |
#define BUILTIN_CHR_METHODDEF \ |
| 238 |
{"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
| 239 |
|
| 240 |
PyDoc_STRVAR(builtin_compile__doc__, |
| 241 |
"compile($module, /, source, filename, mode, flags=0,\n" |
| 242 |
" dont_inherit=False, optimize=-1, *, _feature_version=-1)\n" |
| 243 |
"--\n" |
| 244 |
"\n" |
| 245 |
"Compile source into a code object that can be executed by exec() or eval().\n" |
| 246 |
"\n" |
| 247 |
"The source code may represent a Python module, statement or\n" |
| 248 |
"expression.\n" |
| 249 |
"The filename will be used for run-time error messages.\n" |
| 250 |
"The mode must be \'exec\' to compile a module, \'single\' to compile a\n" |
| 251 |
"single (interactive) statement, or \'eval\' to compile an expression.\n" |
| 252 |
"The flags argument, if present, controls which future statements\n" |
| 253 |
"influence the compilation of the code.\n" |
| 254 |
"The dont_inherit argument, if true, stops the compilation inheriting\n" |
| 255 |
"the effects of any future statements in effect in the code calling\n" |
| 256 |
"compile; if absent or false these statements do influence the\n" |
| 257 |
"compilation, in addition to any features explicitly specified."); |
| 258 |
|
| 259 |
#define BUILTIN_COMPILE_METHODDEF \ |
| 260 |
{"compile", _PyCFunction_CAST(builtin_compile), METH_FASTCALL|METH_KEYWORDS, builtin_compile__doc__}, |
| 261 |
|
| 262 |
static PyObject * |
| 263 |
builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename, |
| 264 |
const char *mode, int flags, int dont_inherit, |
| 265 |
int optimize, int feature_version); |
| 266 |
|
| 267 |
static PyObject * |
| 268 |
builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 269 |
{ |
| 270 |
PyObject *return_value = NULL; |
| 271 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 272 |
|
| 273 |
#define NUM_KEYWORDS 7 |
| 274 |
static struct { |
| 275 |
PyGC_Head _this_is_not_used; |
| 276 |
PyObject_VAR_HEAD |
| 277 |
Py_hash_t ob_hash; |
| 278 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 279 |
} _kwtuple = { |
| 280 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 281 |
.ob_hash = -1, |
| 282 |
.ob_item = { &_Py_ID(source), &_Py_ID(filename), &_Py_ID(mode), &_Py_ID(flags), &_Py_ID(dont_inherit), &_Py_ID(optimize), &_Py_ID(_feature_version), }, |
| 283 |
}; |
| 284 |
#undef NUM_KEYWORDS |
| 285 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 286 |
|
| 287 |
#else // !Py_BUILD_CORE |
| 288 |
# define KWTUPLE NULL |
| 289 |
#endif // !Py_BUILD_CORE |
| 290 |
|
| 291 |
static const char * const _keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", "_feature_version", NULL}; |
| 292 |
static _PyArg_Parser _parser = { |
| 293 |
.keywords = _keywords, |
| 294 |
.fname = "compile", |
| 295 |
.kwtuple = KWTUPLE, |
| 296 |
}; |
| 297 |
#undef KWTUPLE |
| 298 |
PyObject *argsbuf[7]; |
| 299 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3; |
| 300 |
PyObject *source; |
| 301 |
PyObject *filename = NULL; |
| 302 |
const char *mode; |
| 303 |
int flags = 0; |
| 304 |
int dont_inherit = 0; |
| 305 |
int optimize = -1; |
| 306 |
int feature_version = -1; |
| 307 |
|
| 308 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 309 |
/*minpos*/ 3, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 310 |
if (!args) { |
| 311 |
goto exit; |
| 312 |
} |
| 313 |
source = args[0]; |
| 314 |
if (!PyUnicode_FSDecoder(args[1], &filename)) { |
| 315 |
goto exit; |
| 316 |
} |
| 317 |
if (!PyUnicode_Check(args[2])) { |
| 318 |
_PyArg_BadArgument("compile", "argument 'mode'", "str", args[2]); |
| 319 |
goto exit; |
| 320 |
} |
| 321 |
Py_ssize_t mode_length; |
| 322 |
mode = PyUnicode_AsUTF8AndSize(args[2], &mode_length); |
| 323 |
if (mode == NULL) { |
| 324 |
goto exit; |
| 325 |
} |
| 326 |
if (strlen(mode) != (size_t)mode_length) { |
| 327 |
PyErr_SetString(PyExc_ValueError, "embedded null character"); |
| 328 |
goto exit; |
| 329 |
} |
| 330 |
if (!noptargs) { |
| 331 |
goto skip_optional_pos; |
| 332 |
} |
| 333 |
if (args[3]) { |
| 334 |
flags = PyLong_AsInt(args[3]); |
| 335 |
if (flags == -1 && PyErr_Occurred()) { |
| 336 |
goto exit; |
| 337 |
} |
| 338 |
if (!--noptargs) { |
| 339 |
goto skip_optional_pos; |
| 340 |
} |
| 341 |
} |
| 342 |
if (args[4]) { |
| 343 |
dont_inherit = PyObject_IsTrue(args[4]); |
| 344 |
if (dont_inherit < 0) { |
| 345 |
goto exit; |
| 346 |
} |
| 347 |
if (!--noptargs) { |
| 348 |
goto skip_optional_pos; |
| 349 |
} |
| 350 |
} |
| 351 |
if (args[5]) { |
| 352 |
optimize = PyLong_AsInt(args[5]); |
| 353 |
if (optimize == -1 && PyErr_Occurred()) { |
| 354 |
goto exit; |
| 355 |
} |
| 356 |
if (!--noptargs) { |
| 357 |
goto skip_optional_pos; |
| 358 |
} |
| 359 |
} |
| 360 |
skip_optional_pos: |
| 361 |
if (!noptargs) { |
| 362 |
goto skip_optional_kwonly; |
| 363 |
} |
| 364 |
feature_version = PyLong_AsInt(args[6]); |
| 365 |
if (feature_version == -1 && PyErr_Occurred()) { |
| 366 |
goto exit; |
| 367 |
} |
| 368 |
skip_optional_kwonly: |
| 369 |
return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize, feature_version); |
| 370 |
|
| 371 |
exit: |
| 372 |
/* Cleanup for filename */ |
| 373 |
Py_XDECREF(filename); |
| 374 |
|
| 375 |
return return_value; |
| 376 |
} |
| 377 |
|
| 378 |
PyDoc_STRVAR(builtin_divmod__doc__, |
| 379 |
"divmod($module, x, y, /)\n" |
| 380 |
"--\n" |
| 381 |
"\n" |
| 382 |
"Return the tuple (x//y, x%y). Invariant: div*y + mod == x."); |
| 383 |
|
| 384 |
#define BUILTIN_DIVMOD_METHODDEF \ |
| 385 |
{"divmod", _PyCFunction_CAST(builtin_divmod), METH_FASTCALL, builtin_divmod__doc__}, |
| 386 |
|
| 387 |
static PyObject * |
| 388 |
builtin_divmod_impl(PyObject *module, PyObject *x, PyObject *y); |
| 389 |
|
| 390 |
static PyObject * |
| 391 |
builtin_divmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 392 |
{ |
| 393 |
PyObject *return_value = NULL; |
| 394 |
PyObject *x; |
| 395 |
PyObject *y; |
| 396 |
|
| 397 |
if (!_PyArg_CheckPositional("divmod", nargs, 2, 2)) { |
| 398 |
goto exit; |
| 399 |
} |
| 400 |
x = args[0]; |
| 401 |
y = args[1]; |
| 402 |
return_value = builtin_divmod_impl(module, x, y); |
| 403 |
|
| 404 |
exit: |
| 405 |
return return_value; |
| 406 |
} |
| 407 |
|
| 408 |
PyDoc_STRVAR(builtin_eval__doc__, |
| 409 |
"eval($module, source, /, globals=None, locals=None)\n" |
| 410 |
"--\n" |
| 411 |
"\n" |
| 412 |
"Evaluate the given source in the context of globals and locals.\n" |
| 413 |
"\n" |
| 414 |
"The source may be a string representing a Python expression\n" |
| 415 |
"or a code object as returned by compile().\n" |
| 416 |
"The globals must be a dictionary and locals can be any mapping,\n" |
| 417 |
"defaulting to the current globals and locals.\n" |
| 418 |
"If only globals is given, locals defaults to it."); |
| 419 |
|
| 420 |
#define BUILTIN_EVAL_METHODDEF \ |
| 421 |
{"eval", _PyCFunction_CAST(builtin_eval), METH_FASTCALL|METH_KEYWORDS, builtin_eval__doc__}, |
| 422 |
|
| 423 |
static PyObject * |
| 424 |
builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, |
| 425 |
PyObject *locals); |
| 426 |
|
| 427 |
static PyObject * |
| 428 |
builtin_eval(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 429 |
{ |
| 430 |
PyObject *return_value = NULL; |
| 431 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 432 |
|
| 433 |
#define NUM_KEYWORDS 2 |
| 434 |
static struct { |
| 435 |
PyGC_Head _this_is_not_used; |
| 436 |
PyObject_VAR_HEAD |
| 437 |
Py_hash_t ob_hash; |
| 438 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 439 |
} _kwtuple = { |
| 440 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 441 |
.ob_hash = -1, |
| 442 |
.ob_item = { &_Py_ID(globals), &_Py_ID(locals), }, |
| 443 |
}; |
| 444 |
#undef NUM_KEYWORDS |
| 445 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 446 |
|
| 447 |
#else // !Py_BUILD_CORE |
| 448 |
# define KWTUPLE NULL |
| 449 |
#endif // !Py_BUILD_CORE |
| 450 |
|
| 451 |
static const char * const _keywords[] = {"", "globals", "locals", NULL}; |
| 452 |
static _PyArg_Parser _parser = { |
| 453 |
.keywords = _keywords, |
| 454 |
.fname = "eval", |
| 455 |
.kwtuple = KWTUPLE, |
| 456 |
}; |
| 457 |
#undef KWTUPLE |
| 458 |
PyObject *argsbuf[3]; |
| 459 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 460 |
PyObject *source; |
| 461 |
PyObject *globals = Py_None; |
| 462 |
PyObject *locals = Py_None; |
| 463 |
|
| 464 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 465 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 466 |
if (!args) { |
| 467 |
goto exit; |
| 468 |
} |
| 469 |
source = args[0]; |
| 470 |
if (!noptargs) { |
| 471 |
goto skip_optional_pos; |
| 472 |
} |
| 473 |
if (args[1]) { |
| 474 |
globals = args[1]; |
| 475 |
if (!--noptargs) { |
| 476 |
goto skip_optional_pos; |
| 477 |
} |
| 478 |
} |
| 479 |
locals = args[2]; |
| 480 |
skip_optional_pos: |
| 481 |
return_value = builtin_eval_impl(module, source, globals, locals); |
| 482 |
|
| 483 |
exit: |
| 484 |
return return_value; |
| 485 |
} |
| 486 |
|
| 487 |
PyDoc_STRVAR(builtin_exec__doc__, |
| 488 |
"exec($module, source, /, globals=None, locals=None, *, closure=None)\n" |
| 489 |
"--\n" |
| 490 |
"\n" |
| 491 |
"Execute the given source in the context of globals and locals.\n" |
| 492 |
"\n" |
| 493 |
"The source may be a string representing one or more Python statements\n" |
| 494 |
"or a code object as returned by compile().\n" |
| 495 |
"The globals must be a dictionary and locals can be any mapping,\n" |
| 496 |
"defaulting to the current globals and locals.\n" |
| 497 |
"If only globals is given, locals defaults to it.\n" |
| 498 |
"The closure must be a tuple of cellvars, and can only be used\n" |
| 499 |
"when source is a code object requiring exactly that many cellvars."); |
| 500 |
|
| 501 |
#define BUILTIN_EXEC_METHODDEF \ |
| 502 |
{"exec", _PyCFunction_CAST(builtin_exec), METH_FASTCALL|METH_KEYWORDS, builtin_exec__doc__}, |
| 503 |
|
| 504 |
static PyObject * |
| 505 |
builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, |
| 506 |
PyObject *locals, PyObject *closure); |
| 507 |
|
| 508 |
static PyObject * |
| 509 |
builtin_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 510 |
{ |
| 511 |
PyObject *return_value = NULL; |
| 512 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 513 |
|
| 514 |
#define NUM_KEYWORDS 3 |
| 515 |
static struct { |
| 516 |
PyGC_Head _this_is_not_used; |
| 517 |
PyObject_VAR_HEAD |
| 518 |
Py_hash_t ob_hash; |
| 519 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 520 |
} _kwtuple = { |
| 521 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 522 |
.ob_hash = -1, |
| 523 |
.ob_item = { &_Py_ID(globals), &_Py_ID(locals), &_Py_ID(closure), }, |
| 524 |
}; |
| 525 |
#undef NUM_KEYWORDS |
| 526 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 527 |
|
| 528 |
#else // !Py_BUILD_CORE |
| 529 |
# define KWTUPLE NULL |
| 530 |
#endif // !Py_BUILD_CORE |
| 531 |
|
| 532 |
static const char * const _keywords[] = {"", "globals", "locals", "closure", NULL}; |
| 533 |
static _PyArg_Parser _parser = { |
| 534 |
.keywords = _keywords, |
| 535 |
.fname = "exec", |
| 536 |
.kwtuple = KWTUPLE, |
| 537 |
}; |
| 538 |
#undef KWTUPLE |
| 539 |
PyObject *argsbuf[4]; |
| 540 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 541 |
PyObject *source; |
| 542 |
PyObject *globals = Py_None; |
| 543 |
PyObject *locals = Py_None; |
| 544 |
PyObject *closure = NULL; |
| 545 |
|
| 546 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 547 |
/*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 548 |
if (!args) { |
| 549 |
goto exit; |
| 550 |
} |
| 551 |
source = args[0]; |
| 552 |
if (!noptargs) { |
| 553 |
goto skip_optional_pos; |
| 554 |
} |
| 555 |
if (args[1]) { |
| 556 |
globals = args[1]; |
| 557 |
if (!--noptargs) { |
| 558 |
goto skip_optional_pos; |
| 559 |
} |
| 560 |
} |
| 561 |
if (args[2]) { |
| 562 |
locals = args[2]; |
| 563 |
if (!--noptargs) { |
| 564 |
goto skip_optional_pos; |
| 565 |
} |
| 566 |
} |
| 567 |
skip_optional_pos: |
| 568 |
if (!noptargs) { |
| 569 |
goto skip_optional_kwonly; |
| 570 |
} |
| 571 |
closure = args[3]; |
| 572 |
skip_optional_kwonly: |
| 573 |
return_value = builtin_exec_impl(module, source, globals, locals, closure); |
| 574 |
|
| 575 |
exit: |
| 576 |
return return_value; |
| 577 |
} |
| 578 |
|
| 579 |
PyDoc_STRVAR(builtin_globals__doc__, |
| 580 |
"globals($module, /)\n" |
| 581 |
"--\n" |
| 582 |
"\n" |
| 583 |
"Return the dictionary containing the current scope\'s global variables.\n" |
| 584 |
"\n" |
| 585 |
"NOTE: Updates to this dictionary *will* affect name lookups in the\n" |
| 586 |
"current global scope and vice-versa."); |
| 587 |
|
| 588 |
#define BUILTIN_GLOBALS_METHODDEF \ |
| 589 |
{"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, |
| 590 |
|
| 591 |
static PyObject * |
| 592 |
builtin_globals_impl(PyObject *module); |
| 593 |
|
| 594 |
static PyObject * |
| 595 |
builtin_globals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 596 |
{ |
| 597 |
return builtin_globals_impl(module); |
| 598 |
} |
| 599 |
|
| 600 |
PyDoc_STRVAR(builtin_hasattr__doc__, |
| 601 |
"hasattr($module, obj, name, /)\n" |
| 602 |
"--\n" |
| 603 |
"\n" |
| 604 |
"Return whether the object has an attribute with the given name.\n" |
| 605 |
"\n" |
| 606 |
"This is done by calling getattr(obj, name) and catching AttributeError."); |
| 607 |
|
| 608 |
#define BUILTIN_HASATTR_METHODDEF \ |
| 609 |
{"hasattr", _PyCFunction_CAST(builtin_hasattr), METH_FASTCALL, builtin_hasattr__doc__}, |
| 610 |
|
| 611 |
static PyObject * |
| 612 |
builtin_hasattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
| 613 |
|
| 614 |
static PyObject * |
| 615 |
builtin_hasattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 616 |
{ |
| 617 |
PyObject *return_value = NULL; |
| 618 |
PyObject *obj; |
| 619 |
PyObject *name; |
| 620 |
|
| 621 |
if (!_PyArg_CheckPositional("hasattr", nargs, 2, 2)) { |
| 622 |
goto exit; |
| 623 |
} |
| 624 |
obj = args[0]; |
| 625 |
name = args[1]; |
| 626 |
return_value = builtin_hasattr_impl(module, obj, name); |
| 627 |
|
| 628 |
exit: |
| 629 |
return return_value; |
| 630 |
} |
| 631 |
|
| 632 |
PyDoc_STRVAR(builtin_id__doc__, |
| 633 |
"id($module, obj, /)\n" |
| 634 |
"--\n" |
| 635 |
"\n" |
| 636 |
"Return the identity of an object.\n" |
| 637 |
"\n" |
| 638 |
"This is guaranteed to be unique among simultaneously existing objects.\n" |
| 639 |
"(CPython uses the object\'s memory address.)"); |
| 640 |
|
| 641 |
#define BUILTIN_ID_METHODDEF \ |
| 642 |
{"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, |
| 643 |
|
| 644 |
static PyObject * |
| 645 |
builtin_id_impl(PyModuleDef *self, PyObject *v); |
| 646 |
|
| 647 |
static PyObject * |
| 648 |
builtin_id(PyObject *self, PyObject *v) |
| 649 |
{ |
| 650 |
PyObject *return_value = NULL; |
| 651 |
|
| 652 |
return_value = builtin_id_impl((PyModuleDef *)self, v); |
| 653 |
|
| 654 |
return return_value; |
| 655 |
} |
| 656 |
|
| 657 |
PyDoc_STRVAR(builtin_setattr__doc__, |
| 658 |
"setattr($module, obj, name, value, /)\n" |
| 659 |
"--\n" |
| 660 |
"\n" |
| 661 |
"Sets the named attribute on the given object to the specified value.\n" |
| 662 |
"\n" |
| 663 |
"setattr(x, \'y\', v) is equivalent to ``x.y = v``"); |
| 664 |
|
| 665 |
#define BUILTIN_SETATTR_METHODDEF \ |
| 666 |
{"setattr", _PyCFunction_CAST(builtin_setattr), METH_FASTCALL, builtin_setattr__doc__}, |
| 667 |
|
| 668 |
static PyObject * |
| 669 |
builtin_setattr_impl(PyObject *module, PyObject *obj, PyObject *name, |
| 670 |
PyObject *value); |
| 671 |
|
| 672 |
static PyObject * |
| 673 |
builtin_setattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 674 |
{ |
| 675 |
PyObject *return_value = NULL; |
| 676 |
PyObject *obj; |
| 677 |
PyObject *name; |
| 678 |
PyObject *value; |
| 679 |
|
| 680 |
if (!_PyArg_CheckPositional("setattr", nargs, 3, 3)) { |
| 681 |
goto exit; |
| 682 |
} |
| 683 |
obj = args[0]; |
| 684 |
name = args[1]; |
| 685 |
value = args[2]; |
| 686 |
return_value = builtin_setattr_impl(module, obj, name, value); |
| 687 |
|
| 688 |
exit: |
| 689 |
return return_value; |
| 690 |
} |
| 691 |
|
| 692 |
PyDoc_STRVAR(builtin_delattr__doc__, |
| 693 |
"delattr($module, obj, name, /)\n" |
| 694 |
"--\n" |
| 695 |
"\n" |
| 696 |
"Deletes the named attribute from the given object.\n" |
| 697 |
"\n" |
| 698 |
"delattr(x, \'y\') is equivalent to ``del x.y``"); |
| 699 |
|
| 700 |
#define BUILTIN_DELATTR_METHODDEF \ |
| 701 |
{"delattr", _PyCFunction_CAST(builtin_delattr), METH_FASTCALL, builtin_delattr__doc__}, |
| 702 |
|
| 703 |
static PyObject * |
| 704 |
builtin_delattr_impl(PyObject *module, PyObject *obj, PyObject *name); |
| 705 |
|
| 706 |
static PyObject * |
| 707 |
builtin_delattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 708 |
{ |
| 709 |
PyObject *return_value = NULL; |
| 710 |
PyObject *obj; |
| 711 |
PyObject *name; |
| 712 |
|
| 713 |
if (!_PyArg_CheckPositional("delattr", nargs, 2, 2)) { |
| 714 |
goto exit; |
| 715 |
} |
| 716 |
obj = args[0]; |
| 717 |
name = args[1]; |
| 718 |
return_value = builtin_delattr_impl(module, obj, name); |
| 719 |
|
| 720 |
exit: |
| 721 |
return return_value; |
| 722 |
} |
| 723 |
|
| 724 |
PyDoc_STRVAR(builtin_hash__doc__, |
| 725 |
"hash($module, obj, /)\n" |
| 726 |
"--\n" |
| 727 |
"\n" |
| 728 |
"Return the integer hash value for the given object.\n" |
| 729 |
"\n" |
| 730 |
"Two objects that compare equal must also have the same hash value, but\n" |
| 731 |
"the reverse is not necessarily true. Hash values may differ between\n" |
| 732 |
"Python processes. Not all objects are hashable; calling hash() on an\n" |
| 733 |
"unhashable object raises TypeError."); |
| 734 |
|
| 735 |
#define BUILTIN_HASH_METHODDEF \ |
| 736 |
{"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, |
| 737 |
|
| 738 |
PyDoc_STRVAR(builtin_hex__doc__, |
| 739 |
"hex($module, number, /)\n" |
| 740 |
"--\n" |
| 741 |
"\n" |
| 742 |
"Return the hexadecimal representation of an integer.\n" |
| 743 |
"\n" |
| 744 |
" >>> hex(12648430)\n" |
| 745 |
" \'0xc0ffee\'"); |
| 746 |
|
| 747 |
#define BUILTIN_HEX_METHODDEF \ |
| 748 |
{"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, |
| 749 |
|
| 750 |
PyDoc_STRVAR(builtin_aiter__doc__, |
| 751 |
"aiter($module, async_iterable, /)\n" |
| 752 |
"--\n" |
| 753 |
"\n" |
| 754 |
"Return an AsyncIterator for an AsyncIterable object."); |
| 755 |
|
| 756 |
#define BUILTIN_AITER_METHODDEF \ |
| 757 |
{"aiter", (PyCFunction)builtin_aiter, METH_O, builtin_aiter__doc__}, |
| 758 |
|
| 759 |
PyDoc_STRVAR(builtin_anext__doc__, |
| 760 |
"anext($module, aiterator, default=<unrepresentable>, /)\n" |
| 761 |
"--\n" |
| 762 |
"\n" |
| 763 |
"Return the next item from the async iterator.\n" |
| 764 |
"\n" |
| 765 |
"If default is given and the async iterator is exhausted,\n" |
| 766 |
"it is returned instead of raising StopAsyncIteration."); |
| 767 |
|
| 768 |
#define BUILTIN_ANEXT_METHODDEF \ |
| 769 |
{"anext", _PyCFunction_CAST(builtin_anext), METH_FASTCALL, builtin_anext__doc__}, |
| 770 |
|
| 771 |
static PyObject * |
| 772 |
builtin_anext_impl(PyObject *module, PyObject *aiterator, |
| 773 |
PyObject *default_value); |
| 774 |
|
| 775 |
static PyObject * |
| 776 |
builtin_anext(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 777 |
{ |
| 778 |
PyObject *return_value = NULL; |
| 779 |
PyObject *aiterator; |
| 780 |
PyObject *default_value = NULL; |
| 781 |
|
| 782 |
if (!_PyArg_CheckPositional("anext", nargs, 1, 2)) { |
| 783 |
goto exit; |
| 784 |
} |
| 785 |
aiterator = args[0]; |
| 786 |
if (nargs < 2) { |
| 787 |
goto skip_optional; |
| 788 |
} |
| 789 |
default_value = args[1]; |
| 790 |
skip_optional: |
| 791 |
return_value = builtin_anext_impl(module, aiterator, default_value); |
| 792 |
|
| 793 |
exit: |
| 794 |
return return_value; |
| 795 |
} |
| 796 |
|
| 797 |
PyDoc_STRVAR(builtin_len__doc__, |
| 798 |
"len($module, obj, /)\n" |
| 799 |
"--\n" |
| 800 |
"\n" |
| 801 |
"Return the number of items in a container."); |
| 802 |
|
| 803 |
#define BUILTIN_LEN_METHODDEF \ |
| 804 |
{"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, |
| 805 |
|
| 806 |
PyDoc_STRVAR(builtin_locals__doc__, |
| 807 |
"locals($module, /)\n" |
| 808 |
"--\n" |
| 809 |
"\n" |
| 810 |
"Return a dictionary containing the current scope\'s local variables.\n" |
| 811 |
"\n" |
| 812 |
"NOTE: Whether or not updates to this dictionary will affect name\n" |
| 813 |
"lookups in the local scope and vice-versa is *implementation\n" |
| 814 |
"dependent* and not covered by any backwards compatibility\n" |
| 815 |
"guarantees."); |
| 816 |
|
| 817 |
#define BUILTIN_LOCALS_METHODDEF \ |
| 818 |
{"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, |
| 819 |
|
| 820 |
static PyObject * |
| 821 |
builtin_locals_impl(PyObject *module); |
| 822 |
|
| 823 |
static PyObject * |
| 824 |
builtin_locals(PyObject *module, PyObject *Py_UNUSED(ignored)) |
| 825 |
{ |
| 826 |
return builtin_locals_impl(module); |
| 827 |
} |
| 828 |
|
| 829 |
PyDoc_STRVAR(builtin_oct__doc__, |
| 830 |
"oct($module, number, /)\n" |
| 831 |
"--\n" |
| 832 |
"\n" |
| 833 |
"Return the octal representation of an integer.\n" |
| 834 |
"\n" |
| 835 |
" >>> oct(342391)\n" |
| 836 |
" \'0o1234567\'"); |
| 837 |
|
| 838 |
#define BUILTIN_OCT_METHODDEF \ |
| 839 |
{"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, |
| 840 |
|
| 841 |
PyDoc_STRVAR(builtin_ord__doc__, |
| 842 |
"ord($module, character, /)\n" |
| 843 |
"--\n" |
| 844 |
"\n" |
| 845 |
"Return the ordinal value of a character.\n" |
| 846 |
"\n" |
| 847 |
"If the argument is a one-character string, return the Unicode code\n" |
| 848 |
"point of that character.\n" |
| 849 |
"\n" |
| 850 |
"If the argument is a bytes or bytearray object of length 1, return its\n" |
| 851 |
"single byte value."); |
| 852 |
|
| 853 |
#define BUILTIN_ORD_METHODDEF \ |
| 854 |
{"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, |
| 855 |
|
| 856 |
PyDoc_STRVAR(builtin_pow__doc__, |
| 857 |
"pow($module, /, base, exp, mod=None)\n" |
| 858 |
"--\n" |
| 859 |
"\n" |
| 860 |
"Equivalent to base**exp with 2 arguments or base**exp % mod with 3 arguments\n" |
| 861 |
"\n" |
| 862 |
"Some types, such as ints, are able to use a more efficient algorithm\n" |
| 863 |
"when invoked using the three argument form."); |
| 864 |
|
| 865 |
#define BUILTIN_POW_METHODDEF \ |
| 866 |
{"pow", _PyCFunction_CAST(builtin_pow), METH_FASTCALL|METH_KEYWORDS, builtin_pow__doc__}, |
| 867 |
|
| 868 |
static PyObject * |
| 869 |
builtin_pow_impl(PyObject *module, PyObject *base, PyObject *exp, |
| 870 |
PyObject *mod); |
| 871 |
|
| 872 |
static PyObject * |
| 873 |
builtin_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 874 |
{ |
| 875 |
PyObject *return_value = NULL; |
| 876 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 877 |
|
| 878 |
#define NUM_KEYWORDS 3 |
| 879 |
static struct { |
| 880 |
PyGC_Head _this_is_not_used; |
| 881 |
PyObject_VAR_HEAD |
| 882 |
Py_hash_t ob_hash; |
| 883 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 884 |
} _kwtuple = { |
| 885 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 886 |
.ob_hash = -1, |
| 887 |
.ob_item = { &_Py_ID(base), &_Py_ID(exp), &_Py_ID(mod), }, |
| 888 |
}; |
| 889 |
#undef NUM_KEYWORDS |
| 890 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 891 |
|
| 892 |
#else // !Py_BUILD_CORE |
| 893 |
# define KWTUPLE NULL |
| 894 |
#endif // !Py_BUILD_CORE |
| 895 |
|
| 896 |
static const char * const _keywords[] = {"base", "exp", "mod", NULL}; |
| 897 |
static _PyArg_Parser _parser = { |
| 898 |
.keywords = _keywords, |
| 899 |
.fname = "pow", |
| 900 |
.kwtuple = KWTUPLE, |
| 901 |
}; |
| 902 |
#undef KWTUPLE |
| 903 |
PyObject *argsbuf[3]; |
| 904 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2; |
| 905 |
PyObject *base; |
| 906 |
PyObject *exp; |
| 907 |
PyObject *mod = Py_None; |
| 908 |
|
| 909 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 910 |
/*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 911 |
if (!args) { |
| 912 |
goto exit; |
| 913 |
} |
| 914 |
base = args[0]; |
| 915 |
exp = args[1]; |
| 916 |
if (!noptargs) { |
| 917 |
goto skip_optional_pos; |
| 918 |
} |
| 919 |
mod = args[2]; |
| 920 |
skip_optional_pos: |
| 921 |
return_value = builtin_pow_impl(module, base, exp, mod); |
| 922 |
|
| 923 |
exit: |
| 924 |
return return_value; |
| 925 |
} |
| 926 |
|
| 927 |
PyDoc_STRVAR(builtin_print__doc__, |
| 928 |
"print($module, /, *args, sep=\' \', end=\'\\n\', file=None, flush=False)\n" |
| 929 |
"--\n" |
| 930 |
"\n" |
| 931 |
"Prints the values to a stream, or to sys.stdout by default.\n" |
| 932 |
"\n" |
| 933 |
" sep\n" |
| 934 |
" string inserted between values, default a space.\n" |
| 935 |
" end\n" |
| 936 |
" string appended after the last value, default a newline.\n" |
| 937 |
" file\n" |
| 938 |
" a file-like object (stream); defaults to the current sys.stdout.\n" |
| 939 |
" flush\n" |
| 940 |
" whether to forcibly flush the stream."); |
| 941 |
|
| 942 |
#define BUILTIN_PRINT_METHODDEF \ |
| 943 |
{"print", _PyCFunction_CAST(builtin_print), METH_FASTCALL|METH_KEYWORDS, builtin_print__doc__}, |
| 944 |
|
| 945 |
static PyObject * |
| 946 |
builtin_print_impl(PyObject *module, PyObject * const *args, |
| 947 |
Py_ssize_t args_length, PyObject *sep, PyObject *end, |
| 948 |
PyObject *file, int flush); |
| 949 |
|
| 950 |
static PyObject * |
| 951 |
builtin_print(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 952 |
{ |
| 953 |
PyObject *return_value = NULL; |
| 954 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 955 |
|
| 956 |
#define NUM_KEYWORDS 4 |
| 957 |
static struct { |
| 958 |
PyGC_Head _this_is_not_used; |
| 959 |
PyObject_VAR_HEAD |
| 960 |
Py_hash_t ob_hash; |
| 961 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 962 |
} _kwtuple = { |
| 963 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 964 |
.ob_hash = -1, |
| 965 |
.ob_item = { &_Py_ID(sep), &_Py_ID(end), &_Py_ID(file), &_Py_ID(flush), }, |
| 966 |
}; |
| 967 |
#undef NUM_KEYWORDS |
| 968 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 969 |
|
| 970 |
#else // !Py_BUILD_CORE |
| 971 |
# define KWTUPLE NULL |
| 972 |
#endif // !Py_BUILD_CORE |
| 973 |
|
| 974 |
static const char * const _keywords[] = {"sep", "end", "file", "flush", NULL}; |
| 975 |
static _PyArg_Parser _parser = { |
| 976 |
.keywords = _keywords, |
| 977 |
.fname = "print", |
| 978 |
.kwtuple = KWTUPLE, |
| 979 |
}; |
| 980 |
#undef KWTUPLE |
| 981 |
PyObject *argsbuf[4]; |
| 982 |
PyObject * const *fastargs; |
| 983 |
Py_ssize_t noptargs = 0 + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
| 984 |
PyObject * const *__clinic_args; |
| 985 |
Py_ssize_t args_length; |
| 986 |
PyObject *sep = Py_None; |
| 987 |
PyObject *end = Py_None; |
| 988 |
PyObject *file = Py_None; |
| 989 |
int flush = 0; |
| 990 |
|
| 991 |
fastargs = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 992 |
/*minpos*/ 0, /*maxpos*/ 0, /*minkw*/ 0, /*varpos*/ 1, argsbuf); |
| 993 |
if (!fastargs) { |
| 994 |
goto exit; |
| 995 |
} |
| 996 |
if (!noptargs) { |
| 997 |
goto skip_optional_kwonly; |
| 998 |
} |
| 999 |
if (fastargs[0]) { |
| 1000 |
sep = fastargs[0]; |
| 1001 |
if (!--noptargs) { |
| 1002 |
goto skip_optional_kwonly; |
| 1003 |
} |
| 1004 |
} |
| 1005 |
if (fastargs[1]) { |
| 1006 |
end = fastargs[1]; |
| 1007 |
if (!--noptargs) { |
| 1008 |
goto skip_optional_kwonly; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
if (fastargs[2]) { |
| 1012 |
file = fastargs[2]; |
| 1013 |
if (!--noptargs) { |
| 1014 |
goto skip_optional_kwonly; |
| 1015 |
} |
| 1016 |
} |
| 1017 |
flush = PyObject_IsTrue(fastargs[3]); |
| 1018 |
if (flush < 0) { |
| 1019 |
goto exit; |
| 1020 |
} |
| 1021 |
skip_optional_kwonly: |
| 1022 |
__clinic_args = args; |
| 1023 |
args_length = nargs; |
| 1024 |
return_value = builtin_print_impl(module, __clinic_args, args_length, sep, end, file, flush); |
| 1025 |
|
| 1026 |
exit: |
| 1027 |
return return_value; |
| 1028 |
} |
| 1029 |
|
| 1030 |
PyDoc_STRVAR(builtin_input__doc__, |
| 1031 |
"input($module, prompt=\'\', /)\n" |
| 1032 |
"--\n" |
| 1033 |
"\n" |
| 1034 |
"Read a string from standard input. The trailing newline is stripped.\n" |
| 1035 |
"\n" |
| 1036 |
"The prompt string, if given, is printed to standard output without a\n" |
| 1037 |
"trailing newline before reading input.\n" |
| 1038 |
"\n" |
| 1039 |
"If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise\n" |
| 1040 |
"EOFError.\n" |
| 1041 |
"On *nix systems, readline is used if available."); |
| 1042 |
|
| 1043 |
#define BUILTIN_INPUT_METHODDEF \ |
| 1044 |
{"input", _PyCFunction_CAST(builtin_input), METH_FASTCALL, builtin_input__doc__}, |
| 1045 |
|
| 1046 |
static PyObject * |
| 1047 |
builtin_input_impl(PyObject *module, PyObject *prompt); |
| 1048 |
|
| 1049 |
static PyObject * |
| 1050 |
builtin_input(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1051 |
{ |
| 1052 |
PyObject *return_value = NULL; |
| 1053 |
PyObject *prompt = NULL; |
| 1054 |
|
| 1055 |
if (!_PyArg_CheckPositional("input", nargs, 0, 1)) { |
| 1056 |
goto exit; |
| 1057 |
} |
| 1058 |
if (nargs < 1) { |
| 1059 |
goto skip_optional; |
| 1060 |
} |
| 1061 |
prompt = args[0]; |
| 1062 |
skip_optional: |
| 1063 |
return_value = builtin_input_impl(module, prompt); |
| 1064 |
|
| 1065 |
exit: |
| 1066 |
return return_value; |
| 1067 |
} |
| 1068 |
|
| 1069 |
PyDoc_STRVAR(builtin_repr__doc__, |
| 1070 |
"repr($module, obj, /)\n" |
| 1071 |
"--\n" |
| 1072 |
"\n" |
| 1073 |
"Return the canonical string representation of the object.\n" |
| 1074 |
"\n" |
| 1075 |
"For many object types, including most builtins, eval(repr(obj)) == obj."); |
| 1076 |
|
| 1077 |
#define BUILTIN_REPR_METHODDEF \ |
| 1078 |
{"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, |
| 1079 |
|
| 1080 |
PyDoc_STRVAR(builtin_round__doc__, |
| 1081 |
"round($module, /, number, ndigits=None)\n" |
| 1082 |
"--\n" |
| 1083 |
"\n" |
| 1084 |
"Round a number to a given precision in decimal digits.\n" |
| 1085 |
"\n" |
| 1086 |
"The return value is an integer if ndigits is omitted or None.\n" |
| 1087 |
"Otherwise the return value has the same type as the number. ndigits\n" |
| 1088 |
"may be negative."); |
| 1089 |
|
| 1090 |
#define BUILTIN_ROUND_METHODDEF \ |
| 1091 |
{"round", _PyCFunction_CAST(builtin_round), METH_FASTCALL|METH_KEYWORDS, builtin_round__doc__}, |
| 1092 |
|
| 1093 |
static PyObject * |
| 1094 |
builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits); |
| 1095 |
|
| 1096 |
static PyObject * |
| 1097 |
builtin_round(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1098 |
{ |
| 1099 |
PyObject *return_value = NULL; |
| 1100 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1101 |
|
| 1102 |
#define NUM_KEYWORDS 2 |
| 1103 |
static struct { |
| 1104 |
PyGC_Head _this_is_not_used; |
| 1105 |
PyObject_VAR_HEAD |
| 1106 |
Py_hash_t ob_hash; |
| 1107 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1108 |
} _kwtuple = { |
| 1109 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1110 |
.ob_hash = -1, |
| 1111 |
.ob_item = { &_Py_ID(number), &_Py_ID(ndigits), }, |
| 1112 |
}; |
| 1113 |
#undef NUM_KEYWORDS |
| 1114 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1115 |
|
| 1116 |
#else // !Py_BUILD_CORE |
| 1117 |
# define KWTUPLE NULL |
| 1118 |
#endif // !Py_BUILD_CORE |
| 1119 |
|
| 1120 |
static const char * const _keywords[] = {"number", "ndigits", NULL}; |
| 1121 |
static _PyArg_Parser _parser = { |
| 1122 |
.keywords = _keywords, |
| 1123 |
.fname = "round", |
| 1124 |
.kwtuple = KWTUPLE, |
| 1125 |
}; |
| 1126 |
#undef KWTUPLE |
| 1127 |
PyObject *argsbuf[2]; |
| 1128 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 1129 |
PyObject *number; |
| 1130 |
PyObject *ndigits = Py_None; |
| 1131 |
|
| 1132 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 1133 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 1134 |
if (!args) { |
| 1135 |
goto exit; |
| 1136 |
} |
| 1137 |
number = args[0]; |
| 1138 |
if (!noptargs) { |
| 1139 |
goto skip_optional_pos; |
| 1140 |
} |
| 1141 |
ndigits = args[1]; |
| 1142 |
skip_optional_pos: |
| 1143 |
return_value = builtin_round_impl(module, number, ndigits); |
| 1144 |
|
| 1145 |
exit: |
| 1146 |
return return_value; |
| 1147 |
} |
| 1148 |
|
| 1149 |
PyDoc_STRVAR(builtin_sum__doc__, |
| 1150 |
"sum($module, iterable, /, start=0)\n" |
| 1151 |
"--\n" |
| 1152 |
"\n" |
| 1153 |
"Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" |
| 1154 |
"\n" |
| 1155 |
"When the iterable is empty, return the start value.\n" |
| 1156 |
"This function is intended specifically for use with numeric values and\n" |
| 1157 |
"may reject non-numeric types."); |
| 1158 |
|
| 1159 |
#define BUILTIN_SUM_METHODDEF \ |
| 1160 |
{"sum", _PyCFunction_CAST(builtin_sum), METH_FASTCALL|METH_KEYWORDS, builtin_sum__doc__}, |
| 1161 |
|
| 1162 |
static PyObject * |
| 1163 |
builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start); |
| 1164 |
|
| 1165 |
static PyObject * |
| 1166 |
builtin_sum(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
| 1167 |
{ |
| 1168 |
PyObject *return_value = NULL; |
| 1169 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 1170 |
|
| 1171 |
#define NUM_KEYWORDS 1 |
| 1172 |
static struct { |
| 1173 |
PyGC_Head _this_is_not_used; |
| 1174 |
PyObject_VAR_HEAD |
| 1175 |
Py_hash_t ob_hash; |
| 1176 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 1177 |
} _kwtuple = { |
| 1178 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 1179 |
.ob_hash = -1, |
| 1180 |
.ob_item = { &_Py_ID(start), }, |
| 1181 |
}; |
| 1182 |
#undef NUM_KEYWORDS |
| 1183 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 1184 |
|
| 1185 |
#else // !Py_BUILD_CORE |
| 1186 |
# define KWTUPLE NULL |
| 1187 |
#endif // !Py_BUILD_CORE |
| 1188 |
|
| 1189 |
static const char * const _keywords[] = {"", "start", NULL}; |
| 1190 |
static _PyArg_Parser _parser = { |
| 1191 |
.keywords = _keywords, |
| 1192 |
.fname = "sum", |
| 1193 |
.kwtuple = KWTUPLE, |
| 1194 |
}; |
| 1195 |
#undef KWTUPLE |
| 1196 |
PyObject *argsbuf[2]; |
| 1197 |
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1; |
| 1198 |
PyObject *iterable; |
| 1199 |
PyObject *start = NULL; |
| 1200 |
|
| 1201 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 1202 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 1203 |
if (!args) { |
| 1204 |
goto exit; |
| 1205 |
} |
| 1206 |
iterable = args[0]; |
| 1207 |
if (!noptargs) { |
| 1208 |
goto skip_optional_pos; |
| 1209 |
} |
| 1210 |
start = args[1]; |
| 1211 |
skip_optional_pos: |
| 1212 |
return_value = builtin_sum_impl(module, iterable, start); |
| 1213 |
|
| 1214 |
exit: |
| 1215 |
return return_value; |
| 1216 |
} |
| 1217 |
|
| 1218 |
PyDoc_STRVAR(builtin_isinstance__doc__, |
| 1219 |
"isinstance($module, obj, class_or_tuple, /)\n" |
| 1220 |
"--\n" |
| 1221 |
"\n" |
| 1222 |
"Return whether an object is an instance of a class or of a subclass thereof.\n" |
| 1223 |
"\n" |
| 1224 |
"A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the\n" |
| 1225 |
"target to check against. This is equivalent to ``isinstance(x, A) or\n" |
| 1226 |
"isinstance(x, B) or ...`` etc."); |
| 1227 |
|
| 1228 |
#define BUILTIN_ISINSTANCE_METHODDEF \ |
| 1229 |
{"isinstance", _PyCFunction_CAST(builtin_isinstance), METH_FASTCALL, builtin_isinstance__doc__}, |
| 1230 |
|
| 1231 |
static PyObject * |
| 1232 |
builtin_isinstance_impl(PyObject *module, PyObject *obj, |
| 1233 |
PyObject *class_or_tuple); |
| 1234 |
|
| 1235 |
static PyObject * |
| 1236 |
builtin_isinstance(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1237 |
{ |
| 1238 |
PyObject *return_value = NULL; |
| 1239 |
PyObject *obj; |
| 1240 |
PyObject *class_or_tuple; |
| 1241 |
|
| 1242 |
if (!_PyArg_CheckPositional("isinstance", nargs, 2, 2)) { |
| 1243 |
goto exit; |
| 1244 |
} |
| 1245 |
obj = args[0]; |
| 1246 |
class_or_tuple = args[1]; |
| 1247 |
return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
| 1248 |
|
| 1249 |
exit: |
| 1250 |
return return_value; |
| 1251 |
} |
| 1252 |
|
| 1253 |
PyDoc_STRVAR(builtin_issubclass__doc__, |
| 1254 |
"issubclass($module, cls, class_or_tuple, /)\n" |
| 1255 |
"--\n" |
| 1256 |
"\n" |
| 1257 |
"Return whether \'cls\' is derived from another class or is the same class.\n" |
| 1258 |
"\n" |
| 1259 |
"A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the\n" |
| 1260 |
"target to check against. This is equivalent to ``issubclass(x, A) or\n" |
| 1261 |
"issubclass(x, B) or ...``."); |
| 1262 |
|
| 1263 |
#define BUILTIN_ISSUBCLASS_METHODDEF \ |
| 1264 |
{"issubclass", _PyCFunction_CAST(builtin_issubclass), METH_FASTCALL, builtin_issubclass__doc__}, |
| 1265 |
|
| 1266 |
static PyObject * |
| 1267 |
builtin_issubclass_impl(PyObject *module, PyObject *cls, |
| 1268 |
PyObject *class_or_tuple); |
| 1269 |
|
| 1270 |
static PyObject * |
| 1271 |
builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
| 1272 |
{ |
| 1273 |
PyObject *return_value = NULL; |
| 1274 |
PyObject *cls; |
| 1275 |
PyObject *class_or_tuple; |
| 1276 |
|
| 1277 |
if (!_PyArg_CheckPositional("issubclass", nargs, 2, 2)) { |
| 1278 |
goto exit; |
| 1279 |
} |
| 1280 |
cls = args[0]; |
| 1281 |
class_or_tuple = args[1]; |
| 1282 |
return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
| 1283 |
|
| 1284 |
exit: |
| 1285 |
return return_value; |
| 1286 |
} |
| 1287 |
/*[clinic end generated code: output=bc267a3ce1596f24 input=a9049054013a1b77]*/ |