class ReadExcelFileMemory(InputSource): """Pick up 'file_type' and read a sheet from memory""" fields = [params.FILE_TYPE] targets = (constants.SHEET, constants.BOOK) actions = (constants.READ_ACTION, ) attributes = PARSER.get_all_file_types() key = params.FILE_TYPE def __init__(self, file_content=None, file_type=None, file_stream=None, **keywords): self.__file_type = file_type self.__file_stream = file_stream self.__file_content = file_content self.__parser = PARSER.get_a_plugin(file_type) InputSource.__init__(self, **keywords) def get_data(self): if self.__file_stream is not None: sheets = self.__parser.parse_file_stream(self.__file_stream, **self._keywords) else: sheets = self.__parser.parse_file_content(self.__file_content, **self._keywords) return sheets def get_source_info(self): return params.MEMORY, None
def __init__(self, file_name=None, parser_library=None, **keywords): self.__file_name = file_name if "force_file_type" in keywords: file_type = keywords.get("force_file_type") else: file_type = self.__file_name.split(".")[-1] self.__parser = PARSER.get_a_plugin(file_type, parser_library) AbstractSource.__init__(self, **keywords)
def can_i_handle(cls, action, file_type): __file_type = None if file_type: __file_type = file_type.lower() if action == constants.READ_ACTION: status = __file_type in PARSER.get_all_file_types() else: status = False return status
def get_data(self): aparser = PARSER.get_a_plugin(self._db_type, self.__parser_library) export_params = self.get_export_params() data = aparser.parse_file_stream( export_params, export_columns_list=[self.__export_columns], **self._keywords) if self.__sheet_name is not None: _set_dictionary_key(data, self.__sheet_name) return data
def __init__(self, file_content=None, file_type=None, file_stream=None, **keywords): self.__file_type = file_type self.__file_stream = file_stream self.__file_content = file_content self.__parser = PARSER.get_a_plugin(file_type) InputSource.__init__(self, **keywords)
def __init__(self, file_content=None, file_type=None, file_stream=None, parser_library=None, **keywords): self.__file_type = file_type self.__file_stream = file_stream self.__file_content = file_content self.__parser = PARSER.get_a_plugin(file_type, parser_library) AbstractSource.__init__(self, **keywords)
def get_data(self): connection = request.urlopen(self.__url) info = connection.info() if PY2: mime_type = info.type else: mime_type = info.get_content_type() file_type = FILE_TYPE_MIME_TABLE.get(mime_type, None) if file_type is None: file_type = _get_file_type_from_url(self.__url) parser_library = self._keywords.get("parser_library", None) aparser = PARSER.get_a_plugin(file_type, parser_library) sheets = aparser.parse_file_stream(connection, **self._keywords) return sheets
def get_data(self): connection = request.urlopen(self.__url) info = connection.info() if PY2: mime_type = info.type else: mime_type = info.get_content_type() file_type = FILE_TYPE_MIME_TABLE.get(mime_type, None) if file_type is None: file_type = _get_file_type_from_url(self.__url) parser_library = self._keywords.get('parser_library', None) aparser = PARSER.get_a_plugin(file_type, parser_library) sheets = aparser.parse_file_stream(connection, **self._keywords) return sheets
def _find_file_type_from_file_name(file_name, action): if action == 'read': list_of_file_types = PARSER.get_all_file_types() else: list_of_file_types = RENDERER.get_all_file_types() file_types = [] lowercase_file_name = file_name.lower() for a_supported_type in list_of_file_types: if lowercase_file_name.endswith(a_supported_type): file_types.append(a_supported_type) if len(file_types) > 1: file_types = sorted(file_types, key=lambda x: len(x)) file_type = file_types[-1] elif len(file_types) == 1: file_type = file_types[0] else: file_type = lowercase_file_name.split('.')[-1] raise FileTypeNotSupported( constants.FILE_TYPE_NOT_SUPPORTED_FMT % (file_type, action)) return file_type
def get_data(self): aparser = PARSER.get_a_plugin(self.__db_type, self.__parser_library) export_params = self.get_params() data = aparser.parse_file_stream(export_params, **self._keywords) return data
def __init__(self, file_name=None, **keywords): self.__file_name = file_name file_type = self.__file_name.split('.')[-1] self.__parser = PARSER.get_a_plugin(file_type) InputSource.__init__(self, **keywords)
def __init__(self, file_name=None, parser_library=None, **keywords): self.__file_name = file_name file_type = self.__file_name.split('.')[-1] self.__parser = PARSER.get_a_plugin(file_type, parser_library) AbstractSource.__init__(self, **keywords)