From bdb7127d270b4795e5544378773ebc7bdab49c1c Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 31 Mar 2026 17:28:38 +0200 Subject: [PATCH] ldap.Connection.walk(): Support decode & unroll The entry instance passed to the walk callback contains raw results of LDAP search operations, i.e. all attribute values are lists, and all attribute values are bytes. Add the boolean parameters decode and unroll to walk() as a convenience method to get decoded values. They default to False, representing current behaviour. Signed-off-by: Jan Lindemann --- tools/python/jwutils/ldap.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/python/jwutils/ldap.py b/tools/python/jwutils/ldap.py index 3d023f0..bbd94ef 100644 --- a/tools/python/jwutils/ldap.py +++ b/tools/python/jwutils/ldap.py @@ -138,7 +138,8 @@ class Connection: # export slog(ERR, f'Failed to delete {dn} ({e})') raise - def walk(self, + def walk( + self, callback: Callable[[Self, Any, Any], None], base: str, scope, @@ -149,7 +150,10 @@ class Connection: # export serverctrls=None, clientctrls=None, timeout=-1, - sizelimit=0): + sizelimit=0, + decode: bool=False, + unroll: bool=False + ): # TODO: Support ignored arguments search_return = self.__ldap.search(base=base, @@ -164,6 +168,10 @@ class Connection: # export if result_type != ldap.RES_SEARCH_ENTRY: continue for entry in result_data: + if decode: + entry = entry[0], {key: [val.decode() for val in vals] for key, vals in entry[1].items()} + if unroll and False: + entry = entry[0], {key: val[0] for key, val in entry[1].items()} try: callback(self, entry, context) except Exception as e: