当前位置: 首页>>代码示例>>Python>>正文


Python warnings.formatwarning方法代码示例

本文整理汇总了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) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:19,代码来源:__init__.py

示例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) 
开发者ID:AdamGagorik,项目名称:pydarkstar,代码行数:22,代码来源:logutils.py

示例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) 
开发者ID:simondlevy,项目名称:BreezyCreate2,代码行数:23,代码来源:__init__.py

示例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) 
开发者ID:abusesa,项目名称:abusehelper,代码行数:18,代码来源:bot.py

示例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)) 
开发者ID:recipy,项目名称:recipy,代码行数:20,代码来源:log.py

示例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) 
开发者ID:QQuick,项目名称:Transcrypt,代码行数:19,代码来源:__init__.py


注:本文中的warnings.formatwarning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。