def modifyModlist(
  old_entry,new_entry,ignore_attr_types=None,ignore_oldexistent=0
):
  ignore_attr_types = list_dict(map(string.lower,(ignore_attr_types or [])))
  modlist = []
  attrtype_lower_map = {}
  for a in old_entry.keys():
    attrtype_lower_map[string.lower(a)]=a
  for attrtype in new_entry.keys():
    attrtype_lower = string.lower(attrtype)
    if ignore_attr_types.has_key(attrtype_lower):
      # This attribute type is ignored
      continue
    # Filter away null-strings
    new_value = filter(lambda x:x!=None,new_entry[attrtype])
    if attrtype_lower_map.has_key(attrtype_lower):
      old_value = old_entry.get(attrtype_lower_map[attrtype_lower],[])
      old_value = filter(lambda x:x!=None,old_value)
      del attrtype_lower_map[attrtype_lower]
    else:
      old_value = []
    if not old_value and new_value:
      # Add a new attribute to entry
      modlist.append((ldap.MOD_ADD,attrtype,new_value))
    elif old_value and new_value:
      # Replace existing attribute
      replace_attr_value = len(old_value)!=len(new_value)
      if not replace_attr_value:
        old_value_dict=list_dict(old_value)
        new_value_dict=list_dict(new_value)
        delete_values = []
        for v in old_value:
          if not new_value_dict.has_key(v):
            replace_attr_value = 1
            break
        add_values = []
        if not replace_attr_value:
          for v in new_value:
            if not old_value_dict.has_key(v):
              replace_attr_value = 1
              break
      if replace_attr_value:
        modlist.append((ldap.MOD_DELETE,attrtype,None))
        modlist.append((ldap.MOD_ADD,attrtype,new_value))
    elif old_value and not new_value:
      # Completely delete an existing attribute
      modlist.append((ldap.MOD_DELETE,attrtype,None))
  if not ignore_oldexistent:
    # Remove all attributes of old_entry which are not present
    # in new_entry at all
    for a in attrtype_lower_map.keys():
      if ignore_attr_types.has_key(a):
        # This attribute type is ignored
        continue
      attrtype = attrtype_lower_map[a]
      modlist.append((ldap.MOD_DELETE,attrtype,None))
  return modlist # modifyModlist()
Build differential modify list for calling LDAPObject.modify()/modify_s()
dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/python-ldap-2.3.13/Lib/ldap/modlist.py/modifyModlist