Revision 94803aaf ncclient/content.py

b/ncclient/content.py
20 20
### Namespace-related ###
21 21

  
22 22
BASE_NS = 'urn:ietf:params:xml:ns:netconf:base:1.0'
23
NOTIFICATION_NS = 'urn:ietf:params:xml:ns:netconf:notification:1.0'
24 23
# and this is BASE_NS according to cisco devices...
25 24
CISCO_BS = 'urn:ietf:params:netconf:base:1.0'
26 25

  
......
43 42

  
44 43
unqualify = lambda tag: tag[tag.rfind('}')+1:]
45 44

  
46

  
47 45
### Build XML using Python data structures ###
48 46

  
49
class TreeBuilder:
47
class XMLConverter:
50 48
    """Build an ElementTree.Element instance from an XML tree specification
51 49
    based on nested dictionaries. TODO: describe spec
52 50
    """
53 51
    
54 52
    def __init__(self, spec):
55 53
        "TODO: docstring"
56
        self._root = TreeBuilder.build(spec)
54
        self._root = XMLConverter.build(spec)
57 55
    
58 56
    def to_string(self, encoding='utf-8'):
59 57
        "TODO: docstring"
60 58
        xml = ET.tostring(self._root, encoding)
61
        # some etree versions don't always include xml decl
59
        # some etree versions don't always include xml decl e.g. with utf-8
62 60
        # this is a problem with some devices
63 61
        if not xml.startswith('<?xml'):
64
            return '<?xml version="1.0" encoding="%s"?>%s' % (encoding, xml)
62
            return ((u'<?xml version="1.0" encoding="%s"?>'
63
                     % encoding).encode(encoding) + xml)
65 64
        else:
66 65
            return xml
67 66
    
......
82 81
            for child in children:
83 82
                ele.append(TreeBuilder.build(child))
84 83
            return ele
84
        elif 'xml' in spec:
85
            return ET.XML(spec['xml'])
85 86
        elif 'comment' in spec:
86 87
            return ET.Comment(spec.get('comment'))
87 88
        else:
88 89
            raise ValueError('Invalid tree spec')
89

  
90
class Parser:
91
    pass
92

  
93
class PartialParser(Parser):
94
    
95
    pass
96

  
97
class RootParser(Parser):
98
    
99
    pass

Also available in: Unified diff