Browse Source

Merge branch 'master' of git.illyse.org:coin

Conflicts:
	.gitignore
fabs 11 years ago
parent
commit
bdacccfc83

+ 2 - 0
.gitignore

@@ -1 +1,3 @@
 *.pyc
+*~
+.svn

+ 0 - 23
ldapdb/.svn/all-wcprops

@@ -1,23 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 52
-/opensource/!svn/ver/1117/django-ldapdb/trunk/ldapdb
-END
-__init__.py
-K 25
-svn:wc:ra_dav:version-url
-V 64
-/opensource/!svn/ver/1049/django-ldapdb/trunk/ldapdb/__init__.py
-END
-router.py
-K 25
-svn:wc:ra_dav:version-url
-V 62
-/opensource/!svn/ver/1052/django-ldapdb/trunk/ldapdb/router.py
-END
-tests.py
-K 25
-svn:wc:ra_dav:version-url
-V 61
-/opensource/!svn/ver/1115/django-ldapdb/trunk/ldapdb/tests.py
-END

+ 0 - 136
ldapdb/.svn/entries

@@ -1,136 +0,0 @@
-10
-
-dir
-1180
-https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk/ldapdb
-https://svn.bolloretelecom.eu/opensource
-
-
-
-2012-03-29T02:51:53.277739Z
-1117
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e071eeec-0327-468d-9b6a-08194a12b294
-
-backends
-dir
-
-models
-dir
-
-__init__.py
-file
-
-
-
-
-2013-03-18T13:47:28.573755Z
-3ad0a8522a59d7377a03a2c387826476
-2011-04-12T07:52:08.547990Z
-1049
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2434
-
-router.py
-file
-
-
-
-
-2013-03-18T13:47:28.573755Z
-04f9ba9b2c3636250c9dbc82d197582c
-2011-05-03T19:41:27.859431Z
-1052
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-2960
-
-tests.py
-file
-
-
-
-
-2013-03-18T13:47:28.573755Z
-5ae7b36776816cab4bbac0510147986b
-2012-03-29T02:15:08.328149Z
-1115
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-6134
-

+ 0 - 58
ldapdb/.svn/text-base/__init__.py.svn-base

@@ -1,58 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.conf import settings
-
-def escape_ldap_filter(value):
-    value = unicode(value)
-    return value.replace('\\', '\\5c') \
-                .replace('*', '\\2a') \
-                .replace('(', '\\28') \
-                .replace(')', '\\29') \
-                .replace('\0', '\\00')
-
-# Legacy single database support
-if hasattr(settings, 'LDAPDB_SERVER_URI'):
-    from django import db
-    from ldapdb.router import Router
-
-    # Add the LDAP backend
-    settings.DATABASES['ldap'] = {
-        'ENGINE': 'ldapdb.backends.ldap',
-        'NAME': settings.LDAPDB_SERVER_URI,
-        'USER': settings.LDAPDB_BIND_DN,
-        'PASSWORD': settings.LDAPDB_BIND_PASSWORD}
-
-    # Add the LDAP router
-    db.router.routers.append(Router())

+ 0 - 74
ldapdb/.svn/text-base/router.py.svn-base

@@ -1,74 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-def is_ldap_model(model):
-    # FIXME: there is probably a better check than testing 'base_dn'
-    return hasattr(model, 'base_dn')
-
-class Router(object):
-    """
-    A router to point database operations on LDAP models to the LDAP
-    database.
-
-    NOTE: if you have more than one LDAP database, you will need to
-    write your own router.
-    """
-
-    def __init__(self):
-        "Find the name of the LDAP database"
-        from django.conf import settings
-        self.ldap_alias = None
-        for alias, settings_dict in settings.DATABASES.items():
-            if settings_dict['ENGINE'] == 'ldapdb.backends.ldap':
-                self.ldap_alias = alias
-                break
-
-    def allow_syncdb(self, db, model):
-        "Do not create tables for LDAP models"
-        if is_ldap_model(model):
-            return db == self.ldap_alias
-        return None
-
-    def db_for_read(self, model, **hints):
-        "Point all operations on LDAP models to the LDAP database"
-        if is_ldap_model(model):
-            return self.ldap_alias
-        return None
-
-    def db_for_write(self, model, **hints):
-        "Point all operations on LDAP models to the LDAP database"
-        if is_ldap_model(model):
-            return self.ldap_alias
-        return None
-

+ 0 - 129
ldapdb/.svn/text-base/tests.py.svn-base

@@ -1,129 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.test import TestCase
-from django.db.models.sql.where import Constraint, AND, OR, WhereNode
-
-from ldapdb import escape_ldap_filter
-from ldapdb.backends.ldap.compiler import where_as_ldap
-from ldapdb.models.fields import CharField, IntegerField, ListField
-
-class WhereTestCase(TestCase):
-    def test_escape(self):
-        self.assertEquals(escape_ldap_filter(u'fôöbàr'), u'fôöbàr')
-        self.assertEquals(escape_ldap_filter('foo*bar'), 'foo\\2abar')
-        self.assertEquals(escape_ldap_filter('foo(bar'), 'foo\\28bar')
-        self.assertEquals(escape_ldap_filter('foo)bar'), 'foo\\29bar')
-        self.assertEquals(escape_ldap_filter('foo\\bar'), 'foo\\5cbar')
-        self.assertEquals(escape_ldap_filter('foo\\bar*wiz'), 'foo\\5cbar\\2awiz')
-
-    def test_char_field_exact(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'exact', "test"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=test)", []))
-
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'exact', "(test)"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=\\28test\\29)", []))
-
-    def test_char_field_in(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'in', ["foo", "bar"]), AND)
-        self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(cn=bar))", []))
-
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'in', ["(foo)", "(bar)"]), AND)
-        self.assertEquals(where_as_ldap(where), ("(|(cn=\\28foo\\29)(cn=\\28bar\\29))", []))
-
-    def test_char_field_startswith(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'startswith', "test"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=test*)", []))
-
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'startswith', "te*st"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=te\\2ast*)", []))
-
-    def test_char_field_endswith(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'endswith', "test"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=*test)", []))
-
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'endswith', "te*st"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast)", []))
-
-    def test_char_field_contains(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'contains', "test"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=*test*)", []))
-
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'contains', "te*st"), AND)
-        self.assertEquals(where_as_ldap(where), ("(cn=*te\\2ast*)", []))
-
-    def test_integer_field(self):
-        where = WhereNode()
-        where.add((Constraint("uid", "uid", IntegerField()), 'exact', 1), AND)
-        self.assertEquals(where_as_ldap(where), ("(uid=1)", []))
-
-        where = WhereNode()
-        where.add((Constraint("uid", "uid", IntegerField()), 'gte', 1), AND)
-        self.assertEquals(where_as_ldap(where), ("(uid>=1)", []))
-
-        where = WhereNode()
-        where.add((Constraint("uid", "uid", IntegerField()), 'lte', 1), AND)
-        self.assertEquals(where_as_ldap(where), ("(uid<=1)", []))
-
-    def test_list_field_contains(self):
-        where = WhereNode()
-        where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', 'foouser'), AND)
-        self.assertEquals(where_as_ldap(where), ("(memberUid=foouser)", []))
-
-        where = WhereNode()
-        where.add((Constraint("memberUid", "memberUid", ListField()), 'contains', '(foouser)'), AND)
-        self.assertEquals(where_as_ldap(where), ("(memberUid=\\28foouser\\29)", []))
-
-    def test_and(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)
-        where.add((Constraint("givenName", "givenName", CharField()), 'exact', "bar"), AND)
-        self.assertEquals(where_as_ldap(where), ("(&(cn=foo)(givenName=bar))", []))
-
-    def test_or(self):
-        where = WhereNode()
-        where.add((Constraint("cn", "cn", CharField()), 'exact', "foo"), AND)
-        where.add((Constraint("givenName", "givenName", CharField()), 'exact', "bar"), OR)
-        self.assertEquals(where_as_ldap(where), ("(|(cn=foo)(givenName=bar))", []))
-

+ 0 - 11
ldapdb/backends/.svn/all-wcprops

@@ -1,11 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 61
-/opensource/!svn/ver/1117/django-ldapdb/trunk/ldapdb/backends
-END
-__init__.py
-K 25
-svn:wc:ra_dav:version-url
-V 73
-/opensource/!svn/ver/1013/django-ldapdb/trunk/ldapdb/backends/__init__.py
-END

+ 0 - 65
ldapdb/backends/.svn/entries

@@ -1,65 +0,0 @@
-10
-
-dir
-1180
-https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk/ldapdb/backends
-https://svn.bolloretelecom.eu/opensource
-
-
-
-2012-03-29T02:51:53.277739Z
-1117
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e071eeec-0327-468d-9b6a-08194a12b294
-
-ldap
-dir
-
-__init__.py
-file
-
-
-
-
-2013-03-18T13:47:28.569755Z
-d41d8cd98f00b204e9800998ecf8427e
-2011-04-11T07:50:03.669671Z
-1013
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-0
-

+ 0 - 0
ldapdb/backends/.svn/text-base/__init__.py.svn-base


+ 0 - 124
ldapdb/backends/ldap/base.py~

@@ -1,124 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2010, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-import ldap
-import django
-
-from django.db.backends import BaseDatabaseFeatures, BaseDatabaseOperations, BaseDatabaseWrapper
-from django.db.backends.creation import BaseDatabaseCreation
-
-class DatabaseCreation(BaseDatabaseCreation):
-    def create_test_db(self, verbosity=1, autoclobber=False):
-        """
-        Creates a test database, prompting the user for confirmation if the
-        database already exists. Returns the name of the test database created.
-        """
-        pass
-
-    def destroy_test_db(self, old_database_name, verbosity=1):
-        """
-        Destroy a test database, prompting the user for confirmation if the
-        database already exists. Returns the name of the test database created.
-        """
-        pass
-
-class DatabaseCursor(object):
-    def __init__(self, ldap_connection):
-        self.connection = ldap_connection
-
-class DatabaseFeatures(BaseDatabaseFeatures):
-    def __init__(self, connection):
-        self.connection = connection
-
-class DatabaseOperations(BaseDatabaseOperations):
-    compiler_module = "ldapdb.backends.ldap.compiler"
-
-    def quote_name(self, name):
-        return name
-
-class DatabaseWrapper(BaseDatabaseWrapper):
-    def __init__(self, *args, **kwargs):
-        super(DatabaseWrapper, self).__init__(*args, **kwargs)
-
-        self.charset = "utf-8"
-        self.creation = DatabaseCreation(self)
-        self.features = DatabaseFeatures(self)
-        if django.VERSION > (1, 4):
-            self.ops = DatabaseOperations(self)
-        else:
-            self.ops = DatabaseOperations()
-        self.settings_dict['SUPPORTS_TRANSACTIONS'] = False
-
-    def close(self):
-        pass
-
-    def _commit(self):
-        pass
-
-    def _cursor(self):
-        if self.connection is None:
-            self.connection = ldap.initialize(self.settings_dict['NAME'])
-            self.connection.simple_bind_s(
-                self.settings_dict['USER'],
-                self.settings_dict['PASSWORD'])
-        return DatabaseCursor(self.connection)
-
-    def _rollback(self):
-        pass
-
-    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='(objectClass=*)',attrlist=None):
-        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))
-        print filterstr        
-        return output
-

+ 0 - 23
ldapdb/models/.svn/all-wcprops

@@ -1,23 +0,0 @@
-K 25
-svn:wc:ra_dav:version-url
-V 59
-/opensource/!svn/ver/1064/django-ldapdb/trunk/ldapdb/models
-END
-fields.py
-K 25
-svn:wc:ra_dav:version-url
-V 69
-/opensource/!svn/ver/1049/django-ldapdb/trunk/ldapdb/models/fields.py
-END
-base.py
-K 25
-svn:wc:ra_dav:version-url
-V 67
-/opensource/!svn/ver/1064/django-ldapdb/trunk/ldapdb/models/base.py
-END
-__init__.py
-K 25
-svn:wc:ra_dav:version-url
-V 71
-/opensource/!svn/ver/1049/django-ldapdb/trunk/ldapdb/models/__init__.py
-END

+ 0 - 130
ldapdb/models/.svn/entries

@@ -1,130 +0,0 @@
-10
-
-dir
-1180
-https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk/ldapdb/models
-https://svn.bolloretelecom.eu/opensource
-
-
-
-2011-12-06T10:13:34.643205Z
-1064
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-e071eeec-0327-468d-9b6a-08194a12b294
-
-fields.py
-file
-
-
-
-
-2013-03-18T13:47:28.497755Z
-91d47c443bda86c39a3caf1a1153f844
-2011-04-12T07:52:08.547990Z
-1049
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-5823
-
-base.py
-file
-
-
-
-
-2013-03-18T13:47:28.497755Z
-e6d078d97f424266aec0a74fd12a899a
-2011-12-06T10:13:34.643205Z
-1064
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-6069
-
-__init__.py
-file
-
-
-
-
-2013-03-18T13:47:28.497755Z
-60f1a81f72149f52cdc7bbef5a860bc9
-2011-04-12T07:52:08.547990Z
-1049
-jlaine
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-1732
-

+ 0 - 35
ldapdb/models/.svn/text-base/__init__.py.svn-base

@@ -1,35 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from ldapdb.models.base import Model

+ 0 - 160
ldapdb/models/.svn/text-base/base.py.svn-base

@@ -1,160 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-import ldap
-import logging
-
-import django.db.models
-from django.db import connections, router
-from django.db.models import signals
-
-import ldapdb
-
-class Model(django.db.models.base.Model):
-    """
-    Base class for all LDAP models.
-    """
-    dn = django.db.models.fields.CharField(max_length=200)
-
-    # meta-data
-    base_dn = None
-    search_scope = ldap.SCOPE_SUBTREE
-    object_classes = ['top']
-
-    def __init__(self, *args, **kwargs):
-        super(Model, self).__init__(*args, **kwargs)
-        self.saved_pk = self.pk
-
-    def build_rdn(self):
-        """
-        Build the Relative Distinguished Name for this entry.
-        """
-        bits = []
-        for field in self._meta.fields:
-            if field.db_column and field.primary_key:
-                bits.append("%s=%s" % (field.db_column, getattr(self, field.name)))
-        if not len(bits):
-            raise Exception("Could not build Distinguished Name")
-        return '+'.join(bits)
-
-    def build_dn(self):
-        """
-        Build the Distinguished Name for this entry.
-        """
-        return "%s,%s" % (self.build_rdn(), self.base_dn)
-        raise Exception("Could not build Distinguished Name")
-
-    def delete(self, using=None):
-        """
-        Delete this entry.
-        """
-        using = using or router.db_for_write(self.__class__, instance=self)
-        connection = connections[using]
-        logging.debug("Deleting LDAP entry %s" % self.dn)
-        connection.delete_s(self.dn)
-        signals.post_delete.send(sender=self.__class__, instance=self)
-
-    def save(self, using=None):
-        """
-        Saves the current instance.
-        """
-        using = using or router.db_for_write(self.__class__, instance=self)
-        connection = connections[using]
-        if not self.dn:
-            # create a new entry
-            record_exists = False 
-            entry = [('objectClass', self.object_classes)]
-            new_dn = self.build_dn()
-
-            for field in self._meta.fields:
-                if not field.db_column:
-                    continue
-                value = getattr(self, field.name)
-                if value:
-                    entry.append((field.db_column, field.get_db_prep_save(value, connection=connection)))
-
-            logging.debug("Creating new LDAP entry %s" % new_dn)
-            connection.add_s(new_dn, entry)
-
-            # update object
-            self.dn = new_dn
-
-        else:
-            # update an existing entry
-            record_exists = True
-            modlist = []
-            orig = self.__class__.objects.get(pk=self.saved_pk)
-            for field in self._meta.fields:
-                if not field.db_column:
-                    continue
-                old_value = getattr(orig, field.name, None)
-                new_value = getattr(self, field.name, None)
-                if old_value != new_value:
-                    if new_value:
-                        modlist.append((ldap.MOD_REPLACE, field.db_column, field.get_db_prep_save(new_value, connection=connection)))
-                    elif old_value:
-                        modlist.append((ldap.MOD_DELETE, field.db_column, None))
-
-            if len(modlist):
-                # handle renaming
-                new_dn = self.build_dn()
-                if new_dn != self.dn:
-                    logging.debug("Renaming LDAP entry %s to %s" % (self.dn, new_dn))
-                    connection.rename_s(self.dn, self.build_rdn())
-                    self.dn = new_dn
-            
-                logging.debug("Modifying existing LDAP entry %s" % self.dn)
-                connection.modify_s(self.dn, modlist)
-            else:
-                logging.debug("No changes to be saved to LDAP entry %s" % self.dn)
-
-        # done
-        self.saved_pk = self.pk
-        signals.post_save.send(sender=self.__class__, instance=self, created=(not record_exists))
-
-    @classmethod
-    def scoped(base_class, base_dn):
-        """
-        Returns a copy of the current class with a different base_dn.
-        """
-        class Meta:
-            proxy = True
-        import re
-        suffix = re.sub('[=,]', '_', base_dn)
-        name = "%s_%s" % (base_class.__name__, str(suffix))
-        new_class = type(name, (base_class,), {'base_dn': base_dn, '__module__': base_class.__module__, 'Meta': Meta})
-        return new_class
-
-    class Meta:
-        abstract = True

+ 0 - 144
ldapdb/models/.svn/text-base/fields.py.svn-base

@@ -1,144 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.db.models import fields, SubfieldBase
-
-from ldapdb import escape_ldap_filter
-
-class CharField(fields.CharField):
-    def __init__(self, *args, **kwargs):
-        kwargs['max_length'] = 200
-        super(CharField, self).__init__(*args, **kwargs)
-
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return ''
-        else:
-            return value[0].decode(connection.charset)
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        if lookup_type == 'endswith':
-            return ["*%s" % escape_ldap_filter(value)]
-        elif lookup_type == 'startswith':
-            return ["%s*" % escape_ldap_filter(value)]
-        elif lookup_type in ['contains', 'icontains']:
-            return ["*%s*" % escape_ldap_filter(value)]
-        elif lookup_type == 'exact':
-            return [escape_ldap_filter(value)]
-        elif lookup_type == 'in':
-            return [escape_ldap_filter(v) for v in value]
-
-        raise TypeError("CharField has invalid lookup: %s" % lookup_type)
-
-    def get_db_prep_save(self, value, connection):
-        return [value.encode(connection.charset)]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type == 'endswith':
-            return "*%s" % escape_ldap_filter(value)
-        elif lookup_type == 'startswith':
-            return "%s*" % escape_ldap_filter(value)
-        elif lookup_type in ['contains', 'icontains']:
-            return "*%s*" % escape_ldap_filter(value)
-        elif lookup_type == 'exact':
-            return escape_ldap_filter(value)
-        elif lookup_type == 'in':
-            return [escape_ldap_filter(v) for v in value]
-
-        raise TypeError("CharField has invalid lookup: %s" % lookup_type)
-
-class ImageField(fields.Field):
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return ''
-        else:
-            return value[0]
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [value]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        raise TypeError("ImageField has invalid lookup: %s" % lookup_type)
-
-class IntegerField(fields.IntegerField):
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return 0
-        else:
-            return int(value[0])
-        
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [str(value)]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type in ('exact', 'gte', 'lte'):
-            return value
-        raise TypeError("IntegerField has invalid lookup: %s" % lookup_type)
-
-class ListField(fields.Field):
-    __metaclass__ = SubfieldBase
-
-    def from_ldap(self, value, connection):
-        return value
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [x.encode(connection.charset) for x in value]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type == 'contains':
-            return escape_ldap_filter(value)
-        raise TypeError("ListField has invalid lookup: %s" % lookup_type)
-
-    def to_python(self, value):
-        if not value:
-            return []
-        return value
-

+ 0 - 164
ldapdb/models/base.py~

@@ -1,164 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-import ldap
-import logging
-
-import django.db.models
-from django.db import connections, router
-from django.db.models import signals
-
-import ldapdb
-
-class Model(django.db.models.base.Model):
-    """
-    Base class for all LDAP models.
-    """
-    dn = django.db.models.fields.CharField(max_length=200)
-
-    # meta-data
-    base_dn = None
-    search_scope = ldap.SCOPE_SUBTREE
-    object_classes = ['top']
-
-    def __init__(self, *args, **kwargs):
-        super(Model, self).__init__(*args, **kwargs)
-        self.saved_pk = self.pk
-
-    def build_rdn(self):
-        """
-        Build the Relative Distinguished Name for this entry.
-        """
-        bits = []
-        for field in self._meta.fields:
-            if field.db_column and field.primary_key:
-                bits.append("%s=%s" % (field.db_column, getattr(self, field.name)))
-        if not len(bits):
-            raise Exception("Could not build Distinguished Name")
-        return '+'.join(bits)
-
-    def build_dn(self):
-        """
-        Build the Distinguished Name for this entry.
-        """
-        return "%s,%s" % (self.build_rdn(), self.base_dn)
-        raise Exception("Could not build Distinguished Name")
-
-    def delete(self, using=None):
-        """
-        Delete this entry.
-        """
-        using = using or router.db_for_write(self.__class__, instance=self)
-        connection = connections[using]
-        logging.debug("Deleting LDAP entry %s" % self.dn)
-        connection.delete_s(self.dn)
-        signals.post_delete.send(sender=self.__class__, instance=self)
-
-    def save(self, using=None):
-
-        """
-        Saves the current instance.
-        """
-        using = using or router.db_for_write(self.__class__, instance=self)
-        connection = connections[using]
-
-        if not self.dn:
-            
-            # create a new entry
-            record_exists = False 
-            entry = [('objectClass', self.object_classes)]
-            new_dn = self.build_dn()
-
-            for field in self._meta.fields:
-                if not field.db_column:
-                    continue
-                value = getattr(self, field.name)
-                if value:
-                    entry.append((field.db_column, field.get_db_prep_save(value, connection=connection)))
-
-            logging.debug("Creating new LDAP entry %s" % new_dn)
-            print 'blop'
-            connection.add_s(new_dn, entry)
-
-            # update object
-            self.dn = new_dn
-
-        else:
-            # update an existing entry
-            record_exists = True
-            modlist = []
-            orig = self.__class__.objects.get(pk=self.saved_pk)
-            for field in self._meta.fields:
-                if not field.db_column:
-                    continue
-                old_value = getattr(orig, field.name, None)
-                new_value = getattr(self, field.name, None)
-                if old_value != new_value:
-                    if new_value:
-                        modlist.append((ldap.MOD_REPLACE, field.db_column, field.get_db_prep_save(new_value, connection=connection)))
-                    elif old_value:
-                        modlist.append((ldap.MOD_DELETE, field.db_column, None))
-
-            if len(modlist):
-                # handle renaming
-                new_dn = self.build_dn()
-                if new_dn != self.dn:
-                    logging.debug("Renaming LDAP entry %s to %s" % (self.dn, new_dn))
-                    connection.rename_s(self.dn, self.build_rdn())
-                    self.dn = new_dn
-            
-                logging.debug("Modifying existing LDAP entry %s" % self.dn)
-                connection.modify_s(self.dn, modlist)
-            else:
-                logging.debug("No changes to be saved to LDAP entry %s" % self.dn)
-
-        # done
-        self.saved_pk = self.pk
-        signals.post_save.send(sender=self.__class__, instance=self, created=(not record_exists))
-
-    @classmethod
-    def scoped(base_class, base_dn):
-        """
-        Returns a copy of the current class with a different base_dn.
-        """
-        class Meta:
-            proxy = True
-        import re
-        suffix = re.sub('[=,]', '_', base_dn)
-        name = "%s_%s" % (base_class.__name__, str(suffix))
-        new_class = type(name, (base_class,), {'base_dn': base_dn, '__module__': base_class.__module__, 'Meta': Meta})
-        return new_class
-
-    class Meta:
-        abstract = True

+ 0 - 145
ldapdb/models/fields.py~

@@ -1,145 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-from django.db.models import fields, SubfieldBase
-
-from ldapdb import escape_ldap_filter
-
-class CharField(fields.CharField):
-    def __init__(self, *args, **kwargs):
-        kwargs['max_length'] = 200
-        super(CharField, self).__init__(*args, **kwargs)
-
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return ''
-        else:
-            print value[0]
-            return value[0].decode(connection.charset)
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        if lookup_type == 'endswith':
-            return ["*%s" % escape_ldap_filter(value)]
-        elif lookup_type == 'startswith':
-            return ["%s*" % escape_ldap_filter(value)]
-        elif lookup_type in ['contains', 'icontains']:
-            return ["*%s*" % escape_ldap_filter(value)]
-        elif lookup_type == 'exact':
-            return [escape_ldap_filter(value)]
-        elif lookup_type == 'in':
-            return [escape_ldap_filter(v) for v in value]
-
-        raise TypeError("CharField has invalid lookup: %s" % lookup_type)
-
-    def get_db_prep_save(self, value, connection):
-        return [value.encode(connection.charset)]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type == 'endswith':
-            return "*%s" % escape_ldap_filter(value)
-        elif lookup_type == 'startswith':
-            return "%s*" % escape_ldap_filter(value)
-        elif lookup_type in ['contains', 'icontains']:
-            return "*%s*" % escape_ldap_filter(value)
-        elif lookup_type == 'exact':
-            return escape_ldap_filter(value)
-        elif lookup_type == 'in':
-            return [escape_ldap_filter(v) for v in value]
-
-        raise TypeError("CharField has invalid lookup: %s" % lookup_type)
-
-class ImageField(fields.Field):
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return ''
-        else:
-            return value[0]
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [value]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        raise TypeError("ImageField has invalid lookup: %s" % lookup_type)
-
-class IntegerField(fields.IntegerField):
-    def from_ldap(self, value, connection):
-        if len(value) == 0:
-            return 0
-        else:
-            return int(value[0])
-        
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [str(value)]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type in ('exact', 'gte', 'lte'):
-            return value
-        raise TypeError("IntegerField has invalid lookup: %s" % lookup_type)
-
-class ListField(fields.Field):
-    __metaclass__ = SubfieldBase
-
-    def from_ldap(self, value, connection):
-        return value
-
-    def get_db_prep_lookup(self, lookup_type, value, connection, prepared=False):
-        "Returns field's value prepared for database lookup."
-        return [self.get_prep_lookup(lookup_type, value)]
-
-    def get_db_prep_save(self, value, connection):
-        return [x.encode(connection.charset) for x in value]
-
-    def get_prep_lookup(self, lookup_type, value):
-        "Perform preliminary non-db specific lookup checks and conversions"
-        if lookup_type == 'contains':
-            return escape_ldap_filter(value)
-        raise TypeError("ListField has invalid lookup: %s" % lookup_type)
-
-    def to_python(self, value):
-        if not value:
-            return []
-        return value
-

+ 0 - 74
ldapdb/router.py~

@@ -1,74 +0,0 @@
-# -*- coding: utf-8 -*-
-# 
-# django-ldapdb
-# Copyright (c) 2009-2011, Bolloré telecom
-# All rights reserved.
-# 
-# See AUTHORS file for a full list of contributors.
-# 
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-# 
-#     1. Redistributions of source code must retain the above copyright notice, 
-#        this list of conditions and the following disclaimer.
-#     
-#     2. Redistributions in binary form must reproduce the above copyright 
-#        notice, this list of conditions and the following disclaimer in the
-#        documentation and/or other materials provided with the distribution.
-# 
-#     3. Neither the name of Bolloré telecom nor the names of its contributors
-#        may be used to endorse or promote products derived from this software
-#        without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-def is_ldap_model(model):
-    # FIXME: there is probably a better check than testing 'base_dn'
-	return hasattr(model, 'base_dn')
-
-class Router(object):
-    """
-    A router to point database operations on LDAP models to the LDAP
-    database.
-
-    NOTE: if you have more than one LDAP database, you will need to
-    write your own router.
-    """
-
-    def __init__(self):
-        "Find the name of the LDAP database"
-        from django.conf import settings
-        self.ldap_alias = None
-        for alias, settings_dict in settings.DATABASES.items():
-            if settings_dict['ENGINE'] == 'ldapdb.backends.ldap':
-                self.ldap_alias = alias
-                break
-
-    def allow_syncdb(self, db, model):
-        "Do not create tables for LDAP models"
-        if is_ldap_model(model):
-            return db == self.ldap_alias
-        return None
-
-    def db_for_read(self, model, **hints):
-        "Point all operations on LDAP models to the LDAP database"
-        if is_ldap_model(model):
-            return self.ldap_alias
-        return None
-
-    def db_for_write(self, model, **hints):
-        "Point all operations on LDAP models to the LDAP database"
-        if is_ldap_model(model):
-            return self.ldap_alias
-        return None
-