comparison env/lib/python3.7/site-packages/galaxy/util/validation.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 """ Module for validation of incoming inputs.
2
3 TODO: Refactor BaseController references to similar methods to use this module.
4 """
5 from six import string_types
6
7 from galaxy import exceptions
8 from galaxy.util.sanitize_html import sanitize_html
9
10
11 def validate_and_sanitize_basestring(key, val):
12 if not isinstance(val, string_types):
13 raise exceptions.RequestParameterInvalidException('%s must be a string or unicode: %s'
14 % (key, str(type(val))))
15 return sanitize_html(val)
16
17
18 def validate_and_sanitize_basestring_list(key, val):
19 try:
20 assert isinstance(val, list)
21 return [sanitize_html(t) for t in val]
22 except (AssertionError, TypeError):
23 raise exceptions.RequestParameterInvalidException('%s must be a list of strings: %s'
24 % (key, str(type(val))))
25
26
27 def validate_boolean(key, val):
28 if not isinstance(val, bool):
29 raise exceptions.RequestParameterInvalidException('%s must be a boolean: %s'
30 % (key, str(type(val))))
31 return val
32
33
34 # TODO:
35 # def validate_integer(self, key, val, min, max):
36 # def validate_float(self, key, val, min, max):
37 # def validate_number(self, key, val, min, max):
38 # def validate_genome_build(self, key, val):