__init__.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:rstvalidator.py.cli 作者: russianidiot 项目源码 文件源码
def rstvalidator(path):
    if not path:
        raise ValueError("path '' EMPTY")
    if not os.path.exists(path):
        raise OSError("%s NOT EXISTS" % path)

    reports = []

    def system_message(self, level, message, *children, **kwargs):
        args = [self, level, message] + list(children)
        result = orignal_system_message(*args, **kwargs)
        if level >= self.WARNING_LEVEL:
            # All reST failures preventing doc publishing go to reports
            # and thus will result to failed checkdocs run
            reports.append(message)
        return result

    def rst2html(value):
        """ Run rst2html translation """
        parts = publish_parts(source=value, writer_name="html4css1")
        return parts['whole']

    text = open(path).read()
    # Monkeypatch docutils for simple error/warning output support
    orignal_system_message = utils.Reporter.system_message
    utils.Reporter.system_message = system_message
    old_stderr = sys.stderr
    sys.stderr = open(os.devnull, "w")
    try:
        rst2html(text)
        utils.Reporter.system_message = orignal_system_message
        return reports
    finally:
        sys.stderr.close()
        sys.stderr = old_stderr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号