1
2
3 from collections import Iterable
4 from marshmallow import Schema, fields, ValidationError, validate
5 from six import string_types
6
7
9 """
10 :param fn_list: list of callable functions, each takes one param
11 :return: None if at least one validation function exists without exceptions
12 :raises ValidationError: otherwise
13 """
14 def func(value):
15 errors = []
16 for fn in fn_list:
17 try:
18 fn(value)
19 except ValidationError as err:
20 errors.append(str(err))
21 else:
22 return
23 else:
24 errors.insert(0, u"At least one validator should accept given value:")
25 raise ValidationError(errors)
26
27 return func
28
29
32 if value is None:
33 return []
34 return value.split()
35
37 if value is None:
38 return ""
39 elif not isinstance(value, Iterable) or isinstance(value, string_types):
40 raise ValidationError("Value `{}` is not a list of strings"
41 .format(value))
42 else:
43 return " ".join(value)
44
45
47 """ stored in db as a string:
48 "python3-marshmallow 2.0.0b5\npython-marshmallow 2.0.0b5"
49 we would represent them as
50 { name: "pkg", version: "pkg version" }
51 we implement only the serialization, since field is read-only
52 """
54 if value is None:
55 return []
56 result = []
57 try:
58 for chunk in value.split("\n"):
59 pkg, version = chunk.split()
60 result.append({
61 "name": pkg,
62 "version": version
63 })
64 except:
65 pass
66
67 return result
68
69
75
76
81
82
105
106
108 name = fields.Str(
109 required=True,
110 validate=[
111 validate.Regexp(
112 r"^[a-zA-Z][\w.-]*$",
113 error="Name must contain only letters,"
114 "digits, underscores, dashes and dots."
115 "And starts with letter"),
116 ])
117 group = fields.Str(load_only=True, allow_none=True)
118 chroots = SpaceSeparatedList(load_only=True, default=list)
119
120
121
130
131
134
135
146
147
168
169
176
177
179 srpm_url = fields.Url(required=True, validate=lambda u: u.startswith("http"))
180