[SCM] Samba Shared Repository - branch v4-0-test updated -
release-4-0-0alpha2-340-g1ccbab8
Jelmer Vernooij
jelmer at samba.org
Fri Jan 11 00:56:50 GMT 2008
The branch, v4-0-test has been updated
via 1ccbab81d79f83bb419104f2bbaf2ae7b368e90f (commit)
from a8f90ed34ce9341080b63c801ef54b82de42b8e6 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v4-0-test
- Log -----------------------------------------------------------------
commit 1ccbab81d79f83bb419104f2bbaf2ae7b368e90f
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Jan 11 01:55:56 2008 +0100
ldb/python: Allow comparing a MessageElement to a list or a singleton.
-----------------------------------------------------------------------
Summary of changes:
source/lib/ldb/ldb.i | 13 ++++++++-----
source/lib/ldb/ldb.py | 13 ++++++++-----
source/lib/ldb/tests/python/api.py | 6 ++++++
3 files changed, 22 insertions(+), 10 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source/lib/ldb/ldb.i b/source/lib/ldb/ldb.i
index 57fa365..b671835 100644
--- a/source/lib/ldb/ldb.i
+++ b/source/lib/ldb/ldb.i
@@ -306,12 +306,15 @@ typedef struct ldb_message_element {
return ret
def __eq__(self, other):
- if (isinstance(other, str) and
- len(set(self)) == 1 and
- set(self).pop() == other):
+ if (len(self) == 1 and self.get(0) == other):
return True
- return self.__cmp__(other) == 0
-
+ if isinstance(other, self.__class__):
+ return self.__cmp__(other) == 0
+ o = iter(other)
+ for i in range(len(self)):
+ if self.get(i) != o.next():
+ return False
+ return True
}
} ldb_msg_element;
diff --git a/source/lib/ldb/ldb.py b/source/lib/ldb/ldb.py
index 2d037f0..6aacc8c 100644
--- a/source/lib/ldb/ldb.py
+++ b/source/lib/ldb/ldb.py
@@ -101,12 +101,15 @@ class ldb_msg_element(object):
return ret
def __eq__(self, other):
- if (isinstance(other, str) and
- len(set(self)) == 1 and
- set(self).pop() == other):
+ if (len(self) == 1 and self.get(0) == other):
return True
- return self.__cmp__(other) == 0
-
+ if isinstance(other, self.__class__):
+ return self.__cmp__(other) == 0
+ o = iter(other)
+ for i in range(len(self)):
+ if self.get(i) != o.next():
+ return False
+ return True
ldb_msg_element.__iter__ = new_instancemethod(_ldb.ldb_msg_element___iter__,None,ldb_msg_element)
ldb_msg_element.__set__ = new_instancemethod(_ldb.ldb_msg_element___set__,None,ldb_msg_element)
diff --git a/source/lib/ldb/tests/python/api.py b/source/lib/ldb/tests/python/api.py
index 5ab4010..8469e8f 100755
--- a/source/lib/ldb/tests/python/api.py
+++ b/source/lib/ldb/tests/python/api.py
@@ -392,6 +392,12 @@ class MessageElementTests(unittest.TestCase):
x = ldb.MessageElement(["foo", "bar"])
self.assertEquals(2, len(x))
+ def test_eq(self):
+ x = ldb.MessageElement(["foo", "bar"])
+ self.assertEquals(["foo", "bar"], x)
+ x = ldb.MessageElement(["foo"])
+ self.assertEquals("foo", x)
+
class ExampleModule:
name = "example"
--
Samba Shared Repository
More information about the samba-cvs
mailing list