Package bodhi :: Module validators
[hide private]
[frames] | no frames]

Source Code for Module bodhi.validators

 1  # $Id: $ 
 2  # This program is free software; you can redistribute it and/or modify 
 3  # it under the terms of the GNU General Public License as published by 
 4  # the Free Software Foundation; version 2 of the License. 
 5  # 
 6  # This program is distributed in the hope that it will be useful, 
 7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 9  # GNU Library General Public License for more details. 
10  # 
11  # You should have received a copy of the GNU General Public License 
12  # along with this program; if not, write to the Free Software 
13  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
14   
15  import re 
16   
17  from formencode import Invalid 
18  from turbogears import validators 
19   
20 -class PackageValidator(validators.FancyValidator):
21 messages = { 22 'bad_name' : 'Invalid package name; must be in package-version-' 23 'release format', 24 } 25
26 - def _to_python(self, value, state):
27 return value.strip()
28
29 - def validate_python(self, value, state):
30 # We eventually should check the koji tag of each package in this 31 # validator, but in that case we need to know what release this update 32 # is being submitted for. 33 if len(value.split('-')) < 3: 34 raise Invalid(self.message('bad_name', state), value, state)
35
36 -class AutoCompleteValidator(validators.Schema):
37 - def _to_python(self, value, state):
38 vals = [] 39 builds = [] 40 if isinstance(value, str): 41 vals = value.split() 42 elif not isinstance(value['text'], list): 43 vals = [value['text']] 44 elif isinstance(value['text'], list): 45 vals = value['text'] 46 for build in vals: 47 builds += build.replace(',', ' ').split() 48 return map(PackageValidator().to_python, 49 map(validators.UnicodeString().to_python, 50 filter(lambda x: x != '', builds)))
51
52 -class BugValidator(validators.FancyValidator):
53 messages = { 54 'invalid_bug' : "Invalid bug(s). Please supply a list of bug " 55 "numbers. Example: 123, 456 #789" 56 } 57
58 - def _to_python(self, value, state):
59 bugs = validators.UnicodeString().to_python(value.strip()) 60 try: 61 bugs = map(int, bugs.replace(',', ' ').replace('#', '').split()) 62 except ValueError: 63 raise Invalid(self.message('invalid_bug', state), bugs, state) 64 return bugs
65
66 - def validate_python(self, bugs, state):
67 for bug in bugs: 68 if bug <= 0: 69 raise Invalid(self.message('invalid_bug', state), bugs, state)
70
71 -class CVEValidator(validators.FancyValidator):
72 messages = { 73 'invalid_cve' : "Invalid CVE(s). Please list CVEs in the format " 74 "CVE-2007-0000" 75 } 76 regex = re.compile("(CAN|CVE)-\d\d\d\d-\d\d\d\d") 77
78 - def _to_python(self, value, state):
79 cves = validators.UnicodeString().to_python(value.strip()) 80 return cves.replace(',', ' ').split()
81
82 - def validate_python(self, cves, state):
83 for cve in cves: 84 if not self.regex.match(cve): 85 raise Invalid(self.message('invalid_cve', state), cves, state)
86