Revision 17135383

/dev/null
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
NETCONF_NS = 'urn:ietf:params:xml:ns:netconf:base:1.0'
16

  
/dev/null
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
from ..error import ClientError, NETCONFError
16

  
17
class ContentError(ClientError):
18
    pass
/dev/null
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
/dev/null
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
from xml.etree import cElementTree as ElementTree
16

  
17
from . import NETCONF_NS
18
from .util import qualify as _
19

  
20
def make(id, op):
21
    return '<rpc message-id="%s" xmlns="%s">%s</rpc>' % (id, NETCONF_NS, op)
22

  
23
#def parse(raw):
24
#    
25
#    class RootElementParser:
26
#        
27
#        def __init__(self):
28
#            self.id = 0
29
#            self.is_notification = False
30
#            
31
#        def start(self, tag, attrib):
32
#            if tag == _('rpc'):
33
#                self.id = int(attrib['message-id'])
34
#            elif tag == _('notification'):
35
#                self.is_notification = True
36
#    
37
#    target = RootElementParser()
38
#    parser = ElementTree.XMLTreeBuilder(target=target)
39
#    parser.feed(raw)
40
#    return target.id, target.is_notification
41
#
/dev/null
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
from . import NETCONF_NS
16

  
17
def qualify(tag, ns=NETCONF_NS):
18
    return '{%s}%s' % (ns, tag)

Also available in: Unified diff