Debian Codegraph @

Modules/clinic/_dbmmodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_runtime.h" // _Py_SINGLETON()
7 #endif
8 #include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
9 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
10
11 PyDoc_STRVAR(_dbm_dbm_close__doc__,
12 "close($self, /)\n"
13 "--\n"
14 "\n"
15 "Close the database.");
16
17 #define _DBM_DBM_CLOSE_METHODDEF \
18 {"close", (PyCFunction)_dbm_dbm_close, METH_NOARGS, _dbm_dbm_close__doc__},
19
20 static PyObject *
21 _dbm_dbm_close_impl(dbmobject *self);
22
23 static PyObject *
24 _dbm_dbm_close(PyObject *self, PyObject *Py_UNUSED(ignored))
25 {
26 PyObject *return_value = NULL;
27
28 Py_BEGIN_CRITICAL_SECTION(self);
29 return_value = _dbm_dbm_close_impl((dbmobject *)self);
30 Py_END_CRITICAL_SECTION();
31
32 return return_value;
33 }
34
35 PyDoc_STRVAR(_dbm_dbm_keys__doc__,
36 "keys($self, /)\n"
37 "--\n"
38 "\n"
39 "Return a list of all keys in the database.");
40
41 #define _DBM_DBM_KEYS_METHODDEF \
42 {"keys", _PyCFunction_CAST(_dbm_dbm_keys), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_keys__doc__},
43
44 static PyObject *
45 _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls);
46
47 static PyObject *
48 _dbm_dbm_keys(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
49 {
50 PyObject *return_value = NULL;
51
52 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
53 PyErr_SetString(PyExc_TypeError, "keys() takes no arguments");
54 goto exit;
55 }
56 Py_BEGIN_CRITICAL_SECTION(self);
57 return_value = _dbm_dbm_keys_impl((dbmobject *)self, cls);
58 Py_END_CRITICAL_SECTION();
59
60 exit:
61 return return_value;
62 }
63
64 PyDoc_STRVAR(_dbm_dbm_get__doc__,
65 "get($self, key, default=None, /)\n"
66 "--\n"
67 "\n"
68 "Return the value for key if present, otherwise default.");
69
70 #define _DBM_DBM_GET_METHODDEF \
71 {"get", _PyCFunction_CAST(_dbm_dbm_get), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_get__doc__},
72
73 static PyObject *
74 _dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key,
75 Py_ssize_t key_length, PyObject *default_value);
76
77 static PyObject *
78 _dbm_dbm_get(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
79 {
80 PyObject *return_value = NULL;
81 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
82 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
83 #else
84 # define KWTUPLE NULL
85 #endif
86
87 static const char * const _keywords[] = {"", "", NULL};
88 static _PyArg_Parser _parser = {
89 .keywords = _keywords,
90 .format = "s#|O:get",
91 .kwtuple = KWTUPLE,
92 };
93 #undef KWTUPLE
94 const char *key;
95 Py_ssize_t key_length;
96 PyObject *default_value = Py_None;
97
98 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
99 &key, &key_length, &default_value)) {
100 goto exit;
101 }
102 Py_BEGIN_CRITICAL_SECTION(self);
103 return_value = _dbm_dbm_get_impl((dbmobject *)self, cls, key, key_length, default_value);
104 Py_END_CRITICAL_SECTION();
105
106 exit:
107 return return_value;
108 }
109
110 PyDoc_STRVAR(_dbm_dbm_setdefault__doc__,
111 "setdefault($self, key, default=b\'\', /)\n"
112 "--\n"
113 "\n"
114 "Return the value for key if present, otherwise default.\n"
115 "\n"
116 "If key is not in the database, it is inserted with default as the\n"
117 "value.");
118
119 #define _DBM_DBM_SETDEFAULT_METHODDEF \
120 {"setdefault", _PyCFunction_CAST(_dbm_dbm_setdefault), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_setdefault__doc__},
121
122 static PyObject *
123 _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
124 Py_ssize_t key_length, PyObject *default_value);
125
126 static PyObject *
127 _dbm_dbm_setdefault(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
128 {
129 PyObject *return_value = NULL;
130 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
131 # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
132 #else
133 # define KWTUPLE NULL
134 #endif
135
136 static const char * const _keywords[] = {"", "", NULL};
137 static _PyArg_Parser _parser = {
138 .keywords = _keywords,
139 .format = "s#|O:setdefault",
140 .kwtuple = KWTUPLE,
141 };
142 #undef KWTUPLE
143 const char *key;
144 Py_ssize_t key_length;
145 PyObject *default_value = NULL;
146
147 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
148 &key, &key_length, &default_value)) {
149 goto exit;
150 }
151 Py_BEGIN_CRITICAL_SECTION(self);
152 return_value = _dbm_dbm_setdefault_impl((dbmobject *)self, cls, key, key_length, default_value);
153 Py_END_CRITICAL_SECTION();
154
155 exit:
156 return return_value;
157 }
158
159 PyDoc_STRVAR(_dbm_dbm_clear__doc__,
160 "clear($self, /)\n"
161 "--\n"
162 "\n"
163 "Remove all items from the database.");
164
165 #define _DBM_DBM_CLEAR_METHODDEF \
166 {"clear", _PyCFunction_CAST(_dbm_dbm_clear), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_clear__doc__},
167
168 static PyObject *
169 _dbm_dbm_clear_impl(dbmobject *self, PyTypeObject *cls);
170
171 static PyObject *
172 _dbm_dbm_clear(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
173 {
174 PyObject *return_value = NULL;
175
176 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
177 PyErr_SetString(PyExc_TypeError, "clear() takes no arguments");
178 goto exit;
179 }
180 Py_BEGIN_CRITICAL_SECTION(self);
181 return_value = _dbm_dbm_clear_impl((dbmobject *)self, cls);
182 Py_END_CRITICAL_SECTION();
183
184 exit:
185 return return_value;
186 }
187
188 PyDoc_STRVAR(dbmopen__doc__,
189 "open($module, filename, flags=\'r\', mode=0o666, /)\n"
190 "--\n"
191 "\n"
192 "Return a database object.\n"
193 "\n"
194 " filename\n"
195 " The filename to open.\n"
196 " flags\n"
197 " How to open the file. \"r\" for reading, \"w\" for writing, etc.\n"
198 " mode\n"
199 " If creating a new file, the mode bits for the new file\n"
200 " (e.g. os.O_RDWR).");
201
202 #define DBMOPEN_METHODDEF \
203 {"open", _PyCFunction_CAST(dbmopen), METH_FASTCALL, dbmopen__doc__},
204
205 static PyObject *
206 dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
207 int mode);
208
209 static PyObject *
210 dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
211 {
212 PyObject *return_value = NULL;
213 PyObject *filename;
214 const char *flags = "r";
215 int mode = 438;
216
217 if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
218 goto exit;
219 }
220 filename = args[0];
221 if (nargs < 2) {
222 goto skip_optional;
223 }
224 if (!PyUnicode_Check(args[1])) {
225 _PyArg_BadArgument("open", "argument 2", "str", args[1]);
226 goto exit;
227 }
228 Py_ssize_t flags_length;
229 flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
230 if (flags == NULL) {
231 goto exit;
232 }
233 if (strlen(flags) != (size_t)flags_length) {
234 PyErr_SetString(PyExc_ValueError, "embedded null character");
235 goto exit;
236 }
237 if (nargs < 3) {
238 goto skip_optional;
239 }
240 mode = PyLong_AsInt(args[2]);
241 if (mode == -1 && PyErr_Occurred()) {
242 goto exit;
243 }
244 skip_optional:
245 return_value = dbmopen_impl(module, filename, flags, mode);
246
247 exit:
248 return return_value;
249 }
250 /*[clinic end generated code: output=677deecf525167a5 input=a9049054013a1b77]*/