mirror of
https://github.com/samba-team/samba.git
synced 2025-07-28 11:42:03 +03:00
python: bulk port tdb iterkeys for py3
In py3, `dict.iterkeys()` is removed, we need to use `keys()` instead. This is compatible with py2 since `dict.keys()` exists for py2. tdb pretents to be a dict, however, not completely. It provides `iterkeys()` for py2 only, and `keys()` for py3 only, which means replace `iterkeys()` to `keys()` will break py2. In python, iter a dict will implicitly iter on keys. Use this feature to work around. Signed-off-by: Joe Guo <joeg@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
This commit is contained in:
@ -142,7 +142,7 @@ class IdmapDatabase(DbDatabase):
|
||||
|
||||
def ids(self):
|
||||
"""Retrieve a list of all ids in this database."""
|
||||
for k in self.db.iterkeys():
|
||||
for k in self.db:
|
||||
if k.startswith(IDMAP_USER_PREFIX):
|
||||
yield k.rstrip(b"\0").split(b" ")
|
||||
if k.startswith(IDMAP_GROUP_PREFIX):
|
||||
@ -213,7 +213,7 @@ class SecretsDatabase(DbDatabase):
|
||||
return self.db.get("SECRETS/DOMGUID/%s" % host)
|
||||
|
||||
def ldap_dns(self):
|
||||
for k in self.db.iterkeys():
|
||||
for k in self.db:
|
||||
if k.startswith("SECRETS/LDAP_BIND_PW/"):
|
||||
yield k[len("SECRETS/LDAP_BIND_PW/"):].rstrip("\0")
|
||||
|
||||
@ -222,7 +222,7 @@ class SecretsDatabase(DbDatabase):
|
||||
|
||||
:return: Iterator over the names of domains in this database.
|
||||
"""
|
||||
for k in self.db.iterkeys():
|
||||
for k in self.db:
|
||||
if k.startswith("SECRETS/SID/"):
|
||||
yield k[len("SECRETS/SID/"):].rstrip("\0")
|
||||
|
||||
@ -248,7 +248,7 @@ class SecretsDatabase(DbDatabase):
|
||||
return self.db.get("SECRETS/$DOMTRUST.ACC/%s" % host)
|
||||
|
||||
def trusted_domains(self):
|
||||
for k in self.db.iterkeys():
|
||||
for k in self.db:
|
||||
if k.startswith("SECRETS/$DOMTRUST.ACC/"):
|
||||
yield k[len("SECRETS/$DOMTRUST.ACC/"):].rstrip("\0")
|
||||
|
||||
|
Reference in New Issue
Block a user