Changeset 391 for python/trunk/Lib/warnings.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/warnings.py
r2 r391 30 30 except IOError: 31 31 pass # the file (probably stderr) is invalid - this warning gets lost. 32 # Keep a wor rking version around in case the deprecation of the old API is32 # Keep a working version around in case the deprecation of the old API is 33 33 # triggered. 34 34 showwarning = _show_warning … … 47 47 """Insert an entry into the list of warnings filters (at the front). 48 48 49 Use assertions to check that all arguments have the right type.""" 49 'action' -- one of "error", "ignore", "always", "default", "module", 50 or "once" 51 'message' -- a regex that the warning message must match 52 'category' -- a class that the warning must be a subclass of 53 'module' -- a regex that the module name must match 54 'lineno' -- an integer line number, 0 matches all warnings 55 'append' -- if true, append to the list of filters 56 """ 50 57 import re 51 58 assert action in ("error", "ignore", "always", "default", "module", … … 69 76 70 77 A simple filter matches all modules and messages. 78 'action' -- one of "error", "ignore", "always", "default", "module", 79 or "once" 80 'category' -- a class that the warning must be a subclass of 81 'lineno' -- an integer line number, 0 matches all warnings 82 'append' -- if true, append to the list of filters 71 83 """ 72 84 assert action in ("error", "ignore", "always", "default", "module", … … 263 275 "Unrecognized action (%r) in warnings.filters:\n %s" % 264 276 (action, item)) 265 # Warn if showwarning() does not support the 'line' argument.266 # Don't use 'inspect' as it relies on an extension module, which break the267 # build thanks to 'warnings' being imported by setup.py.268 fxn_code = None269 if hasattr(showwarning, 'func_code'):270 fxn_code = showwarning.func_code271 elif hasattr(showwarning, '__func__'):272 fxn_code = showwarning.__func__.func_code273 if fxn_code:274 args = fxn_code.co_varnames[:fxn_code.co_argcount]275 CO_VARARGS = 0x4276 if 'line' not in args and not fxn_code.co_flags & CO_VARARGS:277 showwarning_msg = ("functions overriding warnings.showwarning() "278 "must support the 'line' argument")279 if message == showwarning_msg:280 _show_warning(message, category, filename, lineno)281 else:282 warn(showwarning_msg, DeprecationWarning)283 277 # Print message and context 284 278 showwarning(message, category, filename, lineno) … … 390 384 _processoptions(sys.warnoptions) 391 385 if not _warnings_defaults: 392 simplefilter("ignore", category=PendingDeprecationWarning, append=1) 393 simplefilter("ignore", category=ImportWarning, append=1) 386 silence = [ImportWarning, PendingDeprecationWarning] 387 # Don't silence DeprecationWarning if -3 or -Q was used. 388 if not sys.py3kwarning and not sys.flags.division_warning: 389 silence.append(DeprecationWarning) 390 for cls in silence: 391 simplefilter("ignore", category=cls) 394 392 bytes_warning = sys.flags.bytes_warning 395 393 if bytes_warning > 1:
Note:
See TracChangeset
for help on using the changeset viewer.