#----------------------------------------------------------------------
import re
-
+import sys
from sfa.util.faults import SfaAPIError
# for convenience and smoother translation - we should get rid of these functions eventually
# provide either urn, or (hrn + type)
def __init__ (self, xrn, type=None):
if not xrn: xrn = ""
+
# user has specified xrn : guess if urn or hrn
if xrn.startswith(Xrn.URN_PREFIX):
self.hrn=None
self.urn=xrn
self.urn_to_hrn()
+ #print>>sys.stderr, " \r\n \r\n \t XRN.PY init xrn.startswith(Xrn.URN_PREFIX) hrn %s urn %s type %s" %( self.hrn, self.urn, self.type)
else:
self.urn=None
self.hrn=xrn
self.type=type
self.hrn_to_urn()
+ #print>>sys.stderr, " \r\n \r\n \t XRN.PY init ELSE hrn %s urn %s type %s" %( self.hrn, self.urn, self.type)
# happens all the time ..
# if not type:
# debug_logger.debug("type-less Xrn's are not safe")
def get_hrn_type(self): return (self.hrn, self.type)
def _normalize(self):
+ #print>>sys.stderr, " \r\n \r\n \t XRN.PY _normalize self.hrn %s ",self.hrn
if self.hrn is None: raise SfaAPIError, "Xrn._normalize"
if not hasattr(self,'leaf'):
self.leaf=Xrn.hrn_split(self.hrn)[-1]
# self.authority keeps a list
if not hasattr(self,'authority'):
self.authority=Xrn.hrn_auth_list(self.hrn)
-
+ #print>>sys.stderr, " \r\n \r\n \t XRN.PY _normalize self.hrn %s leaf %s authority %s"%(self.hrn, self.leaf, self.authority)
+
+
def get_leaf(self):
self._normalize()
return self.leaf
self._normalize()
urn = self.get_urn()
if authority:
- tmp_hrn = ".".join([authority,self.get_authority_hrn(), self.get_leaf()])
- urn = Xrn(tmp_hrn, self.get_type()).get_urn()
+ authority_hrn = self.get_authority_hrn()
+ if not authority_hrn.startswith(authority):
+ hrn = ".".join([authority,self.get_authority_hrn(), self.get_leaf()])
+ else:
+ hrn = ".".join([self.get_authority_hrn(), self.get_leaf()])
+ urn = Xrn(hrn, self.get_type()).get_urn()
return ":".join(map(str, [urn, slice_id, node_id, index]))
def urn_to_hrn(self):