[tor-commits] [stem/master] Minor revisions to close_stream()

atagar at torproject.org atagar at torproject.org
Mon Dec 10 15:49:01 UTC 2012


commit 29a6d14fa054c05e4c3c6bb97b0a91fd2fe3569a
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Dec 9 14:41:53 2012 -0800

    Minor revisions to close_stream()
    
    * Dropping the NONE RelayEndReason. It feels a little hacky to include it just
      so the index_of() will align with the integer values. Instead having
      close_stream() account for the offset.
    
    * The reason parameter of close_stream() is a stem.RelayEndReason rather than
      int so fixing its pydocs.
    
    * When doing formatted strings it's not necessary to wrap values in str(). If
      it's being assigned to a '%s' then that happens as part of the insertion.
---
 stem/__init__.py |    1 -
 stem/control.py  |    7 +++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/stem/__init__.py b/stem/__init__.py
index 5d6d8fb..3e23d26 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -496,7 +496,6 @@ CircPurpose = stem.util.enum.UppercaseEnum(
 )
 
 CircClosureReason = stem.util.enum.UppercaseEnum(
-  "NONE",
   "TORPROTOCOL",
   "INTERNAL",
   "REQUESTED",
diff --git a/stem/control.py b/stem/control.py
index cdcbe29..4b41e1c 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1483,14 +1483,17 @@ class Controller(BaseController):
     Closes the specified stream.
     
     :param int stream_id: id of the stream to be closed
-    :param int reason: reason the stream is closing (see RelayEndReason)
+    :param stem.RelayEndReason reason: reason the stream is closing
     :param str flag: not currently used
     
     :raises: :class:`stem.InvalidArguments` if the stream or reason are not recognized
     :raises: :class:`stem.InvalidRequest` if the stream and/or reason are missing
     """
     
-    response = self.msg("CLOSESTREAM %s %s %s"% (str(stream_id), str(stem.RelayEndReason.index_of(reason)), flag))
+    # there's a single value offset between RelayEndReason.index_of() and the
+    # value that tor expects since tor's value starts with the index of one
+    
+    response = self.msg("CLOSESTREAM %s %s %s"% (stream_id, stem.RelayEndReason.index_of(reason) + 1, flag))
     stem.response.convert("SINGLELINE", response)
     
     if not response.is_ok():





More information about the tor-commits mailing list