from sfa.util.rspec import RSpec
import sys
import pdb
-from sfa.util.namespace import hrn_to_pl_slicename, hrn_to_urn
--from sfa.util.xrn import urn_to_hrn, get_authority
++from sfa.util.xrn import urn_to_hrn, hrn_to_urn, get_authority
++from sfa.util.plxrn import hrn_to_pl_slicename
+from sfa.util.plxrn import hrn_to_pl_slicename
from sfa.util.rspec import *
from sfa.util.specdict import *
from sfa.util.faults import *
def urn_split (urn):
return Xrn.urn_meaningful(urn).split('+')
+ ####################
+ # the local fields that are kept consistent
+ # self.urn
+ # self.hrn
+ # self.type
+ # self.path
# provide either urn, or (hrn + type)
def __init__ (self, xrn=None, urn=None, hrn=None, type=None):
- if not xrn:
- if urn:
- xrn = urn
- elif hrn:
- xrn = hrn
++ # user has specified xrn : guess if urn or hrn
+ if xrn is not None:
+ if xrn.startswith(Xrn.URN_PREFIX):
+ self.urn=xrn
+ self.urn_to_hrn()
else:
- raise SfaAPIError,"Xrn.__init__"
-
- if xrn.startswith(Xrn.URN_PREFIX):
- self.urn=xrn
+ self.hrn=xrn
+ self.type=type
+ self.hrn_to_urn()
++ # user has specified urn, let's use it
+ elif urn is not None:
+ self.urn=urn
self.urn_to_hrn()
- else:
- self.hrn=xrn
++ # user has specified hrn and type
+ elif hrn is not None and type is not None:
+ self.hrn=hrn
self.type=type
self.hrn_to_urn()
-
- if not type:
- sfa_logger().debug("type-less Xrn's are not safe")
++ # what should we do ?
+ else:
+ raise SfaAPIError,"Xrn.__init__"
+# happens all the time ..
+# if not type:
+# sfa_logger().debug("type-less Xrn's are not safe")
def get_urn(self): return self.urn
- def get_hrn(self): return (self.hrn, self.type)
+ def get_hrn(self): return self.hrn
+ def get_type(self): return self.type
+ def get_hrn_type(self): return (self.hrn, self.type)
- def get_leaf(self):
- if not self.hrn: raise SfaAPIError, "Xrn.get_leaf"
+ def _normalize(self):
+ 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)
+
+ def get_leaf(self):
+ self._normalize()
return self.leaf
def get_authority_hrn(self):