def hrn_to_urn(hrn,type): return Xrn(hrn, type=type).urn\r
def hrn_authfor_hrn(parenthrn, hrn): return Xrn.hrn_is_auth_for_hrn(parenthrn, hrn)\r
\r
-def urn_to_sliver_id(urn, slice_id, node_id, index=0, authority=None):\r
- return Xrn(urn).get_sliver_id(slice_id, node_id, index, authority)\r
-\r
class Xrn:\r
\r
########## basic tools on HRNs\r
# self.type\r
# self.path\r
# provide either urn, or (hrn + type)\r
- def __init__ (self, xrn, type=None):\r
+ def __init__ (self, xrn="", type=None, id=None):\r
if not xrn: xrn = ""\r
# user has specified xrn : guess if urn or hrn\r
+ self.id = id\r
if Xrn.is_urn(xrn):\r
self.hrn=None\r
self.urn=xrn\r
+ if id:\r
+ self.urn = "%s:%s" % (self.urn, str(id))\r
self.urn_to_hrn()\r
else:\r
self.urn=None\r
self._normalize()\r
return ':'.join( [Xrn.unescape(x) for x in self.authority] )\r
\r
- def get_sliver_id(self, slice_id, node_id, index=0, authority=None):\r
+ def set_authority(self, authority):\r
+ """\r
+ update the authority section of an existing urn\r
+ """\r
+ authority_hrn = self.get_authority_hrn()\r
+ if not authority_hrn.startswith(authority):\r
+ hrn = ".".join([authority,authority_hrn, self.get_leaf()])\r
+ else:\r
+ hrn = ".".join([authority_hrn, self.get_leaf()])\r
+ \r
+ self.hrn = hrn \r
+ self.hrn_to_urn()\r
self._normalize()\r
- urn = self.get_urn()\r
- if authority:\r
- authority_hrn = self.get_authority_hrn()\r
- if not authority_hrn.startswith(authority):\r
- hrn = ".".join([authority,authority_hrn, self.get_leaf()])\r
- else:\r
- hrn = ".".join([authority_hrn, self.get_leaf()])\r
- urn = Xrn(hrn, self.get_type()).get_urn()\r
- return ":".join(map(str, [urn, slice_id, node_id, index]))\r
-\r
+ \r
def urn_to_hrn(self):\r
"""\r
compute tuple (hrn, type) from urn\r
hrn = '.'.join([Xrn.escape(part).replace(':','.') for part in parts if part])\r
# dont replace ':' in the name section\r
if name:\r
+ parts = name.split(':')\r
+ if len(parts) > 1:\r
+ self.id = ":".join(parts[1:])\r
+ name = parts[0] \r
hrn += '.%s' % Xrn.escape(name) \r
\r
self.hrn=str(hrn)\r
urn = "+".join(['',authority_string,Xrn.unescape(name)])\r
else:\r
urn = "+".join(['',authority_string,self.type,Xrn.unescape(name)])\r
- \r
+\r
+ if hasattr(self, 'id') and self.id:\r
+ urn = "%s:%s" % (urn, self.id) \r
+\r
self.urn = Xrn.URN_PREFIX + urn\r
\r
def dump_string(self):\r