-class DatabaseCursor(object):
- def __init__(self, ldap_connection):
- self.connection = ldap_connection
-
-class DatabaseFeatures(BaseDatabaseFeatures):
- pass
-
-class DatabaseOperations(BaseDatabaseOperations):
- def quote_name(self, name):
- return name
-
-class LdapConnection(object):
- def __init__(self):
- self.connection = None
- self.charset = "utf-8"
- self.features = DatabaseFeatures()
- self.ops = DatabaseOperations()
-
- def _cursor(self):
- if self.connection is None:
- self.connection = ldap.initialize(settings.LDAPDB_SERVER_URI)
- self.connection.simple_bind_s(
- settings.LDAPDB_BIND_DN,
- settings.LDAPDB_BIND_PASSWORD)
- return DatabaseCursor(self.connection)
-
- def add_s(self, dn, modlist):
- cursor = self._cursor()
- return cursor.connection.add_s(dn.encode(self.charset), modlist)
-
- def delete_s(self, dn):
- cursor = self._cursor()
- return cursor.connection.delete_s(dn.encode(self.charset))
-
- def modify_s(self, dn, modlist):
- cursor = self._cursor()
- return cursor.connection.modify_s(dn.encode(self.charset), modlist)
-
- def rename_s(self, dn, newrdn):
- cursor = self._cursor()
- return cursor.connection.rename_s(dn.encode(self.charset), newrdn.encode(self.charset))
-
- def search_s(self, base, scope, filterstr, attrlist):
- cursor = self._cursor()
- results = cursor.connection.search_s(base, scope, filterstr.encode(self.charset), attrlist)
- output = []
- for dn, attrs in results:
- output.append((dn.decode(self.charset), attrs))
- return output
-