Hook to write a warning to a file; replace if you like.
(msg)
| 95 | _showwarning_orig = showwarning |
| 96 | |
| 97 | def _showwarnmsg(msg): |
| 98 | """Hook to write a warning to a file; replace if you like.""" |
| 99 | try: |
| 100 | sw = showwarning |
| 101 | except NameError: |
| 102 | pass |
| 103 | else: |
| 104 | if sw is not _showwarning_orig: |
| 105 | # warnings.showwarning() was replaced |
| 106 | if not callable(sw): |
| 107 | raise TypeError("warnings.showwarning() must be set to a " |
| 108 | "function or method") |
| 109 | |
| 110 | sw(msg.message, msg.category, msg.filename, msg.lineno, |
| 111 | msg.file, msg.line) |
| 112 | return |
| 113 | _showwarnmsg_impl(msg) |
| 114 | |
| 115 | # Keep a reference to check if the function was replaced |
| 116 | _formatwarning_orig = formatwarning |
no test coverage detected