Revision 65c6a607 ncclient/transport/hello.py
b/ncclient/transport/hello.py | ||
---|---|---|
42 | 42 |
"Given a list of capability URI's returns encoded <hello> message" |
43 | 43 |
spec = { |
44 | 44 |
'tag': content.qualify('hello'), |
45 |
'children': [{
|
|
45 |
'subtree': [{
|
|
46 | 46 |
'tag': 'capabilities', |
47 | 47 |
'children': # this is fun :-) |
48 |
[{ 'tag': 'capability', 'text': uri} for uri in capabilities]
|
|
48 |
[{'tag': 'capability', 'text': uri} for uri in capabilities] |
|
49 | 49 |
}] |
50 | 50 |
} |
51 | 51 |
return content.to_xml(spec) |
... | ... | |
54 | 54 |
def parse(raw): |
55 | 55 |
"Returns tuple of ('session-id', ['capability_uri', ...])" |
56 | 56 |
sid, capabilities = 0, [] |
57 |
root = content.from_xml(raw)
|
|
58 |
for child in root['children']:
|
|
57 |
root = content.xml2ele(raw)
|
|
58 |
for child in root.getchildren():
|
|
59 | 59 |
tag = content.unqualify(child['tag']) |
60 | 60 |
if tag == 'session-id': |
61 |
sid = child['text']
|
|
61 |
sid = child.text
|
|
62 | 62 |
elif tag == 'capabilities': |
63 |
for cap in child['children']:
|
|
64 |
if content.unqualify(cap['text']) == 'capability':
|
|
65 |
capabilities.append(cap['text'])
|
|
63 |
for cap in child.getchildren():
|
|
64 |
if content.unqualify(cap.tag) == 'capability':
|
|
65 |
capabilities.append(cap.text)
|
|
66 | 66 |
return sid, capabilities |
Also available in: Unified diff