Replace entry.getValues() by entry.get()

Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
This commit is contained in:
Petr Viktorin 2013-01-21 04:34:44 -05:00 committed by Martin Kosek
parent b2dd8d7f05
commit c613caab67
5 changed files with 16 additions and 21 deletions

View File

@ -494,7 +494,7 @@ class LDAPUpdate:
for item in default:
# We already do syntax-parsing so this is safe
(attr, value) = item.split(':',1)
e = entry.getValues(attr)
e = entry.get(attr)
if e:
# multi-valued attribute
e = list(e)
@ -538,7 +538,7 @@ class LDAPUpdate:
if self.conn.has_dn_syntax(attr):
update_values = [DN(x) for x in update_values]
entry_values = entry.getValues(attr)
entry_values = entry.get(attr)
if not isinstance(entry_values, list):
if entry_values is None:
entry_values = []
@ -607,7 +607,7 @@ class LDAPUpdate:
self.debug("addifexist: '%s' to %s, current value %s", update_value, attr, entry_values)
# Only add the attribute if the entry doesn't exist. We
# determine this based on whether it has an objectclass
if entry.getValues('objectclass'):
if entry.get('objectclass'):
entry_values.append(update_value)
self.debug('addifexist: set %s to %s', attr, entry_values)
entry.setValues(attr, entry_values)
@ -624,7 +624,7 @@ class LDAPUpdate:
self.debug("onlyifexist: '%s' to %s, current value %s", update_value, attr, entry_values)
# Only set the attribute if the entry exist's. We
# determine this based on whether it has an objectclass
if entry.getValues('objectclass'):
if entry.get('objectclass'):
if only.get(attr):
entry_values.append(update_value)
else:
@ -681,7 +681,7 @@ class LDAPUpdate:
self.debug("dn: %s", e.dn)
attr = e.attrList()
for a in attr:
value = e.getValues(a)
value = e.get(a)
if isinstance(value, (list, tuple)):
self.debug('%s:', a)
for l in value:

View File

@ -326,7 +326,7 @@ class ReplicationManager(object):
try:
entry = conn.getEntry(dn, ldap.SCOPE_BASE)
managers = entry.getValues('nsDS5ReplicaBindDN')
managers = entry.get('nsDS5ReplicaBindDN')
for m in managers:
if replica_binddn == DN(m):
return
@ -466,7 +466,7 @@ class ReplicationManager(object):
# Add it to the list of users allowed to bypass password policy
extop_dn = DN(('cn', 'ipa_pwd_extop'), ('cn', 'plugins'), ('cn', 'config'))
entry = conn.getEntry(extop_dn, ldap.SCOPE_BASE)
pass_mgrs = entry.getValues('passSyncManagersDNs')
pass_mgrs = entry.get('passSyncManagersDNs')
if not pass_mgrs:
pass_mgrs = []
if not isinstance(pass_mgrs, list):
@ -1033,7 +1033,7 @@ class ReplicationManager(object):
entry = self.conn.getEntry(dn, ldap.SCOPE_BASE)
objectclass = entry.getValues("objectclass")
objectclass = entry.get("objectclass")
for o in objectclass:
if o.lower() == "nsdswindowsreplicationagreement":

View File

@ -197,7 +197,7 @@ class Service(object):
hostdn = DN(('fqdn', self.fqdn), ('cn', 'computers'), ('cn', 'accounts'), self.suffix)
self.admin_conn.deleteEntry(dn)
entry.dn = newdn
classes = entry.getValues("objectclass")
classes = entry.get("objectclass")
classes = classes + ["ipaobject", "ipaservice", "pkiuser"]
entry.setValues("objectclass", list(set(classes)))
entry.setValue("ipauniqueid", 'autogenerate')

View File

@ -697,11 +697,6 @@ class LDAPEntry(dict):
yield self._dn
yield self
def getValues(self, name):
# FIXME: for backwards compatibility only
"""Get the list (array) of values for the attribute named name"""
return self.data.get(name)
def getValue(self, name, default=None):
# FIXME: for backwards compatibility only
"""Get the first value for the attribute named name"""

View File

@ -106,7 +106,7 @@ class test_update(unittest.TestCase):
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.getValues('objectclass')
objectclasses = entry.get('objectclass')
for item in ('top', 'nsContainer'):
self.assertTrue(item in objectclasses)
@ -116,7 +116,7 @@ class test_update(unittest.TestCase):
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.getValues('objectclass')
objectclasses = entry.get('objectclass')
for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'):
self.assertTrue(item in objectclasses)
@ -172,7 +172,7 @@ class test_update(unittest.TestCase):
entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*'])
self.assertEqual(len(entries), 1)
entry = entries[0]
self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User', 'Test User New']))
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User', 'Test User New']))
def test_6_update(self):
"""
@ -184,7 +184,7 @@ class test_update(unittest.TestCase):
entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*'])
self.assertEqual(len(entries), 1)
entry = entries[0]
self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User']))
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User']))
def test_6_update_1(self):
"""
@ -196,7 +196,7 @@ class test_update(unittest.TestCase):
entries = self.ld.getList(self.user_dn, ldap.SCOPE_BASE, 'objectclass=*', ['*'])
self.assertEqual(len(entries), 1)
entry = entries[0]
self.assertEqual(sorted(entry.getValues('cn')), sorted(['Test User']))
self.assertEqual(sorted(entry.get('cn')), sorted(['Test User']))
def test_7_cleanup(self):
"""
@ -278,7 +278,7 @@ class test_update(unittest.TestCase):
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.getValues('objectclass')
objectclasses = entry.get('objectclass')
for item in ('top', 'nsContainer'):
self.assertTrue(item in objectclasses)
@ -288,7 +288,7 @@ class test_update(unittest.TestCase):
self.assertEqual(len(entries), 1)
entry = entries[0]
objectclasses = entry.getValues('objectclass')
objectclasses = entry.get('objectclass')
for item in ('top', 'person', 'posixaccount', 'krbprincipalaux', 'inetuser'):
self.assertTrue(item in objectclasses)