What's the best way to replace value of attribute which can handle multiple values?

Zhang Huangbin zhbmaillistonly at gmail.com
Wed Sep 9 08:03:03 CEST 2009

On Sep 9, 2009, at 1:32 PM, Zhang Huangbin wrote:
> I want to replace cn=cn2 by cn=cn4 if it exist, or add cn=cn4  
> directly if 'cn=cn2' donesn't exist.
> If cn=cn2 is not exist, [(ldap.MOD_DELETE, 'cn', 'cn2')] will raise  
> an error.
> If cn=cn2 is not exist, [(ldap.MOD_ADD, 'cn', 'cn4')] will add  
> cn=cn4, but can't delete 'cn=cn2'.

Oops, forget to mention that i will modify more attributes every time,  
not only 'cn'. Such as:

mod_attrs = [
    (ldap.MOD_XXX, attr1, value1),
    (ldap.MOD_XXX, attr2, [value2]),

self.conn.modify_s(dn, mod_attrs)

Is there a better way to modify it except using several  
'try:...except:...' block?

Best Regards.

Zhang Huangbin

- Open Source Mail Server Solution for Red Hat(R) Enterprise Linux,
   CentOS, Debian, Ubuntu: http://www.iredmail.org/

More information about the python-ldap mailing list