Revision 0b7d3b31 ncclient/content.py
b/ncclient/content.py | ||
---|---|---|
74 | 74 |
ele.tail = spec.get('tail', '') |
75 | 75 |
subtree = spec.get('subtree', []) |
76 | 76 |
# might not be properly specified as list but may be dict |
77 |
if isinstance(subtree, dict):
|
|
77 |
if not isinstance(subtree, list):
|
|
78 | 78 |
subtree = [subtree] |
79 | 79 |
for subele in subtree: |
80 | 80 |
ele.append(DictTree.Element(subele)) |
... | ... | |
184 | 184 |
for event, element in ET.iterparse(fp, events=('start',)): |
185 | 185 |
return (element.tag, element.attrib) |
186 | 186 |
|
187 |
def validated_element(rep, tag=None, attrs=None, text=None): |
|
187 |
def validated_element(rep, tags=None, attrs=None, text=None):
|
|
188 | 188 |
"""Checks if the root element meets the supplied criteria. Returns a :class:`~xml.etree.ElementTree.Element` instance if so, otherwise raises :exc:`ContentError`. |
189 | 189 |
|
190 |
:arg tag: tag name or a list of allowable tag names |
|
190 |
:arg tags: tag name or a list of allowable tag names
|
|
191 | 191 |
:arg attrs: list of required attribute names, each item may be a list of allowable alternatives |
192 | 192 |
:arg text: textual content to match |
193 | 193 |
:type rep: :obj:`dict` or :obj:`string` or :class:`~xml.etree.ElementTree.Element` |
194 | 194 |
""" |
195 | 195 |
ele = dtree2ele(rep) |
196 | 196 |
err = False |
197 |
if tag: |
|
198 |
if isinstance(tag, basestring): tag = [tag] |
|
197 |
if tags: |
|
198 |
if isinstance(tags, basestring): |
|
199 |
tags = [tags] |
|
199 | 200 |
if ele.tag not in tags: |
200 | 201 |
err = True |
201 | 202 |
if attrs: |
Also available in: Unified diff