From: Joe Guo Date: Thu, 12 Apr 2018 04:07:24 +0000 (+1200) Subject: python: bulk port tdb iterkeys for py3 X-Git-Tag: ldb-1.4.0~604 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2892293182f282336f08ed17315ae744aa72bddc;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andrew Bartlett Reviewed-by: Douglas Bagnall --- diff --git a/python/samba/samba3/__init__.py b/python/samba/samba3/__init__.py index f7927836c98..b145e432c97 100644 --- a/python/samba/samba3/__init__.py +++ b/python/samba/samba3/__init__.py @@ -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")