Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_source():
source = AbstractSource(source="asource", params="params")
info = source.get_source_info()
assert info, (None, None)
def test_write_only_source():
source = AbstractSource()
source.get_data()
pyexcel.plugins.sources.file_input
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Representation of input file sources
:copyright: (c) 2015-2017 by Onni Software Ltd.
:license: New BSD License
"""
import os
from pyexcel.source import AbstractSource
from pyexcel.internal import PARSER
# pylint: disable=W0223
class ReadExcelFromFile(AbstractSource):
"""Pick up 'file_name' field and do single sheet based read and write
"""
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 get_source_info(self):
path, file_name = os.path.split(self.__file_name)
return file_name, path
pyexcel.plugins.sources.memory_input
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Representation of input file sources
:copyright: (c) 2015-2017 by Onni Software Ltd.
:license: New BSD License
"""
from pyexcel.source import AbstractSource
from pyexcel.internal import PARSER
from . import params
# pylint: disable=W0223
class ReadExcelFileMemory(AbstractSource):
"""Pick up 'file_type' and read a sheet from memory"""
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 __init__(self, bookdict, **keywords):
self.__bookdict = bookdict
self._content = _FakeIO()
AbstractSource.__init__(self, **keywords)
Generic database sources
:copyright: (c) 2015-2017 by Onni Software Ltd.
:license: New BSD License
"""
from pyexcel.source import AbstractSource
from pyexcel._compact import PY2
from pyexcel.internal import PARSER, RENDERER
from . import params
NO_COLUMN_NAMES = "Only sheet with column names is accepted"
class SheetDbSource(AbstractSource):
"""
SQLAlchemy channeled sql database as data source
"""
def __init__(
self,
db_type,
export_columns=None,
sheet_name=None,
parser_library=None,
renderer_library=None,
**keywords
):
self._db_type = db_type
self.__export_columns = export_columns
self.__sheet_name = sheet_name
init_func, map_dict = _transcode_sheet_db_keywords(self._keywords)
import_params = self.get_import_params()
arender.render_sheet_to_stream(
import_params,
sheet,
init=init_func,
mapdict=map_dict,
**self._keywords
)
def get_import_params(self):
"""form the parameters for the db parser"""
pass
class BookDbSource(AbstractSource):
"""
multiple Django table as data source
"""
def __init__(
self, db_type, parser_library=None, renderer_library=None, **keywords
):
self.__db_type = db_type
self.__parser_library = parser_library
self.__renderer_library = renderer_library
AbstractSource.__init__(self, **keywords)
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)
def __init__(self, url=None, **keywords):
self.__url = url
AbstractSource.__init__(self, **keywords)