[python-ldap] Auto encoding of binary fields

Philipp Hahn hahn at univention.de
Wed May 17 01:38:12 EDT 2017


Hello,

Am 17.05.2017 um 05:34 schrieb Ritesh Nadhani:
> One more observation that I cannot seem to find information for, is
> why the python package returns every attribute value as a list. Even
> for attribute like sAMAccountName (which seems can only hold on single
> string value) is returned as:
> 
> ['someName']

Because that is the data model defined by LDAP, so it's not python-ldap
specific.
It makes generic LDAP application easier to write if you can just handle
every attribute the same, that is as multi-valued. Otherwise you would
need attribute specific knowledge into every app, which breaks as soon
as you add new attributes, which old application then would not be able
to handle.
(I've inherited a legacy LDAP library, which adds some wrapper around
the low-level LDAP stuff. It distinguished between single-valued
attributes and multi-valued attributes and either presents them an
"string" or "list of strings" in Python. Any application using that
application is riddled with if statements like "if that attribute is
single-valued, do this, otherwise do that". Often they are wrong because
in Python "stings" are handled as "list of characters", leading to
strange errors.)

> For display purposes in my app, I would like to show those values as
> single element but attributes which allow multiple values as list. Is
> there some specification/list of fields that can be multivalue?

Look at the schema definition of each attribute; if it is declared as
"SINGLE-VALUE", only one value is allowed, otherwise it's multi-valued:
> ldapsearch -x -LLL -o ldif-wrap=no -b cn=Subschema -s base attributeTypes | grep SINGLE-VALUE

> Sorry, if its something that I overlooked or is just a simple question.

I hope I could help you.

Philipp


More information about the python-ldap mailing list