py-ldb: allow dictionnary like usage (ie. e.get("myattribute", defVal)
authorMatthieu Patou <mat@matws.net>
Sat, 11 Jun 2011 12:57:02 +0000 (16:57 +0400)
committerMatthieu Patou <mat@samba.org>
Sun, 19 Jun 2011 21:21:07 +0000 (23:21 +0200)
source4/lib/ldb/pyldb.c

index 61662f6763355ec6f3e70fb4e20ca4f2373766e3..b568bc2ccd1b6c86d8f50993469685bd2215762f 100644 (file)
@@ -2442,15 +2442,20 @@ static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
 
 static PyObject *py_ldb_msg_get(PyLdbMessageObject *self, PyObject *args)
 {
-       PyObject *name, *ret;
-       if (!PyArg_ParseTuple(args, "O", &name))
+       PyObject *name, *ret, *retobj;
+       retobj = NULL;
+       if (!PyArg_ParseTuple(args, "O|O", &name, &retobj))
                return NULL;
 
        ret = py_ldb_msg_getitem_helper(self, name);
        if (ret == NULL) {
                if (PyErr_Occurred())
                        return NULL;
-               Py_RETURN_NONE;
+               if (retobj != NULL) {
+                       return retobj;
+               } else {
+                       Py_RETURN_NONE;
+               }
        }
        return ret;
 }