Revision 68ac4439 ncclient/capabilities.py

b/ncclient/capabilities.py
36 36

  
37 37
class Capabilities:
38 38

  
39
    """Represents the set of capabilities for a NETCONF client or server.
40
    Initialised with a list of capability URI's.
41

  
42
    Presence of a capability can be checked with the *in* operations. In addition
39
    """Represents the set of capabilities available to a NETCONF client or
40
    server.
41
    
42
    Presence of a capability can be checked with the *in* operation. In addition
43 43
    to the URI, for capabilities of the form
44 44
    *urn:ietf:params:netconf:capability:$name:$version* their shorthand can be
45 45
    used as a key. For example, for
46 46
    *urn:ietf:params:netconf:capability:candidate:1.0* the shorthand would be
47 47
    *:candidate*. If version is significant, use *:candidate:1.0* as key.
48 48
    """
49

  
49
    
50 50
    def __init__(self, capabilities):
51
        "Initializes with a list of capability URI's"
51 52
        self._dict = {}
52 53
        for uri in capabilities:
53 54
            self._dict[uri] = _abbreviate(uri)
......
80 81
        "Remove a capability"
81 82
        if key in self._dict:
82 83
            del self._dict[key]
83

  
84
    def check(self, key):
85
        """Whether specified capability is present.
86

  
87
        :arg key: URI or shorthand
88

  
89
        .. note:
90
            The *in* operation is the preferred form.
91
        """
92
        return key in self
93

  
84
    
94 85
    def get_uri(self, shorthand):
95 86
        for uri, abbrs in self._dict.items():
96 87
            if shorthand in abbrs:
97 88
                return uri
98

  
99
#: :class:`Capabilities` object representing the capabilities currently supported by NCClient
100
CAPABILITIES = Capabilities([
101
    "urn:ietf:params:netconf:base:1.0",
102
    "urn:ietf:params:netconf:capability:writable-running:1.0",
103
    "urn:ietf:params:netconf:capability:candidate:1.0",
104
    "urn:ietf:params:netconf:capability:confirmed-commit:1.0",
105
    "urn:ietf:params:netconf:capability:rollback-on-error:1.0",
106
    "urn:ietf:params:netconf:capability:startup:1.0",
107
    "urn:ietf:params:netconf:capability:url:1.0?scheme=http,ftp,file,https,sftp",
108
    "urn:ietf:params:netconf:capability:validate:1.0",
109
    "urn:ietf:params:netconf:capability:xpath:1.0",
110
    "urn:liberouter:params:netconf:capability:power-control:1.0"
111
    "urn:ietf:params:netconf:capability:interleave:1.0"
112
    #'urn:ietf:params:netconf:capability:notification:1.0', # TODO
113
    
114
])

Also available in: Unified diff