<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> from django . db import utils <EOL> from django . db . backends import * <EOL> from django . db . backends . signals import connection_created <EOL> from django . db . backends . sqlite3 . client import DatabaseClient <EOL> from django . db . backends . sqlite3 . creation import DatabaseCreation <EOL> from django . db . backends . sqlite3 . introspection import DatabaseIntrospection <EOL> from django . utils . safestring import SafeString <EOL> try : <EOL> try : <EOL> from pysqlite2 import dbapi2 as Database <EOL> except ImportError , e1 : <EOL> from sqlite3 import dbapi2 as Database <EOL> except ImportError , exc : <EOL> import sys <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:0> ) : <EOL> module = '<STR_LIT>' <EOL> exc = e1 <EOL> else : <EOL> module = '<STR_LIT>' <EOL> raise ImproperlyConfigured ( "<STR_LIT>" % ( module , exc ) ) <EOL> DatabaseError = Database . DatabaseError <EOL> IntegrityError = Database . IntegrityError <EOL> Database . register_converter ( "<STR_LIT:bool>" , lambda s : str ( s ) == '<STR_LIT:1>' ) <EOL> Database . register_converter ( "<STR_LIT:time>" , util . typecast_time ) <EOL> Database . register_converter ( "<STR_LIT:date>" , util . typecast_date ) <EOL> Database . register_converter ( "<STR_LIT>" , util . typecast_timestamp ) <EOL> Database . register_converter ( "<STR_LIT>" , util . typecast_timestamp ) <EOL> Database . register_converter ( "<STR_LIT>" , util . typecast_timestamp ) <EOL> Database . register_converter ( "<STR_LIT>" , util . typecast_decimal ) <EOL> Database . register_adapter ( decimal . Decimal , util . rev_typecast_decimal ) <EOL> if Database . version_info >= ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:1> ) : <EOL> Database . register_adapter ( str , lambda s : s . decode ( '<STR_LIT:utf-8>' ) ) <EOL> Database . register_adapter ( SafeString , lambda s : s . decode ( '<STR_LIT:utf-8>' ) ) <EOL> class DatabaseFeatures ( BaseDatabaseFeatures ) : <EOL> can_use_chunked_reads = False <EOL> class DatabaseOperations ( BaseDatabaseOperations ) : <EOL> def date_extract_sql ( self , lookup_type , field_name ) : <EOL> return "<STR_LIT>" % ( lookup_type . lower ( ) , field_name ) <EOL> def date_trunc_sql ( self , lookup_type , field_name ) : <EOL> return "<STR_LIT>" % ( lookup_type . lower ( ) , field_name ) <EOL> def drop_foreignkey_sql ( self ) : <EOL> return "<STR_LIT>" <EOL> def pk_default_value ( self ) : <EOL> return '<STR_LIT>' <EOL> def quote_name ( self , name ) : <EOL> if name . startswith ( '<STR_LIT:">' ) and name . endswith ( '<STR_LIT:">' ) : <EOL> return name <EOL> return '<STR_LIT>' % name <EOL> def no_limit_value ( self ) : <EOL> return - <NUM_LIT:1> <EOL> def sql_flush ( self , style , tables , sequences ) : <EOL> sql = [ '<STR_LIT>' % ( style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_KEYWORD ( '<STR_LIT>' ) , <EOL> style . SQL_FIELD ( self . quote_name ( table ) ) <EOL> ) for table in tables ] <EOL> return sql <EOL> def year_lookup_bounds ( self , value ) : <EOL> first = '<STR_LIT>' <EOL> second = '<STR_LIT>' <EOL> return [ first % value , second % value ] <EOL> def convert_values ( self , value , field ) : <EOL> """<STR_LIT>""" <EOL> internal_type = field . get_internal_type ( ) <EOL> if internal_type == '<STR_LIT>' : <EOL> return util . typecast_decimal ( field . format_number ( value ) ) <EOL> elif internal_type and internal_type . endswith ( '<STR_LIT>' ) or internal_type == '<STR_LIT>' : <EOL> return int ( value ) <EOL> elif internal_type == '<STR_LIT>' : <EOL> return util . typecast_date ( value ) <EOL> elif internal_type == '<STR_LIT>' : <EOL> return util . typecast_timestamp ( value ) <EOL> elif internal_type == '<STR_LIT>' : <EOL> return util . typecast_time ( value ) <EOL> return value <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 ( self ) <EOL> self . creation = DatabaseCreation ( self ) <EOL> self . introspection = DatabaseIntrospection ( self ) <EOL> self . validation = BaseDatabaseValidation ( self ) <EOL> def _cursor ( self ) : <EOL> if self . connection is None : <EOL> settings_dict = self . settings_dict <EOL> if not settings_dict [ '<STR_LIT>' ] : <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> raise ImproperlyConfigured ( "<STR_LIT>" ) <EOL> kwargs = { <EOL> '<STR_LIT>' : settings_dict [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : Database . PARSE_DECLTYPES | Database . PARSE_COLNAMES , <EOL> } <EOL> kwargs . update ( settings_dict [ '<STR_LIT>' ] ) <EOL> self . connection = Database . connect ( ** kwargs ) <EOL> self . connection . create_function ( "<STR_LIT>" , <NUM_LIT:2> , _sqlite_extract ) <EOL> self . connection . create_function ( "<STR_LIT>" , <NUM_LIT:2> , _sqlite_date_trunc ) <EOL> self . connection . create_function ( "<STR_LIT>" , <NUM_LIT:2> , _sqlite_regexp ) <EOL> connection_created . send ( sender = self . __class__ , connection = self ) <EOL> return self . connection . cursor ( factory = SQLiteCursorWrapper ) <EOL> def close ( self ) : <EOL> if self . settings_dict [ '<STR_LIT>' ] != "<STR_LIT>" : <EOL> BaseDatabaseWrapper . close ( self ) <EOL> FORMAT_QMARK_REGEX = re . compile ( r'<STR_LIT>' ) <EOL> class SQLiteCursorWrapper ( Database . Cursor ) : <EOL> """<STR_LIT>""" <EOL> def execute ( self , query , params = ( ) ) : <EOL> query = self . convert_query ( query ) <EOL> try : <EOL> return Database . Cursor . execute ( self , query , params ) <EOL> except Database . IntegrityError , e : <EOL> raise utils . IntegrityError , utils . IntegrityError ( * tuple ( e ) ) , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> except Database . DatabaseError , e : <EOL> raise utils . DatabaseError , utils . DatabaseError ( * tuple ( e ) ) , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> def executemany ( self , query , param_list ) : <EOL> query = self . convert_query ( query ) <EOL> try : <EOL> return Database . Cursor . executemany ( self , query , param_list ) <EOL> except Database . IntegrityError , e : <EOL> raise utils . IntegrityError , utils . IntegrityError ( * tuple ( e ) ) , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> except Database . DatabaseError , e : <EOL> raise utils . DatabaseError , utils . DatabaseError ( * tuple ( e ) ) , sys . exc_info ( ) [ <NUM_LIT:2> ] <EOL> def convert_query ( self , query ) : <EOL> return FORMAT_QMARK_REGEX . sub ( '<STR_LIT:?>' , query ) . replace ( '<STR_LIT>' , '<STR_LIT:%>' ) <EOL> def _sqlite_extract ( lookup_type , dt ) : <EOL> if dt is None : <EOL> return None <EOL> try : <EOL> dt = util . typecast_timestamp ( dt ) <EOL> except ( ValueError , TypeError ) : <EOL> return None <EOL> if lookup_type == '<STR_LIT>' : <EOL> return ( dt . isoweekday ( ) % <NUM_LIT:7> ) + <NUM_LIT:1> <EOL> else : <EOL> return getattr ( dt , lookup_type ) <EOL> def _sqlite_date_trunc ( lookup_type , dt ) : <EOL> try : <EOL> dt = util . typecast_timestamp ( dt ) <EOL> except ( ValueError , TypeError ) : <EOL> return None <EOL> if lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % dt . year <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % ( dt . year , dt . month ) <EOL> elif lookup_type == '<STR_LIT>' : <EOL> return "<STR_LIT>" % ( dt . year , dt . month , dt . day ) <EOL> def _sqlite_regexp ( re_pattern , re_string ) : <EOL> import re <EOL> try : <EOL> return bool ( re . search ( re_pattern , re_string ) ) <EOL> except : <EOL> return False </s>
