<s> """<STR_LIT>""" <EOL> from django . db . backends import * <EOL> from django . db . backends . postgresql . client import DatabaseClient <EOL> from django . db . backends . postgresql . creation import DatabaseCreation <EOL> from django . db . backends . postgresql . introspection import DatabaseIntrospection <EOL> from django . db . backends . postgresql . operations import DatabaseOperations <EOL> from django . db . backends . postgresql . version import get_version <EOL> from django . utils . encoding import smart_str , smart_unicode <EOL> try : <EOL> import psycopg as Database <EOL> except ImportError , e : <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> raise ImproperlyConfigured ( "<STR_LIT>" % e ) <EOL> DatabaseError = Database . DatabaseError <EOL> IntegrityError = Database . IntegrityError <EOL> class UnicodeCursorWrapper ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , cursor , charset ) : <EOL> self . cursor = cursor <EOL> self . charset = charset <EOL> def format_params ( self , params ) : <EOL> if isinstance ( params , dict ) : <EOL> result = { } <EOL> charset = self . charset <EOL> for key , value in params . items ( ) : <EOL> result [ smart_str ( key , charset ) ] = smart_str ( value , charset ) <EOL> return result <EOL> else : <EOL> return tuple ( [ smart_str ( p , self . charset , True ) for p in params ] ) <EOL> def execute ( self , sql , params = ( ) ) : <EOL> return self . cursor . execute ( smart_str ( sql , self . charset ) , self . format_params ( params ) ) <EOL> def executemany ( self , sql , param_list ) : <EOL> new_param_list = [ self . format_params ( params ) for params in param_list ] <EOL> return self . cursor . executemany ( sql , new_param_list ) <EOL> def __getattr__ ( self , attr ) : <EOL> if attr in self . __dict__ : <EOL> return self . __dict__ [ attr ] <EOL> else : <EOL> return getattr ( self . cursor , attr ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . cursor ) <EOL> class DatabaseFeatures ( BaseDatabaseFeatures ) : <EOL> uses_savepoints = True <EOL> class DatabaseWrapper ( BaseDatabaseWrapper ) : <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 . features = DatabaseFeatures ( ) <EOL> self . ops = DatabaseOperations ( ) <EOL> self . client = DatabaseClient ( ) <EOL> self . creation = DatabaseCreation ( self ) <EOL> self . introspection = DatabaseIntrospection ( self ) <EOL> self . validation = BaseDatabaseValidation ( ) <EOL> def _cursor ( self , settings ) : <EOL> set_tz = False <EOL> if self . connection is None : <EOL> set_tz = True <EOL> if settings . DATABASE_NAME == '<STR_LIT>' : <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> raise ImproperlyConfigured ( "<STR_LIT>" ) <EOL> conn_string = "<STR_LIT>" % settings . DATABASE_NAME <EOL> if settings . DATABASE_USER : <EOL> conn_string = "<STR_LIT>" % ( settings . DATABASE_USER , conn_string ) <EOL> if settings . DATABASE_PASSWORD : <EOL> conn_string += "<STR_LIT>" % settings . DATABASE_PASSWORD <EOL> if settings . DATABASE_HOST : <EOL> conn_string += "<STR_LIT>" % settings . DATABASE_HOST <EOL> if settings . DATABASE_PORT : <EOL> conn_string += "<STR_LIT>" % settings . DATABASE_PORT <EOL> self . connection = Database . connect ( conn_string , ** self . options ) <EOL> self . connection . set_isolation_level ( <NUM_LIT:1> ) <EOL> cursor = self . connection . cursor ( ) <EOL> if set_tz : <EOL> cursor . execute ( "<STR_LIT>" , [ settings . TIME_ZONE ] ) <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> self . __class__ . _version = get_version ( cursor ) <EOL> if self . _version < ( <NUM_LIT:8> , <NUM_LIT:0> ) : <EOL> self . features . uses_savepoints = False <EOL> cursor . execute ( "<STR_LIT>" ) <EOL> cursor = UnicodeCursorWrapper ( cursor , '<STR_LIT:utf-8>' ) <EOL> return cursor <EOL> def typecast_string ( s ) : <EOL> """<STR_LIT>""" <EOL> if not s and not isinstance ( s , str ) : <EOL> return s <EOL> return smart_unicode ( s ) <EOL> try : <EOL> Database . register_type ( Database . new_type ( ( <NUM_LIT> , ) , "<STR_LIT>" , util . typecast_date ) ) <EOL> except AttributeError : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> Database . register_type ( Database . new_type ( ( <NUM_LIT> , <NUM_LIT> ) , "<STR_LIT>" , util . typecast_time ) ) <EOL> Database . register_type ( Database . new_type ( ( <NUM_LIT> , <NUM_LIT> ) , "<STR_LIT>" , util . typecast_timestamp ) ) <EOL> Database . register_type ( Database . new_type ( ( <NUM_LIT:16> , ) , "<STR_LIT>" , util . typecast_boolean ) ) <EOL> Database . register_type ( Database . new_type ( ( <NUM_LIT> , ) , "<STR_LIT>" , util . typecast_decimal ) ) <EOL> Database . register_type ( Database . new_type ( Database . types [ <NUM_LIT> ] . values , '<STR_LIT>' , typecast_string ) ) </s>
