<s> import os <EOL> from django . conf import settings <EOL> from django . core import signals <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . utils . functional import curry <EOL> from django . utils . importlib import import_module <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not settings . DATABASE_ENGINE : <EOL> settings . DATABASE_ENGINE = '<STR_LIT>' <EOL> def load_backend ( backend_name ) : <EOL> try : <EOL> return import_module ( '<STR_LIT>' , '<STR_LIT>' % backend_name ) <EOL> except ImportError , e : <EOL> try : <EOL> return import_module ( '<STR_LIT>' , backend_name ) <EOL> except ImportError , e_user : <EOL> backend_dir = os . path . join ( __path__ [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> try : <EOL> available_backends = [ f for f in os . listdir ( backend_dir ) <EOL> if os . path . isdir ( os . path . join ( backend_dir , f ) ) <EOL> and not f . startswith ( '<STR_LIT:.>' ) ] <EOL> except EnvironmentError : <EOL> available_backends = [ ] <EOL> available_backends . sort ( ) <EOL> if backend_name not in available_backends : <EOL> error_msg = "<STR_LIT>" % ( backend_name , "<STR_LIT:U+002CU+0020>" . join ( map ( repr , available_backends ) ) , e_user ) <EOL> raise ImproperlyConfigured ( error_msg ) <EOL> else : <EOL> raise <EOL> backend = load_backend ( settings . DATABASE_ENGINE ) <EOL> connection = backend . DatabaseWrapper ( { <EOL> '<STR_LIT>' : settings . DATABASE_HOST , <EOL> '<STR_LIT>' : settings . DATABASE_NAME , <EOL> '<STR_LIT>' : settings . DATABASE_OPTIONS , <EOL> '<STR_LIT>' : settings . DATABASE_PASSWORD , <EOL> '<STR_LIT>' : settings . DATABASE_PORT , <EOL> '<STR_LIT>' : settings . DATABASE_USER , <EOL> '<STR_LIT>' : settings . TIME_ZONE , <EOL> } ) <EOL> DatabaseError = backend . DatabaseError <EOL> IntegrityError = backend . IntegrityError <EOL> def close_connection ( ** kwargs ) : <EOL> connection . close ( ) <EOL> signals . request_finished . connect ( close_connection ) <EOL> def reset_queries ( ** kwargs ) : <EOL> connection . queries = [ ] <EOL> signals . request_started . connect ( reset_queries ) <EOL> def _rollback_on_exception ( ** kwargs ) : <EOL> from django . db import transaction <EOL> try : <EOL> transaction . rollback_unless_managed ( ) <EOL> except DatabaseError : <EOL> pass <EOL> signals . got_request_exception . connect ( _rollback_on_exception ) </s>
