<s> """<STR_LIT>""" <EOL> from django . contrib . gis . gdal import DataSource <EOL> from django . contrib . gis . gdal . field import ( <EOL> OFTDate , OFTDateTime , OFTInteger , OFTInteger64 , OFTReal , OFTString , <EOL> OFTTime , <EOL> ) <EOL> from django . utils import six <EOL> from django . utils . six . moves import zip <EOL> def mapping ( data_source , geom_name = '<STR_LIT>' , layer_key = <NUM_LIT:0> , multi_geom = False ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data_source , six . string_types ) : <EOL> data_source = DataSource ( data_source ) <EOL> elif isinstance ( data_source , DataSource ) : <EOL> pass <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> _mapping = { } <EOL> for field in data_source [ layer_key ] . fields : <EOL> mfield = field . lower ( ) <EOL> if mfield [ - <NUM_LIT:1> : ] == '<STR_LIT:_>' : <EOL> mfield += '<STR_LIT>' <EOL> _mapping [ mfield ] = field <EOL> gtype = data_source [ layer_key ] . geom_type <EOL> if multi_geom : <EOL> gtype . to_multi ( ) <EOL> _mapping [ geom_name ] = str ( gtype ) . upper ( ) <EOL> return _mapping <EOL> def ogrinspect ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:\n>' . join ( s for s in _ogrinspect ( * args , ** kwargs ) ) <EOL> def _ogrinspect ( data_source , model_name , geom_name = '<STR_LIT>' , layer_key = <NUM_LIT:0> , srid = None , <EOL> multi_geom = False , name_field = None , imports = True , <EOL> decimal = False , blank = False , null = False ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data_source , six . string_types ) : <EOL> data_source = DataSource ( data_source ) <EOL> elif isinstance ( data_source , DataSource ) : <EOL> pass <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> layer = data_source [ layer_key ] <EOL> ogr_fields = layer . fields <EOL> def process_kwarg ( kwarg ) : <EOL> if isinstance ( kwarg , ( list , tuple ) ) : <EOL> return [ s . lower ( ) for s in kwarg ] <EOL> elif kwarg : <EOL> return [ s . lower ( ) for s in ogr_fields ] <EOL> else : <EOL> return [ ] <EOL> null_fields = process_kwarg ( null ) <EOL> blank_fields = process_kwarg ( blank ) <EOL> decimal_fields = process_kwarg ( decimal ) <EOL> def get_kwargs_str ( field_name ) : <EOL> kwlist = [ ] <EOL> if field_name . lower ( ) in null_fields : <EOL> kwlist . append ( '<STR_LIT>' ) <EOL> if field_name . lower ( ) in blank_fields : <EOL> kwlist . append ( '<STR_LIT>' ) <EOL> if kwlist : <EOL> return '<STR_LIT:U+002CU+0020>' + '<STR_LIT:U+002CU+0020>' . join ( kwlist ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> if imports : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % model_name <EOL> for field_name , width , precision , field_type in zip ( <EOL> ogr_fields , layer . field_widths , layer . field_precisions , layer . field_types ) : <EOL> mfield = field_name . lower ( ) <EOL> if mfield [ - <NUM_LIT:1> : ] == '<STR_LIT:_>' : <EOL> mfield += '<STR_LIT>' <EOL> kwargs_str = get_kwargs_str ( field_name ) <EOL> if field_type is OFTReal : <EOL> if field_name . lower ( ) in decimal_fields : <EOL> yield '<STR_LIT>' % ( <EOL> mfield , width , precision , kwargs_str <EOL> ) <EOL> else : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> elif field_type is OFTInteger : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> elif field_type is OFTInteger64 : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> elif field_type is OFTString : <EOL> yield '<STR_LIT>' % ( mfield , width , kwargs_str ) <EOL> elif field_type is OFTDate : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> elif field_type is OFTDateTime : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> elif field_type is OFTTime : <EOL> yield '<STR_LIT>' % ( mfield , kwargs_str [ <NUM_LIT:2> : ] ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' % ( field_type , mfield ) ) <EOL> gtype = layer . geom_type <EOL> if multi_geom : <EOL> gtype . to_multi ( ) <EOL> geom_field = gtype . django <EOL> if srid is None : <EOL> if layer . srs is None : <EOL> srid_str = '<STR_LIT>' <EOL> else : <EOL> srid = layer . srs . srid <EOL> if srid is None : <EOL> srid_str = '<STR_LIT>' <EOL> elif srid == <NUM_LIT> : <EOL> srid_str = '<STR_LIT>' <EOL> else : <EOL> srid_str = '<STR_LIT>' % srid <EOL> else : <EOL> srid_str = '<STR_LIT>' % srid <EOL> yield '<STR_LIT>' % ( geom_name , geom_field , srid_str ) <EOL> if name_field : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' % ( <EOL> '<STR_LIT:str>' if six . PY3 else '<STR_LIT>' , name_field ) </s>
