svn commit: samba r15348 - in branches/SAMBA_4_0/source:
lib/ldb/swig scripting/swig/torture
tpot at samba.org
tpot at samba.org
Sun Apr 30 01:08:53 GMT 2006
Author: tpot
Date: 2006-04-30 01:08:52 +0000 (Sun, 30 Apr 2006)
New Revision: 15348
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15348
Log:
Start adding a dict interface and tests to LdbMessage class.
Modified:
branches/SAMBA_4_0/source/lib/ldb/swig/Ldb.py
branches/SAMBA_4_0/source/scripting/swig/torture/torture_ldb.py
Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/swig/Ldb.py
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/swig/Ldb.py 2006-04-30 01:08:02 UTC (rev 15347)
+++ branches/SAMBA_4_0/source/lib/ldb/swig/Ldb.py 2006-04-30 01:08:52 UTC (rev 15348)
@@ -52,6 +52,8 @@
self.mem_ctx = None
self.msg = None
+ # Make the dn attribute of the object dynamic
+
def __getattr__(self, attr):
if attr == 'dn':
return ldb_dn_linearize(None, self.msg.dn)
@@ -63,8 +65,7 @@
return
self.__dict__[attr] = value
- def len(self):
- return self.msg.num_elements
+ # Get and set individual elements
def __getitem__(self, key):
@@ -81,7 +82,23 @@
[ldb_msg_add_value(self.msg, key, v) for v in value]
else:
ldb_msg_add_value(self.msg, key, value)
-
+
+ # Dictionary interface
+ # TODO: move to iterator based interface
+
+ def len(self):
+ return self.msg.num_elements
+
+ def keys(self):
+ return [ldb_message_element_array_getitem(self.msg.elements, i).name
+ for i in range(self.msg.num_elements)]
+
+ def values(self):
+ return [self[k] for k in self.keys()]
+
+ def items(self):
+ return [(k, self[k]) for k in self.keys()]
+
class Ldb:
"""A class representing a binding to a ldb file."""
Modified: branches/SAMBA_4_0/source/scripting/swig/torture/torture_ldb.py
===================================================================
--- branches/SAMBA_4_0/source/scripting/swig/torture/torture_ldb.py 2006-04-30 01:08:02 UTC (rev 15347)
+++ branches/SAMBA_4_0/source/scripting/swig/torture/torture_ldb.py 2006-04-30 01:08:52 UTC (rev 15348)
@@ -1,14 +1,18 @@
#!/usr/bin/python
-import Ldb
+import Ldb, sys
-def fail(msg):
- print 'FAILED:', msg
- sys.exit(1)
+def test(cond, msg):
+ if not cond:
+ print 'FAILED:', msg
+ sys.exit(1)
-l = Ldb.Ldb()
+# Torture LdbMessage
-l.connect('tdb:///tmp/foo.ldb')
-result = l.search('(dn=*)')
+m = Ldb.LdbMessage()
+m['animal'] = 'dog'
+m['name'] = 'spotty'
-print result
+test(m.keys() == ['animal', 'name'], 'keys() test failed')
+test(m.values() == [['dog'], ['spotty']], 'values() test failed')
+test(m.items() == [('animal', ['dog']), ('name', ['spotty'])], 'items() test failed')
More information about the samba-cvs
mailing list