Open roskakori opened 9 years ago
Goals: format for which there are already standard modules to write can be written in a validated way.
Rough design:
In rowio:
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.
AbstractWriter
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.
OdsWriter()
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:
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
Goals: format for which there are already standard modules to write can be written in a validated way.
Rough design:
In
rowio
:From
AbstractWriter
we can derive format specific writers, e.g.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:
In
validio
: