fix set_authority()
[sfa.git] / sfa / util / xrn.py
index 414a8a6..c623cbd 100644 (file)
@@ -126,11 +126,15 @@ class Xrn:
             if id:
                 self.urn = "%s-%s" % (self.urn, str(id))
             self.urn_to_hrn()
+            if type:
+                self.type=type
+                self.hrn_to_urn()
         else:
             self.urn=None
             self.hrn=xrn
             self.type=type
             self.hrn_to_urn()
+
         self._normalize()
 # happens all the time ..
 #        if not type:
@@ -173,7 +177,9 @@ class Xrn:
         update the authority section of an existing urn
         """
         authority_hrn = self.get_authority_hrn()
-        hrn = ".".join([authority, self.get_leaf()]) 
+        old_hrn_parts = Xrn.hrn_split(self.hrn)
+        old_hrn_parts[0] = authority
+        hrn = ".".join(old_hrn_list) 
         self.hrn = hrn 
         self.hrn_to_urn()
         self._normalize()
@@ -240,6 +246,9 @@ class Xrn:
         else:
             self.authority = Xrn.hrn_auth_list(self.hrn)
             name = Xrn.hrn_leaf(self.hrn)
+            # separate name from id
+            name_parts = name.split("-")
+            name = name_parts[0]
             authority_string = self.get_authority_urn()
 
         if self.type == None:
@@ -248,7 +257,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