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)
| 46 | |
| 47 | |
| 48 | def 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 | |
| 76 | def read_dict(values_dict, key, default=None): |