LDAPMod(s) classes

class LDAPMod(mode, attr[, values=None])

This class is just a Python wrapper for the corresponding C structure LDAPMod described in ldap_modify_ext_s(3)

Parameters:
  • mode (LDAP_MOD_ADD, LDAP_MOD_DELETE or LDAP_MOD_REPLACE) – type of modification to perform
  • attr (str) – the attribute to modify
  • values – a list of values (strings) to add, delete, or replace respectively or None if the the entire attribute is to be deleted when parameter mode is LDAP_MOD_DELETE
Returns:

a new LDAPMod object

Raises:

TypeError, ValueError

An instance of the class LDAPMod has the following attributes:

mode

type of modification to perform (LDAP_MOD_ADD, LDAP_MOD_DELETE or LDAP_MOD_REPLACE)

attr

attribute to modify

values

a list of values to add, delete, or replace respectively or None

Some examples:

>>> lma = LDAPMod(LDAP_MOD_ADD, 'uid', ['bob'])
>>> lmd = LDAPMod(LDAP_MOD_DELETE, 'uid')

See also

ldap_add_ext_s(3), ldap_modify_ext_s(3)

class LDAPMods(mode, **attrs)

This class is just a utility for regrouping classes LDAPMod with the same mode. It is a subclass of Python class list

Parameters:
  • mode (LDAP_MOD_ADD, LDAP_MOD_DELETE or LDAP_MOD_REPLACE) – type of modification to perform
  • attrs (dict) – attributes to modify
Returns:

a list of LDAPMod objects

Raises:

LDAPError, TypeError or ValueError

So instead of writing,

>>> lma = LDAPMod(LDAP_MOD_ADD, 'uid', ['bob'])
>>> lmb = LDAPMod(LDAP_MOD_ADD, 'givenName', ['Robert'])
>>> l.add_ext_s('ou=users', [lma, lmb])

it is often shorter to write:

>>> lm = LDAPMods(LDAP_MOD_ADD, uid=['bob'], givenName=['Robert'])
>>> l.add_ext_s('ou=users', lm)

or

>>> d = {'uid': ['bob'], 'givenName': ['Robert']}
>>> l.add_ext_s('ou=users', LDAPMods(LDAP_MOD_ADD, **d))