[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/master] Standardize on single quotes
commit 40c302e7447767fa9794e6406a8a964042b5bee5
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Apr 9 08:41:10 2015 -0700
Standardize on single quotes
Made this transition for Stem but guess I was doing it on a file-by-file basis
for Nyx? That's annoying, and in the longrun a waste of time. Just biting the
bullet and getting it done.
---
nyx/arguments.py | 2 +-
nyx/config_panel.py | 198 +++++++++++------------
nyx/connections/circ_entry.py | 60 +++----
nyx/connections/conn_entry.py | 302 +++++++++++++++++------------------
nyx/connections/conn_panel.py | 88 +++++-----
nyx/connections/count_popup.py | 18 +--
nyx/connections/descriptor_popup.py | 62 +++----
nyx/connections/entries.py | 24 +--
nyx/controller.py | 94 +++++------
nyx/log_panel.py | 254 ++++++++++++++---------------
nyx/menu/actions.py | 116 +++++++-------
nyx/menu/item.py | 12 +-
nyx/menu/menu.py | 10 +-
nyx/popups.py | 44 ++---
nyx/starter.py | 4 +-
nyx/torrc_panel.py | 38 ++---
nyx/util/panel.py | 38 ++---
nyx/util/text_input.py | 2 +-
nyx/util/tor_config.py | 280 ++++++++++++++++----------------
nyx/util/tracker.py | 8 +-
nyx/util/ui_tools.py | 10 +-
run_nyx | 8 +-
setup.py | 38 ++---
23 files changed, 855 insertions(+), 855 deletions(-)
diff --git a/nyx/arguments.py b/nyx/arguments.py
index c612b10..834fea1 100644
--- a/nyx/arguments.py
+++ b/nyx/arguments.py
@@ -18,7 +18,7 @@ DEFAULT_ARGS = {
'user_provided_port': False,
'control_socket': '/var/run/tor/control',
'user_provided_socket': False,
- 'config': os.path.expanduser("~/.nyx/nyxrc"),
+ 'config': os.path.expanduser('~/.nyx/nyxrc'),
'debug_path': None,
'logged_events': 'N3',
'print_version': False,
diff --git a/nyx/config_panel.py b/nyx/config_panel.py
index 4fa3646..170ef46 100644
--- a/nyx/config_panel.py
+++ b/nyx/config_panel.py
@@ -19,67 +19,67 @@ from stem.util import conf, enum, str_tools
# modified, have their descriptions fetched, or even get a complete listing
# of what's available.
-State = enum.Enum("TOR", "NYX") # state to be presented
+State = enum.Enum('TOR', 'NYX') # state to be presented
# mappings of option categories to the color for their entries
CATEGORY_COLOR = {
- tor_config.Category.GENERAL: "green",
- tor_config.Category.CLIENT: "blue",
- tor_config.Category.RELAY: "yellow",
- tor_config.Category.DIRECTORY: "magenta",
- tor_config.Category.AUTHORITY: "red",
- tor_config.Category.HIDDEN_SERVICE: "cyan",
- tor_config.Category.TESTING: "white",
- tor_config.Category.UNKNOWN: "white",
+ tor_config.Category.GENERAL: 'green',
+ tor_config.Category.CLIENT: 'blue',
+ tor_config.Category.RELAY: 'yellow',
+ tor_config.Category.DIRECTORY: 'magenta',
+ tor_config.Category.AUTHORITY: 'red',
+ tor_config.Category.HIDDEN_SERVICE: 'cyan',
+ tor_config.Category.TESTING: 'white',
+ tor_config.Category.UNKNOWN: 'white',
}
# attributes of a ConfigEntry
Field = enum.Enum(
- "CATEGORY",
- "OPTION",
- "VALUE",
- "TYPE",
- "ARG_USAGE",
- "SUMMARY",
- "DESCRIPTION",
- "MAN_ENTRY",
- "IS_DEFAULT",
+ 'CATEGORY',
+ 'OPTION',
+ 'VALUE',
+ 'TYPE',
+ 'ARG_USAGE',
+ 'SUMMARY',
+ 'DESCRIPTION',
+ 'MAN_ENTRY',
+ 'IS_DEFAULT',
)
FIELD_ATTR = {
- Field.CATEGORY: ("Category", "red"),
- Field.OPTION: ("Option Name", "blue"),
- Field.VALUE: ("Value", "cyan"),
- Field.TYPE: ("Arg Type", "green"),
- Field.ARG_USAGE: ("Arg Usage", "yellow"),
- Field.SUMMARY: ("Summary", "green"),
- Field.DESCRIPTION: ("Description", "white"),
- Field.MAN_ENTRY: ("Man Page Entry", "blue"),
- Field.IS_DEFAULT: ("Is Default", "magenta"),
+ Field.CATEGORY: ('Category', 'red'),
+ Field.OPTION: ('Option Name', 'blue'),
+ Field.VALUE: ('Value', 'cyan'),
+ Field.TYPE: ('Arg Type', 'green'),
+ Field.ARG_USAGE: ('Arg Usage', 'yellow'),
+ Field.SUMMARY: ('Summary', 'green'),
+ Field.DESCRIPTION: ('Description', 'white'),
+ Field.MAN_ENTRY: ('Man Page Entry', 'blue'),
+ Field.IS_DEFAULT: ('Is Default', 'magenta'),
}
def conf_handler(key, value):
- if key == "features.config.selectionDetails.height":
+ if key == 'features.config.selectionDetails.height':
return max(0, value)
- elif key == "features.config.state.colWidth.option":
+ elif key == 'features.config.state.colWidth.option':
return max(5, value)
- elif key == "features.config.state.colWidth.value":
+ elif key == 'features.config.state.colWidth.value':
return max(5, value)
- elif key == "features.config.order":
+ elif key == 'features.config.order':
return conf.parse_enum_csv(key, value[0], Field, 3)
-CONFIG = conf.config_dict("nyx", {
- "features.config.order": [Field.MAN_ENTRY, Field.OPTION, Field.IS_DEFAULT],
- "features.config.selectionDetails.height": 6,
- "features.config.prepopulateEditValues": True,
- "features.config.state.showPrivateOptions": False,
- "features.config.state.showVirtualOptions": False,
- "features.config.state.colWidth.option": 25,
- "features.config.state.colWidth.value": 15,
+CONFIG = conf.config_dict('nyx', {
+ 'features.config.order': [Field.MAN_ENTRY, Field.OPTION, Field.IS_DEFAULT],
+ 'features.config.selectionDetails.height': 6,
+ 'features.config.prepopulateEditValues': True,
+ 'features.config.state.showPrivateOptions': False,
+ 'features.config.state.showVirtualOptions': False,
+ 'features.config.state.colWidth.option': 25,
+ 'features.config.state.colWidth.value': 15,
}, conf_handler)
@@ -119,8 +119,8 @@ class ConfigEntry():
else:
self.fields[Field.MAN_ENTRY] = 99999 # sorts non-man entries last
self.fields[Field.CATEGORY] = tor_config.Category.UNKNOWN
- self.fields[Field.ARG_USAGE] = ""
- self.fields[Field.DESCRIPTION] = ""
+ self.fields[Field.ARG_USAGE] = ''
+ self.fields[Field.DESCRIPTION] = ''
# uses the full man page description if a summary is unavailable
@@ -174,7 +174,7 @@ class ConfigEntry():
option_label = str_tools.crop(self.get(Field.OPTION), option_width)
value_label = str_tools.crop(self.get(Field.VALUE), value_width)
summary_label = str_tools.crop(self.get(Field.SUMMARY), summary_width, None)
- line_text_layout = "%%-%is %%-%is %%-%is" % (option_width, value_width, summary_width)
+ line_text_layout = '%%-%is %%-%is %%-%is' % (option_width, value_width, summary_width)
self.label_cache = line_text_layout % (option_label, value_label, summary_label)
self.label_cache_args = arg_set
@@ -196,17 +196,17 @@ class ConfigEntry():
value's type to provide a user friendly representation if able.
"""
- conf_value = ", ".join(tor_controller().get_conf(self.get(Field.OPTION), [], True))
+ conf_value = ', '.join(tor_controller().get_conf(self.get(Field.OPTION), [], True))
# provides nicer values for recognized types
if not conf_value:
- conf_value = "<none>"
- elif self.get(Field.TYPE) == "Boolean" and conf_value in ("0", "1"):
- conf_value = "False" if conf_value == "0" else "True"
- elif self.get(Field.TYPE) == "DataSize" and conf_value.isdigit():
+ conf_value = '<none>'
+ elif self.get(Field.TYPE) == 'Boolean' and conf_value in ('0', '1'):
+ conf_value = 'False' if conf_value == '0' else 'True'
+ elif self.get(Field.TYPE) == 'DataSize' and conf_value.isdigit():
conf_value = str_tools.size_label(int(conf_value))
- elif self.get(Field.TYPE) == "TimeInterval" and conf_value.isdigit():
+ elif self.get(Field.TYPE) == 'TimeInterval' and conf_value.isdigit():
conf_value = str_tools.time_label(int(conf_value), is_long = True)
return conf_value
@@ -219,7 +219,7 @@ class ConfigPanel(panel.Panel):
"""
def __init__(self, stdscr, config_type):
- panel.Panel.__init__(self, stdscr, "configuration", 0)
+ panel.Panel.__init__(self, stdscr, 'configuration', 0)
self.config_type = config_type
self.conf_contents = []
@@ -258,10 +258,10 @@ class ConfigPanel(panel.Panel):
if self.config_type == State.TOR:
controller, config_option_lines = tor_controller(), []
custom_options = tor_config.get_custom_options()
- config_option_query = controller.get_info("config/names", None)
+ config_option_query = controller.get_info('config/names', None)
if config_option_query:
- config_option_lines = config_option_query.strip().split("\n")
+ config_option_lines = config_option_query.strip().split('\n')
for line in config_option_lines:
# lines are of the form "<option> <type>[ <documentation>]", like:
@@ -269,14 +269,14 @@ class ConfigPanel(panel.Panel):
# documentation is aparently only in older versions (for instance,
# 0.2.1.25)
- line_comp = line.strip().split(" ")
+ line_comp = line.strip().split(' ')
conf_option, conf_type = line_comp[0], line_comp[1]
# skips private and virtual entries if not configured to show them
- if not CONFIG["features.config.state.showPrivateOptions"] and conf_option.startswith("__"):
+ if not CONFIG['features.config.state.showPrivateOptions'] and conf_option.startswith('__'):
continue
- elif not CONFIG["features.config.state.showVirtualOptions"] and conf_type == "Virtual":
+ elif not CONFIG['features.config.state.showVirtualOptions'] and conf_type == 'Virtual':
continue
self.conf_contents.append(ConfigEntry(conf_option, conf_type, conf_option not in custom_options))
@@ -284,7 +284,7 @@ class ConfigPanel(panel.Panel):
elif self.config_type == State.NYX:
# loaded via the conf utility
- nyx_config = conf.get_config("nyx")
+ nyx_config = conf.get_config('nyx')
for key in nyx_config.keys():
pass # TODO: implement
@@ -335,10 +335,10 @@ class ConfigPanel(panel.Panel):
self.vals_lock.acquire()
if ordering:
- CONFIG["features.config.order"] = ordering
+ CONFIG['features.config.order'] = ordering
- self.conf_contents.sort(key=lambda i: (i.get_all(CONFIG["features.config.order"])))
- self.conf_important_contents.sort(key=lambda i: (i.get_all(CONFIG["features.config.order"])))
+ self.conf_contents.sort(key=lambda i: (i.get_all(CONFIG['features.config.order'])))
+ self.conf_important_contents.sort(key=lambda i: (i.get_all(CONFIG['features.config.order'])))
self.vals_lock.release()
def show_sort_dialog(self):
@@ -348,9 +348,9 @@ class ConfigPanel(panel.Panel):
# set ordering for config options
- title_label = "Config Option Ordering:"
+ title_label = 'Config Option Ordering:'
options = [FIELD_ATTR[field][0] for field in Field]
- old_selection = [FIELD_ATTR[field][0] for field in CONFIG["features.config.order"]]
+ old_selection = [FIELD_ATTR[field][0] for field in CONFIG['features.config.order']]
option_colors = dict([FIELD_ATTR[field] for field in Field])
results = popups.show_sort_dialog(title_label, options, old_selection, option_colors)
@@ -363,7 +363,7 @@ class ConfigPanel(panel.Panel):
with self.vals_lock:
if key.is_scroll():
page_height = self.get_preferred_size()[0] - 1
- detail_panel_height = CONFIG["features.config.selectionDetails.height"]
+ detail_panel_height = CONFIG['features.config.selectionDetails.height']
if detail_panel_height > 0 and detail_panel_height + 2 <= page_height:
page_height -= (detail_panel_height + 1)
@@ -382,26 +382,26 @@ class ConfigPanel(panel.Panel):
config_option = selection.get(Field.OPTION)
if selection.is_unset():
- initial_value = ""
+ initial_value = ''
else:
initial_value = selection.get(Field.VALUE)
- prompt_msg = "%s Value (esc to cancel): " % config_option
- is_prepopulated = CONFIG["features.config.prepopulateEditValues"]
- new_value = popups.input_prompt(prompt_msg, initial_value if is_prepopulated else "")
+ prompt_msg = '%s Value (esc to cancel): ' % config_option
+ is_prepopulated = CONFIG['features.config.prepopulateEditValues']
+ new_value = popups.input_prompt(prompt_msg, initial_value if is_prepopulated else '')
if new_value is not None and new_value != initial_value:
try:
- if selection.get(Field.TYPE) == "Boolean":
+ if selection.get(Field.TYPE) == 'Boolean':
# if the value's a boolean then allow for 'true' and 'false' inputs
- if new_value.lower() == "true":
- new_value = "1"
- elif new_value.lower() == "false":
- new_value = "0"
- elif selection.get(Field.TYPE) == "LineList":
+ if new_value.lower() == 'true':
+ new_value = '1'
+ elif new_value.lower() == 'false':
+ new_value = '0'
+ elif selection.get(Field.TYPE) == 'LineList':
# set_option accepts list inputs when there's multiple values
- new_value = new_value.split(",")
+ new_value = new_value.split(',')
tor_controller().set_conf(config_option, new_value)
@@ -416,7 +416,7 @@ class ConfigPanel(panel.Panel):
self.redraw(True)
except Exception as exc:
- popups.show_msg("%s (press any key)" % exc)
+ popups.show_msg('%s (press any key)' % exc)
elif key.match('a'):
self.show_all = not self.show_all
self.redraw(True)
@@ -447,9 +447,9 @@ class ConfigPanel(panel.Panel):
# displayed options (truncating the labels if there's limited room)
if width >= 30:
- selection_options = ("Save", "Save As...", "Cancel")
+ selection_options = ('Save', 'Save As...', 'Cancel')
else:
- selection_options = ("Save", "Save As", "X")
+ selection_options = ('Save', 'Save As', 'X')
# checks if we can show options beside the last line of visible content
@@ -488,15 +488,15 @@ class ConfigPanel(panel.Panel):
popup.win.erase()
popup.win.box()
- popup.addstr(0, 0, "Configuration being saved:", curses.A_STANDOUT)
+ popup.addstr(0, 0, 'Configuration being saved:', curses.A_STANDOUT)
visible_config_lines = height - 3 if is_option_line_separate else height - 2
for i in range(visible_config_lines):
line = str_tools.crop(config_lines[i], width - 2)
- if " " in line:
- option, arg = line.split(" ", 1)
+ if ' ' in line:
+ option, arg = line.split(' ', 1)
popup.addstr(i + 1, 1, option, curses.A_BOLD, 'green')
popup.addstr(i + 1, len(option) + 2, arg, curses.A_BOLD, 'cyan')
else:
@@ -517,9 +517,9 @@ class ConfigPanel(panel.Panel):
break
selection_format = curses.A_STANDOUT if i == selection else curses.A_NORMAL
- popup.addstr(height - 2, draw_x, "[")
+ popup.addstr(height - 2, draw_x, '[')
popup.addstr(height - 2, draw_x + 1, option_label, selection_format, curses.A_BOLD)
- popup.addstr(height - 2, draw_x + len(option_label) + 1, "]")
+ popup.addstr(height - 2, draw_x + len(option_label) + 1, ']')
draw_x -= 1 # space gap between the options
@@ -540,11 +540,11 @@ class ConfigPanel(panel.Panel):
try:
config_location = loaded_torrc.get_config_location()
except IOError:
- config_location = ""
+ config_location = ''
if selection == 1:
# prompts user for a configuration location
- config_location = popups.input_prompt("Save to (esc to cancel): ", config_location)
+ config_location = popups.input_prompt('Save to (esc to cancel): ', config_location)
if not config_location:
prompt_canceled = True
@@ -552,9 +552,9 @@ class ConfigPanel(panel.Panel):
if not prompt_canceled:
try:
tor_config.save_conf(config_location, config_lines)
- msg = "Saved configuration to %s" % config_location
+ msg = 'Saved configuration to %s' % config_location
except IOError as exc:
- msg = "Unable to save configuration (%s)" % exc.strerror
+ msg = 'Unable to save configuration (%s)' % exc.strerror
popups.show_msg(msg, 2)
finally:
@@ -577,7 +577,7 @@ class ConfigPanel(panel.Panel):
# panel with details for the current selection
- detail_panel_height = CONFIG["features.config.selectionDetails.height"]
+ detail_panel_height = CONFIG['features.config.selectionDetails.height']
is_scrollbar_visible = False
if detail_panel_height == 0 or detail_panel_height + 2 >= height:
@@ -602,9 +602,9 @@ class ConfigPanel(panel.Panel):
# draws the top label
if self.is_title_visible():
- config_type = "Tor" if self.config_type == State.TOR else "Arm"
+ config_type = 'Tor' if self.config_type == State.TOR else 'Arm'
hidden_msg = "press 'a' to hide most options" if self.show_all else "press 'a' to show all options"
- title_label = "%s Configuration (%s):" % (config_type, hidden_msg)
+ title_label = '%s Configuration (%s):' % (config_type, hidden_msg)
self.addstr(0, 0, title_label, curses.A_STANDOUT)
# draws left-hand scroll bar if content's longer than the height
@@ -615,8 +615,8 @@ class ConfigPanel(panel.Panel):
scroll_offset = 3
self.add_scroll_bar(scroll_location, scroll_location + height - detail_panel_height - 1, len(self._get_config_options()), 1 + detail_panel_height)
- option_width = CONFIG["features.config.state.colWidth.option"]
- value_width = CONFIG["features.config.state.colWidth.value"]
+ option_width = CONFIG['features.config.state.colWidth.option']
+ value_width = CONFIG['features.config.state.colWidth.value']
description_width = max(0, width - scroll_offset - option_width - value_width - 2)
# if the description column is overly long then use its space for the
@@ -667,7 +667,7 @@ class ConfigPanel(panel.Panel):
# first entry:
# <option> (<category> Option)
- option_label = " (%s Option)" % selection.get(Field.CATEGORY)
+ option_label = ' (%s Option)' % selection.get(Field.CATEGORY)
self.addstr(1, 2, selection.get(Field.OPTION) + option_label, *selection_format)
# second entry:
@@ -675,20 +675,20 @@ class ConfigPanel(panel.Panel):
if detail_panel_height >= 3:
value_attr = []
- value_attr.append("default" if selection.get(Field.IS_DEFAULT) else "custom")
+ value_attr.append('default' if selection.get(Field.IS_DEFAULT) else 'custom')
value_attr.append(selection.get(Field.TYPE))
- value_attr.append("usage: %s" % (selection.get(Field.ARG_USAGE)))
- value_attr_label = ", ".join(value_attr)
+ value_attr.append('usage: %s' % (selection.get(Field.ARG_USAGE)))
+ value_attr_label = ', '.join(value_attr)
value_label_width = width - 12 - len(value_attr_label)
value_label = str_tools.crop(selection.get(Field.VALUE), value_label_width)
- self.addstr(2, 2, "Value: %s (%s)" % (value_label, value_attr_label), *selection_format)
+ self.addstr(2, 2, 'Value: %s (%s)' % (value_label, value_attr_label), *selection_format)
# remainder is filled with the man page description
description_height = max(0, detail_panel_height - 3)
- description_content = "Description: " + selection.get(Field.DESCRIPTION)
+ description_content = 'Description: ' + selection.get(Field.DESCRIPTION)
for i in range(description_height):
# checks if we're done writing the description
@@ -699,14 +699,14 @@ class ConfigPanel(panel.Panel):
# there's a leading indent after the first line
if i > 0:
- description_content = " " + description_content
+ description_content = ' ' + description_content
# we only want to work with content up until the next newline
- if "\n" in description_content:
- line_content, description_content = description_content.split("\n", 1)
+ if '\n' in description_content:
+ line_content, description_content = description_content.split('\n', 1)
else:
- line_content, description_content = description_content, ""
+ line_content, description_content = description_content, ''
if i != description_height - 1:
# there's more lines to display
diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py
index f0e7f14..b3738c1 100644
--- a/nyx/connections/circ_entry.py
+++ b/nyx/connections/circ_entry.py
@@ -20,7 +20,7 @@ ADDRESS_LOOKUP_CACHE = {}
class CircEntry(conn_entry.ConnectionEntry):
def __init__(self, circuit_id, status, purpose, path):
- conn_entry.ConnectionEntry.__init__(self, "127.0.0.1", "0", "127.0.0.1", "0")
+ conn_entry.ConnectionEntry.__init__(self, '127.0.0.1', '0', '127.0.0.1', '0')
self.circuit_id = circuit_id
self.status = status
@@ -54,25 +54,25 @@ class CircEntry(conn_entry.ConnectionEntry):
self.lines = [self.lines[0]]
controller = tor_controller()
- if status == "BUILT" and not self.lines[0].is_built:
- exit_ip, exit_port = get_relay_address(controller, path[-1], ("192.168.0.1", "0"))
+ if status == 'BUILT' and not self.lines[0].is_built:
+ exit_ip, exit_port = get_relay_address(controller, path[-1], ('192.168.0.1', '0'))
self.lines[0].set_exit(exit_ip, exit_port, path[-1])
for i in range(len(path)):
relay_fingerprint = path[i]
- relay_ip, relay_port = get_relay_address(controller, relay_fingerprint, ("192.168.0.1", "0"))
+ relay_ip, relay_port = get_relay_address(controller, relay_fingerprint, ('192.168.0.1', '0'))
if i == len(path) - 1:
- if status == "BUILT":
- placement_type = "Exit"
+ if status == 'BUILT':
+ placement_type = 'Exit'
else:
- placement_type = "Extending"
+ placement_type = 'Extending'
elif i == 0:
- placement_type = "Guard"
+ placement_type = 'Guard'
else:
- placement_type = "Middle"
+ placement_type = 'Middle'
- placement_label = "%i / %s" % (i + 1, placement_type)
+ placement_label = '%i / %s' % (i + 1, placement_type)
self.lines.append(CircLine(relay_ip, relay_port, relay_fingerprint, placement_label))
@@ -86,13 +86,13 @@ class CircHeaderLine(conn_entry.ConnectionLine):
"""
def __init__(self, circuit_id, purpose):
- conn_entry.ConnectionLine.__init__(self, "127.0.0.1", "0", "0.0.0.0", "0", False, False)
+ conn_entry.ConnectionLine.__init__(self, '127.0.0.1', '0', '0.0.0.0', '0', False, False)
self.circuit_id = circuit_id
self.purpose = purpose
self.is_built = False
def set_exit(self, exit_address, exit_port, exit_fingerprint):
- conn_entry.ConnectionLine.__init__(self, "127.0.0.1", "0", exit_address, exit_port, False, False)
+ conn_entry.ConnectionLine.__init__(self, '127.0.0.1', '0', exit_address, exit_port, False, False)
self.is_built = True
self.foreign.fingerprint_overwrite = exit_fingerprint
@@ -101,7 +101,7 @@ class CircHeaderLine(conn_entry.ConnectionLine):
def get_destination_label(self, max_length, include_locale=False, include_hostname=False):
if not self.is_built:
- return "Building..."
+ return 'Building...'
return conn_entry.ConnectionLine.get_destination_label(self, max_length, include_locale, include_hostname)
@@ -111,20 +111,20 @@ class CircHeaderLine(conn_entry.ConnectionLine):
shown completely (not enough room) is dropped.
"""
- etc_attr = ["Purpose: %s" % self.purpose, "Circuit ID: %s" % self.circuit_id]
+ etc_attr = ['Purpose: %s' % self.purpose, 'Circuit ID: %s' % self.circuit_id]
for i in range(len(etc_attr), -1, -1):
- etc_label = ", ".join(etc_attr[:i])
+ etc_label = ', '.join(etc_attr[:i])
if len(etc_label) <= width:
- return ("%%-%is" % width) % etc_label
+ return ('%%-%is' % width) % etc_label
- return ""
+ return ''
def get_details(self, width):
if not self.is_built:
detail_format = (curses.A_BOLD, conn_entry.CATEGORY_COLOR[self.get_type()])
- return [("Building Circuit...", detail_format)]
+ return [('Building Circuit...', detail_format)]
else:
return conn_entry.ConnectionLine.get_details(self, width)
@@ -137,7 +137,7 @@ class CircLine(conn_entry.ConnectionLine):
"""
def __init__(self, remote_address, remote_port, remote_fingerprint, placement_label):
- conn_entry.ConnectionLine.__init__(self, "127.0.0.1", "0", remote_address, remote_port)
+ conn_entry.ConnectionLine.__init__(self, '127.0.0.1', '0', remote_address, remote_port)
self.foreign.fingerprint_overwrite = remote_fingerprint
self.placement_label = placement_label
self.include_port = False
@@ -182,42 +182,42 @@ class CircLine(conn_entry.ConnectionLine):
baseline_space = 14 + 5
- dst, etc = "", ""
+ dst, etc = '', ''
if listing_type == entries.ListingType.IP_ADDRESS:
# TODO: include hostname when that's available
# dst width is derived as:
# src (21) + dst (26) + divider (7) + right gap (2) - bracket (3) = 53 char
- dst = "%-53s" % self.get_destination_label(53, include_locale = True)
+ dst = '%-53s' % self.get_destination_label(53, include_locale = True)
# fills the nickname into the empty space here
- dst = "%s%-25s " % (dst[:25], str_tools.crop(self.foreign.get_nickname(), 25, 0))
+ dst = '%s%-25s ' % (dst[:25], str_tools.crop(self.foreign.get_nickname(), 25, 0))
etc = self.get_etc_content(width - baseline_space - len(dst), listing_type)
elif listing_type == entries.ListingType.HOSTNAME:
# min space for the hostname is 40 characters
etc = self.get_etc_content(width - baseline_space - 40, listing_type)
- dst_layout = "%%-%is" % (width - baseline_space - len(etc))
+ dst_layout = '%%-%is' % (width - baseline_space - len(etc))
dst = dst_layout % self.foreign.get_hostname(self.foreign.get_address())
elif listing_type == entries.ListingType.FINGERPRINT:
# dst width is derived as:
# src (9) + dst (40) + divider (7) + right gap (2) - bracket (3) = 55 char
- dst = "%-55s" % self.foreign.get_fingerprint()
+ dst = '%-55s' % self.foreign.get_fingerprint()
etc = self.get_etc_content(width - baseline_space - len(dst), listing_type)
else:
# min space for the nickname is 56 characters
etc = self.get_etc_content(width - baseline_space - 56, listing_type)
- dst_layout = "%%-%is" % (width - baseline_space - len(etc))
+ dst_layout = '%%-%is' % (width - baseline_space - len(etc))
dst = dst_layout % self.foreign.get_nickname()
return ((dst + etc, line_format),
- (" " * (width - baseline_space - len(dst) - len(etc) + 5), line_format),
- ("%-14s" % self.placement_label, line_format))
+ (' ' * (width - baseline_space - len(dst) - len(etc) + 5), line_format),
+ ('%-14s' % self.placement_label, line_format))
def get_relay_address(controller, relay_fingerprint, default = None):
@@ -234,10 +234,10 @@ def get_relay_address(controller, relay_fingerprint, default = None):
if controller.is_alive():
# query the address if it isn't yet cached
if relay_fingerprint not in ADDRESS_LOOKUP_CACHE:
- if relay_fingerprint == controller.get_info("fingerprint", None):
+ if relay_fingerprint == controller.get_info('fingerprint', None):
# this is us, simply check the config
- my_address = controller.get_info("address", None)
- my_or_port = controller.get_conf("ORPort", None)
+ my_address = controller.get_info('address', None)
+ my_or_port = controller.get_conf('ORPort', None)
if my_address and my_or_port:
ADDRESS_LOOKUP_CACHE[relay_fingerprint] = (my_address, my_or_port)
diff --git a/nyx/connections/conn_entry.py b/nyx/connections/conn_entry.py
index 4979de3..cfd4fa3 100644
--- a/nyx/connections/conn_entry.py
+++ b/nyx/connections/conn_entry.py
@@ -23,37 +23,37 @@ from stem.util import conf, connection, enum, str_tools
# Directory Fetching tor consensus information.
# Control Tor controller (nyx, vidalia, etc).
-Category = enum.Enum("INBOUND", "OUTBOUND", "EXIT", "HIDDEN", "SOCKS", "CIRCUIT", "DIRECTORY", "CONTROL")
+Category = enum.Enum('INBOUND', 'OUTBOUND', 'EXIT', 'HIDDEN', 'SOCKS', 'CIRCUIT', 'DIRECTORY', 'CONTROL')
CATEGORY_COLOR = {
- Category.INBOUND: "green",
- Category.OUTBOUND: "blue",
- Category.EXIT: "red",
- Category.HIDDEN: "magenta",
- Category.SOCKS: "yellow",
- Category.CIRCUIT: "cyan",
- Category.DIRECTORY: "magenta",
- Category.CONTROL: "red",
+ Category.INBOUND: 'green',
+ Category.OUTBOUND: 'blue',
+ Category.EXIT: 'red',
+ Category.HIDDEN: 'magenta',
+ Category.SOCKS: 'yellow',
+ Category.CIRCUIT: 'cyan',
+ Category.DIRECTORY: 'magenta',
+ Category.CONTROL: 'red',
}
# static data for listing format
# <src> --> <dst> <etc><padding>
-LABEL_FORMAT = "%s --> %s %s%s"
+LABEL_FORMAT = '%s --> %s %s%s'
LABEL_MIN_PADDING = 2 # min space between listing label and following data
# sort value for scrubbed ip addresses
SCRUBBED_IP_VAL = 255 ** 4
-CONFIG = conf.config_dict("nyx", {
- "features.connection.markInitialConnections": True,
- "features.connection.showIps": True,
- "features.connection.showExitPort": True,
- "features.connection.showColumn.fingerprint": True,
- "features.connection.showColumn.nickname": True,
- "features.connection.showColumn.destination": True,
- "features.connection.showColumn.expandedIp": True,
+CONFIG = conf.config_dict('nyx', {
+ 'features.connection.markInitialConnections': True,
+ 'features.connection.showIps': True,
+ 'features.connection.showExitPort': True,
+ 'features.connection.showColumn.fingerprint': True,
+ 'features.connection.showColumn.nickname': True,
+ 'features.connection.showColumn.destination': True,
+ 'features.connection.showColumn.expandedIp': True,
})
FINGERPRINT_TRACKER = None
@@ -134,7 +134,7 @@ class Endpoint:
"""
controller = tor_controller()
- return controller.get_info("ip-to-country/%s" % self.address, default)
+ return controller.get_info('ip-to-country/%s' % self.address, default)
def get_fingerprint(self):
"""
@@ -156,7 +156,7 @@ class Endpoint:
if my_fingerprint:
return my_fingerprint
else:
- return "UNKNOWN"
+ return 'UNKNOWN'
def get_nickname(self):
"""
@@ -166,15 +166,15 @@ class Endpoint:
my_fingerprint = self.get_fingerprint()
- if my_fingerprint != "UNKNOWN":
+ if my_fingerprint != 'UNKNOWN':
my_nickname = get_fingerprint_tracker().get_relay_nickname(my_fingerprint)
if my_nickname:
return my_nickname
else:
- return "UNKNOWN"
+ return 'UNKNOWN'
else:
- return "UNKNOWN"
+ return 'UNKNOWN'
class ConnectionEntry(entries.ConnectionPanelEntry):
@@ -204,16 +204,16 @@ class ConnectionEntry(entries.ConnectionPanelEntry):
return connection_line.sort_port
elif attr == entries.SortAttr.HOSTNAME:
if connection_line.is_private():
- return ""
+ return ''
- return connection_line.foreign.get_hostname("")
+ return connection_line.foreign.get_hostname('')
elif attr == entries.SortAttr.FINGERPRINT:
return connection_line.foreign.get_fingerprint()
elif attr == entries.SortAttr.NICKNAME:
my_nickname = connection_line.foreign.get_nickname()
- if my_nickname == "UNKNOWN":
- return "z" * 20 # orders at the end
+ if my_nickname == 'UNKNOWN':
+ return 'z' * 20 # orders at the end
else:
return my_nickname.lower()
elif attr == entries.SortAttr.CATEGORY:
@@ -222,9 +222,9 @@ class ConnectionEntry(entries.ConnectionPanelEntry):
return connection_line.start_time
elif attr == entries.SortAttr.COUNTRY:
if connection.is_private_address(self.lines[0].foreign.get_address()):
- return ""
+ return ''
else:
- return connection_line.foreign.get_locale("")
+ return connection_line.foreign.get_locale('')
else:
return entries.ConnectionPanelEntry.get_sort_value(self, attr, listing_type)
@@ -245,7 +245,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# overwrite the local fingerprint with ours
controller = tor_controller()
- self.local.fingerprint_overwrite = controller.get_info("fingerprint", None)
+ self.local.fingerprint_overwrite = controller.get_info('fingerprint', None)
# True if the connection has matched the properties of a client/directory
# connection every time we've checked. The criteria we check is...
@@ -262,18 +262,18 @@ class ConnectionLine(entries.ConnectionPanelLine):
self.application_pid = None
self.is_application_resolving = False
- my_or_port = controller.get_conf("ORPort", None)
- my_dir_port = controller.get_conf("DirPort", None)
- my_socks_port = controller.get_conf("SocksPort", "9050")
- my_ctl_port = controller.get_conf("ControlPort", None)
+ my_or_port = controller.get_conf('ORPort', None)
+ my_dir_port = controller.get_conf('DirPort', None)
+ my_socks_port = controller.get_conf('SocksPort', '9050')
+ my_ctl_port = controller.get_conf('ControlPort', None)
my_hidden_service_ports = get_hidden_service_ports(controller)
# the ORListenAddress can overwrite the ORPort
- listen_addr = controller.get_conf("ORListenAddress", None)
+ listen_addr = controller.get_conf('ORListenAddress', None)
- if listen_addr and ":" in listen_addr:
- my_or_port = listen_addr[listen_addr.find(":") + 1:]
+ if listen_addr and ':' in listen_addr:
+ my_or_port = listen_addr[listen_addr.find(':') + 1:]
if local_port in (my_or_port, my_dir_port):
self.base_type = Category.INBOUND
@@ -300,7 +300,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
ip_value = 0
- for comp in self.foreign.get_address().split("."):
+ for comp in self.foreign.get_address().split('.'):
ip_value *= 255
ip_value += int(comp)
@@ -346,12 +346,12 @@ class ConnectionLine(entries.ConnectionPanelLine):
# fill in the current uptime and return the results
- if CONFIG["features.connection.markInitialConnections"]:
- time_prefix = "+" if self.is_initial_connection else " "
+ if CONFIG['features.connection.markInitialConnections']:
+ time_prefix = '+' if self.is_initial_connection else ' '
else:
- time_prefix = ""
+ time_prefix = ''
- time_label = time_prefix + "%5s" % str_tools.time_label(current_time - self.start_time, 1)
+ time_label = time_prefix + '%5s' % str_tools.time_label(current_time - self.start_time, 1)
my_listing[2] = (time_label, my_listing[2][1])
return my_listing
@@ -375,14 +375,14 @@ class ConnectionLine(entries.ConnectionPanelLine):
# postType - ") "
line_format = CATEGORY_COLOR[entry_type]
- time_width = 6 if CONFIG["features.connection.markInitialConnections"] else 5
+ time_width = 6 if CONFIG['features.connection.markInitialConnections'] else 5
- draw_entry = [(" ", line_format),
+ draw_entry = [(' ', line_format),
(self._get_listing_content(width - (12 + time_width) - 1, listing_type), line_format),
- (" " * time_width, line_format),
- (" (", line_format),
+ (' ' * time_width, line_format),
+ (' (', line_format),
(entry_type.upper(), line_format, curses.A_BOLD),
- (")" + " " * (9 - len(entry_type)), line_format)]
+ (')' + ' ' * (9 - len(entry_type)), line_format)]
return draw_entry
@@ -408,7 +408,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
connection or exit traffic.
"""
- if not CONFIG["features.connection.showIps"]:
+ if not CONFIG['features.connection.showIps']:
return True
# This is used to scrub private information from the interface. Relaying
@@ -424,7 +424,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
controller = tor_controller()
my_flags = []
- my_fingerprint = self.get_info("fingerprint", None)
+ my_fingerprint = self.get_info('fingerprint', None)
if my_fingerprint:
my_status_entry = self.controller.get_network_status(my_fingerprint)
@@ -432,7 +432,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
if my_status_entry:
my_flags = my_status_entry.flags
- if "Guard" in my_flags or controller.get_conf("BridgeRelay", None) == "1":
+ if 'Guard' in my_flags or controller.get_conf('BridgeRelay', None) == '1':
all_matches = get_fingerprint_tracker().get_relay_fingerprint(self.foreign.get_address(), get_all_matches = True)
return all_matches == []
@@ -445,7 +445,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# will take a bit more work to propagate the information up from the
# connection resolver.
- return self.foreign.get_port() != "53"
+ return self.foreign.get_port() != '53'
# for everything else this isn't a concern
@@ -474,7 +474,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
controller = tor_controller()
destination_fingerprint = self.foreign.get_fingerprint()
- if destination_fingerprint == "UNKNOWN":
+ if destination_fingerprint == 'UNKNOWN':
# Not a known relay. This might be an exit connection.
if is_exiting_allowed(controller, self.foreign.get_address(), self.foreign.get_port()):
@@ -493,7 +493,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# mirror).
for circ in my_circuits:
- if circ.path and circ.path[0][0] == destination_fingerprint and (circ.status != "BUILT" or len(circ.path) > 1):
+ if circ.path and circ.path[0][0] == destination_fingerprint and (circ.status != 'BUILT' or len(circ.path) > 1):
self.cached_type = Category.CIRCUIT # matched a probable guard connection
# if we fell through, we can eliminate ourselves as a guard in the future
@@ -504,7 +504,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# Checks if we match a built, single hop circuit.
for circ in my_circuits:
- if circ.path and circ.path[0][0] == destination_fingerprint and circ.status == "BUILT" and len(circ.path) == 1:
+ if circ.path and circ.path[0][0] == destination_fingerprint and circ.status == 'BUILT' and len(circ.path) == 1:
self.cached_type = Category.DIRECTORY
# if we fell through, eliminate ourselves as a directory connection
@@ -528,58 +528,58 @@ class ConnectionLine(entries.ConnectionPanelLine):
# for applications show the command/pid
if self.get_type() in (Category.SOCKS, Category.HIDDEN, Category.CONTROL):
- display_label = ""
+ display_label = ''
if self.application_name:
if self.application_pid:
- display_label = "%s (%s)" % (self.application_name, self.application_pid)
+ display_label = '%s (%s)' % (self.application_name, self.application_pid)
else:
display_label = self.application_name
elif self.is_application_resolving:
- display_label = "resolving..."
+ display_label = 'resolving...'
else:
- display_label = "UNKNOWN"
+ display_label = 'UNKNOWN'
if len(display_label) < width:
- return ("%%-%is" % width) % display_label
+ return ('%%-%is' % width) % display_label
else:
- return ""
+ return ''
# for everything else display connection/consensus information
destination_address = self.get_destination_label(26, include_locale = True)
- etc, used_space = "", 0
+ etc, used_space = '', 0
if listing_type == entries.ListingType.IP_ADDRESS:
- if width > used_space + 42 and CONFIG["features.connection.showColumn.fingerprint"]:
+ if width > used_space + 42 and CONFIG['features.connection.showColumn.fingerprint']:
# show fingerprint (column width: 42 characters)
- etc += "%-40s " % self.foreign.get_fingerprint()
+ etc += '%-40s ' % self.foreign.get_fingerprint()
used_space += 42
- if width > used_space + 10 and CONFIG["features.connection.showColumn.nickname"]:
+ if width > used_space + 10 and CONFIG['features.connection.showColumn.nickname']:
# show nickname (column width: remainder)
nickname_space = width - used_space
nickname_label = str_tools.crop(self.foreign.get_nickname(), nickname_space, 0)
- etc += ("%%-%is " % nickname_space) % nickname_label
+ etc += ('%%-%is ' % nickname_space) % nickname_label
used_space += nickname_space + 2
elif listing_type == entries.ListingType.HOSTNAME:
- if width > used_space + 28 and CONFIG["features.connection.showColumn.destination"]:
+ if width > used_space + 28 and CONFIG['features.connection.showColumn.destination']:
# show destination ip/port/locale (column width: 28 characters)
- etc += "%-26s " % destination_address
+ etc += '%-26s ' % destination_address
used_space += 28
- if width > used_space + 42 and CONFIG["features.connection.showColumn.fingerprint"]:
+ if width > used_space + 42 and CONFIG['features.connection.showColumn.fingerprint']:
# show fingerprint (column width: 42 characters)
- etc += "%-40s " % self.foreign.get_fingerprint()
+ etc += '%-40s ' % self.foreign.get_fingerprint()
used_space += 42
- if width > used_space + 17 and CONFIG["features.connection.showColumn.nickname"]:
+ if width > used_space + 17 and CONFIG['features.connection.showColumn.nickname']:
# show nickname (column width: min 17 characters, uses half of the remainder)
nickname_space = 15 + (width - (used_space + 17)) / 2
nickname_label = str_tools.crop(self.foreign.get_nickname(), nickname_space, 0)
- etc += ("%%-%is " % nickname_space) % nickname_label
+ etc += ('%%-%is ' % nickname_space) % nickname_label
used_space += (nickname_space + 2)
elif listing_type == entries.ListingType.FINGERPRINT:
if width > used_space + 17:
@@ -591,31 +591,31 @@ class ConnectionLine(entries.ConnectionPanelLine):
# ip/port/locale (column width: 28 characters)
is_locale_included = width > used_space + 45
- is_locale_included &= CONFIG["features.connection.showColumn.destination"]
+ is_locale_included &= CONFIG['features.connection.showColumn.destination']
if is_locale_included:
nickname_space -= 28
- if CONFIG["features.connection.showColumn.nickname"]:
+ if CONFIG['features.connection.showColumn.nickname']:
nickname_label = str_tools.crop(self.foreign.get_nickname(), nickname_space, 0)
- etc += ("%%-%is " % nickname_space) % nickname_label
+ etc += ('%%-%is ' % nickname_space) % nickname_label
used_space += nickname_space + 2
if is_locale_included:
- etc += "%-26s " % destination_address
+ etc += '%-26s ' % destination_address
used_space += 28
else:
- if width > used_space + 42 and CONFIG["features.connection.showColumn.fingerprint"]:
+ if width > used_space + 42 and CONFIG['features.connection.showColumn.fingerprint']:
# show fingerprint (column width: 42 characters)
- etc += "%-40s " % self.foreign.get_fingerprint()
+ etc += '%-40s ' % self.foreign.get_fingerprint()
used_space += 42
- if width > used_space + 28 and CONFIG["features.connection.showColumn.destination"]:
+ if width > used_space + 28 and CONFIG['features.connection.showColumn.destination']:
# show destination ip/port/locale (column width: 28 characters)
- etc += "%-26s " % destination_address
+ etc += '%-26s ' % destination_address
used_space += 28
- return ("%%-%is" % width) % etc
+ return ('%%-%is' % width) % etc
def _get_listing_content(self, width, listing_type):
"""
@@ -635,13 +635,13 @@ class ConnectionLine(entries.ConnectionPanelLine):
# - base data for the listing
# - that extra field plus any previous
- used_space = len(LABEL_FORMAT % tuple([""] * 4)) + LABEL_MIN_PADDING
- local_port = ":%s" % self.local.get_port() if self.include_port else ""
+ used_space = len(LABEL_FORMAT % tuple([''] * 4)) + LABEL_MIN_PADDING
+ local_port = ':%s' % self.local.get_port() if self.include_port else ''
- src, dst, etc = "", "", ""
+ src, dst, etc = '', '', ''
if listing_type == entries.ListingType.IP_ADDRESS:
- my_external_address = controller.get_info("address", self.local.get_address())
+ my_external_address = controller.get_info('address', self.local.get_address())
address_differ = my_external_address != self.local.get_address()
# Expanding doesn't make sense, if the connection isn't actually
@@ -665,11 +665,11 @@ class ConnectionLine(entries.ConnectionPanelLine):
# (their fingerprint and nickname are both for us). Reversing the
# fields here to keep the same column alignments.
- src = "%-21s" % destination_address
- dst = "%-26s" % src_address
+ src = '%-21s' % destination_address
+ dst = '%-26s' % src_address
else:
- src = "%-21s" % src_address # ip:port = max of 21 characters
- dst = "%-26s" % destination_address # ip:port (xx) = max of 26 characters
+ src = '%-21s' % src_address # ip:port = max of 21 characters
+ dst = '%-26s' % destination_address # ip:port (xx) = max of 26 characters
used_space += len(src) + len(dst) # base data requires 47 characters
@@ -679,10 +679,10 @@ class ConnectionLine(entries.ConnectionPanelLine):
is_expanded_address_visible = width > used_space + 28
- if is_expanded_address_visible and CONFIG["features.connection.showColumn.fingerprint"]:
+ if is_expanded_address_visible and CONFIG['features.connection.showColumn.fingerprint']:
is_expanded_address_visible = width < used_space + 42 or width > used_space + 70
- if address_differ and is_expansion_type and is_expanded_address_visible and self.include_expanded_addresses and CONFIG["features.connection.showColumn.expandedIp"]:
+ if address_differ and is_expansion_type and is_expanded_address_visible and self.include_expanded_addresses and CONFIG['features.connection.showColumn.expandedIp']:
# include the internal address in the src (extra 28 characters)
internal_address = self.local.get_address() + local_port
@@ -692,9 +692,9 @@ class ConnectionLine(entries.ConnectionPanelLine):
# when the src and dst are swapped later
if my_type == Category.INBOUND:
- src = "%-21s --> %s" % (src, internal_address)
+ src = '%-21s --> %s' % (src, internal_address)
else:
- src = "%-21s --> %s" % (internal_address, src)
+ src = '%-21s --> %s' % (internal_address, src)
used_space += 28
@@ -705,7 +705,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
# TODO: when actually functional the src and dst need to be swapped for
# SOCKS and CONTROL connections
- src = "localhost%-6s" % local_port
+ src = 'localhost%-6s' % local_port
used_space += len(src)
min_hostname_space = 40
@@ -716,24 +716,24 @@ class ConnectionLine(entries.ConnectionPanelLine):
used_space = width # prevents padding at the end
if self.is_private():
- dst = ("%%-%is" % hostname_space) % "<scrubbed>"
+ dst = ('%%-%is' % hostname_space) % '<scrubbed>'
else:
hostname = self.foreign.get_hostname(self.foreign.get_address())
- port_label = ":%-5s" % self.foreign.get_port() if self.include_port else ""
+ port_label = ':%-5s' % self.foreign.get_port() if self.include_port else ''
# truncates long hostnames and sets dst to <hostname>:<port>
hostname = str_tools.crop(hostname, hostname_space, 0)
- dst = ("%%-%is" % hostname_space) % (hostname + port_label)
+ dst = ('%%-%is' % hostname_space) % (hostname + port_label)
elif listing_type == entries.ListingType.FINGERPRINT:
- src = "localhost"
+ src = 'localhost'
if my_type == Category.CONTROL:
- dst = "localhost"
+ dst = 'localhost'
else:
dst = self.foreign.get_fingerprint()
- dst = "%-40s" % dst
+ dst = '%-40s' % dst
used_space += len(src) + len(dst) # base data requires 49 characters
@@ -762,12 +762,12 @@ class ConnectionLine(entries.ConnectionPanelLine):
# pads dst entry to its max space
- dst = ("%%-%is" % (base_space - len(src))) % dst
+ dst = ('%%-%is' % (base_space - len(src))) % dst
if my_type == Category.INBOUND:
src, dst = dst, src
- padding = " " * (width - used_space + LABEL_MIN_PADDING)
+ padding = ' ' * (width - used_space + LABEL_MIN_PADDING)
return LABEL_FORMAT % (src, dst, etc, padding)
@@ -779,9 +779,9 @@ class ConnectionLine(entries.ConnectionPanelLine):
width - max length of lines
"""
- lines = [""] * 7
- lines[0] = "address: %s" % self.get_destination_label(width - 11)
- lines[1] = "locale: %s" % ("??" if self.is_private() else self.foreign.get_locale("??"))
+ lines = [''] * 7
+ lines[0] = 'address: %s' % self.get_destination_label(width - 11)
+ lines[1] = 'locale: %s' % ('??' if self.is_private() else self.foreign.get_locale('??'))
# Remaining data concerns the consensus results, with three possible cases:
# - if there's a single match then display its details
@@ -793,15 +793,15 @@ class ConnectionLine(entries.ConnectionPanelLine):
fingerprint = self.foreign.get_fingerprint()
controller = tor_controller()
- if fingerprint != "UNKNOWN":
+ if fingerprint != 'UNKNOWN':
# single match - display information available about it
- ns_entry = controller.get_info("ns/id/%s" % fingerprint, None)
- desc_entry = controller.get_info("desc/id/%s" % fingerprint, None)
+ ns_entry = controller.get_info('ns/id/%s' % fingerprint, None)
+ desc_entry = controller.get_info('desc/id/%s' % fingerprint, None)
# append the fingerprint to the second line
- lines[1] = "%-13sfingerprint: %s" % (lines[1], fingerprint)
+ lines[1] = '%-13sfingerprint: %s' % (lines[1], fingerprint)
if ns_entry:
# example consensus entry:
@@ -810,18 +810,18 @@ class ConnectionLine(entries.ConnectionPanelLine):
# w Bandwidth=2540
# p accept 20-23,43,53,79-81,88,110,143,194,443
- ns_lines = ns_entry.split("\n")
+ ns_lines = ns_entry.split('\n')
- first_line_comp = ns_lines[0].split(" ")
+ first_line_comp = ns_lines[0].split(' ')
if len(first_line_comp) >= 9:
_, nickname, _, _, published_date, published_time, _, or_port, dir_port = first_line_comp[:9]
else:
- nickname, published_date, published_time, or_port, dir_port = "", "", "", "", ""
+ nickname, published_date, published_time, or_port, dir_port = '', '', '', '', ''
- flags = "unknown"
+ flags = 'unknown'
- if len(ns_lines) >= 2 and ns_lines[1].startswith("s "):
+ if len(ns_lines) >= 2 and ns_lines[1].startswith('s '):
flags = ns_lines[1][2:]
exit_policy = None
@@ -833,62 +833,62 @@ class ConnectionLine(entries.ConnectionPanelLine):
if exit_policy:
policy_label = exit_policy.summary()
else:
- policy_label = "unknown"
+ policy_label = 'unknown'
- dir_port_label = "" if dir_port == "0" else "dirport: %s" % dir_port
- lines[2] = "nickname: %-25s orport: %-10s %s" % (nickname, or_port, dir_port_label)
- lines[3] = "published: %s %s" % (published_time, published_date)
- lines[4] = "flags: %s" % flags.replace(" ", ", ")
- lines[5] = "exit policy: %s" % policy_label
+ dir_port_label = '' if dir_port == '0' else 'dirport: %s' % dir_port
+ lines[2] = 'nickname: %-25s orport: %-10s %s' % (nickname, or_port, dir_port_label)
+ lines[3] = 'published: %s %s' % (published_time, published_date)
+ lines[4] = 'flags: %s' % flags.replace(' ', ', ')
+ lines[5] = 'exit policy: %s' % policy_label
if desc_entry:
- tor_version, platform, contact = "", "", ""
+ tor_version, platform, contact = '', '', ''
- for desc_line in desc_entry.split("\n"):
- if desc_line.startswith("platform"):
+ for desc_line in desc_entry.split('\n'):
+ if desc_line.startswith('platform'):
# has the tor version and platform, ex:
# platform Tor 0.2.1.29 (r318f470bc5f2ad43) on Linux x86_64
- tor_version = desc_line[13:desc_line.find(" ", 13)]
- platform = desc_line[desc_line.rfind(" on ") + 4:]
- elif desc_line.startswith("contact"):
+ tor_version = desc_line[13:desc_line.find(' ', 13)]
+ platform = desc_line[desc_line.rfind(' on ') + 4:]
+ elif desc_line.startswith('contact'):
contact = desc_line[8:]
# clears up some highly common obscuring
- for alias in (" at ", " AT "):
- contact = contact.replace(alias, "@")
+ for alias in (' at ', ' AT '):
+ contact = contact.replace(alias, '@')
- for alias in (" dot ", " DOT "):
- contact = contact.replace(alias, ".")
+ for alias in (' dot ', ' DOT '):
+ contact = contact.replace(alias, '.')
break # contact lines come after the platform
- lines[3] = "%-35s os: %-14s version: %s" % (lines[3], platform, tor_version)
+ lines[3] = '%-35s os: %-14s version: %s' % (lines[3], platform, tor_version)
# contact information is an optional field
if contact:
- lines[6] = "contact: %s" % contact
+ lines[6] = 'contact: %s' % contact
else:
all_matches = get_fingerprint_tracker().get_relay_fingerprint(self.foreign.get_address(), get_all_matches = True)
if all_matches:
# multiple matches
- lines[2] = "Multiple matches, possible fingerprints are:"
+ lines[2] = 'Multiple matches, possible fingerprints are:'
for i in range(len(all_matches)):
is_last_line = i == 3
relay_port, relay_fingerprint = all_matches[i]
- line_text = "%i. or port: %-5s fingerprint: %s" % (i, relay_port, relay_fingerprint)
+ line_text = '%i. or port: %-5s fingerprint: %s' % (i, relay_port, relay_fingerprint)
# if there's multiple lines remaining at the end then give a count
remaining_relays = len(all_matches) - i
if is_last_line and remaining_relays > 1:
- line_text = "... %i more" % remaining_relays
+ line_text = '... %i more' % remaining_relays
lines[3 + i] = line_text
@@ -896,7 +896,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
break
else:
# no consensus entry for this ip address
- lines[2] = "No consensus data found"
+ lines[2] = 'No consensus data found'
# crops any lines that are too long
@@ -925,12 +925,12 @@ class ConnectionLine(entries.ConnectionPanelLine):
# the port and port derived data can be hidden by config or without include_port
- include_port = self.include_port and (CONFIG["features.connection.showExitPort"] or self.get_type() != Category.EXIT)
+ include_port = self.include_port and (CONFIG['features.connection.showExitPort'] or self.get_type() != Category.EXIT)
# destination of the connection
- address_label = "<scrubbed>" if self.is_private() else self.foreign.get_address()
- port_label = ":%s" % self.foreign.get_port() if include_port else ""
+ address_label = '<scrubbed>' if self.is_private() else self.foreign.get_address()
+ port_label = ':%s' % self.foreign.get_port() if include_port else ''
destination_address = address_label + port_label
# Only append the extra info if there's at least a couple characters of
@@ -946,20 +946,20 @@ class ConnectionLine(entries.ConnectionPanelLine):
# BitTorrent is a common protocol to truncate, so just use "Torrent"
# if there's not enough room.
- if len(purpose) > space_available and purpose == "BitTorrent":
- purpose = "Torrent"
+ if len(purpose) > space_available and purpose == 'BitTorrent':
+ purpose = 'Torrent'
# crops with a hyphen if too long
purpose = str_tools.crop(purpose, space_available, ending = str_tools.Ending.HYPHEN)
- destination_address += " (%s)" % purpose
+ destination_address += ' (%s)' % purpose
elif not connection.is_private_address(self.foreign.get_address()):
extra_info = []
controller = tor_controller()
if include_locale and not controller.is_geoip_unavailable():
- foreign_locale = self.foreign.get_locale("??")
+ foreign_locale = self.foreign.get_locale('??')
extra_info.append(foreign_locale)
space_available -= len(foreign_locale) + 2
@@ -976,7 +976,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
space_available -= len(destination_hostname)
if extra_info:
- destination_address += " (%s)" % ", ".join(extra_info)
+ destination_address += ' (%s)' % ', '.join(extra_info)
return destination_address[:max_length]
@@ -990,9 +990,9 @@ def get_hidden_service_ports(controller, default = []):
"""
result = []
- hs_options = controller.get_conf_map("HiddenServiceOptions", {})
+ hs_options = controller.get_conf_map('HiddenServiceOptions', {})
- for entry in hs_options.get("HiddenServicePort", []):
+ for entry in hs_options.get('HiddenServicePort', []):
# HiddenServicePort entries are of the form...
#
# VIRTPORT [TARGET]
@@ -1040,7 +1040,7 @@ def is_exiting_allowed(controller, ip_address, port):
our_policy = controller.get_exit_policy(None)
- if our_policy and our_policy.is_exiting_allowed() and port == "53":
+ if our_policy and our_policy.is_exiting_allowed() and port == '53':
result = True
else:
result = our_policy and our_policy.can_exit_to(ip_address, port)
@@ -1166,9 +1166,9 @@ class FingerprintTracker:
if controller.is_alive():
# query the nickname if it isn't yet cached
if relay_fingerprint not in self._nickname_lookup_cache:
- if relay_fingerprint == controller.get_info("fingerprint", None):
+ if relay_fingerprint == controller.get_info('fingerprint', None):
# this is us, simply check the config
- my_nickname = controller.get_conf("Nickname", "Unnamed")
+ my_nickname = controller.get_conf('Nickname', 'Unnamed')
self._nickname_lookup_cache[relay_fingerprint] = my_nickname
else:
ns_entry = controller.get_network_status(relay_fingerprint, None)
@@ -1197,9 +1197,9 @@ class FingerprintTracker:
# checks if this matches us
- if relay_address == controller.get_info("address", None):
- if not relay_port or str(relay_port) == controller.get_conf("ORPort", None):
- return controller.get_info("fingerprint", None)
+ if relay_address == controller.get_info('address', None):
+ if not relay_port or str(relay_port) == controller.get_conf('ORPort', None):
+ return controller.get_info('fingerprint', None)
# if we haven't yet populated the ip -> fingerprint mappings then do so
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index f02eef8..786cf9c 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -22,27 +22,27 @@ DETAILS_HEIGHT = 7
# listing types
-Listing = enum.Enum(("IP_ADDRESS", "IP Address"), "HOSTNAME", "FINGERPRINT", "NICKNAME")
+Listing = enum.Enum(('IP_ADDRESS', 'IP Address'), 'HOSTNAME', 'FINGERPRINT', 'NICKNAME')
def conf_handler(key, value):
- if key == "features.connection.listing_type":
+ if key == 'features.connection.listing_type':
return conf.parse_enum(key, value, Listing)
- elif key == "features.connection.refreshRate":
+ elif key == 'features.connection.refreshRate':
return max(1, value)
- elif key == "features.connection.order":
+ elif key == 'features.connection.order':
return conf.parse_enum_csv(key, value[0], entries.SortAttr, 3)
-CONFIG = conf.config_dict("nyx", {
- "features.connection.resolveApps": True,
- "features.connection.listing_type": Listing.IP_ADDRESS,
- "features.connection.order": [
+CONFIG = conf.config_dict('nyx', {
+ 'features.connection.resolveApps': True,
+ 'features.connection.listing_type': Listing.IP_ADDRESS,
+ 'features.connection.order': [
entries.SortAttr.CATEGORY,
entries.SortAttr.LISTING,
entries.SortAttr.UPTIME],
- "features.connection.refreshRate": 5,
- "features.connection.showIps": True,
+ 'features.connection.refreshRate': 5,
+ 'features.connection.showIps': True,
}, conf_handler)
@@ -53,7 +53,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
"""
def __init__(self, stdscr):
- panel.Panel.__init__(self, stdscr, "connections", 0)
+ panel.Panel.__init__(self, stdscr, 'connections', 0)
threading.Thread.__init__(self)
self.setDaemon(True)
@@ -63,12 +63,12 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# TODO: This is a little sucky in that it won't work if showIps changes
# while we're running (... but nyx doesn't allow for that atm)
- if not CONFIG["features.connection.showIps"] and CONFIG["features.connection.listing_type"] == 0:
- nyx_config = conf.get_config("nyx")
- nyx_config.set("features.connection.listing_type", Listing.keys()[Listing.index_of(Listing.FINGERPRINT)])
+ if not CONFIG['features.connection.showIps'] and CONFIG['features.connection.listing_type'] == 0:
+ nyx_config = conf.get_config('nyx')
+ nyx_config.set('features.connection.listing_type', Listing.keys()[Listing.index_of(Listing.FINGERPRINT)])
self._scroller = ui_tools.Scroller(True)
- self._title = "Connections:" # title line of the panel
+ self._title = 'Connections:' # title line of the panel
self._entries = [] # last fetched display entries
self._entry_lines = [] # individual lines rendered from the entries listing
self._show_details = False # presents the details panel if true
@@ -89,7 +89,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# last day's clients.
controller = tor_controller()
- bridge_clients = controller.get_info("status/clients-seen", None)
+ bridge_clients = controller.get_info('status/clients-seen', None)
if bridge_clients:
# Response has a couple arguments...
@@ -98,14 +98,14 @@ class ConnectionPanel(panel.Panel, threading.Thread):
country_summary = None
for arg in bridge_clients.split():
- if arg.startswith("CountrySummary="):
+ if arg.startswith('CountrySummary='):
country_summary = arg[15:]
break
if country_summary:
- for entry in country_summary.split(","):
- if re.match("^..=[0-9]+$", entry):
- locale, count = entry.split("=", 1)
+ for entry in country_summary.split(','):
+ if re.match('^..=[0-9]+$', entry):
+ locale, count = entry.split('=', 1)
self._client_locale_usage[locale] = int(count)
# Last sampling received from the ConnectionResolver, used to detect when
@@ -168,12 +168,12 @@ class ConnectionPanel(panel.Panel, threading.Thread):
self.vals_lock.acquire()
if ordering:
- nyx_config = conf.get_config("nyx")
+ nyx_config = conf.get_config('nyx')
ordering_keys = [entries.SortAttr.keys()[entries.SortAttr.index_of(v)] for v in ordering]
- nyx_config.set("features.connection.order", ", ".join(ordering_keys))
+ nyx_config.set('features.connection.order', ', '.join(ordering_keys))
- self._entries.sort(key = lambda i: (i.get_sort_values(CONFIG["features.connection.order"], self.get_listing_type())))
+ self._entries.sort(key = lambda i: (i.get_sort_values(CONFIG['features.connection.order'], self.get_listing_type())))
self._entry_lines = []
@@ -187,7 +187,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
Provides the priority content we list connections by.
"""
- return CONFIG["features.connection.listing_type"]
+ return CONFIG['features.connection.listing_type']
def set_listing_type(self, listing_type):
"""
@@ -202,12 +202,12 @@ class ConnectionPanel(panel.Panel, threading.Thread):
self.vals_lock.acquire()
- nyx_config = conf.get_config("nyx")
- nyx_config.set("features.connection.listing_type", Listing.keys()[Listing.index_of(listing_type)])
+ nyx_config = conf.get_config('nyx')
+ nyx_config.set('features.connection.listing_type', Listing.keys()[Listing.index_of(listing_type)])
# if we're sorting by the listing then we need to resort
- if entries.SortAttr.LISTING in CONFIG["features.connection.order"]:
+ if entries.SortAttr.LISTING in CONFIG['features.connection.order']:
self.set_sort_order()
self.vals_lock.release()
@@ -220,7 +220,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
controller = tor_controller()
my_flags = []
- my_fingerprint = self.get_info("fingerprint", None)
+ my_fingerprint = self.get_info('fingerprint', None)
if my_fingerprint:
my_status_entry = self.controller.get_network_status(my_fingerprint)
@@ -228,7 +228,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
if my_status_entry:
my_flags = my_status_entry.flags
- return "Guard" in my_flags or controller.get_conf("BridgeRelay", None) == "1"
+ return 'Guard' in my_flags or controller.get_conf('BridgeRelay', None) == '1'
def is_exits_allowed(self):
"""
@@ -237,7 +237,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
controller = tor_controller()
- if not controller.get_conf("ORPort", None):
+ if not controller.get_conf('ORPort', None):
return False # no ORPort
policy = controller.get_exit_policy(None)
@@ -251,9 +251,9 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# set ordering for connection options
- title_label = "Connection Ordering:"
+ title_label = 'Connection Ordering:'
options = list(entries.SortAttr)
- old_selection = CONFIG["features.connection.order"]
+ old_selection = CONFIG['features.connection.order']
option_colors = dict([(attr, entries.SORT_COLORS[attr]) for attr in options])
results = nyx.popups.show_sort_dialog(title_label, options, old_selection, option_colors)
@@ -280,8 +280,8 @@ class ConnectionPanel(panel.Panel, threading.Thread):
elif key.match('u'):
# provides a menu to pick the connection resolver
- title = "Resolver Util:"
- options = ["auto"] + list(connection.Resolver)
+ title = 'Resolver Util:'
+ options = ['auto'] + list(connection.Resolver)
conn_resolver = nyx.util.tracker.get_connection_tracker()
current_overwrite = conn_resolver.get_custom_resolver()
@@ -301,7 +301,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
elif key.match('l'):
# provides a menu to pick the primary information we list connections by
- title = "List By:"
+ title = 'List By:'
options = list(entries.ListingType)
# dropping the HOSTNAME listing type until we support displaying that content
@@ -347,7 +347,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
while not self._halt:
current_time = time.time()
- if self.is_paused() or not self._is_tor_running or current_time - last_draw < CONFIG["features.connection.refreshRate"]:
+ if self.is_paused() or not self._is_tor_running or current_time - last_draw < CONFIG['features.connection.refreshRate']:
self._cond.acquire()
if not self._halt:
@@ -363,8 +363,8 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# we may have missed multiple updates due to being paused, showing
# another panel, etc so last_draw might need to jump multiple ticks
- draw_ticks = (time.time() - last_draw) / CONFIG["features.connection.refreshRate"]
- last_draw += CONFIG["features.connection.refreshRate"] * draw_ticks
+ draw_ticks = (time.time() - last_draw) / CONFIG['features.connection.refreshRate']
+ last_draw += CONFIG['features.connection.refreshRate'] * draw_ticks
def get_help(self):
resolver_util = nyx.util.tracker.get_connection_tracker().get_custom_resolver()
@@ -431,7 +431,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# title label with connection counts
if self.is_title_visible():
- title = "Connection Details:" if self._show_details else self._title
+ title = 'Connection Details:' if self._show_details else self._title
self.addstr(0, 0, title, curses.A_STANDOUT)
scroll_offset = 0
@@ -518,7 +518,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
# Skips established single-hop circuits (these are for directory
# fetches, not client circuits)
- if not (circ.status == "BUILT" and len(circ.path) == 1):
+ if not (circ.status == 'BUILT' and len(circ.path) == 1):
new_circuits[circ.id] = (circ.status, circ.purpose, [entry[0] for entry in circ.path])
# Populates new_entries with any of our old entries that still exist.
@@ -594,12 +594,12 @@ class ConnectionPanel(panel.Panel, threading.Thread):
for category in category_types:
if type_counts[category] > 0:
- count_labels.append("%i %s" % (type_counts[category], category.lower()))
+ count_labels.append('%i %s' % (type_counts[category], category.lower()))
if count_labels:
- self._title = "Connections (%s):" % ", ".join(count_labels)
+ self._title = 'Connections (%s):' % ', '.join(count_labels)
else:
- self._title = "Connections:"
+ self._title = 'Connections:'
self._entries = new_entries
@@ -622,7 +622,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
until the next update if true
"""
- if self.app_resolve_since_update or not CONFIG["features.connection.resolveApps"]:
+ if self.app_resolve_since_update or not CONFIG['features.connection.resolveApps']:
return
unresolved_lines = [l for l in self._entry_lines if isinstance(l, conn_entry.ConnectionLine) and l.is_unresolved_application()]
diff --git a/nyx/connections/count_popup.py b/nyx/connections/count_popup.py
index 7d392c9..00aeb31 100644
--- a/nyx/connections/count_popup.py
+++ b/nyx/connections/count_popup.py
@@ -10,7 +10,7 @@ import nyx.popups
from stem.util import connection, enum, log
-CountType = enum.Enum("CLIENT_LOCALE", "EXIT_PORT")
+CountType = enum.Enum('CLIENT_LOCALE', 'EXIT_PORT')
EXIT_USAGE_WIDTH = 15
@@ -43,12 +43,12 @@ def showCountDialog(count_type, counts):
# dialog title
if count_type == CountType.CLIENT_LOCALE:
- title = "Client Locales"
+ title = 'Client Locales'
elif count_type == CountType.EXIT_PORT:
- title = "Exiting Port Usage"
+ title = 'Exiting Port Usage'
else:
- title = ""
- log.warn("Unrecognized count type: %s" % count_type)
+ title = ''
+ log.warn('Unrecognized count type: %s' % count_type)
popup.addstr(0, 0, title, curses.A_STANDOUT)
@@ -72,7 +72,7 @@ def showCountDialog(count_type, counts):
if count_type == CountType.EXIT_PORT:
key_width += EXIT_USAGE_WIDTH
- label_format = "%%-%is %%%ii (%%%%%%-2i)" % (key_width, val_width)
+ label_format = '%%-%is %%%ii (%%%%%%-2i)' % (key_width, val_width)
for i in range(height - 4):
k, v = sorted_counts[i]
@@ -83,7 +83,7 @@ def showCountDialog(count_type, counts):
usage = connection.port_usage(k)
if usage:
- key_format = "%%-%is %%s" % (key_width - EXIT_USAGE_WIDTH)
+ key_format = '%%-%is %%s' % (key_width - EXIT_USAGE_WIDTH)
k = key_format % (k, usage[:EXIT_USAGE_WIDTH - 3])
label = label_format % (k, v, v * 100 / value_total)
@@ -99,9 +99,9 @@ def showCountDialog(count_type, counts):
fill_width = v * (width - 4 - label_width) / value_total
for j in range(fill_width):
- popup.addstr(i + 1, 3 + label_width + j, " ", curses.A_STANDOUT, 'red')
+ popup.addstr(i + 1, 3 + label_width + j, ' ', curses.A_STANDOUT, 'red')
- popup.addstr(height - 2, 2, "Press any key...")
+ popup.addstr(height - 2, 2, 'Press any key...')
popup.win.refresh()
diff --git a/nyx/connections/descriptor_popup.py b/nyx/connections/descriptor_popup.py
index 5f30ce7..f05631a 100644
--- a/nyx/connections/descriptor_popup.py
+++ b/nyx/connections/descriptor_popup.py
@@ -14,16 +14,16 @@ from stem.util import str_tools
# field keywords used to identify areas for coloring
-LINE_NUM_COLOR = "yellow"
-HEADER_COLOR = "cyan"
-HEADER_PREFIX = ["ns/id/", "desc/id/"]
+LINE_NUM_COLOR = 'yellow'
+HEADER_COLOR = 'cyan'
+HEADER_PREFIX = ['ns/id/', 'desc/id/']
-SIG_COLOR = "red"
-SIG_START_KEYS = ["-----BEGIN RSA PUBLIC KEY-----", "-----BEGIN SIGNATURE-----"]
-SIG_END_KEYS = ["-----END RSA PUBLIC KEY-----", "-----END SIGNATURE-----"]
+SIG_COLOR = 'red'
+SIG_START_KEYS = ['-----BEGIN RSA PUBLIC KEY-----', '-----BEGIN SIGNATURE-----']
+SIG_END_KEYS = ['-----END RSA PUBLIC KEY-----', '-----END SIGNATURE-----']
-UNRESOLVED_MSG = "No consensus data available"
-ERROR_MSG = "Unable to retrieve data"
+UNRESOLVED_MSG = 'No consensus data available'
+ERROR_MSG = 'Unable to retrieve data'
def show_descriptor_popup(conn_panel):
@@ -55,7 +55,7 @@ def show_descriptor_popup(conn_panel):
fingerprint = selection.foreign.get_fingerprint()
- if fingerprint == "UNKNOWN":
+ if fingerprint == 'UNKNOWN':
fingerprint = None
display_text = get_display_text(fingerprint)
@@ -120,19 +120,19 @@ def get_display_text(fingerprint):
controller, description = tor_controller(), []
- description.append("ns/id/%s" % fingerprint)
- consensus_entry = controller.get_info("ns/id/%s" % fingerprint, None)
+ description.append('ns/id/%s' % fingerprint)
+ consensus_entry = controller.get_info('ns/id/%s' % fingerprint, None)
if consensus_entry:
- description += consensus_entry.split("\n")
+ description += consensus_entry.split('\n')
else:
- description += [ERROR_MSG, ""]
+ description += [ERROR_MSG, '']
- description.append("desc/id/%s" % fingerprint)
- descriptor_entry = controller.get_info("desc/id/%s" % fingerprint, None)
+ description.append('desc/id/%s' % fingerprint)
+ descriptor_entry = controller.get_info('desc/id/%s' % fingerprint, None)
if descriptor_entry:
- description += descriptor_entry.split("\n")
+ description += descriptor_entry.split('\n')
else:
description += [ERROR_MSG]
@@ -169,9 +169,9 @@ def draw(popup, fingerprint, display_text, display_color, scroll, show_line_numb
x_offset = 2
if fingerprint:
- title = "Consensus Descriptor (%s):" % fingerprint
+ title = 'Consensus Descriptor (%s):' % fingerprint
else:
- title = "Consensus Descriptor:"
+ title = 'Consensus Descriptor:'
popup.addstr(0, 0, title, curses.A_STANDOUT)
@@ -195,7 +195,7 @@ def draw(popup, fingerprint, display_text, display_color, scroll, show_line_numb
x_offset = 2
if show_line_number:
- line_number_label = ("%%%ii" % line_number_width) % (i + 1)
+ line_number_label = ('%%%ii' % line_number_width) % (i + 1)
popup.addstr(draw_line, x_offset, line_number_label, curses.A_BOLD, LINE_NUM_COLOR)
x_offset += line_number_width + 1
@@ -203,27 +203,27 @@ def draw(popup, fingerprint, display_text, display_color, scroll, show_line_numb
# Most consensus and descriptor lines are keyword/value pairs. Both are
# shown with the same color, but the keyword is bolded.
- keyword, value = line_text, ""
+ keyword, value = line_text, ''
draw_format = display_color
if line_text.startswith(HEADER_PREFIX[0]) or line_text.startswith(HEADER_PREFIX[1]):
- keyword, value = line_text, ""
+ keyword, value = line_text, ''
draw_format = HEADER_COLOR
elif line_text == UNRESOLVED_MSG or line_text == ERROR_MSG:
- keyword, value = line_text, ""
+ keyword, value = line_text, ''
elif line_text in SIG_START_KEYS:
- keyword, value = line_text, ""
+ keyword, value = line_text, ''
is_encryption_block = True
draw_format = SIG_COLOR
elif line_text in SIG_END_KEYS:
- keyword, value = line_text, ""
+ keyword, value = line_text, ''
is_encryption_block = False
draw_format = SIG_COLOR
elif is_encryption_block:
- keyword, value = "", line_text
+ keyword, value = '', line_text
draw_format = SIG_COLOR
- elif " " in line_text:
- div_index = line_text.find(" ")
+ elif ' ' in line_text:
+ div_index = line_text.find(' ')
keyword, value = line_text[:div_index], line_text[div_index:]
display_queue = [(keyword, (draw_format, curses.A_BOLD)), (value, (draw_format,))]
@@ -242,15 +242,15 @@ def draw(popup, fingerprint, display_text, display_color, scroll, show_line_numb
msg, remainder = str_tools.crop(msg, max_msg_size, None, ending = None, get_remainder = True)
- if x_offset == cursor_location and msg == "":
+ if x_offset == cursor_location and msg == '':
# first word is longer than the line
msg = str_tools.crop(remainder, max_msg_size)
- if " " in remainder:
- remainder = remainder.split(" ", 1)[1]
+ if ' ' in remainder:
+ remainder = remainder.split(' ', 1)[1]
else:
- remainder = ""
+ remainder = ''
popup.addstr(draw_line, cursor_location, msg, *msg_format)
cursor_location = x_offset
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 85bce32..d034aa2 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -8,20 +8,20 @@ from stem.util import enum
# attributes we can list entries by
-ListingType = enum.Enum(("IP_ADDRESS", "IP Address"), "HOSTNAME", "FINGERPRINT", "NICKNAME")
+ListingType = enum.Enum(('IP_ADDRESS', 'IP Address'), 'HOSTNAME', 'FINGERPRINT', 'NICKNAME')
-SortAttr = enum.Enum("CATEGORY", "UPTIME", "LISTING", "IP_ADDRESS", "PORT", "HOSTNAME", "FINGERPRINT", "NICKNAME", "COUNTRY")
+SortAttr = enum.Enum('CATEGORY', 'UPTIME', 'LISTING', 'IP_ADDRESS', 'PORT', 'HOSTNAME', 'FINGERPRINT', 'NICKNAME', 'COUNTRY')
SORT_COLORS = {
- SortAttr.CATEGORY: "red",
- SortAttr.UPTIME: "yellow",
- SortAttr.LISTING: "green",
- SortAttr.IP_ADDRESS: "blue",
- SortAttr.PORT: "blue",
- SortAttr.HOSTNAME: "magenta",
- SortAttr.FINGERPRINT: "cyan",
- SortAttr.NICKNAME: "cyan",
- SortAttr.COUNTRY: "blue",
+ SortAttr.CATEGORY: 'red',
+ SortAttr.UPTIME: 'yellow',
+ SortAttr.LISTING: 'green',
+ SortAttr.IP_ADDRESS: 'blue',
+ SortAttr.PORT: 'blue',
+ SortAttr.HOSTNAME: 'magenta',
+ SortAttr.FINGERPRINT: 'cyan',
+ SortAttr.NICKNAME: 'cyan',
+ SortAttr.COUNTRY: 'blue',
}
# maximum number of ports a system can have
@@ -95,7 +95,7 @@ class ConnectionPanelEntry:
elif listing_type == ListingType.NICKNAME:
return self.get_sort_value(SortAttr.NICKNAME, listing_type)
- return ""
+ return ''
def reset_display(self):
"""
diff --git a/nyx/controller.py b/nyx/controller.py
index da95588..f94bf11 100644
--- a/nyx/controller.py
+++ b/nyx/controller.py
@@ -31,25 +31,25 @@ NYX_CONTROLLER = None
def conf_handler(key, value):
- if key == "features.redrawRate":
+ if key == 'features.redrawRate':
return max(1, value)
- elif key == "features.refreshRate":
+ elif key == 'features.refreshRate':
return max(0, value)
-CONFIG = conf.config_dict("nyx", {
- "startup.events": "N3",
- "startup.data_directory": "~/.nyx",
- "features.acsSupport": True,
- "features.panels.show.graph": True,
- "features.panels.show.log": True,
- "features.panels.show.connection": True,
- "features.panels.show.config": True,
- "features.panels.show.torrc": True,
- "features.redrawRate": 5,
- "features.refreshRate": 5,
- "features.confirmQuit": True,
- "start_time": 0,
+CONFIG = conf.config_dict('nyx', {
+ 'startup.events': 'N3',
+ 'startup.data_directory': '~/.nyx',
+ 'features.acsSupport': True,
+ 'features.panels.show.graph': True,
+ 'features.panels.show.log': True,
+ 'features.panels.show.connection': True,
+ 'features.panels.show.config': True,
+ 'features.panels.show.torrc': True,
+ 'features.redrawRate': 5,
+ 'features.refreshRate': 5,
+ 'features.confirmQuit': True,
+ 'start_time': 0,
}, conf_handler)
@@ -101,18 +101,18 @@ def init_controller(stdscr, start_time):
page_panels, first_page_panels = [], []
# first page: graph and log
- if CONFIG["features.panels.show.graph"]:
+ if CONFIG['features.panels.show.graph']:
first_page_panels.append(nyx.graph_panel.GraphPanel(stdscr))
- if CONFIG["features.panels.show.log"]:
- expanded_events = nyx.arguments.expand_events(CONFIG["startup.events"])
+ if CONFIG['features.panels.show.log']:
+ expanded_events = nyx.arguments.expand_events(CONFIG['startup.events'])
first_page_panels.append(nyx.log_panel.LogPanel(stdscr, expanded_events))
if first_page_panels:
page_panels.append(first_page_panels)
# second page: connections
- if CONFIG["features.panels.show.connection"]:
+ if CONFIG['features.panels.show.connection']:
page_panels.append([nyx.connections.conn_panel.ConnectionPanel(stdscr)])
# The DisableDebuggerAttachment will prevent our connection panel from really
@@ -121,7 +121,7 @@ def init_controller(stdscr, start_time):
controller = tor_controller()
- if controller.get_conf("DisableDebuggerAttachment", None) == "1":
+ if controller.get_conf('DisableDebuggerAttachment', None) == '1':
log.notice("Tor is preventing system utilities like netstat and lsof from working. This means that nyx can't provide you with connection information. You can change this by adding 'DisableDebuggerAttachment 0' to your torrc and restarting tor. For more information see...\nhttps://trac.torproject.org/3313")
nyx.util.tracker.get_connection_tracker().set_paused(True)
else:
@@ -137,10 +137,10 @@ def init_controller(stdscr, start_time):
tor_cmd = system.name_by_pid(tor_pid)
if tor_cmd is None:
- tor_cmd = "tor"
+ tor_cmd = 'tor'
resolver = nyx.util.tracker.get_connection_tracker()
- log.info("Operating System: %s, Connection Resolvers: %s" % (os.uname()[0], ", ".join(resolver._resolvers)))
+ log.info('Operating System: %s, Connection Resolvers: %s' % (os.uname()[0], ', '.join(resolver._resolvers)))
resolver.start()
else:
# constructs singleton resolver and, if tor isn't connected, initizes
@@ -150,12 +150,12 @@ def init_controller(stdscr, start_time):
# third page: config
- if CONFIG["features.panels.show.config"]:
+ if CONFIG['features.panels.show.config']:
page_panels.append([nyx.config_panel.ConfigPanel(stdscr, nyx.config_panel.State.TOR)])
# fourth page: torrc
- if CONFIG["features.panels.show.torrc"]:
+ if CONFIG['features.panels.show.torrc']:
page_panels.append([nyx.torrc_panel.TorrcPanel(stdscr, nyx.torrc_panel.Config.TORRC)])
# initializes the controller
@@ -169,8 +169,8 @@ class LabelPanel(panel.Panel):
"""
def __init__(self, stdscr):
- panel.Panel.__init__(self, stdscr, "msg", 0, height=1)
- self.msg_text = ""
+ panel.Panel.__init__(self, stdscr, 'msg', 0, height=1)
+ self.msg_text = ''
self.msg_attr = curses.A_NORMAL
def set_message(self, msg, attr = None):
@@ -255,7 +255,7 @@ class Controller:
"""
if page_number < 0 or page_number >= self.get_page_count():
- raise ValueError("Invalid page number: %i" % page_number)
+ raise ValueError('Invalid page number: %i' % page_number)
if page_number != self._page:
self._page = page_number
@@ -378,8 +378,8 @@ class Controller:
current_time = time.time()
- if CONFIG["features.refreshRate"] != 0:
- if self._last_drawn + CONFIG["features.refreshRate"] <= current_time:
+ if CONFIG['features.refreshRate'] != 0:
+ if self._last_drawn + CONFIG['features.refreshRate'] <= current_time:
force = True
display_panels = self.get_display_panels()
@@ -431,17 +431,17 @@ class Controller:
"""
if msg is None:
- msg = ""
+ msg = ''
if attr is None:
if not self._is_paused:
- msg = "page %i / %i - m: menu, p: pause, h: page help, q: quit" % (self._page + 1, len(self._page_panels))
+ msg = 'page %i / %i - m: menu, p: pause, h: page help, q: quit' % (self._page + 1, len(self._page_panels))
attr = curses.A_NORMAL
else:
- msg = "Paused"
+ msg = 'Paused'
attr = curses.A_STANDOUT
- control_panel = self.get_panel("msg")
+ control_panel = self.get_panel('msg')
control_panel.set_message(msg, attr)
if redraw:
@@ -455,10 +455,10 @@ class Controller:
with a slash and is created if it doesn't already exist.
"""
- data_dir = os.path.expanduser(CONFIG["startup.data_directory"])
+ data_dir = os.path.expanduser(CONFIG['startup.data_directory'])
- if not data_dir.endswith("/"):
- data_dir += "/"
+ if not data_dir.endswith('/'):
+ data_dir += '/'
if not os.path.exists(data_dir):
os.makedirs(data_dir)
@@ -480,11 +480,11 @@ def heartbeat_check(is_unresponsive):
if controller.is_alive():
if not is_unresponsive and (time.time() - last_heartbeat) >= 10:
is_unresponsive = True
- log.notice("Relay unresponsive (last heartbeat: %s)" % time.ctime(last_heartbeat))
+ log.notice('Relay unresponsive (last heartbeat: %s)' % time.ctime(last_heartbeat))
elif is_unresponsive and (time.time() - last_heartbeat) < 10:
# really shouldn't happen (meant Tor froze for a bit)
is_unresponsive = False
- log.notice("Relay resumed")
+ log.notice('Relay resumed')
return is_unresponsive
@@ -505,7 +505,7 @@ def conn_reset_listener(controller, event_type, _):
# do this instead since it wants to do validation and redraw _after_ the
# new contents are loaded.
- if get_controller().get_panel("torrc") is None:
+ if get_controller().get_panel('torrc') is None:
tor_config.get_torrc().load(True)
@@ -520,13 +520,13 @@ def start_nyx(stdscr):
init_controller(stdscr, CONFIG['start_time'])
control = get_controller()
- if not CONFIG["features.acsSupport"]:
+ if not CONFIG['features.acsSupport']:
ui_tools.disable_acs()
# provides notice about any unused config keys
- for key in conf.get_config("nyx").unused_keys():
- log.notice("Unused configuration entry: %s" % key)
+ for key in conf.get_config('nyx').unused_keys():
+ log.notice('Unused configuration entry: %s' % key)
# tells daemon panels to start
@@ -549,7 +549,7 @@ def start_nyx(stdscr):
# logs the initialization time
- log.info("nyx started (initialization took %0.3f seconds)" % (time.time() - CONFIG['start_time']))
+ log.info('nyx started (initialization took %0.3f seconds)' % (time.time() - CONFIG['start_time']))
# main draw loop
@@ -575,7 +575,7 @@ def start_nyx(stdscr):
if override_key:
key, override_key = override_key, None
else:
- curses.halfdelay(CONFIG["features.redrawRate"] * 10)
+ curses.halfdelay(CONFIG['features.redrawRate'] * 10)
key = panel.KeyInput(stdscr.getch())
if key.match('right'):
@@ -589,8 +589,8 @@ def start_nyx(stdscr):
elif key.match('q'):
# provides prompt to confirm that nyx should exit
- if CONFIG["features.confirmQuit"]:
- msg = "Are you sure (q again to confirm)?"
+ if CONFIG['features.confirmQuit']:
+ msg = 'Are you sure (q again to confirm)?'
confirmation_key = nyx.popups.show_msg(msg, attr = curses.A_BOLD)
quit_confirmed = confirmation_key.match('q')
else:
@@ -608,7 +608,7 @@ def start_nyx(stdscr):
try:
tor_controller().signal(stem.Signal.RELOAD)
except IOError as exc:
- log.error("Error detected when reloading tor: %s" % exc.strerror)
+ log.error('Error detected when reloading tor: %s' % exc.strerror)
elif key.match('h'):
override_key = nyx.popups.show_help_popup()
elif key == ord('l') - 96:
diff --git a/nyx/log_panel.py b/nyx/log_panel.py
index 071ca79..62d2319 100644
--- a/nyx/log_panel.py
+++ b/nyx/log_panel.py
@@ -22,46 +22,46 @@ from nyx import __version__
from nyx.util import panel, tor_controller, ui_tools
RUNLEVEL_EVENT_COLOR = {
- log.DEBUG: "magenta",
- log.INFO: "blue",
- log.NOTICE: "green",
- log.WARN: "yellow",
- log.ERR: "red",
+ log.DEBUG: 'magenta',
+ log.INFO: 'blue',
+ log.NOTICE: 'green',
+ log.WARN: 'yellow',
+ log.ERR: 'red',
}
-DAYBREAK_EVENT = "DAYBREAK" # special event for marking when the date changes
+DAYBREAK_EVENT = 'DAYBREAK' # special event for marking when the date changes
TIMEZONE_OFFSET = time.altzone if time.localtime()[8] else time.timezone
ENTRY_INDENT = 2 # spaces an entry's message is indented after the first line
def conf_handler(key, value):
- if key == "features.log.max_lines_per_entry":
+ if key == 'features.log.max_lines_per_entry':
return max(1, value)
- elif key == "features.log.prepopulateReadLimit":
+ elif key == 'features.log.prepopulateReadLimit':
return max(0, value)
- elif key == "features.log.maxRefreshRate":
+ elif key == 'features.log.maxRefreshRate':
return max(10, value)
- elif key == "cache.log_panel.size":
+ elif key == 'cache.log_panel.size':
return max(1000, value)
-CONFIG = conf.config_dict("nyx", {
- "features.log_file": "",
- "features.log.showDateDividers": True,
- "features.log.showDuplicateEntries": False,
- "features.log.entryDuration": 7,
- "features.log.max_lines_per_entry": 6,
- "features.log.prepopulate": True,
- "features.log.prepopulateReadLimit": 5000,
- "features.log.maxRefreshRate": 300,
- "features.log.regex": [],
- "cache.log_panel.size": 1000,
- "msg.misc.event_types": '',
- "tor.chroot": '',
+CONFIG = conf.config_dict('nyx', {
+ 'features.log_file': '',
+ 'features.log.showDateDividers': True,
+ 'features.log.showDuplicateEntries': False,
+ 'features.log.entryDuration': 7,
+ 'features.log.max_lines_per_entry': 6,
+ 'features.log.prepopulate': True,
+ 'features.log.prepopulateReadLimit': 5000,
+ 'features.log.maxRefreshRate': 300,
+ 'features.log.regex': [],
+ 'cache.log_panel.size': 1000,
+ 'msg.misc.event_types': '',
+ 'tor.chroot': '',
}, conf_handler)
-DUPLICATE_MSG = " [%i duplicate%s hidden]"
+DUPLICATE_MSG = ' [%i duplicate%s hidden]'
# The height of the drawn content is estimated based on the last time we redrew
# the panel. It's chiefly used for scrolling and the bar indicating its
@@ -113,12 +113,12 @@ def load_log_messages():
"""
global COMMON_LOG_MESSAGES
- nyx_config = conf.get_config("nyx")
+ nyx_config = conf.get_config('nyx')
COMMON_LOG_MESSAGES = {}
for conf_key in nyx_config.keys():
- if conf_key.startswith("dedup."):
+ if conf_key.startswith('dedup.'):
event_type = conf_key[4:].upper()
messages = nyx_config.get(conf_key, [])
COMMON_LOG_MESSAGES[event_type] = messages
@@ -146,12 +146,12 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
logging_types, logging_location = None, None
- for logging_entry in tor_controller().get_conf("Log", [], True):
+ for logging_entry in tor_controller().get_conf('Log', [], True):
# looks for an entry like: notice file /var/log/tor/notices.log
entry_comp = logging_entry.split()
- if entry_comp[1] == "file":
+ if entry_comp[1] == 'file':
logging_types, logging_location = entry_comp[0], entry_comp[2]
break
@@ -169,8 +169,8 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
logging_types = logging_types.upper()
if add_limit and (not read_limit or read_limit > add_limit):
- if "-" in logging_types:
- div_index = logging_types.find("-")
+ if '-' in logging_types:
+ div_index = logging_types.find('-')
start_index = runlevels.index(logging_types[:div_index])
end_index = runlevels.index(logging_types[div_index + 1:])
log_file_run_levels = runlevels[start_index:end_index + 1]
@@ -196,12 +196,12 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
try:
if read_limit:
- lines = system.call("tail -n %i %s" % (read_limit, logging_location))
+ lines = system.call('tail -n %i %s' % (read_limit, logging_location))
if not lines:
raise IOError()
else:
- log_file = open(logging_location, "r")
+ log_file = open(logging_location, 'r')
lines = log_file.readlines()
log_file.close()
except IOError:
@@ -233,12 +233,12 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
if event_type in runlevels:
# converts timestamp to unix time
- timestamp = " ".join(line_comp[:3])
+ timestamp = ' '.join(line_comp[:3])
# strips the decimal seconds
- if "." in timestamp:
- timestamp = timestamp[:timestamp.find(".")]
+ if '.' in timestamp:
+ timestamp = timestamp[:timestamp.find('.')]
# Ignoring wday and yday since they aren't used.
#
@@ -249,8 +249,8 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
#
# https://trac.torproject.org/projects/tor/ticket/5265
- timestamp = "2012 " + timestamp
- event_time_comp = list(time.strptime(timestamp, "%Y %b %d %H:%M:%S"))
+ timestamp = '2012 ' + timestamp
+ event_time_comp = list(time.strptime(timestamp, '%Y %b %d %H:%M:%S'))
event_time_comp[8] = current_local_time.tm_isdst
event_time = time.mktime(event_time_comp) # converts local to unix time
@@ -261,10 +261,10 @@ def get_log_file_entries(runlevels, read_limit = None, add_limit = None):
event_time_comp[0] -= 1
event_time = time.mktime(event_time_comp)
- event_msg = " ".join(line_comp[4:])
+ event_msg = ' '.join(line_comp[4:])
logged_events.append(LogEntry(event_time, event_type, event_msg, RUNLEVEL_EVENT_COLOR[event_type]))
- if "opening log file" in line:
+ if 'opening log file' in line:
break # this entry marks the start of this tor instance
if add_limit:
@@ -306,7 +306,7 @@ def get_daybreaks(events, ignore_time_for_cache = False):
if event_day != last_day:
marker_timestamp = (event_day * 86400) + TIMEZONE_OFFSET
- new_listing.append(LogEntry(marker_timestamp, DAYBREAK_EVENT, "", "white"))
+ new_listing.append(LogEntry(marker_timestamp, DAYBREAK_EVENT, '', 'white'))
new_listing.append(entry)
last_day = event_day
@@ -400,7 +400,7 @@ def is_duplicate(event, event_set, get_duplicates = False):
# if it starts with an asterisk then check the whole message rather
# than just the start
- if common_msg[0] == "*":
+ if common_msg[0] == '*':
is_duplicate = common_msg[1:] in event.msg and common_msg[1:] in forward_entry.msg
else:
is_duplicate = event.msg.startswith(common_msg) and forward_entry.msg.startswith(common_msg)
@@ -424,7 +424,7 @@ class LogEntry():
"""
Individual log file entry, having the following attributes:
timestamp - unix timestamp for when the event occurred
- event_type - event type that occurred ("INFO", "BW", "NYX_WARN", etc)
+ event_type - event type that occurred ('INFO', 'BW', 'NYX_WARN', etc)
msg - message that was logged
color - color of the log entry
"""
@@ -447,12 +447,12 @@ class LogEntry():
if include_date:
# not the common case so skip caching
entry_time = time.localtime(self.timestamp)
- time_label = "%i/%i/%i %02i:%02i:%02i" % (entry_time[1], entry_time[2], entry_time[0], entry_time[3], entry_time[4], entry_time[5])
- return "%s [%s] %s" % (time_label, self.type, self.msg)
+ time_label = '%i/%i/%i %02i:%02i:%02i' % (entry_time[1], entry_time[2], entry_time[0], entry_time[3], entry_time[4], entry_time[5])
+ return '%s [%s] %s' % (time_label, self.type, self.msg)
if not self._display_message:
entry_time = time.localtime(self.timestamp)
- self._display_message = "%02i:%02i:%02i [%s] %s" % (entry_time[3], entry_time[4], entry_time[5], self.type, self.msg)
+ self._display_message = '%02i:%02i:%02i [%s] %s' % (entry_time[3], entry_time[4], entry_time[5], self.type, self.msg)
return self._display_message
@@ -464,7 +464,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
"""
def __init__(self, stdscr, logged_events):
- panel.Panel.__init__(self, stdscr, "log", 0)
+ panel.Panel.__init__(self, stdscr, 'log', 0)
logging.Handler.__init__(self, level = log.logging_level(log.DEBUG))
self.setFormatter(logging.Formatter(
@@ -485,7 +485,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.filter_options = []
- for filter in CONFIG["features.log.regex"]:
+ for filter in CONFIG['features.log.regex']:
# checks if we can't have more filters
if len(self.filter_options) >= MAX_REGEX_FILTERS:
@@ -495,7 +495,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
re.compile(filter)
self.filter_options.append(filter)
except re.error as exc:
- log.notice("Invalid regular expression pattern (%s): %s" % (exc, filter))
+ log.notice('Invalid regular expression pattern (%s): %s' % (exc, filter))
self.logged_events = [] # needs to be set before we receive any events
@@ -504,7 +504,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.logged_events = self.set_event_listening(logged_events)
- self.set_pause_attr("msg_log") # tracks the message log when we're paused
+ self.set_pause_attr('msg_log') # tracks the message log when we're paused
self.msg_log = [] # log entries, sorted by the timestamp
self.regex_filter = None # filter for presented log events (no filtering if None)
self.last_content_height = 0 # height of the rendered content when last drawn
@@ -544,8 +544,8 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# opens log file if we'll be saving entries
- if CONFIG["features.log_file"]:
- log_path = CONFIG["features.log_file"]
+ if CONFIG['features.log_file']:
+ log_path = CONFIG['features.log_file']
try:
# make dir if the path doesn't already exist
@@ -555,24 +555,24 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
if not os.path.exists(base_dir):
os.makedirs(base_dir)
- self.log_file = open(log_path, "a")
- log.notice("nyx %s opening log file (%s)" % (__version__, log_path))
+ self.log_file = open(log_path, 'a')
+ log.notice('nyx %s opening log file (%s)' % (__version__, log_path))
except IOError as exc:
- log.error("Unable to write to log file: %s" % exc.strerror)
+ log.error('Unable to write to log file: %s' % exc.strerror)
self.log_file = None
except OSError as exc:
- log.error("Unable to write to log file: %s" % exc)
+ log.error('Unable to write to log file: %s' % exc)
self.log_file = None
stem_logger = log.get_logger()
stem_logger.addHandler(self)
def emit(self, record):
- if record.levelname == "WARNING":
- record.levelname = "WARN"
+ if record.levelname == 'WARNING':
+ record.levelname = 'WARN'
event_color = RUNLEVEL_EVENT_COLOR[record.levelname]
- self.register_event(LogEntry(int(record.created), "NYX_%s" % record.levelname, record.msg, event_color))
+ self.register_event(LogEntry(int(record.created), 'NYX_%s' % record.levelname, record.msg, event_color))
def reprepopulate_events(self):
"""
@@ -587,10 +587,10 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# fetches past tor events from log file, if available
- if CONFIG["features.log.prepopulate"]:
+ if CONFIG['features.log.prepopulate']:
set_runlevels = list(set.intersection(set(self.logged_events), set(list(log.Runlevel))))
- read_limit = CONFIG["features.log.prepopulateReadLimit"]
- add_limit = CONFIG["cache.log_panel.size"]
+ read_limit = CONFIG['features.log.prepopulateReadLimit']
+ add_limit = CONFIG['cache.log_panel.size']
for entry in get_log_file_entries(set_runlevels, read_limit, add_limit):
self.msg_log.append(entry)
@@ -610,8 +610,8 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
deduplicated
"""
- nyx_config = conf.get_config("nyx")
- nyx_config.set("features.log.showDuplicateEntries", str(is_visible))
+ nyx_config = conf.get_config('nyx')
+ nyx_config.set('features.log.showDuplicateEntries', str(is_visible))
def register_tor_event(self, event):
"""
@@ -619,24 +619,24 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
register_event().
"""
- msg, color = ' '.join(str(event).split(' ')[1:]), "white"
+ msg, color = ' '.join(str(event).split(' ')[1:]), 'white'
if isinstance(event, events.CircuitEvent):
- color = "yellow"
+ color = 'yellow'
elif isinstance(event, events.BandwidthEvent):
- color = "cyan"
- msg = "READ: %i, WRITTEN: %i" % (event.read, event.written)
+ color = 'cyan'
+ msg = 'READ: %i, WRITTEN: %i' % (event.read, event.written)
elif isinstance(event, events.LogEvent):
color = RUNLEVEL_EVENT_COLOR[event.runlevel]
msg = event.message
elif isinstance(event, events.NetworkStatusEvent):
- color = "blue"
+ color = 'blue'
elif isinstance(event, events.NewConsensusEvent):
- color = "magenta"
+ color = 'magenta'
elif isinstance(event, events.GuardEvent):
- color = "yellow"
+ color = 'yellow'
elif event.type not in nyx.arguments.TOR_EVENT_TYPES.values():
- color = "red" # unknown event type
+ color = 'red' # unknown event type
self.register_event(LogEntry(event.arrived_at, event.type, msg, color))
@@ -659,10 +659,10 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
if self.log_file:
try:
- self.log_file.write(event.get_display_message(True) + "\n")
+ self.log_file.write(event.get_display_message(True) + '\n')
self.log_file.flush()
except IOError as exc:
- log.error("Unable to write to log file: %s" % exc.strerror)
+ log.error('Unable to write to log file: %s' % exc.strerror)
self.log_file = None
self.vals_lock.acquire()
@@ -754,7 +754,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
Prompts the user to add a new regex filter.
"""
- regex_input = nyx.popups.input_prompt("Regular expression: ")
+ regex_input = nyx.popups.input_prompt('Regular expression: ')
if regex_input:
try:
@@ -765,7 +765,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.filter_options.insert(0, regex_input)
except re.error as exc:
- nyx.popups.show_msg("Unable to compile expression: %s" % exc, 2)
+ nyx.popups.show_msg('Unable to compile expression: %s' % exc, 2)
def show_event_selection_prompt(self):
"""
@@ -781,15 +781,15 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# displays the available flags
popup.win.box()
- popup.addstr(0, 0, "Event Types:", curses.A_STANDOUT)
- event_lines = CONFIG['msg.misc.event_types'].split("\n")
+ popup.addstr(0, 0, 'Event Types:', curses.A_STANDOUT)
+ event_lines = CONFIG['msg.misc.event_types'].split('\n')
for i in range(len(event_lines)):
popup.addstr(i + 1, 1, event_lines[i][6:])
popup.win.refresh()
- user_input = nyx.popups.input_prompt("Events to log: ")
+ user_input = nyx.popups.input_prompt('Events to log: ')
if user_input:
user_input = user_input.replace(' ', '') # strips spaces
@@ -797,7 +797,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
try:
self.set_logged_events(nyx.arguments.expand_events(user_input))
except ValueError as exc:
- nyx.popups.show_msg("Invalid flags: %s" % str(exc), 2)
+ nyx.popups.show_msg('Invalid flags: %s' % str(exc), 2)
finally:
nyx.popups.finalize()
@@ -806,14 +806,14 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
Lets user enter a path to take a snapshot, canceling if left blank.
"""
- path_input = nyx.popups.input_prompt("Path to save log snapshot: ")
+ path_input = nyx.popups.input_prompt('Path to save log snapshot: ')
if path_input:
try:
self.save_snapshot(path_input)
- nyx.popups.show_msg("Saved: %s" % path_input, 2)
+ nyx.popups.show_msg('Saved: %s' % path_input, 2)
except IOError as exc:
- nyx.popups.show_msg("Unable to save snapshot: %s" % exc.strerror, 2)
+ nyx.popups.show_msg('Unable to save snapshot: %s' % exc.strerror, 2)
def clear(self):
"""
@@ -847,7 +847,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
except OSError as exc:
raise IOError("unable to make directory '%s'" % base_dir)
- snapshot_file = open(path, "w")
+ snapshot_file = open(path, 'w')
self.vals_lock.acquire()
try:
@@ -855,7 +855,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
is_visible = not self.regex_filter or self.regex_filter.search(entry.get_display_message())
if is_visible:
- snapshot_file.write(entry.get_display_message(True) + "\n")
+ snapshot_file.write(entry.get_display_message(True) + '\n')
self.vals_lock.release()
except Exception as exc:
@@ -874,11 +874,11 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.vals_lock.release()
elif key.match('u'):
self.vals_lock.acquire()
- self.set_duplicate_visability(not CONFIG["features.log.showDuplicateEntries"])
+ self.set_duplicate_visability(not CONFIG['features.log.showDuplicateEntries'])
self.redraw(True)
self.vals_lock.release()
elif key.match('c'):
- msg = "This will clear the log. Are you sure (c again to confirm)?"
+ msg = 'This will clear the log. Are you sure (c again to confirm)?'
key_press = nyx.popups.show_msg(msg, attr = curses.A_BOLD)
if key_press.match('c'):
@@ -887,7 +887,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# Provides menu to pick regular expression filters or adding new ones:
# for syntax see: http://docs.python.org/library/re.html#regular-expression-syntax
- options = ["None"] + self.filter_options + ["New..."]
+ options = ['None'] + self.filter_options + ['New...']
old_selection = 0 if not self.regex_filter else 1
# does all activity under a curses lock to prevent redraws when adding
@@ -896,7 +896,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
panel.CURSES_LOCK.acquire()
try:
- selection = nyx.popups.show_menu("Log Filter:", options, old_selection)
+ selection = nyx.popups.show_menu('Log Filter:', options, old_selection)
# applies new setting
@@ -938,7 +938,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
contain up to two lines. Starts with newest entries.
"""
- current_log = self.get_attr("msg_log")
+ current_log = self.get_attr('msg_log')
self.vals_lock.acquire()
self._last_logged_events, self._last_update = list(current_log), time.time()
@@ -967,14 +967,14 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
seen_first_date_divider = False
divider_attr, duplicate_attr = (curses.A_BOLD, 'yellow'), (curses.A_BOLD, 'green')
- is_dates_shown = self.regex_filter is None and CONFIG["features.log.showDateDividers"]
+ is_dates_shown = self.regex_filter is None and CONFIG['features.log.showDateDividers']
event_log = get_daybreaks(current_log, self.is_paused()) if is_dates_shown else list(current_log)
- if not CONFIG["features.log.showDuplicateEntries"]:
+ if not CONFIG['features.log.showDuplicateEntries']:
deduplicated_log = get_duplicates(event_log)
if deduplicated_log is None:
- log.warn("Deduplication took too long. Its current implementation has difficulty handling large logs so disabling it to keep the interface responsive.")
+ log.warn('Deduplication took too long. Its current implementation has difficulty handling large logs so disabling it to keep the interface responsive.')
self.set_duplicate_visability(True)
deduplicated_log = [(entry, 0) for entry in event_log]
else:
@@ -1006,7 +1006,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# top of the divider
if line_count >= 1 and line_count < height and show_daybreaks:
- time_label = time.strftime(" %B %d, %Y ", time.localtime(entry.timestamp))
+ time_label = time.strftime(' %B %d, %Y ', time.localtime(entry.timestamp))
self.addch(line_count, divider_indent, curses.ACS_ULCORNER, *divider_attr)
self.addch(line_count, divider_indent + 1, curses.ACS_HLINE, *divider_attr)
self.addstr(line_count, divider_indent + 2, time_label, curses.A_BOLD, *divider_attr)
@@ -1023,19 +1023,19 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
display_queue = []
- msg_comp = entry.get_display_message().split("\n")
+ msg_comp = entry.get_display_message().split('\n')
for i in range(len(msg_comp)):
- font = curses.A_BOLD if "ERR" in entry.type else curses.A_NORMAL # emphasizes ERR messages
+ font = curses.A_BOLD if 'ERR' in entry.type else curses.A_NORMAL # emphasizes ERR messages
display_queue.append((msg_comp[i].strip(), (font, entry.color), i != len(msg_comp) - 1))
if duplicate_count:
- plural_label = "s" if duplicate_count > 1 else ""
+ plural_label = 's' if duplicate_count > 1 else ''
duplicate_msg = DUPLICATE_MSG % (duplicate_count, plural_label)
display_queue.append((duplicate_msg, duplicate_attr, False))
cursor_location, line_offset = msg_indent, 0
- max_entries_per_line = CONFIG["features.log.max_lines_per_entry"]
+ max_entries_per_line = CONFIG['features.log.max_lines_per_entry']
while display_queue:
msg, format, include_break = display_queue.pop(0)
@@ -1087,12 +1087,12 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
new_content_height = line_count + self.scroll - 1
content_height_delta = abs(self.last_content_height - new_content_height)
- force_redraw, force_redraw_reason = True, ""
+ force_redraw, force_redraw_reason = True, ''
if content_height_delta >= CONTENT_HEIGHT_REDRAW_THRESHOLD:
- force_redraw_reason = "estimate was off by %i" % content_height_delta
+ force_redraw_reason = 'estimate was off by %i' % content_height_delta
elif new_content_height > height and self.scroll + height - 1 > new_content_height:
- force_redraw_reason = "scrolled off the bottom of the page"
+ force_redraw_reason = 'scrolled off the bottom of the page'
elif not is_scroll_bar_visible and new_content_height > height - 1:
force_redraw_reason = "scroll bar wasn't previously visible"
elif is_scroll_bar_visible and new_content_height <= height - 1:
@@ -1103,7 +1103,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.last_content_height = new_content_height
if force_redraw:
- log.debug("redrawing the log panel with the corrected content height (%s)" % force_redraw_reason)
+ log.debug('redrawing the log panel with the corrected content height (%s)' % force_redraw_reason)
self.redraw(True)
self.vals_lock.release()
@@ -1124,7 +1124,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
while not self._halt:
current_day = days_since()
time_since_reset = time.time() - self._last_update
- max_log_update_rate = CONFIG["features.log.maxRefreshRate"] / 1000.0
+ max_log_update_rate = CONFIG['features.log.maxRefreshRate'] / 1000.0
sleep_time = 0
@@ -1173,20 +1173,20 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
# accounts for runlevel naming difference
- if "ERROR" in events:
- events.add("ERR")
- events.remove("ERROR")
+ if 'ERROR' in events:
+ events.add('ERR')
+ events.remove('ERROR')
- if "WARNING" in events:
- events.add("WARN")
- events.remove("WARNING")
+ if 'WARNING' in events:
+ events.add('WARN')
+ events.remove('WARNING')
tor_events = events.intersection(set(nyx.arguments.TOR_EVENT_TYPES.values()))
- nyx_events = events.intersection(set(["NYX_%s" % runlevel for runlevel in log.Runlevel.keys()]))
+ nyx_events = events.intersection(set(['NYX_%s' % runlevel for runlevel in log.Runlevel.keys()]))
# adds events unrecognized by nyx if we're listening to the 'UNKNOWN' type
- if "UNKNOWN" in events:
+ if 'UNKNOWN' in events:
tor_events.update(set(nyx.arguments.missing_event_types()))
controller = tor_controller()
@@ -1210,7 +1210,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
self.reprepopulate_events()
self.redraw(True)
elif event_type == State.CLOSED:
- log.notice("Tor control port closed")
+ log.notice('Tor control port closed')
def _get_title(self, width):
"""
@@ -1219,7 +1219,7 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
This truncates the attributes (with an ellipse) if too long, and condenses
runlevel ranges if there's three or more in a row (for instance NYX_INFO,
- NYX_NOTICE, and NYX_WARN becomes "NYX_INFO - WARN").
+ NYX_NOTICE, and NYX_WARN becomes 'NYX_INFO - WARN').
Arguments:
width - width constraint the label needs to fix in
@@ -1242,10 +1242,10 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
if not events_list:
if not current_pattern:
- panel_label = "Events:"
+ panel_label = 'Events:'
else:
label_pattern = str_tools.crop(current_pattern, width - 18)
- panel_label = "Events (filter: %s):" % label_pattern
+ panel_label = 'Events (filter: %s):' % label_pattern
else:
# does the following with all runlevel types (tor, nyx, and stem):
# - pulls to the start of the list
@@ -1261,9 +1261,9 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
reversed_runlevels = list(log.Runlevel)
reversed_runlevels.reverse()
- for prefix in ("NYX_", ""):
+ for prefix in ('NYX_', ''):
# blank ending runlevel forces the break condition to be reached at the end
- for runlevel in reversed_runlevels + [""]:
+ for runlevel in reversed_runlevels + ['']:
event_type = prefix + runlevel
if runlevel and event_type in events_list:
# runlevel event found, move to the tmp list
@@ -1302,28 +1302,28 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
prefixes = [entry[0] for entry in matches] + [prefix]
for k in range(len(prefixes)):
- if prefixes[k] == "":
- prefixes[k] = "TOR"
+ if prefixes[k] == '':
+ prefixes[k] = 'TOR'
else:
- prefixes[k] = prefixes[k].replace("_", "")
+ prefixes[k] = prefixes[k].replace('_', '')
- events_list.insert(0, "%s %s - %s" % ("/".join(prefixes), start_level, end_level))
+ events_list.insert(0, '%s %s - %s' % ('/'.join(prefixes), start_level, end_level))
else:
- events_list.insert(0, "%s%s - %s" % (prefix, start_level, end_level))
+ events_list.insert(0, '%s%s - %s' % (prefix, start_level, end_level))
# truncates to use an ellipsis if too long, for instance:
- attr_label = ", ".join(events_list)
+ attr_label = ', '.join(events_list)
if current_pattern:
- attr_label += " - filter: %s" % current_pattern
+ attr_label += ' - filter: %s' % current_pattern
attr_label = str_tools.crop(attr_label, width - 10, 1)
if attr_label:
- attr_label = " (%s)" % attr_label
+ attr_label = ' (%s)' % attr_label
- panel_label = "Events%s:" % attr_label
+ panel_label = 'Events%s:' % attr_label
# cache results and return
@@ -1343,12 +1343,12 @@ class LogPanel(panel.Panel, threading.Thread, logging.Handler):
event_listing - listing of log entries
"""
- cache_size = CONFIG["cache.log_panel.size"]
+ cache_size = CONFIG['cache.log_panel.size']
if len(event_listing) > cache_size:
del event_listing[cache_size:]
- log_ttl = CONFIG["features.log.entryDuration"]
+ log_ttl = CONFIG['features.log.entryDuration']
if log_ttl > 0:
current_day = days_since()
diff --git a/nyx/menu/actions.py b/nyx/menu/actions.py
index 5c0d205..03b7b77 100644
--- a/nyx/menu/actions.py
+++ b/nyx/menu/actions.py
@@ -27,22 +27,22 @@ def make_menu():
Constructs the base menu and all of its contents.
"""
- base_menu = nyx.menu.item.Submenu("")
+ base_menu = nyx.menu.item.Submenu('')
base_menu.add(make_actions_menu())
base_menu.add(make_view_menu())
control = nyx.controller.get_controller()
for page_panel in control.get_display_panels(include_sticky = False):
- if page_panel.get_name() == "graph":
+ if page_panel.get_name() == 'graph':
base_menu.add(make_graph_menu(page_panel))
- elif page_panel.get_name() == "log":
+ elif page_panel.get_name() == 'log':
base_menu.add(make_log_menu(page_panel))
- elif page_panel.get_name() == "connections":
+ elif page_panel.get_name() == 'connections':
base_menu.add(make_connections_menu(page_panel))
- elif page_panel.get_name() == "configuration":
+ elif page_panel.get_name() == 'configuration':
base_menu.add(make_configuration_menu(page_panel))
- elif page_panel.get_name() == "torrc":
+ elif page_panel.get_name() == 'torrc':
base_menu.add(make_torrc_menu(page_panel))
base_menu.add(make_help_menu())
@@ -62,23 +62,23 @@ def make_actions_menu():
control = nyx.controller.get_controller()
controller = tor_controller()
- header_panel = control.get_panel("header")
- actions_menu = nyx.menu.item.Submenu("Actions")
- actions_menu.add(nyx.menu.item.MenuItem("Close Menu", None))
- actions_menu.add(nyx.menu.item.MenuItem("New Identity", header_panel.send_newnym))
+ header_panel = control.get_panel('header')
+ actions_menu = nyx.menu.item.Submenu('Actions')
+ actions_menu.add(nyx.menu.item.MenuItem('Close Menu', None))
+ actions_menu.add(nyx.menu.item.MenuItem('New Identity', header_panel.send_newnym))
if controller.is_alive():
- actions_menu.add(nyx.menu.item.MenuItem("Stop Tor", controller.close))
+ actions_menu.add(nyx.menu.item.MenuItem('Stop Tor', controller.close))
- actions_menu.add(nyx.menu.item.MenuItem("Reset Tor", functools.partial(controller.signal, stem.Signal.RELOAD)))
+ actions_menu.add(nyx.menu.item.MenuItem('Reset Tor', functools.partial(controller.signal, stem.Signal.RELOAD)))
if control.is_paused():
- label, arg = "Unpause", False
+ label, arg = 'Unpause', False
else:
- label, arg = "Pause", True
+ label, arg = 'Pause', True
actions_menu.add(nyx.menu.item.MenuItem(label, functools.partial(control.set_paused, arg)))
- actions_menu.add(nyx.menu.item.MenuItem("Exit", control.quit))
+ actions_menu.add(nyx.menu.item.MenuItem('Exit', control.quit))
return actions_menu
@@ -92,7 +92,7 @@ def make_view_menu():
Color (Submenu)
"""
- view_menu = nyx.menu.item.Submenu("View")
+ view_menu = nyx.menu.item.Submenu('View')
control = nyx.controller.get_controller()
if control.get_page_count() > 0:
@@ -100,15 +100,15 @@ def make_view_menu():
for i in range(control.get_page_count()):
page_panels = control.get_display_panels(page_number = i, include_sticky = False)
- label = " / ".join([str_tools._to_camel_case(panel.get_name()) for panel in page_panels])
+ label = ' / '.join([str_tools._to_camel_case(panel.get_name()) for panel in page_panels])
view_menu.add(nyx.menu.item.SelectionMenuItem(label, page_group, i))
if ui_tools.is_color_supported():
- color_menu = nyx.menu.item.Submenu("Color")
+ color_menu = nyx.menu.item.Submenu('Color')
color_group = nyx.menu.item.SelectionGroup(ui_tools.set_color_override, ui_tools.get_color_override())
- color_menu.add(nyx.menu.item.SelectionMenuItem("All", color_group, None))
+ color_menu.add(nyx.menu.item.SelectionMenuItem('All', color_group, None))
for color in ui_tools.COLOR_LIST:
color_menu.add(nyx.menu.item.SelectionMenuItem(str_tools._to_camel_case(color), color_group, color))
@@ -125,9 +125,9 @@ def make_help_menu():
About
"""
- help_menu = nyx.menu.item.Submenu("Help")
- help_menu.add(nyx.menu.item.MenuItem("Hotkeys", nyx.popups.show_help_popup))
- help_menu.add(nyx.menu.item.MenuItem("About", nyx.popups.show_about_popup))
+ help_menu = nyx.menu.item.Submenu('Help')
+ help_menu.add(nyx.menu.item.MenuItem('Hotkeys', nyx.popups.show_help_popup))
+ help_menu.add(nyx.menu.item.MenuItem('About', nyx.popups.show_about_popup))
return help_menu
@@ -145,7 +145,7 @@ def make_graph_menu(graph_panel):
graph_panel - instance of the graph panel
"""
- graph_menu = nyx.menu.item.Submenu("Graph")
+ graph_menu = nyx.menu.item.Submenu('Graph')
# stats options
@@ -153,18 +153,18 @@ def make_graph_menu(graph_panel):
available_stats = graph_panel.stat_options()
available_stats.sort()
- for stat_key in ["None"] + available_stats:
- label = str_tools._to_camel_case(stat_key, divider = " ")
- stat_key = None if stat_key == "None" else stat_key
+ for stat_key in ['None'] + available_stats:
+ label = str_tools._to_camel_case(stat_key, divider = ' ')
+ stat_key = None if stat_key == 'None' else stat_key
graph_menu.add(nyx.menu.item.SelectionMenuItem(label, stat_group, stat_key))
# resizing option
- graph_menu.add(nyx.menu.item.MenuItem("Resize...", graph_panel.resize_graph))
+ graph_menu.add(nyx.menu.item.MenuItem('Resize...', graph_panel.resize_graph))
# interval submenu
- interval_menu = nyx.menu.item.Submenu("Interval")
+ interval_menu = nyx.menu.item.Submenu('Interval')
interval_group = nyx.menu.item.SelectionGroup(functools.partial(setattr, graph_panel, 'update_interval'), graph_panel.update_interval)
for interval in nyx.graph_panel.Interval:
@@ -174,7 +174,7 @@ def make_graph_menu(graph_panel):
# bounds submenu
- bounds_menu = nyx.menu.item.Submenu("Bounds")
+ bounds_menu = nyx.menu.item.Submenu('Bounds')
bounds_group = nyx.menu.item.SelectionGroup(functools.partial(setattr, graph_panel, 'bounds_type'), graph_panel.bounds_type)
for bounds_type in nyx.graph_panel.Bounds:
@@ -198,30 +198,30 @@ def make_log_menu(log_panel):
log_panel - instance of the log panel
"""
- log_menu = nyx.menu.item.Submenu("Log")
+ log_menu = nyx.menu.item.Submenu('Log')
- log_menu.add(nyx.menu.item.MenuItem("Events...", log_panel.show_event_selection_prompt))
- log_menu.add(nyx.menu.item.MenuItem("Snapshot...", log_panel.show_snapshot_prompt))
- log_menu.add(nyx.menu.item.MenuItem("Clear", log_panel.clear))
+ log_menu.add(nyx.menu.item.MenuItem('Events...', log_panel.show_event_selection_prompt))
+ log_menu.add(nyx.menu.item.MenuItem('Snapshot...', log_panel.show_snapshot_prompt))
+ log_menu.add(nyx.menu.item.MenuItem('Clear', log_panel.clear))
- if CONFIG["features.log.showDuplicateEntries"]:
- label, arg = "Hide", False
+ if CONFIG['features.log.showDuplicateEntries']:
+ label, arg = 'Hide', False
else:
- label, arg = "Show", True
+ label, arg = 'Show', True
- log_menu.add(nyx.menu.item.MenuItem("%s Duplicates" % label, functools.partial(log_panel.set_duplicate_visability, arg)))
+ log_menu.add(nyx.menu.item.MenuItem('%s Duplicates' % label, functools.partial(log_panel.set_duplicate_visability, arg)))
# filter submenu
- filter_menu = nyx.menu.item.Submenu("Filter")
+ filter_menu = nyx.menu.item.Submenu('Filter')
filter_group = nyx.menu.item.SelectionGroup(log_panel.make_filter_selection, log_panel.get_filter())
- filter_menu.add(nyx.menu.item.SelectionMenuItem("None", filter_group, None))
+ filter_menu.add(nyx.menu.item.SelectionMenuItem('None', filter_group, None))
for option in log_panel.filter_options:
filter_menu.add(nyx.menu.item.SelectionMenuItem(option, filter_group, option))
- filter_menu.add(nyx.menu.item.MenuItem("New...", log_panel.show_filter_prompt))
+ filter_menu.add(nyx.menu.item.MenuItem('New...', log_panel.show_filter_prompt))
log_menu.add(filter_menu)
return log_menu
@@ -240,7 +240,7 @@ def make_connections_menu(conn_panel):
conn_panel - instance of the connections panel
"""
- connections_menu = nyx.menu.item.Submenu("Connections")
+ connections_menu = nyx.menu.item.Submenu('Connections')
# listing options
@@ -254,15 +254,15 @@ def make_connections_menu(conn_panel):
# sorting option
- connections_menu.add(nyx.menu.item.MenuItem("Sorting...", conn_panel.show_sort_dialog))
+ connections_menu.add(nyx.menu.item.MenuItem('Sorting...', conn_panel.show_sort_dialog))
# resolver submenu
conn_resolver = nyx.util.tracker.get_connection_tracker()
- resolver_menu = nyx.menu.item.Submenu("Resolver")
+ resolver_menu = nyx.menu.item.Submenu('Resolver')
resolver_group = nyx.menu.item.SelectionGroup(conn_resolver.set_custom_resolver, conn_resolver.get_custom_resolver())
- resolver_menu.add(nyx.menu.item.SelectionMenuItem("auto", resolver_group, None))
+ resolver_menu.add(nyx.menu.item.SelectionMenuItem('auto', resolver_group, None))
for option in stem.util.connection.Resolver:
resolver_menu.add(nyx.menu.item.SelectionMenuItem(option, resolver_group, option))
@@ -283,16 +283,16 @@ def make_configuration_menu(config_panel):
config_panel - instance of the configuration panel
"""
- config_menu = nyx.menu.item.Submenu("Configuration")
- config_menu.add(nyx.menu.item.MenuItem("Save Config...", config_panel.show_write_dialog))
- config_menu.add(nyx.menu.item.MenuItem("Sorting...", config_panel.show_sort_dialog))
+ config_menu = nyx.menu.item.Submenu('Configuration')
+ config_menu.add(nyx.menu.item.MenuItem('Save Config...', config_panel.show_write_dialog))
+ config_menu.add(nyx.menu.item.MenuItem('Sorting...', config_panel.show_sort_dialog))
if config_panel.show_all:
- label, arg = "Filter", True
+ label, arg = 'Filter', True
else:
- label, arg = "Unfilter", False
+ label, arg = 'Unfilter', False
- config_menu.add(nyx.menu.item.MenuItem("%s Options" % label, functools.partial(config_panel.set_filtering, arg)))
+ config_menu.add(nyx.menu.item.MenuItem('%s Options' % label, functools.partial(config_panel.set_filtering, arg)))
return config_menu
@@ -308,20 +308,20 @@ def make_torrc_menu(torrc_panel):
torrc_panel - instance of the torrc panel
"""
- torrc_menu = nyx.menu.item.Submenu("Torrc")
- torrc_menu.add(nyx.menu.item.MenuItem("Reload", torrc_panel.reload_torrc))
+ torrc_menu = nyx.menu.item.Submenu('Torrc')
+ torrc_menu.add(nyx.menu.item.MenuItem('Reload', torrc_panel.reload_torrc))
if torrc_panel.strip_comments:
- label, arg = "Show", True
+ label, arg = 'Show', True
else:
- label, arg = "Hide", False
+ label, arg = 'Hide', False
- torrc_menu.add(nyx.menu.item.MenuItem("%s Comments" % label, functools.partial(torrc_panel.set_comments_visible, arg)))
+ torrc_menu.add(nyx.menu.item.MenuItem('%s Comments' % label, functools.partial(torrc_panel.set_comments_visible, arg)))
if torrc_panel.show_line_num:
- label, arg = "Hide", False
+ label, arg = 'Hide', False
else:
- label, arg = "Show", True
- torrc_menu.add(nyx.menu.item.MenuItem("%s Line Numbers" % label, functools.partial(torrc_panel.set_line_number_visible, arg)))
+ label, arg = 'Show', True
+ torrc_menu.add(nyx.menu.item.MenuItem('%s Line Numbers' % label, functools.partial(torrc_panel.set_line_number_visible, arg)))
return torrc_menu
diff --git a/nyx/menu/item.py b/nyx/menu/item.py
index d5b4bb6..8efcaf9 100644
--- a/nyx/menu/item.py
+++ b/nyx/menu/item.py
@@ -21,7 +21,7 @@ class MenuItem():
suffix for this item.
"""
- return ("", self._label, "")
+ return ('', self._label, '')
def get_parent(self):
"""
@@ -120,11 +120,11 @@ class Submenu(MenuItem):
def get_label(self):
"""
- Provides our label with a ">" suffix to indicate that we have suboptions.
+ Provides our label with a '>' suffix to indicate that we have suboptions.
"""
my_label = MenuItem.get_label(self)[1]
- return ("", my_label, " >")
+ return ('', my_label, ' >')
def add(self, menu_item):
"""
@@ -189,12 +189,12 @@ class SelectionMenuItem(MenuItem):
def get_label(self):
"""
- Provides our label with a "[X]" prefix if selected and "[ ]" if not.
+ Provides our label with a '[X]' prefix if selected and '[ ]' if not.
"""
my_label = MenuItem.get_label(self)[1]
- my_prefix = "[X] " if self.is_selected() else "[ ] "
- return (my_prefix, my_label, "")
+ my_prefix = '[X] ' if self.is_selected() else '[ ] '
+ return (my_prefix, my_label, '')
def select(self):
"""
diff --git a/nyx/menu/menu.py b/nyx/menu/menu.py
index b3cc273..59f9a4e 100644
--- a/nyx/menu/menu.py
+++ b/nyx/menu/menu.py
@@ -99,7 +99,7 @@ def show_menu():
# provide a message saying how to close the menu
- control.set_msg("Press m or esc to close the menu.", curses.A_BOLD, True)
+ control.set_msg('Press m or esc to close the menu.', curses.A_BOLD, True)
# renders the menu bar, noting where the open submenu is positioned
@@ -112,7 +112,7 @@ def show_menu():
draw_format |= curses.A_UNDERLINE
selection_left = draw_left
- draw_label = " %s " % top_level_item.get_label()[1]
+ draw_label = ' %s ' % top_level_item.get_label()[1]
popup.addstr(0, draw_left, draw_label, draw_format)
popup.addch(0, draw_left + len(draw_label), curses.ACS_VLINE)
@@ -158,8 +158,8 @@ def _draw_submenu(cursor, level, top, left):
# formatted string so we can display aligned menu entries
- label_format = " %%-%is%%-%is%%-%is " % (prefix_col_size, middle_col_size, suffix_col_size)
- menu_width = len(label_format % ("", "", ""))
+ label_format = ' %%-%is%%-%is%%-%is ' % (prefix_col_size, middle_col_size, suffix_col_size)
+ menu_width = len(label_format % ('', '', ''))
popup, _, _ = nyx.popups.init(len(submenu.get_children()), menu_width, top, left, below_static = False)
@@ -169,7 +169,7 @@ def _draw_submenu(cursor, level, top, left):
try:
# sets the background color
- popup.win.bkgd(' ', curses.A_STANDOUT | ui_tools.get_color("red"))
+ popup.win.bkgd(' ', curses.A_STANDOUT | ui_tools.get_color('red'))
draw_top, selection_top = 0, 0
diff --git a/nyx/popups.py b/nyx/popups.py
index 3f20e02..2f98e73 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -33,7 +33,7 @@ def init(height = -1, width = -1, top = 0, left = 0, below_static = True):
else:
sticky_height = 0
- popup = panel.Panel(control.get_screen(), "popup", top + sticky_height, left, height, width)
+ popup = panel.Panel(control.get_screen(), 'popup', top + sticky_height, left, height, width)
popup.set_visible(True)
# Redraws the popup to prepare a subwindow instance. If none is spawned then
@@ -58,7 +58,7 @@ def finalize():
panel.CURSES_LOCK.release()
-def input_prompt(msg, initial_value = ""):
+def input_prompt(msg, initial_value = ''):
"""
Prompts the user to enter a string on the control line (which usually
displays the page number and basic controls).
@@ -70,7 +70,7 @@ def input_prompt(msg, initial_value = ""):
panel.CURSES_LOCK.acquire()
control = nyx.controller.get_controller()
- msg_panel = control.get_panel("msg")
+ msg_panel = control.get_panel('msg')
msg_panel.set_message(msg)
msg_panel.redraw(True)
user_input = msg_panel.getstr(0, len(msg), initial_value)
@@ -136,7 +136,7 @@ def show_help_popup():
# test doing afterward in case of overwriting
popup.win.box()
- popup.addstr(0, 0, "Page %i Commands:" % (control.get_page() + 1), curses.A_STANDOUT)
+ popup.addstr(0, 0, 'Page %i Commands:' % (control.get_page() + 1), curses.A_STANDOUT)
for i in range(len(help_options)):
if i / 2 >= height - 2:
@@ -149,7 +149,7 @@ def show_help_popup():
key, description, selection = help_options[i]
if key:
- description = ": " + description
+ description = ': ' + description
row = (i / 2) + 1
col = 2 if i % 2 == 0 else 41
@@ -160,14 +160,14 @@ def show_help_popup():
col += len(description)
if selection:
- popup.addstr(row, col, " (")
+ popup.addstr(row, col, ' (')
popup.addstr(row, col + 2, selection, curses.A_BOLD)
- popup.addstr(row, col + 2 + len(selection), ")")
+ popup.addstr(row, col + 2 + len(selection), ')')
# tells user to press a key if the lower left is unoccupied
if len(help_options) < 13 and height == 9:
- popup.addstr(7, 2, "Press any key...")
+ popup.addstr(7, 2, 'Press any key...')
popup.win.refresh()
curses.cbreak()
@@ -196,12 +196,12 @@ def show_about_popup():
control = nyx.controller.get_controller()
popup.win.box()
- popup.addstr(0, 0, "About:", curses.A_STANDOUT)
- popup.addstr(1, 2, "nyx, version %s (released %s)" % (__version__, __release_date__), curses.A_BOLD)
- popup.addstr(2, 4, "Written by Damian Johnson (atagar@xxxxxxxxxxxxxx)")
- popup.addstr(3, 4, "Project page: www.atagar.com/nyx")
- popup.addstr(5, 2, "Released under the GPL v3 (http://www.gnu.org/licenses/gpl.html)")
- popup.addstr(7, 2, "Press any key...")
+ popup.addstr(0, 0, 'About:', curses.A_STANDOUT)
+ popup.addstr(1, 2, 'nyx, version %s (released %s)' % (__version__, __release_date__), curses.A_BOLD)
+ popup.addstr(2, 4, 'Written by Damian Johnson (atagar@xxxxxxxxxxxxxx)')
+ popup.addstr(3, 4, 'Project page: www.atagar.com/nyx')
+ popup.addstr(5, 2, 'Released under the GPL v3 (http://www.gnu.org/licenses/gpl.html)')
+ popup.addstr(7, 2, 'Press any key...')
popup.win.refresh()
curses.cbreak()
@@ -242,15 +242,15 @@ def show_sort_dialog(title, options, old_selection, option_colors):
curses.cbreak() # wait indefinitely for key presses (no timeout)
selection_options = list(options)
- selection_options.append("Cancel")
+ selection_options.append('Cancel')
while len(new_selections) < len(old_selection):
popup.win.erase()
popup.win.box()
popup.addstr(0, 0, title, curses.A_STANDOUT)
- _draw_sort_selection(popup, 1, 2, "Current Order: ", old_selection, option_colors)
- _draw_sort_selection(popup, 2, 2, "New Order: ", new_selections, option_colors)
+ _draw_sort_selection(popup, 1, 2, 'Current Order: ', old_selection, option_colors)
+ _draw_sort_selection(popup, 2, 2, 'New Order: ', new_selections, option_colors)
# presents remaining options, each row having up to four options with
# spacing of nineteen cells
@@ -280,7 +280,7 @@ def show_sort_dialog(title, options, old_selection, option_colors):
elif key.is_selection():
selection = selection_options[cursor_location]
- if selection == "Cancel":
+ if selection == 'Cancel':
break
else:
new_selections.append(selection)
@@ -318,14 +318,14 @@ def _draw_sort_selection(popup, y, x, prefix, options, option_colors):
for i in range(len(options)):
sort_type = options[i]
- sort_color = ui_tools.get_color(option_colors.get(sort_type, "white"))
+ sort_color = ui_tools.get_color(option_colors.get(sort_type, 'white'))
popup.addstr(y, x, sort_type, sort_color | curses.A_BOLD)
x += len(sort_type)
# comma divider between options, if this isn't the last
if i < len(options) - 1:
- popup.addstr(y, x, ", ", curses.A_BOLD)
+ popup.addstr(y, x, ', ', curses.A_BOLD)
x += 2
@@ -368,9 +368,9 @@ def show_menu(title, options, old_selection):
for i in range(len(options)):
label = options[i]
format = curses.A_STANDOUT if i == selection else curses.A_NORMAL
- tab = "> " if i == old_selection else " "
+ tab = '> ' if i == old_selection else ' '
popup.addstr(i + 1, 2, tab)
- popup.addstr(i + 1, 4, " %s " % label, format)
+ popup.addstr(i + 1, 4, ' %s ' % label, format)
popup.win.refresh()
diff --git a/nyx/starter.py b/nyx/starter.py
index 3d3aea2..3b56742 100644
--- a/nyx/starter.py
+++ b/nyx/starter.py
@@ -129,7 +129,7 @@ def _setup_debug_logging(args):
with open(args.config) as nyxrc_file:
nyxrc_content = nyxrc_file.read()
except IOError as exc:
- nyxrc_content = "[unable to read file: %s]" % exc.strerror
+ nyxrc_content = '[unable to read file: %s]' % exc.strerror
log.trace(
'debug.header',
@@ -270,7 +270,7 @@ def _set_process_name():
"nyx <input args>".
"""
- stem.util.system.set_process_name("nyx\0%s" % "\0".join(sys.argv[1:]))
+ stem.util.system.set_process_name('nyx\0%s' % '\0'.join(sys.argv[1:]))
def _shutdown_daemons(controller):
diff --git a/nyx/torrc_panel.py b/nyx/torrc_panel.py
index e96a76b..dd84fb3 100644
--- a/nyx/torrc_panel.py
+++ b/nyx/torrc_panel.py
@@ -15,18 +15,18 @@ from stem.util import conf, enum, str_tools
def conf_handler(key, value):
- if key == "features.config.file.max_lines_per_entry":
+ if key == 'features.config.file.max_lines_per_entry':
return max(1, value)
-CONFIG = conf.config_dict("nyx", {
- "features.config.file.showScrollbars": True,
- "features.config.file.max_lines_per_entry": 8,
+CONFIG = conf.config_dict('nyx', {
+ 'features.config.file.showScrollbars': True,
+ 'features.config.file.max_lines_per_entry': 8,
}, conf_handler)
# TODO: The nyxrc use case is incomplete. There should be equivilant reloading
# and validation capabilities to the torrc.
-Config = enum.Enum("TORRC", "NYXRC") # configuration file types that can be displayed
+Config = enum.Enum('TORRC', 'NYXRC') # configuration file types that can be displayed
class TorrcPanel(panel.Panel):
@@ -36,7 +36,7 @@ class TorrcPanel(panel.Panel):
"""
def __init__(self, stdscr, config_type):
- panel.Panel.__init__(self, stdscr, "torrc", 0)
+ panel.Panel.__init__(self, stdscr, 'torrc', 0)
self.vals_lock = threading.RLock()
self.config_type = config_type
@@ -113,9 +113,9 @@ class TorrcPanel(panel.Panel):
tor_config.get_torrc().load()
self._last_content_height_args = None
self.redraw(True)
- result_msg = "torrc reloaded"
+ result_msg = 'torrc reloaded'
except IOError:
- result_msg = "failed to reload torrc"
+ result_msg = 'failed to reload torrc'
self._last_content_height_args = None
self.redraw(True)
@@ -182,7 +182,7 @@ class TorrcPanel(panel.Panel):
conf_location = loaded_torrc.get_config_location()
if not loaded_torrc.is_loaded():
- rendered_contents = ["### Unable to load the torrc ###"]
+ rendered_contents = ['### Unable to load the torrc ###']
else:
rendered_contents = loaded_torrc.get_display_contents(self.strip_comments)
@@ -192,7 +192,7 @@ class TorrcPanel(panel.Panel):
loaded_torrc.get_lock().release()
else:
- loaded_nyxrc = conf.get_config("nyx")
+ loaded_nyxrc = conf.get_config('nyx')
conf_location = loaded_nyxrc._path
rendered_contents = list(loaded_nyxrc._raw_contents)
@@ -210,7 +210,7 @@ class TorrcPanel(panel.Panel):
scroll_offset = 0
- if CONFIG["features.config.file.showScrollbars"] and self._last_content_height > height - 1:
+ if CONFIG['features.config.file.showScrollbars'] and self._last_content_height > height - 1:
scroll_offset = 3
self.add_scroll_bar(self.scroll, self.scroll + height - 1, self._last_content_height, 1)
@@ -219,9 +219,9 @@ class TorrcPanel(panel.Panel):
# draws the top label
if self.is_title_visible():
- source_label = "Tor" if self.config_type == Config.TORRC else "Arm"
- location_label = " (%s)" % conf_location if conf_location else ""
- self.addstr(0, 0, "%s Configuration File%s:" % (source_label, location_label), curses.A_STANDOUT)
+ source_label = 'Tor' if self.config_type == Config.TORRC else 'Nyx'
+ location_label = ' (%s)' % conf_location if conf_location else ''
+ self.addstr(0, 0, '%s Configuration File%s:' % (source_label, location_label), curses.A_STANDOUT)
is_multiline = False # true if we're in the middle of a multiline torrc entry
@@ -245,7 +245,7 @@ class TorrcPanel(panel.Panel):
# parses the comment
- comment_index = line_text.find("#")
+ comment_index = line_text.find('#')
if comment_index != -1:
line_comp['comment'][0] = line_text[comment_index:]
@@ -254,7 +254,7 @@ class TorrcPanel(panel.Panel):
# splits the option and argument, preserving any whitespace around them
stripped_line = line_text.strip()
- option_index = stripped_line.find(" ")
+ option_index = stripped_line.find(' ')
if is_multiline:
# part of a multiline entry started on a previous line so everything
@@ -273,7 +273,7 @@ class TorrcPanel(panel.Panel):
# with a slash
if stripped_line:
- is_multiline = stripped_line.endswith("\\")
+ is_multiline = stripped_line.endswith('\\')
# gets the correction
@@ -296,13 +296,13 @@ class TorrcPanel(panel.Panel):
# draws the line number
if self.show_line_num and display_line < height and display_line >= 1:
- line_number_str = ("%%%ii" % (line_number_offset - 1)) % (line_number + 1)
+ line_number_str = ('%%%ii' % (line_number_offset - 1)) % (line_number + 1)
self.addstr(display_line, scroll_offset, line_number_str, curses.A_BOLD, 'yellow')
# draws the rest of the components with line wrap
cursor_location, line_offset = line_number_offset + scroll_offset, 0
- max_lines_per_entry = CONFIG["features.config.file.max_lines_per_entry"]
+ max_lines_per_entry = CONFIG['features.config.file.max_lines_per_entry']
display_queue = [line_comp[entry] for entry in ('option', 'argument', 'correction', 'comment')]
while display_queue:
diff --git a/nyx/util/panel.py b/nyx/util/panel.py
index f935a08..bd20de7 100644
--- a/nyx/util/panel.py
+++ b/nyx/util/panel.py
@@ -41,13 +41,13 @@ def _no_op(arg):
FORMAT_TAGS = {
- "<b>": (_no_op, curses.A_BOLD),
- "<u>": (_no_op, curses.A_UNDERLINE),
- "<h>": (_no_op, curses.A_STANDOUT),
+ '<b>': (_no_op, curses.A_BOLD),
+ '<u>': (_no_op, curses.A_UNDERLINE),
+ '<h>': (_no_op, curses.A_STANDOUT),
}
for color_label in ui_tools.COLOR_LIST:
- FORMAT_TAGS["<%s>" % color_label] = (ui_tools.get_color, color_label)
+ FORMAT_TAGS['<%s>' % color_label] = (ui_tools.get_color, color_label)
# prevents curses redraws if set
HALT_ACTIVITY = False
@@ -174,13 +174,13 @@ class Panel(object):
the value when it was last unpaused (or its current value if we're
currently unpaused). For instance...
- > self.set_pause_attr("myVar")
+ > self.set_pause_attr('myVar')
> self.myVar = 5
- > self.myVar = 6 # self.get_attr("myVar") -> 6
+ > self.myVar = 6 # self.get_attr('myVar') -> 6
> self.set_paused(True)
- > self.myVar = 7 # self.get_attr("myVar") -> 6
+ > self.myVar = 7 # self.get_attr('myVar') -> 6
> self.set_paused(False)
- > self.myVar = 7 # self.get_attr("myVar") -> 7
+ > self.myVar = 7 # self.get_attr('myVar') -> 7
Arguments:
attr - parameter to be tracked for get_attr
@@ -553,7 +553,7 @@ class Panel(object):
exception for invalid formatting). Unrecognized tags are treated as normal
text. This should only be called from the context of a panel's draw method.
- Text in multiple color tags (for instance "<blue><red>hello</red></blue>")
+ Text in multiple color tags (for instance '<blue><red>hello</red></blue>')
uses the bitwise OR of those flags (hint: that's probably not what you
want).
@@ -577,8 +577,8 @@ class Panel(object):
expected_tags = FORMAT_TAGS.keys() + expected_close_tags
while next_tag is None:
- tag_start = unused_msg.find("<", tmp_checked)
- tag_end = unused_msg.find(">", tag_start) + 1 if tag_start != -1 else -1
+ tag_start = unused_msg.find('<', tmp_checked)
+ tag_end = unused_msg.find('>', tag_start) + 1 if tag_start != -1 else -1
if tag_start == -1 or tag_end == -1:
break # no more tags to consume
@@ -598,7 +598,7 @@ class Panel(object):
unused_msg = unused_msg[tag_end:]
else:
msg_segment = unused_msg
- unused_msg = ""
+ unused_msg = ''
# adds text before tag with current formatting
@@ -613,12 +613,12 @@ class Panel(object):
# applies tag attributes for future text
if next_tag:
- format_tag = "<" + next_tag[2:] if next_tag.startswith("</") else next_tag
+ format_tag = '<' + next_tag[2:] if next_tag.startswith('</') else next_tag
format_match = FORMAT_TAGS[format_tag][0](FORMAT_TAGS[format_tag][1])
- if not next_tag.startswith("</"):
+ if not next_tag.startswith('</'):
# open tag - add formatting
- expected_close_tags.append("</" + next_tag[1:])
+ expected_close_tags.append('</' + next_tag[1:])
formatting.append(format_match)
else:
# close tag - remove formatting
@@ -630,10 +630,10 @@ class Panel(object):
if expected_close_tags and not unused_msg:
# if we're done then raise an exception for any unclosed tags (tisk, tisk)
- base_msg = "Unclosed formatting tag%s:" % ("s" if len(expected_close_tags) > 1 else "")
+ base_msg = 'Unclosed formatting tag%s:' % ('s' if len(expected_close_tags) > 1 else '')
raise ValueError("%s: '%s'\n \"%s\"" % (base_msg, "', '".join(expected_close_tags), msg))
- def getstr(self, y, x, initial_text = "", text_format = None, max_width = None, validator = None):
+ def getstr(self, y, x, initial_text = '', text_format = None, max_width = None, validator = None):
"""
Provides a text field where the user can input a string, blocking until
they've done so and returning the result. If the user presses escape then
@@ -765,9 +765,9 @@ class Panel(object):
for i in range(scrollbar_height):
if i >= slider_top and i <= slider_top + slider_size:
- self.addstr(i + draw_top, draw_left, " ", curses.A_STANDOUT)
+ self.addstr(i + draw_top, draw_left, ' ', curses.A_STANDOUT)
else:
- self.addstr(i + draw_top, draw_left, " ")
+ self.addstr(i + draw_top, draw_left, ' ')
# draws box around the scroll bar
diff --git a/nyx/util/text_input.py b/nyx/util/text_input.py
index 4faec1e..3172750 100644
--- a/nyx/util/text_input.py
+++ b/nyx/util/text_input.py
@@ -127,7 +127,7 @@ class HistoryValidator(TextInputValidator):
# the fields input prior to selecting a backlog item
- self.custom_input = ""
+ self.custom_input = ''
def handle_key(self, key, textbox):
if key in (curses.KEY_UP, curses.KEY_DOWN):
diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 5a9f402..4e3f16e 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -16,65 +16,65 @@ from stem.util import conf, enum, log, str_tools, system
# filename used for cached tor config descriptions
-CONFIG_DESC_FILENAME = "torConfigDesc.txt"
+CONFIG_DESC_FILENAME = 'torConfigDesc.txt'
# messages related to loading the tor configuration descriptions
DESC_LOAD_SUCCESS_MSG = "Loaded configuration descriptions from '%s' (runtime: %0.3f)"
-DESC_LOAD_FAILED_MSG = "Unable to load configuration descriptions (%s)"
-DESC_INTERNAL_LOAD_SUCCESS_MSG = "Falling back to descriptions for Tor %s"
+DESC_LOAD_FAILED_MSG = 'Unable to load configuration descriptions (%s)'
+DESC_INTERNAL_LOAD_SUCCESS_MSG = 'Falling back to descriptions for Tor %s'
DESC_INTERNAL_LOAD_FAILED_MSG = "Unable to load fallback descriptions. Categories and help for Tor's configuration options won't be available. (%s)"
DESC_READ_MAN_SUCCESS_MSG = "Read descriptions for tor's configuration options from its man page (runtime %0.3f)"
DESC_READ_MAN_FAILED_MSG = "Unable to get the descriptions of Tor's configuration options from its man page (%s)"
DESC_SAVE_SUCCESS_MSG = "Saved configuration descriptions to '%s' (runtime: %0.3f)"
-DESC_SAVE_FAILED_MSG = "Unable to save configuration descriptions (%s)"
+DESC_SAVE_FAILED_MSG = 'Unable to save configuration descriptions (%s)'
def conf_handler(key, value):
- if key == "torrc.important":
+ if key == 'torrc.important':
# stores lowercase entries to drop case sensitivity
return [entry.lower() for entry in value]
-CONFIG = conf.config_dict("nyx", {
- "features.torrc.validate": True,
- "torrc.important": [],
- "torrc.alias": {},
- "torrc.units.size.b": [],
- "torrc.units.size.kb": [],
- "torrc.units.size.mb": [],
- "torrc.units.size.gb": [],
- "torrc.units.size.tb": [],
- "torrc.units.time.sec": [],
- "torrc.units.time.min": [],
- "torrc.units.time.hour": [],
- "torrc.units.time.day": [],
- "torrc.units.time.week": [],
- "startup.data_directory": "~/.nyx",
- "features.config.descriptions.enabled": True,
- "features.config.descriptions.persist": True,
- "tor.chroot": '',
+CONFIG = conf.config_dict('nyx', {
+ 'features.torrc.validate': True,
+ 'torrc.important': [],
+ 'torrc.alias': {},
+ 'torrc.units.size.b': [],
+ 'torrc.units.size.kb': [],
+ 'torrc.units.size.mb': [],
+ 'torrc.units.size.gb': [],
+ 'torrc.units.size.tb': [],
+ 'torrc.units.time.sec': [],
+ 'torrc.units.time.min': [],
+ 'torrc.units.time.hour': [],
+ 'torrc.units.time.day': [],
+ 'torrc.units.time.week': [],
+ 'startup.data_directory': '~/.nyx',
+ 'features.config.descriptions.enabled': True,
+ 'features.config.descriptions.persist': True,
+ 'tor.chroot': '',
}, conf_handler)
def general_conf_handler(config, key):
value = config.get(key)
- if key.startswith("torrc.summary."):
+ if key.startswith('torrc.summary.'):
# we'll look for summary keys with a lowercase config name
CONFIG[key.lower()] = value
- elif key.startswith("torrc.units.") and value:
+ elif key.startswith('torrc.units.') and value:
# all the torrc.units.* values are comma separated lists
- return [entry.strip() for entry in value[0].split(",")]
+ return [entry.strip() for entry in value[0].split(',')]
-conf.get_config("nyx").add_listener(general_conf_handler, backfill = True)
+conf.get_config('nyx').add_listener(general_conf_handler, backfill = True)
# enums and values for numeric torrc entries
-ValueType = enum.Enum("UNRECOGNIZED", "SIZE", "TIME")
-SIZE_MULT = {"b": 1, "kb": 1024, "mb": 1048576, "gb": 1073741824, "tb": 1099511627776}
-TIME_MULT = {"sec": 1, "min": 60, "hour": 3600, "day": 86400, "week": 604800}
+ValueType = enum.Enum('UNRECOGNIZED', 'SIZE', 'TIME')
+SIZE_MULT = {'b': 1, 'kb': 1024, 'mb': 1048576, 'gb': 1073741824, 'tb': 1099511627776}
+TIME_MULT = {'sec': 1, 'min': 60, 'hour': 3600, 'day': 86400, 'week': 604800}
# enums for issues found during torrc validation:
# DUPLICATE - entry is ignored due to being a duplicate
@@ -82,7 +82,7 @@ TIME_MULT = {"sec": 1, "min": 60, "hour": 3600, "day": 86400, "week": 604800}
# MISSING - value differs from its default but is missing from the torrc
# IS_DEFAULT - the configuration option matches tor's default
-ValidationError = enum.Enum("DUPLICATE", "MISMATCH", "MISSING", "IS_DEFAULT")
+ValidationError = enum.Enum('DUPLICATE', 'MISMATCH', 'MISSING', 'IS_DEFAULT')
# descriptions of tor's configuration options fetched from its man page
@@ -91,17 +91,17 @@ CONFIG_DESCRIPTIONS = {}
# categories for tor configuration options
-Category = enum.Enum("GENERAL", "CLIENT", "RELAY", "DIRECTORY", "AUTHORITY", "HIDDEN_SERVICE", "TESTING", "UNKNOWN")
+Category = enum.Enum('GENERAL', 'CLIENT', 'RELAY', 'DIRECTORY', 'AUTHORITY', 'HIDDEN_SERVICE', 'TESTING', 'UNKNOWN')
TORRC = None # singleton torrc instance
MAN_OPT_INDENT = 7 # indentation before options in the man page
MAN_EX_INDENT = 15 # indentation used for man page examples
-PERSIST_ENTRY_DIVIDER = "-" * 80 + "\n" # splits config entries when saving to a file
+PERSIST_ENTRY_DIVIDER = '-' * 80 + '\n' # splits config entries when saving to a file
MULTILINE_PARAM = None # cached multiline parameters (lazily loaded)
# torrc options that bind to ports
-PORT_OPT = ("SocksPort", "ORPort", "DirPort", "ControlPort", "TransPort")
+PORT_OPT = ('SocksPort', 'ORPort', 'DirPort', 'ControlPort', 'TransPort')
class ManPageEntry:
@@ -153,7 +153,7 @@ def load_option_descriptions(load_path = None, check_version = True):
CONFIG_DESCRIPTIONS.clear()
raised_exc = None
- loaded_version = ""
+ loaded_version = ''
try:
if load_path:
@@ -162,23 +162,23 @@ def load_option_descriptions(load_path = None, check_version = True):
# <arg description>
# <description, possibly multiple lines>
# <PERSIST_ENTRY_DIVIDER>
- input_file = open(load_path, "r")
+ input_file = open(load_path, 'r')
input_file_contents = input_file.readlines()
input_file.close()
try:
version_line = input_file_contents.pop(0).rstrip()
- if version_line.startswith("Tor Version "):
+ if version_line.startswith('Tor Version '):
file_version = version_line[12:]
loaded_version = file_version
- tor_version = tor_controller().get_info("version", "")
+ tor_version = tor_controller().get_info('version', '')
if check_version and file_version != tor_version:
msg = "wrong version, tor is %s but the file's from %s" % (tor_version, file_version)
raise IOError(msg)
else:
- raise IOError("unable to parse version")
+ raise IOError('unable to parse version')
while input_file_contents:
# gets category enum, failing if it doesn't exist
@@ -191,20 +191,20 @@ def load_option_descriptions(load_path = None, check_version = True):
# gets the position in the man page
index_arg, index_str = -1, input_file_contents.pop(0).rstrip()
- if index_str.startswith("index: "):
+ if index_str.startswith('index: '):
index_str = index_str[7:]
if index_str.isdigit():
index_arg = int(index_str)
else:
- raise IOError("non-numeric index value: %s" % index_str)
+ raise IOError('non-numeric index value: %s' % index_str)
else:
- raise IOError("malformed index argument: %s" % index_str)
+ raise IOError('malformed index argument: %s' % index_str)
option = input_file_contents.pop(0).rstrip()
argument = input_file_contents.pop(0).rstrip()
- description, loaded_line = "", input_file_contents.pop(0)
+ description, loaded_line = '', input_file_contents.pop(0)
while loaded_line != PERSIST_ENTRY_DIVIDER:
description += loaded_line
@@ -217,25 +217,25 @@ def load_option_descriptions(load_path = None, check_version = True):
CONFIG_DESCRIPTIONS[option.lower()] = ManPageEntry(option, index_arg, category, argument, description.rstrip())
except IndexError:
CONFIG_DESCRIPTIONS.clear()
- raise IOError("input file format is invalid")
+ raise IOError('input file format is invalid')
else:
- man_call_results = system.call("man tor", None)
+ man_call_results = system.call('man tor', None)
if not man_call_results:
- raise IOError("man page not found")
+ raise IOError('man page not found')
# Fetches all options available with this tor instance. This isn't
# vital, and the valid_options are left empty if the call fails.
controller, valid_options = tor_controller(), []
- config_option_query = controller.get_info("config/names", None)
+ config_option_query = controller.get_info('config/names', None)
if config_option_query:
- for line in config_option_query.strip().split("\n"):
- valid_options.append(line[:line.find(" ")].lower())
+ for line in config_option_query.strip().split('\n'):
+ valid_options.append(line[:line.find(' ')].lower())
option_count, last_option, last_arg = 0, None, None
- last_category, last_description = Category.GENERAL, ""
+ last_category, last_description = Category.GENERAL, ''
for line in man_call_results:
line = codecs.latin_1_encode(line, 'replace')[0]
@@ -243,13 +243,13 @@ 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
- is_opt_indent = line.startswith(" " * MAN_OPT_INDENT) and line[MAN_OPT_INDENT] != " "
+ is_opt_indent = line.startswith(' ' * MAN_OPT_INDENT) and line[MAN_OPT_INDENT] != ' '
- is_category_line = not line.startswith(" ") and "OPTIONS" in line
+ is_category_line = not line.startswith(' ') and 'OPTIONS' in line
# if this is a category header or a new option, add an entry using the
# buffered results
@@ -266,12 +266,12 @@ def load_option_descriptions(load_path = None, check_version = True):
CONFIG_DESCRIPTIONS[last_option.lower()] = ManPageEntry(last_option, option_count, last_category, last_arg, stripped_description)
option_count += 1
- last_description = ""
+ last_description = ''
# parses the option and argument
line = line.strip()
- div_index = line.find(" ")
+ div_index = line.find(' ')
if div_index != -1:
last_option, last_arg = line[:div_index], line[div_index + 1:]
@@ -279,34 +279,34 @@ def load_option_descriptions(load_path = None, check_version = True):
# if this is a category header then switch it
if is_category_line:
- if line.startswith("OPTIONS"):
+ if line.startswith('OPTIONS'):
last_category = Category.GENERAL
- elif line.startswith("CLIENT"):
+ elif line.startswith('CLIENT'):
last_category = Category.CLIENT
- elif line.startswith("SERVER"):
+ elif line.startswith('SERVER'):
last_category = Category.RELAY
- elif line.startswith("DIRECTORY SERVER"):
+ elif line.startswith('DIRECTORY SERVER'):
last_category = Category.DIRECTORY
- elif line.startswith("DIRECTORY AUTHORITY SERVER"):
+ elif line.startswith('DIRECTORY AUTHORITY SERVER'):
last_category = Category.AUTHORITY
- elif line.startswith("HIDDEN SERVICE"):
+ elif line.startswith('HIDDEN SERVICE'):
last_category = Category.HIDDEN_SERVICE
- elif line.startswith("TESTING NETWORK"):
+ elif line.startswith('TESTING NETWORK'):
last_category = Category.TESTING
else:
- log.notice("Unrecognized category in the man page: %s" % line.strip())
+ log.notice('Unrecognized category in the man page: %s' % line.strip())
else:
# Appends the text to the running description. Empty lines and lines
# starting with a specific indentation are used for formatting, for
# instance the ExitPolicy and TestingTorNetwork entries.
- if last_description and last_description[-1] != "\n":
- last_description += " "
+ if last_description and last_description[-1] != '\n':
+ last_description += ' '
if not stripped_line:
- last_description += "\n\n"
- elif line.startswith(" " * MAN_EX_INDENT):
- last_description += " %s\n" % stripped_line
+ last_description += '\n\n'
+ elif line.startswith(' ' * MAN_EX_INDENT):
+ last_description += ' %s\n' % stripped_line
else:
last_description += stripped_line
except IOError as exc:
@@ -336,18 +336,18 @@ def save_option_descriptions(path):
if not os.path.exists(base_dir):
os.makedirs(base_dir)
- output_file = open(path, "w")
+ output_file = open(path, 'w')
CONFIG_DESCRIPTIONS_LOCK.acquire()
sorted_options = CONFIG_DESCRIPTIONS.keys()
sorted_options.sort()
- tor_version = tor_controller().get_info("version", "")
- output_file.write("Tor Version %s\n" % tor_version)
+ tor_version = tor_controller().get_info('version', '')
+ output_file.write('Tor Version %s\n' % tor_version)
for i in range(len(sorted_options)):
man_entry = get_config_description(sorted_options[i])
- output_file.write("%s\nindex: %i\n%s\n%s\n%s\n" % (man_entry.category, man_entry.index, man_entry.option, man_entry.arg_usage, man_entry.description))
+ output_file.write('%s\nindex: %i\n%s\n%s\n%s\n' % (man_entry.category, man_entry.index, man_entry.option, man_entry.arg_usage, man_entry.description))
if i != len(sorted_options) - 1:
output_file.write(PERSIST_ENTRY_DIVIDER)
@@ -365,7 +365,7 @@ def get_config_summary(option):
option - tor config option
"""
- return CONFIG.get("torrc.summary.%s" % option.lower())
+ return CONFIG.get('torrc.summary.%s' % option.lower())
def is_important(option):
@@ -377,7 +377,7 @@ def is_important(option):
option - tor config option
"""
- return option.lower() in CONFIG["torrc.important"]
+ return option.lower() in CONFIG['torrc.important']
def get_config_description(option):
@@ -423,11 +423,11 @@ def get_config_location():
"""
controller = tor_controller()
- config_location = controller.get_info("config-file", None)
+ config_location = controller.get_info('config-file', None)
tor_pid, tor_prefix = controller.controller.get_pid(None), CONFIG['tor.chroot']
if not config_location:
- raise IOError("unable to query the torrc location")
+ raise IOError('unable to query the torrc location')
try:
tor_cwd = system.cwd(tor_pid)
@@ -450,13 +450,13 @@ def get_multiline_parameters():
if MULTILINE_PARAM is None:
controller, multiline_entries = tor_controller(), []
- config_option_query = controller.get_info("config/names", None)
+ config_option_query = controller.get_info('config/names', None)
if config_option_query:
- for line in config_option_query.strip().split("\n"):
- conf_option, conf_type = line.strip().split(" ", 1)
+ for line in config_option_query.strip().split('\n'):
+ conf_option, conf_type = line.strip().split(' ', 1)
- if conf_type in ("LineList", "Dependant", "Virtual"):
+ if conf_type in ('LineList', 'Dependant', 'Virtual'):
multiline_entries.append(conf_option)
else:
# unable to query tor connection, so not caching results
@@ -476,8 +476,8 @@ def get_custom_options(include_value = False):
this just contains the options
"""
- config_text = tor_controller().get_info("config-text", "").strip()
- config_lines = config_text.split("\n")
+ config_text = tor_controller().get_info('config-text', '').strip()
+ config_lines = config_text.split('\n')
# removes any duplicates
@@ -493,24 +493,24 @@ def get_custom_options(include_value = False):
# https://trac.torproject.org/projects/tor/ticket/4602
try:
- config_lines.remove("Log notice stdout")
+ config_lines.remove('Log notice stdout')
except ValueError:
pass
try:
- config_lines.remove("Log notice file /var/log/tor/log")
+ config_lines.remove('Log notice file /var/log/tor/log')
except ValueError:
pass
try:
- config_lines.remove("Nickname %s" % socket.gethostname())
+ config_lines.remove('Nickname %s' % socket.gethostname())
except ValueError:
pass
if include_value:
return config_lines
else:
- return [line[:line.find(" ")] for line in config_lines]
+ return [line[:line.find(' ')] for line in config_lines]
def save_conf(destination = None, contents = None):
@@ -550,8 +550,8 @@ def save_conf(destination = None, contents = None):
# double check that "GETINFO config-text" is unavailable rather than just
# giving an empty result
- if tor_controller().get_info("config-text", None) is None:
- raise IOError("determining the torrc requires Tor version 0.2.2.7")
+ if tor_controller().get_info('config-text', None) is None:
+ raise IOError('determining the torrc requires Tor version 0.2.2.7')
current_location = None
@@ -568,7 +568,7 @@ def save_conf(destination = None, contents = None):
if not destination:
raise IOError("unable to determine the torrc's path")
- log_msg = "Saved config by %%s to %s (runtime: %%0.4f)" % destination
+ log_msg = 'Saved config by %%s to %s (runtime: %%0.4f)' % destination
# attempts SAVECONF if we're updating our torrc with the current state
@@ -581,7 +581,7 @@ def save_conf(destination = None, contents = None):
except IOError:
pass
- log.debug(log_msg % ("SAVECONF", time.time() - start_time))
+ log.debug(log_msg % ('SAVECONF', time.time() - start_time))
return # if successful then we're done
except:
pass
@@ -598,8 +598,8 @@ def save_conf(destination = None, contents = None):
# saves the configuration to the file
- config_file = open(destination, "w")
- config_file.write("\n".join(contents))
+ config_file = open(destination, 'w')
+ config_file.write('\n'.join(contents))
config_file.close()
except (IOError, OSError) as exc:
raise IOError(exc)
@@ -612,7 +612,7 @@ def save_conf(destination = None, contents = None):
except IOError:
pass
- log.debug(log_msg % ("directly writing", time.time() - start_time))
+ log.debug(log_msg % ('directly writing', time.time() - start_time))
def validate(contents = None):
@@ -633,18 +633,18 @@ def validate(contents = None):
# information see:
# https://trac.torproject.org/projects/tor/ticket/1929
- stripped_contents, multiline_buffer = [], ""
+ stripped_contents, multiline_buffer = [], ''
for line in _strip_comments(contents):
if not line:
- stripped_contents.append("")
+ stripped_contents.append('')
else:
line = multiline_buffer + line
- multiline_buffer = ""
+ multiline_buffer = ''
- if line.endswith("\\"):
+ if line.endswith('\\'):
multiline_buffer = line[:-1]
- stripped_contents.append("")
+ stripped_contents.append('')
else:
stripped_contents.append(line.strip())
@@ -659,7 +659,7 @@ def validate(contents = None):
if len(line_comp) == 2:
option, value = line_comp
else:
- option, value = line_text, ""
+ option, value = line_text, ''
# Tor is case insensetive when parsing its torrc. This poses a bit of an
# issue for us because we want all of our checks to be case insensetive
@@ -678,8 +678,8 @@ def validate(contents = None):
# if an aliased option then use its real name
- if option in CONFIG["torrc.alias"]:
- option = CONFIG["torrc.alias"][option]
+ if option in CONFIG['torrc.alias']:
+ option = CONFIG['torrc.alias'][option]
# most parameters are overwritten if defined multiple times
@@ -696,13 +696,13 @@ def validate(contents = None):
# replace aliases with their recognized representation
- if option in CONFIG["torrc.alias"]:
- option = CONFIG["torrc.alias"][option]
+ if option in CONFIG['torrc.alias']:
+ option = CONFIG['torrc.alias'][option]
# tor appears to replace tabs with a space, for instance:
# "accept\t*:563" is read back as "accept *:563"
- value = value.replace("\t", " ")
+ value = value.replace('\t', ' ')
# parse value if it's a size or time, expanding the units
@@ -717,11 +717,11 @@ def validate(contents = None):
value_list = [value]
if option in get_multiline_parameters():
- value_list = [val.strip() for val in value.split(",")]
+ value_list = [val.strip() for val in value.split(',')]
fetched_values, tor_values = tor_values, []
for fetched_value in fetched_values:
- for fetched_entry in fetched_value.split(","):
+ for fetched_entry in fetched_value.split(','):
fetched_entry = fetched_entry.strip()
if fetched_entry not in tor_values:
@@ -742,7 +742,7 @@ def validate(contents = None):
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.append((line_number, ValidationError.MISMATCH, ', '.join(display_values)))
# checks if any custom options are missing from the torrc
@@ -753,7 +753,7 @@ def validate(contents = None):
#
# https://trac.torproject.org/projects/tor/ticket/4237
- if option == "DirReqStatistics":
+ if option == 'DirReqStatistics':
continue
if option not in seen_options:
@@ -772,8 +772,8 @@ def _parse_conf_value(conf_arg):
conf_arg - torrc argument
"""
- if conf_arg.count(" ") == 1:
- val, unit = conf_arg.lower().split(" ", 1)
+ if conf_arg.count(' ') == 1:
+ val, unit = conf_arg.lower().split(' ', 1)
if not val.isdigit():
return conf_arg, ValueType.UNRECOGNIZED
@@ -796,11 +796,11 @@ def _get_unit_type(unit):
"""
for label in SIZE_MULT:
- if unit in CONFIG["torrc.units.size." + label]:
+ if unit in CONFIG['torrc.units.size.' + label]:
return SIZE_MULT[label], ValueType.SIZE
for label in TIME_MULT:
- if unit in CONFIG["torrc.units.time." + label]:
+ if unit in CONFIG['torrc.units.time.' + label]:
return TIME_MULT[label], ValueType.TIME
return None, ValueType.UNRECOGNIZED
@@ -817,8 +817,8 @@ def _strip_comments(contents):
stripped_contents = []
for line in contents:
- if line and "#" in line:
- line = line[:line.find("#")]
+ if line and '#' in line:
+ line = line[:line.find('#')]
stripped_contents.append(line.strip())
@@ -863,12 +863,12 @@ class Torrc():
try:
self.config_location = get_config_location()
- config_file = open(self.config_location, "r")
+ config_file = open(self.config_location, 'r')
self.contents = config_file.readlines()
config_file.close()
except IOError as exc:
if log_failure and not self.is_foad_fail_warned:
- log.warn("Unable to load torrc (%s)" % exc.strerror)
+ log.warn('Unable to load torrc (%s)' % exc.strerror)
self.is_foad_fail_warned = True
self.vals_lock.release()
@@ -925,7 +925,7 @@ class Torrc():
for line_number in range(len(self.contents)):
line_text = self.contents[line_number]
- line_text = line_text.replace("\t", " ")
+ line_text = line_text.replace('\t', ' ')
line_text = ui_tools.get_printable(line_text)
self.displayable_contents.append(line_text)
@@ -953,11 +953,11 @@ class Torrc():
return_val = None
else:
tor_version = tor_controller().get_version(None)
- skip_validation = not CONFIG["features.torrc.validate"]
+ skip_validation = not CONFIG['features.torrc.validate']
skip_validation |= (tor_version is None or not tor_version >= stem.version.Requirement.GETINFO_CONFIG_TEXT)
if skip_validation:
- log.info("Skipping torrc validation (requires tor 0.2.2.7-alpha)")
+ log.info('Skipping torrc validation (requires tor 0.2.2.7-alpha)')
return_val = {}
else:
if self.corrections is None:
@@ -988,9 +988,9 @@ class Torrc():
for line_number, issue, msg in corrections:
if issue == ValidationError.DUPLICATE:
- duplicate_options.append("%s (line %i)" % (msg, line_number + 1))
+ duplicate_options.append('%s (line %i)' % (msg, line_number + 1))
elif issue == ValidationError.IS_DEFAULT:
- default_options.append("%s (line %i)" % (msg, line_number + 1))
+ default_options.append('%s (line %i)' % (msg, line_number + 1))
elif issue == ValidationError.MISMATCH:
mismatch_lines.append(line_number + 1)
elif issue == ValidationError.MISSING:
@@ -1001,21 +1001,21 @@ class Torrc():
if duplicate_options:
if len(duplicate_options) > 1:
- msg += "\n- entries ignored due to having duplicates: "
+ msg += '\n- entries ignored due to having duplicates: '
else:
- msg += "\n- entry ignored due to having a duplicate: "
+ msg += '\n- entry ignored due to having a duplicate: '
duplicate_options.sort()
- msg += ", ".join(duplicate_options)
+ msg += ', '.join(duplicate_options)
if default_options:
if len(default_options) > 1:
- msg += "\n- entries match their default values: "
+ msg += '\n- entries match their default values: '
else:
- msg += "\n- entry matches its default value: "
+ msg += '\n- entry matches its default value: '
default_options.sort()
- msg += ", ".join(default_options)
+ msg += ', '.join(default_options)
log.notice(msg)
@@ -1024,21 +1024,21 @@ class Torrc():
if mismatch_lines:
if len(mismatch_lines) > 1:
- msg += "\n- torrc values differ on lines: "
+ msg += '\n- torrc values differ on lines: '
else:
- msg += "\n- torrc value differs on line: "
+ msg += '\n- torrc value differs on line: '
mismatch_lines.sort()
- msg += ", ".join([str(val + 1) for val in mismatch_lines])
+ msg += ', '.join([str(val + 1) for val in mismatch_lines])
if missing_options:
if len(missing_options) > 1:
- msg += "\n- configuration values are missing from the torrc: "
+ msg += '\n- configuration values are missing from the torrc: '
else:
- msg += "\n- configuration value is missing from the torrc: "
+ msg += '\n- configuration value is missing from the torrc: '
missing_options.sort()
- msg += ", ".join(missing_options)
+ msg += ', '.join(missing_options)
log.warn(msg)
@@ -1053,7 +1053,7 @@ def load_configuration_descriptions(path_prefix):
# otherwise the man call pegs the cpu for around a minute (I'm not sure
# why... curses must mess the terminal in a way that's important to man).
- if CONFIG["features.config.descriptions.enabled"]:
+ if CONFIG['features.config.descriptions.enabled']:
is_config_descriptions_loaded = False
# determines the path where cached descriptions should be persisted (left
@@ -1061,13 +1061,13 @@ def load_configuration_descriptions(path_prefix):
descriptor_path = None
- if CONFIG["features.config.descriptions.persist"]:
- data_dir = CONFIG["startup.data_directory"]
+ if CONFIG['features.config.descriptions.persist']:
+ data_dir = CONFIG['startup.data_directory']
- if not data_dir.endswith("/"):
- data_dir += "/"
+ if not data_dir.endswith('/'):
+ data_dir += '/'
- descriptor_path = os.path.expanduser(data_dir + "cache/") + CONFIG_DESC_FILENAME
+ descriptor_path = os.path.expanduser(data_dir + 'cache/') + CONFIG_DESC_FILENAME
# attempts to load configuration descriptions cached in the data directory
@@ -1111,7 +1111,7 @@ def load_configuration_descriptions(path_prefix):
if not is_config_descriptions_loaded:
try:
load_start_time = time.time()
- loaded_version = load_option_descriptions("%sresources/%s" % (path_prefix, CONFIG_DESC_FILENAME), False)
+ loaded_version = load_option_descriptions('%sresources/%s' % (path_prefix, CONFIG_DESC_FILENAME), False)
is_config_descriptions_loaded = True
log.notice(DESC_INTERNAL_LOAD_SUCCESS_MSG % loaded_version)
except IOError as exc:
diff --git a/nyx/util/tracker.py b/nyx/util/tracker.py
index 79acfdd..1b51a05 100644
--- a/nyx/util/tracker.py
+++ b/nyx/util/tracker.py
@@ -156,7 +156,7 @@ def _resources_via_ps(pid):
# TIME ELAPSED RSS %MEM
# 0:04.40 37:57 18772 0.9
- ps_call = system.call("ps -p {pid} -o cputime,etime,rss,%mem".format(pid = pid))
+ ps_call = system.call('ps -p {pid} -o cputime,etime,rss,%mem'.format(pid = pid))
if ps_call and len(ps_call) >= 2:
stats = ps_call[1].strip().split()
@@ -172,7 +172,7 @@ def _resources_via_ps(pid):
except ValueError:
pass
- raise IOError("unrecognized output from ps: %s" % ps_call)
+ raise IOError('unrecognized output from ps: %s' % ps_call)
def _resources_via_proc(pid):
@@ -274,11 +274,11 @@ def _process_for_ports(local_ports, remote_ports):
elif remote_port in remote_ports:
results[remote_port] = cmd
except ValueError as exc:
- raise IOError("unrecognized output from lsof (%s): %s" % (exc, line))
+ raise IOError('unrecognized output from lsof (%s): %s' % (exc, line))
return results
- raise IOError("no results from lsof")
+ raise IOError('no results from lsof')
class Daemon(threading.Thread):
diff --git a/nyx/util/ui_tools.py b/nyx/util/ui_tools.py
index ba16967..1123080 100644
--- a/nyx/util/ui_tools.py
+++ b/nyx/util/ui_tools.py
@@ -385,14 +385,14 @@ def is_wide_characters_supported():
lib_dependency_lines = None
- if system.is_available("ldd"):
- lib_dependency_lines = system.call("ldd %s" % _curses.__file__)
- elif system.is_available("otool"):
- lib_dependency_lines = system.call("otool -L %s" % _curses.__file__)
+ if system.is_available('ldd'):
+ lib_dependency_lines = system.call('ldd %s' % _curses.__file__)
+ elif system.is_available('otool'):
+ lib_dependency_lines = system.call('otool -L %s' % _curses.__file__)
if lib_dependency_lines:
for line in lib_dependency_lines:
- if "libncursesw" in line:
+ if 'libncursesw' in line:
return True
except:
pass
diff --git a/run_nyx b/run_nyx
index b1b6403..c3ba49b 100755
--- a/run_nyx
+++ b/run_nyx
@@ -31,7 +31,7 @@ def _check_prereq():
major_version, minor_version = sys.version_info[0:2]
if major_version < 2 or (major_version == 2 and minor_version < 6):
- raise ImportError("nyx requires python version 2.6 or greater")
+ raise ImportError('nyx requires python version 2.6 or greater')
try:
import stem
@@ -41,9 +41,9 @@ def _check_prereq():
elif distutils.spawn.find_executable('apt-get') is not None:
advice = "try running 'sudo apt-get install python-stem'"
else:
- advice = "you can find it at https://stem.torproject.org/download.html"
+ advice = 'you can find it at https://stem.torproject.org/download.html'
- raise ImportError("nyx requires stem, %s" % advice)
+ raise ImportError('nyx requires stem, %s' % advice)
try:
import curses
@@ -53,7 +53,7 @@ def _check_prereq():
else:
advice = '' # not sure what to do for other platforms
- raise ImportError("nyx requires curses" + advice)
+ raise ImportError('nyx requires curses' + advice)
if __name__ == '__main__':
diff --git a/setup.py b/setup.py
index 73746bb..c484ea1 100644
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@ def getResources(dst, sourceDir):
results = []
- for root, _, files in os.walk(os.path.join("nyx", sourceDir)):
+ for root, _, files in os.walk(os.path.join('nyx', sourceDir)):
if files:
fileListing = tuple([os.path.join(root, file) for file in files])
results.append((os.path.join(dst, root[4:]), fileListing))
@@ -29,18 +29,18 @@ def getResources(dst, sourceDir):
isDebInstall = False
for arg in sys.argv:
- if "tor-nyx" in arg or "release_deb" in arg:
+ if 'tor-nyx' in arg or 'release_deb' in arg:
isDebInstall = True
break
-docPath = "/usr/share/doc/%s" % ("tor-nyx" if isDebInstall else "nyx")
+docPath = '/usr/share/doc/%s' % ('tor-nyx' if isDebInstall else 'nyx')
# Allow the docPath to be overridden via a '--docPath' argument. This is to
# support custom documentation locations on Gentoo, as discussed in:
# https://bugs.gentoo.org/349792
try:
- docPathFlagIndex = sys.argv.index("--docPath")
+ docPathFlagIndex = sys.argv.index('--docPath')
if docPathFlagIndex < len(sys.argv) - 1:
docPath = sys.argv[docPathFlagIndex + 1]
@@ -48,20 +48,20 @@ try:
# complain about them)
del sys.argv[docPathFlagIndex:docPathFlagIndex + 3]
else:
- print "No path provided for --docPath"
+ print 'No path provided for --docPath'
sys.exit(1)
except ValueError: pass # --docPath flag not found
-# Provides the configuration option to install to "/usr/share" rather than as a
+# Provides the configuration option to install to '/usr/share' rather than as a
# python module. Alternatives are to either provide this as an input argument
# (not an option for deb/rpm builds) or add a setup.cfg with:
# [install]
# install-purelib=/usr/share
# which would mean a bit more unnecessary clutter.
-manFilename = "nyx/resoureces/nyx.1"
-if "install" in sys.argv:
- sys.argv += ["--install-purelib", "/usr/share"]
+manFilename = 'nyx/resoureces/nyx.1'
+if 'install' in sys.argv:
+ sys.argv += ['--install-purelib', '/usr/share']
# Compresses the man page. This is a temporary file that we'll install. If
# something goes wrong then we'll print the issue and use the uncompressed man
@@ -74,7 +74,7 @@ if "install" in sys.argv:
# temporary destination for the man page guarenteed to be unoccupied (to
# avoid conflicting with files that are already there)
- tmpFilename = tempfile.mktemp("/nyx.1.gz")
+ tmpFilename = tempfile.mktemp('/nyx.1.gz')
# make dir if the path doesn't already exist
baseDir = os.path.dirname(tmpFilename)
@@ -88,7 +88,7 @@ if "install" in sys.argv:
# in the deb and rpm builds
manFilename = tmpFilename
except IOError, exc:
- print "Unable to compress man page: %s" % exc
+ print 'Unable to compress man page: %s' % exc
installPackages = ['nyx', 'nyx.cli', 'nyx.cli.graphing', 'nyx.cli.connections', 'nyx.cli.menu', 'nyx.util', 'nyx.stem']
@@ -101,17 +101,17 @@ setup(name='nyx',
url='http://www.atagar.com/nyx/',
packages=installPackages,
package_dir={'nyx': 'nyx'},
- data_files=[("/usr/bin", ["run_nyx"]),
- ("/usr/share/man/man1", [manFilename]),
- (docPath, ["nyxrc.sample"]),
- ("/usr/share/nyx/gui", ["nyx/gui/nyx.xml"]),
- ("/usr/share/nyx", ["nyx/settings.cfg", "nyx/uninstall"])] +
- getResources("/usr/share/nyx", "resources"),
+ data_files=[('/usr/bin', ['run_nyx']),
+ ('/usr/share/man/man1', [manFilename]),
+ (docPath, ['nyxrc.sample']),
+ ('/usr/share/nyx/gui', ['nyx/gui/nyx.xml']),
+ ('/usr/share/nyx', ['nyx/settings.cfg', 'nyx/uninstall'])] +
+ getResources('/usr/share/nyx', 'resources'),
)
# Cleans up the temporary compressed man page.
if manFilename != 'nyx/resoureces/nyx.1' and os.path.isfile(manFilename):
- if "-q" not in sys.argv: print "Removing %s" % manFilename
+ if '-q' not in sys.argv: print 'Removing %s' % manFilename
os.remove(manFilename)
# Removes the egg_info file. Apparently it is not optional during setup
@@ -120,6 +120,6 @@ if manFilename != 'nyx/resoureces/nyx.1' and os.path.isfile(manFilename):
eggPath = '/usr/share/nyx-%s.egg-info' % VERSION
if not isDebInstall and os.path.isfile(eggPath):
- if "-q" not in sys.argv: print "Removing %s" % eggPath
+ if '-q' not in sys.argv: print 'Removing %s' % eggPath
os.remove(eggPath)
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits