Port validation levels to enum34
authorRuben Pollan <meskio@sindominio.net>
Mon, 5 Jan 2015 14:54:24 +0000 (08:54 -0600)
committerRuben Pollan <meskio@sindominio.net>
Thu, 15 Jan 2015 19:10:57 +0000 (13:10 -0600)
pkg/requirements.pip
src/leap/keymanager/keys.py
src/leap/keymanager/tests/test_keymanager.py
src/leap/keymanager/validation.py

index 207483c..11c4229 100644 (file)
@@ -4,4 +4,4 @@ requests
 # if we bump the gnupg version, bump also the sanity check
 # in keymanager.__init__
 gnupg>=1.4.0
-enum
+enum34
index 4e98de6..562c0a9 100644 (file)
@@ -213,7 +213,7 @@ class EncryptionKey(object):
             KEY_EXPIRY_DATE_KEY: expiry_date,
             KEY_LAST_AUDITED_AT_KEY: last_audited_at,
             KEY_REFRESHED_AT_KEY: refreshed_at,
-            KEY_VALIDATION_KEY: str(self.validation),
+            KEY_VALIDATION_KEY: self.validation.name,
             KEY_ENCR_USED_KEY: self.encr_used,
             KEY_SIGN_USED_KEY: self.sign_used,
             KEY_TAGS_KEY: [KEYMANAGER_KEY_TAG],
index 86832ba..93bc42c 100644 (file)
@@ -79,7 +79,7 @@ class KeyManagerUtilTestCase(unittest.TestCase):
             'expiry_date': 0,
             'last_audited_at': 0,
             'refreshed_at': 1311239602,
-            'validation': str(ValidationLevel.Weak_Chain),
+            'validation': ValidationLevel.Weak_Chain.name,
             'encr_used': False,
             'sign_used': True,
         }
index c6fe478..c81d533 100644 (file)
@@ -24,17 +24,17 @@ See:
 
 
 from datetime import datetime
-from enum import Enum
+from enum import IntEnum
 
 
-ValidationLevel = Enum(
-    "Weak_Chain",
-    "Provider_Trust",
-    "Provider_Endorsement",
-    "Third_Party_Endorsement",
-    "Third_Party_Consensus",
-    "Historically_Auditing",
-    "Known_Key",
+ValidationLevel = IntEnum("ValidationLevel",
+    "Weak_Chain "
+    "Provider_Trust "
+    "Provider_Endorsement "
+    "Third_Party_Endorsement "
+    "Third_Party_Consensus "
+    "Historically_Auditing "
+    "Known_Key "
     "Fingerprint")
 
 
@@ -49,7 +49,7 @@ def toValidationLevel(value):
     :raises ValueError: if C{value} is not a validation level
     """
     for level in ValidationLevel:
-        if value == str(level):
+        if value == level.name:
             return level
     raise ValueError("Not valid validation level: %s" % (value,))