<s> import ldap <EOL> import django <EOL> if django . VERSION < ( <NUM_LIT:1> , <NUM_LIT:8> ) : <EOL> from django . db . backends import ( BaseDatabaseFeatures , BaseDatabaseOperations , <EOL> BaseDatabaseWrapper ) <EOL> from django . db . backends . creation import BaseDatabaseCreation <EOL> else : <EOL> from django . db . backends . base . features import BaseDatabaseFeatures <EOL> from django . db . backends . base . operations import BaseDatabaseOperations <EOL> from django . db . backends . base . base import BaseDatabaseWrapper <EOL> from django . db . backends . base . creation import BaseDatabaseCreation <EOL> class DatabaseCreation ( BaseDatabaseCreation ) : <EOL> def create_test_db ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def destroy_test_db ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class DatabaseCursor ( object ) : <EOL> def __init__ ( self , ldap_connection ) : <EOL> self . connection = ldap_connection <EOL> class DatabaseFeatures ( BaseDatabaseFeatures ) : <EOL> def __init__ ( self , connection ) : <EOL> self . connection = connection <EOL> self . supports_transactions = False <EOL> class DatabaseOperations ( BaseDatabaseOperations ) : <EOL> compiler_module = "<STR_LIT>" <EOL> def quote_name ( self , name ) : <EOL> return name <EOL> def no_limit_value ( self ) : <EOL> return - <NUM_LIT:1> <EOL> class DatabaseWrapper ( BaseDatabaseWrapper ) : <EOL> vendor = '<STR_LIT>' <EOL> operators = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( DatabaseWrapper , self ) . __init__ ( * args , ** kwargs ) <EOL> self . charset = "<STR_LIT:utf-8>" <EOL> self . creation = DatabaseCreation ( self ) <EOL> self . features = DatabaseFeatures ( self ) <EOL> if django . VERSION > ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> self . ops = DatabaseOperations ( self ) <EOL> else : <EOL> self . ops = DatabaseOperations ( ) <EOL> self . settings_dict [ '<STR_LIT>' ] = True <EOL> self . autocommit = True <EOL> def close ( self ) : <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> self . validate_thread_sharing ( ) <EOL> if self . connection is not None : <EOL> self . connection . unbind_s ( ) <EOL> self . connection = None <EOL> def ensure_connection ( self ) : <EOL> if self . connection is None : <EOL> self . connection = ldap . initialize ( self . settings_dict [ '<STR_LIT>' ] ) <EOL> options = self . settings_dict . get ( '<STR_LIT>' , { } ) <EOL> for opt , value in options . items ( ) : <EOL> self . connection . set_option ( opt , value ) <EOL> if self . settings_dict . get ( '<STR_LIT>' , False ) : <EOL> self . connection . start_tls_s ( ) <EOL> self . connection . simple_bind_s ( <EOL> self . settings_dict [ '<STR_LIT>' ] , <EOL> self . settings_dict [ '<STR_LIT>' ] ) <EOL> def _commit ( self ) : <EOL> pass <EOL> def _cursor ( self ) : <EOL> self . ensure_connection ( ) <EOL> return DatabaseCursor ( self . connection ) <EOL> def _rollback ( self ) : <EOL> pass <EOL> def _set_autocommit ( self , autocommit ) : <EOL> pass <EOL> def add_s ( self , dn , modlist ) : <EOL> cursor = self . _cursor ( ) <EOL> return cursor . connection . add_s ( dn . encode ( self . charset ) , modlist ) <EOL> def delete_s ( self , dn ) : <EOL> cursor = self . _cursor ( ) <EOL> return cursor . connection . delete_s ( dn . encode ( self . charset ) ) <EOL> def modify_s ( self , dn , modlist ) : <EOL> cursor = self . _cursor ( ) <EOL> return cursor . connection . modify_s ( dn . encode ( self . charset ) , modlist ) <EOL> def rename_s ( self , dn , newrdn ) : <EOL> cursor = self . _cursor ( ) <EOL> return cursor . connection . rename_s ( dn . encode ( self . charset ) , <EOL> newrdn . encode ( self . charset ) ) <EOL> def search_s ( self , base , scope , filterstr = '<STR_LIT>' , <EOL> attrlist = None ) : <EOL> cursor = self . _cursor ( ) <EOL> results = cursor . connection . search_s ( base , scope , <EOL> filterstr . encode ( self . charset ) , <EOL> attrlist ) <EOL> output = [ ] <EOL> for dn , attrs in results : <EOL> if dn is not None : <EOL> output . append ( ( dn . decode ( self . charset ) , attrs ) ) <EOL> return output </s>
