svn commit: samba r14915 - in branches/SAMBA_4_0/source/scripting/swig: .

tpot at samba.org tpot at samba.org
Tue Apr 4 22:15:28 GMT 2006


Author: tpot
Date: 2006-04-04 22:15:27 +0000 (Tue, 04 Apr 2006)
New Revision: 14915

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=14915

Log:
Work in progress - getting ldb_add() working.

Modified:
   branches/SAMBA_4_0/source/scripting/swig/Ldb.py
   branches/SAMBA_4_0/source/scripting/swig/ldb.i


Changeset:
Modified: branches/SAMBA_4_0/source/scripting/swig/Ldb.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/Ldb.py	2006-04-04 17:48:53 UTC (rev 14914)
+++ branches/SAMBA_4_0/source/scripting/swig/Ldb.py	2006-04-04 22:15:27 UTC (rev 14915)
@@ -44,15 +44,21 @@
 class LdbMessage:
     """A class representing a ldb message as a dict of ldb elements."""
     
-    def __init__(self, msg):
-        self.dn = msg.dn
-        self.private_data = msg.private_data
-        eltlist = \
-            [LdbElement(ldb.ldb_message_element_array_getitem(msg.elements, x))
-             for x in range(msg.num_elements)]
-        self.elements = \
-            dict([(x.name, x) for x in eltlist])
+    def __init__(self, msg = None):
 
+        self.dn = None
+        self.private_data = None
+        self.elements = []
+
+        if msg is not None:
+            self.dn = msg.dn
+            self.private_data = msg.private_data
+            eltlist = \
+                [LdbElement(ldb.ldb_message_element_array_getitem(
+                            msg.elements, x))
+                 for x in range(msg.num_elements)]
+            self.elements = dict([(x.name, x) for x in eltlist])
+
     def __repr__(self):
         return '<%s(dn=%s) instance at 0x%x>' % (self.__class__.__name__,
                                                `self.dn`, id(self))

Modified: branches/SAMBA_4_0/source/scripting/swig/ldb.i
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/ldb.i	2006-04-04 17:48:53 UTC (rev 14914)
+++ branches/SAMBA_4_0/source/scripting/swig/ldb.i	2006-04-04 22:15:27 UTC (rev 14915)
@@ -156,6 +156,30 @@
 	void *private_data; /* private to the backend */
 };
 
+%typemap(in) struct ldb_message * {
+	PyObject *obj, *key, *value;
+	int pos;
+
+	$1 = ldb_msg_new(NULL);
+
+	obj = PyObject_GetAttrString($input, "dn");
+	$1->dn = ldb_dn_explode(NULL, PyString_AsString(obj));
+
+	obj = PyObject_GetAttrString($input, "private_data");
+	$1->private_data = PyString_AsString(obj);
+
+	obj = PyObject_GetAttrString($input, "elements");
+
+	pos = 0;
+	while (PyDict_Next(obj, &pos, &key, &value)) {
+		struct ldb_val v;
+
+		v.data = PyString_AsString(value);
+		v.length = PyString_Size(value);
+		ldb_msg_add_value($1, PyString_AsString(key), &v);
+	}
+}
+
 /*
  * Wrap struct ldb_result
  */



More information about the samba-cvs mailing list