(
cls,
dict_: Optional[
Union[
Sequence[Tuple[str, Union[Sequence[str], str]]],
Mapping[str, Union[Sequence[str], str]],
]
],
)
| 241 | |
| 242 | @classmethod |
| 243 | def _str_dict( |
| 244 | cls, |
| 245 | dict_: Optional[ |
| 246 | Union[ |
| 247 | Sequence[Tuple[str, Union[Sequence[str], str]]], |
| 248 | Mapping[str, Union[Sequence[str], str]], |
| 249 | ] |
| 250 | ], |
| 251 | ) -> util.immutabledict[str, Union[Tuple[str, ...], str]]: |
| 252 | if dict_ is None: |
| 253 | return util.EMPTY_DICT |
| 254 | |
| 255 | @overload |
| 256 | def _assert_value( |
| 257 | val: str, |
| 258 | ) -> str: ... |
| 259 | |
| 260 | @overload |
| 261 | def _assert_value( |
| 262 | val: Sequence[str], |
| 263 | ) -> Union[str, Tuple[str, ...]]: ... |
| 264 | |
| 265 | def _assert_value( |
| 266 | val: Union[str, Sequence[str]], |
| 267 | ) -> Union[str, Tuple[str, ...]]: |
| 268 | if isinstance(val, str): |
| 269 | return val |
| 270 | elif isinstance(val, collections_abc.Sequence): |
| 271 | return tuple(_assert_value(elem) for elem in val) |
| 272 | else: |
| 273 | raise TypeError( |
| 274 | "Query dictionary values must be strings or " |
| 275 | "sequences of strings" |
| 276 | ) |
| 277 | |
| 278 | def _assert_str(v: str) -> str: |
| 279 | if not isinstance(v, str): |
| 280 | raise TypeError("Query dictionary keys must be strings") |
| 281 | return v |
| 282 | |
| 283 | dict_items: Iterable[Tuple[str, Union[Sequence[str], str]]] |
| 284 | if isinstance(dict_, collections_abc.Sequence): |
| 285 | dict_items = dict_ |
| 286 | else: |
| 287 | dict_items = dict_.items() |
| 288 | |
| 289 | return util.immutabledict( |
| 290 | { |
| 291 | _assert_str(key): _assert_value( |
| 292 | value, |
| 293 | ) |
| 294 | for key, value in dict_items |
| 295 | } |
| 296 | ) |
| 297 | |
| 298 | def set( |
| 299 | self, |
no test coverage detected