MCPcopy Index your code
hub / github.com/bugy/script-server / read_list

Function read_list

src/model/model_helper.py:48–73  ·  view source on GitHub ↗

Reads value from values_dict as a list If value is a list, then list is returned If value is missing, then default value is returned (or an empty list if not specified) If value is a dictionary, then error is raised Otherwise, a list of single element is retu

(values_dict, key, default=None)

Source from the content-addressed store, hash-verified

46
47
48def read_list(values_dict, key, default=None):
49 """
50 Reads value from values_dict as a list
51
52 If value is a list, then list is returned
53
54 If value is missing, then default value is returned (or an empty list if not specified)
55
56 If value is a dictionary, then error is raised
57
58 Otherwise, a list of single element is returned as a value
59 """
60
61 value = values_dict.get(key)
62 if value is None:
63 if default is not None:
64 return default
65 return []
66
67 if isinstance(value, list):
68 return value
69
70 if isinstance(value, dict):
71 raise Exception('"' + key + '" has invalid type. List expected, got dictionary')
72
73 return [value]
74
75
76def read_dict(values_dict, key, default=None):

Callers 12

from_jsonFunction · 0.90
_parse_admin_usersFunction · 0.90
_parse_history_usersFunction · 0.90
_parse_code_editor_usersFunction · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
test_simple_listMethod · 0.90
test_single_valueMethod · 0.90

Calls 1

getMethod · 0.45

Tested by 5

test_simple_listMethod · 0.72
test_single_valueMethod · 0.72