Hi I really like your approach but when do you actually get connected?? You never call the method connect?
> > class NSCLdap(object): > def __init__(self, > server="sc-ldap.nsc.com", > baseDN="o=nsc.com", > who=None, > cred=None): > self.server = server > self.baseDN = baseDN > if who is None: > self.who = "" > else: > self.who = who > if cred is None: > self.cred = "" > else: > self.cred = cred > self.connection = None > > def connect(self): > try: > print "LDAP Version", ldap.__version__ > self.connection = ldap.open(server) > self.connection.simple_bind_s(self.who, self.cred) > self.connection.protocol_version=ldap.VERSION3 > > except ldap.LDAPError, error_message: > # I would not catch this. It's the caller's > # responsabilitie to handle this IMHO > print >> sys.stderr, "Couldn't Connect to %s %s " % > (server,error_message) > > def search(self, > baseDN=None, > searchScope=ldap.SCOPE_SUBTREE, > retrieveAttrs=None, > searchAttrs="cn=*klass*" ): > > cnx = self.connection > if baseDN is None: > baseDN = self.baseDN > > try: > ldap_result_id = cnx.search_s(baseDN, > searchScope, > searchAttrs, > retrieveAttrs) > result_set = [] > while True: > result_type, result_data =cnx.result(ldap_result_id, 0) > #if (result_data == []): > if not result_data: > break > ## here you don't have to append to a list > ## you could do whatever you want with the > ## individual entry > ## The appending to list is just for > ## illustration. > if result_type == ldap.RES_SEARCH_ENTRY: > result_set.append(result_data) > print result_set > except ldap.LDAPError, error_message: > print >> sys.stderr, "Errors on Search %s " % error_message > > if __name__ == '__main__': > truc = NSCLdap() > truc.search() -- http://mail.python.org/mailman/listinfo/python-list