• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(_gdbm_gdbm_get__doc__,
6 "get($self, key, default=None, /)\n"
7 "--\n"
8 "\n"
9 "Get the value for key, or default if not present.");
10 
11 #define _GDBM_GDBM_GET_METHODDEF    \
12     {"get", (PyCFunction)_gdbm_gdbm_get, METH_VARARGS, _gdbm_gdbm_get__doc__},
13 
14 static PyObject *
15 _gdbm_gdbm_get_impl(dbmobject *self, PyObject *key, PyObject *default_value);
16 
17 static PyObject *
_gdbm_gdbm_get(dbmobject * self,PyObject * args)18 _gdbm_gdbm_get(dbmobject *self, PyObject *args)
19 {
20     PyObject *return_value = NULL;
21     PyObject *key;
22     PyObject *default_value = Py_None;
23 
24     if (!PyArg_UnpackTuple(args, "get",
25         1, 2,
26         &key, &default_value)) {
27         goto exit;
28     }
29     return_value = _gdbm_gdbm_get_impl(self, key, default_value);
30 
31 exit:
32     return return_value;
33 }
34 
35 PyDoc_STRVAR(_gdbm_gdbm_setdefault__doc__,
36 "setdefault($self, key, default=None, /)\n"
37 "--\n"
38 "\n"
39 "Get value for key, or set it to default and return default if not present.");
40 
41 #define _GDBM_GDBM_SETDEFAULT_METHODDEF    \
42     {"setdefault", (PyCFunction)_gdbm_gdbm_setdefault, METH_VARARGS, _gdbm_gdbm_setdefault__doc__},
43 
44 static PyObject *
45 _gdbm_gdbm_setdefault_impl(dbmobject *self, PyObject *key,
46                            PyObject *default_value);
47 
48 static PyObject *
_gdbm_gdbm_setdefault(dbmobject * self,PyObject * args)49 _gdbm_gdbm_setdefault(dbmobject *self, PyObject *args)
50 {
51     PyObject *return_value = NULL;
52     PyObject *key;
53     PyObject *default_value = Py_None;
54 
55     if (!PyArg_UnpackTuple(args, "setdefault",
56         1, 2,
57         &key, &default_value)) {
58         goto exit;
59     }
60     return_value = _gdbm_gdbm_setdefault_impl(self, key, default_value);
61 
62 exit:
63     return return_value;
64 }
65 
66 PyDoc_STRVAR(_gdbm_gdbm_close__doc__,
67 "close($self, /)\n"
68 "--\n"
69 "\n"
70 "Close the database.");
71 
72 #define _GDBM_GDBM_CLOSE_METHODDEF    \
73     {"close", (PyCFunction)_gdbm_gdbm_close, METH_NOARGS, _gdbm_gdbm_close__doc__},
74 
75 static PyObject *
76 _gdbm_gdbm_close_impl(dbmobject *self);
77 
78 static PyObject *
_gdbm_gdbm_close(dbmobject * self,PyObject * Py_UNUSED (ignored))79 _gdbm_gdbm_close(dbmobject *self, PyObject *Py_UNUSED(ignored))
80 {
81     return _gdbm_gdbm_close_impl(self);
82 }
83 
84 PyDoc_STRVAR(_gdbm_gdbm_keys__doc__,
85 "keys($self, /)\n"
86 "--\n"
87 "\n"
88 "Get a list of all keys in the database.");
89 
90 #define _GDBM_GDBM_KEYS_METHODDEF    \
91     {"keys", (PyCFunction)_gdbm_gdbm_keys, METH_NOARGS, _gdbm_gdbm_keys__doc__},
92 
93 static PyObject *
94 _gdbm_gdbm_keys_impl(dbmobject *self);
95 
96 static PyObject *
_gdbm_gdbm_keys(dbmobject * self,PyObject * Py_UNUSED (ignored))97 _gdbm_gdbm_keys(dbmobject *self, PyObject *Py_UNUSED(ignored))
98 {
99     return _gdbm_gdbm_keys_impl(self);
100 }
101 
102 PyDoc_STRVAR(_gdbm_gdbm_firstkey__doc__,
103 "firstkey($self, /)\n"
104 "--\n"
105 "\n"
106 "Return the starting key for the traversal.\n"
107 "\n"
108 "It\'s possible to loop over every key in the database using this method\n"
109 "and the nextkey() method.  The traversal is ordered by GDBM\'s internal\n"
110 "hash values, and won\'t be sorted by the key values.");
111 
112 #define _GDBM_GDBM_FIRSTKEY_METHODDEF    \
113     {"firstkey", (PyCFunction)_gdbm_gdbm_firstkey, METH_NOARGS, _gdbm_gdbm_firstkey__doc__},
114 
115 static PyObject *
116 _gdbm_gdbm_firstkey_impl(dbmobject *self);
117 
118 static PyObject *
_gdbm_gdbm_firstkey(dbmobject * self,PyObject * Py_UNUSED (ignored))119 _gdbm_gdbm_firstkey(dbmobject *self, PyObject *Py_UNUSED(ignored))
120 {
121     return _gdbm_gdbm_firstkey_impl(self);
122 }
123 
124 PyDoc_STRVAR(_gdbm_gdbm_nextkey__doc__,
125 "nextkey($self, key, /)\n"
126 "--\n"
127 "\n"
128 "Returns the key that follows key in the traversal.\n"
129 "\n"
130 "The following code prints every key in the database db, without having\n"
131 "to create a list in memory that contains them all:\n"
132 "\n"
133 "      k = db.firstkey()\n"
134 "      while k != None:\n"
135 "          print(k)\n"
136 "          k = db.nextkey(k)");
137 
138 #define _GDBM_GDBM_NEXTKEY_METHODDEF    \
139     {"nextkey", (PyCFunction)_gdbm_gdbm_nextkey, METH_O, _gdbm_gdbm_nextkey__doc__},
140 
141 static PyObject *
142 _gdbm_gdbm_nextkey_impl(dbmobject *self, const char *key,
143                         Py_ssize_clean_t key_length);
144 
145 static PyObject *
_gdbm_gdbm_nextkey(dbmobject * self,PyObject * arg)146 _gdbm_gdbm_nextkey(dbmobject *self, PyObject *arg)
147 {
148     PyObject *return_value = NULL;
149     const char *key;
150     Py_ssize_clean_t key_length;
151 
152     if (!PyArg_Parse(arg, "s#:nextkey", &key, &key_length)) {
153         goto exit;
154     }
155     return_value = _gdbm_gdbm_nextkey_impl(self, key, key_length);
156 
157 exit:
158     return return_value;
159 }
160 
161 PyDoc_STRVAR(_gdbm_gdbm_reorganize__doc__,
162 "reorganize($self, /)\n"
163 "--\n"
164 "\n"
165 "Reorganize the database.\n"
166 "\n"
167 "If you have carried out a lot of deletions and would like to shrink\n"
168 "the space used by the GDBM file, this routine will reorganize the\n"
169 "database.  GDBM will not shorten the length of a database file except\n"
170 "by using this reorganization; otherwise, deleted file space will be\n"
171 "kept and reused as new (key,value) pairs are added.");
172 
173 #define _GDBM_GDBM_REORGANIZE_METHODDEF    \
174     {"reorganize", (PyCFunction)_gdbm_gdbm_reorganize, METH_NOARGS, _gdbm_gdbm_reorganize__doc__},
175 
176 static PyObject *
177 _gdbm_gdbm_reorganize_impl(dbmobject *self);
178 
179 static PyObject *
_gdbm_gdbm_reorganize(dbmobject * self,PyObject * Py_UNUSED (ignored))180 _gdbm_gdbm_reorganize(dbmobject *self, PyObject *Py_UNUSED(ignored))
181 {
182     return _gdbm_gdbm_reorganize_impl(self);
183 }
184 
185 PyDoc_STRVAR(_gdbm_gdbm_sync__doc__,
186 "sync($self, /)\n"
187 "--\n"
188 "\n"
189 "Flush the database to the disk file.\n"
190 "\n"
191 "When the database has been opened in fast mode, this method forces\n"
192 "any unwritten data to be written to the disk.");
193 
194 #define _GDBM_GDBM_SYNC_METHODDEF    \
195     {"sync", (PyCFunction)_gdbm_gdbm_sync, METH_NOARGS, _gdbm_gdbm_sync__doc__},
196 
197 static PyObject *
198 _gdbm_gdbm_sync_impl(dbmobject *self);
199 
200 static PyObject *
_gdbm_gdbm_sync(dbmobject * self,PyObject * Py_UNUSED (ignored))201 _gdbm_gdbm_sync(dbmobject *self, PyObject *Py_UNUSED(ignored))
202 {
203     return _gdbm_gdbm_sync_impl(self);
204 }
205 
206 PyDoc_STRVAR(dbmopen__doc__,
207 "open($module, filename, flags=\'r\', mode=0o666, /)\n"
208 "--\n"
209 "\n"
210 "Open a dbm database and return a dbm object.\n"
211 "\n"
212 "The filename argument is the name of the database file.\n"
213 "\n"
214 "The optional flags argument can be \'r\' (to open an existing database\n"
215 "for reading only -- default), \'w\' (to open an existing database for\n"
216 "reading and writing), \'c\' (which creates the database if it doesn\'t\n"
217 "exist), or \'n\' (which always creates a new empty database).\n"
218 "\n"
219 "Some versions of gdbm support additional flags which must be\n"
220 "appended to one of the flags described above.  The module constant\n"
221 "\'open_flags\' is a string of valid additional flags.  The \'f\' flag\n"
222 "opens the database in fast mode; altered data will not automatically\n"
223 "be written to the disk after every change.  This results in faster\n"
224 "writes to the database, but may result in an inconsistent database\n"
225 "if the program crashes while the database is still open.  Use the\n"
226 "sync() method to force any unwritten data to be written to the disk.\n"
227 "The \'s\' flag causes all database operations to be synchronized to\n"
228 "disk.  The \'u\' flag disables locking of the database file.\n"
229 "\n"
230 "The optional mode argument is the Unix mode of the file, used only\n"
231 "when the database has to be created.  It defaults to octal 0o666.");
232 
233 #define DBMOPEN_METHODDEF    \
234     {"open", (PyCFunction)dbmopen, METH_VARARGS, dbmopen__doc__},
235 
236 static PyObject *
237 dbmopen_impl(PyObject *module, const char *name, const char *flags, int mode);
238 
239 static PyObject *
dbmopen(PyObject * module,PyObject * args)240 dbmopen(PyObject *module, PyObject *args)
241 {
242     PyObject *return_value = NULL;
243     const char *name;
244     const char *flags = "r";
245     int mode = 438;
246 
247     if (!PyArg_ParseTuple(args, "s|si:open",
248         &name, &flags, &mode)) {
249         goto exit;
250     }
251     return_value = dbmopen_impl(module, name, flags, mode);
252 
253 exit:
254     return return_value;
255 }
256 /*[clinic end generated code: output=ed0f5d4e3d79b80c input=a9049054013a1b77]*/
257