Revision dd225c7a ncclient/xml_.py
b/ncclient/xml_.py | ||
---|---|---|
30 | 30 |
### Namespace-related |
31 | 31 |
|
32 | 32 |
#: Base NETCONF namespace |
33 |
BASE_NS = 'urn:ietf:params:xml:ns:netconf:base:1.0' |
|
33 |
BASE_NS_1_0 = 'urn:ietf:params:xml:ns:netconf:base:1.0'
|
|
34 | 34 |
#: ... and this is BASE_NS according to Cisco devices tested |
35 |
CISCO_BS = 'urn:ietf:params:netconf:base:1.0' |
|
35 |
CISCO_BS_1_0 = 'urn:ietf:params:netconf:base:1.0'
|
|
36 | 36 |
#: namespace for Tail-f data model |
37 | 37 |
TAILF_AAA_1_1 = 'http://tail-f.com/ns/aaa/1.1' |
38 | 38 |
#: namespace for Tail-f data model |
39 | 39 |
TAILF_EXECD_1_1 = 'http://tail-f.com/ns/execd/1.1' |
40 | 40 |
#: namespace for Cisco data model |
41 |
CISCO_CPI_10 = 'http://www.cisco.com/cpi_10/schema' |
|
41 |
CISCO_CPI_1_0 = 'http://www.cisco.com/cpi_10/schema' |
|
42 |
#: namespace for Flowmon data model |
|
43 |
FLOWMON_1_0 = 'http://www.liberouter.org/ns/netopeer/flowmon/1.0' |
|
42 | 44 |
|
43 | 45 |
try: |
44 | 46 |
register_namespace = ET.register_namespace |
... | ... | |
48 | 50 |
# cElementTree uses ElementTree's _namespace_map, so that's ok |
49 | 51 |
ElementTree._namespace_map[uri] = prefix |
50 | 52 |
|
51 |
register_namespace('netconf', BASE_NS) |
|
52 |
register_namespace('aaa', TAILF_AAA_1_1) |
|
53 |
register_namespace('execd', TAILF_EXECD_1_1) |
|
54 |
register_namespace('cpi', CISCO_CPI_10) |
|
53 |
prefix_map = { |
|
54 |
BASE_NS_1_0: 'nc', |
|
55 |
TAILF_AAA_1_1: 'aaa', |
|
56 |
TAILF_EXECD_1_1: 'execd', |
|
57 |
CISCO_CPI_1_0: 'cpi', |
|
58 |
FLOWMON_1_0: 'fm', |
|
59 |
} |
|
55 | 60 |
|
61 |
for (ns, pre) in prefix_map.items(): |
|
62 |
register_namespace(pre, ns) |
|
56 | 63 |
|
57 |
qualify = lambda tag, ns=BASE_NS: tag if ns is None else '{%s}%s' % (ns, tag) |
|
64 |
qualify = lambda tag, ns=BASE_NS_1_0: tag if ns is None else '{%s}%s' % (ns, tag)
|
|
58 | 65 |
|
59 |
#: Deprecated |
|
60 |
multiqualify = lambda tag, nslist=(BASE_NS, CISCO_BS): [qualify(tag, ns) for ns in nslist] |
|
66 |
multiqualify = lambda tag, nslist=(BASE_NS_1_0, CISCO_BS_1_0): [qualify(tag, ns) for ns in nslist] |
|
61 | 67 |
|
62 | 68 |
unqualify = lambda tag: tag[tag.rfind('}')+1:] |
63 | 69 |
|
64 |
### XML with Python data structures
|
|
70 |
### XML representations
|
|
65 | 71 |
|
66 | 72 |
class DictTree: |
67 | 73 |
|
... | ... | |
169 | 175 |
|
170 | 176 |
iselement = ET.iselement |
171 | 177 |
|
178 |
|
|
179 |
NSLIST = [BASE_NS_1_0, CISCO_BS_1_0] |
|
180 |
|
|
172 | 181 |
def find(ele, tag, nslist=[]): |
173 | 182 |
"""If *nslist* is empty, same as :meth:`xml.etree.ElementTree.Element.find`. |
174 | 183 |
If it is not, *tag* is interpreted as an unqualified name and qualified |
Also available in: Unified diff