root / ncclient / content / hello.py @ 35ad9d81
History | View | Annotate | Download (1.3 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
# you may not use this file except in compliance with the License.
|
5 |
# You may obtain a copy of the License at
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
|
15 |
import logging |
16 |
from xml.etree import cElementTree as ElementTree |
17 |
|
18 |
logging.getLogger('ncclient.content.hello')
|
19 |
|
20 |
from . import NETCONF_NS
|
21 |
from .util import qualify as _ |
22 |
from ..capability import Capabilities |
23 |
|
24 |
def make(capabilities): |
25 |
return '<hello xmlns="%s">%s</hello>' % (NETCONF_NS, capabilities) |
26 |
|
27 |
def parse(raw): |
28 |
id, capabilities = 0, Capabilities() |
29 |
root = ElementTree.fromstring(raw) |
30 |
if root.tag == _('hello'): |
31 |
for child in hello.getchildren(): |
32 |
if child.tag == _('session-id'): |
33 |
id = int(child.text)
|
34 |
elif child.tag == _('capabilities'): |
35 |
for cap in child.getiterator(_('capability')): |
36 |
capabilities.add(cap.text) |
37 |
return id, capabilities |