<s> import re <EOL> from collections import OrderedDict <EOL> from . column import Column <EOL> from . foreign_key_constraint import ForeignKeyConstraint <EOL> from . schema_manager import SchemaManager <EOL> from . platforms . mysql_platform import MySQLPlatform <EOL> class MySQLSchemaManager ( SchemaManager ) : <EOL> def _get_portable_table_column_definition ( self , table_column ) : <EOL> db_type = table_column [ '<STR_LIT:type>' ] . lower ( ) <EOL> match = re . match ( '<STR_LIT>' , db_type ) <EOL> if match : <EOL> db_type = match . group ( <NUM_LIT:1> ) <EOL> if '<STR_LIT>' in table_column : <EOL> length = table_column [ '<STR_LIT>' ] <EOL> else : <EOL> if match and match . group ( <NUM_LIT:2> ) and '<STR_LIT:U+002C>' not in match . group ( <NUM_LIT:2> ) : <EOL> length = int ( match . group ( <NUM_LIT:2> ) ) <EOL> else : <EOL> length = <NUM_LIT:0> <EOL> fixed = None <EOL> if '<STR_LIT:name>' not in table_column : <EOL> table_column [ '<STR_LIT:name>' ] = '<STR_LIT>' <EOL> precision = None <EOL> scale = None <EOL> type = self . _platform . get_type_mapping ( db_type ) <EOL> if db_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> fixed = True <EOL> elif db_type in [ '<STR_LIT:float>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> match = re . match ( '<STR_LIT>' , table_column [ '<STR_LIT:type>' ] ) <EOL> if match : <EOL> precision = match . group ( <NUM_LIT:1> ) <EOL> scale = match . group ( <NUM_LIT:2> ) <EOL> length = None <EOL> elif db_type == '<STR_LIT>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_TINYTEXT <EOL> elif db_type == '<STR_LIT:text>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_TEXT <EOL> elif db_type == '<STR_LIT>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_MEDIUMTEXT <EOL> elif db_type == '<STR_LIT>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_TINYBLOB <EOL> elif db_type == '<STR_LIT>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_BLOB <EOL> elif db_type == '<STR_LIT>' : <EOL> length = MySQLPlatform . LENGTH_LIMIT_MEDIUMBLOB <EOL> elif db_type in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:int>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> length = None <EOL> if length is None or length == <NUM_LIT:0> : <EOL> length = None <EOL> options = { <EOL> '<STR_LIT>' : length , <EOL> '<STR_LIT>' : table_column [ '<STR_LIT:type>' ] . find ( '<STR_LIT>' ) != - <NUM_LIT:1> , <EOL> '<STR_LIT>' : fixed , <EOL> '<STR_LIT>' : table_column [ '<STR_LIT:null>' ] != '<STR_LIT>' , <EOL> '<STR_LIT:default>' : table_column . get ( '<STR_LIT:default>' ) , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : table_column [ '<STR_LIT>' ] . find ( '<STR_LIT>' ) != - <NUM_LIT:1> <EOL> } <EOL> if scale is not None and precision is not None : <EOL> options [ '<STR_LIT>' ] = scale <EOL> options [ '<STR_LIT>' ] = precision <EOL> column = Column ( table_column [ '<STR_LIT>' ] , type , options ) <EOL> if '<STR_LIT>' in table_column : <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> new = [ ] <EOL> for v in table_indexes : <EOL> v = dict ( ( k . lower ( ) , value ) for k , value in v . items ( ) ) <EOL> if v [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> v [ '<STR_LIT>' ] = True <EOL> else : <EOL> v [ '<STR_LIT>' ] = False <EOL> if '<STR_LIT>' in v [ '<STR_LIT>' ] : <EOL> v [ '<STR_LIT>' ] = { '<STR_LIT>' : True } <EOL> else : <EOL> v [ '<STR_LIT>' ] = { '<STR_LIT>' : True } <EOL> new . append ( v ) <EOL> return super ( MySQLSchemaManager , self ) . _get_portable_table_indexes_list ( new , 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>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in value or value [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> value [ '<STR_LIT>' ] = '<STR_LIT>' <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> } <EOL> foreign_keys [ name ] [ '<STR_LIT>' ] . append ( value [ '<STR_LIT>' ] ) <EOL> foreign_keys [ name ] [ '<STR_LIT>' ] . append ( value [ '<STR_LIT>' ] ) <EOL> result = [ ] <EOL> for constraint in foreign_keys . values ( ) : <EOL> result . append ( 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> } <EOL> ) ) <EOL> return result </s>
