11import os
22
33
4+ def dict_prepend (original , key , value ):
5+ # Since Python 3.7, python dictionaries preserve insertion
6+ # order, so to prepend an item to the top of the dictionary,
7+ # we create a new dictionary inserting the new key first,
8+ # then add the previous output
9+ new_dict = {key : value }
10+ new_dict .update (original )
11+ return new_dict
12+
13+
414def get_os_var (varnam ):
515 try :
616 return os .environ [varnam ]
@@ -22,6 +32,17 @@ def _param_bool(params, param):
2232 return False
2333
2434
35+ def _param_int (params , param ):
36+ number = 0
37+ if params and param in params :
38+ try :
39+ number = int (params [param ])
40+ except ValueError as exc :
41+ msg = f"The parameter '{ param } ' must be an integer"
42+ raise ValueError (msg ) from exc
43+ return number
44+
45+
2546def param_inactive_bool (params ):
2647 return not _param_bool (params , "show_inactive_codes" )
2748
@@ -35,13 +56,10 @@ def param_no_program_bool(params):
3556
3657
3758def param_limit_int (params ):
38- if params and "limit" in params :
39- try :
40- return int (params ["limit" ])
41- except ValueError as exc :
42- err_str = "QueryStringParameter 'limit' must be an Integer"
43- raise ValueError (err_str ) from exc
44- return 0
59+ limit = _param_int (params , "limit" )
60+ if limit < 0 :
61+ raise ValueError ("The parameter 'limit' must be a positive Integer" )
62+ return limit
4563
4664
4765def param_priority_list (params ):
0 commit comments