Changeset 2221 for pykota/trunk

Show
Ignore:
Timestamp:
04/28/05 23:36:22 (20 years ago)
Author:
jerome
Message:

Add a workaround for users with an old version of python-ldap.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r2218 r2221  
    2929# 
    3030 
     31import sys 
    3132import os 
    3233import types 
     
    4041    import ldap 
    4142    import ldap.modlist 
    42     import ldap.cidict 
    4343except ImportError :     
    44     import sys 
    4544    raise PyKotaStorageError, "This python version (%s) doesn't seem to have the python-ldap module installed correctly." % sys.version.split()[0] 
     45else :     
     46    try : 
     47        from ldap.cidict import cidict 
     48    except ImportError :     
     49        import UserDict 
     50        sys.stderr.write("ERROR: PyKota requires a newer version of python-ldap. Workaround activated. Please upgrade python-ldap !\n") 
     51        class cidict(UserDict.UserDict) : 
     52            pass # Fake it all, and don't care for case insensitivity : users who need it will have to upgrade. 
    4653     
    4754class Storage(BaseStorage) : 
     
    159166            else :      
    160167                self.tool.logdebug("QUERY : Result : %s" % result) 
    161                 result = [ (dn, ldap.cidict.cidict(attrs)) for (dn, attrs) in result ] 
     168                result = [ (dn, cidict(attrs)) for (dn, attrs) in result ] 
    162169                if self.useldapcache : 
    163170                    for (dn, attributes) in result : 
     
    169176    def doAdd(self, dn, fields) : 
    170177        """Adds an entry in the LDAP directory.""" 
    171         fields = self.normalizeFields(ldap.cidict.cidict(fields)) 
     178        fields = self.normalizeFields(cidict(fields)) 
    172179        message = "" 
    173180        for tryit in range(3) : 
     
    215222    def doModify(self, dn, fields, ignoreold=1, flushcache=0) : 
    216223        """Modifies an entry in the LDAP directory.""" 
    217         fields = ldap.cidict.cidict(fields) 
     224        fields = cidict(fields) 
    218225        for tryit in range(3) : 
    219226            try :