當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。