2to3 -f has_key
[sfa.git] / sfa / trust / credential_factory.py
index 47ddc66..cf5a8fb 100644 (file)
@@ -21,6 +21,8 @@
 # IN THE WORK.
 #----------------------------------------------------------------------
 
+from __future__ import print_function
+
 from sfa.util.sfalogging import logger
 from sfa.trust.credential import Credential
 from sfa.trust.abac_credential import ABACCredential
@@ -60,17 +62,17 @@ class CredentialFactory:
         if credFile:
             try:
                 credString = open(credFile).read()
-            except Exception, e:
+            except Exception as e:
                 logger.info("Error opening credential file %s: %s" % credFile, e)
                 return None
 
         # Try to treat the file as JSON, getting the cred_type from the struct
         try:
             credO = json.loads(credString, encoding='ascii')
-            if credO.has_key('geni_value') and credO.has_key('geni_type'):
+            if 'geni_value' in credO and 'geni_type' in credO:
                 cred_type = credO['geni_type']
                 credString = credO['geni_value']
-        except Exception, e:
+        except Exception as e:
             # It wasn't a struct. So the credString is XML. Pull the type directly from the string
             logger.debug("Credential string not JSON: %s" % e)
             cred_type = CredentialFactory.getType(credString)
@@ -79,7 +81,7 @@ class CredentialFactory:
             try:
                 cred = Credential(string=credString)
                 return cred
-            except Exception, e:
+            except Exception as e:
                 if credFile:
                     msg = "credString started: %s" % credString[:50]
                     raise Exception("%s not a parsable SFA credential: %s. " % (credFile, e) + msg)
@@ -90,7 +92,7 @@ class CredentialFactory:
             try:
                 cred = ABACCredential(string=credString)
                 return cred
-            except Exception, e:
+            except Exception as e:
                 if credFile:
                     raise Exception("%s not a parsable ABAC credential: %s" % (credFile, e))
                 else:
@@ -103,8 +105,8 @@ if __name__ == "__main__":
     cred1 = CredentialFactory.createCred(credFile='/tmp/cred.xml')
     cred2 = CredentialFactory.createCred(credString=c2)
 
-    print "C1 = %s" % cred1
-    print "C2 = %s" % cred2
+    print("C1 = %s" % cred1)
+    print("C2 = %s" % cred2)
     c1s = cred1.dump_string()
-    print "C1 = %s" % c1s
+    print("C1 = %s" % c1s)
 #    print "C2 = %s" % cred2.dump_string()