Revision 179b00d4 ncclient/transport/hello.py
b/ncclient/transport/hello.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
"All to do with NETCONF <hello> messages" |
16 | 16 |
|
17 |
from xml.etree import cElementTree as ET |
|
18 |
|
|
19 | 17 |
from ncclient.glue import Listener |
20 | 18 |
from ncclient.content import XMLConverter, BASE_NS |
21 | 19 |
from ncclient.content import qualify as _ |
... | ... | |
59 | 57 |
def parse(raw): |
60 | 58 |
"Returns tuple of ('session-id', ['capability_uri', ...])" |
61 | 59 |
sid, capabilities = 0, [] |
62 |
root = ET.fromstring(raw) |
|
63 |
for child in root.getchildren(): |
|
64 |
if __(child.tag) == 'session-id': |
|
65 |
sid = child.text |
|
66 |
elif __(child.tag) == 'capabilities': |
|
67 |
for cap in child.getiterator(_('capability', BASE_NS)): |
|
68 |
capabilities.append(cap.text) |
|
69 |
# cisco doesn't namespace hello message |
|
70 |
for cap in child.getiterator('capability'): |
|
71 |
capabilities.append(cap.text) |
|
60 |
root = XMLConverter.from_string(raw) |
|
61 |
for child in root['children']: |
|
62 |
if __(child['tag']) == 'session-id': |
|
63 |
sid = child['text'] |
|
64 |
elif __(child['tag']) == 'capabilities': |
|
65 |
for cap in child['children']: |
|
66 |
if __(cap['text']) == 'capability': |
|
67 |
capabilities.append(cap['text']) |
|
72 | 68 |
return sid, capabilities |
Also available in: Unified diff