Package pyctags :: Module kwargs_validator
[hide private]
[frames] | no frames]

Source Code for Module pyctags.kwargs_validator

 1  ## Copyright (C) 2008 Ben Smith <benjamin.coder.smith@gmail.com> 
 2   
 3  ##    This file is part of pyctags. 
 4   
 5  ##    pyctags is free software: you can redistribute it and/or modify 
 6  ##    it under the terms of the GNU Lesser General Public License as published 
 7  ##    by the Free Software Foundation, either version 3 of the License, or 
 8  ##    (at your option) any later version. 
 9   
10  ##    pyctags is distributed in the hope that it will be useful, 
11  ##    but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  ##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  ##    GNU General Public License for more details. 
14   
15  ##    You should have received a copy of the GNU Lesser General Public License 
16  ##    and the GNU Lesser General Public Licens along with pyctags.  If not,  
17  ##    see <http://www.gnu.org/licenses/>. 
18   
19   
20  """ 
21  A simple validator to make sure keyword arguments are valid. 
22  """ 
23   
24 -class ParameterError(Exception):
25 """ 26 Raised if an invalid argument is passed to kwargs_validator. 27 """
28 - def __init__(self, value):
29 self.value = value
30
31 - def __str__(self):
32 return str(self.value)
33
34 -class kwargs_validator:
35 """ 36 Used to validate arguments. 37 """
38 - def validate(self, args, allowed_args):
39 """ 40 @param args: arguments to check for validity. 41 @type args: iterable 42 @param allowed_args: list of valid arguments. 43 @type allowed_args: list 44 @raises ParameterError: if an element of args is not in allowed_args. 45 """ 46 for arg in args: 47 if arg not in allowed_args: 48 raise ParameterError("Parameter " + arg + " is not accepted by calling function.")
49 50 the_validator = kwargs_validator() 51