Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(builtin_abs__doc__, |
| 6 | "abs($module, x, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "Return the absolute value of the argument."); |
| 10 | |
| 11 | #define BUILTIN_ABS_METHODDEF \ |
| 12 | {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__}, |
| 13 | |
| 14 | PyDoc_STRVAR(builtin_all__doc__, |
| 15 | "all($module, iterable, /)\n" |
| 16 | "--\n" |
| 17 | "\n" |
| 18 | "Return True if bool(x) is True for all values x in the iterable.\n" |
| 19 | "\n" |
| 20 | "If the iterable is empty, return True."); |
| 21 | |
| 22 | #define BUILTIN_ALL_METHODDEF \ |
| 23 | {"all", (PyCFunction)builtin_all, METH_O, builtin_all__doc__}, |
| 24 | |
| 25 | PyDoc_STRVAR(builtin_any__doc__, |
| 26 | "any($module, iterable, /)\n" |
| 27 | "--\n" |
| 28 | "\n" |
| 29 | "Return True if bool(x) is True for any x in the iterable.\n" |
| 30 | "\n" |
| 31 | "If the iterable is empty, return False."); |
| 32 | |
| 33 | #define BUILTIN_ANY_METHODDEF \ |
| 34 | {"any", (PyCFunction)builtin_any, METH_O, builtin_any__doc__}, |
| 35 | |
| 36 | PyDoc_STRVAR(builtin_ascii__doc__, |
| 37 | "ascii($module, obj, /)\n" |
| 38 | "--\n" |
| 39 | "\n" |
| 40 | "Return an ASCII-only representation of an object.\n" |
| 41 | "\n" |
| 42 | "As repr(), return a string containing a printable representation of an\n" |
| 43 | "object, but escape the non-ASCII characters in the string returned by\n" |
| 44 | "repr() using \\\\x, \\\\u or \\\\U escapes. This generates a string similar\n" |
| 45 | "to that returned by repr() in Python 2."); |
| 46 | |
| 47 | #define BUILTIN_ASCII_METHODDEF \ |
| 48 | {"ascii", (PyCFunction)builtin_ascii, METH_O, builtin_ascii__doc__}, |
| 49 | |
| 50 | PyDoc_STRVAR(builtin_bin__doc__, |
| 51 | "bin($module, number, /)\n" |
| 52 | "--\n" |
| 53 | "\n" |
| 54 | "Return the binary representation of an integer.\n" |
| 55 | "\n" |
| 56 | " >>> bin(2796202)\n" |
| 57 | " \'0b1010101010101010101010\'"); |
| 58 | |
| 59 | #define BUILTIN_BIN_METHODDEF \ |
| 60 | {"bin", (PyCFunction)builtin_bin, METH_O, builtin_bin__doc__}, |
| 61 | |
| 62 | PyDoc_STRVAR(builtin_callable__doc__, |
| 63 | "callable($module, obj, /)\n" |
| 64 | "--\n" |
| 65 | "\n" |
| 66 | "Return whether the object is callable (i.e., some kind of function).\n" |
| 67 | "\n" |
| 68 | "Note that classes are callable, as are instances of classes with a\n" |
| 69 | "__call__() method."); |
| 70 | |
| 71 | #define BUILTIN_CALLABLE_METHODDEF \ |
| 72 | {"callable", (PyCFunction)builtin_callable, METH_O, builtin_callable__doc__}, |
| 73 | |
| 74 | PyDoc_STRVAR(builtin_format__doc__, |
| 75 | "format($module, value, format_spec=\'\', /)\n" |
| 76 | "--\n" |
| 77 | "\n" |
| 78 | "Return value.__format__(format_spec)\n" |
| 79 | "\n" |
| 80 | "format_spec defaults to the empty string"); |
| 81 | |
| 82 | #define BUILTIN_FORMAT_METHODDEF \ |
| 83 | {"format", (PyCFunction)builtin_format, METH_VARARGS, builtin_format__doc__}, |
| 84 | |
| 85 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 86 | builtin_format_impl(PyModuleDef *module, PyObject *value, |
| 87 | PyObject *format_spec); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 88 | |
| 89 | static PyObject * |
| 90 | builtin_format(PyModuleDef *module, PyObject *args) |
| 91 | { |
| 92 | PyObject *return_value = NULL; |
| 93 | PyObject *value; |
| 94 | PyObject *format_spec = NULL; |
| 95 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 96 | if (!PyArg_ParseTuple(args, "O|U:format", |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 97 | &value, &format_spec)) |
| 98 | goto exit; |
| 99 | return_value = builtin_format_impl(module, value, format_spec); |
| 100 | |
| 101 | exit: |
| 102 | return return_value; |
| 103 | } |
| 104 | |
| 105 | PyDoc_STRVAR(builtin_chr__doc__, |
| 106 | "chr($module, i, /)\n" |
| 107 | "--\n" |
| 108 | "\n" |
| 109 | "Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff."); |
| 110 | |
| 111 | #define BUILTIN_CHR_METHODDEF \ |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 112 | {"chr", (PyCFunction)builtin_chr, METH_O, builtin_chr__doc__}, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 113 | |
| 114 | static PyObject * |
| 115 | builtin_chr_impl(PyModuleDef *module, int i); |
| 116 | |
| 117 | static PyObject * |
Serhiy Storchaka | 92e8af6 | 2015-04-04 00:12:11 +0300 | [diff] [blame] | 118 | builtin_chr(PyModuleDef *module, PyObject *arg) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 119 | { |
| 120 | PyObject *return_value = NULL; |
| 121 | int i; |
| 122 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 123 | if (!PyArg_Parse(arg, "i:chr", &i)) |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 124 | goto exit; |
| 125 | return_value = builtin_chr_impl(module, i); |
| 126 | |
| 127 | exit: |
| 128 | return return_value; |
| 129 | } |
| 130 | |
| 131 | PyDoc_STRVAR(builtin_compile__doc__, |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 132 | "compile($module, /, source, filename, mode, flags=0,\n" |
| 133 | " dont_inherit=False, optimize=-1)\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 134 | "--\n" |
| 135 | "\n" |
| 136 | "Compile source into a code object that can be executed by exec() or eval().\n" |
| 137 | "\n" |
| 138 | "The source code may represent a Python module, statement or expression.\n" |
| 139 | "The filename will be used for run-time error messages.\n" |
| 140 | "The mode must be \'exec\' to compile a module, \'single\' to compile a\n" |
| 141 | "single (interactive) statement, or \'eval\' to compile an expression.\n" |
| 142 | "The flags argument, if present, controls which future statements influence\n" |
| 143 | "the compilation of the code.\n" |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 144 | "The dont_inherit argument, if true, stops the compilation inheriting\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 145 | "the effects of any future statements in effect in the code calling\n" |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 146 | "compile; if absent or false these statements do influence the compilation,\n" |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 147 | "in addition to any features explicitly specified."); |
| 148 | |
| 149 | #define BUILTIN_COMPILE_METHODDEF \ |
| 150 | {"compile", (PyCFunction)builtin_compile, METH_VARARGS|METH_KEYWORDS, builtin_compile__doc__}, |
| 151 | |
| 152 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 153 | builtin_compile_impl(PyModuleDef *module, PyObject *source, |
| 154 | PyObject *filename, const char *mode, int flags, |
| 155 | int dont_inherit, int optimize); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 156 | |
| 157 | static PyObject * |
| 158 | builtin_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs) |
| 159 | { |
| 160 | PyObject *return_value = NULL; |
| 161 | static char *_keywords[] = {"source", "filename", "mode", "flags", "dont_inherit", "optimize", NULL}; |
| 162 | PyObject *source; |
| 163 | PyObject *filename; |
| 164 | const char *mode; |
| 165 | int flags = 0; |
| 166 | int dont_inherit = 0; |
| 167 | int optimize = -1; |
| 168 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 169 | if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO&s|iii:compile", _keywords, |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 170 | &source, PyUnicode_FSDecoder, &filename, &mode, &flags, &dont_inherit, &optimize)) |
| 171 | goto exit; |
| 172 | return_value = builtin_compile_impl(module, source, filename, mode, flags, dont_inherit, optimize); |
| 173 | |
| 174 | exit: |
| 175 | return return_value; |
| 176 | } |
| 177 | |
| 178 | PyDoc_STRVAR(builtin_divmod__doc__, |
| 179 | "divmod($module, x, y, /)\n" |
| 180 | "--\n" |
| 181 | "\n" |
| 182 | "Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x."); |
| 183 | |
| 184 | #define BUILTIN_DIVMOD_METHODDEF \ |
| 185 | {"divmod", (PyCFunction)builtin_divmod, METH_VARARGS, builtin_divmod__doc__}, |
| 186 | |
| 187 | static PyObject * |
| 188 | builtin_divmod_impl(PyModuleDef *module, PyObject *x, PyObject *y); |
| 189 | |
| 190 | static PyObject * |
| 191 | builtin_divmod(PyModuleDef *module, PyObject *args) |
| 192 | { |
| 193 | PyObject *return_value = NULL; |
| 194 | PyObject *x; |
| 195 | PyObject *y; |
| 196 | |
| 197 | if (!PyArg_UnpackTuple(args, "divmod", |
| 198 | 2, 2, |
| 199 | &x, &y)) |
| 200 | goto exit; |
| 201 | return_value = builtin_divmod_impl(module, x, y); |
| 202 | |
| 203 | exit: |
| 204 | return return_value; |
| 205 | } |
| 206 | |
| 207 | PyDoc_STRVAR(builtin_eval__doc__, |
| 208 | "eval($module, source, globals=None, locals=None, /)\n" |
| 209 | "--\n" |
| 210 | "\n" |
| 211 | "Evaluate the given source in the context of globals and locals.\n" |
| 212 | "\n" |
| 213 | "The source may be a string representing a Python expression\n" |
| 214 | "or a code object as returned by compile().\n" |
| 215 | "The globals must be a dictionary and locals can be any mapping,\n" |
| 216 | "defaulting to the current globals and locals.\n" |
| 217 | "If only globals is given, locals defaults to it."); |
| 218 | |
| 219 | #define BUILTIN_EVAL_METHODDEF \ |
| 220 | {"eval", (PyCFunction)builtin_eval, METH_VARARGS, builtin_eval__doc__}, |
| 221 | |
| 222 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 223 | builtin_eval_impl(PyModuleDef *module, PyObject *source, PyObject *globals, |
| 224 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 225 | |
| 226 | static PyObject * |
| 227 | builtin_eval(PyModuleDef *module, PyObject *args) |
| 228 | { |
| 229 | PyObject *return_value = NULL; |
| 230 | PyObject *source; |
| 231 | PyObject *globals = Py_None; |
| 232 | PyObject *locals = Py_None; |
| 233 | |
| 234 | if (!PyArg_UnpackTuple(args, "eval", |
| 235 | 1, 3, |
| 236 | &source, &globals, &locals)) |
| 237 | goto exit; |
| 238 | return_value = builtin_eval_impl(module, source, globals, locals); |
| 239 | |
| 240 | exit: |
| 241 | return return_value; |
| 242 | } |
| 243 | |
| 244 | PyDoc_STRVAR(builtin_exec__doc__, |
| 245 | "exec($module, source, globals=None, locals=None, /)\n" |
| 246 | "--\n" |
| 247 | "\n" |
| 248 | "Execute the given source in the context of globals and locals.\n" |
| 249 | "\n" |
| 250 | "The source may be a string representing one or more Python statements\n" |
| 251 | "or a code object as returned by compile().\n" |
| 252 | "The globals must be a dictionary and locals can be any mapping,\n" |
| 253 | "defaulting to the current globals and locals.\n" |
| 254 | "If only globals is given, locals defaults to it."); |
| 255 | |
| 256 | #define BUILTIN_EXEC_METHODDEF \ |
| 257 | {"exec", (PyCFunction)builtin_exec, METH_VARARGS, builtin_exec__doc__}, |
| 258 | |
| 259 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 260 | builtin_exec_impl(PyModuleDef *module, PyObject *source, PyObject *globals, |
| 261 | PyObject *locals); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 262 | |
| 263 | static PyObject * |
| 264 | builtin_exec(PyModuleDef *module, PyObject *args) |
| 265 | { |
| 266 | PyObject *return_value = NULL; |
| 267 | PyObject *source; |
| 268 | PyObject *globals = Py_None; |
| 269 | PyObject *locals = Py_None; |
| 270 | |
| 271 | if (!PyArg_UnpackTuple(args, "exec", |
| 272 | 1, 3, |
| 273 | &source, &globals, &locals)) |
| 274 | goto exit; |
| 275 | return_value = builtin_exec_impl(module, source, globals, locals); |
| 276 | |
| 277 | exit: |
| 278 | return return_value; |
| 279 | } |
| 280 | |
| 281 | PyDoc_STRVAR(builtin_globals__doc__, |
| 282 | "globals($module, /)\n" |
| 283 | "--\n" |
| 284 | "\n" |
| 285 | "Return the dictionary containing the current scope\'s global variables.\n" |
| 286 | "\n" |
| 287 | "NOTE: Updates to this dictionary *will* affect name lookups in the current\n" |
| 288 | "global scope and vice-versa."); |
| 289 | |
| 290 | #define BUILTIN_GLOBALS_METHODDEF \ |
| 291 | {"globals", (PyCFunction)builtin_globals, METH_NOARGS, builtin_globals__doc__}, |
| 292 | |
| 293 | static PyObject * |
| 294 | builtin_globals_impl(PyModuleDef *module); |
| 295 | |
| 296 | static PyObject * |
| 297 | builtin_globals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 298 | { |
| 299 | return builtin_globals_impl(module); |
| 300 | } |
| 301 | |
| 302 | PyDoc_STRVAR(builtin_hasattr__doc__, |
| 303 | "hasattr($module, obj, name, /)\n" |
| 304 | "--\n" |
| 305 | "\n" |
| 306 | "Return whether the object has an attribute with the given name.\n" |
| 307 | "\n" |
| 308 | "This is done by calling getattr(obj, name) and catching AttributeError."); |
| 309 | |
| 310 | #define BUILTIN_HASATTR_METHODDEF \ |
| 311 | {"hasattr", (PyCFunction)builtin_hasattr, METH_VARARGS, builtin_hasattr__doc__}, |
| 312 | |
| 313 | static PyObject * |
| 314 | builtin_hasattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); |
| 315 | |
| 316 | static PyObject * |
| 317 | builtin_hasattr(PyModuleDef *module, PyObject *args) |
| 318 | { |
| 319 | PyObject *return_value = NULL; |
| 320 | PyObject *obj; |
| 321 | PyObject *name; |
| 322 | |
| 323 | if (!PyArg_UnpackTuple(args, "hasattr", |
| 324 | 2, 2, |
| 325 | &obj, &name)) |
| 326 | goto exit; |
| 327 | return_value = builtin_hasattr_impl(module, obj, name); |
| 328 | |
| 329 | exit: |
| 330 | return return_value; |
| 331 | } |
| 332 | |
| 333 | PyDoc_STRVAR(builtin_id__doc__, |
| 334 | "id($module, obj, /)\n" |
| 335 | "--\n" |
| 336 | "\n" |
| 337 | "Return the identity of an object.\n" |
| 338 | "\n" |
| 339 | "This is guaranteed to be unique among simultaneously existing objects.\n" |
| 340 | "(CPython uses the object\'s memory address.)"); |
| 341 | |
| 342 | #define BUILTIN_ID_METHODDEF \ |
| 343 | {"id", (PyCFunction)builtin_id, METH_O, builtin_id__doc__}, |
| 344 | |
| 345 | PyDoc_STRVAR(builtin_setattr__doc__, |
| 346 | "setattr($module, obj, name, value, /)\n" |
| 347 | "--\n" |
| 348 | "\n" |
| 349 | "Sets the named attribute on the given object to the specified value.\n" |
| 350 | "\n" |
| 351 | "setattr(x, \'y\', v) is equivalent to ``x.y = v\'\'"); |
| 352 | |
| 353 | #define BUILTIN_SETATTR_METHODDEF \ |
| 354 | {"setattr", (PyCFunction)builtin_setattr, METH_VARARGS, builtin_setattr__doc__}, |
| 355 | |
| 356 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 357 | builtin_setattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name, |
| 358 | PyObject *value); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 359 | |
| 360 | static PyObject * |
| 361 | builtin_setattr(PyModuleDef *module, PyObject *args) |
| 362 | { |
| 363 | PyObject *return_value = NULL; |
| 364 | PyObject *obj; |
| 365 | PyObject *name; |
| 366 | PyObject *value; |
| 367 | |
| 368 | if (!PyArg_UnpackTuple(args, "setattr", |
| 369 | 3, 3, |
| 370 | &obj, &name, &value)) |
| 371 | goto exit; |
| 372 | return_value = builtin_setattr_impl(module, obj, name, value); |
| 373 | |
| 374 | exit: |
| 375 | return return_value; |
| 376 | } |
| 377 | |
| 378 | PyDoc_STRVAR(builtin_delattr__doc__, |
| 379 | "delattr($module, obj, name, /)\n" |
| 380 | "--\n" |
| 381 | "\n" |
| 382 | "Deletes the named attribute from the given object.\n" |
| 383 | "\n" |
| 384 | "delattr(x, \'y\') is equivalent to ``del x.y\'\'"); |
| 385 | |
| 386 | #define BUILTIN_DELATTR_METHODDEF \ |
| 387 | {"delattr", (PyCFunction)builtin_delattr, METH_VARARGS, builtin_delattr__doc__}, |
| 388 | |
| 389 | static PyObject * |
| 390 | builtin_delattr_impl(PyModuleDef *module, PyObject *obj, PyObject *name); |
| 391 | |
| 392 | static PyObject * |
| 393 | builtin_delattr(PyModuleDef *module, PyObject *args) |
| 394 | { |
| 395 | PyObject *return_value = NULL; |
| 396 | PyObject *obj; |
| 397 | PyObject *name; |
| 398 | |
| 399 | if (!PyArg_UnpackTuple(args, "delattr", |
| 400 | 2, 2, |
| 401 | &obj, &name)) |
| 402 | goto exit; |
| 403 | return_value = builtin_delattr_impl(module, obj, name); |
| 404 | |
| 405 | exit: |
| 406 | return return_value; |
| 407 | } |
| 408 | |
| 409 | PyDoc_STRVAR(builtin_hash__doc__, |
| 410 | "hash($module, obj, /)\n" |
| 411 | "--\n" |
| 412 | "\n" |
| 413 | "Return the hash value for the given object.\n" |
| 414 | "\n" |
| 415 | "Two objects that compare equal must also have the same hash value, but the\n" |
| 416 | "reverse is not necessarily true."); |
| 417 | |
| 418 | #define BUILTIN_HASH_METHODDEF \ |
| 419 | {"hash", (PyCFunction)builtin_hash, METH_O, builtin_hash__doc__}, |
| 420 | |
| 421 | PyDoc_STRVAR(builtin_hex__doc__, |
| 422 | "hex($module, number, /)\n" |
| 423 | "--\n" |
| 424 | "\n" |
| 425 | "Return the hexadecimal representation of an integer.\n" |
| 426 | "\n" |
| 427 | " >>> hex(12648430)\n" |
| 428 | " \'0xc0ffee\'"); |
| 429 | |
| 430 | #define BUILTIN_HEX_METHODDEF \ |
| 431 | {"hex", (PyCFunction)builtin_hex, METH_O, builtin_hex__doc__}, |
| 432 | |
| 433 | PyDoc_STRVAR(builtin_len__doc__, |
| 434 | "len($module, obj, /)\n" |
| 435 | "--\n" |
| 436 | "\n" |
| 437 | "Return the number of items in a container."); |
| 438 | |
| 439 | #define BUILTIN_LEN_METHODDEF \ |
| 440 | {"len", (PyCFunction)builtin_len, METH_O, builtin_len__doc__}, |
| 441 | |
| 442 | PyDoc_STRVAR(builtin_locals__doc__, |
| 443 | "locals($module, /)\n" |
| 444 | "--\n" |
| 445 | "\n" |
| 446 | "Return a dictionary containing the current scope\'s local variables.\n" |
| 447 | "\n" |
| 448 | "NOTE: Whether or not updates to this dictionary will affect name lookups in\n" |
| 449 | "the local scope and vice-versa is *implementation dependent* and not\n" |
| 450 | "covered by any backwards compatibility guarantees."); |
| 451 | |
| 452 | #define BUILTIN_LOCALS_METHODDEF \ |
| 453 | {"locals", (PyCFunction)builtin_locals, METH_NOARGS, builtin_locals__doc__}, |
| 454 | |
| 455 | static PyObject * |
| 456 | builtin_locals_impl(PyModuleDef *module); |
| 457 | |
| 458 | static PyObject * |
| 459 | builtin_locals(PyModuleDef *module, PyObject *Py_UNUSED(ignored)) |
| 460 | { |
| 461 | return builtin_locals_impl(module); |
| 462 | } |
| 463 | |
| 464 | PyDoc_STRVAR(builtin_oct__doc__, |
| 465 | "oct($module, number, /)\n" |
| 466 | "--\n" |
| 467 | "\n" |
| 468 | "Return the octal representation of an integer.\n" |
| 469 | "\n" |
| 470 | " >>> oct(342391)\n" |
| 471 | " \'0o1234567\'"); |
| 472 | |
| 473 | #define BUILTIN_OCT_METHODDEF \ |
| 474 | {"oct", (PyCFunction)builtin_oct, METH_O, builtin_oct__doc__}, |
| 475 | |
| 476 | PyDoc_STRVAR(builtin_ord__doc__, |
| 477 | "ord($module, c, /)\n" |
| 478 | "--\n" |
| 479 | "\n" |
| 480 | "Return the Unicode code point for a one-character string."); |
| 481 | |
| 482 | #define BUILTIN_ORD_METHODDEF \ |
| 483 | {"ord", (PyCFunction)builtin_ord, METH_O, builtin_ord__doc__}, |
| 484 | |
| 485 | PyDoc_STRVAR(builtin_pow__doc__, |
| 486 | "pow($module, x, y, z=None, /)\n" |
| 487 | "--\n" |
| 488 | "\n" |
| 489 | "Equivalent to x**y (with two arguments) or x**y % z (with three arguments)\n" |
| 490 | "\n" |
| 491 | "Some types, such as ints, are able to use a more efficient algorithm when\n" |
| 492 | "invoked using the three argument form."); |
| 493 | |
| 494 | #define BUILTIN_POW_METHODDEF \ |
| 495 | {"pow", (PyCFunction)builtin_pow, METH_VARARGS, builtin_pow__doc__}, |
| 496 | |
| 497 | static PyObject * |
| 498 | builtin_pow_impl(PyModuleDef *module, PyObject *x, PyObject *y, PyObject *z); |
| 499 | |
| 500 | static PyObject * |
| 501 | builtin_pow(PyModuleDef *module, PyObject *args) |
| 502 | { |
| 503 | PyObject *return_value = NULL; |
| 504 | PyObject *x; |
| 505 | PyObject *y; |
| 506 | PyObject *z = Py_None; |
| 507 | |
| 508 | if (!PyArg_UnpackTuple(args, "pow", |
| 509 | 2, 3, |
| 510 | &x, &y, &z)) |
| 511 | goto exit; |
| 512 | return_value = builtin_pow_impl(module, x, y, z); |
| 513 | |
| 514 | exit: |
| 515 | return return_value; |
| 516 | } |
| 517 | |
| 518 | PyDoc_STRVAR(builtin_input__doc__, |
| 519 | "input($module, prompt=None, /)\n" |
| 520 | "--\n" |
| 521 | "\n" |
| 522 | "Read a string from standard input. The trailing newline is stripped.\n" |
| 523 | "\n" |
| 524 | "The prompt string, if given, is printed to standard output without a\n" |
| 525 | "trailing newline before reading input.\n" |
| 526 | "\n" |
| 527 | "If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.\n" |
| 528 | "On *nix systems, readline is used if available."); |
| 529 | |
| 530 | #define BUILTIN_INPUT_METHODDEF \ |
| 531 | {"input", (PyCFunction)builtin_input, METH_VARARGS, builtin_input__doc__}, |
| 532 | |
| 533 | static PyObject * |
| 534 | builtin_input_impl(PyModuleDef *module, PyObject *prompt); |
| 535 | |
| 536 | static PyObject * |
| 537 | builtin_input(PyModuleDef *module, PyObject *args) |
| 538 | { |
| 539 | PyObject *return_value = NULL; |
| 540 | PyObject *prompt = NULL; |
| 541 | |
| 542 | if (!PyArg_UnpackTuple(args, "input", |
| 543 | 0, 1, |
| 544 | &prompt)) |
| 545 | goto exit; |
| 546 | return_value = builtin_input_impl(module, prompt); |
| 547 | |
| 548 | exit: |
| 549 | return return_value; |
| 550 | } |
| 551 | |
| 552 | PyDoc_STRVAR(builtin_repr__doc__, |
| 553 | "repr($module, obj, /)\n" |
| 554 | "--\n" |
| 555 | "\n" |
| 556 | "Return the canonical string representation of the object.\n" |
| 557 | "\n" |
| 558 | "For many object types, including most builtins, eval(repr(obj)) == obj."); |
| 559 | |
| 560 | #define BUILTIN_REPR_METHODDEF \ |
| 561 | {"repr", (PyCFunction)builtin_repr, METH_O, builtin_repr__doc__}, |
| 562 | |
| 563 | PyDoc_STRVAR(builtin_sum__doc__, |
| 564 | "sum($module, iterable, start=0, /)\n" |
| 565 | "--\n" |
| 566 | "\n" |
| 567 | "Return the sum of a \'start\' value (default: 0) plus an iterable of numbers\n" |
| 568 | "\n" |
| 569 | "When the iterable is empty, return the start value.\n" |
| 570 | "This function is intended specifically for use with numeric values and may\n" |
| 571 | "reject non-numeric types."); |
| 572 | |
| 573 | #define BUILTIN_SUM_METHODDEF \ |
| 574 | {"sum", (PyCFunction)builtin_sum, METH_VARARGS, builtin_sum__doc__}, |
| 575 | |
| 576 | static PyObject * |
| 577 | builtin_sum_impl(PyModuleDef *module, PyObject *iterable, PyObject *start); |
| 578 | |
| 579 | static PyObject * |
| 580 | builtin_sum(PyModuleDef *module, PyObject *args) |
| 581 | { |
| 582 | PyObject *return_value = NULL; |
| 583 | PyObject *iterable; |
| 584 | PyObject *start = NULL; |
| 585 | |
| 586 | if (!PyArg_UnpackTuple(args, "sum", |
| 587 | 1, 2, |
| 588 | &iterable, &start)) |
| 589 | goto exit; |
| 590 | return_value = builtin_sum_impl(module, iterable, start); |
| 591 | |
| 592 | exit: |
| 593 | return return_value; |
| 594 | } |
| 595 | |
| 596 | PyDoc_STRVAR(builtin_isinstance__doc__, |
| 597 | "isinstance($module, obj, class_or_tuple, /)\n" |
| 598 | "--\n" |
| 599 | "\n" |
| 600 | "Return whether an object is an instance of a class or of a subclass thereof.\n" |
| 601 | "\n" |
| 602 | "A tuple, as in ``isinstance(x, (A, B, ...))``, may be given as the target to\n" |
| 603 | "check against. This is equivalent to ``isinstance(x, A) or isinstance(x, B)\n" |
| 604 | "or ...`` etc."); |
| 605 | |
| 606 | #define BUILTIN_ISINSTANCE_METHODDEF \ |
| 607 | {"isinstance", (PyCFunction)builtin_isinstance, METH_VARARGS, builtin_isinstance__doc__}, |
| 608 | |
| 609 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 610 | builtin_isinstance_impl(PyModuleDef *module, PyObject *obj, |
| 611 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 612 | |
| 613 | static PyObject * |
| 614 | builtin_isinstance(PyModuleDef *module, PyObject *args) |
| 615 | { |
| 616 | PyObject *return_value = NULL; |
| 617 | PyObject *obj; |
| 618 | PyObject *class_or_tuple; |
| 619 | |
| 620 | if (!PyArg_UnpackTuple(args, "isinstance", |
| 621 | 2, 2, |
| 622 | &obj, &class_or_tuple)) |
| 623 | goto exit; |
| 624 | return_value = builtin_isinstance_impl(module, obj, class_or_tuple); |
| 625 | |
| 626 | exit: |
| 627 | return return_value; |
| 628 | } |
| 629 | |
| 630 | PyDoc_STRVAR(builtin_issubclass__doc__, |
| 631 | "issubclass($module, cls, class_or_tuple, /)\n" |
| 632 | "--\n" |
| 633 | "\n" |
| 634 | "Return whether \'cls\' is a derived from another class or is the same class.\n" |
| 635 | "\n" |
| 636 | "A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to\n" |
| 637 | "check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B)\n" |
| 638 | "or ...`` etc."); |
| 639 | |
| 640 | #define BUILTIN_ISSUBCLASS_METHODDEF \ |
| 641 | {"issubclass", (PyCFunction)builtin_issubclass, METH_VARARGS, builtin_issubclass__doc__}, |
| 642 | |
| 643 | static PyObject * |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 644 | builtin_issubclass_impl(PyModuleDef *module, PyObject *cls, |
| 645 | PyObject *class_or_tuple); |
Serhiy Storchaka | 1009bf1 | 2015-04-03 23:53:51 +0300 | [diff] [blame] | 646 | |
| 647 | static PyObject * |
| 648 | builtin_issubclass(PyModuleDef *module, PyObject *args) |
| 649 | { |
| 650 | PyObject *return_value = NULL; |
| 651 | PyObject *cls; |
| 652 | PyObject *class_or_tuple; |
| 653 | |
| 654 | if (!PyArg_UnpackTuple(args, "issubclass", |
| 655 | 2, 2, |
| 656 | &cls, &class_or_tuple)) |
| 657 | goto exit; |
| 658 | return_value = builtin_issubclass_impl(module, cls, class_or_tuple); |
| 659 | |
| 660 | exit: |
| 661 | return return_value; |
| 662 | } |
Serhiy Storchaka | 8b2e8b6 | 2015-05-30 11:30:39 +0300 | [diff] [blame] | 663 | /*[clinic end generated code: output=bec3399c0aee98d7 input=a9049054013a1b77]*/ |