[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [nyx/master] Merge _get_unit_type() into caller



commit b546ab920681e9403a65fb9af8110941b8cb5c74
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Feb 6 13:01:16 2016 -0800

    Merge _get_unit_type() into caller
    
    Helper isn't providing any better readability so merging it into its caller.
---
 nyx/util/tor_config.py | 37 +++++++++----------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

diff --git a/nyx/util/tor_config.py b/nyx/util/tor_config.py
index 8a382c9..22e7938 100644
--- a/nyx/util/tor_config.py
+++ b/nyx/util/tor_config.py
@@ -79,7 +79,7 @@ def get_multiline_parameters():
   return tuple(MULTILINE_PARAM)
 
 
-def validate(contents = None):
+def validate(contents):
   """
   Performs validation on the given torrc contents, providing back a listing of
   (line number, issue, msg) tuples for issues found. If the issue occures on a
@@ -91,7 +91,7 @@ def validate(contents = None):
 
   controller = tor_controller()
 
-  config_text = tor_controller().get_info('config-text', None)
+  config_text = controller.get_info('config-text', None)
   config_lines = config_text.splitlines() if config_text else []
   custom_options = list(set([line.split(' ')[0] for line in config_lines]))
 
@@ -228,37 +228,18 @@ def _parse_conf_value(conf_arg):
   if conf_arg.count(' ') == 1:
     val, unit = conf_arg.lower().split(' ', 1)
 
-    if not val.isdigit():
-      return conf_arg, ValueType.UNRECOGNIZED
+    if val.isdigit():
+      for label in SIZE_MULT:
+        if unit in CONFIG['torrc.units.size.' + label]:
+          return str(int(val) * SIZE_MULT[label]), ValueType.SIZE
 
-    mult, mult_type = _get_unit_type(unit)
-
-    if mult is not None:
-      return str(int(val) * mult), mult_type
+      for label in TIME_MULT:
+        if unit in CONFIG['torrc.units.time.' + label]:
+          return str(int(val) * TIME_MULT[label]), ValueType.TIME
 
   return conf_arg, ValueType.UNRECOGNIZED
 
 
-def _get_unit_type(unit):
-  """
-  Provides the type and multiplier for an argument's unit. The multiplier is
-  None if the unit isn't recognized.
-
-  Arguments:
-    unit - string representation of a unit
-  """
-
-  for label in SIZE_MULT:
-    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]:
-      return TIME_MULT[label], ValueType.TIME
-
-  return None, ValueType.UNRECOGNIZED
-
-
 def _strip_comments(contents):
   """
   Removes comments and extra whitespace from the given torrc contents.



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits