<s> from data_importer . readers . xls_reader import XLSReader <EOL> from data_importer . readers . xlsx_reader import XLSXReader <EOL> from data_importer . readers . csv_reader import CSVReader <EOL> from data_importer . readers . xml_reader import XMLReader <EOL> from data_importer . core . exceptions import UnsuportedFile <EOL> from . base import BaseImporter <EOL> class GenericImporter ( BaseImporter ) : <EOL> """<STR_LIT>""" <EOL> def set_reader ( self ) : <EOL> reader = self . get_reader_class ( ) <EOL> extra_values = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : True , '<STR_LIT>' : True } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : self . Meta . sheet_name or None , '<STR_LIT>' : self . Meta . sheet_index or <NUM_LIT:0> } , <EOL> '<STR_LIT>' : { '<STR_LIT>' : self . Meta . delimiter or '<STR_LIT:;>' } , <EOL> '<STR_LIT>' : { } , <EOL> } <EOL> selected_extra_values = extra_values [ self . get_source_file_extension ( ) ] <EOL> self . _reader = reader ( self , ** selected_extra_values ) <EOL> def get_reader_class ( self ) : <EOL> """<STR_LIT>""" <EOL> readers = { <EOL> '<STR_LIT>' : XLSReader , <EOL> '<STR_LIT>' : XLSXReader , <EOL> '<STR_LIT>' : XMLReader , <EOL> '<STR_LIT>' : CSVReader , <EOL> } <EOL> source_file_extension = self . get_source_file_extension ( ) <EOL> if source_file_extension not in readers . keys ( ) : <EOL> raise UnsuportedFile ( "<STR_LIT>" ) <EOL> return readers [ source_file_extension ] <EOL> def get_source_file_extension ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . source , '<STR_LIT:file>' ) and hasattr ( self . source . file , '<STR_LIT:name>' ) : <EOL> filename = self . source . file . name <EOL> elif hasattr ( self . source , '<STR_LIT>' ) : <EOL> if hasattr ( self . source . file_upload , '<STR_LIT:name>' ) : <EOL> filename = self . source . file_upload . name <EOL> else : <EOL> filename = self . source . file_upload <EOL> elif hasattr ( self . source , '<STR_LIT:name>' ) : <EOL> filename = self . source . name <EOL> else : <EOL> filename = self . source <EOL> ext = filename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> return ext . lower ( ) </s>
