linecook.transforms package

Submodules

linecook.transforms.core module

Text formatters match the signature of basic regex functions, taking a text/regex match pattern and an input string.

class linecook.transforms.core.CountLines(line_template='{count_label} {line}', count_template='{count:>3}:', color_kwargs={'attrs': ['bold'], 'color': 'grey'})

Bases: object

Tranformation returning line of text with line count added.

reset()
linecook.transforms.core.color_text(match_pattern='.*', color=None, on_color=None, attrs=None)

Return color transform that returns colorized version of input string.

Parameters:
  • color (str) – Text color. Any of the following values grey, red, green, yellow, blue, magenta, cyan, white.
  • on_color (str) – Background color. Any of the following values on_grey, on_red, on_green, on_yellow, on_blue, on_magenta, on_cyan, on_white
  • attrs (list(str)) – Text attributes. Any of the following values: bold, dark, underline, blink, reverse, concealed.
linecook.transforms.core.delete_text(match_pattern, *, replacement='')
linecook.transforms.core.filter_line(match_pattern, on_match=None, on_mismatch=None)

Return transform that filters lines by match pattern.

If neither on_match or on_mismatch are given, return input string if it matches the given pattern. Otherwise, the input string is passed to those callback functions and the output is returned.

Parameters:
  • on_match (callable) – A text transform that is called with the input string if the string matches the match_pattern.
  • on_mismatch (callable) – A text transform that is called with the input string if the string does not match the match_pattern.
linecook.transforms.core.partition(match_pattern, on_match=None, on_mismatch=None)

Return line partitioned by pattern and re-joined after transformation.

Parameters:
  • on_match (callable) – A text transform that is called with each substring that matches the match_pattern.
  • on_mismatch (callable) – A text transform that is called with each substring that does not match the match_pattern.
linecook.transforms.core.replace_text(match_pattern, replacement)
linecook.transforms.core.split_on(match_pattern, *, replacement='\n')

linecook.transforms.logging module

linecook.transforms.parse module

Transforms that parse data from text.

linecook.transforms.parse.json_from_qs(flatten=True)

Return tranform that outputs json string from query string.

Module contents

linecook.transforms.delete_text(match_pattern, *, replacement='')
linecook.transforms.split_on(match_pattern, *, replacement='\n')