1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_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
14static PyObject *
15OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
16
17static PyObject *
18OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
19{
20    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
25    PyObject *seq;
26    PyObject *value = Py_None;
27
28    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
29    if (!args) {
30        goto exit;
31    }
32    seq = args[0];
33    if (!noptargs) {
34        goto skip_optional_pos;
35    }
36    value = args[1];
37skip_optional_pos:
38    return_value = OrderedDict_fromkeys_impl(type, seq, value);
39
40exit:
41    return return_value;
42}
43
44PyDoc_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
55static PyObject *
56OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
57                            PyObject *default_value);
58
59static PyObject *
60OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
61{
62    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
67    PyObject *key;
68    PyObject *default_value = Py_None;
69
70    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
71    if (!args) {
72        goto exit;
73    }
74    key = args[0];
75    if (!noptargs) {
76        goto skip_optional_pos;
77    }
78    default_value = args[1];
79skip_optional_pos:
80    return_value = OrderedDict_setdefault_impl(self, key, default_value);
81
82exit:
83    return return_value;
84}
85
86PyDoc_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
98static PyObject *
99OrderedDict_pop_impl(PyODictObject *self, PyObject *key,
100                     PyObject *default_value);
101
102static PyObject *
103OrderedDict_pop(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
104{
105    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
110    PyObject *key;
111    PyObject *default_value = NULL;
112
113    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
114    if (!args) {
115        goto exit;
116    }
117    key = args[0];
118    if (!noptargs) {
119        goto skip_optional_pos;
120    }
121    default_value = args[1];
122skip_optional_pos:
123    return_value = OrderedDict_pop_impl(self, key, default_value);
124
125exit:
126    return return_value;
127}
128
129PyDoc_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
140static PyObject *
141OrderedDict_popitem_impl(PyODictObject *self, int last);
142
143static PyObject *
144OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
145{
146    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
151    int last = 1;
152
153    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
154    if (!args) {
155        goto exit;
156    }
157    if (!noptargs) {
158        goto skip_optional_pos;
159    }
160    last = PyObject_IsTrue(args[0]);
161    if (last < 0) {
162        goto exit;
163    }
164skip_optional_pos:
165    return_value = OrderedDict_popitem_impl(self, last);
166
167exit:
168    return return_value;
169}
170
171PyDoc_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
182static PyObject *
183OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
184
185static PyObject *
186OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
187{
188    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    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
193    PyObject *key;
194    int last = 1;
195
196    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
197    if (!args) {
198        goto exit;
199    }
200    key = args[0];
201    if (!noptargs) {
202        goto skip_optional_pos;
203    }
204    last = PyObject_IsTrue(args[1]);
205    if (last < 0) {
206        goto exit;
207    }
208skip_optional_pos:
209    return_value = OrderedDict_move_to_end_impl(self, key, last);
210
211exit:
212    return return_value;
213}
214/*[clinic end generated code: output=4182a5dab66963d0 input=a9049054013a1b77]*/
215