<s> import re <EOL> import warnings <EOL> from optparse import make_option <EOL> from django . core . management . commands . inspectdb import Command as InspectDBCommand <EOL> from django . db import connections , DEFAULT_DB_ALIAS <EOL> from django . utils import six <EOL> from salesforce . backend import introspection as sf_introspection <EOL> from salesforce import DJANGO_18_PLUS , DJANGO_19_PLUS <EOL> import django <EOL> import salesforce <EOL> from collections import OrderedDict <EOL> def fix_field_params_repr ( params ) : <EOL> """<STR_LIT>""" <EOL> class ReprUnicode ( six . text_type ) : <EOL> def __new__ ( cls , text ) : <EOL> return unicode . __new__ ( cls , text ) <EOL> def __repr__ ( self ) : <EOL> out = repr ( unicode ( self ) ) <EOL> return out [ <NUM_LIT:1> : ] if out . startswith ( "<STR_LIT>" ) or out . startswith ( '<STR_LIT>' ) else out <EOL> class ReprChoices ( list ) : <EOL> def __new__ ( cls , choices ) : <EOL> return list . __new__ ( cls , choices ) <EOL> def __repr__ ( self ) : <EOL> out = [ ] <EOL> for x0 , x1 in self : <EOL> out . append ( '<STR_LIT>' % ( <EOL> repr ( ReprUnicode ( x0 ) if isinstance ( x0 , unicode ) else x0 ) , <EOL> repr ( ReprUnicode ( x1 ) if isinstance ( x1 , unicode ) else x1 ) <EOL> ) ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( out ) ) <EOL> if six . PY3 : <EOL> return params <EOL> out = OrderedDict ( ) <EOL> for k , v in params . items ( ) : <EOL> if k == '<STR_LIT>' and v : <EOL> v = ReprChoices ( v ) <EOL> elif isinstance ( v , unicode ) : <EOL> v = ReprUnicode ( v ) <EOL> out [ k ] = v <EOL> return out <EOL> def fix_international ( text ) : <EOL> "<STR_LIT>" <EOL> class SmartInternational ( str ) : <EOL> def __new__ ( cls , text ) : <EOL> return str . __new__ ( cls , text ) <EOL> def endswith ( self , string ) : <EOL> return super ( SmartInternational , self ) . endswith ( str ( string ) ) <EOL> if six . PY3 : <EOL> return text <EOL> out = [ ] <EOL> last = <NUM_LIT:0> <EOL> for match in re . finditer ( r'<STR_LIT>' , text ) : <EOL> start , end , group = match . start ( ) , match . end ( ) , match . group ( ) <EOL> out . append ( text [ last : start ] ) <EOL> c = group . decode ( '<STR_LIT>' ) <EOL> out . append ( c if ord ( c ) > <NUM_LIT> and ord ( c ) != <NUM_LIT> else group ) <EOL> last = end <EOL> out . append ( text [ last : ] ) <EOL> return SmartInternational ( '<STR_LIT>' . join ( out ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> class Command ( InspectDBCommand ) : <EOL> if DJANGO_18_PLUS : <EOL> def add_arguments ( self , parser ) : <EOL> super ( Command , self ) . add_arguments ( parser ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> else : <EOL> option_list = InspectDBCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> def handle_noargs ( self , ** options ) : <EOL> if isinstance ( options [ '<STR_LIT>' ] , str ) : <EOL> options [ '<STR_LIT>' ] = re . compile ( options [ '<STR_LIT>' ] ) . match <EOL> self . verbosity = int ( options [ '<STR_LIT>' ] ) <EOL> self . connection = connections [ options [ '<STR_LIT>' ] ] <EOL> if self . connection . vendor == '<STR_LIT>' : <EOL> if not six . PY3 : <EOL> self . stdout . write ( "<STR_LIT>" ) <EOL> self . db_module = '<STR_LIT>' <EOL> for line in self . handle_inspection ( options ) : <EOL> line = line . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> line = re . sub ( '<STR_LIT>' , '<STR_LIT>' , line ) <EOL> self . stdout . write ( fix_international ( "<STR_LIT>" % line ) ) <EOL> else : <EOL> if DJANGO_18_PLUS : <EOL> super ( Command , self ) . handle ( ** options ) <EOL> else : <EOL> super ( Command , self ) . handle_noargs ( ** options ) <EOL> if DJANGO_18_PLUS : <EOL> handle = handle_noargs <EOL> del handle_noargs <EOL> def get_field_type ( self , connection , table_name , row ) : <EOL> field_type , field_params , field_notes = super ( Command , self <EOL> ) . get_field_type ( connection , table_name , row ) <EOL> if connection . vendor == '<STR_LIT>' : <EOL> name , type_code , display_size , internal_size , precision , scale , null_ok , sf_params = row <EOL> if '<STR_LIT>' in sf_params : <EOL> field_notes . append ( sf_params . pop ( '<STR_LIT>' ) ) <EOL> field_params . update ( sf_params ) <EOL> return field_type , fix_field_params_repr ( field_params ) , field_notes <EOL> def normalize_col_name ( self , col_name , used_column_names , is_relation ) : <EOL> if self . connection . vendor == '<STR_LIT>' : <EOL> beautified = re . sub ( '<STR_LIT>' , '<STR_LIT>' , col_name ) <EOL> beautified = re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , beautified ) <EOL> beautified = beautified . lower ( ) <EOL> new_name , field_params , field_notes = super ( Command , self <EOL> ) . normalize_col_name ( beautified , used_column_names , is_relation ) <EOL> field_params = OrderedDict ( sorted ( field_params . items ( ) ) ) <EOL> reconstructed = new_name . title ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> if col_name . endswith ( '<STR_LIT>' ) : <EOL> reconstructed += '<STR_LIT>' <EOL> field_params [ '<STR_LIT>' ] = True <EOL> elif is_relation : <EOL> reconstructed += '<STR_LIT>' <EOL> if reconstructed != col_name or self . verbosity >= <NUM_LIT:2> : <EOL> field_params [ '<STR_LIT>' ] = col_name <EOL> else : <EOL> field_params . pop ( '<STR_LIT>' , None ) <EOL> if is_relation : <EOL> if col_name in sf_introspection . last_with_important_related_name : <EOL> field_params [ '<STR_LIT:related_name>' ] = '<STR_LIT>' % ( <EOL> sf_introspection . last_introspected_model . lower ( ) , <EOL> new_name . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> ) <EOL> if col_name in sf_introspection . last_read_only : <EOL> field_params [ '<STR_LIT>' ] = sf_introspection . last_read_only [ col_name ] <EOL> if not DJANGO_19_PLUS : <EOL> field_params [ '<STR_LIT>' ] = sf_introspection . SymbolicModelsName ( '<STR_LIT>' ) <EOL> reference_to , relationship_order = sf_introspection . last_refs [ col_name ] <EOL> if len ( reference_to ) > <NUM_LIT:1> : <EOL> field_notes . append ( '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( reference_to ) ) ) <EOL> if relationship_order is not None : <EOL> field_notes . append ( '<STR_LIT>' % relationship_order ) <EOL> else : <EOL> new_name , field_params , field_notes = super ( Command , self <EOL> ) . normalize_col_name ( col_name , used_column_names , is_relation ) <EOL> return new_name , fix_field_params_repr ( field_params ) , field_notes <EOL> def get_meta ( self , table_name , constraints = None , column_to_field_name = None ) : <EOL> """<STR_LIT>""" <EOL> meta = [ "<STR_LIT>" , <EOL> "<STR_LIT>" % table_name ] <EOL> if self . connection . vendor == '<STR_LIT>' : <EOL> for line in self . connection . introspection . get_additional_meta ( table_name ) : <EOL> meta . append ( "<STR_LIT:U+0020>" + line ) <EOL> meta . append ( "<STR_LIT>" ) <EOL> return meta </s>
