@@ -0,0 +1,3689 @@
+# -*- coding: utf-8 -*-%0A# %0A# django-ldapdb%0A# Copyright (c) 2009-2010, Bollor%C3%A9 telecom%0A# All rights reserved.%0A# %0A# See AUTHORS file for a full list of contributors.%0A# %0A# Redistribution and use in source and binary forms, with or without modification,%0A# are permitted provided that the following conditions are met:%0A# %0A#     1. Redistributions of source code must retain the above copyright notice, %0A#        this list of conditions and the following disclaimer.%0A#     %0A#     2. Redistributions in binary form must reproduce the above copyright %0A#        notice, this list of conditions and the following disclaimer in the%0A#        documentation and/or other materials provided with the distribution.%0A# %0A#     3. Neither the name of Bollor%C3%A9 telecom nor the names of its contributors%0A#        may be used to endorse or promote products derived from this software%0A#        without specific prior written permission.%0A# %0A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS %22AS IS%22 AND%0A# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED%0A# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE%0A# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR%0A# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES%0A# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;%0A# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON%0A# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT%0A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS%0A# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.%0A#%0A%0Aimport ldap%0A%0Afrom django.db.backends import BaseDatabaseFeatures, BaseDatabaseOperations, BaseDatabaseWrapper%0A%0Aclass DatabaseCursor(object):%0A    def __init__(self, ldap_connection):%0A        self.connection = ldap_connection%0A%0Aclass DatabaseFeatures(BaseDatabaseFeatures):%0A    def __init__(self, connection):%0A        self.connection = connection%0A%0Aclass DatabaseOperations(BaseDatabaseOperations):%0A    def quote_name(self, name):%0A        return name%0A%0Aclass DatabaseWrapper(BaseDatabaseWrapper):%0A    def __init__(self, settings_dict, alias='ldap'):%0A        super(DatabaseWrapper, self).__init__(settings_dict, alias=alias)%0A%0A        self.charset = %22utf-8%22%0A        self.features = DatabaseFeatures(self)%0A        self.ops = DatabaseOperations()%0A%0A    def close(self):%0A        pass%0A%0A    def _cursor(self):%0A        if self.connection is None:%0A            self.connection = ldap.initialize(self.settings_dict%5B'NAME'%5D)%0A            self.connection.simple_bind_s(%0A                self.settings_dict%5B'USER'%5D,%0A                self.settings_dict%5B'PASSWORD'%5D)%0A        return DatabaseCursor(self.connection)%0A%0A    def add_s(self, dn, modlist):%0A        cursor = self._cursor()%0A        return cursor.connection.add_s(dn.encode(self.charset), modlist)%0A%0A    def delete_s(self, dn):%0A        cursor = self._cursor()%0A        return cursor.connection.delete_s(dn.encode(self.charset))%0A%0A    def modify_s(self, dn, modlist):%0A        cursor = self._cursor()%0A        return cursor.connection.modify_s(dn.encode(self.charset), modlist)%0A%0A    def rename_s(self, dn, newrdn):%0A        cursor = self._cursor()%0A        return cursor.connection.rename_s(dn.encode(self.charset), newrdn.encode(self.charset))%0A%0A    def search_s(self, base, scope, filterstr, attrlist):%0A        cursor = self._cursor()%0A        results = cursor.connection.search_s(base, scope, filterstr.encode(self.charset), attrlist)%0A        output = %5B%5D%0A        for dn, attrs in results:%0A            output.append((dn.decode(self.charset), attrs))%0A        return output%0A%0A

move backend definition