A class shouldn't write to stderr on error, it should throw an exception
[mirror/userdir-ldap.git] / UDLdap.py
index 2e45092..0155345 100644 (file)
--- a/UDLdap.py
+++ b/UDLdap.py
@@ -16,11 +16,9 @@ class Account:
     def from_search(ldap_connection, base, user):
         searchresult = ldap_connection.search_s(base, ldap.SCOPE_SUBTREE, 'uid=%s'%(user))
         if len(searchresult) < 1:
-            sys.stderr.write("No such user: %s\n"%(user))
-            return
+            raise IndexError, "No such user: %s\n"%(user)
         elif len(searchresult) > 1:
-            sys.stderr.write("More than one hit when getting %s\n"%(user))
-            return
+            raise IndexError, "More than one hit when getting %s\n"%(user)
         else:
             return Account(searchresult[0][0], searchresult[0][1])