[tor-commits] [nyx/master] Drop duplicate ListingType enum

atagar at torproject.org atagar at torproject.org
Tue Sep 22 17:08:41 UTC 2015


commit ca3038beeb313128910970f69e00cce0a3a31c0a
Author: Damian Johnson <atagar at torproject.org>
Date:   Mon Aug 31 08:31:19 2015 -0700

    Drop duplicate ListingType enum
    
    Weird, the panel had a Listing and entries had a ListingType. They're identical
    so could be used interchangeably, so just dropping the entry's copy.
---
 nyx/connections/circ_entry.py |    6 +++---
 nyx/connections/conn_entry.py |   18 +++++++++++-------
 nyx/connections/conn_panel.py |   10 +++++-----
 nyx/connections/entries.py    |    4 ----
 4 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/nyx/connections/circ_entry.py b/nyx/connections/circ_entry.py
index f396385..3cf0147 100644
--- a/nyx/connections/circ_entry.py
+++ b/nyx/connections/circ_entry.py
@@ -14,7 +14,7 @@ import datetime
 import nyx.util.tracker
 import nyx.util.ui_tools
 
-from nyx.connections import entries, conn_entry
+from nyx.connections import conn_entry, conn_panel, entries
 
 from stem.util import str_tools
 
@@ -139,7 +139,7 @@ class CircLine(conn_entry.ConnectionLine):
 
     dst, etc = '', ''
 
-    if listing_type == entries.ListingType.IP_ADDRESS:
+    if listing_type == conn_panel.Listing.IP_ADDRESS:
       # dst width is derived as:
       # src (21) + dst (26) + divider (7) + right gap (2) - bracket (3) = 53 char
 
@@ -150,7 +150,7 @@ class CircLine(conn_entry.ConnectionLine):
       dst = '%s%-25s   ' % (dst[:25], str_tools.crop(self.get_nickname('UNKNOWN'), 25, 0))
 
       etc = self.get_etc_content(width - baseline_space - len(dst), listing_type)
-    elif listing_type == entries.ListingType.FINGERPRINT:
+    elif listing_type == conn_panel.Listing.FINGERPRINT:
       # dst width is derived as:
       # src (9) + dst (40) + divider (7) + right gap (2) - bracket (3) = 55 char
 
diff --git a/nyx/connections/conn_entry.py b/nyx/connections/conn_entry.py
index 40a626f..b2fe648 100644
--- a/nyx/connections/conn_entry.py
+++ b/nyx/connections/conn_entry.py
@@ -102,17 +102,17 @@ class ConnectionLine(entries.ConnectionPanelLine):
     of the following components:
       <src>  -->  <dst>     <etc>     <uptime> (<type>)
 
-    ListingType.IP_ADDRESS:
+    Listing.IP_ADDRESS:
       src - <internal addr:port> --> <external addr:port>
       dst - <destination addr:port>
       etc - <fingerprint> <nickname>
 
-    ListingType.FINGERPRINT:
+    Listing.FINGERPRINT:
       src - localhost
       dst - <destination fingerprint>
       etc - <nickname> <destination addr:port>
 
-    ListingType.NICKNAME:
+    Listing.NICKNAME:
       src - <source nickname>
       dst - <destination nickname>
       etc - <fingerprint> <destination addr:port>
@@ -184,6 +184,8 @@ class ConnectionLine(entries.ConnectionPanelLine):
       listing_type - primary attribute we're listing connections by
     """
 
+    from nyx.connections import conn_panel
+
     # for applications show the command/pid
 
     if self._entry.get_type() in (Category.SOCKS, Category.HIDDEN, Category.CONTROL):
@@ -207,7 +209,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
     destination_address = self.get_destination_label(26, include_locale = True)
     etc, used_space = '', 0
 
-    if listing_type == entries.ListingType.IP_ADDRESS:
+    if listing_type == conn_panel.Listing.IP_ADDRESS:
       if width > used_space + 42 and CONFIG['features.connection.showColumn.fingerprint']:
         # show fingerprint (column width: 42 characters)
 
@@ -221,7 +223,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
         nickname_label = str_tools.crop(self.get_nickname('UNKNOWN'), nickname_space, 0)
         etc += ('%%-%is  ' % nickname_space) % nickname_label
         used_space += nickname_space + 2
-    elif listing_type == entries.ListingType.FINGERPRINT:
+    elif listing_type == conn_panel.Listing.FINGERPRINT:
       if width > used_space + 17:
         # show nickname (column width: min 17 characters, consumes any remaining space)
 
@@ -266,6 +268,8 @@ class ConnectionLine(entries.ConnectionPanelLine):
       listing_type - primary attribute we're listing connections by
     """
 
+    from nyx.connections import conn_panel
+
     controller = tor_controller()
     my_type = self._entry.get_type()
     destination_address = self.get_destination_label(26, include_locale = True)
@@ -280,7 +284,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
 
     src, dst, etc = '', '', ''
 
-    if listing_type == entries.ListingType.IP_ADDRESS:
+    if listing_type == conn_panel.Listing.IP_ADDRESS:
       my_external_address = controller.get_info('address', self.connection.local_address)
       address_differ = my_external_address != self.connection.local_address
 
@@ -340,7 +344,7 @@ class ConnectionLine(entries.ConnectionPanelLine):
 
       etc = self.get_etc_content(width - used_space, listing_type)
       used_space += len(etc)
-    elif listing_type == entries.ListingType.FINGERPRINT:
+    elif listing_type == conn_panel.Listing.FINGERPRINT:
       src = 'localhost'
 
       if my_type == Category.CONTROL:
diff --git a/nyx/connections/conn_panel.py b/nyx/connections/conn_panel.py
index f28c943..57c2efb 100644
--- a/nyx/connections/conn_panel.py
+++ b/nyx/connections/conn_panel.py
@@ -160,11 +160,11 @@ class ConnectionPanel(panel.Panel, threading.Thread):
 
       def sort_value(entry, attr):
         if attr == entries.SortAttr.LISTING:
-          if self.get_listing_type() == entries.ListingType.IP_ADDRESS:
+          if self.get_listing_type() == Listing.IP_ADDRESS:
             attr = entries.SortAttr.IP_ADDRESS
-          elif self.get_listing_type() == entries.ListingType.FINGERPRINT:
+          elif self.get_listing_type() == Listing.FINGERPRINT:
             attr = entries.SortAttr.FINGERPRINT
-          elif self.get_listing_type() == entries.ListingType.NICKNAME:
+          elif self.get_listing_type() == Listing.NICKNAME:
             attr = entries.SortAttr.NICKNAME
 
         connection_line = entry.get_lines()[0]
@@ -284,7 +284,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
         # provides a menu to pick the primary information we list connections by
 
         title = 'List By:'
-        options = list(entries.ListingType)
+        options = list(Listing)
 
         old_selection = options.index(self.get_listing_type())
         selection = nyx.popups.show_menu(title, options, old_selection)
@@ -303,7 +303,7 @@ class ConnectionPanel(panel.Panel, threading.Thread):
           if not selection:
             break
 
-          color = nyx.connections.conn_entry.CATEGORY_COLOR[selection.get_type()]
+          color = conn_entry.CATEGORY_COLOR[selection.get_type()]
           fingerprint = selection.get_fingerprint()
           is_close_key = lambda key: key.is_selection() or key.match('d') or key.match('left') or key.match('right')
           key = descriptor_popup.show_descriptor_popup(fingerprint, color, self.max_x, is_close_key)
diff --git a/nyx/connections/entries.py b/nyx/connections/entries.py
index 20d19a8..91994bc 100644
--- a/nyx/connections/entries.py
+++ b/nyx/connections/entries.py
@@ -17,10 +17,6 @@ try:
 except ImportError:
   from stem.util.lru_cache import lru_cache
 
-# attributes we can list entries by
-
-ListingType = enum.Enum(('IP_ADDRESS', 'IP Address'), 'FINGERPRINT', 'NICKNAME')
-
 SortAttr = enum.Enum('CATEGORY', 'UPTIME', 'LISTING', 'IP_ADDRESS', 'PORT', 'FINGERPRINT', 'NICKNAME', 'COUNTRY')
 
 SORT_COLORS = {





More information about the tor-commits mailing list