本文整理汇总了Python中warnings.formatwarning方法的典型用法代码示例。如果您正苦于以下问题:Python warnings.formatwarning方法的具体用法?Python warnings.formatwarning怎么用?Python warnings.formatwarning使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类warnings
的用法示例。
在下文中一共展示了warnings.formatwarning方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _showwarning
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def _showwarning(message, category, filename, lineno, file=None, line=None):
"""
Implementation of showwarnings which redirects to logging, which will first
check to see if the file parameter is None. If a file is specified, it will
delegate to the original warnings implementation of showwarning. Otherwise,
it will call warnings.formatwarning and will log the resulting string to a
warnings logger named "py.warnings" with level logging.WARNING.
"""
if file is not None:
if _warnings_showwarning is not None:
_warnings_showwarning(message, category, filename, lineno, file, line)
else:
s = warnings.formatwarning(message, category, filename, lineno, line)
logger = getLogger("py.warnings")
if not logger.handlers:
logger.addHandler(NullHandler())
logger.warning("%s", s)
示例2: capture
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def capture(capture_warnings=True, fail=False):
"""
Log exceptions and warnings.
"""
default_warning_format = warnings.formatwarning
try:
if capture_warnings:
warnings.formatwarning = custom_warning_format
logging.captureWarnings(True)
try:
yield
except Exception as e:
logging.exception('caught unhandled excetion')
if fail:
if not isinstance(e, Warning):
raise RuntimeError('application failure')
finally:
if capture_warnings:
warnings.formatwarning = default_warning_format
logging.captureWarnings(False)
示例3: play_note
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def play_note(self,note_name,note_duration):
"""Plays a single note by creating a 1 note song in song 0
"""
current_song = 0
play_list=[]
noError = True
if noError:
#Need to map ascii to numbers from the dict.
if note_name in self.config.data['midi table']:
play_list.append(self.config.data['midi table'][note_name])
play_list.append(note_duration)
else:
# That note doesn't exist. Plays nothing
# Raise an error so the software knows that the input was bad
play_list.append(self.config.data['midi table'][0])
warnings.formatwarning = custom_format_warning
warnings.warn("Warning: Note '" + note_name + "' was not found in midi table")
#create a song from play_list and play it
self.create_song(current_song,play_list)
self.play(current_song)
示例4: execute
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def execute(self):
def showwarning(message, category, filename, fileno, file=None, line=None):
msg = warnings.formatwarning(message, category, filename, fileno, line)
self.log.warning(msg.strip())
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.showwarning = showwarning
try:
return self.run()
except SystemExit:
raise
except:
self.log.critical(traceback.format_exc().strip())
sys.exit(1)
示例5: log_warning
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def log_warning(msg, typ, script, lineno, file=None, line=None):
if option_set('general', 'debug'):
print('Logging warning "%s"' % str(msg))
warning = {
'type': typ.__name__,
'message': str(msg),
'script': script,
'lineno': lineno
}
# Update object in DB
db = open_or_create_db()
db.update(append("warnings", warning, no_duplicates=True), eids=[RUN_ID])
db.close()
# Done logging, print warning to stderr
sys.stderr.write(warnings.formatwarning(msg, typ, script, lineno, line=line))
示例6: _showwarning
# 需要导入模块: import warnings [as 别名]
# 或者: from warnings import formatwarning [as 别名]
def _showwarning(message, category, filename, lineno, file=None, line=None):
"""
Implementation of showwarnings which redirects to logging, which will first
check to see if the file parameter is None. If a file is specified, it will
delegate to the original warnings implementation of showwarning. Otherwise,
it will call warnings.formatwarning and will log the resulting string to a
warnings logger named "py.warnings" with level logging.WARNING.
"""
if file is not None:
if _warnings_showwarning is not None:
_warnings_showwarning(message, category, filename, lineno, file, line)
else:
s = warnings.formatwarning(message, category, filename, lineno, line)
logger = getLogger("py.warnings")
if not logger.handlers:
logger.addHandler(NullHandler())
logger.warning(s)