simpler and hopefully less error-prone way to init Xrn
authorBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Mon, 18 Oct 2010 14:46:49 +0000 (16:46 +0200)
committerBarış Metin <Talip-Baris.Metin@sophia.inria.fr>
Mon, 18 Oct 2010 14:46:49 +0000 (16:46 +0200)
sfa/util/xrn.py

index 86a1f86..c00dcef 100644 (file)
@@ -56,23 +56,22 @@ class Xrn:
 
     # provide either urn, or (hrn + type)
     def __init__ (self, xrn=None, urn=None, hrn=None, type=None):
-        if xrn:
-            if xrn.startswith(Xrn.URN_PREFIX):
-                self.urn=xrn
-                self.urn_to_hrn()
+        if not xrn:
+            if urn:
+                xrn = urn
+            elif hrn:
+                xrn = hrn
             else:
-                self.hrn=xrn
-                self.type=type
-                self.hrn_to_urn()
-        elif urn: 
-            self.urn=urn
+                raise SfaAPIError,"Xrn.__init__"
+
+        if xrn.startswith(Xrn.URN_PREFIX):
+            self.urn=xrn
             self.urn_to_hrn()
-        elif hrn and type: 
-            self.hrn=hrn
+        else:
+            self.hrn=xrn
             self.type=type
             self.hrn_to_urn()
-        else:
-            raise SfaAPIError,"Xrn.__init__"
+
         if not type:
             sfa_logger().debug("type-less Xrn's are not safe")