diff options
author | Kamen Mazdrashki <kamenim@samba.org> | 2010-11-18 22:11:30 +0200 |
---|---|---|
committer | Kamen Mazdrashki <kamenim@samba.org> | 2010-11-18 22:28:08 +0100 |
commit | a403d7777e94ffdcdb57045e8a4755aced0e8484 (patch) | |
tree | af44f93807b879235fea074c29fb706f935a5c89 /source4/lib | |
parent | a09a41f300a4d721c117a95822d272cc5866ac92 (diff) | |
download | samba-a403d7777e94ffdcdb57045e8a4755aced0e8484.tar.gz samba-a403d7777e94ffdcdb57045e8a4755aced0e8484.tar.bz2 samba-a403d7777e94ffdcdb57045e8a4755aced0e8484.zip |
s4-pyldb: ldb.Message.from_dict class method to create LdbMessage object from dictionary
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/pyldb.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source4/lib/ldb/pyldb.c b/source4/lib/ldb/pyldb.c index ac19c4f739..d4b63008f8 100644 --- a/source4/lib/ldb/pyldb.c +++ b/source4/lib/ldb/pyldb.c @@ -2003,6 +2003,45 @@ PyTypeObject PyLdbMessageElement = { .tp_flags = Py_TPFLAGS_DEFAULT, }; + +static PyObject *py_ldb_msg_from_dict(PyTypeObject *type, PyObject *args) +{ + PyObject *py_ldb; + PyObject *py_dict; + PyObject *py_ret; + struct ldb_message *msg; + struct ldb_context *ldb_ctx; + unsigned int mod_flags = LDB_FLAG_MOD_REPLACE; + + if (!PyArg_ParseTuple(args, "O!O!|I", + &PyLdb, &py_ldb, &PyDict_Type, &py_dict, + &mod_flags)) { + return NULL; + } + + /* mask only flags we are going to use */ + mod_flags = LDB_FLAG_MOD_TYPE(mod_flags); + if (!mod_flags) { + PyErr_SetString(PyExc_ValueError, + "FLAG_MOD_ADD, FLAG_MOD_REPLACE or FLAG_MOD_DELETE" + " expected as mod_flag value"); + return NULL; + } + + ldb_ctx = PyLdb_AsLdbContext(py_ldb); + + msg = PyDict_AsMessage(ldb_ctx, py_dict, ldb_ctx, mod_flags); + if (!msg) { + return NULL; + } + + py_ret = PyLdbMessage_FromMessage(msg); + + talloc_unlink(ldb_ctx, msg); + + return py_ret; +} + static PyObject *py_ldb_msg_remove_attr(PyLdbMessageObject *self, PyObject *args) { char *name; @@ -2090,6 +2129,11 @@ static PyObject *py_ldb_msg_items(PyLdbMessageObject *self) } static PyMethodDef py_ldb_msg_methods[] = { + { "from_dict", (PyCFunction)py_ldb_msg_from_dict, METH_CLASS | METH_VARARGS, + "Message.from_dict(ldb, dict, mod_flag) -> ldb.Message\n" + "Class method to create ldb.Message object from Dictionary.\n" + "mod_flag is one of FLAG_MOD_ADD, FLAG_MOD_REPLACE or FLAG_MOD_DELETE.\n" + "mod_flag defaults to FLAG_MOD_REPLACE"}, { "keys", (PyCFunction)py_ldb_msg_keys, METH_NOARGS, NULL }, { "remove", (PyCFunction)py_ldb_msg_remove_attr, METH_VARARGS, NULL }, { "get", (PyCFunction)py_ldb_msg_get, METH_VARARGS, NULL }, |