aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2017-05-03 16:39:25 +0100
committerBryn M. Reeves <bmr@redhat.com>2017-05-03 16:39:25 +0100
commit471d8e86c3c174f7b075c306542c732f30893281 (patch)
treee1be3074f135396dfa2c3a1f7c39f7865cc73550
parentf0f20b41ff3344cf02c9d13938a431c9b482a1d4 (diff)
downloadsos-471d8e86c3c174f7b075c306542c732f30893281.tar.gz
[reporting] imrove readability of Six string workaround
Improve the readability of the changes to work around Six issue emphasise the fact that the buffer contains line oriented data, and introduce a helper function to test whether the string needs the workaround to be applied or not: this shortens the list comprehension which would otherwise overflow a single line due to the longer buffer variable name. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/reporting.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/sos/reporting.py b/sos/reporting.py
index 0bb7d29e..a4941adb 100644
--- a/sos/reporting.py
+++ b/sos/reporting.py
@@ -118,6 +118,17 @@ class Note(Leaf):
self.data = content
+def ends_bs(string):
+ """ Return True if 'string' ends with a backslash, and False otherwise.
+
+ Define this as a named function for no other reason than that pep8
+ now forbids binding of a lambda expression to a name:
+
+ 'E731 do not assign a lambda expression, use a def'
+ """
+ return string.endswith('\\')
+
+
class PlainTextReport(object):
"""Will generate a plain text report from a top_level Report object"""
@@ -134,16 +145,16 @@ class PlainTextReport(object):
(Note, NOTE, "- notes:"),
)
- buf = []
+ line_buf = []
def __init__(self, report_node):
self.report_node = report_node
def unicode(self):
- self.buf = buf = []
+ self.line_buf = line_buf = []
for section_name, section_contents in sorted(iteritems(
self.report_node.data)):
- buf.append(section_name + "\n" + self.DIVIDER)
+ line_buf.append(section_name + "\n" + self.DIVIDER)
for type_, format_, header in self.subsections:
self.process_subsection(section_contents, type_.ADDS_TO,
header, format_)
@@ -151,10 +162,10 @@ class PlainTextReport(object):
# Workaround python.six mishandling of strings ending in '/' by
# adding a single space following any '\' at end-of-line.
# See Six issue #60.
- buf = [(val + " ") if val.endswith('\\') else val for val in buf]
+ line_buf = [line + " " if ends_bs(line) else line for line in line_buf]
output = u'\n'.join(map(lambda i: (i if isinstance(i, six.text_type)
- else six.u(i)), buf))
+ else six.u(i)), line_buf))
if six.PY3:
return output
else:
@@ -162,8 +173,8 @@ class PlainTextReport(object):
def process_subsection(self, section, key, header, format_):
if key in section:
- self.buf.append(header)
+ self.line_buf.append(header)
for item in section.get(key):
- self.buf.append(format_ % item)
+ self.line_buf.append(format_ % item)
# vim: set et ts=4 sw=4 :