def indent(text, prefix, predicate=None):
if predicate is None:<EOL><INDENT>def predicate(line):<EOL><INDENT>return line.strip()<EOL><DEDENT><DEDENT>def prefixed_lines():<EOL><INDENT>for line in text.splitlines(True):<EOL><INDENT>yield (prefix + line if predicate(line) else line)<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(prefixed_lines())<EOL>
Adds 'prefix' to the beginning of selected lines in 'text'.

    If 'predicate' is provided, 'prefix' will only be added to the lines
    where 'predicate(line)' is True. If 'predicate' is not provided,
    it will default to adding 'prefix' to all non-empty lines that do not
    consist solely of whitespace characters.

    Borrowed from Py3 `textwrap` module.