• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)(void(*)(void))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 = {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];
37 skip_optional_pos:
38     return_value = OrderedDict_fromkeys_impl(type, seq, value);
39 
40 exit:
41     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)(void(*)(void))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 *
OrderedDict_setdefault(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)60 OrderedDict_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];
79 skip_optional_pos:
80     return_value = OrderedDict_setdefault_impl(self, key, default_value);
81 
82 exit:
83     return return_value;
84 }
85 
86 PyDoc_STRVAR(OrderedDict_popitem__doc__,
87 "popitem($self, /, last=True)\n"
88 "--\n"
89 "\n"
90 "Remove and return a (key, value) pair from the dictionary.\n"
91 "\n"
92 "Pairs are returned in LIFO order if last is true or FIFO order if false.");
93 
94 #define ORDEREDDICT_POPITEM_METHODDEF    \
95     {"popitem", (PyCFunction)(void(*)(void))OrderedDict_popitem, METH_FASTCALL|METH_KEYWORDS, OrderedDict_popitem__doc__},
96 
97 static PyObject *
98 OrderedDict_popitem_impl(PyODictObject *self, int last);
99 
100 static PyObject *
OrderedDict_popitem(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)101 OrderedDict_popitem(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
102 {
103     PyObject *return_value = NULL;
104     static const char * const _keywords[] = {"last", NULL};
105     static _PyArg_Parser _parser = {NULL, _keywords, "popitem", 0};
106     PyObject *argsbuf[1];
107     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
108     int last = 1;
109 
110     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
111     if (!args) {
112         goto exit;
113     }
114     if (!noptargs) {
115         goto skip_optional_pos;
116     }
117     last = PyObject_IsTrue(args[0]);
118     if (last < 0) {
119         goto exit;
120     }
121 skip_optional_pos:
122     return_value = OrderedDict_popitem_impl(self, last);
123 
124 exit:
125     return return_value;
126 }
127 
128 PyDoc_STRVAR(OrderedDict_move_to_end__doc__,
129 "move_to_end($self, /, key, last=True)\n"
130 "--\n"
131 "\n"
132 "Move an existing element to the end (or beginning if last is false).\n"
133 "\n"
134 "Raise KeyError if the element does not exist.");
135 
136 #define ORDEREDDICT_MOVE_TO_END_METHODDEF    \
137     {"move_to_end", (PyCFunction)(void(*)(void))OrderedDict_move_to_end, METH_FASTCALL|METH_KEYWORDS, OrderedDict_move_to_end__doc__},
138 
139 static PyObject *
140 OrderedDict_move_to_end_impl(PyODictObject *self, PyObject *key, int last);
141 
142 static PyObject *
OrderedDict_move_to_end(PyODictObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)143 OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
144 {
145     PyObject *return_value = NULL;
146     static const char * const _keywords[] = {"key", "last", NULL};
147     static _PyArg_Parser _parser = {NULL, _keywords, "move_to_end", 0};
148     PyObject *argsbuf[2];
149     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
150     PyObject *key;
151     int last = 1;
152 
153     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
154     if (!args) {
155         goto exit;
156     }
157     key = args[0];
158     if (!noptargs) {
159         goto skip_optional_pos;
160     }
161     last = PyObject_IsTrue(args[1]);
162     if (last < 0) {
163         goto exit;
164     }
165 skip_optional_pos:
166     return_value = OrderedDict_move_to_end_impl(self, key, last);
167 
168 exit:
169     return return_value;
170 }
171 /*[clinic end generated code: output=8eb1296df9142908 input=a9049054013a1b77]*/
172