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