1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 import re
16
17 from formencode import Invalid
18 from turbogears import validators
19
21 messages = {
22 'bad_name' : 'Invalid package name; must be in package-version-'
23 'release format',
24 }
25
28
30
31
32
33 if len(value.split('-')) < 3:
34 raise Invalid(self.message('bad_name', state), value, state)
35
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
53 messages = {
54 'invalid_bug' : "Invalid bug(s). Please supply a list of bug "
55 "numbers. Example: 123, 456 #789"
56 }
57
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
67 for bug in bugs:
68 if bug <= 0:
69 raise Invalid(self.message('invalid_bug', state), bugs, state)
70
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
79 cves = validators.UnicodeString().to_python(value.strip())
80 return cves.replace(',', ' ').split()
81
83 for cve in cves:
84 if not self.regex.match(cve):
85 raise Invalid(self.message('invalid_cve', state), cves, state)
86