mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-04-24 18:13:37 +02:00
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 <jan@janware.com>
This commit is contained in:
parent
988d420e44
commit
bdb7127d27
1 changed files with 10 additions and 2 deletions
|
|
@ -138,7 +138,8 @@ class Connection: # export
|
||||||
slog(ERR, f'Failed to delete {dn} ({e})')
|
slog(ERR, f'Failed to delete {dn} ({e})')
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def walk(self,
|
def walk(
|
||||||
|
self,
|
||||||
callback: Callable[[Self, Any, Any], None],
|
callback: Callable[[Self, Any, Any], None],
|
||||||
base: str,
|
base: str,
|
||||||
scope,
|
scope,
|
||||||
|
|
@ -149,7 +150,10 @@ class Connection: # export
|
||||||
serverctrls=None,
|
serverctrls=None,
|
||||||
clientctrls=None,
|
clientctrls=None,
|
||||||
timeout=-1,
|
timeout=-1,
|
||||||
sizelimit=0):
|
sizelimit=0,
|
||||||
|
decode: bool=False,
|
||||||
|
unroll: bool=False
|
||||||
|
):
|
||||||
|
|
||||||
# TODO: Support ignored arguments
|
# TODO: Support ignored arguments
|
||||||
search_return = self.__ldap.search(base=base,
|
search_return = self.__ldap.search(base=base,
|
||||||
|
|
@ -164,6 +168,10 @@ class Connection: # export
|
||||||
if result_type != ldap.RES_SEARCH_ENTRY:
|
if result_type != ldap.RES_SEARCH_ENTRY:
|
||||||
continue
|
continue
|
||||||
for entry in result_data:
|
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:
|
try:
|
||||||
callback(self, entry, context)
|
callback(self, entry, context)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue