Return: - a mapping for facet patterns to a list of unique facet names as {pattern: [facet, facet, ...]} - a sorted list of error messages for invalid or unknown facet definitions found in `facets`. The `known` facets set of known facets is used for validation.
(facets, known_facet_names=FACETS)
| 170 | |
| 171 | |
| 172 | def build_facets(facets, known_facet_names=FACETS): |
| 173 | """ |
| 174 | Return: |
| 175 | - a mapping for facet patterns to a list of unique facet names as |
| 176 | {pattern: [facet, facet, ...]} |
| 177 | - a sorted list of error messages for invalid or unknown facet definitions |
| 178 | found in `facets`. |
| 179 | The `known` facets set of known facets is used for validation. |
| 180 | """ |
| 181 | invalid_facet_definitions = set() |
| 182 | facet_patterns = defaultdict(list) |
| 183 | for facet_def in facets: |
| 184 | facet, _, pattern = facet_def.partition('=') |
| 185 | facet = facet.strip().lower() |
| 186 | pattern = pattern.strip() |
| 187 | |
| 188 | if not pattern: |
| 189 | invalid_facet_definitions.add( |
| 190 | 'missing <pattern> in "{facet_def}".'.format(**locals())) |
| 191 | continue |
| 192 | |
| 193 | if not facet: |
| 194 | invalid_facet_definitions.add( |
| 195 | 'missing <facet> in "{facet_def}".'.format(**locals())) |
| 196 | continue |
| 197 | |
| 198 | if facet not in known_facet_names: |
| 199 | invalid_facet_definitions.add( |
| 200 | 'unknown <facet> in "{facet_def}".'.format(**locals())) |
| 201 | continue |
| 202 | |
| 203 | facets = facet_patterns[pattern] |
| 204 | |
| 205 | if facet not in facets: |
| 206 | facet_patterns[pattern].append(facet) |
| 207 | |
| 208 | return facet_patterns, sorted(invalid_facet_definitions) |
no test coverage detected