comparison env/lib/python3.7/site-packages/galaxy/util/validation.py @ 2:6af9afd405e9 draft

"planemo upload commit 0a63dd5f4d38a1f6944587f52a8cd79874177fc1"
author shellac
date Thu, 14 May 2020 14:56:58 -0400
parents 26e78fe6e8c4
children
comparison
equal deleted inserted replaced
1:75ca89e9b81c 2:6af9afd405e9
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):