1 # Copyright 2009 Shikhar Bhushan
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 'Boilerplate ugliness'
17 from ncclient import content
19 from errors import OperationError, MissingCapabilityError
22 'Verifies that only one of the arguments is not None'
23 for i, arg in enumerate(args):
25 for argh in args[i+1:]:
27 raise OperationError('Too many parameters')
30 raise OperationError('Insufficient parameters')
32 def store_or_url(wha, loc, capcheck=None):
33 node = { 'tag': wha, 'subtree': {} }
34 if '://' in loc: # e.g. http://, file://, ftp://
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
40 #if loc == 'candidate':
41 # capcheck(':candidate')
42 #elif loc == 'startup':
43 # capcheck(':startup')
44 #elif loc == 'running' and wha == 'target':
45 # capcheck(':writable-running')
46 node['subtree']['tag'] = loc
49 def build_filter(spec, capcheck=None):
51 if isinstance(spec, tuple):
53 rep = {'tag': 'filter', 'attrib': {'type': type}}
55 rep['attrib']['select'] = criteria
56 elif type == 'subtree':
57 rep['subtree'] = criteria
59 raise OperationError("Invalid filter type")
61 rep = content.validated_element(spec, ['filter', content.qualify('filter')],
62 attrs=[('type', content.qualify('type'))])
63 if type == 'xpath' and capcheck is not None: