24 from .formatters
import TsvFormatter, TxtFormatter, PipeFormatter
25 from .htmlformatter
import HtmlFormatter
26 from .htmltemplate
import TEMPLATE_START, TEMPLATE_END
36 if context.format == context.html_format:
38 if context.format == context.tsv_format:
40 if context.pipe_separated:
49 self.
_output_output = configuration.output
52 tables = [table
for table
in datafile
if table]
53 if datafile.has_preamble:
56 self.
_write_table_write_table(table, is_last=table
is tables[-1])
76 raise NotImplementedError
87 self.
_separator_separator =
' ' * configuration.txt_separating_spaces
88 _DataFileWriter.__init__(self, formatter, configuration)
91 line = self.
_separator_separator.join(row).rstrip() +
'\n'
103 _DataFileWriter.__init__(self, formatter, configuration)
108 row =
'| ' + row +
' |'
116 raise RuntimeError(
'No csv module found. '
117 'Writing tab separated format is not possible.')
118 formatter =
TsvFormatter(configuration.tsv_column_count)
119 _DataFileWriter.__init__(self, formatter, configuration)
125 dialect = csv.excel_tab()
126 dialect.lineterminator = configuration.line_separator
if PY2
else '\n'
127 return csv.writer(configuration.output, dialect=dialect)
131 row = [c.encode(
'UTF-8')
for c
in row]
132 self.
_writer_writer.writerow(row)
139 _DataFileWriter.__init__(self, formatter, configuration)
140 self.
_name_name = configuration.datafile.name
144 self.
_writer_writer.content(TEMPLATE_START % {
'NAME': self.
_name_name}, escape=
False)
145 _DataFileWriter.write(self, datafile)
146 self.
_writer_writer.content(TEMPLATE_END, escape=
False)
149 self.
_writer_writer.
start(
'table', {
'id': table.type.replace(
' ',
''),
151 _DataFileWriter._write_table(self, table, is_last)
152 self.
_writer_writer.end(
'table')
157 self.
_writer_writer.element(cell.tag, cell.content, cell.attributes,
def _write_row(self, row)
def write(self, datafile)
def _write_table(self, table, is_last)
def __init__(self, configuration)
def _write_row(self, row)
def __init__(self, configuration)
def _write_row(self, row)
def __init__(self, configuration)
def _write_row(self, row)
def _get_writer(self, configuration)
def __init__(self, configuration)
def _write_empty_row(self, table)
def _write_rows(self, rows)
def _write_table(self, table, is_last)
def _write_row(self, row)
def _write_preamble(self, rows)
def _write_header(self, table)
def write(self, datafile)
def __init__(self, formatter, configuration)
def FileWriter(context)
Creates and returns a FileWriter object.