commit bf2b27c2e034ad0f7d9eb758ea79505f16e2aac2 Author: Damian Johnson <atagar@torproject.org> Date: Sat Feb 6 13:24:31 2016 -0800 Have validate() provide a 'line => (type, msg)' dict We only have one caller of validate() so might as well provide what it wants. --- nyx/torrc_panel.py | 2 +- nyx/util/tor_config.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py index 01d12fc..e37c9b5 100644 --- a/nyx/torrc_panel.py +++ b/nyx/torrc_panel.py @@ -142,7 +142,7 @@ class TorrcPanel(panel.Panel): if line and '#' in line: rendered_contents[i] = line[:line.find('#')].strip() - corrections = dict((line_number, (issue, msg)) for line_number, issue, msg in tor_config.validate(self.torrc_content)) + corrections = tor_config.validate(self.torrc_content) # offset to make room for the line numbers diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py index 22e7938..ed8c88e 100644 --- a/nyx/util/tor_config.py +++ b/nyx/util/tor_config.py @@ -95,7 +95,7 @@ def validate(contents): config_lines = config_text.splitlines() if config_text else [] custom_options = list(set([line.split(' ')[0] for line in config_lines])) - issues_found, seen_options = [], [] + issues_found, seen_options = {}, [] # Strips comments and collapses multiline multi-line entries, for more # information see: @@ -152,7 +152,7 @@ def validate(contents): # most parameters are overwritten if defined multiple times if option in seen_options and option not in get_multiline_parameters(): - issues_found.append((line_number, ValidationError.DUPLICATE, option)) + issues_found[line_number] = (ValidationError.DUPLICATE, option) continue else: seen_options.append(option) @@ -160,7 +160,7 @@ def validate(contents): # checks if the value isn't necessary due to matching the defaults if option not in custom_options: - issues_found.append((line_number, ValidationError.IS_DEFAULT, option)) + issues_found[line_number] = (ValidationError.IS_DEFAULT, option) # replace aliases with their recognized representation @@ -210,7 +210,7 @@ def validate(contents): elif value_type == ValueType.TIME: display_values = [str_tools.time_label(int(val)) for val in tor_values] - issues_found.append((line_number, ValidationError.MISMATCH, ', '.join(display_values))) + issues_found[line_number] = (ValidationError.MISMATCH, ', '.join(display_values)) return issues_found