<s> import re <EOL> from collections import OrderedDict <EOL> from . schema_manager import SchemaManager <EOL> from . column import Column <EOL> from . foreign_key_constraint import ForeignKeyConstraint <EOL> class SQLiteSchemaManager ( SchemaManager ) : <EOL> def _get_portable_table_column_definition ( self , table_column ) : <EOL> parts = table_column [ '<STR_LIT:type>' ] . split ( '<STR_LIT:(>' ) <EOL> table_column [ '<STR_LIT:type>' ] = parts [ <NUM_LIT:0> ] <EOL> if len ( parts ) > <NUM_LIT:1> : <EOL> length = parts [ <NUM_LIT:1> ] . strip ( '<STR_LIT:)>' ) <EOL> table_column [ '<STR_LIT>' ] = length <EOL> db_type = table_column [ '<STR_LIT:type>' ] . lower ( ) <EOL> length = table_column . get ( '<STR_LIT>' , None ) <EOL> unsigned = False <EOL> if '<STR_LIT>' in db_type : <EOL> db_type = db_type . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> unsigned = True <EOL> fixed = False <EOL> type = self . _platform . get_type_mapping ( db_type ) <EOL> default = table_column [ '<STR_LIT>' ] <EOL> if default == '<STR_LIT>' : <EOL> default = None <EOL> if default is not None : <EOL> default = re . sub ( "<STR_LIT>" , '<STR_LIT>' , default ) <EOL> notnull = bool ( table_column [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT:name>' not in table_column : <EOL> table_column [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> precision = None <EOL> scale = None <EOL> if db_type in [ '<STR_LIT>' ] : <EOL> fixed = True <EOL> elif db_type in [ '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if '<STR_LIT>' in table_column : <EOL> if '<STR_LIT:U+002C>' not in table_column [ '<STR_LIT>' ] : <EOL> table_column [ '<STR_LIT>' ] += '<STR_LIT>' <EOL> precision , scale = tuple ( map ( lambda x : x . strip ( ) , table_column [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> length = None <EOL> options = { <EOL> '<STR_LIT>' : length , <EOL> '<STR_LIT>' : bool ( unsigned ) , <EOL> '<STR_LIT>' : fixed , <EOL> '<STR_LIT>' : notnull , <EOL> '<STR_LIT:default>' : default , <EOL> '<STR_LIT>' : precision , <EOL> '<STR_LIT>' : scale , <EOL> '<STR_LIT>' : False <EOL> } <EOL> column = Column ( table_column [ '<STR_LIT:name>' ] , type , options ) <EOL> column . set_platform_option ( '<STR_LIT>' , table_column [ '<STR_LIT>' ] ) <EOL> return column <EOL> def _get_portable_table_indexes_list ( self , table_indexes , table_name ) : <EOL> index_buffer = [ ] <EOL> info = self . _connection . select ( '<STR_LIT>' % table_name ) <EOL> for row in info : <EOL> if row [ '<STR_LIT>' ] != <NUM_LIT:0> : <EOL> index_buffer . append ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : row [ '<STR_LIT:name>' ] <EOL> } ) <EOL> for index in table_indexes : <EOL> if index [ '<STR_LIT:name>' ] . find ( '<STR_LIT>' ) == - <NUM_LIT:1> : <EOL> key_name = index [ '<STR_LIT:name>' ] <EOL> idx = { <EOL> '<STR_LIT>' : key_name , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : not bool ( index [ '<STR_LIT>' ] ) <EOL> } <EOL> info = self . _connection . select ( '<STR_LIT>' % key_name ) <EOL> for row in info : <EOL> idx [ '<STR_LIT>' ] = row [ '<STR_LIT:name>' ] <EOL> index_buffer . append ( idx ) <EOL> return super ( SQLiteSchemaManager , self ) . _get_portable_table_indexes_list ( index_buffer , table_name ) <EOL> def _get_portable_table_foreign_keys_list ( self , table_foreign_keys ) : <EOL> foreign_keys = OrderedDict ( ) <EOL> for value in table_foreign_keys : <EOL> value = dict ( ( k . lower ( ) , v ) for k , v in value . items ( ) ) <EOL> name = value . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if name not in foreign_keys : <EOL> if '<STR_LIT>' not in value or value [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> value [ '<STR_LIT>' ] = None <EOL> if '<STR_LIT>' not in value or value [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> value [ '<STR_LIT>' ] = None <EOL> foreign_keys [ name ] = { <EOL> '<STR_LIT:name>' : name , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : value [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : value [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : value [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : value . get ( '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' : value . get ( '<STR_LIT>' , False ) <EOL> } <EOL> foreign_keys [ name ] [ '<STR_LIT>' ] . append ( value [ '<STR_LIT>' ] ) <EOL> foreign_keys [ name ] [ '<STR_LIT>' ] . append ( value [ '<STR_LIT:to>' ] ) <EOL> result = [ ] <EOL> for constraint in foreign_keys . values ( ) : <EOL> result . append ( <EOL> ForeignKeyConstraint ( <EOL> constraint [ '<STR_LIT>' ] , constraint [ '<STR_LIT>' ] , <EOL> constraint [ '<STR_LIT>' ] , constraint [ '<STR_LIT:name>' ] , <EOL> { <EOL> '<STR_LIT>' : constraint [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : constraint [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : constraint [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : constraint [ '<STR_LIT>' ] <EOL> } <EOL> ) <EOL> ) <EOL> return result </s>
