LDAPMod(s) classes¶
-
class
LDAPMod(mode, attr[, values=None])¶ This class is just a Python wrapper for the corresponding C structure
LDAPModdescribed in ldap_modify_ext_s(3)Parameters: - mode (
LDAP_MOD_ADD,LDAP_MOD_DELETEorLDAP_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
Noneif the the entire attribute is to be deleted when parameter mode isLDAP_MOD_DELETE
Returns: a new
LDAPModobjectRaises: TypeError,ValueErrorAn instance of the class
LDAPModhas the following attributes:-
mode¶ type of modification to perform (
LDAP_MOD_ADD,LDAP_MOD_DELETEorLDAP_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)
- mode (
-
class
LDAPMods(mode, **attrs)¶ This class is just a utility for regrouping classes
LDAPModwith the same mode. It is a subclass of Python classlistParameters: - mode (
LDAP_MOD_ADD,LDAP_MOD_DELETEorLDAP_MOD_REPLACE) – type of modification to perform - attrs (dict) – attributes to modify
Returns: a list of
LDAPModobjectsRaises: LDAPError,TypeErrororValueErrorSo 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))
- mode (