blob: a3ab9ea507f44f1a155d5d34ea1f99c6a3299aaf [file] [log] [blame]
Victor Stinnerb05cbac2017-01-17 03:46:13 +01001/*[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"
Serhiy Storchaka78d9e582017-01-25 00:30:04 +02009"Create a new ordered dictionary with keys from iterable and values set to value.");
Victor Stinnerb05cbac2017-01-17 03:46:13 +010010
11#define ORDEREDDICT_FROMKEYS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020012 {"fromkeys", (PyCFunction)(void(*)(void))OrderedDict_fromkeys, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, OrderedDict_fromkeys__doc__},
Victor Stinnerb05cbac2017-01-17 03:46:13 +010013
14static PyObject *
15OrderedDict_fromkeys_impl(PyTypeObject *type, PyObject *seq, PyObject *value);
16
17static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020018OrderedDict_fromkeys(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinnerb05cbac2017-01-17 03:46:13 +010019{
20 PyObject *return_value = NULL;
21 static const char * const _keywords[] = {"iterable", "value", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020022 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;
Victor Stinnerb05cbac2017-01-17 03:46:13 +010025 PyObject *seq;
26 PyObject *value = Py_None;
27
Serhiy Storchaka31913912019-03-14 10:32:22 +020028 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
29 if (!args) {
Victor Stinnerb05cbac2017-01-17 03:46:13 +010030 goto exit;
31 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020032 seq = args[0];
33 if (!noptargs) {
34 goto skip_optional_pos;
35 }
36 value = args[1];
37skip_optional_pos:
Victor Stinnerb05cbac2017-01-17 03:46:13 +010038 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"
Serhiy Storchaka78d9e582017-01-25 00:30:04 +020048"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.");
Victor Stinnerb05cbac2017-01-17 03:46:13 +010051
52#define ORDEREDDICT_SETDEFAULT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +020053 {"setdefault", (PyCFunction)(void(*)(void))OrderedDict_setdefault, METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__},
Victor Stinnerb05cbac2017-01-17 03:46:13 +010054
55static PyObject *
56OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
Serhiy Storchakaa70eaf22017-01-19 19:38:13 +020057 PyObject *default_value);
Victor Stinnerb05cbac2017-01-17 03:46:13 +010058
59static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +020060OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinnerb05cbac2017-01-17 03:46:13 +010061{
62 PyObject *return_value = NULL;
63 static const char * const _keywords[] = {"key", "default", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +020064 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;
Victor Stinnerb05cbac2017-01-17 03:46:13 +010067 PyObject *key;
Serhiy Storchakaa70eaf22017-01-19 19:38:13 +020068 PyObject *default_value = Py_None;
Victor Stinnerb05cbac2017-01-17 03:46:13 +010069
Serhiy Storchaka31913912019-03-14 10:32:22 +020070 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
71 if (!args) {
Victor Stinnerb05cbac2017-01-17 03:46:13 +010072 goto exit;
73 }
Serhiy Storchaka31913912019-03-14 10:32:22 +020074 key = args[0];
75 if (!noptargs) {
76 goto skip_optional_pos;
77 }
78 default_value = args[1];
79skip_optional_pos:
Serhiy Storchakaa70eaf22017-01-19 19:38:13 +020080 return_value = OrderedDict_setdefault_impl(self, key, default_value);
Victor Stinnerb05cbac2017-01-17 03:46:13 +010081
82exit:
83 return return_value;
84}
85
Serhiy Storchaka6bf323732020-07-19 09:18:55 +030086PyDoc_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)(void(*)(void))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
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100129PyDoc_STRVAR(OrderedDict_popitem__doc__,
130"popitem($self, /, last=True)\n"
131"--\n"
132"\n"
Serhiy Storchaka78d9e582017-01-25 00:30:04 +0200133"Remove and return a (key, value) pair from the dictionary.\n"
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100134"\n"
135"Pairs are returned in LIFO order if last is true or FIFO order if false.");
136
137#define ORDEREDDICT_POPITEM_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200138 {"popitem", (PyCFunction)(void(*)(void))OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100139
140static PyObject *
141OrderedDict_popitem_impl(PyODictObject *self, int last);
142
143static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200144OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100145{
146 PyObject *return_value = NULL;
147 static const char * const _keywords[] = {"last", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200148 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;
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100151 int last = 1;
152
Serhiy Storchaka31913912019-03-14 10:32:22 +0200153 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
154 if (!args) {
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100155 goto exit;
156 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200157 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:
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100165 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"
Serhiy Storchaka78d9e582017-01-25 00:30:04 +0200175"Move an existing element to the end (or beginning if last is false).\n"
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100176"\n"
Serhiy Storchaka78d9e582017-01-25 00:30:04 +0200177"Raise KeyError if the element does not exist.");
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100178
179#define ORDEREDDICT_MOVE_TO_END_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200180 {"move_to_end", (PyCFunction)(void(*)(void))OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100181
182static PyObject *
183OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
184
185static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200186OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100187{
188 PyObject *return_value = NULL;
189 static const char * const _keywords[] = {"key", "last", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200190 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;
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100193 PyObject *key;
194 int last = 1;
195
Serhiy Storchaka31913912019-03-14 10:32:22 +0200196 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
197 if (!args) {
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100198 goto exit;
199 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200200 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:
Victor Stinnerb05cbac2017-01-17 03:46:13 +0100209 return_value = OrderedDict_move_to_end_impl(self, key, last);
210
211exit:
212 return return_value;
213}
Serhiy Storchaka6bf323732020-07-19 09:18:55 +0300214/*[clinic end generated code: output=e0afaad5b4bb47fe input=a9049054013a1b77]*/