(cls, arg: HostPatternType)
| 250 | |
| 251 | @classmethod |
| 252 | def to_host_pattern(cls, arg: HostPatternType) -> "HostPattern": |
| 253 | if arg is None: |
| 254 | return cls() |
| 255 | elif isinstance(arg, str): |
| 256 | return cls(arg) |
| 257 | elif isinstance(arg, cls): |
| 258 | return arg |
| 259 | elif isinstance(arg, dict): |
| 260 | if 'pattern' not in arg: |
| 261 | raise SpecValidationError("Got dict for host pattern " |
| 262 | f"with no pattern field: {arg}") |
| 263 | pattern = arg['pattern'] |
| 264 | if not pattern: |
| 265 | raise SpecValidationError("Got dict for host pattern" |
| 266 | f"with empty pattern: {arg}") |
| 267 | assert isinstance(pattern, str) |
| 268 | if 'pattern_type' in arg: |
| 269 | pattern_type = arg['pattern_type'] |
| 270 | if not pattern_type or pattern_type == 'fnmatch': |
| 271 | return cls(pattern, pattern_type=PatternType.fnmatch) |
| 272 | elif pattern_type == 'regex': |
| 273 | return cls(pattern, pattern_type=PatternType.regex) |
| 274 | else: |
| 275 | raise SpecValidationError("Got dict for host pattern " |
| 276 | f"with unknown pattern type: {arg}") |
| 277 | return cls(pattern) |
| 278 | raise SpecValidationError(f"Cannot convert {type(arg)} object to HostPattern") |
| 279 | |
| 280 | def __eq__(self, other: Any) -> bool: |
| 281 | try: |
no test coverage detected