Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validated writing #84

Open
roskakori opened this issue Jan 11, 2015 · 0 comments
Open

Add validated writing #84

roskakori opened this issue Jan 11, 2015 · 0 comments
Milestone

Comments

@roskakori
Copy link
Owner

Goals: format for which there are already standard modules to write can be written in a validated way.

Rough design:

  • TODO add location

In rowio:

class AbtractWriter():
    def __init__(self, target):
        assert target is not None
        self.target = target
        self.is_opened = False
    def write_row():
        raise NotImplementedError
    def write_rows(self, rows):
        assert rows is not None
        for row in rows:
            self.write_row(row)
    def close():
        if self.is_opened:
           self.target.close()
    def __enter__(self):
       # for context manager
    def __exit__(self):
        # call close() from context manager

From AbstractWriter we can derive format specific writers, e.g.

class DelimitedWriter():
    def __init__(self, target, ...): ...
    def write_row(): ...
class ExcelWriter(AbstractWriter):
    def __init__(self, target): ...
    def write_row(): ...
    def close():
       # TODO: Actually write workbook.
       super().close()
class FixedWriter(AbstractWriter):
    def __init___(self, target, field_names_and_lengths, has_line_delimiter): ...
    def write_row(): ...

There will be not OdsWriter() because at the moment there does not seem to exist a stable and easy to use Python package for that.

These writers can be collected in a single factory function:

def writer(data_format, target):
    if data_format.format == data.FORMAT_DELIMITED:
        result = DelimitedWriter(...)
    elif ...
    elif data_format.format == data.FORMAT_ODS:
        raise NotImplementedError('cannot write ODS, see <url to github issue for OdsWriter>')
    else:
        assert False

In validio:

class Writer(object):
    def __init__(self, cid, target):
        self._cid = cid
        self._delegated_writer = rowio.writer(cid.data_format, target)
    def write_row(self, row):
        # TODO: validate row against self._cid
        self._delegated_writer.write_row(row)    
    def write_rows(self, rows):
        assert rows is not None
        for row in rows:
            self.write_row(row)
    close():
        # Perform checks at end.
        # For Excel, actually write workbook
    def __enter__(self):
       # for context manager
    def __exit__(self):
        # call close() from context manager
@roskakori roskakori self-assigned this Jan 11, 2015
@roskakori roskakori added this to the 0.8.3 milestone Jan 24, 2015
roskakori added a commit that referenced this issue Jan 25, 2015
roskakori added a commit that referenced this issue Jan 25, 2015
roskakori added a commit that referenced this issue Jan 26, 2015
roskakori added a commit that referenced this issue Jan 27, 2015
Fixed broken test cases under Python 2.
@roskakori roskakori modified the milestones: 0.8.4, 0.8.3 Jan 31, 2015
roskakori added a commit that referenced this issue Feb 4, 2015
roskakori added a commit that referenced this issue Mar 1, 2015
Fixed validated writing of header rows by disabling validation of the header.
@roskakori roskakori modified the milestones: 0.8.5, 0.8.4 Mar 1, 2015
@roskakori roskakori modified the milestones: 0.8.6, 0.8.5 Mar 9, 2015
roskakori added a commit that referenced this issue Apr 3, 2015
Added row writer for *.xlsx format.
roskakori added a commit that referenced this issue Apr 3, 2015
Fixed actual writing of Excel file and broken test caused by missing target folder.
@roskakori roskakori modified the milestones: 0.8.7, 0.8.6, 0.8.8 Jul 17, 2015
@roskakori roskakori modified the milestones: 0.8.9, 0.8.8 Nov 16, 2015
@roskakori roskakori modified the milestones: 0.8.9, 0.9.1 Dec 27, 2021
@roskakori roskakori modified the milestones: 0.9.1, 0.9.2 Dec 29, 2022
@roskakori roskakori removed their assignment Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant