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)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 *
OrderedDict_fromkeys(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)18 OrderedDict_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 = {"O|O:fromkeys", _keywords, 0};
23 PyObject *seq;
24 PyObject *value = Py_None;
25
26 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
27 &seq, &value)) {
28 goto exit;
29 }
30 return_value = OrderedDict_fromkeys_impl(type, seq, value);
31
32 exit:
33 return return_value;
34 }
35
36 PyDoc_STRVAR(OrderedDict_setdefault__doc__,
37 "setdefault($self, /, key, default=None)\n"
38 "--\n"
39 "\n"
40 "Insert key with a value of default if key is not in the dictionary.\n"
41 "\n"
42 "Return the value for key if key is in the dictionary, else default.");
43
44 #define ORDEREDDICT_SETDEFAULT_METHODDEF \
45 {"setdefault", (PyCFunction)OrderedDict_setdefault, METH_FASTCALL|METH_KEYWORDS, OrderedDict_setdefault__doc__},
46
47 static PyObject *
48 OrderedDict_setdefault_impl(PyODictObject *self, PyObject *key,
49 PyObject *default_value);
50
51 static PyObject *
OrderedDict_setdefault(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)52 OrderedDict_setdefault(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
53 {
54 PyObject *return_value = NULL;
55 static const char * const _keywords[] = {"key", "default", NULL};
56 static _PyArg_Parser _parser = {"O|O:setdefault", _keywords, 0};
57 PyObject *key;
58 PyObject *default_value = Py_None;
59
60 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
61 &key, &default_value)) {
62 goto exit;
63 }
64 return_value = OrderedDict_setdefault_impl(self, key, default_value);
65
66 exit:
67 return return_value;
68 }
69
70 PyDoc_STRVAR(OrderedDict_popitem__doc__,
71 "popitem($self, /, last=True)\n"
72 "--\n"
73 "\n"
74 "Remove and return a (key, value) pair from the dictionary.\n"
75 "\n"
76 "Pairs are returned in LIFO order if last is true or FIFO order if false.");
77
78 #define ORDEREDDICT_POPITEM_METHODDEF \
79 {"popitem", (PyCFunction)OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
80
81 static PyObject *
82 OrderedDict_popitem_impl(PyODictObject *self, int last);
83
84 static PyObject *
OrderedDict_popitem(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)85 OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
86 {
87 PyObject *return_value = NULL;
88 static const char * const _keywords[] = {"last", NULL};
89 static _PyArg_Parser _parser = {"|p:popitem", _keywords, 0};
90 int last = 1;
91
92 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
93 &last)) {
94 goto exit;
95 }
96 return_value = OrderedDict_popitem_impl(self, last);
97
98 exit:
99 return return_value;
100 }
101
102 PyDoc_STRVAR(OrderedDict_move_to_end__doc__,
103 "move_to_end($self, /, key, last=True)\n"
104 "--\n"
105 "\n"
106 "Move an existing element to the end (or beginning if last is false).\n"
107 "\n"
108 "Raise KeyError if the element does not exist.");
109
110 #define ORDEREDDICT_MOVE_TO_END_METHODDEF \
111 {"move_to_end", (PyCFunction)OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
112
113 static PyObject *
114 OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
115
116 static PyObject *
OrderedDict_move_to_end(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)117 OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
118 {
119 PyObject *return_value = NULL;
120 static const char * const _keywords[] = {"key", "last", NULL};
121 static _PyArg_Parser _parser = {"O|p:move_to_end", _keywords, 0};
122 PyObject *key;
123 int last = 1;
124
125 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
126 &key, &last)) {
127 goto exit;
128 }
129 return_value = OrderedDict_move_to_end_impl(self, key, last);
130
131 exit:
132 return return_value;
133 }
134 /*[clinic end generated code: output=7f23d569eda2a558 input=a9049054013a1b77]*/
135