comparison env/lib/python3.9/site-packages/galaxy/util/validation.py @ 0:4f3585e2f14b draft default tip

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