# Copyright 2012-2014 Brian May## This file is part of python-tldap.## python-tldap is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## python-tldap is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with python-tldap If not, see <http://www.gnu.org/licenses/>.fromtldap.utilsimportDEFAULT_LDAP_ALIAS,ConnectionHandlerconnections=None"""An object containing a list of all LDAP connections."""
[docs]defsetup(settings):""" Function used to initialize LDAP settings. """globalconnectionsconnections=ConnectionHandler(settings)
# DatabaseWrapper.__init__() takes a dictionary, not a settings module, so# we manually create the dictionary from the settings, passing only the# settings that the database backends care about. Note that TIME_ZONE is used# by the PostgreSQL backends.# We load all these up for backwards compatibility, you should use# connections['default'] instead.
[docs]classDefaultConnectionProxy(object):""" Proxy for accessing the default DatabaseWrapper object's attributes. If you need to access the DatabaseWrapper object itself, use connections[DEFAULT_LDAP_ALIAS] instead. """def__getattr__(self,item):returngetattr(connections[DEFAULT_LDAP_ALIAS],item)def__setattr__(self,name,value):returnsetattr(connections[DEFAULT_LDAP_ALIAS],name,value)def__delattr__(self,name):returndelattr(connections[DEFAULT_LDAP_ALIAS],name)def__eq__(self,other):returnconnections[DEFAULT_LDAP_ALIAS]==otherdef__ne__(self,other):returnconnections[DEFAULT_LDAP_ALIAS]!=other
""" The default LDAP connection. """connection=DefaultConnectionProxy()