summaryrefslogtreecommitdiff
path: root/Modules/_dbmmodule.c
diff options
context:
space:
mode:
authorLarry Hastings <larry@hastings.org>2013-10-19 00:09:25 -0700
committerLarry Hastings <larry@hastings.org>2013-10-19 00:09:25 -0700
commit3182680210fa0cf570233382bbaec8b64d57f4da (patch)
tree93932cf52fd5cbbdeab62b2fc43851e3cb637e3d /Modules/_dbmmodule.c
parent5ceae41083f3bec479fe8f135f442e6576c6e273 (diff)
downloadcpython-git-3182680210fa0cf570233382bbaec8b64d57f4da.tar.gz
Issue #16612: Add "Argument Clinic", a compile-time preprocessor
for C files to generate argument parsing code. (See PEP 436.)
Diffstat (limited to 'Modules/_dbmmodule.c')
-rw-r--r--Modules/_dbmmodule.c71
1 files changed, 61 insertions, 10 deletions
diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c
index d89948050f..8babd0eb15 100644
--- a/Modules/_dbmmodule.c
+++ b/Modules/_dbmmodule.c
@@ -44,7 +44,7 @@ static PyTypeObject Dbmtype;
static PyObject *DbmError;
static PyObject *
-newdbmobject(char *file, int flags, int mode)
+newdbmobject(const char *file, int flags, int mode)
{
dbmobject *dp;
@@ -361,16 +361,69 @@ static PyTypeObject Dbmtype = {
/* ----------------------------------------------------------------- */
+/*[clinic]
+module dbm
+
+dbm.open as dbmopen
+
+ filename: str
+ The filename to open.
+
+ flags: str="r"
+ How to open the file. "r" for reading, "w" for writing, etc.
+
+ mode: int(doc_default="0o666") = 0o666
+ If creating a new file, the mode bits for the new file
+ (e.g. os.O_RDWR).
+
+ /
+
+Return a database object.
+
+[clinic]*/
+
+PyDoc_STRVAR(dbmopen__doc__,
+"Return a database object.\n"
+"\n"
+"dbm.open(filename, flags=\'r\', mode=0o666)\n"
+" filename\n"
+" The filename to open.\n"
+" flags\n"
+" How to open the file. \"r\" for reading, \"w\" for writing, etc.\n"
+" mode\n"
+" If creating a new file, the mode bits for the new file\n"
+" (e.g. os.O_RDWR).");
+
+#define DBMOPEN_METHODDEF \
+ {"open", (PyCFunction)dbmopen, METH_VARARGS, dbmopen__doc__},
+
+static PyObject *
+dbmopen_impl(PyObject *self, const char *filename, const char *flags, int mode);
+
static PyObject *
dbmopen(PyObject *self, PyObject *args)
{
- char *name;
- char *flags = "r";
+ PyObject *return_value = NULL;
+ const char *filename;
+ const char *flags = "r";
+ int mode = 438;
+
+ if (!PyArg_ParseTuple(args,
+ "s|si:open",
+ &filename, &flags, &mode))
+ goto exit;
+ return_value = dbmopen_impl(self, filename, flags, mode);
+
+exit:
+ return return_value;
+}
+
+static PyObject *
+dbmopen_impl(PyObject *self, const char *filename, const char *flags, int mode)
+/*[clinic checksum: 61007c796d38af85c8035afa769fb4bb453429ee]*/
+{
int iflags;
- int mode = 0666;
- if ( !PyArg_ParseTuple(args, "s|si:open", &name, &flags, &mode) )
- return NULL;
if ( strcmp(flags, "r") == 0 )
iflags = O_RDONLY;
else if ( strcmp(flags, "w") == 0 )
@@ -386,13 +439,11 @@ dbmopen(PyObject *self, PyObject *args)
"arg 2 to open should be 'r', 'w', 'c', or 'n'");
return NULL;
}
- return newdbmobject(name, iflags, mode);
+ return newdbmobject(filename, iflags, mode);
}
static PyMethodDef dbmmodule_methods[] = {
- { "open", (PyCFunction)dbmopen, METH_VARARGS,
- "open(path[, flag[, mode]]) -> mapping\n"
- "Return a database object."},
+ DBMOPEN_METHODDEF
{ 0, 0 },
};