# HG changeset patch # User Goffi # Date 1529536894 -7200 # Node ID c9dddf691d7b5a8de55c9d3c9b7dd8dc0791901c # Parent 75d2ac87296550a8518e69d614a604eee75e5242 jp (common): allow tables filters callbacks to have only one argument diff -r 75d2ac872965 -r c9dddf691d7b sat_frontends/jp/common.py --- a/sat_frontends/jp/common.py Wed Jun 06 19:24:15 2018 +0200 +++ b/sat_frontends/jp/common.py Thu Jun 21 01:21:34 2018 +0200 @@ -410,7 +410,11 @@ @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 @@ 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 @@ @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 """