Revision 9667bcb2 ncclient/operations/util.py
b/ncclient/operations/util.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
'Boilerplate ugliness' |
16 | 16 |
|
17 |
from ncclient import xml_
|
|
17 |
from ncclient.xml_ import *
|
|
18 | 18 |
|
19 | 19 |
from errors import OperationError, MissingCapabilityError |
20 | 20 |
|
21 | 21 |
def one_of(*args): |
22 |
'Verifies that only one of the arguments is not None'
|
|
22 |
"Verifies that only one of the arguments is not None"
|
|
23 | 23 |
for i, arg in enumerate(args): |
24 | 24 |
if arg is not None: |
25 | 25 |
for argh in args[i+1:]: |
26 | 26 |
if argh is not None: |
27 |
raise OperationError('Too many parameters')
|
|
27 |
raise OperationError("Too many parameters")
|
|
28 | 28 |
else: |
29 | 29 |
return |
30 |
raise OperationError('Insufficient parameters')
|
|
30 |
raise OperationError("Insufficient parameters")
|
|
31 | 31 |
|
32 |
def store_or_url(wha, loc, capcheck=None): |
|
33 |
node = { 'tag': wha, 'subtree': {} }
|
|
34 |
if '://' in loc: # e.g. http://, file://, ftp://
|
|
32 |
def datastore_or_url(wha, loc, capcheck=None):
|
|
33 |
node = new_ele(wha)
|
|
34 |
if "://" in loc: # e.g. http://, file://, ftp://
|
|
35 | 35 |
if capcheck is not None: |
36 |
capcheck(':url') # url schema check at some point! |
|
37 |
node['subtree']['tag'] = 'url' |
|
38 |
node['subtree']['text'] = loc |
|
36 |
capcheck(":url") # url schema check at some point! |
|
37 |
sub_ele(node, "url").text = loc |
|
39 | 38 |
else: |
40 | 39 |
#if loc == 'candidate': |
41 | 40 |
# capcheck(':candidate') |
... | ... | |
43 | 42 |
# capcheck(':startup') |
44 | 43 |
#elif loc == 'running' and wha == 'target': |
45 | 44 |
# capcheck(':writable-running') |
46 |
node['subtree']['tag'] = loc
|
|
45 |
sub_ele(node, loc)
|
|
47 | 46 |
return node |
48 | 47 |
|
49 | 48 |
def build_filter(spec, capcheck=None): |
50 | 49 |
type = None |
51 | 50 |
if isinstance(spec, tuple): |
52 | 51 |
type, criteria = spec |
53 |
rep = {'tag': 'filter', 'attrib': {'type': type}}
|
|
54 |
if type == 'xpath':
|
|
55 |
rep['attrib']['select'] = criteria
|
|
56 |
elif type == 'subtree':
|
|
57 |
rep['subtree'] = criteria
|
|
52 |
rep = new_ele("filter", type=type)
|
|
53 |
if type == "xpath":
|
|
54 |
rep.attrib["select"] = criteria
|
|
55 |
elif type == "subtree":
|
|
56 |
rep.append(to_ele(criteria))
|
|
58 | 57 |
else: |
59 | 58 |
raise OperationError("Invalid filter type") |
60 | 59 |
else: |
61 |
rep = xml_.validated_element(spec, ['filter', xml_.qualify('filter')], |
|
62 |
attrs=[('type', xml_.qualify('type'))]) |
|
63 |
if type == 'xpath' and capcheck is not None: |
|
64 |
capcheck(':xpath') |
|
60 |
rep = validated_element(spec, ("filter", qualify("filter")), |
|
61 |
attrs=("type",)) |
|
62 |
# TODO set type var here, check if select attr present in case of xpath.. |
|
63 |
if type == "xpath" and capcheck is not None: |
|
64 |
capcheck(":xpath") |
|
65 | 65 |
return rep |
Also available in: Unified diff