mirror of
https://github.com/samba-team/samba.git
synced 2025-12-07 20:23:50 +03:00
ldb/python: Allow comparing a MessageElement to a list or a singleton.
This commit is contained in:
@@ -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
|
||||
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;
|
||||
|
||||
|
||||
@@ -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
|
||||
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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user