[Twisted-Python] Ldaptor attributes in Python 3

Adi Roiban adi at roiban.ro
Sat Jan 23 15:09:17 MST 2021


Hi,

On Fri, 22 Jan 2021 at 11:15, Peter Westlake <peter.westlake at pobox.com>
wrote:

> I'm using Ldaptor for LDAP access because it fits in with Twisted, and the
> results are a bit mystifying. The results that come back from a search are
> a list of LDAPEntryWithClient.  Indexing this, e.g. entry['cn'], gives an
> object of type JournaledLDAPAttributeSet, which is a subclass of set. It
> contains the name of the attribute and a list containing the value:
>
> JournaledLDAPAttributeSet(b'cn', [b'Peter Westlake'])
>
> Getting the value out of that isn't straightforward: I'd have to check the
> elements of the set for a list. Is there a better way?
>
> I've also found that the items() method gives something more tractable:
>
> >>> entry.items()
> [
> (b'cn', b'Peter Westlake'),
> ...
> ]
>
> so I can turn that into a dict and index that. But again, this seems like
> an odd design for an API. Is there a better way to extract the value of an
> attribute from an entry?
>
>
Can you send a full example of how you would like the  API to behave ? Or
send a PR ? :)

I am doing a client-side search like this and I was happy with API

o = LDAPEntry(client, base_dn)
results = yield o.search(
    attributes=[b'objectclass'],
    scope=LDAP_SCOPE_wholeSubtree,
    filterText='(cn=test)',
    )
for result in results:
    print (result['objectclass'])

-- 
Adi Roiban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20210123/d9c34b71/attachment.htm>


More information about the Twisted-Python mailing list