| 371 | |
| 372 | |
| 373 | class OrPredicate(Predicate): |
| 374 | def __init__(self, predicates, description=None): |
| 375 | self.predicates = predicates |
| 376 | self.description = description |
| 377 | |
| 378 | def __call__(self, config): |
| 379 | for pred in self.predicates: |
| 380 | if pred(config): |
| 381 | return True |
| 382 | return False |
| 383 | |
| 384 | def _eval_str(self, config, negate=False): |
| 385 | if negate: |
| 386 | conjunction = " and " |
| 387 | else: |
| 388 | conjunction = " or " |
| 389 | return conjunction.join( |
| 390 | p._as_string(config, negate=negate) for p in self.predicates |
| 391 | ) |
| 392 | |
| 393 | def _negation_str(self, config): |
| 394 | if self.description is not None: |
| 395 | return "Not " + self._format_description(config) |
| 396 | else: |
| 397 | return self._eval_str(config, negate=True) |
| 398 | |
| 399 | def _as_string(self, config, negate=False): |
| 400 | if negate: |
| 401 | return self._negation_str(config) |
| 402 | else: |
| 403 | if self.description is not None: |
| 404 | return self._format_description(config) |
| 405 | else: |
| 406 | return self._eval_str(config) |
| 407 | |
| 408 | |
| 409 | _as_predicate = Predicate.as_predicate |
no outgoing calls
no test coverage detected