コード例 #1
0
class DummySource(WriteOnlySheetSource):
    """
    Write into json file
    """
    fields = [params.FILE_TYPE]
    targets = (params.BOOK, params.SHEET)
    actions = (params.WRITE_ACTION,)

    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self.content = file_stream
        else:
            self.content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    @classmethod
    def can_i_handle(cls, action, file_type):
        status = False
        if action == params.WRITE_ACTION and file_type == 'dummy':
            status = True
        return status

    def write_data(self, sheet):
        self.content.write(FIXTURE)
コード例 #2
0
class DummySource(with_metaclass(Plugin, AbstractSource, MemorySourceMixin)):
    """
    For a dynamically loaded plugin, you will need to create the following
    fields. and implement to class level functions: keywords and
    is_my_business.
    """
    plugin_name = 'source'
    fields = [FIXTURE]
    targets = (constants.BOOK, constants.SHEET)
    actions = (constants.WRITE_ACTION,)
    attributes = [FIXTURE]
    key = FIXTURE

    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self._content = file_stream
        else:
            self._content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    def write_data(self, sheet):
        self._content.write(FIXTURE)

    @classmethod
    def keywords(self):
        for target, action in product(self.targets, self.actions):
            yield "%s-%s" % (target, action)

    @classmethod
    def is_my_business(self, action, **keywords):
        statuses = [_has_field(field, keywords) for field in self.fields]
        results = [status for status in statuses if status is False]
        return len(results) == 0
コード例 #3
0
class DummySource(WriteOnlySheetSource):
    """
    Write into json file
    """
    fields = [params.FILE_TYPE]
    targets = (params.BOOK, params.SHEET)
    actions = (params.WRITE_ACTION,)

    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self.content = file_stream
        else:
            self.content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    @classmethod
    def can_i_handle(cls, action, file_type):
        status = False
        if action == params.WRITE_ACTION and file_type == 'dummy':
            status = True
        return status

    def write_data(self, sheet):
        self.content.write(FIXTURE)
コード例 #4
0
def test_issue_76():
    from pyexcel._compact import StringIO
    tsv_stream = StringIO()
    tsv_stream.write('1\t2\t3\t4\n')
    tsv_stream.write('1\t2\t3\t4\n')
    tsv_stream.seek(0)
    sheet = pe.get_sheet(file_stream=tsv_stream,
                         file_type='csv',
                         delimiter='\t')
    data = [[1, 2, 3, 4], [1, 2, 3, 4]]
    eq_(sheet.array, data)
コード例 #5
0
ファイル: test_bug_fixes.py プロジェクト: lanicon/pyexcel
def test_issue_76():
    from pyexcel._compact import StringIO

    tsv_stream = StringIO()
    tsv_stream.write("1\t2\t3\t4\n")
    tsv_stream.write("1\t2\t3\t4\n")
    tsv_stream.seek(0)
    sheet = p.get_sheet(
        file_stream=tsv_stream, file_type="csv", delimiter="\t"
    )
    data = [[1, 2, 3, 4], [1, 2, 3, 4]]
    eq_(sheet.array, data)
コード例 #6
0
class DummySource(AbstractSource, MemorySourceMixin):
    """
    For a dynamically loaded plugin, you will need to create the following
    fields. and implement to class level functions: keywords and
    is_my_business.
    """
    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self._content = file_stream
        else:
            self._content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    def write_data(self, sheet):
        self._content.write(FIXTURE)
コード例 #7
0
class DummySource(AbstractSource, MemorySourceMixin):
    """
    Write into json file
    """
    fields = [FIXTURE]
    targets = (constants.BOOK, constants.SHEET)
    actions = (constants.WRITE_ACTION,)
    attributes = [FIXTURE]
    key = FIXTURE

    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self._content = file_stream
        else:
            self._content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    def write_data(self, sheet):
        self._content.write(FIXTURE)
コード例 #8
0
class DummySource(Source):
    """
    Write into json file
    """
    fields = [FIXTURE]
    targets = (params.BOOK, params.SHEET)
    actions = (params.WRITE_ACTION, )
    attributes = [FIXTURE]
    key = FIXTURE

    def __init__(self, file_type=None, file_stream=None, **keywords):
        if file_stream:
            self.content = file_stream
        else:
            self.content = StringIO()
        self.file_type = file_type
        self.keywords = keywords

    def write_data(self, sheet):
        self.content.write(FIXTURE)

    def get_internal_stream(self):
        return self.content