(message, category, filename, lineno,
module=None, registry=None, module_globals=None,
source=None)
| 496 | |
| 497 | |
| 498 | def warn_explicit(message, category, filename, lineno, |
| 499 | module=None, registry=None, module_globals=None, |
| 500 | source=None): |
| 501 | lineno = int(lineno) |
| 502 | if module is None: |
| 503 | module = filename or "<unknown>" |
| 504 | if module[-3:].lower() == ".py": |
| 505 | module = module[:-3] # XXX What about leading pathname? |
| 506 | if isinstance(message, Warning): |
| 507 | text = str(message) |
| 508 | category = message.__class__ |
| 509 | else: |
| 510 | text = message |
| 511 | message = category(message) |
| 512 | key = (text, category, lineno) |
| 513 | with _wm._lock: |
| 514 | if registry is None: |
| 515 | registry = {} |
| 516 | if registry.get('version', 0) != _wm._filters_version: |
| 517 | registry.clear() |
| 518 | registry['version'] = _wm._filters_version |
| 519 | # Quick test for common case |
| 520 | if registry.get(key): |
| 521 | return |
| 522 | # Search the filters |
| 523 | for item in _wm._get_filters(): |
| 524 | action, msg, cat, mod, ln = item |
| 525 | if ((msg is None or msg.match(text)) and |
| 526 | issubclass(category, cat) and |
| 527 | (mod is None or mod.match(module)) and |
| 528 | (ln == 0 or lineno == ln)): |
| 529 | break |
| 530 | else: |
| 531 | action = _wm.defaultaction |
| 532 | # Early exit actions |
| 533 | if action == "ignore": |
| 534 | return |
| 535 | |
| 536 | if action == "error": |
| 537 | raise message |
| 538 | # Other actions |
| 539 | if action == "once": |
| 540 | registry[key] = 1 |
| 541 | oncekey = (text, category) |
| 542 | if _wm.onceregistry.get(oncekey): |
| 543 | return |
| 544 | _wm.onceregistry[oncekey] = 1 |
| 545 | elif action in {"always", "all"}: |
| 546 | pass |
| 547 | elif action == "module": |
| 548 | registry[key] = 1 |
| 549 | altkey = (text, category, 0) |
| 550 | if registry.get(altkey): |
| 551 | return |
| 552 | registry[altkey] = 1 |
| 553 | elif action == "default": |
| 554 | registry[key] = 1 |
| 555 | else: |
nothing calls this directly
no test coverage detected