Revision a14c36f9 ncclient/transport/hello.py
b/ncclient/transport/hello.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
"All to do with NETCONF <hello> messages" |
16 | 16 |
|
17 |
from ncclient.glue import Listener |
|
18 |
from ncclient.content import XMLConverter, BASE_NS |
|
19 |
from ncclient.content import qualify as _ |
|
20 |
from ncclient.content import unqualify as __ |
|
17 |
from ncclient import content |
|
21 | 18 |
|
22 | 19 |
class HelloHandler(Listener): |
23 | 20 |
|
... | ... | |
29 | 26 |
return 'HelloListener' |
30 | 27 |
|
31 | 28 |
def callback(self, root, raw): |
32 |
if __(root[0]) == 'hello':
|
|
29 |
if content.unqualify(root[0]) == 'hello':
|
|
33 | 30 |
try: |
34 | 31 |
id, capabilities = HelloHandler.parse(raw) |
35 | 32 |
except Exception as e: |
... | ... | |
44 | 41 |
def build(capabilities): |
45 | 42 |
"Given a list of capability URI's returns encoded <hello> message" |
46 | 43 |
spec = { |
47 |
'tag': _('hello', BASE_NS),
|
|
44 |
'tag': content.qualify('hello'),
|
|
48 | 45 |
'children': [{ |
49 | 46 |
'tag': 'capabilities', |
50 | 47 |
'children': # this is fun :-) |
51 | 48 |
[{ 'tag': 'capability', 'text': uri} for uri in capabilities] |
52 | 49 |
}] |
53 | 50 |
} |
54 |
return XMLConverter(spec).to_string()
|
|
51 |
return content.to_xml(spec)
|
|
55 | 52 |
|
56 | 53 |
@staticmethod |
57 | 54 |
def parse(raw): |
58 | 55 |
"Returns tuple of ('session-id', ['capability_uri', ...])" |
59 | 56 |
sid, capabilities = 0, [] |
60 |
root = XMLConverter.from_string(raw)
|
|
57 |
root = content.from_xml(raw)
|
|
61 | 58 |
for child in root['children']: |
62 |
if __(child['tag']) == 'session-id': |
|
59 |
tag = content.unqualify(child['tag']) |
|
60 |
if tag == 'session-id': |
|
63 | 61 |
sid = child['text'] |
64 |
elif __(child['tag']) == 'capabilities':
|
|
62 |
elif tag == 'capabilities':
|
|
65 | 63 |
for cap in child['children']: |
66 |
if __(cap['text']) == 'capability':
|
|
64 |
if content.unqualify(cap['text']) == 'capability':
|
|
67 | 65 |
capabilities.append(cap['text']) |
68 | 66 |
return sid, capabilities |
Also available in: Unified diff