[Buildbot-devel] problem implementing IEmailLookup

John Blair John.Blair at Sun.COM
Wed Mar 7 22:24:26 UTC 2007


Howdy,

I'm trying to implement an IEmailLookup object that does LDAP lookups 
here at Sun.  I've written the following.  I know the code inside the 
object works, as I've tested it on its own.  However, I'm not 
understanding something about how to implement an IEmailLookup object.  
See the end of the email for the error msg.

I'd appreciate it if anybody can point to what I'm doing incorrectly.

thanks so much!
 -john.


# if an address appears here it won't be looked up in ldap
email_map = {
}

class SunEmailLookup(IEmailLookup):
        def __init__(self, email_map):
                self.email_map = email_map
        def getAddress(user):
                l = ldap.open('sun-ds.sun.com')
                l.simple_bind_s("dc=sun,dc=com")
                ldap_timeout = 10;

                if self.email_map.has_key(user):
                        return self.email_map[user]
                try:
                        result_id = l.search("dc=sun,dc=com", 
ldap.SCOPE_SUBTREE, "uid="+user+"", ["mail"])
                        result_type, result_data = l.result(result_id, 
ldap_timeout)
                except:
                        return user
                if len(result_data) == 0:
                        return user
                else:
                        return result_data[0][1]['mail'][0]

email_lookup = SunEmailLookup(email_map);



Error mesage follows:

          File "../masters.cfg", line 53, in ?
            email_lookup = SunEmailLookup(email_map);
          File 
"/usr/lib/python2.3/site-packages/twisted/python/components.py", line 
195, in __call__
            return interface.InterfaceClass.__call__(self, adaptable)
          File 
"/usr/lib/python2.3/site-packages/zope/interface/interface.py", line 
703, in __call__
            raise TypeError("Could not adapt", obj, self)
        exceptions.TypeError: ('Could not adapt', {}, <MetaInterface 
__builtin__.SunEmailLookup>)







More information about the devel mailing list