commit cdd4e47affe863cd82c54eca097ce5bb25dbef3b Author: Damian Johnson atagar@torproject.org Date: Wed Aug 27 09:21:19 2014 -0700
Stylistic issues from pep8 1.5.7
Fixing issues spotted by the new release of pep8. --- arm/config_panel.py | 4 +-- arm/connections/circ_entry.py | 2 +- arm/connections/conn_entry.py | 20 +++++------ arm/graphing/bandwidth_stats.py | 2 +- arm/graphing/graph_panel.py | 4 +-- arm/header_panel.py | 70 +++++++++++++++++++-------------------- arm/log_panel.py | 4 +-- arm/popups.py | 2 +- arm/util/panel.py | 2 +- arm/util/tor_config.py | 14 ++++---- 10 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/arm/config_panel.py b/arm/config_panel.py index 84f7f3a..dabe078 100644 --- a/arm/config_panel.py +++ b/arm/config_panel.py @@ -279,7 +279,7 @@ class ConfigPanel(panel.Panel): elif not CONFIG["features.config.state.showVirtualOptions"] and conf_type == "Virtual": continue
- self.conf_contents.append(ConfigEntry(conf_option, conf_type, not conf_option in custom_options)) + self.conf_contents.append(ConfigEntry(conf_option, conf_type, conf_option not in custom_options))
elif self.config_type == State.ARM: # loaded via the conf utility @@ -416,7 +416,7 @@ class ConfigPanel(panel.Panel): # resets the is_default flag
custom_options = tor_config.get_custom_options() - selection.fields[Field.IS_DEFAULT] = not config_option in custom_options + selection.fields[Field.IS_DEFAULT] = config_option not in custom_options
self.redraw(True) except Exception as exc: diff --git a/arm/connections/circ_entry.py b/arm/connections/circ_entry.py index 7f9c47b..0041a97 100644 --- a/arm/connections/circ_entry.py +++ b/arm/connections/circ_entry.py @@ -231,7 +231,7 @@ def get_relay_address(controller, relay_fingerprint, default = None):
if controller.is_alive(): # query the address if it isn't yet cached - if not relay_fingerprint in ADDRESS_LOOKUP_CACHE: + if relay_fingerprint not in ADDRESS_LOOKUP_CACHE: if relay_fingerprint == controller.get_info("fingerprint", None): # this is us, simply check the config my_address = controller.get_info("address", None) diff --git a/arm/connections/conn_entry.py b/arm/connections/conn_entry.py index 62c01f3..f3ec86c 100644 --- a/arm/connections/conn_entry.py +++ b/arm/connections/conn_entry.py @@ -114,14 +114,14 @@ class Endpoint: """
# TODO: skipping all hostname resolution to be safe for now - #try: - # myHostname = hostnames.resolve(self.address) - #except: - # # either a ValueError or IOError depending on the source of the lookup failure - # myHostname = None + # try: + # myHostname = hostnames.resolve(self.address) + # except: + # # either a ValueError or IOError depending on the source of the lookup failure + # myHostname = None # - #if not myHostname: return default - #else: return myHostname + # if not myHostname: return default + # else: return myHostname
return default
@@ -652,7 +652,7 @@ class ConnectionLine(entries.ConnectionPanelLine): # the source and destination addresses are both private, but that might # not be perfectly reliable either.
- is_expansion_type = not my_type in (Category.SOCKS, Category.HIDDEN, Category.CONTROL) + is_expansion_type = my_type not in (Category.SOCKS, Category.HIDDEN, Category.CONTROL)
if is_expansion_type: src_address = my_external_address + local_port @@ -1143,7 +1143,7 @@ class FingerprintTracker: result = [] else: # query the fingerprint if it isn't yet cached - if not (relay_address, relay_port) in self._fingerprint_lookup_cache: + if (relay_address, relay_port) not in self._fingerprint_lookup_cache: relay_fingerprint = self._get_relay_fingerprint(controller, relay_address, relay_port) self._fingerprint_lookup_cache[(relay_address, relay_port)] = relay_fingerprint
@@ -1165,7 +1165,7 @@ class FingerprintTracker:
if controller.is_alive(): # query the nickname if it isn't yet cached - if not relay_fingerprint in self._nickname_lookup_cache: + if relay_fingerprint not in self._nickname_lookup_cache: if relay_fingerprint == controller.get_info("fingerprint", None): # this is us, simply check the config my_nickname = controller.get_conf("Nickname", "Unnamed") diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py index 1fffa4a..6396873 100644 --- a/arm/graphing/bandwidth_stats.py +++ b/arm/graphing/bandwidth_stats.py @@ -167,7 +167,7 @@ class BandwidthStats(graph_panel.GraphStats): # the state tracks a day's worth of data and this should only prepopulate # results associated with this tor instance
- if not uptime or not "-" in uptime: + if not uptime or "-" not in uptime: msg = PREPOPULATE_FAILURE_MSG % "insufficient uptime" log.notice(msg) return False diff --git a/arm/graphing/graph_panel.py b/arm/graphing/graph_panel.py index f36b090..41bd352 100644 --- a/arm/graphing/graph_panel.py +++ b/arm/graphing/graph_panel.py @@ -502,13 +502,13 @@ class GraphPanel(panel.Panel): if primary_min_bound != primary_max_bound: primary_val = (primary_max_bound - primary_min_bound) * (self.graph_height - row - 1) / (self.graph_height - 1)
- if not primary_val in (primary_min_bound, primary_max_bound): + if primary_val not in (primary_min_bound, primary_max_bound): self.addstr(row + 2, 0, "%4i" % primary_val, primary_color)
if secondary_min_bound != secondary_max_bound: secondary_val = (secondary_max_bound - secondary_min_bound) * (self.graph_height - row - 1) / (self.graph_height - 1)
- if not secondary_val in (secondary_min_bound, secondary_max_bound): + if secondary_val not in (secondary_min_bound, secondary_max_bound): self.addstr(row + 2, graph_column + 5, "%4i" % secondary_val, secondary_color)
# creates bar graph (both primary and secondary) diff --git a/arm/header_panel.py b/arm/header_panel.py index 841100f..e16f98c 100644 --- a/arm/header_panel.py +++ b/arm/header_panel.py @@ -97,46 +97,46 @@ class HeaderPanel(panel.Panel, threading.Thread): if key in (ord('n'), ord('N')) and tor_controller().is_newnym_available(): self.send_newnym() elif key in (ord('r'), ord('R')) and not self.vals.is_connected: - #oldSocket = tor_tools.get_conn().get_controller().get_socket() + # oldSocket = tor_tools.get_conn().get_controller().get_socket() # - #controller = None - #allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes() + # controller = None + # allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes() # - #if os.path.exists(CONFIG["startup.interface.socket"]) and allowSocketConnection: - # try: - # # TODO: um... what about passwords? - # controller = Controller.from_socket_file(CONFIG["startup.interface.socket"]) - # controller.authenticate() - # except (IOError, stem.SocketError), exc: - # controller = None + # if os.path.exists(CONFIG["startup.interface.socket"]) and allowSocketConnection: + # try: + # # TODO: um... what about passwords? + # controller = Controller.from_socket_file(CONFIG["startup.interface.socket"]) + # controller.authenticate() + # except (IOError, stem.SocketError), exc: + # controller = None # - # if not allowPortConnection: - # arm.popups.show_msg("Unable to reconnect (%s)" % exc, 3) - #elif not allowPortConnection: - # arm.popups.show_msg("Unable to reconnect (socket '%s' doesn't exist)" % CONFIG["startup.interface.socket"], 3) + # if not allowPortConnection: + # arm.popups.show_msg("Unable to reconnect (%s)" % exc, 3) + # elif not allowPortConnection: + # arm.popups.show_msg("Unable to reconnect (socket '%s' doesn't exist)" % CONFIG["startup.interface.socket"], 3) # - #if not controller and allowPortConnection: - # # TODO: This has diverged from starter.py's connection, for instance it - # # doesn't account for relative cookie paths or multiple authentication - # # methods. We can't use the starter.py's connection function directly - # # due to password prompts, but we could certainly make this mess more - # # manageable. + # if not controller and allowPortConnection: + # # TODO: This has diverged from starter.py's connection, for instance it + # # doesn't account for relative cookie paths or multiple authentication + # # methods. We can't use the starter.py's connection function directly + # # due to password prompts, but we could certainly make this mess more + # # manageable. # - # try: - # ctlAddr, ctl_port = CONFIG["startup.interface.ip_address"], CONFIG["startup.interface.port"] - # controller = Controller.from_port(ctlAddr, ctl_port) + # try: + # ctlAddr, ctl_port = CONFIG["startup.interface.ip_address"], CONFIG["startup.interface.port"] + # controller = Controller.from_port(ctlAddr, ctl_port) # - # try: - # controller.authenticate() - # except stem.connection.MissingPassword: - # controller.authenticate(authValue) # already got the password above - # except Exception, exc: - # controller = None + # try: + # controller.authenticate() + # except stem.connection.MissingPassword: + # controller.authenticate(authValue) # already got the password above + # except Exception, exc: + # controller = None # - #if controller: - # tor_tools.get_conn().init(controller) - # log.notice("Reconnected to Tor's control port") - # arm.popups.show_msg("Tor reconnected", 1) + # if controller: + # tor_tools.get_conn().init(controller) + # log.notice("Reconnected to Tor's control port") + # arm.popups.show_msg("Tor reconnected", 1)
pass else: @@ -388,8 +388,8 @@ class HeaderPanel(panel.Panel, threading.Thread): is_changed = False
if self.vals.pid: - #resource_tracker = arm.util.tracker.get_resource_tracker() - #is_changed = self._last_resource_fetch != resource_tracker.run_counter() + # resource_tracker = arm.util.tracker.get_resource_tracker() + # is_changed = self._last_resource_fetch != resource_tracker.run_counter() is_changed = True # TODO: we should decide to redraw or not based on if the sampling values have changed
if is_changed or (self.vals and current_time - self.vals.retrieved >= 20): diff --git a/arm/log_panel.py b/arm/log_panel.py index f782e6b..e984938 100644 --- a/arm/log_panel.py +++ b/arm/log_panel.py @@ -635,7 +635,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler): color = "magenta" elif isinstance(event, events.GuardEvent): color = "yellow" - elif not event.type in arm.arguments.TOR_EVENT_TYPES.values(): + elif event.type not in arm.arguments.TOR_EVENT_TYPES.values(): color = "red" # unknown event type
self.register_event(LogEntry(event.arrived_at, event.type, msg, color)) @@ -648,7 +648,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler): event - LogEntry for the event that occurred """
- if not event.type in self.logged_events: + if event.type not in self.logged_events: return
# strips control characters to avoid screwing up the terminal diff --git a/arm/popups.py b/arm/popups.py index be07336..59cf40a 100644 --- a/arm/popups.py +++ b/arm/popups.py @@ -179,7 +179,7 @@ def show_help_popup():
if not ui_tools.is_selection_key(exit_key) and \ not ui_tools.is_scroll_key(exit_key) and \ - not exit_key in (curses.KEY_LEFT, curses.KEY_RIGHT): + exit_key not in (curses.KEY_LEFT, curses.KEY_RIGHT): return exit_key else: return None diff --git a/arm/util/panel.py b/arm/util/panel.py index 99723b0..33cff32 100644 --- a/arm/util/panel.py +++ b/arm/util/panel.py @@ -185,7 +185,7 @@ class Panel(): attr - local variable to be returned """
- if not attr in self.pause_attr: + if attr not in self.pause_attr: return None elif self.paused: return self.pause_buffer[attr] diff --git a/arm/util/tor_config.py b/arm/util/tor_config.py index 33b53a3..32d0b07 100644 --- a/arm/util/tor_config.py +++ b/arm/util/tor_config.py @@ -183,7 +183,7 @@ def load_option_descriptions(load_path = None, check_version = True): # gets category enum, failing if it doesn't exist category = input_file_contents.pop(0).rstrip()
- if not category in Category: + if category not in Category: base_msg = "invalid category in input file: '%s'" raise IOError(base_msg % category)
@@ -241,7 +241,7 @@ def load_option_descriptions(load_path = None, check_version = True): stripped_line = line.strip()
# we have content, but an indent less than an option (ignore line) - #if stripped_line and not line.startswith(" " * MAN_OPT_INDENT): continue + # if stripped_line and not line.startswith(" " * MAN_OPT_INDENT): continue
# line starts with an indent equivilant to a new config option
@@ -681,7 +681,7 @@ def validate(contents = None):
# most parameters are overwritten if defined multiple times
- if option in seen_options and not option in get_multiline_parameters(): + if option in seen_options and option not in get_multiline_parameters(): issues_found.append((line_number, ValidationError.DUPLICATE, option)) continue else: @@ -689,7 +689,7 @@ def validate(contents = None):
# checks if the value isn't necessary due to matching the defaults
- if not option in custom_options: + if option not in custom_options: issues_found.append((line_number, ValidationError.IS_DEFAULT, option))
# replace aliases with their recognized representation @@ -722,7 +722,7 @@ def validate(contents = None): for fetched_entry in fetched_value.split(","): fetched_entry = fetched_entry.strip()
- if not fetched_entry in tor_values: + if fetched_entry not in tor_values: tor_values.append(fetched_entry)
for val in value_list: @@ -730,7 +730,7 @@ def validate(contents = None):
is_blank_match = not val and not tor_values
- if not is_blank_match and not val in tor_values: + if not is_blank_match and val not in tor_values: # converts corrections to reader friedly size values
display_values = tor_values @@ -754,7 +754,7 @@ def validate(contents = None): if option == "DirReqStatistics": continue
- if not option in seen_options: + if option not in seen_options: issues_found.append((None, ValidationError.MISSING, option))
return issues_found