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


Python ErrorHandler.reset方法代码示例

本文整理汇总了Python中errorhandler.ErrorHandler.reset方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorHandler.reset方法的具体用法?Python ErrorHandler.reset怎么用?Python ErrorHandler.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在errorhandler.ErrorHandler的用法示例。


在下文中一共展示了ErrorHandler.reset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ErrorFilter

# 需要导入模块: from errorhandler import ErrorHandler [as 别名]
# 或者: from errorhandler.ErrorHandler import reset [as 别名]
class ErrorFilter(BaseReader, BaseWriter):

    temp_path = None

    def __init__(self, level=logging.ERROR, message="No output as errors have occurred."):
        from errorhandler import ErrorHandler

        self.handler = ErrorHandler(level)
        self.message = message

    def start(self, create=True):
        self.prefix = 0
        self.handler.reset()
        if self.temp_path is not None:
            rmtree(self.temp_path)
        if create:
            self.temp_path = mkdtemp()
        else:
            self.temp_path = None
        BaseWriter.start(self)

    def get_stream(self, filename):
        self.prefix += 1
        return open(os.path.join(self.temp_path, str(self.prefix) + "-" + filename), "wb")

    def get_workbooks(self):
        if self.temp_path is None:
            return
        filenames = []
        for name in os.listdir(self.temp_path):
            d = name.split("-", 1)
            d.append(name)
            filenames.append(d)
        filenames.sort()
        for i, filename, pathname in filenames:
            yield (
                # We currently don't open with on_demand=True here
                # as error filters should be lastish in the chain
                # so there's not much win.
                # However, if we did, getting rid of the temp dirs
                # becomes a problem as, on Windows, they can't be
                # deleted until the xlrd.Book object is done with
                # and we don't know when that might be :-(
                xlrd.open_workbook(
                    os.path.join(self.temp_path, pathname),
                    pickleable=0,
                    formatting_info=1,
                    on_demand=False,
                    ragged_rows=True,
                ),
                filename,
            )

    def sheet(self, rdsheet, wtsheet_name):
        self.rdsheet = rdsheet
        BaseWriter.sheet(self, rdsheet, wtsheet_name)

    def cell(self, rdrowx, rdcolx, wtrowx, wtcolx):
        cell = self.rdsheet.cell(rdrowx, rdcolx)
        if cell.ctype == xlrd.XL_CELL_EMPTY:
            return
        if cell.ctype == xlrd.XL_CELL_ERROR:
            logger.error(
                "Cell %s of sheet %r contains a bad value: %s"
                % (
                    xlrd.cellname(rdrowx, rdcolx),
                    quoted_sheet_name(self.rdsheet.name),
                    cell_display(cell, self.rdbook.datemode),
                )
            )
            return
        BaseWriter.cell(self, rdrowx, rdcolx, wtrowx, wtcolx)

    def finish(self):
        BaseWriter.finish(self)
        if self.handler.fired:
            logger.error(self.message)
        else:
            self(self.next)
        self.start(create=False)
        for attr in ("rdbook", "rdsheet"):
            if hasattr(self, attr):
                delattr(self, attr)
开发者ID:saullocastro,项目名称:desicos,代码行数:85,代码来源:filter.py


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