comparison env/lib/python3.7/site-packages/galaxy/util/validation.py @ 0:26e78fe6e8c4 draft

"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author shellac
date Sat, 02 May 2020 07:14:21 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:26e78fe6e8c4
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):