From 48bc8e4a7ba7d5ea4360b22a3527a3b028c6ce3b Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Fri, 19 Jan 2018 19:43:49 +0100 Subject: Always rstrip() when dedenting Factors out some code and makes the logic a bit more transparent. It's only used for help text lines. --- kconfiglib.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index c52b156..db0ffb0 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1745,7 +1745,7 @@ class Kconfig(object): self._reuse_line = True # "Unget" the line break - help_lines = [_deindent(line, indent).rstrip()] + help_lines = [_dedent_rstrip(line, indent)] # The help text goes on till the first non-empty line with less # indent @@ -1758,7 +1758,7 @@ class Kconfig(object): node.help = "\n".join(help_lines).rstrip() + "\n" break - help_lines.append(_deindent(line, indent).rstrip()) + help_lines.append(_dedent_rstrip(line, indent)) if not line: break @@ -3752,11 +3752,18 @@ def _indentation(line): line = line.expandtabs() return len(line) - len(line.lstrip()) -def _deindent(line, indent): - """ - Deindents 'line' by 'indent' spaces. +def _dedent_rstrip(line, indent): + r""" + De-indents 'line' by 'indent' spaces and rstrip()s it to remove any + newlines (which gets rid of other trailing whitespace too, but that's + fine). + + Used to prepare help text lines in a speedy way: The [indent:] might + already remove trailing newlines for lines shorter than indent (e.g. empty + lines). The rstrip() makes it consistent, meaning we can join the lines + with "\n" later. """ - return line.expandtabs()[indent:] + return line.expandtabs()[indent:].rstrip() def _is_base_n(s, n): try: -- cgit v1.2.3