From 00ff7a992b2761e26629cbdc685dfb25242925d6 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Mon, 6 Nov 2023 15:56:31 +0100 Subject: [PATCH] Skip monkey-patching ZipFile on py3.7+ (has the fix) Signed-off-by: Bernhard Kaindl --- xen-bugtool | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xen-bugtool b/xen-bugtool index 08e576bc..b1bdbd4a 100755 --- a/xen-bugtool +++ b/xen-bugtool @@ -65,16 +65,18 @@ from xml.etree.ElementTree import Element import defusedxml.sax +# Fixed in 3.7: https://github.com/python/cpython/pull/12628 # Monkey-patch zipfile's __del__ function to be less stupid # Specifically, it calls close which further writes to the file, which # fails with ENOSPC if the root filesystem is full -zipfile_del = zipfile.ZipFile.__del__ -def exceptionless_del(*argl, **kwargs): - try: - zipfile_del(*argl, **kwargs) - except: - pass -zipfile.ZipFile.__del__ = exceptionless_del +if sys.version < "3.7": + zipfile_del = zipfile.ZipFile.__del__ # type: ignore[attr-defined] # mypy,pyright + def exceptionless_del(*argl, **kwargs): + try: + zipfile_del(*argl, **kwargs) + except OSError: + pass + zipfile.ZipFile.__del__ = exceptionless_del # type: ignore[attr-defined] # mypy,pyright def xapi_local_session(): import XenAPI # Import on first use.