已开启
fix: it is safer to open files using with open #131
AtomGit-Bot创建于 2025年3月31日
fix: it is safer to open files using with open #131
已开启
AtomGit-Bot创建于 2025年3月31日
refs/pull/131/head合入到master
1 个文件变更+5-3
@@ -132,9 +132,11 @@ def diff_rpm_info(old_info, new_info, report_name, isContext="false"):
132 d = difflib.HtmlDiff()132 d = difflib.HtmlDiff()
133 html = d.make_file(old_info.splitlines(), new_info.splitlines(), context=isContext)133 html = d.make_file(old_info.splitlines(), new_info.splitlines(), context=isContext)
134 html = html.encode()134 html = html.encode()
135- fp = open(report_name + ".html", "w+b")135+ try:
136- fp.write(html)136+ with open(f"{report_name}.html", "wb") as fp:
137- fp.close()137+ fp.write(html.encode())
138+ except IOError as e:
139+ print(f"Error writing diff report: {str(e)}")
138 140 
139 141 
140if __name__ == "__main__":142if __name__ == "__main__":