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

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



commit 122d0a6aa57f21fe2ef7d41c6fd14736074345c6
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
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):

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