X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxrn.py;h=985b571188dba07462a78de4cd5351fcb4e167d4;hb=97d09a321eff49c73c09f44a10d1ae0d7767d250;hp=90d8549fabcd8bc0523f2b7a01546bf9e018e640;hpb=d629510c4d6c31eea9713203419742778920e2e7;p=sfa.git diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index 90d8549f..985b5711 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -32,8 +32,8 @@ def urn_to_hrn(urn): xrn=Xrn(urn); return (xrn.hrn, xrn.type) def hrn_to_urn(hrn,type): return Xrn(hrn, type=type).urn def hrn_authfor_hrn(parenthrn, hrn): return Xrn.hrn_is_auth_for_hrn(parenthrn, hrn) -def urn_to_sliver_id(urn, slice_id, node_id, index=0): - return Xrn(urn).get_sliver_id(slice_id, node_id, index) +def urn_to_sliver_id(urn, slice_id, node_id, index=0, authority=None): + return Xrn(urn).get_sliver_id(slice_id, node_id, index, authority) class Xrn: @@ -82,7 +82,7 @@ class Xrn: # A better alternative than childHRN.startswith(parentHRN) # e.g. hrn_is_auth_for_hrn('a\.b', 'a\.b.c.d') -> True, # but hrn_is_auth_for_hrn('a', 'a\.b.c.d') -> False - # Also hrn_is_uauth_for_hrn('a\.b.c.d', 'a\.b.c.d') -> True + # Also hrn_is_auth_for_hrn('a\.b.c.d', 'a\.b.c.d') -> True @staticmethod def hrn_is_auth_for_hrn(parenthrn, hrn): if parenthrn == hrn: @@ -92,16 +92,21 @@ class Xrn: return True return False + ########## basic tools on URNs URN_PREFIX = "urn:publicid:IDN" + URN_PREFIX_lower = "urn:publicid:idn" + + @staticmethod + def is_urn (text): + return text.lower().startswith(Xrn.URN_PREFIX_lower) - ########## basic tools on URNs @staticmethod def urn_full (urn): - if urn.startswith(Xrn.URN_PREFIX): return urn + if Xrn.is_urn(urn): return urn else: return Xrn.URN_PREFIX+urn @staticmethod def urn_meaningful (urn): - if urn.startswith(Xrn.URN_PREFIX): return urn[len(Xrn.URN_PREFIX):] + if Xrn.is_urn(urn): return urn[len(Xrn.URN_PREFIX):] else: return urn @staticmethod def urn_split (urn): @@ -117,7 +122,7 @@ class Xrn: 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): + if Xrn.is_urn(xrn): self.hrn=None self.urn=xrn self.urn_to_hrn() @@ -126,10 +131,18 @@ class Xrn: self.hrn=xrn self.type=type self.hrn_to_urn() + self._normalize() # happens all the time .. # if not type: # debug_logger.debug("type-less Xrn's are not safe") + def __repr__ (self): + result=" 1: name = type_parts[1] + auth_parts = [part for part in [self.get_authority_urn(), leaf] if part] + authority_string = ":".join(auth_parts) else: self.authority = Xrn.hrn_auth_list(self.hrn) name = Xrn.hrn_leaf(self.hrn) - - authority_string = self.get_authority_urn() + authority_string = self.get_authority_urn() if self.type == None: urn = "+".join(['',authority_string,Xrn.unescape(name)])