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