X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Futil%2Fxrn.py;h=08a257daad5290c0412dd787e1c0a7c28b5b631a;hb=b6dcfc034473c011988fba0d02bbeb6406925465;hp=4709b4958a239863f712940311eabd877a7da4ab;hpb=f6f1bf872dd9700136c54d5b14fc3e3aa9b18b7d;p=sfa.git diff --git a/sfa/util/xrn.py b/sfa/util/xrn.py index 4709b495..08a257da 100644 --- a/sfa/util/xrn.py +++ b/sfa/util/xrn.py @@ -22,8 +22,8 @@ #---------------------------------------------------------------------- import re - -from sfa.util.faults import * +import sys +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): @@ -116,8 +121,9 @@ class Xrn: # 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): + if Xrn.is_urn(xrn): self.hrn=None self.urn=xrn self.urn_to_hrn() @@ -130,6 +136,13 @@ class Xrn: # 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)])