[tor-commits] [stem/master] Tuples lack an index method in python 2.5

atagar at torproject.org atagar at torproject.org
Wed Jun 13 16:33:51 UTC 2012


commit 122d0a6aa57f21fe2ef7d41c6fd14736074345c6
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jun 13 09:33:20 2012 -0700

    Tuples lack an index method in python 2.5
    
    Yet another python 2.5 compatability hack.
---
 stem/util/enum.py |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/stem/util/enum.py b/stem/util/enum.py
index af9ac27..8b21100 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -134,7 +134,9 @@ class Enum:
     if not value in self._values:
       raise ValueError("No such enumeration exists: %s (options: %s)" % (value, ", ".join(self._values)))
     
-    next_index = (self._values.index(value) + 1) % len(self._values)
+    # TODO: python 2.5 lacks an index method on tuples, when we drop support
+    # we can drop this hack
+    next_index = (list(self._values).index(value) + 1) % len(self._values)
     return self._values[next_index]
   
   def previous(self, value):
@@ -151,7 +153,9 @@ class Enum:
     if not value in self._values:
       raise ValueError("No such enumeration exists: %s (options: %s)" % (value, ", ".join(self._values)))
     
-    prev_index = (self._values.index(value) - 1) % len(self._values)
+    # TODO: python 2.5 lacks an index method on tuples, when we drop support
+    # we can drop this hack
+    prev_index = (list(self._values).index(value) - 1) % len(self._values)
     return self._values[prev_index]
   
   def __getitem__(self, item):



More information about the tor-commits mailing list