[python-ldap] modifyModlist : are old and new values get compared somehow ?

Michael Ströder michael at stroeder.com
Tue Dec 1 14:21:45 EST 2015


mh at ow2.org wrote:
> Le 30/11/2015 13:10, Benjamin Dauvergne a écrit :
>> Le 11/30, mh at ow2.org a écrit : >> Hi, >> >> In the following code, >> >> old = {'attr':['oldvalue']}
> new = {'attr':['newvalue']} >> >> mod = modlist.modifyModlist(old,new)
>>>>> l.modify_s(dn,mod) >> >> >> I'm not sure to fully understand the
> documentation ; it seems the >> new attribute value is modified in all
> case - whatever the value >> stored in old attr ; in this case what's
> the point in specifying an >> 'oldvalue' ? > > As LDAP is a multivalued
> database i.e. each attribute can have > multiple values, what's computed
> by modifyModlist is a "diff": remove > old values, add new values. If
> you want to keep some old values > because for example the schema forbid
> a value to be missing (and > between the DELETE and the ADD there will
> be a time where no value is > defined) you have create your modlist
> yourself such as: > > l.modify_s(dn, [(ldap.MOD_REPLACE, attr,
> ['newvalue'])]) > > modlist.modifyModlist is just an helper function to
> build such change > lists, possible value for the action are: -
> ldap.MOD_ADD - > ldap.MOD_DELETE - ldap.MOD_REPLACE - ldap.MOD_INCREMENT >
> 
> Thank you Michael and Benjamin, I think I got it.
> 
> Let met reformulate what I've understood : the helper is only here to
> compare what's in dicts and build a diff list intended to be passed to
> modify() - it never gets compared values by accessing the LDAP directory
> straight (I stumbled on that).

Yes.

> So if I need to get the attribute value from the directory *before*
> updating it, I would need to use compare() isn't ?

You have to read/search the entry before.

> A side question : when I print str(mod), I see the constant value as
> number : is there a way to see that constant as constant name  ?(ie :
> MOD_XXX)

If you write a Python class for that implementing a __repr__() method...

Ciao, Michael.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4245 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20151201/18c25b86/attachment.bin>


More information about the python-ldap mailing list