(selected: str, *, possible=None)
| 114 | |
| 115 | |
| 116 | def normalize_selection(selected: str, *, possible=None): |
| 117 | if selected in (None, True, False): |
| 118 | return selected |
| 119 | elif isinstance(selected, str): |
| 120 | selected = [selected] |
| 121 | elif not selected: |
| 122 | return () |
| 123 | |
| 124 | unsupported = [] |
| 125 | _selected = set() |
| 126 | for item in selected: |
| 127 | if not item: |
| 128 | continue |
| 129 | for value in item.strip().replace(',', ' ').split(): |
| 130 | if not value: |
| 131 | continue |
| 132 | # XXX Handle subtraction (leading "-"). |
| 133 | if possible and value not in possible and value != 'all': |
| 134 | unsupported.append(value) |
| 135 | _selected.add(value) |
| 136 | if unsupported: |
| 137 | raise UnsupportedSelectionError(unsupported, tuple(possible)) |
| 138 | if 'all' in _selected: |
| 139 | return True |
| 140 | return frozenset(selected) |
| 141 | |
| 142 | |
| 143 | ################################## |
no test coverage detected
searching dependent graphs…