| 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(mappingproxy_new__doc__, |
| 12 |
"mappingproxy(mapping)\n" |
| 13 |
"--\n" |
| 14 |
"\n" |
| 15 |
"Read-only proxy of a mapping."); |
| 16 |
|
| 17 |
static PyObject * |
| 18 |
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping); |
| 19 |
|
| 20 |
static PyObject * |
| 21 |
mappingproxy_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) |
| 22 |
{ |
| 23 |
PyObject *return_value = NULL; |
| 24 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 25 |
|
| 26 |
#define NUM_KEYWORDS 1 |
| 27 |
static struct { |
| 28 |
PyGC_Head _this_is_not_used; |
| 29 |
PyObject_VAR_HEAD |
| 30 |
Py_hash_t ob_hash; |
| 31 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 32 |
} _kwtuple = { |
| 33 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 34 |
.ob_hash = -1, |
| 35 |
.ob_item = { &_Py_ID(mapping), }, |
| 36 |
}; |
| 37 |
#undef NUM_KEYWORDS |
| 38 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 39 |
|
| 40 |
#else // !Py_BUILD_CORE |
| 41 |
# define KWTUPLE NULL |
| 42 |
#endif // !Py_BUILD_CORE |
| 43 |
|
| 44 |
static const char * const _keywords[] = {"mapping", NULL}; |
| 45 |
static _PyArg_Parser _parser = { |
| 46 |
.keywords = _keywords, |
| 47 |
.fname = "mappingproxy", |
| 48 |
.kwtuple = KWTUPLE, |
| 49 |
}; |
| 50 |
#undef KWTUPLE |
| 51 |
PyObject *argsbuf[1]; |
| 52 |
PyObject * const *fastargs; |
| 53 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 54 |
PyObject *mapping; |
| 55 |
|
| 56 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
| 57 |
/*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 58 |
if (!fastargs) { |
| 59 |
goto exit; |
| 60 |
} |
| 61 |
mapping = fastargs[0]; |
| 62 |
return_value = mappingproxy_new_impl(type, mapping); |
| 63 |
|
| 64 |
exit: |
| 65 |
return return_value; |
| 66 |
} |
| 67 |
|
| 68 |
PyDoc_STRVAR(property_init__doc__, |
| 69 |
"property(fget=None, fset=None, fdel=None, doc=None)\n" |
| 70 |
"--\n" |
| 71 |
"\n" |
| 72 |
"Property attribute.\n" |
| 73 |
"\n" |
| 74 |
" fget\n" |
| 75 |
" function to be used for getting an attribute value\n" |
| 76 |
" fset\n" |
| 77 |
" function to be used for setting an attribute value\n" |
| 78 |
" fdel\n" |
| 79 |
" function to be used for del\'ing an attribute\n" |
| 80 |
" doc\n" |
| 81 |
" docstring\n" |
| 82 |
"\n" |
| 83 |
"Typical use is to define a managed attribute x:\n" |
| 84 |
"\n" |
| 85 |
"class C(object):\n" |
| 86 |
" def getx(self): return self._x\n" |
| 87 |
" def setx(self, value): self._x = value\n" |
| 88 |
" def delx(self): del self._x\n" |
| 89 |
" x = property(getx, setx, delx, \"I\'m the \'x\' property.\")\n" |
| 90 |
"\n" |
| 91 |
"Decorators make defining new properties or modifying existing ones easy:\n" |
| 92 |
"\n" |
| 93 |
"class C(object):\n" |
| 94 |
" @property\n" |
| 95 |
" def x(self):\n" |
| 96 |
" \"I am the \'x\' property.\"\n" |
| 97 |
" return self._x\n" |
| 98 |
" @x.setter\n" |
| 99 |
" def x(self, value):\n" |
| 100 |
" self._x = value\n" |
| 101 |
" @x.deleter\n" |
| 102 |
" def x(self):\n" |
| 103 |
" del self._x"); |
| 104 |
|
| 105 |
static int |
| 106 |
property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, |
| 107 |
PyObject *fdel, PyObject *doc); |
| 108 |
|
| 109 |
static int |
| 110 |
property_init(PyObject *self, PyObject *args, PyObject *kwargs) |
| 111 |
{ |
| 112 |
int return_value = -1; |
| 113 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 114 |
|
| 115 |
#define NUM_KEYWORDS 4 |
| 116 |
static struct { |
| 117 |
PyGC_Head _this_is_not_used; |
| 118 |
PyObject_VAR_HEAD |
| 119 |
Py_hash_t ob_hash; |
| 120 |
PyObject *ob_item[NUM_KEYWORDS]; |
| 121 |
} _kwtuple = { |
| 122 |
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS) |
| 123 |
.ob_hash = -1, |
| 124 |
.ob_item = { &_Py_ID(fget), &_Py_ID(fset), &_Py_ID(fdel), &_Py_ID(doc), }, |
| 125 |
}; |
| 126 |
#undef NUM_KEYWORDS |
| 127 |
#define KWTUPLE (&_kwtuple.ob_base.ob_base) |
| 128 |
|
| 129 |
#else // !Py_BUILD_CORE |
| 130 |
# define KWTUPLE NULL |
| 131 |
#endif // !Py_BUILD_CORE |
| 132 |
|
| 133 |
static const char * const _keywords[] = {"fget", "fset", "fdel", "doc", NULL}; |
| 134 |
static _PyArg_Parser _parser = { |
| 135 |
.keywords = _keywords, |
| 136 |
.fname = "property", |
| 137 |
.kwtuple = KWTUPLE, |
| 138 |
}; |
| 139 |
#undef KWTUPLE |
| 140 |
PyObject *argsbuf[4]; |
| 141 |
PyObject * const *fastargs; |
| 142 |
Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
| 143 |
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
| 144 |
PyObject *fget = NULL; |
| 145 |
PyObject *fset = NULL; |
| 146 |
PyObject *fdel = NULL; |
| 147 |
PyObject *doc = NULL; |
| 148 |
|
| 149 |
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, |
| 150 |
/*minpos*/ 0, /*maxpos*/ 4, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 151 |
if (!fastargs) { |
| 152 |
goto exit; |
| 153 |
} |
| 154 |
if (!noptargs) { |
| 155 |
goto skip_optional_pos; |
| 156 |
} |
| 157 |
if (fastargs[0]) { |
| 158 |
fget = fastargs[0]; |
| 159 |
if (!--noptargs) { |
| 160 |
goto skip_optional_pos; |
| 161 |
} |
| 162 |
} |
| 163 |
if (fastargs[1]) { |
| 164 |
fset = fastargs[1]; |
| 165 |
if (!--noptargs) { |
| 166 |
goto skip_optional_pos; |
| 167 |
} |
| 168 |
} |
| 169 |
if (fastargs[2]) { |
| 170 |
fdel = fastargs[2]; |
| 171 |
if (!--noptargs) { |
| 172 |
goto skip_optional_pos; |
| 173 |
} |
| 174 |
} |
| 175 |
doc = fastargs[3]; |
| 176 |
skip_optional_pos: |
| 177 |
return_value = property_init_impl((propertyobject *)self, fget, fset, fdel, doc); |
| 178 |
|
| 179 |
exit: |
| 180 |
return return_value; |
| 181 |
} |
| 182 |
/*[clinic end generated code: output=2e8df497abc4f915 input=a9049054013a1b77]*/ |