1 # Copyright 2009 Shikhar Bhushan
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 # "urn:liberouter:params:netconf:capability:power-control:1.0":
17 # [":power-control", ":power-control:1.0"]
21 if uri.startswith("urn:ietf:params:netconf:"):
22 splitted = uri.split(":")
23 if ":capability:" in uri:
24 return [ ":" + splitted[5], ":" + splitted[5] + ":" + splitted[6] ]
26 return [ ":base", ":base" + ":" + splitted[5] ]
27 #elif uri in _capability_map:
28 # return _capability_map[uri]
32 """Given a URI that has a *scheme* query string (i.e. *:url* capability
33 URI), will return a list of supported schemes.
35 return url_uri.partition("?scheme=")[2].split(",")
39 """Represents the set of capabilities available to a NETCONF client or
42 Presence of a capability can be checked with the *in* operation. In addition
43 to the URI, for capabilities of the form
44 *urn:ietf:params:netconf:capability:$name:$version* their shorthand can be
45 used as a key. For example, for
46 *urn:ietf:params:netconf:capability:candidate:1.0* the shorthand would be
47 *:candidate*. If version is significant, use *:candidate:1.0* as key.
50 def __init__(self, capabilities):
51 "Initializes with a list of capability URI's"
53 for uri in capabilities:
54 self._dict[uri] = _abbreviate(uri)
56 def __contains__(self, key):
59 for abbrs in self._dict.values():
65 return len(self._dict)
68 return self._dict.keys().__iter__()
71 return repr(self._dict.keys())
74 return self._dict.keys()
78 self._dict[uri] = _abbreviate(uri)
80 def remove(self, uri):
85 def get_uri(self, shorthand):
86 for uri, abbrs in self._dict.items():
87 if shorthand in abbrs: