<s> """<STR_LIT>""" <EOL> from mongokit import Connection <EOL> from django . db . backends import ( <EOL> BaseDatabaseOperations , <EOL> BaseDatabaseClient , <EOL> BaseDatabaseIntrospection , <EOL> BaseDatabaseWrapper , <EOL> BaseDatabaseFeatures , <EOL> BaseDatabaseValidation <EOL> ) <EOL> from django . db . backends . creation import BaseDatabaseCreation <EOL> from django . conf import settings <EOL> TEST_DATABASE_PREFIX = '<STR_LIT>' <EOL> class UnsupportedConnectionOperation ( Exception ) : <EOL> pass <EOL> def complain ( * args , ** kwargs ) : <EOL> raise UnsupportedConnectionOperation ( "<STR_LIT>" % unicode ( args ) ) <EOL> def ignore ( * args , ** kwargs ) : <EOL> pass <EOL> class DatabaseError ( Exception ) : <EOL> pass <EOL> class IntegrityError ( DatabaseError ) : <EOL> pass <EOL> class DatabaseOperations ( BaseDatabaseOperations ) : <EOL> def quote_name ( self , name ) : <EOL> return '<STR_LIT>' % name <EOL> def sql_flush ( self , * args , ** kwargs ) : <EOL> return [ True ] <EOL> class DatabaseClient ( BaseDatabaseClient ) : <EOL> runshell = complain <EOL> class DatabaseIntrospection ( BaseDatabaseIntrospection ) : <EOL> def get_table_list ( self , cursor ) : <EOL> return [ ] <EOL> get_table_description = complain <EOL> get_relations = complain <EOL> get_indexes = complain <EOL> class DatabaseCreation ( BaseDatabaseCreation ) : <EOL> def create_test_db ( self , verbosity = <NUM_LIT:1> , autoclobber = False ) : <EOL> if self . connection . settings_dict . get ( '<STR_LIT>' ) : <EOL> test_database_name = self . connection . settings_dict [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in self . connection . settings_dict : <EOL> test_database_name = ( TEST_DATABASE_PREFIX + <EOL> self . connection . settings_dict [ '<STR_LIT>' ] ) <EOL> elif '<STR_LIT>' in self . connection . settings_dict : <EOL> if ( self . connection . settings_dict [ '<STR_LIT>' ] <EOL> . startswith ( TEST_DATABASE_PREFIX ) ) : <EOL> test_database_name = ( self . connection <EOL> . settings_dict [ '<STR_LIT>' ] ) <EOL> else : <EOL> test_database_name = TEST_DATABASE_PREFIX + self . connection . settings_dict [ '<STR_LIT>' ] <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> try : <EOL> settings . DATABASES [ '<STR_LIT>' ] [ '<STR_LIT>' ] = test_database_name <EOL> except AttributeError : <EOL> settings . MONGO_DATABASE_NAME = test_database_name <EOL> settings . DATABASE_SUPPORTS_TRANSACTIONS = False <EOL> self . _drop_database ( test_database_name ) <EOL> def destroy_test_db ( self , old_database_name , verbosity = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if verbosity >= <NUM_LIT:1> : <EOL> print "<STR_LIT>" % self . connection . alias <EOL> if '<STR_LIT>' in self . connection . settings_dict : <EOL> test_database_name = settings . MONGO_DATABASE_NAME <EOL> else : <EOL> test_database_name = self . connection . settings_dict [ '<STR_LIT>' ] <EOL> self . _drop_database ( test_database_name ) <EOL> try : <EOL> settings . DATABASES [ '<STR_LIT>' ] [ '<STR_LIT>' ] = old_database_name <EOL> except AttributeError : <EOL> settings . MONGO_DATABASE_NAME = old_database_name <EOL> def _drop_database ( self , database_name ) : <EOL> if not database_name . startswith ( TEST_DATABASE_PREFIX ) : <EOL> raise DatabaseError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( database_name , TEST_DATABASE_PREFIX ) <EOL> ) <EOL> if database_name in self . connection . connection . database_names ( ) : <EOL> self . connection . connection . drop_database ( database_name ) <EOL> class DatabaseFeatures ( BaseDatabaseFeatures ) : <EOL> def __init__ ( self , connection ) : <EOL> super ( DatabaseFeatures , self ) . __init__ ( connection ) <EOL> @ property <EOL> def supports_transactions ( self ) : <EOL> return False <EOL> class DatabaseWrapper ( BaseDatabaseWrapper ) : <EOL> operators = { } <EOL> _commit = ignore <EOL> _rollback = ignore <EOL> autocommit = None <EOL> def __init__ ( self , settings_dict , alias = None , * args , ** kwargs ) : <EOL> super ( DatabaseWrapper , self ) . __init__ ( <EOL> settings_dict , <EOL> alias = alias , <EOL> * args , <EOL> ** kwargs <EOL> ) <EOL> if settings_dict [ '<STR_LIT>' ] : <EOL> kwargs [ '<STR_LIT:host>' ] = settings_dict [ '<STR_LIT>' ] <EOL> if settings_dict [ '<STR_LIT>' ] : <EOL> kwargs [ '<STR_LIT:port>' ] = int ( settings_dict [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in settings_dict : <EOL> kwargs . update ( settings_dict [ '<STR_LIT>' ] ) <EOL> self . connection = ConnectionWrapper ( ** kwargs ) <EOL> try : <EOL> self . features = DatabaseFeatures ( self . connection ) <EOL> except TypeError : <EOL> self . features = BaseDatabaseFeatures ( ) <EOL> try : <EOL> self . ops = DatabaseOperations ( self . connection ) <EOL> except TypeError : <EOL> self . ops = DatabaseOperations ( ) <EOL> self . client = DatabaseClient ( self ) <EOL> self . creation = DatabaseCreation ( self ) <EOL> self . introspection = DatabaseIntrospection ( self ) <EOL> try : <EOL> self . validation = BaseDatabaseValidation ( self ) <EOL> except TypeError : <EOL> self . validation = BaseDatabaseValidation ( ) <EOL> settings_dict [ '<STR_LIT>' ] = False <EOL> self . settings_dict = settings_dict <EOL> self . alias = alias and alias or settings_dict [ '<STR_LIT>' ] <EOL> self . transaction_state = None <EOL> def close ( self ) : <EOL> pass <EOL> class ConnectionWrapper ( Connection ) : <EOL> autocommit = True <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ConnectionWrapper , self ) . __init__ ( * args , ** kwargs ) <EOL> def __repr__ ( self ) : <EOL> return ( '<STR_LIT>' + <EOL> super ( ConnectionWrapper , self ) . __repr__ ( ) ) </s>
