summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/swig
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2006-04-30 01:08:52 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:05:23 -0500
commit5abd8940f9bcfbab1b68018759a2405ec944f831 (patch)
tree06ea76e67a8382d48ec0ed82da1e0c124cec6721 /source4/lib/ldb/swig
parentec4421d126fd69d3caa51d89651b4f5f13d097ca (diff)
downloadsamba-5abd8940f9bcfbab1b68018759a2405ec944f831.tar.gz
samba-5abd8940f9bcfbab1b68018759a2405ec944f831.tar.bz2
samba-5abd8940f9bcfbab1b68018759a2405ec944f831.zip
r15348: Start adding a dict interface and tests to LdbMessage class.
(This used to be commit 7e30e8ba57efe37314ebca02f964420f56b9eb52)
Diffstat (limited to 'source4/lib/ldb/swig')
-rw-r--r--source4/lib/ldb/swig/Ldb.py23
1 files changed, 20 insertions, 3 deletions
diff --git a/source4/lib/ldb/swig/Ldb.py b/source4/lib/ldb/swig/Ldb.py
index d00b2b0be1..e78d56efda 100644
--- a/source4/lib/ldb/swig/Ldb.py
+++ b/source4/lib/ldb/swig/Ldb.py
@@ -52,6 +52,8 @@ class LdbMessage:
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 @@ class LdbMessage:
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 @@ class LdbMessage:
[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."""