[tor-commits] [stem/master] Adding a default arg to get_streams()

atagar at torproject.org atagar at torproject.org
Sat Jan 5 03:17:46 UTC 2013


commit 7b2f6be091f4bb340277a49565bf37ec3a97e3c2
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 4 09:34:39 2013 -0800

    Adding a default arg to get_streams()
    
    Adding a default argument to the new get_streams() method (see ffdd61e).
---
 stem/control.py |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index 39b00b9..c7d52b4 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1688,24 +1688,31 @@ class Controller(BaseController):
       else:
         raise stem.ProtocolError("CLOSECIRCUIT returned unexpected response code: %s" % response.code)
   
-  def get_streams(self):
+  def get_streams(self, default = UNDEFINED):
     """
     Provides the list of streams tor is currently handling.
     
+    :param object default: response if the query fails
+    
     :returns: list of :class:`stem.events.StreamEvent` objects
     
-    :raises: :class:`stem.ControllerError` if the call fails
+    :raises: :class:`stem.ControllerError` if the call fails and no default was
+      provided
     """
     
-    streams = []
-    response = self.get_info("stream-status")
-    
-    for stream in response.splitlines():
-      message = stem.socket.recv_message(StringIO.StringIO("650 STREAM " + stream + "\r\n"))
-      stem.response.convert("EVENT", message, arrived_at = 0)
-      streams.append(message)
-    
-    return streams
+    try:
+      streams = []
+      response = self.get_info("stream-status")
+      
+      for stream in response.splitlines():
+        message = stem.socket.recv_message(StringIO.StringIO("650 STREAM " + stream + "\r\n"))
+        stem.response.convert("EVENT", message, arrived_at = 0)
+        streams.append(message)
+      
+      return streams
+    except Exception, exc:
+      if default == UNDEFINED: raise exc
+      else: return default
   
   def attach_stream(self, stream_id, circuit_id, exiting_hop = None):
     """





More information about the tor-commits mailing list