X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxrn.py;h=083e620f2158c4264197356db28de2f14c872a36;hb=7c07392f73ae780e78a434292507d5a64a8faa4d;hp=4709b4958a239863f712940311eabd877a7da4ab;hpb=f6f1bf872dd9700136c54d5b14fc3e3aa9b18b7d;p=sfa.git diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index 4709b495..083e620f 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -23,7 +23,7 @@ import re -from sfa.util.faults import * +from sfa.util.faults import SfaAPIError # for convenience and smoother translation - we should get rid of these functions eventually def get_leaf(hrn): return Xrn(hrn).get_leaf() @@ -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 ":".join([urn, 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: @@ -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 - else: return Xrn.URN_PREFIX+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() @@ -130,6 +135,13 @@ class Xrn: # if not type: # debug_logger.debug("type-less Xrn's are not safe") + def __repr__ (self): + result="