Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python3....
File: warnings.py
"""Python part of the warnings subsystem."""
[0] Fix | Delete
[1] Fix | Delete
import sys
[2] Fix | Delete
[3] Fix | Delete
[4] Fix | Delete
__all__ = ["warn", "warn_explicit", "showwarning",
[5] Fix | Delete
"formatwarning", "filterwarnings", "simplefilter",
[6] Fix | Delete
"resetwarnings", "catch_warnings"]
[7] Fix | Delete
[8] Fix | Delete
def showwarning(message, category, filename, lineno, file=None, line=None):
[9] Fix | Delete
"""Hook to write a warning to a file; replace if you like."""
[10] Fix | Delete
msg = WarningMessage(message, category, filename, lineno, file, line)
[11] Fix | Delete
_showwarnmsg_impl(msg)
[12] Fix | Delete
[13] Fix | Delete
def formatwarning(message, category, filename, lineno, line=None):
[14] Fix | Delete
"""Function to format a warning the standard way."""
[15] Fix | Delete
msg = WarningMessage(message, category, filename, lineno, None, line)
[16] Fix | Delete
return _formatwarnmsg_impl(msg)
[17] Fix | Delete
[18] Fix | Delete
def _showwarnmsg_impl(msg):
[19] Fix | Delete
file = msg.file
[20] Fix | Delete
if file is None:
[21] Fix | Delete
file = sys.stderr
[22] Fix | Delete
if file is None:
[23] Fix | Delete
# sys.stderr is None when run with pythonw.exe:
[24] Fix | Delete
# warnings get lost
[25] Fix | Delete
return
[26] Fix | Delete
text = _formatwarnmsg(msg)
[27] Fix | Delete
try:
[28] Fix | Delete
file.write(text)
[29] Fix | Delete
except OSError:
[30] Fix | Delete
# the file (probably stderr) is invalid - this warning gets lost.
[31] Fix | Delete
pass
[32] Fix | Delete
[33] Fix | Delete
def _formatwarnmsg_impl(msg):
[34] Fix | Delete
s = ("%s:%s: %s: %s\n"
[35] Fix | Delete
% (msg.filename, msg.lineno, msg.category.__name__,
[36] Fix | Delete
msg.message))
[37] Fix | Delete
[38] Fix | Delete
if msg.line is None:
[39] Fix | Delete
try:
[40] Fix | Delete
import linecache
[41] Fix | Delete
line = linecache.getline(msg.filename, msg.lineno)
[42] Fix | Delete
except Exception:
[43] Fix | Delete
# When a warning is logged during Python shutdown, linecache
[44] Fix | Delete
# and the import machinery don't work anymore
[45] Fix | Delete
line = None
[46] Fix | Delete
linecache = None
[47] Fix | Delete
else:
[48] Fix | Delete
line = msg.line
[49] Fix | Delete
if line:
[50] Fix | Delete
line = line.strip()
[51] Fix | Delete
s += " %s\n" % line
[52] Fix | Delete
[53] Fix | Delete
if msg.source is not None:
[54] Fix | Delete
try:
[55] Fix | Delete
import tracemalloc
[56] Fix | Delete
tb = tracemalloc.get_object_traceback(msg.source)
[57] Fix | Delete
except Exception:
[58] Fix | Delete
# When a warning is logged during Python shutdown, tracemalloc
[59] Fix | Delete
# and the import machinery don't work anymore
[60] Fix | Delete
tb = None
[61] Fix | Delete
[62] Fix | Delete
if tb is not None:
[63] Fix | Delete
s += 'Object allocated at (most recent call first):\n'
[64] Fix | Delete
for frame in tb:
[65] Fix | Delete
s += (' File "%s", lineno %s\n'
[66] Fix | Delete
% (frame.filename, frame.lineno))
[67] Fix | Delete
[68] Fix | Delete
try:
[69] Fix | Delete
if linecache is not None:
[70] Fix | Delete
line = linecache.getline(frame.filename, frame.lineno)
[71] Fix | Delete
else:
[72] Fix | Delete
line = None
[73] Fix | Delete
except Exception:
[74] Fix | Delete
line = None
[75] Fix | Delete
if line:
[76] Fix | Delete
line = line.strip()
[77] Fix | Delete
s += ' %s\n' % line
[78] Fix | Delete
return s
[79] Fix | Delete
[80] Fix | Delete
# Keep a reference to check if the function was replaced
[81] Fix | Delete
_showwarning_orig = showwarning
[82] Fix | Delete
[83] Fix | Delete
def _showwarnmsg(msg):
[84] Fix | Delete
"""Hook to write a warning to a file; replace if you like."""
[85] Fix | Delete
try:
[86] Fix | Delete
sw = showwarning
[87] Fix | Delete
except NameError:
[88] Fix | Delete
pass
[89] Fix | Delete
else:
[90] Fix | Delete
if sw is not _showwarning_orig:
[91] Fix | Delete
# warnings.showwarning() was replaced
[92] Fix | Delete
if not callable(sw):
[93] Fix | Delete
raise TypeError("warnings.showwarning() must be set to a "
[94] Fix | Delete
"function or method")
[95] Fix | Delete
[96] Fix | Delete
sw(msg.message, msg.category, msg.filename, msg.lineno,
[97] Fix | Delete
msg.file, msg.line)
[98] Fix | Delete
return
[99] Fix | Delete
_showwarnmsg_impl(msg)
[100] Fix | Delete
[101] Fix | Delete
# Keep a reference to check if the function was replaced
[102] Fix | Delete
_formatwarning_orig = formatwarning
[103] Fix | Delete
[104] Fix | Delete
def _formatwarnmsg(msg):
[105] Fix | Delete
"""Function to format a warning the standard way."""
[106] Fix | Delete
try:
[107] Fix | Delete
fw = formatwarning
[108] Fix | Delete
except NameError:
[109] Fix | Delete
pass
[110] Fix | Delete
else:
[111] Fix | Delete
if fw is not _formatwarning_orig:
[112] Fix | Delete
# warnings.formatwarning() was replaced
[113] Fix | Delete
return fw(msg.message, msg.category,
[114] Fix | Delete
msg.filename, msg.lineno, line=msg.line)
[115] Fix | Delete
return _formatwarnmsg_impl(msg)
[116] Fix | Delete
[117] Fix | Delete
def filterwarnings(action, message="", category=Warning, module="", lineno=0,
[118] Fix | Delete
append=False):
[119] Fix | Delete
"""Insert an entry into the list of warnings filters (at the front).
[120] Fix | Delete
[121] Fix | Delete
'action' -- one of "error", "ignore", "always", "default", "module",
[122] Fix | Delete
or "once"
[123] Fix | Delete
'message' -- a regex that the warning message must match
[124] Fix | Delete
'category' -- a class that the warning must be a subclass of
[125] Fix | Delete
'module' -- a regex that the module name must match
[126] Fix | Delete
'lineno' -- an integer line number, 0 matches all warnings
[127] Fix | Delete
'append' -- if true, append to the list of filters
[128] Fix | Delete
"""
[129] Fix | Delete
import re
[130] Fix | Delete
assert action in ("error", "ignore", "always", "default", "module",
[131] Fix | Delete
"once"), "invalid action: %r" % (action,)
[132] Fix | Delete
assert isinstance(message, str), "message must be a string"
[133] Fix | Delete
assert isinstance(category, type), "category must be a class"
[134] Fix | Delete
assert issubclass(category, Warning), "category must be a Warning subclass"
[135] Fix | Delete
assert isinstance(module, str), "module must be a string"
[136] Fix | Delete
assert isinstance(lineno, int) and lineno >= 0, \
[137] Fix | Delete
"lineno must be an int >= 0"
[138] Fix | Delete
_add_filter(action, re.compile(message, re.I), category,
[139] Fix | Delete
re.compile(module), lineno, append=append)
[140] Fix | Delete
[141] Fix | Delete
def simplefilter(action, category=Warning, lineno=0, append=False):
[142] Fix | Delete
"""Insert a simple entry into the list of warnings filters (at the front).
[143] Fix | Delete
[144] Fix | Delete
A simple filter matches all modules and messages.
[145] Fix | Delete
'action' -- one of "error", "ignore", "always", "default", "module",
[146] Fix | Delete
or "once"
[147] Fix | Delete
'category' -- a class that the warning must be a subclass of
[148] Fix | Delete
'lineno' -- an integer line number, 0 matches all warnings
[149] Fix | Delete
'append' -- if true, append to the list of filters
[150] Fix | Delete
"""
[151] Fix | Delete
assert action in ("error", "ignore", "always", "default", "module",
[152] Fix | Delete
"once"), "invalid action: %r" % (action,)
[153] Fix | Delete
assert isinstance(lineno, int) and lineno >= 0, \
[154] Fix | Delete
"lineno must be an int >= 0"
[155] Fix | Delete
_add_filter(action, None, category, None, lineno, append=append)
[156] Fix | Delete
[157] Fix | Delete
def _add_filter(*item, append):
[158] Fix | Delete
# Remove possible duplicate filters, so new one will be placed
[159] Fix | Delete
# in correct place. If append=True and duplicate exists, do nothing.
[160] Fix | Delete
if not append:
[161] Fix | Delete
try:
[162] Fix | Delete
filters.remove(item)
[163] Fix | Delete
except ValueError:
[164] Fix | Delete
pass
[165] Fix | Delete
filters.insert(0, item)
[166] Fix | Delete
else:
[167] Fix | Delete
if item not in filters:
[168] Fix | Delete
filters.append(item)
[169] Fix | Delete
_filters_mutated()
[170] Fix | Delete
[171] Fix | Delete
def resetwarnings():
[172] Fix | Delete
"""Clear the list of warning filters, so that no filters are active."""
[173] Fix | Delete
filters[:] = []
[174] Fix | Delete
_filters_mutated()
[175] Fix | Delete
[176] Fix | Delete
class _OptionError(Exception):
[177] Fix | Delete
"""Exception used by option processing helpers."""
[178] Fix | Delete
pass
[179] Fix | Delete
[180] Fix | Delete
# Helper to process -W options passed via sys.warnoptions
[181] Fix | Delete
def _processoptions(args):
[182] Fix | Delete
for arg in args:
[183] Fix | Delete
try:
[184] Fix | Delete
_setoption(arg)
[185] Fix | Delete
except _OptionError as msg:
[186] Fix | Delete
print("Invalid -W option ignored:", msg, file=sys.stderr)
[187] Fix | Delete
[188] Fix | Delete
# Helper for _processoptions()
[189] Fix | Delete
def _setoption(arg):
[190] Fix | Delete
import re
[191] Fix | Delete
parts = arg.split(':')
[192] Fix | Delete
if len(parts) > 5:
[193] Fix | Delete
raise _OptionError("too many fields (max 5): %r" % (arg,))
[194] Fix | Delete
while len(parts) < 5:
[195] Fix | Delete
parts.append('')
[196] Fix | Delete
action, message, category, module, lineno = [s.strip()
[197] Fix | Delete
for s in parts]
[198] Fix | Delete
action = _getaction(action)
[199] Fix | Delete
message = re.escape(message)
[200] Fix | Delete
category = _getcategory(category)
[201] Fix | Delete
module = re.escape(module)
[202] Fix | Delete
if module:
[203] Fix | Delete
module = module + '$'
[204] Fix | Delete
if lineno:
[205] Fix | Delete
try:
[206] Fix | Delete
lineno = int(lineno)
[207] Fix | Delete
if lineno < 0:
[208] Fix | Delete
raise ValueError
[209] Fix | Delete
except (ValueError, OverflowError):
[210] Fix | Delete
raise _OptionError("invalid lineno %r" % (lineno,))
[211] Fix | Delete
else:
[212] Fix | Delete
lineno = 0
[213] Fix | Delete
filterwarnings(action, message, category, module, lineno)
[214] Fix | Delete
[215] Fix | Delete
# Helper for _setoption()
[216] Fix | Delete
def _getaction(action):
[217] Fix | Delete
if not action:
[218] Fix | Delete
return "default"
[219] Fix | Delete
if action == "all": return "always" # Alias
[220] Fix | Delete
for a in ('default', 'always', 'ignore', 'module', 'once', 'error'):
[221] Fix | Delete
if a.startswith(action):
[222] Fix | Delete
return a
[223] Fix | Delete
raise _OptionError("invalid action: %r" % (action,))
[224] Fix | Delete
[225] Fix | Delete
# Helper for _setoption()
[226] Fix | Delete
def _getcategory(category):
[227] Fix | Delete
import re
[228] Fix | Delete
if not category:
[229] Fix | Delete
return Warning
[230] Fix | Delete
if re.match("^[a-zA-Z0-9_]+$", category):
[231] Fix | Delete
try:
[232] Fix | Delete
cat = eval(category)
[233] Fix | Delete
except NameError:
[234] Fix | Delete
raise _OptionError("unknown warning category: %r" % (category,))
[235] Fix | Delete
else:
[236] Fix | Delete
i = category.rfind(".")
[237] Fix | Delete
module = category[:i]
[238] Fix | Delete
klass = category[i+1:]
[239] Fix | Delete
try:
[240] Fix | Delete
m = __import__(module, None, None, [klass])
[241] Fix | Delete
except ImportError:
[242] Fix | Delete
raise _OptionError("invalid module name: %r" % (module,))
[243] Fix | Delete
try:
[244] Fix | Delete
cat = getattr(m, klass)
[245] Fix | Delete
except AttributeError:
[246] Fix | Delete
raise _OptionError("unknown warning category: %r" % (category,))
[247] Fix | Delete
if not issubclass(cat, Warning):
[248] Fix | Delete
raise _OptionError("invalid warning category: %r" % (category,))
[249] Fix | Delete
return cat
[250] Fix | Delete
[251] Fix | Delete
[252] Fix | Delete
def _is_internal_frame(frame):
[253] Fix | Delete
"""Signal whether the frame is an internal CPython implementation detail."""
[254] Fix | Delete
filename = frame.f_code.co_filename
[255] Fix | Delete
return 'importlib' in filename and '_bootstrap' in filename
[256] Fix | Delete
[257] Fix | Delete
[258] Fix | Delete
def _next_external_frame(frame):
[259] Fix | Delete
"""Find the next frame that doesn't involve CPython internals."""
[260] Fix | Delete
frame = frame.f_back
[261] Fix | Delete
while frame is not None and _is_internal_frame(frame):
[262] Fix | Delete
frame = frame.f_back
[263] Fix | Delete
return frame
[264] Fix | Delete
[265] Fix | Delete
[266] Fix | Delete
# Code typically replaced by _warnings
[267] Fix | Delete
def warn(message, category=None, stacklevel=1, source=None):
[268] Fix | Delete
"""Issue a warning, or maybe ignore it or raise an exception."""
[269] Fix | Delete
# Check if message is already a Warning object
[270] Fix | Delete
if isinstance(message, Warning):
[271] Fix | Delete
category = message.__class__
[272] Fix | Delete
# Check category argument
[273] Fix | Delete
if category is None:
[274] Fix | Delete
category = UserWarning
[275] Fix | Delete
if not (isinstance(category, type) and issubclass(category, Warning)):
[276] Fix | Delete
raise TypeError("category must be a Warning subclass, "
[277] Fix | Delete
"not '{:s}'".format(type(category).__name__))
[278] Fix | Delete
# Get context information
[279] Fix | Delete
try:
[280] Fix | Delete
if stacklevel <= 1 or _is_internal_frame(sys._getframe(1)):
[281] Fix | Delete
# If frame is too small to care or if the warning originated in
[282] Fix | Delete
# internal code, then do not try to hide any frames.
[283] Fix | Delete
frame = sys._getframe(stacklevel)
[284] Fix | Delete
else:
[285] Fix | Delete
frame = sys._getframe(1)
[286] Fix | Delete
# Look for one frame less since the above line starts us off.
[287] Fix | Delete
for x in range(stacklevel-1):
[288] Fix | Delete
frame = _next_external_frame(frame)
[289] Fix | Delete
if frame is None:
[290] Fix | Delete
raise ValueError
[291] Fix | Delete
except ValueError:
[292] Fix | Delete
globals = sys.__dict__
[293] Fix | Delete
lineno = 1
[294] Fix | Delete
else:
[295] Fix | Delete
globals = frame.f_globals
[296] Fix | Delete
lineno = frame.f_lineno
[297] Fix | Delete
if '__name__' in globals:
[298] Fix | Delete
module = globals['__name__']
[299] Fix | Delete
else:
[300] Fix | Delete
module = "<string>"
[301] Fix | Delete
filename = globals.get('__file__')
[302] Fix | Delete
if filename:
[303] Fix | Delete
fnl = filename.lower()
[304] Fix | Delete
if fnl.endswith(".pyc"):
[305] Fix | Delete
filename = filename[:-1]
[306] Fix | Delete
else:
[307] Fix | Delete
if module == "__main__":
[308] Fix | Delete
try:
[309] Fix | Delete
filename = sys.argv[0]
[310] Fix | Delete
except AttributeError:
[311] Fix | Delete
# embedded interpreters don't have sys.argv, see bug #839151
[312] Fix | Delete
filename = '__main__'
[313] Fix | Delete
if not filename:
[314] Fix | Delete
filename = module
[315] Fix | Delete
registry = globals.setdefault("__warningregistry__", {})
[316] Fix | Delete
warn_explicit(message, category, filename, lineno, module, registry,
[317] Fix | Delete
globals, source)
[318] Fix | Delete
[319] Fix | Delete
def warn_explicit(message, category, filename, lineno,
[320] Fix | Delete
module=None, registry=None, module_globals=None,
[321] Fix | Delete
source=None):
[322] Fix | Delete
lineno = int(lineno)
[323] Fix | Delete
if module is None:
[324] Fix | Delete
module = filename or "<unknown>"
[325] Fix | Delete
if module[-3:].lower() == ".py":
[326] Fix | Delete
module = module[:-3] # XXX What about leading pathname?
[327] Fix | Delete
if registry is None:
[328] Fix | Delete
registry = {}
[329] Fix | Delete
if registry.get('version', 0) != _filters_version:
[330] Fix | Delete
registry.clear()
[331] Fix | Delete
registry['version'] = _filters_version
[332] Fix | Delete
if isinstance(message, Warning):
[333] Fix | Delete
text = str(message)
[334] Fix | Delete
category = message.__class__
[335] Fix | Delete
else:
[336] Fix | Delete
text = message
[337] Fix | Delete
message = category(message)
[338] Fix | Delete
key = (text, category, lineno)
[339] Fix | Delete
# Quick test for common case
[340] Fix | Delete
if registry.get(key):
[341] Fix | Delete
return
[342] Fix | Delete
# Search the filters
[343] Fix | Delete
for item in filters:
[344] Fix | Delete
action, msg, cat, mod, ln = item
[345] Fix | Delete
if ((msg is None or msg.match(text)) and
[346] Fix | Delete
issubclass(category, cat) and
[347] Fix | Delete
(mod is None or mod.match(module)) and
[348] Fix | Delete
(ln == 0 or lineno == ln)):
[349] Fix | Delete
break
[350] Fix | Delete
else:
[351] Fix | Delete
action = defaultaction
[352] Fix | Delete
# Early exit actions
[353] Fix | Delete
if action == "ignore":
[354] Fix | Delete
registry[key] = 1
[355] Fix | Delete
return
[356] Fix | Delete
[357] Fix | Delete
# Prime the linecache for formatting, in case the
[358] Fix | Delete
# "file" is actually in a zipfile or something.
[359] Fix | Delete
import linecache
[360] Fix | Delete
linecache.getlines(filename, module_globals)
[361] Fix | Delete
[362] Fix | Delete
if action == "error":
[363] Fix | Delete
raise message
[364] Fix | Delete
# Other actions
[365] Fix | Delete
if action == "once":
[366] Fix | Delete
registry[key] = 1
[367] Fix | Delete
oncekey = (text, category)
[368] Fix | Delete
if onceregistry.get(oncekey):
[369] Fix | Delete
return
[370] Fix | Delete
onceregistry[oncekey] = 1
[371] Fix | Delete
elif action == "always":
[372] Fix | Delete
pass
[373] Fix | Delete
elif action == "module":
[374] Fix | Delete
registry[key] = 1
[375] Fix | Delete
altkey = (text, category, 0)
[376] Fix | Delete
if registry.get(altkey):
[377] Fix | Delete
return
[378] Fix | Delete
registry[altkey] = 1
[379] Fix | Delete
elif action == "default":
[380] Fix | Delete
registry[key] = 1
[381] Fix | Delete
else:
[382] Fix | Delete
# Unrecognized actions are errors
[383] Fix | Delete
raise RuntimeError(
[384] Fix | Delete
"Unrecognized action (%r) in warnings.filters:\n %s" %
[385] Fix | Delete
(action, item))
[386] Fix | Delete
# Print message and context
[387] Fix | Delete
msg = WarningMessage(message, category, filename, lineno, source)
[388] Fix | Delete
_showwarnmsg(msg)
[389] Fix | Delete
[390] Fix | Delete
[391] Fix | Delete
class WarningMessage(object):
[392] Fix | Delete
[393] Fix | Delete
_WARNING_DETAILS = ("message", "category", "filename", "lineno", "file",
[394] Fix | Delete
"line", "source")
[395] Fix | Delete
[396] Fix | Delete
def __init__(self, message, category, filename, lineno, file=None,
[397] Fix | Delete
line=None, source=None):
[398] Fix | Delete
local_values = locals()
[399] Fix | Delete
for attr in self._WARNING_DETAILS:
[400] Fix | Delete
setattr(self, attr, local_values[attr])
[401] Fix | Delete
self._category_name = category.__name__ if category else None
[402] Fix | Delete
[403] Fix | Delete
def __str__(self):
[404] Fix | Delete
return ("{message : %r, category : %r, filename : %r, lineno : %s, "
[405] Fix | Delete
"line : %r}" % (self.message, self._category_name,
[406] Fix | Delete
self.filename, self.lineno, self.line))
[407] Fix | Delete
[408] Fix | Delete
[409] Fix | Delete
class catch_warnings(object):
[410] Fix | Delete
[411] Fix | Delete
"""A context manager that copies and restores the warnings filter upon
[412] Fix | Delete
exiting the context.
[413] Fix | Delete
[414] Fix | Delete
The 'record' argument specifies whether warnings should be captured by a
[415] Fix | Delete
custom implementation of warnings.showwarning() and be appended to a list
[416] Fix | Delete
returned by the context manager. Otherwise None is returned by the context
[417] Fix | Delete
manager. The objects appended to the list are arguments whose attributes
[418] Fix | Delete
mirror the arguments to showwarning().
[419] Fix | Delete
[420] Fix | Delete
The 'module' argument is to specify an alternative module to the module
[421] Fix | Delete
named 'warnings' and imported under that name. This argument is only useful
[422] Fix | Delete
when testing the warnings module itself.
[423] Fix | Delete
[424] Fix | Delete
"""
[425] Fix | Delete
[426] Fix | Delete
def __init__(self, *, record=False, module=None):
[427] Fix | Delete
"""Specify whether to record warnings and if an alternative module
[428] Fix | Delete
should be used other than sys.modules['warnings'].
[429] Fix | Delete
[430] Fix | Delete
For compatibility with Python 3.0, please consider all arguments to be
[431] Fix | Delete
keyword-only.
[432] Fix | Delete
[433] Fix | Delete
"""
[434] Fix | Delete
self._record = record
[435] Fix | Delete
self._module = sys.modules['warnings'] if module is None else module
[436] Fix | Delete
self._entered = False
[437] Fix | Delete
[438] Fix | Delete
def __repr__(self):
[439] Fix | Delete
args = []
[440] Fix | Delete
if self._record:
[441] Fix | Delete
args.append("record=True")
[442] Fix | Delete
if self._module is not sys.modules['warnings']:
[443] Fix | Delete
args.append("module=%r" % self._module)
[444] Fix | Delete
name = type(self).__name__
[445] Fix | Delete
return "%s(%s)" % (name, ", ".join(args))
[446] Fix | Delete
[447] Fix | Delete
def __enter__(self):
[448] Fix | Delete
if self._entered:
[449] Fix | Delete
raise RuntimeError("Cannot enter %r twice" % self)
[450] Fix | Delete
self._entered = True
[451] Fix | Delete
self._filters = self._module.filters
[452] Fix | Delete
self._module.filters = self._filters[:]
[453] Fix | Delete
self._module._filters_mutated()
[454] Fix | Delete
self._showwarning = self._module.showwarning
[455] Fix | Delete
self._showwarnmsg_impl = self._module._showwarnmsg_impl
[456] Fix | Delete
if self._record:
[457] Fix | Delete
log = []
[458] Fix | Delete
self._module._showwarnmsg_impl = log.append
[459] Fix | Delete
# Reset showwarning() to the default implementation to make sure
[460] Fix | Delete
# that _showwarnmsg() calls _showwarnmsg_impl()
[461] Fix | Delete
self._module.showwarning = self._module._showwarning_orig
[462] Fix | Delete
return log
[463] Fix | Delete
else:
[464] Fix | Delete
return None
[465] Fix | Delete
[466] Fix | Delete
def __exit__(self, *exc_info):
[467] Fix | Delete
if not self._entered:
[468] Fix | Delete
raise RuntimeError("Cannot exit %r without entering first" % self)
[469] Fix | Delete
self._module.filters = self._filters
[470] Fix | Delete
self._module._filters_mutated()
[471] Fix | Delete
self._module.showwarning = self._showwarning
[472] Fix | Delete
self._module._showwarnmsg_impl = self._showwarnmsg_impl
[473] Fix | Delete
[474] Fix | Delete
[475] Fix | Delete
# filters contains a sequence of filter 5-tuples
[476] Fix | Delete
# The components of the 5-tuple are:
[477] Fix | Delete
# - an action: error, ignore, always, default, module, or once
[478] Fix | Delete
# - a compiled regex that must match the warning message
[479] Fix | Delete
# - a class representing the warning category
[480] Fix | Delete
# - a compiled regex that must match the module that is being warned
[481] Fix | Delete
# - a line number for the line being warning, or 0 to mean any line
[482] Fix | Delete
# If either if the compiled regexs are None, match anything.
[483] Fix | Delete
_warnings_defaults = False
[484] Fix | Delete
try:
[485] Fix | Delete
from _warnings import (filters, _defaultaction, _onceregistry,
[486] Fix | Delete
warn, warn_explicit, _filters_mutated)
[487] Fix | Delete
defaultaction = _defaultaction
[488] Fix | Delete
onceregistry = _onceregistry
[489] Fix | Delete
_warnings_defaults = True
[490] Fix | Delete
except ImportError:
[491] Fix | Delete
filters = []
[492] Fix | Delete
defaultaction = "default"
[493] Fix | Delete
onceregistry = {}
[494] Fix | Delete
[495] Fix | Delete
_filters_version = 1
[496] Fix | Delete
[497] Fix | Delete
def _filters_mutated():
[498] Fix | Delete
global _filters_version
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function