(message, category, filename, lineno,
module=None, registry=None, module_globals=None,
source=None)
| 326 | globals, source) |
| 327 | |
| 328 | def warn_explicit(message, category, filename, lineno, |
| 329 | module=None, registry=None, module_globals=None, |
| 330 | source=None): |
| 331 | lineno = int(lineno) |
| 332 | if module is None: |
| 333 | module = filename or "<unknown>" |
| 334 | if module[-3:].lower() == ".py": |
| 335 | module = module[:-3] # XXX What about leading pathname? |
| 336 | if registry is None: |
| 337 | registry = {} |
| 338 | if registry.get('version', 0) != _filters_version: |
| 339 | registry.clear() |
| 340 | registry['version'] = _filters_version |
| 341 | if isinstance(message, Warning): |
| 342 | text = str(message) |
| 343 | category = message.__class__ |
| 344 | else: |
| 345 | text = message |
| 346 | message = category(message) |
| 347 | key = (text, category, lineno) |
| 348 | # Quick test for common case |
| 349 | if registry.get(key): |
| 350 | return |
| 351 | # Search the filters |
| 352 | for item in filters: |
| 353 | action, msg, cat, mod, ln = item |
| 354 | if ((msg is None or msg.match(text)) and |
| 355 | issubclass(category, cat) and |
| 356 | (mod is None or mod.match(module)) and |
| 357 | (ln == 0 or lineno == ln)): |
| 358 | break |
| 359 | else: |
| 360 | action = defaultaction |
| 361 | # Early exit actions |
| 362 | if action == "ignore": |
| 363 | return |
| 364 | |
| 365 | # Prime the linecache for formatting, in case the |
| 366 | # "file" is actually in a zipfile or something. |
| 367 | import linecache |
| 368 | linecache.getlines(filename, module_globals) |
| 369 | |
| 370 | if action == "error": |
| 371 | raise message |
| 372 | # Other actions |
| 373 | if action == "once": |
| 374 | registry[key] = 1 |
| 375 | oncekey = (text, category) |
| 376 | if onceregistry.get(oncekey): |
| 377 | return |
| 378 | onceregistry[oncekey] = 1 |
| 379 | elif action == "always": |
| 380 | pass |
| 381 | elif action == "module": |
| 382 | registry[key] = 1 |
| 383 | altkey = (text, category, 0) |
| 384 | if registry.get(altkey): |
| 385 | return |
no test coverage detected