Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
6 : "fromkeys($type, /, iterable, value=None)\n"
7 : "--\n"
8 : "\n"
9 : "Create a new ordered dictionary with keys from iterable and values set to value.");
10 :
11 : #define ORDEREDDICT_FROMKEYS_METHODDEF \
12 : {"fromkeys", _PyCFunction_CAST(OrderedDict_fromkeys), METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__},
13 :
14 : static PyObject *
15 : OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
16 :
17 : static PyObject *
18 50 : OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
19 : {
20 50 : PyObject *return_value = NULL;
21 : static const char * const _keywords[] = {"iterable", "value", NULL};
22 : static _PyArg_Parser _parser = {NULL, _keywords, "fromkeys", 0};
23 : PyObject *argsbuf[2];
24 50 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
25 : PyObject *seq;
26 50 : PyObject *value = Py_None;
27 :
28 50 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
29 50 : if (!args) {
30 0 : goto exit;
31 : }
32 50 : seq = args[0];
33 50 : if (!noptargs) {
34 46 : goto skip_optional_pos;
35 : }
36 4 : value = args[1];
37 50 : skip_optional_pos:
38 50 : return_value = OrderedDict_fromkeys_impl(type, seq, value);
39 :
40 50 : exit:
41 50 : return return_value;
42 : }
43 :
44 : PyDoc_STRVAR(OrderedDict_setdefault__doc__,
45 : "setdefault($self, /, key, default=None)\n"
46 : "--\n"
47 : "\n"
48 : "Insert key with a value of default if key is not in the dictionary.\n"
49 : "\n"
50 : "Return the value for key if key is in the dictionary, else default.");
51 :
52 : #define ORDEREDDICT_SETDEFAULT_METHODDEF \
53 : {"setdefault", _PyCFunction_CAST(OrderedDict_setdefault), METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__},
54 :
55 : static PyObject *
56 : OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
57 : PyObject *default_value);
58 :
59 : static PyObject *
60 14 : OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
61 : {
62 14 : PyObject *return_value = NULL;
63 : static const char * const _keywords[] = {"key", "default", NULL};
64 : static _PyArg_Parser _parser = {NULL, _keywords, "setdefault", 0};
65 : PyObject *argsbuf[2];
66 14 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
67 : PyObject *key;
68 14 : PyObject *default_value = Py_None;
69 :
70 14 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
71 14 : if (!args) {
72 2 : goto exit;
73 : }
74 12 : key = args[0];
75 12 : if (!noptargs) {
76 0 : goto skip_optional_pos;
77 : }
78 12 : default_value = args[1];
79 12 : skip_optional_pos:
80 12 : return_value = OrderedDict_setdefault_impl(self, key, default_value);
81 :
82 14 : exit:
83 14 : return return_value;
84 : }
85 :
86 : PyDoc_STRVAR(OrderedDict_pop__doc__,
87 : "pop($self, /, key, default=<unrepresentable>)\n"
88 : "--\n"
89 : "\n"
90 : "od.pop(key[,default]) -> v, remove specified key and return the corresponding value.\n"
91 : "\n"
92 : "If the key is not found, return the default if given; otherwise,\n"
93 : "raise a KeyError.");
94 :
95 : #define ORDEREDDICT_POP_METHODDEF \
96 : {"pop", _PyCFunction_CAST(OrderedDict_pop), METH_FASTCALL|METH_KEYWORDS, OrderedDict_pop__doc__},
97 :
98 : static PyObject *
99 : OrderedDict_pop_impl(PyODictObject *self, PyObject *key,
100 : PyObject *default_value);
101 :
102 : static PyObject *
103 1904 : OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
104 : {
105 1904 : PyObject *return_value = NULL;
106 : static const char * const _keywords[] = {"key", "default", NULL};
107 : static _PyArg_Parser _parser = {NULL, _keywords, "pop", 0};
108 : PyObject *argsbuf[2];
109 1904 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
110 : PyObject *key;
111 1904 : PyObject *default_value = NULL;
112 :
113 1904 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
114 1904 : if (!args) {
115 0 : goto exit;
116 : }
117 1904 : key = args[0];
118 1904 : if (!noptargs) {
119 1143 : goto skip_optional_pos;
120 : }
121 761 : default_value = args[1];
122 1904 : skip_optional_pos:
123 1904 : return_value = OrderedDict_pop_impl(self, key, default_value);
124 :
125 1904 : exit:
126 1904 : return return_value;
127 : }
128 :
129 : PyDoc_STRVAR(OrderedDict_popitem__doc__,
130 : "popitem($self, /, last=True)\n"
131 : "--\n"
132 : "\n"
133 : "Remove and return a (key, value) pair from the dictionary.\n"
134 : "\n"
135 : "Pairs are returned in LIFO order if last is true or FIFO order if false.");
136 :
137 : #define ORDEREDDICT_POPITEM_METHODDEF \
138 : {"popitem", _PyCFunction_CAST(OrderedDict_popitem), METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
139 :
140 : static PyObject *
141 : OrderedDict_popitem_impl(PyODictObject *self, int last);
142 :
143 : static PyObject *
144 589 : OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
145 : {
146 589 : PyObject *return_value = NULL;
147 : static const char * const _keywords[] = {"last", NULL};
148 : static _PyArg_Parser _parser = {NULL, _keywords, "popitem", 0};
149 : PyObject *argsbuf[1];
150 589 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
151 589 : int last = 1;
152 :
153 589 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
154 589 : if (!args) {
155 0 : goto exit;
156 : }
157 589 : if (!noptargs) {
158 22 : goto skip_optional_pos;
159 : }
160 567 : last = PyObject_IsTrue(args[0]);
161 567 : if (last < 0) {
162 0 : goto exit;
163 : }
164 567 : skip_optional_pos:
165 589 : return_value = OrderedDict_popitem_impl(self, last);
166 :
167 589 : exit:
168 589 : return return_value;
169 : }
170 :
171 : PyDoc_STRVAR(OrderedDict_move_to_end__doc__,
172 : "move_to_end($self, /, key, last=True)\n"
173 : "--\n"
174 : "\n"
175 : "Move an existing element to the end (or beginning if last is false).\n"
176 : "\n"
177 : "Raise KeyError if the element does not exist.");
178 :
179 : #define ORDEREDDICT_MOVE_TO_END_METHODDEF \
180 : {"move_to_end", _PyCFunction_CAST(OrderedDict_move_to_end), METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
181 :
182 : static PyObject *
183 : OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
184 :
185 : static PyObject *
186 78 : OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
187 : {
188 78 : PyObject *return_value = NULL;
189 : static const char * const _keywords[] = {"key", "last", NULL};
190 : static _PyArg_Parser _parser = {NULL, _keywords, "move_to_end", 0};
191 : PyObject *argsbuf[2];
192 78 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
193 : PyObject *key;
194 78 : int last = 1;
195 :
196 78 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
197 78 : if (!args) {
198 0 : goto exit;
199 : }
200 78 : key = args[0];
201 78 : if (!noptargs) {
202 66 : goto skip_optional_pos;
203 : }
204 12 : last = PyObject_IsTrue(args[1]);
205 12 : if (last < 0) {
206 0 : goto exit;
207 : }
208 12 : skip_optional_pos:
209 78 : return_value = OrderedDict_move_to_end_impl(self, key, last);
210 :
211 78 : exit:
212 78 : return return_value;
213 : }
214 : /*[clinic end generated code: output=4182a5dab66963d0 input=a9049054013a1b77]*/
|