def load(self, in_stream, format=None, **kwargs): """ Import `in_stream` to the :class:`Dataset` object using the `format`. `in_stream` can be a file-like object, a string, or a bytestring. :param \\*\\*kwargs: (optional) custom configuration to the format `import_set`. """ stream = normalize_input(in_stream) if not format: # pythonlibrary.net: # 如果没有提供格式,则尝试自动检测 format = detect_format(stream) fmt = registry.get_format(format) if not hasattr(fmt, 'import_set'): raise UnsupportedFormat( 'Format {} cannot be imported.'.format(format)) if not import_set: # support to pass in the custom import_set function raise UnsupportedFormat( 'Format {} cannot be imported.'.format(format)) fmt.import_set(self, stream, **kwargs) return self
def get_format(self, key): if key not in self._formats: if key in uninstalled_format_messages: raise UnsupportedFormat(uninstalled_format_messages[key]) raise UnsupportedFormat( "Tablib has no format '%s' or it is not registered." % key) if isinstance(self._formats[key], str): self._formats[key] = load_format_class(self._formats[key]) return self._formats[key]
def get_format(self, key): if key not in self._formats: if key in uninstalled_format_messages: raise UnsupportedFormat( "The '{key}' format is not available. You may want to install the " "{package_name} (or `pip install tablib[{extras_name}]`).". format(**uninstalled_format_messages[key], key=key)) raise UnsupportedFormat( "Tablib has no format '%s' or it is not registered." % key) if isinstance(self._formats[key], str): self._formats[key] = load_format_class(self._formats[key]) return self._formats[key]
def export(self, format, **kwargs): """ Export :class:`Databook` object to `format`. :param \\*\\*kwargs: (optional) custom configuration to the format `export_book`. """ fmt = registry.get_format(format) if not hasattr(fmt, 'export_book'): raise UnsupportedFormat(f'Format {format} cannot be exported.') return fmt.export_book(self, **kwargs)
def load(self, in_stream, format=None, **kwargs): """ Import `in_stream` to the :class:`Dataset` object using the `format`. :param \\*\\*kwargs: (optional) custom configuration to the format `import_set`. """ if not format: format = detect_format(in_stream) fmt = registry.get_format(format) if not hasattr(fmt, 'import_set'): raise UnsupportedFormat( 'Format {} cannot be imported.'.format(format)) if not import_set: raise UnsupportedFormat( 'Format {} cannot be imported.'.format(format)) fmt.import_set(self, in_stream, **kwargs) return self
def load(self, in_stream, format=None, **kwargs): """ Import `in_stream` to the :class:`Dataset` object using the `format`. `in_stream` can be a file-like object, a string, or a bytestring. :param \\*\\*kwargs: (optional) custom configuration to the format `import_set`. """ stream = normalize_input(in_stream) if not format: format = detect_format(stream) fmt = registry.get_format(format) if not hasattr(fmt, 'import_set'): raise UnsupportedFormat(f'Format {format} cannot be imported.') if not import_set: raise UnsupportedFormat(f'Format {format} cannot be imported.') fmt.import_set(self, stream, **kwargs) return self
def load(self, in_stream, format, **kwargs): """ Import `in_stream` to the :class:`Databook` object using the `format`. `in_stream` can be a file-like object, a string, or a bytestring. :param \\*\\*kwargs: (optional) custom configuration to the format `import_book`. """ stream = normalize_input(in_stream) if not format: format = detect_format(stream) fmt = registry.get_format(format) if not hasattr(fmt, 'import_book'): # pythonlibrary.net: # 格式处理器主要具有import_book raise UnsupportedFormat( 'Format {} cannot be loaded.'.format(format)) fmt.import_book(self, stream, **kwargs) return self