Revision c2a5b930 ncclient/content.py
b/ncclient/content.py | ||
---|---|---|
17 | 17 |
from xml.etree import cElementTree as ET |
18 | 18 |
|
19 | 19 |
iselement = ET.iselement |
20 |
element2string = ET.tostring |
|
20 | 21 |
|
21 | 22 |
### Namespace-related ### |
22 | 23 |
|
... | ... | |
43 | 44 |
|
44 | 45 |
unqualify = lambda tag: tag[tag.rfind('}')+1:] |
45 | 46 |
|
47 |
def namespaced_find(ele, tag, workaround=True): |
|
48 |
"""`workaround` is for Cisco implementations (at least the one tested), |
|
49 |
which uses an incorrect namespace. |
|
50 |
""" |
|
51 |
found = None |
|
52 |
if not workaround: |
|
53 |
found = ele.find(tag) |
|
54 |
else: |
|
55 |
for qname in multiqualify(tag): |
|
56 |
found = ele.find(qname) |
|
57 |
if found is not None: |
|
58 |
break |
|
59 |
return found |
|
60 |
|
|
61 |
|
|
46 | 62 |
### Build XML using Python data structures ### |
47 | 63 |
|
48 | 64 |
class XMLConverter: |
... | ... | |
70 | 86 |
@staticmethod |
71 | 87 |
def build(spec): |
72 | 88 |
"TODO: docstring" |
73 |
if ET.iselement(spec):
|
|
89 |
if iselement(spec): |
|
74 | 90 |
return spec |
75 | 91 |
elif isinstance(spec, basestring): |
76 | 92 |
return ET.XML(spec) |
Also available in: Unified diff