[tor-commits] [stem/master] Moving msg() helper to base module

atagar at torproject.org atagar at torproject.org
Tue May 6 01:21:13 UTC 2014


commit 407f9537cb0de0ec3c1cf1423b74e16f42abe7f0
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu Apr 17 09:12:08 2014 -0700

    Moving msg() helper to base module
    
    We'll want our msg() function outside of the commands module so moving it to
    __init__.py.
---
 stem/interpretor/__init__.py |   49 +++++++++++++++++++++++++++++++++++++++---
 stem/interpretor/commands.py |   43 +-----------------------------------
 2 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/stem/interpretor/__init__.py b/stem/interpretor/__init__.py
index d1a5359..c8cd513 100644
--- a/stem/interpretor/__init__.py
+++ b/stem/interpretor/__init__.py
@@ -6,15 +6,16 @@ Interactive interpretor for interacting with Tor directly. This adds usability
 features such as tab completion, history, and IRC-style functions (like /help).
 """
 
-__all__ = ['arguments']
+__all__ = ['arguments', 'commands', 'msg']
 
+import os
 import sys
 
 import stem
 import stem.connection
-import stem.interpretor.arguments
-import stem.interpretor.commands
 import stem.prereq
+import stem.util.conf
+import stem.util.log
 
 from stem.util.term import Attr, Color, format
 
@@ -31,6 +32,9 @@ else:
 def main():
   import readline
 
+  import stem.interpretor.arguments
+  import stem.interpretor.commands
+
   try:
     args = stem.interpretor.arguments.parse(sys.argv[1:])
   except ValueError as exc:
@@ -68,3 +72,42 @@ def main():
       except (KeyboardInterrupt, EOFError, stem.SocketClosed) as exc:
         print  # move cursor to the following line
         break
+
+
+def uses_settings(func):
+  """
+  Loads our interpretor's internal settings. This should be treated as a fatal
+  failure if unsuccessful.
+
+  :raises: **IOError** if we're unable to read or parse our internal
+    configurations
+  """
+
+  config = stem.util.conf.get_config('stem_interpretor')
+
+  if not config.get('settings_loaded', False):
+    settings_path = os.path.join(os.path.dirname(__file__), 'settings.cfg')
+    config.load(settings_path)
+    config.set('settings_loaded', 'true')
+
+  return func
+
+
+ at uses_settings
+def msg(message, **attr):
+  """
+  Provides the given message.
+
+  :param str message: message handle
+  :param dict attr: attributes to format the message with
+
+  :returns: **str** that was requested
+  """
+
+  config = stem.util.conf.get_config('stem_interpretor')
+
+  try:
+    return config.get(message).format(**attr)
+  except:
+    stem.util.log.notice('BUG: We attempted to use an undefined string resource (%s)' % message)
+    return ''
diff --git a/stem/interpretor/commands.py b/stem/interpretor/commands.py
index 2d2d0a5..a4ab317 100644
--- a/stem/interpretor/commands.py
+++ b/stem/interpretor/commands.py
@@ -2,15 +2,13 @@
 Handles making requests and formatting the responses.
 """
 
-import os
 import re
 
 import stem
 import stem.util.connection
-import stem.util.conf
-import stem.util.log
 import stem.util.tor_tools
 
+from stem.interpretor import msg
 from stem.util.term import Attr, Color, format
 
 OUTPUT_FORMAT = (Color.BLUE, )
@@ -75,25 +73,6 @@ HELP_OPTIONS = {
 }
 
 
-def uses_settings(func):
-  """
-  Loads our interpretor's internal settings. This should be treated as a fatal
-  failure if unsuccessful.
-
-  :raises: **IOError** if we're unable to read or parse our internal
-    configurations
-  """
-
-  config = stem.util.conf.get_config('stem_interpretor')
-
-  if not config.get('settings_loaded', False):
-    settings_path = os.path.join(os.path.dirname(__file__), 'settings.cfg')
-    config.load(settings_path)
-    config.set('settings_loaded', 'true')
-
-  return func
-
-
 def _get_commands(controller):
   """
   Provides commands recognized by tor.
@@ -596,23 +575,3 @@ class ControlInterpretor(object):
             output = format(str(exc), *ERROR_FORMAT)
 
     return output
-
-
- at uses_settings
-def msg(message, **attr):
-  """
-  Provides the given message.
-
-  :param str message: message handle
-  :param dict attr: attributes to format the message with
-
-  :returns: **str** that was requested
-  """
-
-  config = stem.util.conf.get_config('stem_interpretor')
-
-  try:
-    return config.get(message).format(**attr)
-  except:
-    stem.util.log.notice('BUG: We attempted to use an undefined string resource (%s)' % message)
-    return ''





More information about the tor-commits mailing list