jp (common): allow tables filters callbacks to have only one argument
This commit is contained in:
parent
edff42a743
commit
28f15f222d
1 changed files with 10 additions and 4 deletions
|
|
@ -410,7 +410,11 @@ class Table(object):
|
|||
@param headers(iterable[unicode], None): names/titles of the columns
|
||||
if not None, must have same number of columns as data
|
||||
@param filters(iterable[(callable, unicode)], None): values filters
|
||||
the callable will get col value as argument and must return a string
|
||||
the callable will get 2 arguments:
|
||||
- current column value
|
||||
- RowData with all columns values
|
||||
if may also only use 1 argument, which will then be current col value.
|
||||
the callable must return a string
|
||||
if it's unicode, it will be used with .format and must countain u'{}' which will be replaced with the string
|
||||
if not None, must have same number of columns as data
|
||||
@param use_buffer(bool): if True, bufferise output instead of printing it directly
|
||||
|
|
@ -440,7 +444,10 @@ class Table(object):
|
|||
if isinstance(filter_, basestring):
|
||||
col_value = filter_.format(value)
|
||||
else:
|
||||
col_value = filter_(value, row_cls(*row_data_list))
|
||||
try:
|
||||
col_value = filter_(value, row_cls(*row_data_list))
|
||||
except TypeError:
|
||||
col_value = filter_(value)
|
||||
# we count size without ANSI code as they will change length of the string
|
||||
# when it's mostly style/color changes.
|
||||
col_size = len(regex.ansiRemove(col_value))
|
||||
|
|
@ -497,8 +504,7 @@ class Table(object):
|
|||
@param headers(iterable[unicode], None): name of the columns
|
||||
names must be in same order as keys
|
||||
@param filters(dict[unicode, (callable,unicode)), None): filter to use on values
|
||||
keys correspond to keys to filter, and value is a callable or unicode which
|
||||
will get the value as argument and must return a string
|
||||
keys correspond to keys to filter, and value is the same as for Table.__init__
|
||||
@param defaults(dict[unicode, unicode]): default value to use
|
||||
if None, an exception will be raised if not value is found
|
||||
"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue