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

[tor-commits] [stem/master] Revising enum docs and methods



commit db7635abc7878d873a989c35e7aea413ecde2f52
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sun Nov 13 14:38:56 2011 -0800

    Revising enum docs and methods
    
    Minor changes including...
    - standard header documentation
    - replacing the keys() method with making enums iterable (functionally the
      same, but a little nicer for callers)
    - dropping the alternative LEnum - I've never used it
---
 stem/util/enum.py |   39 +++++++++++++++------------------------
 1 files changed, 15 insertions(+), 24 deletions(-)

diff --git a/stem/util/enum.py b/stem/util/enum.py
index d7745ec..6ce54d0 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -5,7 +5,7 @@ constructed as simple type listings, ie:
 >>> insects.ANT
 'Ant'
 >>> insects.values()
-['Ant', 'Wasp', 'Ladybug', 'Firefly']
+('Ant', 'Wasp', 'Ladybug', 'Firefly')
 
 with overwritten string counterparts:
 >>> pets = Enum(("DOG", "Skippy"), "CAT", ("FISH", "Nemo"))
@@ -14,10 +14,13 @@ with overwritten string counterparts:
 >>> pets.CAT
 'Cat'
 
-or with entirely custom string components as an unordered enum with:
->>> pets = LEnum(DOG="Skippy", CAT="Kitty", FISH="Nemo")
->>> pets.CAT
-'Kitty'
+to_camel_case - converts a string to camel case
+Enum - Provides a basic, ordered  enumeration.
+  |- values - string representation of our enums
+  |- index_of - indice of an enum value
+  |- next - provides the enum after a given enum value
+  |- previous - provides the enum before a given value
+  +- __iter__ - iterator over our enum keys
 """
 
 def to_camel_case(label, word_divider = " "):
@@ -62,16 +65,6 @@ class Enum:
     self._keys = tuple(keys)
     self._values = tuple(values)
   
-  def keys(self):
-    """
-    Provides an ordered listing of the enumeration keys in this set.
-    
-    Returns:
-      tuple with our enum keys
-    """
-    
-    return self._keys
-  
   def values(self):
     """
     Provides an ordered listing of the enumerations in this set.
@@ -137,14 +130,12 @@ class Enum:
     
     prev_index = (self._values.index(value) - 1) % len(self._values)
     return self._values[prev_index]
-
-class LEnum(Enum):
-  """
-  Enumeration that accepts custom string mappings.
-  """
   
-  def __init__(self, **args):
-    Enum.__init__(self)
-    self.__dict__.update(args)
-    self._values = sorted(args.values())
+  def __iter__(self):
+    """
+    Provides an ordered listing of the enumeration keys in this set.
+    """
+    
+    for entry in self._keys:
+      yield entry
 



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