python: bulk port tdb iterkeys for py3
authorJoe Guo <joeg@catalyst.net.nz>
Thu, 12 Apr 2018 04:07:24 +0000 (16:07 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 13 Apr 2018 05:27:12 +0000 (07:27 +0200)
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>
python/samba/samba3/__init__.py

index f7927836c989b8b28bf53577453f5128dc8fad81..b145e432c97eb68f580cfb54ce8e838bbb9233de 100644 (file)
@@ -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")