1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(_dbm_dbm_close__doc__,
6 "close($self, /)\n"
7 "--\n"
8 "\n"
9 "Close the database.");
10
11 #define _DBM_DBM_CLOSE_METHODDEF \
12 {"close", (PyCFunction)_dbm_dbm_close, METH_NOARGS, _dbm_dbm_close__doc__},
13
14 static PyObject *
15 _dbm_dbm_close_impl(dbmobject *self);
16
17 static PyObject *
_dbm_dbm_close(dbmobject * self,PyObject * Py_UNUSED (ignored))18 _dbm_dbm_close(dbmobject *self, PyObject *Py_UNUSED(ignored))
19 {
20 return _dbm_dbm_close_impl(self);
21 }
22
23 PyDoc_STRVAR(_dbm_dbm_keys__doc__,
24 "keys($self, /)\n"
25 "--\n"
26 "\n"
27 "Return a list of all keys in the database.");
28
29 #define _DBM_DBM_KEYS_METHODDEF \
30 {"keys", (PyCFunction)(void(*)(void))_dbm_dbm_keys, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_keys__doc__},
31
32 static PyObject *
33 _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls);
34
35 static PyObject *
_dbm_dbm_keys(dbmobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)36 _dbm_dbm_keys(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
37 {
38 PyObject *return_value = NULL;
39 static const char * const _keywords[] = { NULL};
40 static _PyArg_Parser _parser = {":keys", _keywords, 0};
41
42 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser
43 )) {
44 goto exit;
45 }
46 return_value = _dbm_dbm_keys_impl(self, cls);
47
48 exit:
49 return return_value;
50 }
51
52 PyDoc_STRVAR(_dbm_dbm_get__doc__,
53 "get($self, key, default=None, /)\n"
54 "--\n"
55 "\n"
56 "Return the value for key if present, otherwise default.");
57
58 #define _DBM_DBM_GET_METHODDEF \
59 {"get", (PyCFunction)(void(*)(void))_dbm_dbm_get, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_get__doc__},
60
61 static PyObject *
62 _dbm_dbm_get_impl(dbmobject *self, PyTypeObject *cls, const char *key,
63 Py_ssize_clean_t key_length, PyObject *default_value);
64
65 static PyObject *
_dbm_dbm_get(dbmobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)66 _dbm_dbm_get(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
67 {
68 PyObject *return_value = NULL;
69 static const char * const _keywords[] = {"", "", NULL};
70 static _PyArg_Parser _parser = {"s#|O:get", _keywords, 0};
71 const char *key;
72 Py_ssize_clean_t key_length;
73 PyObject *default_value = Py_None;
74
75 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
76 &key, &key_length, &default_value)) {
77 goto exit;
78 }
79 return_value = _dbm_dbm_get_impl(self, cls, key, key_length, default_value);
80
81 exit:
82 return return_value;
83 }
84
85 PyDoc_STRVAR(_dbm_dbm_setdefault__doc__,
86 "setdefault($self, key, default=b\'\', /)\n"
87 "--\n"
88 "\n"
89 "Return the value for key if present, otherwise default.\n"
90 "\n"
91 "If key is not in the database, it is inserted with default as the value.");
92
93 #define _DBM_DBM_SETDEFAULT_METHODDEF \
94 {"setdefault", (PyCFunction)(void(*)(void))_dbm_dbm_setdefault, METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _dbm_dbm_setdefault__doc__},
95
96 static PyObject *
97 _dbm_dbm_setdefault_impl(dbmobject *self, PyTypeObject *cls, const char *key,
98 Py_ssize_clean_t key_length,
99 PyObject *default_value);
100
101 static PyObject *
_dbm_dbm_setdefault(dbmobject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)102 _dbm_dbm_setdefault(dbmobject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
103 {
104 PyObject *return_value = NULL;
105 static const char * const _keywords[] = {"", "", NULL};
106 static _PyArg_Parser _parser = {"s#|O:setdefault", _keywords, 0};
107 const char *key;
108 Py_ssize_clean_t key_length;
109 PyObject *default_value = NULL;
110
111 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
112 &key, &key_length, &default_value)) {
113 goto exit;
114 }
115 return_value = _dbm_dbm_setdefault_impl(self, cls, key, key_length, default_value);
116
117 exit:
118 return return_value;
119 }
120
121 PyDoc_STRVAR(dbmopen__doc__,
122 "open($module, filename, flags=\'r\', mode=0o666, /)\n"
123 "--\n"
124 "\n"
125 "Return a database object.\n"
126 "\n"
127 " filename\n"
128 " The filename to open.\n"
129 " flags\n"
130 " How to open the file. \"r\" for reading, \"w\" for writing, etc.\n"
131 " mode\n"
132 " If creating a new file, the mode bits for the new file\n"
133 " (e.g. os.O_RDWR).");
134
135 #define DBMOPEN_METHODDEF \
136 {"open", (PyCFunction)(void(*)(void))dbmopen, METH_FASTCALL, dbmopen__doc__},
137
138 static PyObject *
139 dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
140 int mode);
141
142 static PyObject *
dbmopen(PyObject * module,PyObject * const * args,Py_ssize_t nargs)143 dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
144 {
145 PyObject *return_value = NULL;
146 PyObject *filename;
147 const char *flags = "r";
148 int mode = 438;
149
150 if (!_PyArg_CheckPositional("open", nargs, 1, 3)) {
151 goto exit;
152 }
153 if (!PyUnicode_Check(args[0])) {
154 _PyArg_BadArgument("open", "argument 1", "str", args[0]);
155 goto exit;
156 }
157 if (PyUnicode_READY(args[0]) == -1) {
158 goto exit;
159 }
160 filename = args[0];
161 if (nargs < 2) {
162 goto skip_optional;
163 }
164 if (!PyUnicode_Check(args[1])) {
165 _PyArg_BadArgument("open", "argument 2", "str", args[1]);
166 goto exit;
167 }
168 Py_ssize_t flags_length;
169 flags = PyUnicode_AsUTF8AndSize(args[1], &flags_length);
170 if (flags == NULL) {
171 goto exit;
172 }
173 if (strlen(flags) != (size_t)flags_length) {
174 PyErr_SetString(PyExc_ValueError, "embedded null character");
175 goto exit;
176 }
177 if (nargs < 3) {
178 goto skip_optional;
179 }
180 mode = _PyLong_AsInt(args[2]);
181 if (mode == -1 && PyErr_Occurred()) {
182 goto exit;
183 }
184 skip_optional:
185 return_value = dbmopen_impl(module, filename, flags, mode);
186
187 exit:
188 return return_value;
189 }
190 /*[clinic end generated code: output=6947b1115df66f7c input=a9049054013a1b77]*/
191