Revision 0cdb8b3c ncclient/content.py

b/ncclient/content.py
23 23
### Namespace-related
24 24

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

  
......
39 40

  
40 41
qualify = lambda tag, ns=BASE_NS: tag if ns is None else '{%s}%s' % (ns, tag)
41 42

  
43
# deprecated
42 44
multiqualify = lambda tag, nslist=(BASE_NS, CISCO_BS): [qualify(tag, ns) for ns in nslist]
43 45

  
44 46
unqualify = lambda tag: tag[tag.rfind('}')+1:]
......
72 74
            raise ContentError('Invalid tree spec')
73 75
    
74 76
    @staticmethod
75
    def XML(spec, encoding='utf-8'):
77
    def XML(spec, encoding='UTF-8'):
76 78
        return Element.XML(DictTree.Element(spec), encoding)
77 79

  
78 80
class Element:
......
88 90
        }
89 91
    
90 92
    @staticmethod
91
    def XML(ele, encoding='utf-8'):
93
    def XML(ele, encoding='UTF-8'):
92 94
        xml = ET.tostring(ele, encoding)
93 95
        if xml.startswith('<?xml'):
94 96
            return xml
......
116 118

  
117 119
iselement = ET.iselement
118 120

  
119
def find(ele, tag, strict=False):
120
    """In strict mode, doesn't workaround Cisco implementations sending incorrectly
121
    namespaced XML. Supply qualified tag name if using strict mode.
121
def find(ele, tag, strict=True, nslist=[BASE_NS, CISCO_BS]):
122
    """In strict mode, doesn't work around Cisco implementations sending incorrectly namespaced XML. Supply qualified tag name if using strict mode.
122 123
    """
123 124
    if strict:
124 125
        return ele.find(tag)
......
126 127
        for qname in multiqualify(tag):
127 128
            found = ele.find(qname)
128 129
            if found is not None:
129
                return found
130
                return found        
130 131

  
131 132
def parse_root(raw):
132
    '''Parse the top-level element from XML string.
133
    
134
    Returns a `(tag, attributes)` tuple, where `tag` is a string representing
135
    the qualified name of the root element and `attributes` is an
136
    `{attribute: value}` dictionary.
137
    '''
133
    """
134
    """
138 135
    fp = StringIO(raw[:1024]) # this is a guess but start element beyond 1024 bytes would be a bit absurd
139 136
    for event, element in ET.iterparse(fp, events=('start',)):
140 137
        return (element.tag, element.attrib)
141 138

  
142 139
def validated_element(rep, tag, attrs=None):
140
    """
141
    """
143 142
    ele = dtree2ele(rep)
144 143
    if ele.tag not in (tag, qualify(tag)):
145 144
        raise ContentError("Required root element [%s] not found" % tag)

Also available in: Unified diff