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

[tor-commits] [stem/master] system.call() support for a default



commit 76205611acb95231226bf42c4c6b20388ef3cfe7
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Jan 3 08:35:09 2013 -0800

    system.call() support for a default
    
    The 'suppress_exc' argument is a relic from long ago when I frequently made
    suppression the default in arm. Stem does things better, following "Errors
    should never pass silently. Unless explicitly silenced."
    
    A default argument lets us do the same thing as a 'suppress_exc' boolean, but
    with more control. It's also more uniform with our controller.
---
 stem/__init__.py    |    6 ++++++
 stem/control.py     |   11 ++---------
 stem/util/system.py |   13 ++++++-------
 3 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/stem/__init__.py b/stem/__init__.py
index 2482299..5fd34ab 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -397,6 +397,12 @@ __all__ = [
 
 import stem.util.enum
 
+# Constant to indicate an undefined argument default. Usually we'd use None for
+# this, but users will commonly provide None as the argument so need something
+# else fairly unique...
+
+UNDEFINED = "<Undefined_ >"
+
 class ControllerError(Exception):
   "Base error for controller communication issues."
 
diff --git a/stem/control.py b/stem/control.py
index b1525a9..d8ee940 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -138,12 +138,11 @@ import stem.response
 import stem.socket
 import stem.util.connection
 import stem.util.enum
+import stem.util.tor_tools
 import stem.version
 
-from stem import CircStatus
-
+from stem import UNDEFINED, CircStatus
 from stem.util import log
-import stem.util.tor_tools
 
 # state changes a control socket can have
 
@@ -177,12 +176,6 @@ EventType = stem.util.enum.UppercaseEnum(
   "CIRC_MINOR",
 )
 
-# Constant to indicate an undefined argument default. Usually we'd use None for
-# this, but users will commonly provide None as the argument so need something
-# else fairly unique...
-
-UNDEFINED = "<Undefined_ >"
-
 # Configuration options that are fetched by a special key. The keys are
 # lowercase to make case insensitive lookups easier.
 
diff --git a/stem/util/system.py b/stem/util/system.py
index 3c3abf4..0b4427e 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -28,6 +28,7 @@ import time
 
 import stem.util.proc
 
+from stem import UNDEFINED, CircStatus
 from stem.util import log
 
 # Mapping of commands to if they're available or not. This isn't always
@@ -552,20 +553,18 @@ def expand_path(path, cwd = None):
   
   return relative_path
 
-def call(command, suppress_exc = True):
+def call(command, default = UNDEFINED):
   """
   Issues a command in a subprocess, blocking until completion and returning the
   results. This is not actually ran in a shell so pipes and other shell syntax
   are not permitted.
   
   :param str command: command to be issued
-  :param bool suppress_exc: if **True** then **None** is returned on failure,
-    otherwise this raises the exception
+  :param object default: response if the query fails
   
-  :returns: **list** with the lines of output from the command, **None** in
-    case of failure if suppress_exc is **True**
+  :returns: **list** with the lines of output from the command
   
-  :raises: **OSError** if this fails and suppress_exc is **False**
+  :raises: **OSError** if this fails and no default was provided
   """
   
   try:
@@ -589,6 +588,6 @@ def call(command, suppress_exc = True):
   except OSError, exc:
     log.debug("System call (failed): %s (error: %s)" % (command, exc))
     
-    if suppress_exc: return None
+    if default != UNDEFINED: return default
     else: raise exc
 



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