ex38
This commit is contained in:
parent
4c98786f05
commit
915c221f6f
@ -49,7 +49,20 @@ class HTMLTableFormatter(TableFormatter):
|
||||
return self._printer(rowdata, "td")
|
||||
|
||||
|
||||
def create_formatter(name):
|
||||
class ColumnFormatMixin:
|
||||
formats = []
|
||||
|
||||
def row(self, rowdata):
|
||||
rowdata = [(fmt % d) for fmt, d in zip(self.formats, rowdata)]
|
||||
super().row(rowdata)
|
||||
|
||||
|
||||
class UpperHeadersMixin:
|
||||
def headings(self, headers):
|
||||
super().headings([h.upper() for h in headers])
|
||||
|
||||
|
||||
def create_formatter(name, column_formats=None, upper_headers=False):
|
||||
formatters = {
|
||||
"text": TextTableFormatter,
|
||||
"csv": CSVTableFormatter,
|
||||
@ -58,6 +71,18 @@ def create_formatter(name):
|
||||
formatter = formatters.get(name, None)
|
||||
if not name:
|
||||
raise ValueError(f'formatter named "{name}" not implemented')
|
||||
if upper_headers:
|
||||
|
||||
class _UpperFormatter(UpperHeadersMixin, formatter):
|
||||
pass
|
||||
|
||||
formatter = _UpperFormatter
|
||||
if column_formats:
|
||||
|
||||
class _ColumnFormatter(ColumnFormatMixin, formatter):
|
||||
formats = column_formats
|
||||
|
||||
formatter = _ColumnFormatter
|
||||
return formatter()
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user