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