Merge branch 'master' into senslab2
[sfa.git] / sfa / util / xrn.py
index 9a5740c..764bd41 100644 (file)
@@ -120,14 +120,13 @@ class Xrn:
         if not xrn: xrn = ""
         # user has specified xrn : guess if urn or hrn
         self.id = id
+        self.type = type
+
         if Xrn.is_urn(xrn):
             self.hrn=None
             self.urn=xrn
-            if id:
-                self.urn = "%s-%s" % (self.urn, str(id))
             self.urn_to_hrn()
-            if type:
-                self.type=type
+            if id:
                 self.hrn_to_urn()
         else:
             self.urn=None
@@ -177,9 +176,9 @@ class Xrn:
         update the authority section of an existing urn
         """
         authority_hrn = self.get_authority_hrn()
-        hrn = ".".join([authority, self.get_leaf()]) 
-        self.hrn = hrn 
-        self.hrn_to_urn()
+        if not authority_hrn.startswith(authority+"."):
+            self.hrn = authority + "." + self.hrn
+            self.hrn_to_urn()
         self._normalize()
         
     def urn_to_hrn(self):
@@ -244,6 +243,7 @@ class Xrn:
         else:
             self.authority = Xrn.hrn_auth_list(self.hrn)
             name = Xrn.hrn_leaf(self.hrn)
+            # separate name from id
             authority_string = self.get_authority_urn()
 
         if self.type == None:
@@ -252,7 +252,7 @@ class Xrn:
             urn = "+".join(['',authority_string,self.type,Xrn.unescape(name)])
 
         if hasattr(self, 'id') and self.id:
-            urn = "%s:%s" % (urn, self.id)        
+            urn = "%s-%s" % (urn, self.id)        
 
         self.urn = Xrn.URN_PREFIX + urn