comparators.py 文件源码

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

项目:webmon 作者: KarolBedkowski 项目源码 文件源码
def compare(self, old: str, old_date: str, new: str, new_date: str,
                ctx: common.Context, meta: dict) \
            -> ty.Tuple[bool, ty.Optional[str], ty.Optional[dict]]:
        # pylint: disable=invalid-sequence-index
        old_lines = old.split('\n')
        res = list(difflib.context_diff(
            old_lines, new.split('\n'),
            fromfiledate=old_date, tofiledate=new_date,
            lineterm='\n'))

        changed_lines = sum(1 for line in res[2:]
                            if line and line[0] != ' ' and line[0] != '*')
        if not _check_changes(ctx, changed_lines, len(old_lines),
                              self.conf.get("changes_threshold"),
                              self.conf.get("min_changed")):
            return False, None, None

        return True, "\n".join(res), self.opts
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号